[wp-trac] [WordPress Trac] #14994: Introduce a way to identify a hook in progress

WordPress Trac wp-trac at lists.automattic.com
Thu Sep 30 11:22:33 UTC 2010


#14994: Introduce a way to identify a hook in progress
--------------------------+-------------------------------------------------
 Reporter:  nacin         |       Owner:     
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  3.1
Component:  Plugins       |     Version:     
 Severity:  normal        |    Keywords:     
--------------------------+-------------------------------------------------
 We have did_action() and current_filter() but I've come across a use case
 for a hybrid of sorts, doing_action().

 Problem is, did_action() returns true the moment the hook is fired. Thus
 if you need to wait until after the hook is done executing, you need to
 also check current_filter(). The problem arises when there was another
 hook called since thne, because current_filter() does not traverse back up
 the stack.

 I considered adding an argument to either of the two other functions
 mentioned, but I think a new function makes the most sense. did_action()
 only works for actions. While current_filter() works for all hooks, it
 does one thing and that is to return the current hook. A new function
 makes the most sense here.

 doing_action() might not be the best name because did_action() only works
 for actions, but this would work for filters as well. At that point, I
 might recommend doing_hook().

 {{{
 function doing_action( $action ) {
    global $wp_current_filter;
    return in_array( $action, $'wp_current_filter );
 }
 }}}

 The use case was that a plugin was applying the_content on wp_head. That
 was messing with my footnotes plugin. So I needed to make sure I had
 completely processed wp_head first, but there was no way to do that. Now I
 would be able to check `if ( did_action('wp_head') && !
 doing_action('wp_head') )`.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14994>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list