[wp-trac] [WordPress Trac] #49002: class-wp-hooks.php -> function apply_filters() -> Add source code: Check if callable function or method exists.
WordPress Trac
noreply at wordpress.org
Mon Dec 16 15:29:21 UTC 2019
#49002: class-wp-hooks.php -> function apply_filters() -> Add source code: Check if
callable function or method exists.
---------------------------+-----------------------------
Reporter: sjoerdlinders | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Site Health | Version: 5.3.1
Severity: trivial | Keywords: has-patch
Focuses: |
---------------------------+-----------------------------
{{{#!php
<?php
public function apply_filters( $value, $args ) {
if ( ! $this->callbacks ) {
return $value;
}
$nesting_level = $this->nesting_level++;
$this->iterations[ $nesting_level ] = array_keys(
$this->callbacks );
$num_args = php5_count( $args );
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;
}
<Add:line1> // Check if callable function or method
exists.
<Add:line2> if ( !is_callable( $the_['function'] ) )
continue;
// 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'] ) );
}
}
} while ( false !== next( $this->iterations[
$nesting_level ] ) );
unset( $this->iterations[ $nesting_level ] );
unset( $this->current_priority[ $nesting_level ] );
$this->nesting_level--;
return $value;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49002>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list