Make WordPress Core

Ticket #30875: 30875.2.diff

File 30875.2.diff, 2.4 KB (added by valendesigns, 10 years ago)

I removed an unnecessary check for is_empty that I was using to test with when the function returned false. It doesn't do that anymore so I removed the extra code.

  • 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..31cf18f 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
    146178        function test_did_action() {
    147179                $tag1 = rand_str();
    148180                $tag2 = rand_str();