Make WordPress Core

Ticket #30875: 30875.5.diff

File 30875.5.diff, 3.4 KB (added by valendesigns, 10 years ago)
  • src/wp-includes/plugin.php

    diff --git src/wp-includes/plugin.php src/wp-includes/plugin.php
    index 06d727f..b31090f 100644
    if ( ! isset( $wp_current_filter ) ) 
    8181function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
    8282        global $wp_filter, $merged_filters;
    8383
    84         $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
    85         $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
     84        if ( is_array( $priority ) || is_object( $priority ) ) {
     85                return false;
     86        }
     87
     88        $idx = _wp_filter_build_unique_id( $tag, $function_to_add, $priority );
     89        $wp_filter[$tag][$priority][$idx] = array( 'function' => $function_to_add, 'accepted_args' => $accepted_args );
    8690        unset( $merged_filters[ $tag ] );
    8791        return true;
    8892}
  • tests/phpunit/tests/actions.php

    diff --git tests/phpunit/tests/actions.php tests/phpunit/tests/actions.php
    index 583c8ce..2e0da94 100644
    class Tests_Actions extends WP_UnitTestCase { 
    143143                $this->assertEquals($expected, $a->get_events());
    144144        }
    145145
     146        /**
     147         * @ticket 30875
     148         */
     149        function test_add_filter_priority_value() {
     150                $a = new MockAction();
     151
     152                // Test integers
     153                add_action( '_test_int', array( &$a, 'action' ), 10 );
     154                do_action( '_test_int' );
     155                $this->assertEquals( 10, has_action( '_test_int', array( &$a, 'action' ) ) );
     156
     157                // Test integer as string
     158                add_action( '_test_int_as_string', array( &$a, 'action' ), '9' );
     159                do_action( '_test_int_as_string' );
     160                $this->assertEquals( 9, has_action( '_test_int_as_string', array( &$a, 'action' ) ) );
     161
     162                // Test float
     163                add_action( '_test_float', array( &$a, 'action' ), 8.1 );
     164                do_action( '_test_float' );
     165                $this->assertEquals( 8, has_action( '_test_float', array( &$a, 'action' ) ) );
     166
     167                // Test float as string
     168                add_action( '_test_float_as_string', array( &$a, 'action' ), '7.2' );
     169                do_action( '_test_float_as_string' );
     170                $this->assertEquals( '7.2', has_action( '_test_float_as_string', array( &$a, 'action' ) ) );
     171
     172                // Test string
     173                add_action( '_test_string', array( &$a, 'action' ), 'micky' );
     174                do_action( '_test_string' );
     175                $this->assertEquals( 'micky', has_action( '_test_string', array( &$a, 'action' ) ) );
     176
     177                // Test boolean true
     178                add_action( '_test_bool_true', array( &$a, 'action' ), true );
     179                do_action( '_test_bool_true' );
     180                $this->assertEquals( 1, has_action( '_test_bool_true', array( &$a, 'action' ) ) );
     181               
     182                // Test boolean false
     183                add_action( '_test_bool_false', array( &$a, 'action' ), false );
     184                do_action( '_test_bool_false' );
     185                $this->assertEquals( 0, has_action( '_test_bool_false', array( &$a, 'action' ) ) );
     186
     187                // Test boolean as string
     188                add_action( '_test_bool_as_string', array( &$a, 'action' ), 'true' );
     189                do_action( '_test_bool_as_string' );
     190                $this->assertEquals( 'true', has_action( '_test_bool_as_string', array( &$a, 'action' ) ) );
     191               
     192                // Test array
     193                add_action( '_test_array', array( &$a, 'action' ), array() );
     194                do_action( '_test_array' );
     195                $this->assertEquals( false, has_action( '_test_array', array( &$a, 'action' ) ) );
     196               
     197                // Test object
     198                add_action( '_test_object', array( &$a, 'action' ), new stdClass() );
     199                do_action( '_test_object' );
     200                $this->assertEquals( false, has_action( '_test_object', array( &$a, 'action' ) ) );
     201        }
     202
    146203        function test_did_action() {
    147204                $tag1 = rand_str();
    148205                $tag2 = rand_str();