diff --git a/aaa-option-optimizer.php b/aaa-option-optimizer.php index 75866c9..3bacb4d 100644 --- a/aaa-option-optimizer.php +++ b/aaa-option-optimizer.php @@ -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/ diff --git a/readme.txt b/readme.txt index d434e3a..d0ae23a 100644 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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. diff --git a/src/class-plugin.php b/src/class-plugin.php index 0caf091..7213d73 100644 --- a/src/class-plugin.php +++ b/src/class-plugin.php @@ -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. * @@ -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; } } @@ -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;