Make WordPress Core

Ticket #30875: 30875.4.diff

File 30875.4.diff, 3.2 KB (added by valendesigns, 10 years ago)

Oops, last one. It's late. I had a typo.

  • src/wp-includes/plugin.php

    diff --git src/wp-includes/plugin.php src/wp-includes/plugin.php
    index 06d727f..4001286 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        // Don't allow string values
     85        if ( ! is_numeric( $priority ) ) {
     86                $priority = 10;
     87        }
     88
     89        // Cast to float and round
     90        $priority = round ( (float) $priority );
     91
     92        $idx = _wp_filter_build_unique_id( $tag, $function_to_add, $priority );
     93        $wp_filter[$tag][$priority][$idx] = array( 'function' => $function_to_add, 'accepted_args' => $accepted_args );
    8694        unset( $merged_filters[ $tag ] );
    8795        return true;
    8896}
  • tests/phpunit/tests/actions.php

    diff --git tests/phpunit/tests/actions.php tests/phpunit/tests/actions.php
    index 583c8ce..2747952 100644
    class Tests_Actions extends WP_UnitTestCase { 
    143143                $this->assertEquals($expected, $a->get_events());
    144144        }
    145145
     146        /**
     147         * @ticket 30875
     148         */
     149        function test_action_priority_is_valid() {
     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, 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( 10, has_action( '_test_string', array( &$a, 'action' ) ) );
     176
     177                // Test boolean
     178                add_action( '_test_bool', array( &$a, 'action' ), true );
     179                do_action( '_test_bool' );
     180                $this->assertEquals( 10, has_action( '_test_bool', array( &$a, 'action' ) ) );
     181
     182                // Test boolean as string
     183                add_action( '_test_bool_as_string', array( &$a, 'action' ), 'true' );
     184                do_action( '_test_bool_as_string' );
     185                $this->assertEquals( 10, has_action( '_test_bool_as_string', array( &$a, 'action' ) ) );
     186               
     187                // Test array
     188                add_action( '_test_array', array( &$a, 'action' ), array() );
     189                do_action( '_test_array' );
     190                $this->assertEquals( 10, has_action( '_test_array', array( &$a, 'action' ) ) );
     191               
     192                // Test object
     193                add_action( '_test_oject', array( &$a, 'action' ), new stdClass() );
     194                do_action( '_test_oject' );
     195                $this->assertEquals( 10, has_action( '_test_oject', array( &$a, 'action' ) ) );
     196        }
     197
    146198        function test_did_action() {
    147199                $tag1 = rand_str();
    148200                $tag2 = rand_str();