Skip to content

Instantly share code, notes, and snippets.

@celsobessa
Last active February 21, 2019 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celsobessa/1b50b17b9da416aeca4d8b850be2d57a to your computer and use it in GitHub Desktop.
Save celsobessa/1b50b17b9da416aeca4d8b850be2d57a to your computer and use it in GitHub Desktop.
Helper functions for developing and debugging WordPress plugins and themes
/**
* Prints all actions and filters hooked to a given hook.
*
* Prints all actions and filters hooked to a given hook.
* Inspired by answers in this WordPress Stackexchange question: https://wordpress.stackexchange.com/questions/17394/how-to-know-what-functions-are-hooked-to-an-action-filter
*/
function what_is_hooked(){
$hook_name = current_filter();
global $wp_filter;
echo '<pre>';
print_r( $wp_filter[$hook_name], true );
echo '</pre>';
}
// Now you add it to the hook you want to check. e.g. wp_head
add_action( 'wp_head', 'what_is_hooked', 999);
/**
* Logs all actions and filters hooked to a given hook.
*
* Logs all actions and filters hooked to a given hook.
* Inspired by answers in this WordPress Stackexchange question: https://wordpress.stackexchange.com/questions/17394/how-to-know-what-functions-are-hooked-to-an-action-filter
*/
function log_what_is_hooked(){
$hook_name = current_filter();
global $wp_filter;
error_log( print_r( $wp_filter[$hook_name], true ) );
}
// Now you add it to the hook you want to check. e.g. wp_head
add_action( 'wp_head', 'log_what_is_hooked', 999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment