$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>filters - How can I output all apply_filters and do_action?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

filters - How can I output all apply_filters and do_action?

matteradmin9PV0评论

I would like to output all apply_filters and do_action to give the user an overview of them.

If I use the Code

add_filter( 'wpErpOs_testFilter', 'wpErpOs_testFilter_callback', 10, 1 );
function wpErpOs_testFilter_callback( $testVar ) {
$testVar[] = "GM";
 return $testVar;
}
$testVar = array("VW", "Audi");
$testVar = apply_filters('wpErpOs_testFilter', $testVar);

then the hooks are displayed in

global $wp_filter;. 

If apply_filters is not called by add_filter, it does not appear in

global $wp_filter;;

How can I output all apply_filters and do_action, even those that are not called?

I would like to output all apply_filters and do_action to give the user an overview of them.

If I use the Code

add_filter( 'wpErpOs_testFilter', 'wpErpOs_testFilter_callback', 10, 1 );
function wpErpOs_testFilter_callback( $testVar ) {
$testVar[] = "GM";
 return $testVar;
}
$testVar = array("VW", "Audi");
$testVar = apply_filters('wpErpOs_testFilter', $testVar);

then the hooks are displayed in

global $wp_filter;. 

If apply_filters is not called by add_filter, it does not appear in

global $wp_filter;;

How can I output all apply_filters and do_action, even those that are not called?

Share Improve this question asked Feb 21, 2019 at 18:01 SeverinSeverin 551 gold badge1 silver badge8 bronze badges 2
  • What do you mean by "How can I output all apply_filters"? Do you want to display all hooks? Or all registered filters/actions assigned to any hook? – Krzysiek Dróżdż Commented Feb 21, 2019 at 19:39
  • I'd like to spend all the names of the hooks. Example: apply_filters('wpErpOs_testFilter', $testVar); ==> Name: wpErpOs_testFilter – Severin Commented Feb 22, 2019 at 12:23
Add a comment  | 

1 Answer 1

Reset to default 3

apply_filters and do_action are NOT stored in $wp_filter, ONLY add_filter and add_action are stored in $wp_filter

When you call apply_filters or do_action, core WordPress loops through all of the registered filters or actions (added by add_filter and add_action), looking for any matching ones, and then executes the associated function.

The only difference being actions which are stored in the $wp_actions global var

These are the global vars available for hooks (actions/filters):

global $wp_filter, $wp_actions, $wp_current_filter;

$wp_actions - stores actions that have already been fired with the number of times it was fired, each time do_action is called this number is incremented.

You can look at the Query Monitor plugin which does handle tracking of hooks (actions/filters): https://github/johnbillion/query-monitor

Now with that said, one option you have that you can do, is to add your own action for the all action, and then collect and save the filters/actions that are ran yourself.

Here's some sites that talk about this: https://www.smashingmagazine/2012/02/inside-wordpress-actions-filters/

Here's example code of doing this: https://gist.github/bueltge/1000143

https://developer.wordpress/plugins/hooks/advanced-topics/#debugging-with-the-all-hook

Post a comment

comment list (0)

  1. No comments so far