Make WordPress Core

Ticket #29070: 29070.patch

File 29070.patch, 1.9 KB (added by boonebgorges, 9 years ago)
  • src/wp-includes/plugin.php

    diff --git src/wp-includes/plugin.php src/wp-includes/plugin.php
    index ea5832a..bfa5f9d 100644
    function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 
    107107function has_filter($tag, $function_to_check = false) {
    108108        global $wp_filter;
    109109
    110         $has = !empty($wp_filter[$tag]);
     110        $has = ! empty( $wp_filter[ $tag ] );
     111
     112        // Make sure at least one priority has a filter callback
     113        if ( $has ) {
     114                $exists = false;
     115                foreach ( $wp_filter[ $tag ] as $callbacks ) {
     116                        if ( ! empty( $callbacks ) ) {
     117                                $exists = true;
     118                                break;
     119                        }
     120                }
     121
     122                if ( ! $exists ) {
     123                        $has = false;
     124                }
     125        }
     126
    111127        if ( false === $function_to_check || false == $has )
    112128                return $has;
    113129
  • tests/phpunit/tests/filters.php

    diff --git tests/phpunit/tests/filters.php tests/phpunit/tests/filters.php
    index 0f6d00a..34fdf56 100644
    class Tests_Filters extends WP_UnitTestCase { 
    267267                $this->assertEquals( 1, $b->get_call_count(), 'priority 12 filters should run after priority 10 empties itself and priority 11 runs' );
    268268                $this->assertEquals( $result, $tag . '_append_append', 'priority 11 and 12 filters should run after priority 10 empties itself' );
    269269        }
     270
     271        /**
     272         * @ticket 29070
     273         */
     274        function test_has_filter_after_remove_all_filters() {
     275                $a = new MockAction();
     276                $tag = rand_str();
     277                $val = rand_str();
     278
     279                // No priority
     280                add_filter( $tag, array( $a, 'filter' ), 11 );
     281                add_filter( $tag, array( $a, 'filter' ), 12 );
     282                $this->assertTrue( has_filter( $tag ) );
     283
     284                remove_all_filters( $tag );
     285                $this->assertFalse( has_filter( $tag ) );
     286
     287                // Remove priorities one at a time
     288                add_filter( $tag, array( $a, 'filter' ), 11 );
     289                add_filter( $tag, array( $a, 'filter' ), 12 );
     290                $this->assertTrue( has_filter( $tag ) );
     291
     292                remove_all_filters( $tag, 11 );
     293                remove_all_filters( $tag, 12 );
     294                $this->assertFalse( has_filter( $tag ) );
     295        }
    270296}