[wp-trac] [WordPress Trac] #38743: Introduce add_action_once()
WordPress Trac
noreply at wordpress.org
Thu Nov 10 10:32:12 UTC 2016
#38743: Introduce add_action_once()
-----------------------------+------------------------------
Reporter: tfrommen | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by tfrommen):
Seems like I'm unable to edit this ticket...
The second function should look like this, acutally:
{{{#!php
<?php
function add_filter_once(
$tag,
callable $function_to_add,
$priority = 10,
$accepted_args = 1,
$check_priority = false
) {
global $wp_filter;
if ( empty( $wp_filter[ $tag ] ) ) {
return add_filter( $tag, $function_to_add, $priority,
$accepted_args );
}
if ( false === $check_priority ) ) {
if ( has_filter( $tag, $function_to_add ) ) {
return false;
}
} else {
if ( empty( $wp_filter[ $tag ][ $check_priority ] ) {
return add_filter( $tag, $function_to_add, $priority,
$accepted_args );
}
foreach ( $wp_filter[ $tag ][ $check_priority ] as $data ) {
if ( isset( $data['function'] ) && $function_to_add ===
$data['function'] ) {
return false;
}
}
}
return add_filter( $tag, $function_to_add, $priority, $accepted_args
);
}
}}}
I had several version here, with and without `has_filter()` - and mixed
them up. :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38743#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list