Last active
February 21, 2019 14:43
-
-
Save celsobessa/1b50b17b9da416aeca4d8b850be2d57a to your computer and use it in GitHub Desktop.
Helper functions for developing and debugging WordPress plugins and themes
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
/** | |
* 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