Changeset 36689
- Timestamp:
- 02/24/2016 06:27:45 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-controls.js
r36586 r36689 1522 1522 return value; 1523 1523 }); 1524 api.apply( api, settings.concat( function () { 1525 var key;1526 1524 1525 if ( 0 === settings.length ) { 1526 control.setting = null; 1527 1527 control.settings = {}; 1528 for ( key in control.params.settings ) {1529 control.settings[ key ] = api( control.params.settings[ key ] );1530 }1531 1532 control.setting = control.settings['default'] || null;1533 1534 1528 control.embed(); 1535 }) ); 1529 } else { 1530 api.apply( api, settings.concat( function() { 1531 var key; 1532 1533 control.settings = {}; 1534 for ( key in control.params.settings ) { 1535 control.settings[ key ] = api( control.params.settings[ key ] ); 1536 } 1537 1538 control.setting = control.settings['default'] || null; 1539 1540 control.embed(); 1541 }) ); 1542 } 1536 1543 1537 1544 // After the control is embedded on the page, invoke the "ready" method. -
trunk/src/wp-includes/class-wp-customize-control.php
r36114 r36689 64 64 */ 65 65 public $setting = 'default'; 66 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; 66 78 67 79 /** … … 188 200 189 201 // Process settings. 190 if ( empty( $this->settings ) ) {202 if ( ! isset( $this->settings ) ) { 191 203 $this->settings = $id; 192 204 } … … 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; … … 300 312 301 313 /** 302 * Check if the theme supports the control and check user capabilities. 314 * Checks if the user can use this control. 315 * 316 * Returns false if the user cannot manipulate one of the associated settings, 317 * or if one of the associated settings does not exist. Also returns false if 318 * the associated section does not exist or if its capability check returns 319 * false. 303 320 * 304 321 * @since 3.4.0 … … 307 324 */ 308 325 final public function check_capabilities() { 326 if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) { 327 return false; 328 } 329 309 330 foreach ( $this->settings as $setting ) { 310 if ( ! $setting ->check_capabilities() )331 if ( ! $setting || ! $setting->check_capabilities() ) { 311 332 return false; 333 } 312 334 } 313 335 314 336 $section = $this->manager->get_section( $this->section ); 315 if ( isset( $section ) && ! $section->check_capabilities() ) 337 if ( isset( $section ) && ! $section->check_capabilities() ) { 316 338 return false; 339 } 317 340 318 341 return true; -
trunk/src/wp-includes/class-wp-customize-nav-menus.php
r36676 r36689 607 607 ) ) ); 608 608 609 $this->manager->add_setting( 'new_menu_name', array(610 'type' => 'new_menu',611 'default' => '',612 'transport' => isset( $this->manager->selective_refresh ) ? 'postMessage' : 'refresh',613 ) );614 615 609 $this->manager->add_control( 'new_menu_name', array( 616 610 'label' => '', 617 611 'section' => 'add_menu', 618 612 'type' => 'text', 613 'settings' => array(), 619 614 'input_attrs' => array( 620 615 'class' => 'menu-name-field', … … 623 618 ) ); 624 619 625 $this->manager->add_setting( 'create_new_menu', array(626 'type' => 'new_menu',627 ) );628 629 620 $this->manager->add_control( new WP_Customize_New_Menu_Control( $this->manager, 'create_new_menu', array( 630 'section' => 'add_menu', 621 'section' => 'add_menu', 622 'settings' => array(), 631 623 ) ) ); 632 624 } … … 852 844 'render_callback' => array( $this, 'render_nav_menu_partial' ), 853 845 'container_inclusive' => true, 846 'settings' => array(), // Empty because the nav menu instance may relate to a menu or a location. 847 'capability' => 'edit_theme_options', 854 848 ) 855 849 ); -
trunk/src/wp-includes/class-wp-customize-widgets.php
r36623 r36689 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(); … … 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 ); -
trunk/src/wp-includes/customize/class-wp-customize-partial.php
r36643 r36689 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 * … … 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 ) ) { … … 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 ); -
trunk/tests/phpunit/tests/customize/partial.php
r36643 r36689 326 326 ) ); 327 327 $this->assertFalse( $partial->check_capabilities() ); 328 329 $partial = new WP_Customize_Partial( $this->selective_refresh, 'no_setting', array( 330 'settings' => array(), 331 ) ); 332 $this->assertTrue( $partial->check_capabilities() ); 333 334 $partial = new WP_Customize_Partial( $this->selective_refresh, 'no_setting', array( 335 'settings' => array(), 336 'capability' => 'top_secret_clearance', 337 ) ); 338 $this->assertFalse( $partial->check_capabilities() ); 339 340 $partial = new WP_Customize_Partial( $this->selective_refresh, 'no_setting', array( 341 'settings' => array(), 342 'capability' => 'edit_theme_options', 343 ) ); 344 $this->assertTrue( $partial->check_capabilities() ); 328 345 } 329 346 -
trunk/tests/qunit/fixtures/customize-menus.js
r36586 r36689 395 395 'instanceNumber': 46 396 396 }; 397 window._wpCustomizeSettings.settings.new_menu_name = {398 'value': '',399 'transport': 'postMessage',400 'dirty': false401 };402 397 403 398 // From nav-menu.js -
trunk/tests/qunit/wp-admin/js/customize-controls.js
r36532 r36689 99 99 var control = wp.customize.control( 'fixture-control' ); 100 100 equal( control.section(), 'fixture-section' ); 101 } ); 102 103 module( 'Customizer control without associated settings' ); 104 test( 'Control can be created without settings', function() { 105 var control = new wp.customize.Control( 'settingless', { 106 params: { 107 content: jQuery( '<li class="settingless">Hello World</li>' ), 108 section: 'fixture-section' 109 } 110 } ); 111 wp.customize.control.add( control.id, control ); 112 equal( control.deferred.embedded.state(), 'resolved' ); 113 ok( null === control.setting ); 114 ok( jQuery.isEmptyObject( control.settings ) ); 101 115 } ); 102 116
Note: See TracChangeset
for help on using the changeset viewer.