[wp-trac] [WordPress Trac] #46991: Stop propagation on actions or filter
WordPress Trac
noreply at wordpress.org
Mon May 20 17:58:19 UTC 2019
#46991: Stop propagation on actions or filter
-----------------------------+------------------------------
Reporter: screamingdev | Owner: (none)
Type: feature request | Status: new
Priority: low | Milestone: Awaiting Review
Component: Plugins | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion | Focuses:
-----------------------------+------------------------------
Comment (by screamingdev):
Hint @johnbillion :
* This is like "Oh, the filter 'the_content' shall not continue with this
kind of text".
* Comparable to `Event.stopPropagation()` from JavaScript
This is a possible solution directly in `\WP_Hook`:
{{{#!php
<?php
do {
$this->current_priority[ $nesting_level ] =
$priority = current( $this->iterations[ $nesting_level ] );
foreach ( $this->callbacks[ $priority ] as $the_ )
{
if( ! $this->doing_action ) {
$args[ 0 ] = $value;
}
// Avoid the array_slice if possible.
if ( $the_['accepted_args'] == 0 ) {
$value = call_user_func_array(
$the_['function'], array() );
} elseif ( $the_['accepted_args'] >=
$num_args ) {
$value = call_user_func_array(
$the_['function'], $args );
} else {
$value = call_user_func_array(
$the_['function'], array_slice( $args, 0, (int)$the_['accepted_args'] ) );
}
}
if ( $value instanceof \WP_Hook_Stop ) {
$value = $value->get_value();
break;
}
} while ( false !== next( $this->iterations[
$nesting_level ] ) );
}}}
{{{#!php
<?php
class WP_Hook_Stop {
__construct( $value = '' );
get_value();
}
}}}
This does not break anything and allows some dynamic in the WP_Hook queue.
There is nothing wrong with early termination of things when the solution
is alrady known.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46991#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list