Changeset 20248
- Timestamp:
- 03/21/2012 10:55:43 PM (13 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-customize-section.php
r20232 r20248 9 9 10 10 class WP_Customize_Section { 11 public $manager; 11 12 public $id; 12 13 public $priority = 10; … … 25 26 * @param array $args Section arguments. 26 27 */ 27 function __construct( $id, $args = array() ) { 28 $this->id = $id; 29 28 function __construct( $manager, $id, $args = array() ) { 30 29 $keys = array_keys( get_class_vars( __CLASS__ ) ); 31 30 foreach ( $keys as $key ) { … … 33 32 $this->$key = $args[ $key ]; 34 33 } 34 35 $this->manager = $manager; 36 $this->id = $id; 35 37 36 38 $this->settings = array(); // Users cannot customize the $settings array. … … 46 48 * @return bool False if theme doesn't support the section or user doesn't have the capability. 47 49 */ 48 function check_capabilities() {50 public final function check_capabilities() { 49 51 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) 50 52 return false; … … 57 59 58 60 /** 61 * Check capabiliites and render the section. 62 * 63 * @since 3.4.0 64 */ 65 public final function maybe_render() { 66 if ( ! $this->check_capabilities() ) 67 return; 68 69 do_action( 'customize_render_section', $this ); 70 do_action( 'customize_render_section_' . $this->id ); 71 72 $this->render(); 73 } 74 75 76 /** 59 77 * Render the section. 60 78 * 61 79 * @since 3.4.0 62 80 */ 63 function render() { 64 if ( ! $this->check_capabilities() ) 65 return; 81 protected function render() { 66 82 ?> 67 83 <li id="customize-section-<?php echo esc_attr( $this->id ); ?>" class="control-section customize-section"> … … 70 86 <?php foreach ( $this->settings as $setting ) : ?> 71 87 <li id="customize-control-<?php echo esc_attr( $setting->id ); ?>" class="customize-control customize-control-<?php echo esc_attr( $setting->control ); ?>"> 72 <?php $setting-> _render(); ?>88 <?php $setting->maybe_render(); ?> 73 89 </li> 74 90 <?php endforeach; ?> -
trunk/wp-includes/class-wp-customize-setting.php
r20232 r20248 9 9 10 10 class WP_Customize_Setting { 11 public $manager; 11 12 public $id; 12 13 public $priority = 10; … … 36 37 * @param array $args Setting arguments. 37 38 */ 38 function __construct( $ id, $args = array() ) {39 function __construct( $manager, $id, $args = array() ) { 39 40 $keys = array_keys( get_class_vars( __CLASS__ ) ); 40 41 foreach ( $keys as $key ) { … … 43 44 } 44 45 46 $this->manager = $manager; 45 47 $this->id = $id; 46 48 … … 266 268 */ 267 269 public final function check_capabilities() { 268 global $customize;269 270 270 if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) 271 271 return false; … … 274 274 return false; 275 275 276 $section = $ customize->get_section( $this->section );276 $section = $this->manager->get_section( $this->section ); 277 277 if ( isset( $section ) && ! $section->check_capabilities() ) 278 278 return false; … … 282 282 283 283 /** 284 * Render the control.285 * 286 * @since 3.4.0 287 */ 288 public final function _render() {284 * Check capabiliites and render the control. 285 * 286 * @since 3.4.0 287 */ 288 public final function maybe_render() { 289 289 if ( ! $this->check_capabilities() ) 290 290 return; 291 291 292 do_action( 'customize_render_' . $this->id ); 292 do_action( 'customize_render_setting', $this ); 293 do_action( 'customize_render_setting_' . $this->id, $this ); 293 294 294 295 $this->render(); … … 301 302 */ 302 303 protected function render() { 303 $this->_render_type();304 }305 306 /**307 * Retrieve the name attribute for an input.308 *309 * @since 3.4.0310 *311 * @return string The name.312 */313 public final function get_name() {314 return self::name_prefix . esc_attr( $this->id );315 }316 317 /**318 * Echo the HTML name attribute for an input.319 *320 * @since 3.4.0321 *322 * @return string The HTML name attribute.323 */324 public final function name() {325 echo 'name="' . $this->get_name() . '"';326 }327 328 /**329 * Render the control type.330 *331 * @todo Improve value and checked attributes.332 *333 * @since 3.4.0334 */335 public final function _render_type() {336 304 switch( $this->control ) { 337 305 case 'text': … … 415 383 <?php 416 384 break; 417 default: 418 do_action( 'customize_render_control-' . $this->control, $this ); 419 420 } 385 } 386 } 387 388 /** 389 * Retrieve the name attribute for an input. 390 * 391 * @since 3.4.0 392 * 393 * @return string The name. 394 */ 395 public final function get_name() { 396 return self::name_prefix . esc_attr( $this->id ); 397 } 398 399 /** 400 * Echo the HTML name attribute for an input. 401 * 402 * @since 3.4.0 403 * 404 * @return string The HTML name attribute. 405 */ 406 public final function name() { 407 echo 'name="' . $this->get_name() . '"'; 421 408 } 422 409 -
trunk/wp-includes/class-wp-customize.php
r20212 r20248 30 30 add_action( 'admin_footer', array( $this, 'admin_footer' ) ); 31 31 32 add_action( 'customize_previewing', array( $this, 'customize_previewing' ) ); 33 add_action( 'customize_register', array( $this, 'register_controls' ) ); 34 add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) ); 32 add_action( 'customize_previewing', array( $this, 'customize_previewing' ) ); 33 add_action( 'customize_register', array( $this, 'register_controls' ) ); 34 add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) ); 35 add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) ); 35 36 } 36 37 … … 103 104 do_action( 'customize_register' ); 104 105 105 if ( ! $this->is_preview() ) 106 return; 106 if ( $this->is_preview() ) 107 add_action( 'template_redirect', array( $this, 'customize_preview_init' ) ); 108 } 109 110 /** 111 * Print javascript settings. 112 * 113 * @since 3.4.0 114 */ 115 public function customize_preview_init() { 116 $this->prepare_controls(); 107 117 108 118 wp_enqueue_script( 'customize-preview' ); … … 112 122 $setting->preview(); 113 123 } 114 } 124 125 do_action( 'customize_preview_init' ); 126 } 127 115 128 116 129 /** … … 350 363 */ 351 364 public function add_setting( $id, $args = array() ) { 352 $setting = new WP_Customize_Setting( $ id, $args );365 $setting = new WP_Customize_Setting( $this, $id, $args ); 353 366 354 367 $this->settings[ $setting->id ] = $setting; … … 388 401 */ 389 402 public function add_section( $id, $args = array() ) { 390 $section = new WP_Customize_Section( $ id, $args );403 $section = new WP_Customize_Section( $this, $id, $args ); 391 404 392 405 $this->sections[ $section->id ] = $section; … … 425 438 * @param object $b Object B. 426 439 */ 427 protected f unction _cmp_priority( $a, $b ) {440 protected final function _cmp_priority( $a, $b ) { 428 441 $ap = $a->priority; 429 442 $bp = $b->priority; … … 435 448 436 449 /** 437 * Prepare settings and sections. Also enqueue needed scripts/styles.450 * Prepare settings and sections. 438 451 * 439 452 * @since 3.4.0 440 453 */ 441 454 public function prepare_controls() { 455 // Prepare settings 442 456 // Reversing makes uasort sort by time added when conflicts occur. 443 457 458 $this->settings = array_reverse( $this->settings ); 459 $settings = array(); 460 461 foreach ( $this->settings as $id => $setting ) { 462 if ( ! isset( $this->sections[ $setting->section ] ) || ! $setting->check_capabilities() ) 463 continue; 464 465 $this->sections[ $setting->section ]->settings[] = $setting; 466 $settings[ $id ] = $setting; 467 } 468 $this->settings = $settings; 469 470 // Prepare sections 444 471 $this->sections = array_reverse( $this->sections ); 445 472 uasort( $this->sections, array( $this, '_cmp_priority' ) ); 446 447 $this->settings = array_reverse( $this->settings ); 473 $sections = array(); 474 475 foreach ( $this->sections as $section ) { 476 if ( ! $section->check_capabilities() ) 477 continue; 478 479 usort( $section->settings, array( $this, '_cmp_priority' ) ); 480 $sections[] = $section; 481 } 482 $this->sections = $sections; 483 } 484 485 /** 486 * Enqueue scripts for customize controls. 487 * 488 * @since 3.4.0 489 */ 490 public function enqueue_control_scripts() { 448 491 foreach ( $this->settings as $setting ) { 449 if ( ! isset( $this->sections[ $setting->section ] ) ) 450 continue; 451 452 $this->sections[ $setting->section ]->settings[] = $setting; 453 454 if ( $setting->check_capabilities() ) 455 $setting->enqueue(); 456 } 457 458 foreach ( $this->sections as $section ) { 459 usort( $section->settings, array( $this, '_cmp_priority' ) ); 492 $setting->enqueue(); 460 493 } 461 494 } … … 480 513 'sanitize_callback' => 'sanitize_hexcolor', 481 514 'control' => 'color', 515 'theme_supports' => array( 'custom-header', 'header-text' ), 482 516 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 483 517 ) ); -
trunk/wp-includes/customize-controls.php
r20133 r20248 75 75 <?php 76 76 foreach ( $this->sections as $section ) 77 $section-> render();77 $section->maybe_render(); 78 78 ?> 79 79 </ul></div>
Note: See TracChangeset
for help on using the changeset viewer.