[wp-trac] [WordPress Trac] #26835: did_action( $tag ) is misleading

WordPress Trac noreply at wordpress.org
Tue Jan 14 20:22:20 UTC 2014


#26835: did_action( $tag ) is misleading
--------------------------+-----------------------------
 Reporter:  avryl         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  trivial       |   Keywords:
--------------------------+-----------------------------
 `did_action( $tag )` returns the number of times an action fired, but if
 you check for this during the action it counts the current one as well. So
 if you use `did_action( $tag ) ?` as a conditional during the action
 ‘`$tag`’, it returns `1` while I expect `0`. WordPress still needs to
 '''do''' the action, it didn't do it yet.

 I know this can't be changed for backward compatibility reasons, but it
 might be good to introduce another function that checks this correctly or
 to point it out in the codex.

 {{{

 function really_did_action( $tag ) {

         $count = did_action( $tag );

         return doing_action( $tag ) ? $count - 1 : $count;

 }

 function doing_action( $tag ) {

         global $wp_current_filter;

         return in_array( $tag, $wp_current_filter );

 }

 }}}

 Of course it could be named `finished_action( $tag )` or something. :)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26835>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list