web/wp-includes/class-wp-customize-control.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Customize
     6  * @subpackage Customize
     7  * @since 3.4.0
     7  * @since 3.4.0
     8  */
     8  */
     9 
       
    10 class WP_Customize_Control {
     9 class WP_Customize_Control {
       
    10 	/**
       
    11 	 * @access public
       
    12 	 * @var WP_Customize_Manager
       
    13 	 */
    11 	public $manager;
    14 	public $manager;
       
    15 
       
    16 	/**
       
    17 	 * @access public
       
    18 	 * @var string
       
    19 	 */
    12 	public $id;
    20 	public $id;
    13 
    21 
    14 	// All settings tied to the control.
    22 	/**
       
    23 	 * All settings tied to the control.
       
    24 	 *
       
    25 	 * @access public
       
    26 	 * @var array
       
    27 	 */
    15 	public $settings;
    28 	public $settings;
    16 
    29 
    17 	// The primary setting for the control (if there is one).
    30 	/**
       
    31 	 * The primary setting for the control (if there is one).
       
    32 	 *
       
    33 	 * @access public
       
    34 	 * @var string
       
    35 	 */
    18 	public $setting = 'default';
    36 	public $setting = 'default';
    19 
    37 
       
    38 	/**
       
    39 	 * @access public
       
    40 	 * @var int
       
    41 	 */
    20 	public $priority          = 10;
    42 	public $priority          = 10;
       
    43 
       
    44 	/**
       
    45 	 * @access public
       
    46 	 * @var string
       
    47 	 */
    21 	public $section           = '';
    48 	public $section           = '';
       
    49 
       
    50 	/**
       
    51 	 * @access public
       
    52 	 * @var string
       
    53 	 */
    22 	public $label             = '';
    54 	public $label             = '';
    23 	// @todo: remove choices
    55 
       
    56 	/**
       
    57 	 * @todo: Remove choices
       
    58 	 *
       
    59 	 * @access public
       
    60 	 * @var array
       
    61 	 */
    24 	public $choices           = array();
    62 	public $choices           = array();
    25 
    63 
       
    64 	/**
       
    65 	 * @access public
       
    66 	 * @var array
       
    67 	 */
    26 	public $json = array();
    68 	public $json = array();
    27 
    69 
       
    70 	/**
       
    71 	 * @access public
       
    72 	 * @var string
       
    73 	 */
    28 	public $type = 'text';
    74 	public $type = 'text';
    29 
    75 
    30 
    76 
    31 	/**
    77 	/**
    32 	 * Constructor.
    78 	 * Constructor.
    33 	 *
    79 	 *
    34 	 * If $args['settings'] is not defined, use the $id as the setting ID.
    80 	 * If $args['settings'] is not defined, use the $id as the setting ID.
    35 	 *
    81 	 *
    36 	 * @since 3.4.0
    82 	 * @since 3.4.0
       
    83 	 *
       
    84 	 * @param WP_Customize_Manager $manager
       
    85 	 * @param string $id
       
    86 	 * @param array $args
    37 	 */
    87 	 */
    38 	function __construct( $manager, $id, $args = array() ) {
    88 	function __construct( $manager, $id, $args = array() ) {
    39 		$keys = array_keys( get_object_vars( $this ) );
    89 		$keys = array_keys( get_object_vars( $this ) );
    40 		foreach ( $keys as $key ) {
    90 		foreach ( $keys as $key ) {
    41 			if ( isset( $args[ $key ] ) )
    91 			if ( isset( $args[ $key ] ) )
    73 	/**
   123 	/**
    74 	 * Fetch a setting's value.
   124 	 * Fetch a setting's value.
    75 	 * Grabs the main setting by default.
   125 	 * Grabs the main setting by default.
    76 	 *
   126 	 *
    77 	 * @since 3.4.0
   127 	 * @since 3.4.0
       
   128 	 *
       
   129 	 * @param string $setting_key
       
   130 	 * @return mixed The requested setting's value, if the setting exists.
    78 	 */
   131 	 */
    79 	public final function value( $setting_key = 'default' ) {
   132 	public final function value( $setting_key = 'default' ) {
    80 		if ( isset( $this->settings[ $setting_key ] ) )
   133 		if ( isset( $this->settings[ $setting_key ] ) )
    81 			return $this->settings[ $setting_key ]->value();
   134 			return $this->settings[ $setting_key ]->value();
    82 	}
   135 	}
   117 
   170 
   118 	/**
   171 	/**
   119 	 * Check capabilities and render the control.
   172 	 * Check capabilities and render the control.
   120 	 *
   173 	 *
   121 	 * @since 3.4.0
   174 	 * @since 3.4.0
       
   175 	 * @uses WP_Customize_Control::render()
   122 	 */
   176 	 */
   123 	public final function maybe_render() {
   177 	public final function maybe_render() {
   124 		if ( ! $this->check_capabilities() )
   178 		if ( ! $this->check_capabilities() )
   125 			return;
   179 			return;
   126 
   180 
   142 		?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>">
   196 		?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>">
   143 			<?php $this->render_content(); ?>
   197 			<?php $this->render_content(); ?>
   144 		</li><?php
   198 		</li><?php
   145 	}
   199 	}
   146 
   200 
       
   201 	/**
       
   202 	 * Get the data link parameter for a setting.
       
   203 	 *
       
   204 	 * @since 3.4.0
       
   205 	 *
       
   206 	 * @param string $setting_key
       
   207 	 * @return string Data link parameter, if $setting_key is a valid setting, empty string otherwise.
       
   208 	 */
   147 	public function get_link( $setting_key = 'default' ) {
   209 	public function get_link( $setting_key = 'default' ) {
   148 		if ( ! isset( $this->settings[ $setting_key ] ) )
   210 		if ( ! isset( $this->settings[ $setting_key ] ) )
   149 			return '';
   211 			return '';
   150 
   212 
   151 		return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
   213 		return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
   152 	}
   214 	}
   153 
   215 
       
   216 	/**
       
   217 	 * Render the data link parameter for a setting
       
   218 	 *
       
   219 	 * @since 3.4.0
       
   220 	 * @uses WP_Customize_Control::get_link()
       
   221 	 *
       
   222 	 * @param string $setting_key
       
   223 	 */
   154 	public function link( $setting_key = 'default' ) {
   224 	public function link( $setting_key = 'default' ) {
   155 		echo $this->get_link( $setting_key );
   225 		echo $this->get_link( $setting_key );
   156 	}
   226 	}
   157 
   227 
   158 	/**
   228 	/**
   236 				break;
   306 				break;
   237 		}
   307 		}
   238 	}
   308 	}
   239 }
   309 }
   240 
   310 
       
   311 /**
       
   312  * Customize Color Control Class
       
   313  *
       
   314  * @package WordPress
       
   315  * @subpackage Customize
       
   316  * @since 3.4.0
       
   317  */
   241 class WP_Customize_Color_Control extends WP_Customize_Control {
   318 class WP_Customize_Color_Control extends WP_Customize_Control {
       
   319 	/**
       
   320 	 * @access public
       
   321 	 * @var string
       
   322 	 */
   242 	public $type = 'color';
   323 	public $type = 'color';
       
   324 
       
   325 	/**
       
   326 	 * @access public
       
   327 	 * @var array
       
   328 	 */
   243 	public $statuses;
   329 	public $statuses;
   244 
   330 
       
   331 	/**
       
   332 	 * Constructor.
       
   333 	 *
       
   334 	 * If $args['settings'] is not defined, use the $id as the setting ID.
       
   335 	 *
       
   336 	 * @since 3.4.0
       
   337 	 * @uses WP_Customize_Control::__construct()
       
   338 	 *
       
   339 	 * @param WP_Customize_Manager $manager
       
   340 	 * @param string $id
       
   341 	 * @param array $args
       
   342 	 */
   245 	public function __construct( $manager, $id, $args = array() ) {
   343 	public function __construct( $manager, $id, $args = array() ) {
   246 		$this->statuses = array( '' => __('Default') );
   344 		$this->statuses = array( '' => __('Default') );
   247 		parent::__construct( $manager, $id, $args );
   345 		parent::__construct( $manager, $id, $args );
   248 	}
   346 	}
   249 
   347 
       
   348 	/**
       
   349 	 * Enqueue control related scripts/styles.
       
   350 	 *
       
   351 	 * @since 3.4.0
       
   352 	 */
   250 	public function enqueue() {
   353 	public function enqueue() {
   251 		wp_enqueue_script( 'farbtastic' );
   354 		wp_enqueue_script( 'wp-color-picker' );
   252 		wp_enqueue_style( 'farbtastic' );
   355 		wp_enqueue_style( 'wp-color-picker' );
   253 	}
   356 	}
   254 
   357 
       
   358 	/**
       
   359 	 * Refresh the parameters passed to the JavaScript via JSON.
       
   360 	 *
       
   361 	 * @since 3.4.0
       
   362 	 * @uses WP_Customize_Control::to_json()
       
   363 	 */
   255 	public function to_json() {
   364 	public function to_json() {
   256 		parent::to_json();
   365 		parent::to_json();
   257 		$this->json['statuses'] = $this->statuses;
   366 		$this->json['statuses'] = $this->statuses;
   258 	}
   367 	}
   259 
   368 
       
   369 	/**
       
   370 	 * Render the control's content.
       
   371 	 *
       
   372 	 * @since 3.4.0
       
   373 	 */
   260 	public function render_content() {
   374 	public function render_content() {
       
   375 		$this_default = $this->setting->default;
       
   376 		$default_attr = '';
       
   377 		if ( $this_default ) {
       
   378 			if ( false === strpos( $this_default, '#' ) )
       
   379 				$this_default = '#' . $this_default;
       
   380 			$default_attr = ' data-default-color="' . esc_attr( $this_default ) . '"';
       
   381 		}
       
   382 		// The input's value gets set by JS. Don't fill it.
   261 		?>
   383 		?>
   262 		<label>
   384 		<label>
   263 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   385 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   264 			<div class="customize-control-content">
   386 			<div class="customize-control-content">
   265 				<div class="dropdown">
   387 				<input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>"<?php echo $default_attr ?> />
   266 					<div class="dropdown-content">
       
   267 						<div class="dropdown-status"></div>
       
   268 					</div>
       
   269 					<div class="dropdown-arrow"></div>
       
   270 				</div>
       
   271 				<input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e('Hex Value'); ?>" />
       
   272 			</div>
   388 			</div>
   273 			<div class="farbtastic-placeholder"></div>
       
   274 		</label>
   389 		</label>
   275 		<?php
   390 		<?php
   276 	}
   391 	}
   277 }
   392 }
   278 
   393 
       
   394 /**
       
   395  * Customize Upload Control Class
       
   396  *
       
   397  * @package WordPress
       
   398  * @subpackage Customize
       
   399  * @since 3.4.0
       
   400  */
   279 class WP_Customize_Upload_Control extends WP_Customize_Control {
   401 class WP_Customize_Upload_Control extends WP_Customize_Control {
   280 	public $type    = 'upload';
   402 	public $type    = 'upload';
   281 	public $removed = '';
   403 	public $removed = '';
   282 	public $context;
   404 	public $context;
   283 
   405 	public $extensions = array();
       
   406 
       
   407 	/**
       
   408 	 * Enqueue control related scripts/styles.
       
   409 	 *
       
   410 	 * @since 3.4.0
       
   411 	 */
   284 	public function enqueue() {
   412 	public function enqueue() {
   285 		wp_enqueue_script( 'wp-plupload' );
   413 		wp_enqueue_script( 'wp-plupload' );
   286 	}
   414 	}
   287 
   415 
       
   416 	/**
       
   417 	 * Refresh the parameters passed to the JavaScript via JSON.
       
   418 	 *
       
   419 	 * @since 3.4.0
       
   420 	 * @uses WP_Customize_Control::to_json()
       
   421 	 */
   288 	public function to_json() {
   422 	public function to_json() {
   289 		parent::to_json();
   423 		parent::to_json();
   290 
   424 
   291 		$this->json['removed'] = $this->removed;
   425 		$this->json['removed'] = $this->removed;
   292 
   426 
   293 		if ( $this->context )
   427 		if ( $this->context )
   294 			$this->json['context'] = $this->context;
   428 			$this->json['context'] = $this->context;
   295 	}
   429 
   296 
   430 		if ( $this->extensions )
       
   431 			$this->json['extensions'] = implode( ',', $this->extensions );
       
   432 	}
       
   433 
       
   434 	/**
       
   435 	 * Render the control's content.
       
   436 	 *
       
   437 	 * @since 3.4.0
       
   438 	 */
   297 	public function render_content() {
   439 	public function render_content() {
   298 		?>
   440 		?>
   299 		<label>
   441 		<label>
   300 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   442 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   301 			<div>
   443 			<div>
   305 		</label>
   447 		</label>
   306 		<?php
   448 		<?php
   307 	}
   449 	}
   308 }
   450 }
   309 
   451 
       
   452 /**
       
   453  * Customize Image Control Class
       
   454  *
       
   455  * @package WordPress
       
   456  * @subpackage Customize
       
   457  * @since 3.4.0
       
   458  */
   310 class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
   459 class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
   311 	public $type = 'image';
   460 	public $type = 'image';
   312 	public $get_url;
   461 	public $get_url;
   313 	public $statuses;
   462 	public $statuses;
       
   463 	public $extensions = array( 'jpg', 'jpeg', 'gif', 'png' );
   314 
   464 
   315 	protected $tabs = array();
   465 	protected $tabs = array();
   316 
   466 
       
   467 	/**
       
   468 	 * Constructor.
       
   469 	 *
       
   470 	 * If $args['settings'] is not defined, use the $id as the setting ID.
       
   471 	 *
       
   472 	 * @since 3.4.0
       
   473 	 * @uses WP_Customize_Upload_Control::__construct()
       
   474 	 *
       
   475 	 * @param WP_Customize_Manager $manager
       
   476 	 * @param string $id
       
   477 	 * @param array $args
       
   478 	 */
   317 	public function __construct( $manager, $id, $args ) {
   479 	public function __construct( $manager, $id, $args ) {
   318 		$this->statuses = array( '' => __('No Image') );
   480 		$this->statuses = array( '' => __('No Image') );
   319 
   481 
   320 		parent::__construct( $manager, $id, $args );
   482 		parent::__construct( $manager, $id, $args );
   321 
   483 
   336 	public function prepare_control() {
   498 	public function prepare_control() {
   337 		if ( ! $this->tabs )
   499 		if ( ! $this->tabs )
   338 			$this->manager->remove_control( $this->id );
   500 			$this->manager->remove_control( $this->id );
   339 	}
   501 	}
   340 
   502 
       
   503 	/**
       
   504 	 * Refresh the parameters passed to the JavaScript via JSON.
       
   505 	 *
       
   506 	 * @since 3.4.0
       
   507 	 * @uses WP_Customize_Upload_Control::to_json()
       
   508 	 */
   341 	public function to_json() {
   509 	public function to_json() {
   342 		parent::to_json();
   510 		parent::to_json();
   343 		$this->json['statuses'] = $this->statuses;
   511 		$this->json['statuses'] = $this->statuses;
   344 	}
   512 	}
   345 
   513 
       
   514 	/**
       
   515 	 * Render the control's content.
       
   516 	 *
       
   517 	 * @since 3.4.0
       
   518 	 */
   346 	public function render_content() {
   519 	public function render_content() {
   347 		$src = $this->value();
   520 		$src = $this->value();
   348 		if ( isset( $this->get_url ) )
   521 		if ( isset( $this->get_url ) )
   349 			$src = call_user_func( $this->get_url, $src );
   522 			$src = call_user_func( $this->get_url, $src );
   350 
   523 
   351 		?>
   524 		?>
   352 		<div class="customize-image-picker">
   525 		<div class="customize-image-picker">
   353 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   526 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   354 
   527 
   355 			<div class="customize-control-content">
   528 			<div class="customize-control-content">
   356 				<div class="dropdown preview-thumbnail">
   529 				<div class="dropdown preview-thumbnail" tabindex="0">
   357 					<div class="dropdown-content">
   530 					<div class="dropdown-content">
   358 						<?php if ( empty( $src ) ): ?>
   531 						<?php if ( empty( $src ) ): ?>
   359 							<img style="display:none;" />
   532 							<img style="display:none;" />
   360 						<?php else: ?>
   533 						<?php else: ?>
   361 							<img src="<?php echo esc_url( set_url_scheme( $src ) ); ?>" />
   534 							<img src="<?php echo esc_url( set_url_scheme( $src ) ); ?>" />
   367 			</div>
   540 			</div>
   368 
   541 
   369 			<div class="library">
   542 			<div class="library">
   370 				<ul>
   543 				<ul>
   371 					<?php foreach ( $this->tabs as $id => $tab ): ?>
   544 					<?php foreach ( $this->tabs as $id => $tab ): ?>
   372 						<li data-customize-tab='<?php echo esc_attr( $id ); ?>'>
   545 						<li data-customize-tab='<?php echo esc_attr( $id ); ?>' tabindex='0'>
   373 							<?php echo esc_html( $tab['label'] ); ?>
   546 							<?php echo esc_html( $tab['label'] ); ?>
   374 						</li>
   547 						</li>
   375 					<?php endforeach; ?>
   548 					<?php endforeach; ?>
   376 				</ul>
   549 				</ul>
   377 				<?php foreach ( $this->tabs as $id => $tab ): ?>
   550 				<?php foreach ( $this->tabs as $id => $tab ): ?>
   386 			</div>
   559 			</div>
   387 		</div>
   560 		</div>
   388 		<?php
   561 		<?php
   389 	}
   562 	}
   390 
   563 
       
   564 	/**
       
   565 	 * Add a tab to the control.
       
   566 	 *
       
   567 	 * @since 3.4.0
       
   568 	 *
       
   569 	 * @param string $id
       
   570 	 * @param string $label
       
   571 	 * @param mixed $callback
       
   572 	 */
   391 	public function add_tab( $id, $label, $callback ) {
   573 	public function add_tab( $id, $label, $callback ) {
   392 		$this->tabs[ $id ] = array(
   574 		$this->tabs[ $id ] = array(
   393 			'label'    => $label,
   575 			'label'    => $label,
   394 			'callback' => $callback,
   576 			'callback' => $callback,
   395 		);
   577 		);
   396 	}
   578 	}
   397 
   579 
       
   580 	/**
       
   581 	 * Remove a tab from the control.
       
   582 	 *
       
   583 	 * @since 3.4.0
       
   584 	 *
       
   585 	 * @param string $id
       
   586 	 */
   398 	public function remove_tab( $id ) {
   587 	public function remove_tab( $id ) {
   399 		unset( $this->tabs[ $id ] );
   588 		unset( $this->tabs[ $id ] );
   400 	}
   589 	}
   401 
   590 
       
   591 	/**
       
   592 	 * @since 3.4.0
       
   593 	 */
   402 	public function tab_upload_new() {
   594 	public function tab_upload_new() {
   403 		if ( ! _device_can_upload() ) {
   595 		if ( ! _device_can_upload() ) {
   404 			?>
   596 			?>
   405 			<p><?php _e('The web browser on your device cannot be used to upload files. You may be able to use the <a href="http://wordpress.org/extend/mobile/">native app for your device</a> instead.'); ?></p>
   597 			<p><?php _e('The web browser on your device cannot be used to upload files. You may be able to use the <a href="http://wordpress.org/extend/mobile/">native app for your device</a> instead.'); ?></p>
   406 			<?php
   598 			<?php
   414 			</div>
   606 			</div>
   415 			<?php
   607 			<?php
   416 		}
   608 		}
   417 	}
   609 	}
   418 
   610 
       
   611 	/**
       
   612 	 * @since 3.4.0
       
   613 	 */
   419 	public function tab_uploaded() {
   614 	public function tab_uploaded() {
   420 		?>
   615 		?>
   421 		<div class="uploaded-target"></div>
   616 		<div class="uploaded-target"></div>
   422 		<?php
   617 		<?php
   423 	}
   618 	}
   424 
   619 
       
   620 	/**
       
   621 	 * @since 3.4.0
       
   622 	 *
       
   623 	 * @param string $url
       
   624 	 * @param string $thumbnail_url
       
   625 	 */
   425 	public function print_tab_image( $url, $thumbnail_url = null ) {
   626 	public function print_tab_image( $url, $thumbnail_url = null ) {
   426 		$url = set_url_scheme( $url );
   627 		$url = set_url_scheme( $url );
   427 		$thumbnail_url = ( $thumbnail_url ) ? set_url_scheme( $thumbnail_url ) : $url;
   628 		$thumbnail_url = ( $thumbnail_url ) ? set_url_scheme( $thumbnail_url ) : $url;
   428 		?>
   629 		?>
   429 		<a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $url ); ?>">
   630 		<a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $url ); ?>">
   431 		</a>
   632 		</a>
   432 		<?php
   633 		<?php
   433 	}
   634 	}
   434 }
   635 }
   435 
   636 
       
   637 /**
       
   638  * Customize Background Image Control Class
       
   639  *
       
   640  * @package WordPress
       
   641  * @subpackage Customize
       
   642  * @since 3.4.0
       
   643  */
   436 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
   644 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
       
   645 
       
   646 	/**
       
   647 	 * Constructor.
       
   648 	 *
       
   649 	 * @since 3.4.0
       
   650 	 * @uses WP_Customize_Image_Control::__construct()
       
   651 	 *
       
   652 	 * @param WP_Customize_Manager $manager
       
   653 	 */
   437 	public function __construct( $manager ) {
   654 	public function __construct( $manager ) {
   438 		parent::__construct( $manager, 'background_image', array(
   655 		parent::__construct( $manager, 'background_image', array(
   439 			'label'    => __( 'Background Image' ),
   656 			'label'    => __( 'Background Image' ),
   440 			'section'  => 'background_image',
   657 			'section'  => 'background_image',
   441 			'context'  => 'custom-background',
   658 			'context'  => 'custom-background',
   444 
   661 
   445 		if ( $this->setting->default )
   662 		if ( $this->setting->default )
   446 			$this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_background' ) );
   663 			$this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_background' ) );
   447 	}
   664 	}
   448 
   665 
       
   666 	/**
       
   667 	 * @since 3.4.0
       
   668 	 */
   449 	public function tab_uploaded() {
   669 	public function tab_uploaded() {
   450 		$backgrounds = get_posts( array(
   670 		$backgrounds = get_posts( array(
   451 			'post_type'  => 'attachment',
   671 			'post_type'  => 'attachment',
   452 			'meta_key'   => '_wp_attachment_is_custom_background',
   672 			'meta_key'   => '_wp_attachment_is_custom_background',
   453 			'meta_value' => $this->manager->get_stylesheet(),
   673 			'meta_value' => $this->manager->get_stylesheet(),
   462 
   682 
   463 		foreach ( (array) $backgrounds as $background )
   683 		foreach ( (array) $backgrounds as $background )
   464 			$this->print_tab_image( esc_url_raw( $background->guid ) );
   684 			$this->print_tab_image( esc_url_raw( $background->guid ) );
   465 	}
   685 	}
   466 
   686 
       
   687 	/**
       
   688 	 * @since 3.4.0
       
   689 	 * @uses WP_Customize_Image_Control::print_tab_image()
       
   690 	 */
   467 	public function tab_default_background() {
   691 	public function tab_default_background() {
   468 		$this->print_tab_image( $this->setting->default );
   692 		$this->print_tab_image( $this->setting->default );
   469 	}
   693 	}
   470 }
   694 }
   471 
   695 
       
   696 /**
       
   697  * Customize Header Image Control Class
       
   698  *
       
   699  * @package WordPress
       
   700  * @subpackage Customize
       
   701  * @since 3.4.0
       
   702  */
   472 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
   703 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
   473 	/**
   704 	/**
   474 	 * The processed default headers.
   705 	 * The processed default headers.
   475 	 * @since 3.4.2
   706 	 * @since 3.4.2
   476 	 * @var array
   707 	 * @var array
   482 	 * @since 3.4.2
   713 	 * @since 3.4.2
   483 	 * @var array
   714 	 * @var array
   484 	 */
   715 	 */
   485 	protected $uploaded_headers;
   716 	protected $uploaded_headers;
   486 
   717 
       
   718 	/**
       
   719 	 * Constructor.
       
   720 	 *
       
   721 	 * @since 3.4.0
       
   722 	 * @uses WP_Customize_Image_Control::__construct()
       
   723 	 * @uses WP_Customize_Image_Control::add_tab()
       
   724 	 *
       
   725 	 * @param WP_Customize_Manager $manager
       
   726 	 */
   487 	public function __construct( $manager ) {
   727 	public function __construct( $manager ) {
   488 		parent::__construct( $manager, 'header_image', array(
   728 		parent::__construct( $manager, 'header_image', array(
   489 			'label'    => __( 'Header Image' ),
   729 			'label'    => __( 'Header Image' ),
   490 			'settings' => array(
   730 			'settings' => array(
   491 				'default' => 'header_image',
   731 				'default' => 'header_image',
   531 			$this->remove_tab( 'uploaded' );
   771 			$this->remove_tab( 'uploaded' );
   532 
   772 
   533 		return parent::prepare_control();
   773 		return parent::prepare_control();
   534 	}
   774 	}
   535 
   775 
       
   776 	/**
       
   777 	 * @since 3.4.0
       
   778 	 *
       
   779 	 * @param mixed $choice Which header image to select. (@see Custom_Image_Header::get_header_image() )
       
   780 	 * @param array $header
       
   781 	 */
   536 	public function print_header_image( $choice, $header ) {
   782 	public function print_header_image( $choice, $header ) {
   537 		$header['url']           = set_url_scheme( $header['url'] );
   783 		$header['url']           = set_url_scheme( $header['url'] );
   538 		$header['thumbnail_url'] = set_url_scheme( $header['thumbnail_url'] );
   784 		$header['thumbnail_url'] = set_url_scheme( $header['thumbnail_url'] );
   539 
   785 
   540 		$header_image_data = array( 'choice' => $choice );
   786 		$header_image_data = array( 'choice' => $choice );
   551 			<img src="<?php echo esc_url( $header['thumbnail_url'] ); ?>" />
   797 			<img src="<?php echo esc_url( $header['thumbnail_url'] ); ?>" />
   552 		</a>
   798 		</a>
   553 		<?php
   799 		<?php
   554 	}
   800 	}
   555 
   801 
       
   802 	/**
       
   803 	 * @since 3.4.0
       
   804 	 */
   556 	public function tab_uploaded() {
   805 	public function tab_uploaded() {
   557 		?><div class="uploaded-target"></div><?php
   806 		?><div class="uploaded-target"></div><?php
   558 
   807 
   559 		foreach ( $this->uploaded_headers as $choice => $header )
   808 		foreach ( $this->uploaded_headers as $choice => $header )
   560 			$this->print_header_image( $choice, $header );
   809 			$this->print_header_image( $choice, $header );
   561 	}
   810 	}
   562 
   811 
       
   812 	/**
       
   813 	 * @since 3.4.0
       
   814 	 */
   563 	public function tab_default_headers() {
   815 	public function tab_default_headers() {
   564 		foreach ( $this->default_headers as $choice => $header )
   816 		foreach ( $this->default_headers as $choice => $header )
   565 			$this->print_header_image( $choice, $header );
   817 			$this->print_header_image( $choice, $header );
   566 	}
   818 	}
   567 }
   819 }