Hi @guido07111975 ,
The default priority is defined here:
https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-customize-control.php
public $priority = 10;
prepare_controls() in file below only sorts the controls by priority:
https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-customize-manager.php
If your custom control appears under the default value, set an explicit priority, for example:
'priority' => 5
Lower numbers appear first.
I haven’t debugged this in detail yet, but I suspect it has to do with https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-customize-manager.php#L4431. That’s where the specified priority is compared. If a priority is specified (which is the case for all of them with the default value of 10), the comparison is based on the instance number. And that, in turn, corresponds to the order in which the controls were added. See: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-customize-control.php#L34
So, to move your controls higher in the order, you’ll need to either add your controls before the others or work with priorities.
Thread Starter
Guido
(@guido07111975)
Thank you both!
So it looks like my custom settings (with no priority set) all have the default priority 10.
While loading all settings, the native ones (with same or lower priority) are displayed first, and any custom ones (that have the same priority) are displayed next (so underneath). Right?
As mentioned, if no priority is specified, it depends on the order in which they are included.
Thread Starter
Guido
(@guido07111975)
Yes, but it seems that if native settings and custom settings both have priority 10 (or no priority), the native settings are displayed first and the custom settings second.
Yes, because, as I said, they are registered before your controllers.
Thread Starter
Guido
(@guido07111975)
I don’t know if it’s just me (cache?) but when omiting both functions from file class-wp-customize-manager.php, the settings order in my Customizer does not change. And I can still use a priority to move my custom settings up/down. So there must be another file that takes care of the settings order as well.
protected function _cmp_priority( $a, $b ) {
return;
}
public function prepare_controls() {
return;
}
Thread Starter
Guido
(@guido07111975)
Main question for creating this topic is that I wanted to know where is determined that custom fields are loaded after native fields. Just found out this has something to do with customize_register.
For testing purposes I added a priority to the action, while registering my custom fields. This lets me display my custom fields (that have no or default priority 10) before or after the native fields. This will display them before the native fields:
add_action( 'customize_register', 'my_custom_fields', 9 );
I will look into customize_register further. Marking this topic “resolved”.
Guido