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.


git-svn-id: https://develop.svn.wordpress.org/trunk@35553 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2015-11-06 06:57:53 +00:00
parent 251915c11f
commit 22135794a2
2 changed files with 35 additions and 1 deletions

View File

@ -1302,7 +1302,7 @@ final class WP_Customize_Manager {
*/
protected function _cmp_priority( $a, $b ) {
if ( $a->priority === $b->priority ) {
return $a->instance_number - $a->instance_number;
return $a->instance_number - $b->instance_number;
} else {
return $a->priority - $b->priority;
}

View File

@ -397,4 +397,38 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertInstanceOf( 'WP_Customize_Manager', $customize_manager );
return array( 'nav_menus' );
}
/**
* @ticket 30225
* @ticket 34594
*/
function test_prepare_controls_stable_sorting() {
$manager = new WP_Customize_Manager();
$manager->register_controls();
$section_id = 'foo-section';
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
$manager->add_section( $section_id, array(
'title' => 'Section',
'priority' => 1,
) );
$added_control_ids = array();
$count = 9;
for ( $i = 0; $i < $count; $i += 1 ) {
$id = 'sort-test-' . $i;
$added_control_ids[] = $id;
$manager->add_setting( $id );
$control = new WP_Customize_Control( $manager, $id, array(
'section' => $section_id,
'priority' => 1,
'setting' => $id,
) );
$manager->add_control( $control );
}
$manager->prepare_controls();
$sorted_control_ids = wp_list_pluck( $manager->get_section( $section_id )->controls, 'id' );
$this->assertEquals( $added_control_ids, $sorted_control_ids );
}
}