From 6464d8d60dab8ca0396d07b349c0e9869a3291fe Mon Sep 17 00:00:00 2001 From: Vedanshu Jain Date: Thu, 19 Sep 2024 17:30:59 +0530 Subject: [PATCH] Register admin filters only on admin requests. --- plugins/woocommerce/src/HooksRegistry.php | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/plugins/woocommerce/src/HooksRegistry.php b/plugins/woocommerce/src/HooksRegistry.php index 9911300b33a..3235f84d106 100644 --- a/plugins/woocommerce/src/HooksRegistry.php +++ b/plugins/woocommerce/src/HooksRegistry.php @@ -94,12 +94,14 @@ class HooksRegistry { call_user_func_array( 'add_filter', $filter ); } - foreach ( self::$admin_actions as $action ) { - call_user_func_array( 'add_action', $action ); - } + if ( is_admin() ) { + foreach ( self::$admin_actions as $action ) { + call_user_func_array( 'add_action', $action ); + } - foreach ( self::$admin_filters as $filter ) { - call_user_func_array( 'add_filter', $filter ); + foreach ( self::$admin_filters as $filter ) { + call_user_func_array( 'add_filter', $filter ); + } } foreach ( self::$frontend_actions as $action ) { @@ -115,13 +117,16 @@ class HooksRegistry { * DANGEROUS: This method is used for testing and benchmarking. Do not call, unless you really know what you are doing. */ public static function unload_hooks() { - foreach ( self::$admin_actions as $action ) { - call_user_func_array( 'remove_action', $action ); + if ( is_admin() ) { + foreach ( self::$admin_actions as $action ) { + call_user_func_array( 'remove_action', $action ); + } + + foreach ( self::$admin_filters as $filter ) { + call_user_func_array( 'remove_filter', $filter ); + } } - foreach ( self::$admin_filters as $filter ) { - call_user_func_array( 'remove_filter', $filter ); - } foreach ( self::$frontend_actions as $action ) { call_user_func_array( 'remove_action', $action ); }