From f71821dc05c971bd389f2aca17782b3f05ce95e8 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 31 Dec 2014 19:06:29 +0000 Subject: [PATCH] In `remove_all_filters()`, only remove callbacks that match the `$priority` parameter. Props GeertDD, valendesigns. Fixes #20920. git-svn-id: https://develop.svn.wordpress.org/trunk@31014 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/plugin.php | 6 +++--- tests/phpunit/tests/filters.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index 27a65ee1b5..06d727f313 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -325,10 +325,10 @@ function remove_all_filters( $tag, $priority = false ) { global $wp_filter, $merged_filters; if ( isset( $wp_filter[ $tag ]) ) { - if ( false !== $priority && isset( $wp_filter[ $tag ][ $priority ] ) ) { - $wp_filter[ $tag ][ $priority ] = array(); - } else { + if ( false === $priority ) { $wp_filter[ $tag ] = array(); + } else if ( isset( $wp_filter[ $tag ][ $priority ] ) ) { + $wp_filter[ $tag ][ $priority ] = array(); } } diff --git a/tests/phpunit/tests/filters.php b/tests/phpunit/tests/filters.php index c0eb1250c7..d9eda55a2b 100644 --- a/tests/phpunit/tests/filters.php +++ b/tests/phpunit/tests/filters.php @@ -196,6 +196,25 @@ class Tests_Filters extends WP_UnitTestCase { $this->assertEquals(array($tag), $a->get_tags()); } + /** + * @ticket 20920 + */ + function test_remove_all_filters_should_respect_the_priority_argument() { + $a = new MockAction(); + $tag = rand_str(); + $val = rand_str(); + + add_filter( $tag, array( $a, 'filter' ), 12 ); + $this->assertTrue( has_filter( $tag ) ); + + // Should not be removed. + remove_all_filters( $tag, 11 ); + $this->assertTrue( has_filter( $tag ) ); + + remove_all_filters( $tag, 12 ); + $this->assertFalse( has_filter( $tag ) ); + } + /** * @ticket 9886 */