3 * WordPress Customize Control classes
6 * @subpackage Customize
11 * Customize Control class.
15 class WP_Customize_Control {
18 * Incremented with each new class instantiation, then stored in $instance_number.
20 * Used when sorting two instances whose priorities are equal.
26 protected static $instance_count = 0;
29 * Order in which this instance was created in relation to other instances.
35 public $instance_number;
39 * @var WP_Customize_Manager
50 * All settings tied to the control.
58 * The primary setting for the control (if there is one).
63 public $setting = 'default';
69 public $priority = 10;
87 public $description = '';
90 * @todo: Remove choices
95 public $choices = array();
101 public $input_attrs = array();
104 * @deprecated It is better to just call the json() method
108 public $json = array();
114 public $type = 'text';
122 * @see WP_Customize_Control::active()
124 * @var callable Callback is called with one argument, the instance of
125 * WP_Customize_Control, and returns bool to indicate whether
126 * the control is active (such as it relates to the URL
127 * currently being previewed).
129 public $active_callback = '';
134 * Supplied $args override class property defaults.
136 * If $args['settings'] is not defined, use the $id as the setting ID.
140 * @param WP_Customize_Manager $manager
144 public function __construct( $manager, $id, $args = array() ) {
145 $keys = array_keys( get_object_vars( $this ) );
146 foreach ( $keys as $key ) {
147 if ( isset( $args[ $key ] ) ) {
148 $this->$key = $args[ $key ];
152 $this->manager = $manager;
154 if ( empty( $this->active_callback ) ) {
155 $this->active_callback = array( $this, 'active_callback' );
157 self::$instance_count += 1;
158 $this->instance_number = self::$instance_count;
161 if ( empty( $this->settings ) ) {
162 $this->settings = $id;
166 if ( is_array( $this->settings ) ) {
167 foreach ( $this->settings as $key => $setting ) {
168 $settings[ $key ] = $this->manager->get_setting( $setting );
171 $this->setting = $this->manager->get_setting( $this->settings );
172 $settings['default'] = $this->setting;
174 $this->settings = $settings;
178 * Enqueue control related scripts/styles.
182 public function enqueue() {}
185 * Check whether control is active to current Customizer preview.
190 * @return bool Whether the control is active to the current preview.
192 final public function active() {
194 $active = call_user_func( $this->active_callback, $this );
197 * Filter response of WP_Customize_Control::active().
201 * @param bool $active Whether the Customizer control is active.
202 * @param WP_Customize_Control $control WP_Customize_Control instance.
204 $active = apply_filters( 'customize_control_active', $active, $control );
210 * Default callback used when invoking WP_Customize_Control::active().
212 * Subclasses can override this with their specific logic, or they may
213 * provide an 'active_callback' argument to the constructor.
218 * @return bool Always true.
220 public function active_callback() {
225 * Fetch a setting's value.
226 * Grabs the main setting by default.
230 * @param string $setting_key
231 * @return mixed The requested setting's value, if the setting exists.
233 final public function value( $setting_key = 'default' ) {
234 if ( isset( $this->settings[ $setting_key ] ) ) {
235 return $this->settings[ $setting_key ]->value();
240 * Refresh the parameters passed to the JavaScript via JSON.
244 public function to_json() {
245 $this->json['settings'] = array();
246 foreach ( $this->settings as $key => $setting ) {
247 $this->json['settings'][ $key ] = $setting->id;
250 $this->json['type'] = $this->type;
251 $this->json['priority'] = $this->priority;
252 $this->json['active'] = $this->active();
253 $this->json['section'] = $this->section;
254 $this->json['content'] = $this->get_content();
255 $this->json['label'] = $this->label;
256 $this->json['description'] = $this->description;
257 $this->json['instanceNumber'] = $this->instance_number;
261 * Get the data to export to the client via JSON.
265 * @return array Array of parameters passed to the JavaScript.
267 public function json() {
273 * Check if the theme supports the control and check user capabilities.
277 * @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
279 final public function check_capabilities() {
280 foreach ( $this->settings as $setting ) {
281 if ( ! $setting->check_capabilities() )
285 $section = $this->manager->get_section( $this->section );
286 if ( isset( $section ) && ! $section->check_capabilities() )
293 * Get the control's content for insertion into the Customizer pane.
297 * @return string Contents of the control.
299 final public function get_content() {
301 $this->maybe_render();
302 $template = trim( ob_get_contents() );
308 * Check capabilities and render the control.
311 * @uses WP_Customize_Control::render()
313 final public function maybe_render() {
314 if ( ! $this->check_capabilities() )
318 * Fires just before the current Customizer control is rendered.
322 * @param WP_Customize_Control $this WP_Customize_Control instance.
324 do_action( 'customize_render_control', $this );
327 * Fires just before a specific Customizer control is rendered.
329 * The dynamic portion of the hook name, `$this->id`, refers to
334 * @param WP_Customize_Control $this {@see WP_Customize_Control} instance.
336 do_action( 'customize_render_control_' . $this->id, $this );
342 * Renders the control wrapper and calls $this->render_content() for the internals.
346 protected function render() {
347 $id = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) );
348 $class = 'customize-control customize-control-' . $this->type;
350 ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>">
351 <?php $this->render_content(); ?>
356 * Get the data link attribute for a setting.
360 * @param string $setting_key
361 * @return string Data link parameter, if $setting_key is a valid setting, empty string otherwise.
363 public function get_link( $setting_key = 'default' ) {
364 if ( ! isset( $this->settings[ $setting_key ] ) )
367 return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
371 * Render the data link attribute for the control's input element.
374 * @uses WP_Customize_Control::get_link()
376 * @param string $setting_key
378 public function link( $setting_key = 'default' ) {
379 echo $this->get_link( $setting_key );
383 * Render the custom attributes for the control's input element.
388 public function input_attrs() {
389 foreach( $this->input_attrs as $attr => $value ) {
390 echo $attr . '="' . esc_attr( $value ) . '" ';
395 * Render the control's content.
397 * Allows the content to be overriden without having to rewrite the wrapper in $this->render().
399 * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
400 * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
402 * Control content can alternately be rendered in JS. See {@see WP_Customize_Control::print_template()}.
406 protected function render_content() {
407 switch( $this->type ) {
411 <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />
412 <?php echo esc_html( $this->label ); ?>
413 <?php if ( ! empty( $this->description ) ) : ?>
414 <span class="description customize-control-description"><?php echo $this->description; ?></span>
420 if ( empty( $this->choices ) )
423 $name = '_customize-radio-' . $this->id;
425 if ( ! empty( $this->label ) ) : ?>
426 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
428 if ( ! empty( $this->description ) ) : ?>
429 <span class="description customize-control-description"><?php echo $this->description ; ?></span>
432 foreach ( $this->choices as $value => $label ) :
435 <input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> />
436 <?php echo esc_html( $label ); ?><br/>
442 if ( empty( $this->choices ) )
447 <?php if ( ! empty( $this->label ) ) : ?>
448 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
450 if ( ! empty( $this->description ) ) : ?>
451 <span class="description customize-control-description"><?php echo $this->description; ?></span>
454 <select <?php $this->link(); ?>>
456 foreach ( $this->choices as $value => $label )
457 echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
466 <?php if ( ! empty( $this->label ) ) : ?>
467 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
469 if ( ! empty( $this->description ) ) : ?>
470 <span class="description customize-control-description"><?php echo $this->description; ?></span>
472 <textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
476 case 'dropdown-pages':
477 $dropdown = wp_dropdown_pages(
479 'name' => '_customize-dropdown-pages-' . $this->id,
481 'show_option_none' => __( '— Select —' ),
482 'option_none_value' => '0',
483 'selected' => $this->value(),
487 // Hackily add in the data link parameter.
488 $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
491 '<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>',
499 <?php if ( ! empty( $this->label ) ) : ?>
500 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
502 if ( ! empty( $this->description ) ) : ?>
503 <span class="description customize-control-description"><?php echo $this->description; ?></span>
505 <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
513 * Render the control's JS template.
515 * This function is only run for control types that have been registered with
516 * {@see WP_Customize_Manager::register_control_type()}.
518 * In the future, this will also print the template for the control's container
519 * element and be override-able.
523 final public function print_template() {
525 <script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content">
526 <?php $this->content_template(); ?>
532 * An Underscore (JS) template for this control's content (but not its container).
534 * Class variables for this control class are available in the `data` JS object;
535 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
537 * @see WP_Customize_Control::print_template()
541 protected function content_template() {}
546 * Customize Color Control class.
550 * @see WP_Customize_Control
552 class WP_Customize_Color_Control extends WP_Customize_Control {
557 public $type = 'color';
569 * @uses WP_Customize_Control::__construct()
571 * @param WP_Customize_Manager $manager
575 public function __construct( $manager, $id, $args = array() ) {
576 $this->statuses = array( '' => __('Default') );
577 parent::__construct( $manager, $id, $args );
581 * Enqueue scripts/styles for the color picker.
585 public function enqueue() {
586 wp_enqueue_script( 'wp-color-picker' );
587 wp_enqueue_style( 'wp-color-picker' );
591 * Refresh the parameters passed to the JavaScript via JSON.
594 * @uses WP_Customize_Control::to_json()
596 public function to_json() {
598 $this->json['statuses'] = $this->statuses;
599 $this->json['defaultValue'] = $this->setting->default;
603 * Don't render the control content from PHP, as it's rendered via JS on load.
607 public function render_content() {}
610 * Render a JS template for the content of the color picker control.
614 public function content_template() {
616 <# var defaultValue = '';
617 if ( data.defaultValue ) {
618 if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
619 defaultValue = '#' + data.defaultValue;
621 defaultValue = data.defaultValue;
623 defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
626 <# if ( data.label ) { #>
627 <span class="customize-control-title">{{{ data.label }}}</span>
629 <# if ( data.description ) { #>
630 <span class="description customize-control-description">{{{ data.description }}}</span>
632 <div class="customize-control-content">
633 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />
641 * Customize Media Control class.
645 * @see WP_Customize_Control
647 class WP_Customize_Media_Control extends WP_Customize_Control {
655 public $type = 'media';
658 * Media control mime type.
664 public $mime_type = '';
673 public $button_labels = array();
679 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
681 * @param WP_Customize_Manager $manager {@see WP_Customize_Manager} instance.
683 public function __construct( $manager, $id, $args = array() ) {
684 parent::__construct( $manager, $id, $args );
686 $this->button_labels = array(
687 'select' => __( 'Select File' ),
688 'change' => __( 'Change File' ),
689 'default' => __( 'Default' ),
690 'remove' => __( 'Remove' ),
691 'placeholder' => __( 'No file selected' ),
692 'frame_title' => __( 'Select File' ),
693 'frame_button' => __( 'Choose File' ),
698 * Enqueue control related scripts/styles.
701 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
703 public function enqueue() {
708 * Refresh the parameters passed to the JavaScript via JSON.
711 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
713 * @see WP_Customize_Control::to_json()
715 public function to_json() {
717 $this->json['mime_type'] = $this->mime_type;
718 $this->json['button_labels'] = $this->button_labels;
720 $value = $this->value();
722 if ( is_object( $this->setting ) ) {
723 if ( $this->setting->default ) {
724 // Fake an attachment model - needs all fields used by template.
725 // Note that the default value must be a URL, NOT an attachment ID.
726 $type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
727 $default_attachment = array(
729 'url' => $this->setting->default,
731 'icon' => wp_mime_type_icon( $type ),
732 'title' => basename( $this->setting->default ),
735 if ( 'image' === $type ) {
736 $default_attachment['sizes'] = array(
737 'full' => array( 'url' => $this->setting->default ),
741 $this->json['defaultAttachment'] = $default_attachment;
744 if ( $value && $this->setting->default && $value === $this->setting->default ) {
745 // Set the default as the attachment.
746 $this->json['attachment'] = $this->json['defaultAttachment'];
747 } elseif ( $value ) {
748 $this->json['attachment'] = wp_prepare_attachment_for_js( $value );
754 * Don't render any content for this control from PHP.
757 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
759 * @see WP_Customize_Media_Control::content_template()
761 public function render_content() {}
764 * Render a JS template for the content of the media control.
767 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
769 public function content_template() {
771 <label for="{{ data.settings['default'] }}-button">
772 <# if ( data.label ) { #>
773 <span class="customize-control-title">{{ data.label }}</span>
775 <# if ( data.description ) { #>
776 <span class="description customize-control-description">{{{ data.description }}}</span>
780 <# if ( data.attachment && data.attachment.id ) { #>
781 <div class="current">
782 <div class="container">
783 <div class="attachment-media-view attachment-media-view-{{ data.attachment.type }} {{ data.attachment.orientation }}">
784 <div class="thumbnail thumbnail-{{ data.attachment.type }}">
785 <# if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.medium ) { #>
786 <img class="attachment-thumb" src="{{ data.attachment.sizes.medium.url }}" draggable="false" />
787 <# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #>
788 <img class="attachment-thumb" src="{{ data.attachment.sizes.full.url }}" draggable="false" />
789 <# } else if ( 'audio' === data.attachment.type ) { #>
790 <# if ( data.attachment.image && data.attachment.image.src && data.attachment.image.src !== data.attachment.icon ) { #>
791 <img src="{{ data.attachment.image.src }}" class="thumbnail" draggable="false" />
793 <img src="{{ data.attachment.icon }}" class="attachment-thumb type-icon" draggable="false" />
795 <p class="attachment-meta attachment-meta-title">“{{ data.attachment.title }}”</p>
796 <# if ( data.attachment.album || data.attachment.meta.album ) { #>
797 <p class="attachment-meta"><em>{{ data.attachment.album || data.attachment.meta.album }}</em></p>
799 <# if ( data.attachment.artist || data.attachment.meta.artist ) { #>
800 <p class="attachment-meta">{{ data.attachment.artist || data.attachment.meta.artist }}</p>
802 <audio style="visibility: hidden" controls class="wp-audio-shortcode" width="100%" preload="none">
803 <source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}"/>
805 <# } else if ( 'video' === data.attachment.type ) { #>
806 <div class="wp-media-wrapper wp-video">
807 <video controls="controls" class="wp-video-shortcode" preload="metadata"
808 <# if ( data.attachment.image && data.attachment.image.src !== data.attachment.icon ) { #>poster="{{ data.attachment.image.src }}"<# } #>>
809 <source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}"/>
813 <img class="attachment-thumb type-icon" src="{{ data.attachment.icon }}" class="icon" draggable="false" />
814 <p class="attachment-title">{{ data.attachment.title }}</p>
820 <div class="actions">
821 <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
822 <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['change']; ?></button>
823 <div style="clear:both"></div>
826 <div class="current">
827 <div class="container">
828 <div class="placeholder">
831 <?php echo $this->button_labels['placeholder']; ?>
837 <div class="actions">
838 <# if ( data.defaultAttachment ) { #>
839 <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
841 <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['select']; ?></button>
842 <div style="clear:both"></div>
850 * Customize Upload Control Class.
854 * @see WP_Customize_Media_Control
856 class WP_Customize_Upload_Control extends WP_Customize_Media_Control {
857 public $type = 'upload';
858 public $mime_type = '';
859 public $button_labels = array();
860 public $removed = ''; // unused
861 public $context; // unused
862 public $extensions = array(); // unused
865 * Refresh the parameters passed to the JavaScript via JSON.
869 * @uses WP_Customize_Media_Control::to_json()
871 public function to_json() {
874 $value = $this->value();
876 // Get the attachment model for the existing file.
877 $attachment_id = attachment_url_to_postid( $value );
878 if ( $attachment_id ) {
879 $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
886 * Customize Image Control class.
890 * @see WP_Customize_Upload_Control
892 class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
893 public $type = 'image';
894 public $mime_type = 'image';
900 * @uses WP_Customize_Upload_Control::__construct()
902 * @param WP_Customize_Manager $manager
906 public function __construct( $manager, $id, $args = array() ) {
907 parent::__construct( $manager, $id, $args );
909 $this->button_labels = array(
910 'select' => __( 'Select Image' ),
911 'change' => __( 'Change Image' ),
912 'remove' => __( 'Remove' ),
913 'default' => __( 'Default' ),
914 'placeholder' => __( 'No image selected' ),
915 'frame_title' => __( 'Select Image' ),
916 'frame_button' => __( 'Choose Image' ),
924 public function prepare_control() {}
931 * @param string $label
932 * @param mixed $callback
934 public function add_tab( $id, $label, $callback ) {}
942 public function remove_tab( $id ) {}
949 * @param string $thumbnail_url
951 public function print_tab_image( $url, $thumbnail_url = null ) {}
955 * Customize Background Image Control class.
959 * @see WP_Customize_Image_Control
961 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
962 public $type = 'background';
968 * @uses WP_Customize_Image_Control::__construct()
970 * @param WP_Customize_Manager $manager
972 public function __construct( $manager ) {
973 parent::__construct( $manager, 'background_image', array(
974 'label' => __( 'Background Image' ),
975 'section' => 'background_image',
980 * Enqueue control related scripts/styles.
984 public function enqueue() {
987 wp_localize_script( 'customize-controls', '_wpCustomizeBackground', array(
989 'add' => wp_create_nonce( 'background-add' ),
996 * Customize Header Image Control class.
1000 * @see WP_Customize_Image_Control
1002 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
1003 public $type = 'header';
1004 public $uploaded_headers;
1005 public $default_headers;
1008 * @param WP_Customize_Manager $manager
1010 public function __construct( $manager ) {
1011 parent::__construct( $manager, 'header_image', array(
1012 'label' => __( 'Header Image' ),
1013 'settings' => array(
1014 'default' => 'header_image',
1015 'data' => 'header_image_data',
1017 'section' => 'header_image',
1018 'removed' => 'remove-header',
1019 'get_url' => 'get_header_image',
1024 public function enqueue() {
1026 wp_enqueue_script( 'customize-views' );
1028 $this->prepare_control();
1030 wp_localize_script( 'customize-views', '_wpCustomizeHeader', array(
1032 'width' => absint( get_theme_support( 'custom-header', 'width' ) ),
1033 'height' => absint( get_theme_support( 'custom-header', 'height' ) ),
1034 'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),
1035 'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),
1036 'currentImgSrc' => $this->get_current_image_src(),
1039 'add' => wp_create_nonce( 'header-add' ),
1040 'remove' => wp_create_nonce( 'header-remove' ),
1042 'uploads' => $this->uploaded_headers,
1043 'defaults' => $this->default_headers
1049 public function prepare_control() {
1050 global $custom_image_header;
1051 if ( empty( $custom_image_header ) ) {
1055 // Process default headers and uploaded headers.
1056 $custom_image_header->process_default_headers();
1057 $this->default_headers = $custom_image_header->get_default_header_images();
1058 $this->uploaded_headers = $custom_image_header->get_uploaded_header_images();
1061 public function print_header_image_template() {
1063 <script type="text/template" id="tmpl-header-choice">
1064 <# if (data.random) { #>
1065 <button type="button" class="button display-options random">
1066 <span class="dashicons dashicons-randomize dice"></span>
1067 <# if ( data.type === 'uploaded' ) { #>
1068 <?php _e( 'Randomize uploaded headers' ); ?>
1069 <# } else if ( data.type === 'default' ) { #>
1070 <?php _e( 'Randomize suggested headers' ); ?>
1076 <# if (data.type === 'uploaded') { #>
1077 <div class="dashicons dashicons-no close"></div>
1080 <button type="button" class="choice thumbnail"
1081 data-customize-image-value="{{{data.header.url}}}"
1082 data-customize-header-image-data="{{JSON.stringify(data.header)}}">
1083 <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
1084 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
1090 <script type="text/template" id="tmpl-header-current">
1091 <# if (data.choice) { #>
1092 <# if (data.random) { #>
1094 <div class="placeholder">
1096 <span><span class="dashicons dashicons-randomize dice"></span>
1097 <# if ( data.type === 'uploaded' ) { #>
1098 <?php _e( 'Randomizing uploaded headers' ); ?>
1099 <# } else if ( data.type === 'default' ) { #>
1100 <?php _e( 'Randomizing suggested headers' ); ?>
1108 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/>
1113 <div class="placeholder">
1116 <?php _e( 'No image set' ); ?>
1126 public function get_current_image_src() {
1127 $src = $this->value();
1128 if ( isset( $this->get_url ) ) {
1129 $src = call_user_func( $this->get_url, $src );
1135 public function render_content() {
1136 $this->print_header_image_template();
1137 $visibility = $this->get_current_image_src() ? '' : ' style="display:none" ';
1138 $width = absint( get_theme_support( 'custom-header', 'width' ) );
1139 $height = absint( get_theme_support( 'custom-header', 'height' ) );
1143 <div class="customize-control-content">
1144 <p class="customizer-section-intro">
1146 if ( $width && $height ) {
1147 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header size of <strong>%s × %s</strong> pixels.' ), $width, $height );
1148 } elseif ( $width ) {
1149 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header width of <strong>%s</strong> pixels.' ), $width );
1151 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header height of <strong>%s</strong> pixels.' ), $height );
1155 <div class="current">
1156 <span class="customize-control-title">
1157 <?php _e( 'Current header' ); ?>
1159 <div class="container">
1162 <div class="actions">
1163 <?php /* translators: Hide as in hide header image via the Customizer */ ?>
1164 <button type="button"<?php echo $visibility ?> class="button remove"><?php _ex( 'Hide image', 'custom header' ); ?></button>
1165 <?php /* translators: New as in add new header image via the Customizer */ ?>
1166 <button type="button" class="button new"><?php _ex( 'Add new image', 'header image' ); ?></button>
1167 <div style="clear:both"></div>
1169 <div class="choices">
1170 <span class="customize-control-title header-previously-uploaded">
1171 <?php _ex( 'Previously uploaded', 'custom headers' ); ?>
1173 <div class="uploaded">
1177 <span class="customize-control-title header-default">
1178 <?php _ex( 'Suggested', 'custom headers' ); ?>
1180 <div class="default">
1191 * Customize Theme Control class.
1195 * @see WP_Customize_Control
1197 class WP_Customize_Theme_Control extends WP_Customize_Control {
1200 * Customize control type.
1206 public $type = 'theme';
1218 * Refresh the parameters passed to the JavaScript via JSON.
1223 * @see WP_Customize_Control::to_json()
1225 public function to_json() {
1227 $this->json['theme'] = $this->theme;
1231 * Don't render the control content from PHP, as it's rendered via JS on load.
1236 public function render_content() {}
1239 * Render a JS template for theme display.
1244 public function content_template() {
1245 $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1246 $active_url = esc_url( remove_query_arg( 'theme', $current_url ) );
1247 $preview_url = esc_url( add_query_arg( 'theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces.
1248 $preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url );
1250 <# if ( data.theme.isActiveTheme ) { #>
1251 <div class="theme active" tabindex="0" data-preview-url="<?php echo esc_attr( $active_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
1253 <div class="theme" tabindex="0" data-preview-url="<?php echo esc_attr( $preview_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
1256 <# if ( data.theme.screenshot[0] ) { #>
1257 <div class="theme-screenshot">
1258 <img data-src="{{ data.theme.screenshot[0] }}" alt="" />
1261 <div class="theme-screenshot blank"></div>
1264 <# if ( data.theme.isActiveTheme ) { #>
1265 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Customize' ); ?></span>
1267 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Live Preview' ); ?></span>
1270 <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.theme.author }}' ); ?></div>
1272 <# if ( data.theme.isActiveTheme ) { #>
1273 <h3 class="theme-name" id="{{ data.theme.id }}-name">
1275 /* translators: %s: theme name */
1276 printf( __( '<span>Active:</span> %s' ), '{{ data.theme.name }}' );
1280 <h3 class="theme-name" id="{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
1281 <div class="theme-actions">
1282 <button type="button" class="button theme-details"><?php _e( 'Theme Details' ); ?></button>
1291 * Widget Area Customize Control class.
1295 * @see WP_Customize_Control
1297 class WP_Widget_Area_Customize_Control extends WP_Customize_Control {
1298 public $type = 'sidebar_widgets';
1301 public function to_json() {
1303 $exported_properties = array( 'sidebar_id' );
1304 foreach ( $exported_properties as $key ) {
1305 $this->json[ $key ] = $this->$key;
1309 public function render_content() {
1311 <span class="button-secondary add-new-widget" tabindex="0">
1312 <?php _e( 'Add a Widget' ); ?>
1315 <span class="reorder-toggle" tabindex="0">
1316 <span class="reorder"><?php _ex( 'Reorder', 'Reorder widgets in Customizer' ); ?></span>
1317 <span class="reorder-done"><?php _ex( 'Done', 'Cancel reordering widgets in Customizer' ); ?></span>
1325 * Widget Form Customize Control class.
1329 * @see WP_Customize_Control
1331 class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
1332 public $type = 'widget_form';
1334 public $widget_id_base;
1336 public $is_new = false;
1339 public $is_wide = false;
1341 public function to_json() {
1343 $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
1344 foreach ( $exported_properties as $key ) {
1345 $this->json[ $key ] = $this->$key;
1349 public function render_content() {
1350 global $wp_registered_widgets;
1351 require_once ABSPATH . '/wp-admin/includes/widgets.php';
1353 $widget = $wp_registered_widgets[ $this->widget_id ];
1354 if ( ! isset( $widget['params'][0] ) ) {
1355 $widget['params'][0] = array();
1359 'widget_id' => $widget['id'],
1360 'widget_name' => $widget['name'],
1363 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
1364 echo $this->manager->widgets->get_widget_control( $args );
1368 * Whether the current widget is rendered on the page.
1373 * @return bool Whether the widget is rendered.
1375 public function active_callback() {
1376 return $this->manager->widgets->is_widget_rendered( $this->widget_id );