Skip to content
Merged
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
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