44

I'm trying to debug a plugin which I didn't develop and I want to list all the registered actions. I've read this SO thread:

But it's specific to one hook and it's about filters, not actions.

Is there any variable like $wp_filter or something?

4
  • Use this plugin to show visually on a page https://wordpress.org/plugins/show-hooks/
    – Rafiq
    Jun 23, 2020 at 13:46
  • and you are the developer of that plugin, correct?
    – alexwc_
    Aug 24, 2020 at 2:57
  • Yes, I made this plugin for myself and then host it in WordPress.
    – Rafiq
    Aug 25, 2020 at 15:59
  • @Rafiq you should remove your show-hooks link as it is no longer valid. Dec 1, 2023 at 18:37

2 Answers 2

58

Filters and actions are both assigned to hooks. Functions assigned to hooks are stored in global $wp_filter variable. So all you have to do is to print_r it.

print_r($GLOBALS['wp_filter']);

PS. add_action function makes a add_filter call. And the latter does $wp_filter[$tag][$priority][$idx].




NOTE: you can directly add this code in functions.php, and you will see a debug on your site:

add_action('wp', function(){ echo '<pre>';print_r($GLOBALS['wp_filter']); echo '</pre>';exit; } );
4
  • nice, but where can i debug them? i tried to add if(WP_DEBUG == true){ global $wp_filter; print_r($wp_filter); } in index.php nad i got NULL
    – Jacer Omri
    Jul 2, 2013 at 14:57
  • my bad, shouldn't write global $wp_filter;
    – Jacer Omri
    Jul 2, 2013 at 15:03
  • OK, so you worked that out? Jul 2, 2013 at 15:12
  • Don't use the wp hook if you get memory problems. Place the code without hook in the functions.php.
    – jMike
    Sep 11, 2022 at 9:21
0

Original question related to action hooks.

...But it's specific to one hook and it's about filters, not actions.

Is there any variable like $wp_filter or something?

So, the answer is Yes, there is. It is $wp_actions global variable.

Refer to wp-includes/plugin.php around the line 31 (for WP 6.4.2) it is first declare $wp_actions variable to global ...without any description.

Scroll down until function do_action() line. Read their doc-block.

* @global int[]     $wp_actions        Stores the number of times each action was triggered.

So, this variable is for store the hook type action that was triggered.

For anyone who come to this page from search engine and looking for triggered filters, yes it is in $wp_filters NOT $wp_filter.

To see what was triggered actions. In your code, hook to shutdown action (or any action that is not too early) and then...

global $wp_actions;
echo '<pre>'.htmlspecialchars(print_r($wp_actions, true)).'</pre>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.