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

WordPress Trac noreply at wordpress.org
Fri Jan 8 02:39:20 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:
-------------------------+------------------------

Comment (by chriscct7):

 A use case of the proposed function is to allow a function attached to a
 filter to detect that another function has run and shortcircuit. For
 example, if you had a filter that could be called multiple times to avoid
 a loop.

 Replying to [comment:7 nacin]:
 > 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. :-)


 If I adjust the PHP file I uploaded above to use actions instead of
 filters, that's how it seems to work. Attaching a copy.

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


More information about the wp-trac mailing list