Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![CS](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/cs.yml/badge.svg)](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/cs.yml)
[![PHPStan](https://github.com/Emilia-Capital/aaa-option-optimizer/actions/workflows/phpstan.yml/badge.svg)](https://github.com/Emilia-Capital/aaa-option-optimizer/actions/workflows/phpstan.yml)
[![Lint](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/lint.yml/badge.svg)](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/lint.yml)
[![Security](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/security.yml/badge.svg)](https://github.com/emilia-capital/aaa-option-optimizer/actions/workflows/security.yml)
[![CS](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/cs.yml/badge.svg)](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/cs.yml)
[![PHPStan](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/phpstan.yml/badge.svg)](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/phpstan.yml)
[![Lint](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/lint.yml/badge.svg)](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/lint.yml)
[![Security](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/security.yml/badge.svg)](https://github.com/ProgressPlanner/aaa-option-optimizer/actions/workflows/security.yml)

[![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/aaa-option-optimizer.svg)](https://wordpress.org/plugins/aaa-option-optimizer/)
![WordPress Plugin: Tested WP Version](https://img.shields.io/wordpress/plugin/tested/aaa-option-optimizer.svg)
Expand All @@ -10,7 +10,7 @@
[![WordPress Plugin Rating](https://img.shields.io/wordpress/plugin/stars/aaa-option-optimizer.svg)](https://wordpress.org/support/plugin/aaa-option-optimizer/reviews/)
[![GitHub](https://img.shields.io/github/license/ProgressPlanner/aaa-option-optimizer.svg)](https://github.com/ProgressPlanner/aaa-option-optimizer/blob/main/LICENSE)

[![Try this plugin on the WordPress playground](https://img.shields.io/badge/Try%20this%20plugin%20on%20the%20WordPress%20Playground-%23117AC9.svg?style=for-the-badge&logo=WordPress&logoColor=ddd)](https://playground.wordpress.net/#%7B%22landingPage%22:%22/wp-admin/tools.php?page=aaa-option-optimizer%22,%22features%22:%7B%22networking%22:true%7D,%22steps%22:%5B%7B%22step%22:%22defineWpConfigConsts%22,%22consts%22:%7B%22IS_PLAYGROUND_PREVIEW%22:true%7D%7D,%7B%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22%7D,%7B%22step%22:%22installPlugin%22,%22pluginZipFile%22:%7B%22resource%22:%22url%22,%22url%22:%22https://bypass-cors.altha.workers.dev/https://github.com/Emilia-Capital/aaa-option-optimizer/archive/refs/heads/develop.zip%22%7D,%22options%22:%7B%22activate%22:true%7D%7D%5D%7D)
[![Try this plugin on the WordPress playground](https://img.shields.io/badge/Try%20this%20plugin%20on%20the%20WordPress%20Playground-%23117AC9.svg?style=for-the-badge&logo=WordPress&logoColor=ddd)](https://playground.wordpress.net/#%7B%22landingPage%22:%22/wp-admin/tools.php?page=aaa-option-optimizer%22,%22features%22:%7B%22networking%22:true%7D,%22steps%22:%5B%7B%22step%22:%22defineWpConfigConsts%22,%22consts%22:%7B%22IS_PLAYGROUND_PREVIEW%22:true%7D%7D,%7B%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22%7D,%7B%22step%22:%22installPlugin%22,%22pluginZipFile%22:%7B%22resource%22:%22url%22,%22url%22:%22https://bypass-cors.altha.workers.dev/https://github.com/ProgressPlanner/aaa-option-optimizer/archive/refs/heads/develop.zip%22%7D,%22options%22:%7B%22activate%22:true%7D%7D%5D%7D)

![GitHub banner](/.wordpress-org/github_banner_aaaoo_pp.png)

Expand All @@ -26,7 +26,7 @@ Install this plugin, and go through your entire site. Best is to use it normally

### Why the AAA prefix in the plugin name?

Because the plugin needs to measure options being loaded, it benefits from being loaded itself first. As WordPress loads plugins alphabetically,
Because the plugin needs to measure options being loaded, it benefits from being loaded itself first. As WordPress loads plugins alphabetically,
starting the name with AAA made sense.

### Do I need to take precautions?
Expand All @@ -35,7 +35,7 @@ Yes!! Backup your database.

### How can I add recognized plugins?

Please do a pull request via GitHub on [this file](https://github.com/Emilia-Capital/aaa-option-optimizer/blob/develop/known-plugins/known-plugins.json) in the plugin.
Please do a pull request via GitHub on [this file](https://github.com/ProgressPlanner/aaa-option-optimizer/blob/develop/known-plugins/known-plugins.json) in the plugin.

### How can I report security bugs?

Expand Down
57 changes: 42 additions & 15 deletions aaa-option-optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin that tracks autoloaded options usage and allows the user to optimize them.
*
* @package Emilia\OptionOptimizer
* @package Progress_Planner\OptionOptimizer
*
* Plugin Name: AAA Option Optimizer
* Plugin URI: https://progressplanner.com/plugins/aaa-option-optimizer/
Expand All @@ -27,12 +27,19 @@
register_deactivation_hook( __FILE__, 'aaa_option_optimizer_deactivation' );

/**
* Activation hooked function to store start stats.
* Activation hooked function to store start stats and create table.
*
* @return void
*/
function aaa_option_optimizer_activation() {
global $wpdb;

// Create the custom table.
Progress_Planner\OptionOptimizer\Database::create_table();

// Migrate existing data if present.
Progress_Planner\OptionOptimizer\Database::maybe_migrate();

$autoload_values = \wp_autoload_values_to_autoload();
$placeholders = implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) );

Expand All @@ -42,19 +49,22 @@ function aaa_option_optimizer_activation() {
);
// phpcs:enable WordPress.DB

update_option(
'option_optimizer',
[
'starting_point_kb' => ( $result->autoload_size / 1024 ),
'starting_point_num' => $result->count,
'starting_point_date' => current_time( 'mysql' ),
'used_options' => [],
'settings' => [
'option_tracking' => 'pre_option',
// Only set starting point if not already set (preserve existing data).
$existing = get_option( 'option_optimizer' );
if ( empty( $existing['starting_point_date'] ) ) {
update_option(
'option_optimizer',
[
'starting_point_kb' => ( $result->autoload_size / 1024 ),
'starting_point_num' => $result->count,
'starting_point_date' => current_time( 'mysql' ),
'settings' => [
'option_tracking' => 'pre_option',
],
],
],
false
);
false
);
}
}

/**
Expand All @@ -67,13 +77,30 @@ function aaa_option_optimizer_deactivation() {
update_option( 'option_optimizer', $aaa_option_value, false );
}

/**
* Ensure database table exists and migrate data if needed.
* Runs on plugins_loaded to handle existing installs that don't trigger activation.
*
* @return void
*/
function aaa_option_optimizer_maybe_upgrade() {
// Check if table exists, create if not.
if ( ! Progress_Planner\OptionOptimizer\Database::table_exists() ) {
Progress_Planner\OptionOptimizer\Database::create_table();
}

// Migrate existing data if present.
Progress_Planner\OptionOptimizer\Database::maybe_migrate();
}
add_action( 'plugins_loaded', 'aaa_option_optimizer_maybe_upgrade' );

/**
* Initializes the plugin.
*
* @return void
*/
function aaa_option_optimizer_init() {
$optimizer = new Emilia\OptionOptimizer\Plugin();
$optimizer = new Progress_Planner\OptionOptimizer\Plugin();
$optimizer->register_hooks();
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "emilia/aaa-option-optimizer",
"name": "progress-planner/aaa-option-optimizer",
"description": "Plugin that tracks autoloaded options usage and allows the user to optimize them.",
"type": "wordpress-plugin",
"license": "GPL-3.0-or-later",
Expand All @@ -16,7 +16,7 @@
"phpstan/phpstan": "^1.10",
"szepeviktor/phpstan-wordpress": "^1.3",
"phpstan/extension-installer": "^1.3",
"phpcompatibility/php-compatibility": "dev-develop as 9.99.99"
"phpcompatibility/php-compatibility": "^9.3"
},
"config": {
"allow-plugins": {
Expand Down
Loading