Intercepting a add_action

You can use has_action(). It returns the priority of the hook if it exists, otherwise false. So check that the priority is not equal to false (and not just false-y, or being hooked at 0 will appear false) then use that to remove the hook.

$priority = has_action( 'publish_post', 'myCustomFunction' );

if ( $priority !== false ) {
    remove_action( 'publish_post', 'myCustomFunction', $priority );
}

There’s also has_filter(), which does exactly the same thing (has_action() just calls has_filter()).

Leave a Comment