Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#26835 closed defect (bug) (duplicate)

did_action( $tag ) is misleading

Reported by: iseulde's profile iseulde Owned by:
Milestone: Priority: normal
Severity: trivial Version: 3.9
Component: General Keywords:
Focuses: Cc:


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)

#1 @nacin
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#14994 :-)

#2 @iseulde
10 years ago

Ah, what. And it did search for it. :)

Note: See TracTickets for help on using tickets.