Last active
November 6, 2022 18:23
-
-
Save renventura/768bce92b73369d5a0c8 to your computer and use it in GitHub Desktop.
List All Currently Hooked WordPress Functions
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 //* mind this opening php tag | |
/** | |
* This snippet returns a list of all currently hooked functions. | |
* It is set up to output this data on a specific page. Do not output this data publicly. | |
* Use this snippet for debugging/testing/development. | |
* Source: http://www.rarst.net/wordpress/debug-wordpress-hooks/ | |
* Modified by Ren Ventura, EngageWP.com | |
**/ | |
//* Define the function to be called | |
function list_hooked_functions($tag=false){ | |
global $wp_filter; | |
if ($tag) { | |
$hook[$tag]=$wp_filter[$tag]; | |
if (!is_array($hook[$tag])) { | |
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); | |
return; | |
} | |
} else { | |
$hook=$wp_filter; | |
ksort($hook); | |
} | |
echo '<pre>'; | |
foreach($hook as $tag => $priority){ | |
echo "<br />>>>>>\t<strong>$tag</strong><br />"; | |
ksort($priority); | |
foreach($priority as $priority => $function){ | |
echo $priority; | |
foreach($function as $name => $properties) echo "\t$name<br />"; | |
} | |
} | |
echo '</pre>'; | |
return; | |
} | |
//* Replace the content of a test page with the output of the function | |
add_filter( 'the_content', 'rv_print_hooked_functions' ); | |
function rv_print_hooked_functions( $content ) { | |
// Replace 46 with the ID of your own test page (do not make this page visible to the public) | |
if ( is_page( 46 ) ) { | |
// Replace 'admin_notices" with the hook you want to test or remove for viewing all hooked functions | |
$content = list_hooked_functions( 'admin_notices' ); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment