Created
May 3, 2019 16:17
-
-
Save mujahidi/3eed9b4c3ea415e2c0775a7d01134091 to your computer and use it in GitHub Desktop.
Remove class hook in WordPress
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 | |
function remove_class_hook( $tag, $class_name = '', $method_name = '', $priority = 10 ) { | |
global $wp_filter; | |
$is_hook_removed = false; | |
if ( ! empty( $wp_filter[ $tag ]->callbacks[ $priority ] ) ) { | |
$methods = wp_list_pluck( $wp_filter[ $tag ]->callbacks[ $priority ], 'function' ); | |
$found_hooks = ! empty( $methods ) ? wp_list_filter( $methods, array( 1 => $method_name ) ) : array(); | |
foreach( $found_hooks as $hook_key => $hook ) { | |
if ( ! empty( $hook[0] ) && is_object( $hook[0] ) && get_class( $hook[0] ) === $class_name ) { | |
$wp_filter[ $tag ]->remove_filter( $tag, $hook, $priority ); | |
$is_hook_removed = true; | |
} | |
} | |
} | |
return $is_hook_removed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment