Plugins: Convert apply_filters() into a proper variadic function.

This makes its signature more correct by implementing the spread operator, and adjusts the internal logic correspondingly without affecting performance.

Props jrf, SergeyBiryukov, davidbaumwald, mauriac, johnbillion

Fixes #53218


git-svn-id: https://develop.svn.wordpress.org/trunk@52952 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2022-03-18 18:21:40 +00:00
parent 26b266ad44
commit 735e913200
2 changed files with 51 additions and 6 deletions

View File

@@ -215,6 +215,49 @@ class Tests_Filters extends WP_UnitTestCase {
$this->assertFalse( has_filter( $tag ) );
}
/**
* @ticket 53218
*/
public function test_filter_with_ref_value() {
$obj = new stdClass();
$ref = &$obj;
$a = new MockAction();
$tag = __FUNCTION__;
add_action( $tag, array( $a, 'filter' ) );
$filtered = apply_filters( $tag, $ref );
$args = $a->get_args();
$this->assertSame( $args[0][0], $obj );
$this->assertSame( $filtered, $obj );
// Just in case we don't trust assertSame().
$obj->foo = true;
$this->assertNotEmpty( $args[0][0]->foo );
$this->assertNotEmpty( $filtered->foo );
}
/**
* @ticket 53218
*/
public function test_filter_with_ref_argument() {
$obj = new stdClass();
$ref = &$obj;
$a = new MockAction();
$tag = __FUNCTION__;
$val = 'Hello';
add_action( $tag, array( $a, 'filter' ), 10, 2 );
apply_filters( $tag, $val, $ref );
$args = $a->get_args();
$this->assertSame( $args[0][1], $obj );
// Just in case we don't trust assertSame().
$obj->foo = true;
$this->assertNotEmpty( $args[0][1]->foo );
}
/**
* @ticket 9886
*/