Support » Developing with WordPress » Where can I find more info about the “all” hook?

  • Cannot find any info in the codex, not listed within the “all actions” list. Any tips greatly appreciated thank you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    What “all” hook?

    http://hookr.io/all/#index=a

    Like I said, it’s not included in any documentation I can find. Only mention I could find in trac -> https://core.trac.wordpress.org/ticket/14789

    It’s a catch-all hook for any and all hooks. See – /wp-includes/plugin.php line 186.

    Found another mention here too – https://nacin.com/2010/04/23/5-ways-to-debug-wordpress/

    What information are you actually looking for? From the code it does what it says… allows every filter to run on every call. There’s not much more to it, is there?

    I was mainly curious why it’s so obscure and not mentioned in codex and was looking to see if there was a more in-depth overview, both situations of why/when to use this and some example recipes like we have for so many other hooks. But you’re correct, the basic gist can be gathered right from the code. Thx

    Moderator bcworkz

    (@bcworkz)

    …every filter to run on every call

    Um, not exactly. Assuming there is an “all” callback added, that callback is executed when any action or filter fires. do_action() and apply_filters() indirectly call WP_Hook::do_all_hook() every time. The method name is a little misleading, it means call any callbacks that have been added to the “all” action. Not do all the callbacks added to other filters and actions.

    The result is any “all” callback is executed dozens of times on any request. You best make it very efficient. Other than for debugging purposes, I don’t see the utility of such a hook.

    @bcworkz Debugging was what led me here and is the main interests of this inquiry. Secondarily was the interest in knowing why it’s not in the codex.

    Moderator bcworkz

    (@bcworkz)

    The fact it’s missing is likely an oversight. The Codex was compiled by random volunteers. Things were missing in it. It’s remarkable it was as complete as it was. The code reference is based on parsing inline comments from the source code. Some things went missing because of how the inline documentation was developed, by manually going over every bit of source code. It’s surprising there are not more things missing. Since “all” has little utility in real world use that I can see, it’s not the worst thing to go missing.

    I’m not trying to excuse the lack of documentation. It should have been documented. I’m only attempting to only explain why it is missing.

    @bcworkz no worries and thanks for the explanation, nothing to harp on I was just curious to stumble across it and seeing that it could be a useful tool for debugging and maybe even mapping out every action and filter from cradle to grave which is definitely a handy tool to have in one’s bag of tricks.

    I was able to do some nifty mapping such as:

    /**
     * Logging of all functions tied to a specific action hook
     * i.e. print_filters_for( 'the_content' );
     * shows all functions that fire for the_content
     **/
    function print_filters_for( $hook = '' ) {
    	global $wp_filter;
    	if ( empty( $hook ) || ! isset( $wp_filter[ $hook ] ) )
    		return;
    
    	$data = '<pre>';
    	$data .= print_r( $wp_filter[ $hook ], true );
    	$data .= '</pre>';
    	return $data;
    }
    add_action( 'all', create_function( '', 'write_log( print_filters_for( current_filter() ) );' ) );
    • This reply was modified 8 months, 3 weeks ago by pingram.
    Moderator bcworkz

    (@bcworkz)

    It’s at the very least an interesting tool to have available.

    BTW, create_function() has been deprecated in 7.2.0. You can use anonymous functions since 5.3.
    add_action( 'all', function(){ //do something });

    @bcworkz Thx, saw the notice in debug too!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Where can I find more info about the “all” hook?’ is closed to new replies.