What is “all” in isset($wp_filter)

I’m a newbie in WordPress. I’m trying to understand how it generates the XHTML pages. I guess it’s the function of do_action( 'hook-name' ) , but I’m stuck with the understanding of the instruction isset( $wp_filter['all] ) when reading the function do_action because I don’t understand what is the meaning of the word all.

Is it a PHP feature or a WordPress one?

Solutions Collecting From Web of "What is “all” in isset($wp_filter)"

all is just a string the WordPress developers picked to behave differently than any other hook. When you attach to all, your callback will fire for all other hooks.

I wouldn’t spend too much time looking at the source of do_action, just know that:

  1. add_action( 'x', 'whatever' ) will mean whatever fires for do_action( 'x' )
  2. add_action( 'all', 'whatever' ) will mean whatever fires for every do_action, regardless of the name of the hook.

Conditional if ( isset($wp_filter['all']) ) { you can find right in these hook creating functions:

  • apply_filters
  • apply_filters_ref_array
  • do_action
  • do_action_ref_array

The difference between these are in number of arguments sent. Either we need multiple arguments, thus ref_array or single argument. The other difference “action vs. filter” is simple, action can do any function/action, and filter name is typically reserved for functions that take string data and return that data filtered.

OK, these are how you create hooks. And hooks do have names, and you can fish multiple function names on the same hook name (read: tag).

enter image description here

But once you define all functions associated with specific hooks, you need to store somewhere all the hook names and associated function names. This is why we ave the global $wp_filter in WordPress. If you output that variable you will get something like…

Array
(
    [pre_term_name] => Array
        (
            [10] => Array
                (
                    [sanitize_text_field] => Array
                        (
                            [function] => sanitize_text_field
                            [accepted_args] => 1
                        )

                    [wp_filter_kses] => Array
                        (
                            [function] => wp_filter_kses
                            [accepted_args] => 1
                        )

                )

            [30] => Array
                (
                    [_wp_specialchars] => Array
                        (
                            [function] => _wp_specialchars
                            [accepted_args] => 1
                        )

                )

        )

Well, let us not argue on the name of this variable. Personally, I would call it different, probable $wp_hooks since this name is not taken. However, if we get back in the history we will find do_action is since @since 1.2.0 and apply_filters is @since 0.71 (released June 9, 2003.). That gives you pretty good explanation why it is called $wp_filter. It is most probable because filters were introduced first in WordPress. Later they introduced actions.

Just building on being said from @TheDeadMedic…

add_action( ‘all’, ‘whatever’ ) will mean whatever fires for every do_action, regardless of the name of the hook.

I raised the question why do we need $wp_filter['all']? Just few examples. Introspection, tests, and probable more of system internal features in the future WordPress versions.