Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#30225 closed defect (bug) (fixed)

Customizer panels/sections/controls with equal priorities do not sort in order of addition

Reported by: westonruter's profile westonruter Owned by: ocean90's profile ocean90
Milestone: 4.1 Priority: normal
Severity: normal Version: 4.1
Component: Customize Keywords: has-patch
Focuses: javascript Cc:


The blogname, blogdescription, and display_header_text controls get added with the same priority of 10, but they are expected to be rendered in the order of creation. This has historically been the case, but with the move to a JS-rendered Customizer pane (#28709), the sort order is no longer reliable since Array.sort is not stable in many browsers, and so sorting two controls with the same priority results in an undefined order once the sort is complete. The situation is the same for panels and sections: their order is not consistent across browsers if identical priorities are used.

In the past, identical priorities were addressed in PHP with logic like this in WP_Customize_Manager::prepare_controls():

// Prepare sections.
// Reversing makes uasort sort by time added when conflicts occur.
$this->sections = array_reverse( $this->sections );
uasort( $this->sections, array( $this, '_cmp_priority' ) );

This, however, does not help on the JS side of things. Sort stability needs to be implemented in JS.

Attachments (1)

30225.diff (9.2 KB) - added by westonruter 10 years ago.

Download all attachments as: .zip

Change History (5)

#1 @westonruter
10 years ago

  • Keywords has-patch added
  • Owner set to ocean90
  • Status changed from new to reviewing
  • Summary changed from Customizer controls with same priorities do not sort in order of addition to Customizer panels/sections/controls with equal priorities do not sort in order of addition

30225.diff adds stable sorting for panels, sections, controls in JS and improves in PHP. Panel, Section, and Control classes get a new static protected variable $instance_count, and when new instances are created this is incremented and the value is stored in an instance's $instance_number. This value is then used to sort the objects when their priorities are equal, thus resulting in a stable sort.

Last edited 10 years ago by westonruter (previous) (diff)

#2 @ocean90
10 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 30214:

Customizer: Add stable sorting for panels, sections and controls in JS. Improve sorting in PHP.

props westonruter.
fixes #30225.

#3 @ocean90
10 years ago

#20733 was marked as a duplicate.

#4 @westonruter
9 years ago

See fixed typo in #34594.

Note: See TracTickets for help on using tickets.