#26835 closed defect (bug) (duplicate)
did_action( $tag ) is misleading
Reported by: | iseulde | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | trivial | Version: | 3.9 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
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. :)
Change History (2)
Note: See
TracTickets for help on using
tickets.
#14994 :-)