WordPress.org

Make WordPress Core

Ticket #20920: 20920.2.diff

File 20920.2.diff, 1.4 KB (added by boonebgorges, 5 years ago)
  • src/wp-includes/plugin.php

    diff --git src/wp-includes/plugin.php src/wp-includes/plugin.php
    index 27a65ee..06d727f 100644
    function remove_all_filters( $tag, $priority = false ) { 
    325325        global $wp_filter, $merged_filters;
    326326
    327327        if ( isset( $wp_filter[ $tag ]) ) {
    328                 if ( false !== $priority && isset( $wp_filter[ $tag ][ $priority ] ) ) {
    329                         $wp_filter[ $tag ][ $priority ] = array();
    330                 } else {
     328                if ( false === $priority ) {
    331329                        $wp_filter[ $tag ] = array();
     330                } else if ( isset( $wp_filter[ $tag ][ $priority ] ) ) {
     331                        $wp_filter[ $tag ][ $priority ] = array();
    332332                }
    333333        }
    334334
  • tests/phpunit/tests/filters.php

    diff --git tests/phpunit/tests/filters.php tests/phpunit/tests/filters.php
    index c0eb125..d9eda55 100644
    class Tests_Filters extends WP_UnitTestCase { 
    197197        }
    198198
    199199        /**
     200         * @ticket 20920
     201         */
     202        function test_remove_all_filters_should_respect_the_priority_argument() {
     203                $a = new MockAction();
     204                $tag = rand_str();
     205                $val = rand_str();
     206
     207                add_filter( $tag, array( $a, 'filter' ), 12 );
     208                $this->assertTrue( has_filter( $tag ) );
     209
     210                // Should not be removed.
     211                remove_all_filters( $tag, 11 );
     212                $this->assertTrue( has_filter( $tag ) );
     213
     214                remove_all_filters( $tag, 12 );
     215                $this->assertFalse( has_filter( $tag ) );
     216        }
     217
     218        /**
    200219         * @ticket 9886
    201220         */
    202221        function test_filter_ref_array() {