@@ -25,6 +25,14 @@ class Plugin {
2525 */
2626 protected $ accessed_options = [];
2727
28+ /**
29+ * Whether the plugin is currently processing an option access.
30+ * Used to prevent infinite recursion.
31+ *
32+ * @var bool
33+ */
34+ protected $ is_processing = false ;
35+
2836 /**
2937 * Whether the plugin should reset the option_optimizer data.
3038 *
@@ -101,10 +109,16 @@ public function reset( $should_reset = true ) {
101109 * @return void
102110 */
103111 public function monitor_option_accesses_legacy ( $ tag ) {
112+ if ( $ this ->is_processing ) {
113+ return ;
114+ }
115+
104116 // Check if the tag is related to an option access.
105117 if ( str_starts_with ( $ tag , 'option_ ' ) || str_starts_with ( $ tag , 'default_option_ ' ) ) {
106- $ option_name = preg_replace ( '#^(default_)?option_# ' , '' , $ tag );
118+ $ this ->is_processing = true ;
119+ $ option_name = preg_replace ( '#^(default_)?option_# ' , '' , $ tag );
107120 $ this ->add_option_usage ( $ option_name );
121+ $ this ->is_processing = false ;
108122 }
109123 }
110124
@@ -117,10 +131,15 @@ public function monitor_option_accesses_legacy( $tag ) {
117131 * @return mixed
118132 */
119133 public function monitor_option_accesses_pre_option ( $ pre , $ option_name ) {
134+ if ( $ this ->is_processing ) {
135+ return $ pre ;
136+ }
120137
121138 // If the $pre is false the get_option() will not be short-circuited.
122139 if ( ! defined ( 'WP_SETUP_CONFIG ' ) && false === $ pre ) {
140+ $ this ->is_processing = true ;
123141 $ this ->add_option_usage ( $ option_name );
142+ $ this ->is_processing = false ;
124143 }
125144
126145 return $ pre ;
0 commit comments