Skip to content
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
38628bc
aaa option optimizer
ilicfilip Feb 14, 2025
cc63c1a
update is_task_completed()
ilicfilip Feb 14, 2025
f5b4ec3
Merge branch 'develop' into filip/aaa-option-optimizer
aristath Feb 17, 2025
c8b94b5
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Feb 20, 2025
bbaca94
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Feb 21, 2025
59a782c
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Feb 25, 2025
d53d38b
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Feb 25, 2025
cb170ed
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Feb 26, 2025
ab9c78f
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Feb 27, 2025
5f856f4
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 4, 2025
4a96d07
check for all auto load values
ilicfilip Mar 4, 2025
44d21c9
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 6, 2025
09353ff
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 11, 2025
b6cb221
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 11, 2025
fe5544f
sync branch with recent changes
ilicfilip Mar 11, 2025
6a05293
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 17, 2025
38116b0
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 19, 2025
603cdeb
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 20, 2025
cfc39a4
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Mar 31, 2025
cde9125
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Apr 2, 2025
d32bafc
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Apr 8, 2025
b7f40a1
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Apr 22, 2025
883cae3
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Apr 28, 2025
a8d69af
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Jun 5, 2025
338869f
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Jul 17, 2025
e1e6254
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Jul 23, 2025
ab79014
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Jul 23, 2025
64375aa
Merge branch 'develop' into filip/aaa-option-optimizer
aristath Jul 28, 2025
dbd3235
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Sep 30, 2025
de3e33e
Merge branch 'develop' into filip/aaa-option-optimizer
aristath Oct 1, 2025
6420274
Merge branch 'develop' into filip/aaa-option-optimizer
aristath Oct 1, 2025
16945a4
Merge branch 'develop' into filip/aaa-option-optimizer
aristath Oct 15, 2025
ed3ab83
Merge branch 'develop' into filip/aaa-option-optimizer
ilicfilip Oct 23, 2025
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
2 changes: 2 additions & 0 deletions classes/suggested-tasks/class-local-tasks-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time\Permalink_Structure;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time\Php_Version;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time\Search_Engine_Visibility;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time\Reduce_Autoloaded_Options;
use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface;

/**
Expand Down Expand Up @@ -61,6 +62,7 @@ public function __construct() {
new Permalink_Structure(),
new Php_Version(),
new Search_Engine_Visibility(),
new Reduce_Autoloaded_Options(),
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* Add tasks for settings saved.
*
* @package Progress_Planner
*/

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\One_Time;

/**
* Add tasks to check if WP debug is enabled.
*/
class Reduce_Autoloaded_Options extends One_Time {

/**
* Whether the task is an onboarding task.
*
* @var bool
*/
protected const IS_ONBOARDING_TASK = false;

/**
* The provider type.
*
* @var string
*/
const CATEGORY = 'maintenance';

/**
* The provider ID.
*
* @var string
*/
const PROVIDER_ID = 'reduce-autoloaded-options';

/**
* The number of autoloaded options.
*
* @var int
*/
private $autoloaded_options_count = null;


/**
* The plugin active state.
*
* @var bool
*/
private $is_plugin_active = null;

/**
* Threshold for the number of autoloaded options.
*
* @var int
*/
private $autoloaded_options_threshold = 10; // TODO: 10 is just for testing purposes.

Check warning on line 58 in classes/suggested-tasks/local-tasks/providers/one-time/class-reduce-autoloaded-options.php

View workflow job for this annotation

GitHub Actions / Check code style

Comment refers to a TODO task "10 is just for testing purposes"

Check warning on line 58 in classes/suggested-tasks/local-tasks/providers/one-time/class-reduce-autoloaded-options.php

View workflow job for this annotation

GitHub Actions / Check code style

Comment refers to a TODO task "10 is just for testing purposes"

/**
* The plugin path.
*
* @var string
*/
private $plugin_path = 'aaa-option-optimizer/aaa-option-optimizer.php';

/**
* Constructor.
*/
public function __construct() {

$this->title = \esc_html__( 'Reduce number of autoloaded options', 'progress-planner' );
$this->description = sprintf(
// translators: %d is the number of autoloaded options.
\esc_html__( 'There are %d autoloaded options. If you don\'t need them, consider disabling them by installing the "AAA Option Optimizer" plugin.', 'progress-planner' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt normal users will understand or know whether they need autoloading options or not, and we should make it clear that this is a performance improvement

Suggested change
\esc_html__( 'There are %d autoloaded options. If you don\'t need them, consider disabling them by installing the "AAA Option Optimizer" plugin.', 'progress-planner' ),
\esc_html__( 'There are %d autoloaded options. Consider installing the "AAA Option Optimizer" plugin to improve performance.', 'progress-planner' ),

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, wording was just a placeholder during WIP and it needs to be improved - that is the one for @tacoverdo and @irisgue , if we decide to merge it 😄

$this->get_autoloaded_options_count(),
);
$this->url = \admin_url( '/plugin-install.php?tab=search&s=aaa+option+optimizer' );
$this->is_dismissable = true;
}

/**
* Check if the task condition is satisfied.
* (bool) true means that the task condition is satisfied, meaning that we don't need to add the task or task was completed.
*
* @return bool
*/
public function should_add_task() {
// If the plugin is active, we don't need to add the task.
if ( $this->is_plugin_active() ) {
return false;
}

return $this->get_autoloaded_options_count() > $this->autoloaded_options_threshold;
}

/**
* Check if the task is completed.
*
* @return bool
*/
public function is_task_completed() {
return $this->is_plugin_active() || $this->get_autoloaded_options_count() <= $this->autoloaded_options_threshold;
}

/**
* Check if the plugin is active.
*
* @return bool
*/
protected function is_plugin_active() {

if ( null === $this->is_plugin_active ) {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore requireOnce.fileNotFound
}

$plugins = get_plugins();
$this->is_plugin_active = isset( $plugins[ $this->plugin_path ] ) && is_plugin_active( $this->plugin_path );
}

return $this->is_plugin_active;
}

/**
* Get the number of autoloaded options.
*
* @return int
*/
protected function get_autoloaded_options_count() {
global $wpdb;

if ( null === $this->autoloaded_options_count ) {
$autoload_values = \wp_autoload_values_to_autoload();
$placeholders = implode( ',', array_fill( 0, count( $autoload_values ), '%s' ) );

// phpcs:disable WordPress.DB
$this->autoloaded_options_count = $wpdb->get_var(
$wpdb->prepare( "SELECT COUNT(*) FROM `{$wpdb->options}` WHERE autoload IN ( $placeholders )", $autoload_values )
);

}

return $this->autoloaded_options_count;
}
}
Loading