Skip to content
Merged
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
2 changes: 1 addition & 1 deletion aaa-option-optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Plugin Name: AAA Option Optimizer
* Plugin URI: https://progressplanner.com/plugins/aaa-option-optimizer/
* Description: Tracks autoloaded options usage and allows the user to optimize them.
* Version: 1.6.0
* Version: 1.6.1
* License: GPL-3.0+
* Author: Team Prospress Planner
* Author URI: https://prospressplanner.com/
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== AAA Option Optimizer ===
Contributors: joostdevalk, aristath, filipi
Contributors: joostdevalk, aristath, filipi, progressplanner
Tags: options, database, cleanup
Requires at least: 6.7
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.6.0
Stable tag: 1.6.1
License: GPL3+
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html

Expand Down Expand Up @@ -54,6 +54,10 @@ Please do a pull request via GitHub on [this file](https://github.com/ProgressPl

== Changelog ==

= 1.6.1 =

* Fix infinite recursion in option access monitoring that could cause a fatal error in certain hosting environments.

= 1.6.0

* Replace using 'all' filter for monitoring option usage with 'pre_option' filter for better performance.
Expand Down
21 changes: 20 additions & 1 deletion src/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class Plugin {
*/
protected $accessed_options = [];

/**
* Whether the plugin is currently processing an option access.
* Used to prevent infinite recursion.
*
* @var bool
*/
protected $is_processing = false;

/**
* Whether the plugin should reset the option_optimizer data.
*
Expand Down Expand Up @@ -101,10 +109,16 @@ public function reset( $should_reset = true ) {
* @return void
*/
public function monitor_option_accesses_legacy( $tag ) {
if ( $this->is_processing ) {
return;
}

// Check if the tag is related to an option access.
if ( str_starts_with( $tag, 'option_' ) || str_starts_with( $tag, 'default_option_' ) ) {
$option_name = preg_replace( '#^(default_)?option_#', '', $tag );
$this->is_processing = true;
$option_name = preg_replace( '#^(default_)?option_#', '', $tag );
$this->add_option_usage( $option_name );
$this->is_processing = false;
}
}

Expand All @@ -117,10 +131,15 @@ public function monitor_option_accesses_legacy( $tag ) {
* @return mixed
*/
public function monitor_option_accesses_pre_option( $pre, $option_name ) {
if ( $this->is_processing ) {
return $pre;
}

// If the $pre is false the get_option() will not be short-circuited.
if ( ! defined( 'WP_SETUP_CONFIG' ) && false === $pre ) {
$this->is_processing = true;
$this->add_option_usage( $option_name );
$this->is_processing = false;
}

return $pre;
Expand Down
Loading