Skip to content

Instantly share code, notes, and snippets.

@mujahidi
Created May 3, 2019 16:17
Show Gist options
  • Save mujahidi/3eed9b4c3ea415e2c0775a7d01134091 to your computer and use it in GitHub Desktop.
Save mujahidi/3eed9b4c3ea415e2c0775a7d01134091 to your computer and use it in GitHub Desktop.
Remove class hook in WordPress
<?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