Make WordPress Core

Changeset 35553


Ignore:
Timestamp:
11/06/2015 06:57:53 AM (11 years ago)
Author:
westonruter
Message:

Customize: Fix typo in WP_Customize_Manager::_cmp_priority() which caused unstable sorting for same-priority constructs in PHP.

The issue, however, does not manifest in the UI because the UI is now built via JS and the wp.customize.utils.prioritySort() algorithm did not have the same typo.

Props bordoni, westonruter.
Fixes #34594.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r35534 r35553  
    13031303        protected function _cmp_priority( $a, $b ) {
    13041304                if ( $a->priority === $b->priority ) {
    1305                         return $a->instance_number - $a->instance_number;
     1305                        return $a->instance_number - $b->instance_number;
    13061306                } else {
    13071307                        return $a->priority - $b->priority;
  • trunk/tests/phpunit/tests/customize/manager.php

    r35483 r35553  
    398398                return array( 'nav_menus' );
    399399        }
     400
     401        /**
     402         * @ticket 30225
     403         * @ticket 34594
     404         */
     405        function test_prepare_controls_stable_sorting() {
     406                $manager = new WP_Customize_Manager();
     407                $manager->register_controls();
     408                $section_id = 'foo-section';
     409                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     410                $manager->add_section( $section_id, array(
     411                        'title'      => 'Section',
     412                        'priority'   => 1,
     413                ) );
     414
     415                $added_control_ids = array();
     416                $count = 9;
     417                for ( $i = 0; $i < $count; $i += 1 ) {
     418                        $id = 'sort-test-' . $i;
     419                        $added_control_ids[] = $id;
     420                        $manager->add_setting( $id );
     421                        $control = new WP_Customize_Control( $manager, $id, array(
     422                                'section' => $section_id,
     423                                'priority' => 1,
     424                                'setting' => $id,
     425                        ) );
     426                        $manager->add_control( $control );
     427                }
     428
     429                $manager->prepare_controls();
     430
     431                $sorted_control_ids = wp_list_pluck( $manager->get_section( $section_id )->controls, 'id' );
     432                $this->assertEquals( $added_control_ids, $sorted_control_ids );
     433        }
    400434}
Note: See TracChangeset for help on using the changeset viewer.