Register admin filters only on admin requests.

This commit is contained in:
Vedanshu Jain 2024-09-19 17:30:59 +05:30
parent 73228a59ed
commit 6464d8d60d
1 changed files with 15 additions and 10 deletions

View File

@ -94,6 +94,7 @@ class HooksRegistry {
call_user_func_array( 'add_filter', $filter ); call_user_func_array( 'add_filter', $filter );
} }
if ( is_admin() ) {
foreach ( self::$admin_actions as $action ) { foreach ( self::$admin_actions as $action ) {
call_user_func_array( 'add_action', $action ); call_user_func_array( 'add_action', $action );
} }
@ -101,6 +102,7 @@ class HooksRegistry {
foreach ( self::$admin_filters as $filter ) { foreach ( self::$admin_filters as $filter ) {
call_user_func_array( 'add_filter', $filter ); call_user_func_array( 'add_filter', $filter );
} }
}
foreach ( self::$frontend_actions as $action ) { foreach ( self::$frontend_actions as $action ) {
call_user_func_array( 'add_action', $action ); call_user_func_array( 'add_action', $action );
@ -115,6 +117,7 @@ class HooksRegistry {
* DANGEROUS: This method is used for testing and benchmarking. Do not call, unless you really know what you are doing. * 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() { public static function unload_hooks() {
if ( is_admin() ) {
foreach ( self::$admin_actions as $action ) { foreach ( self::$admin_actions as $action ) {
call_user_func_array( 'remove_action', $action ); call_user_func_array( 'remove_action', $action );
} }
@ -122,6 +125,8 @@ class HooksRegistry {
foreach ( self::$admin_filters as $filter ) { foreach ( self::$admin_filters as $filter ) {
call_user_func_array( 'remove_filter', $filter ); call_user_func_array( 'remove_filter', $filter );
} }
}
foreach ( self::$frontend_actions as $action ) { foreach ( self::$frontend_actions as $action ) {
call_user_func_array( 'remove_action', $action ); call_user_func_array( 'remove_action', $action );
} }