diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
index 270770d..7f68c13 100644
|
|
|
1521 | 1521 | settings = $.map( control.params.settings, function( value ) { |
1522 | 1522 | return value; |
1523 | 1523 | }); |
1524 | | api.apply( api, settings.concat( function () { |
1525 | | var key; |
1526 | 1524 | |
1527 | | control.settings = {}; |
1528 | | for ( key in control.params.settings ) { |
1529 | | control.settings[ key ] = api( control.params.settings[ key ] ); |
1530 | | } |
| 1525 | if ( 0 === settings.length ) { |
| 1526 | control.embed(); |
| 1527 | } else { |
| 1528 | api.apply( api, settings.concat( function() { |
| 1529 | var key; |
1531 | 1530 | |
1532 | | control.setting = control.settings['default'] || null; |
| 1531 | control.settings = {}; |
| 1532 | for ( key in control.params.settings ) { |
| 1533 | control.settings[ key ] = api( control.params.settings[ key ] ); |
| 1534 | } |
1533 | 1535 | |
1534 | | control.embed(); |
1535 | | }) ); |
| 1536 | control.setting = control.settings['default'] || null; |
| 1537 | |
| 1538 | control.embed(); |
| 1539 | }) ); |
| 1540 | } |
1536 | 1541 | |
1537 | 1542 | // After the control is embedded on the page, invoke the "ready" method. |
1538 | 1543 | control.deferred.embedded.done( function () { |
diff --git src/wp-includes/class-wp-customize-control.php src/wp-includes/class-wp-customize-control.php
index a892b10..59b4a8c 100644
|
|
class WP_Customize_Control { |
65 | 65 | public $setting = 'default'; |
66 | 66 | |
67 | 67 | /** |
| 68 | * Capability required to use this control. |
| 69 | * |
| 70 | * Normally this is empty and the capability is derived from the capabilities |
| 71 | * of the associated `$settings`. |
| 72 | * |
| 73 | * @since 4.5.0 |
| 74 | * @access public |
| 75 | * @var string |
| 76 | */ |
| 77 | public $capability; |
| 78 | |
| 79 | /** |
68 | 80 | * @access public |
69 | 81 | * @var int |
70 | 82 | */ |
… |
… |
class WP_Customize_Control { |
187 | 199 | $this->instance_number = self::$instance_count; |
188 | 200 | |
189 | 201 | // Process settings. |
190 | | if ( empty( $this->settings ) ) { |
| 202 | if ( ! isset( $this->settings ) ) { |
191 | 203 | $this->settings = $id; |
192 | 204 | } |
193 | 205 | |
… |
… |
class WP_Customize_Control { |
196 | 208 | foreach ( $this->settings as $key => $setting ) { |
197 | 209 | $settings[ $key ] = $this->manager->get_setting( $setting ); |
198 | 210 | } |
199 | | } else { |
| 211 | } else if ( is_string( $this->settings ) ) { |
200 | 212 | $this->setting = $this->manager->get_setting( $this->settings ); |
201 | 213 | $settings['default'] = $this->setting; |
202 | 214 | } |
… |
… |
class WP_Customize_Control { |
306 | 318 | * @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true. |
307 | 319 | */ |
308 | 320 | final public function check_capabilities() { |
| 321 | if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) { |
| 322 | return false; |
| 323 | } |
| 324 | |
309 | 325 | foreach ( $this->settings as $setting ) { |
310 | | if ( ! $setting->check_capabilities() ) |
| 326 | if ( ! $setting->check_capabilities() ) { |
311 | 327 | return false; |
| 328 | } |
312 | 329 | } |
313 | 330 | |
314 | 331 | $section = $this->manager->get_section( $this->section ); |
315 | | if ( isset( $section ) && ! $section->check_capabilities() ) |
| 332 | if ( isset( $section ) && ! $section->check_capabilities() ) { |
316 | 333 | return false; |
| 334 | } |
317 | 335 | |
318 | 336 | return true; |
319 | 337 | } |
diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php
index b4bd0fd..b0318d6 100644
|
|
final class WP_Customize_Nav_Menus { |
596 | 596 | 'priority' => 999, |
597 | 597 | ) ) ); |
598 | 598 | |
599 | | $this->manager->add_setting( 'new_menu_name', array( |
600 | | 'type' => 'new_menu', |
601 | | 'default' => '', |
602 | | 'transport' => isset( $this->manager->selective_refresh ) ? 'postMessage' : 'refresh', |
603 | | ) ); |
604 | | |
605 | 599 | $this->manager->add_control( 'new_menu_name', array( |
606 | 600 | 'label' => '', |
607 | 601 | 'section' => 'add_menu', |
608 | 602 | 'type' => 'text', |
| 603 | 'settings' => array(), |
609 | 604 | 'input_attrs' => array( |
610 | 605 | 'class' => 'menu-name-field', |
611 | 606 | 'placeholder' => __( 'New menu name' ), |
612 | 607 | ), |
613 | 608 | ) ); |
614 | 609 | |
615 | | $this->manager->add_setting( 'create_new_menu', array( |
616 | | 'type' => 'new_menu', |
617 | | ) ); |
618 | | |
619 | 610 | $this->manager->add_control( new WP_Customize_New_Menu_Control( $this->manager, 'create_new_menu', array( |
620 | | 'section' => 'add_menu', |
| 611 | 'section' => 'add_menu', |
| 612 | 'settings' => array(), |
621 | 613 | ) ) ); |
622 | 614 | } |
623 | 615 | |
… |
… |
final class WP_Customize_Nav_Menus { |
841 | 833 | 'type' => 'nav_menu_instance', |
842 | 834 | 'render_callback' => array( $this, 'render_nav_menu_partial' ), |
843 | 835 | 'container_inclusive' => true, |
| 836 | 'settings' => array(), // Empty because the nav menu instance may relate to a menu or a location. |
| 837 | 'capability' => 'edit_theme_options', |
844 | 838 | ) |
845 | 839 | ); |
846 | 840 | } |
diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php
index f65e7bf..69cfcc1 100644
|
|
final class WP_Customize_Widgets { |
1485 | 1485 | */ |
1486 | 1486 | public function customize_dynamic_partial_args( $partial_args, $partial_id ) { |
1487 | 1487 | |
1488 | | if ( preg_match( '/^widget\[.+\]$/', $partial_id ) ) { |
| 1488 | if ( preg_match( '/^widget\[(?P<widget_id>.+)\]$/', $partial_id, $matches ) ) { |
1489 | 1489 | if ( false === $partial_args ) { |
1490 | 1490 | $partial_args = array(); |
1491 | 1491 | } |
1492 | 1492 | $partial_args = array_merge( |
1493 | 1493 | $partial_args, |
1494 | 1494 | array( |
1495 | | 'type' => 'widget', |
1496 | | 'render_callback' => array( $this, 'render_widget_partial' ), |
| 1495 | 'type' => 'widget', |
| 1496 | 'render_callback' => array( $this, 'render_widget_partial' ), |
1497 | 1497 | 'container_inclusive' => true, |
| 1498 | 'settings' => array( $this->get_setting_id( $matches['widget_id'] ) ), |
| 1499 | 'capability' => 'edit_theme_options', |
1498 | 1500 | ) |
1499 | 1501 | ); |
1500 | 1502 | } |
diff --git src/wp-includes/customize/class-wp-customize-partial.php src/wp-includes/customize/class-wp-customize-partial.php
index 3cb410b..c27b3f0 100644
|
|
class WP_Customize_Partial { |
90 | 90 | public $primary_setting; |
91 | 91 | |
92 | 92 | /** |
| 93 | * Capability required to edit this partial. |
| 94 | * |
| 95 | * Normally this is empty and the capability is derived from the capabilities |
| 96 | * of the associated `$settings`. |
| 97 | * |
| 98 | * @since 4.5.0 |
| 99 | * @access public |
| 100 | * @var string |
| 101 | */ |
| 102 | public $capability; |
| 103 | |
| 104 | /** |
93 | 105 | * Render callback. |
94 | 106 | * |
95 | 107 | * @since 4.5.0 |
… |
… |
class WP_Customize_Partial { |
157 | 169 | } |
158 | 170 | |
159 | 171 | // Process settings. |
160 | | if ( empty( $this->settings ) ) { |
| 172 | if ( ! isset( $this->settings ) ) { |
161 | 173 | $this->settings = array( $id ); |
162 | 174 | } else if ( is_string( $this->settings ) ) { |
163 | 175 | $this->settings = array( $this->settings ); |
… |
… |
class WP_Customize_Partial { |
299 | 311 | * or if one of the associated settings does not exist. |
300 | 312 | */ |
301 | 313 | final public function check_capabilities() { |
| 314 | if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) { |
| 315 | return false; |
| 316 | } |
302 | 317 | foreach ( $this->settings as $setting_id ) { |
303 | 318 | $setting = $this->component->manager->get_setting( $setting_id ); |
304 | 319 | if ( ! $setting || ! $setting->check_capabilities() ) { |
diff --git tests/qunit/fixtures/customize-menus.js tests/qunit/fixtures/customize-menus.js
index 5fdd892..f3ac0a1 100755
|
|
window._wpCustomizeSettings.controls.new_menu_name = { |
394 | 394 | 'description': '', |
395 | 395 | 'instanceNumber': 46 |
396 | 396 | }; |
397 | | window._wpCustomizeSettings.settings.new_menu_name = { |
398 | | 'value': '', |
399 | | 'transport': 'postMessage', |
400 | | 'dirty': false |
401 | | }; |
402 | 397 | |
403 | 398 | // From nav-menu.js |
404 | 399 | window.wpNavMenu = { |