[wp-trac] [WordPress Trac] #35357: Introduce did_filter()

WordPress Trac noreply at wordpress.org
Fri Jan 8 02:33:36 UTC 2016


#35357: Introduce did_filter()
-------------------------+------------------------
 Reporter:  mordauk      |       Owner:  chriscct7
     Type:  enhancement  |      Status:  accepted
 Priority:  normal       |   Milestone:  4.5
Component:  Plugins      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  needs-patch  |     Focuses:
-------------------------+------------------------
Changes (by nacin):

 * keywords:  has-patch has-unit-tests commit => needs-patch


Comment:

 If we are to do this, I wonder if it should just be an alias of
 `did_action()` and use `$wp_actions`. That would mimic `current_filter()`
 and `add_filter()` behavior as well, making it clear they share the same
 namespace.

 I've never seen much utility for this, because filters are often run in
 different, repeated contexts, rather than a single-time action. But I
 [https://twitter.com/chriscct7/status/685283538007134208 stand corrected]
 and I'm not against adding it.

 This requires unit tests, and preferably ones that would catch that the
 increment is currently in the wrong spot. If you had 4 callbacks tied to
 the `test_did_filter` filter, calling `apply_filters( 'test_did_filter' );
 var_dump( did_filter( 'test_did_filter' );` would return 4, not 1.

 > If run after a filter is run, returns the number of functions that ran
 on the filter. If run in a function attached to a filter, returns the
 number of functions that have run on the filter before the current
 function. This works the same ways as did_action does, but for filters.

 That is not how `did_action()` works. :-)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35357#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list