Last active
May 7, 2021 12:57
-
-
Save DumahX/3c77ad96fdccfdd61eb86fa4d8ce062a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Copy the lines below this one into a plugin like Code Snippets (run everywhere type) | |
/** | |
* Remove an object filter. | |
* | |
* @param string $tag Hook name. | |
* @param string $class Class name. Use 'Closure' for anonymous functions. | |
* @param string|void $method Method name. Leave empty for anonymous functions. | |
* @param string|int|void $priority Priority | |
* @return void | |
*/ | |
function remove_object_filter( $tag, $class, $method = null, $priority = null ) { | |
global $wp_version; | |
$new_wp_filter_struct = false; | |
$filters = $GLOBALS['wp_filter'][ $tag ]; | |
if ( empty ( $filters ) ) { | |
return; | |
} | |
if ( version_compare( $wp_version, '4.7', '>=' ) && isset( $filters->callbacks ) ) { | |
$filters = $filters->callbacks; | |
$new_wp_filter_struct = true; | |
} | |
foreach ( $filters as $p => $filter ) { | |
if ( ! is_null( $priority ) && ( (int) $priority !== (int) $p ) ) { | |
continue; | |
} | |
foreach ( $filter as $identifier => $function ) { | |
$remove = false; | |
$function = $function['function']; | |
if ( $function instanceof Closure && $class === 'Closure' ) { | |
$remove = true; | |
} | |
if ( $remove ) { | |
if ( $new_wp_filter_struct ) { | |
unset( $GLOBALS['wp_filter'][ $tag ]->callbacks[ $p ][ $identifier ] ); | |
if ( count($GLOBALS['wp_filter'][ $tag ]->callbacks[ $p ] ) == 0 ) { | |
unset( $GLOBALS['wp_filter'][ $tag ]->callbacks[ $p ] ); | |
} | |
} else { | |
unset( $GLOBALS['wp_filter'][ $tag ][ $p ][ $identifier ] ); | |
} | |
} | |
} | |
} | |
} | |
function mepr_remove_closures() { | |
global $post; | |
if ( isset( $post->post_type ) && ( MeprProduct::is_product_page( $post ) || MeprUser::is_account_page( $post ) ) ) { | |
remove_object_filter( 'wp_head', 'Closure', null, 10 ); | |
} | |
} | |
add_action( 'wp_head', 'mepr_remove_closures', 9 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment