[wp-trac] [WordPress Trac] #43621: Introduce `add_action_once` and `add_filter_once` sugar.
WordPress Trac
noreply at wordpress.org
Fri Mar 23 19:56:35 UTC 2018
#43621: Introduce `add_action_once` and `add_filter_once` sugar.
-------------------------------------------------+-------------------------
Reporter: soulseekah | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting
Component: Plugins | Review
Severity: normal | Version:
Keywords: has-patch has-unit-tests dev- | Resolution:
feedback | Focuses:
-------------------------------------------------+-------------------------
Changes (by soulseekah):
* keywords: => has-patch has-unit-tests dev-feedback
Comment:
Initial implementation and tests for `add_action_once`, `add_filter_once`
in 43621.once.diff. This depends on two new methods inside `WP_Hook`, both
of which are implemented and tested in 43621.wp_hook.diff
@johnbillion Indeed, my usual use-case for ephemeral callbacks is for
writing self-cleaning tests. However, I have recently found myself
suppressing `wp_mail` sending via the `phpmailer_init` hook for several
emails being sent out in a row.
Another practical example, I thought of is to augment the first title on a
post archive page:
{{{
add_filter_once( 'the_title', 'color_the_title_red' );
}}}
This would make the topmost post on the page be output with a red title,
while the rest is output in the regular way.
I hope this makes sense.
Special thanks to @hokku @campusboy1987 @denisco @SergeyBiryukov for
reviewing and working on this during our online contributor workshop.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43621#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list