Where is the source code that makes the "all" array grabs filters in the $wp_filter?

All we need is an easy explanation of the problem, so here it is.

As the Question states, Where is the source code that makes the “all” array grabs filters in the $wp_filter?

I have searched the whole core about any definition to this and i just could find the if ( isset($wp_filter['all']) ) .. so if there is an isset it has to be set some where … where is the source code that makes the all array grabs filters
what would set the condition if ( isset($wp_filter['all']) ) to true

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

I think you are interested in this function: _wp_call_all_hook.

File: wp-includes/plugin.php
816: /**
817:  * Call the 'all' hook, which will process the functions hooked into it.
818:  *
819:  * The 'all' hook passes all of the arguments or parameters that were used for
820:  * the hook, which this function was called for.
821:  *
822:  * This function is used internally for apply_filters(), do_action(), and
823:  * do_action_ref_array() and is not meant to be used from outside those
824:  * functions. This function does not check for the existence of the all hook, so
825:  * it will fail unless the all hook exists prior to this function call.
826:  *
827:  * @since 2.5.0
828:  * @access private
829:  *
830:  * @global array $wp_filter  Stores all of the filters
831:  *
832:  * @param array $args The collected parameters from the hook that was called.
833:  */
834: function _wp_call_all_hook($args) {
835:    global $wp_filter;
836: 
837:    $wp_filter['all']->do_all_hook( $args );
838: }

Keep in mind.

When you add a filter you write to the $wp_filter global. The same is for the actions.

File: wp-includes/plugin.php
106: function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
107:    global $wp_filter;
108:    if ( ! isset( $wp_filter[ $tag ] ) ) {
109:        $wp_filter[ $tag ] = new WP_Hook();
110:    }
111:    $wp_filter[ $tag ]->add_filter( $tag, $function_to_add, $priority, $accepted_args );
112:    return true;
113: }

In fact, actions and filters are so close:
Look at this:

File: wp-includes/plugin.php
398: function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
399:    return add_filter($tag, $function_to_add, $priority, $accepted_args);
400: }

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply