3 * Customize Control Class
6 * @subpackage Customize
9 class WP_Customize_Control {
12 * Incremented with each new class instantiation, then stored in $instance_number.
14 * Used when sorting two instances whose priorities are equal.
20 protected static $instance_count = 0;
23 * Order in which this instance was created in relation to other instances.
29 public $instance_number;
33 * @var WP_Customize_Manager
44 * All settings tied to the control.
52 * The primary setting for the control (if there is one).
57 public $setting = 'default';
63 public $priority = 10;
81 public $description = '';
84 * @todo: Remove choices
89 public $choices = array();
95 public $input_attrs = array();
98 * @deprecated It is better to just call the json() method
102 public $json = array();
108 public $type = 'text';
116 * @see WP_Customize_Control::active()
118 * @var callable Callback is called with one argument, the instance of
119 * WP_Customize_Control, and returns bool to indicate whether
120 * the control is active (such as it relates to the URL
121 * currently being previewed).
123 public $active_callback = '';
128 * Supplied $args override class property defaults.
130 * If $args['settings'] is not defined, use the $id as the setting ID.
134 * @param WP_Customize_Manager $manager
138 public function __construct( $manager, $id, $args = array() ) {
139 $keys = array_keys( get_object_vars( $this ) );
140 foreach ( $keys as $key ) {
141 if ( isset( $args[ $key ] ) ) {
142 $this->$key = $args[ $key ];
146 $this->manager = $manager;
148 if ( empty( $this->active_callback ) ) {
149 $this->active_callback = array( $this, 'active_callback' );
151 self::$instance_count += 1;
152 $this->instance_number = self::$instance_count;
155 if ( empty( $this->settings ) ) {
156 $this->settings = $id;
160 if ( is_array( $this->settings ) ) {
161 foreach ( $this->settings as $key => $setting ) {
162 $settings[ $key ] = $this->manager->get_setting( $setting );
165 $this->setting = $this->manager->get_setting( $this->settings );
166 $settings['default'] = $this->setting;
168 $this->settings = $settings;
172 * Enqueue control related scripts/styles.
176 public function enqueue() {}
179 * Check whether control is active to current Customizer preview.
184 * @return bool Whether the control is active to the current preview.
186 public final function active() {
188 $active = call_user_func( $this->active_callback, $this );
191 * Filter response of WP_Customize_Control::active().
195 * @param bool $active Whether the Customizer control is active.
196 * @param WP_Customize_Control $control WP_Customize_Control instance.
198 $active = apply_filters( 'customize_control_active', $active, $control );
204 * Default callback used when invoking WP_Customize_Control::active().
206 * Subclasses can override this with their specific logic, or they may
207 * provide an 'active_callback' argument to the constructor.
212 * @return bool Always true.
214 public function active_callback() {
219 * Fetch a setting's value.
220 * Grabs the main setting by default.
224 * @param string $setting_key
225 * @return mixed The requested setting's value, if the setting exists.
227 public final function value( $setting_key = 'default' ) {
228 if ( isset( $this->settings[ $setting_key ] ) ) {
229 return $this->settings[ $setting_key ]->value();
234 * Refresh the parameters passed to the JavaScript via JSON.
238 public function to_json() {
239 $this->json['settings'] = array();
240 foreach ( $this->settings as $key => $setting ) {
241 $this->json['settings'][ $key ] = $setting->id;
244 $this->json['type'] = $this->type;
245 $this->json['priority'] = $this->priority;
246 $this->json['active'] = $this->active();
247 $this->json['section'] = $this->section;
248 $this->json['content'] = $this->get_content();
249 $this->json['label'] = $this->label;
250 $this->json['description'] = $this->description;
251 $this->json['instanceNumber'] = $this->instance_number;
255 * Get the data to export to the client via JSON.
259 * @return array Array of parameters passed to the JavaScript.
261 public function json() {
267 * Check if the theme supports the control and check user capabilities.
271 * @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
273 public final function check_capabilities() {
274 foreach ( $this->settings as $setting ) {
275 if ( ! $setting->check_capabilities() )
279 $section = $this->manager->get_section( $this->section );
280 if ( isset( $section ) && ! $section->check_capabilities() )
287 * Get the control's content for insertion into the Customizer pane.
291 * @return string Contents of the control.
293 public final function get_content() {
295 $this->maybe_render();
296 $template = trim( ob_get_contents() );
302 * Check capabilities and render the control.
305 * @uses WP_Customize_Control::render()
307 public final function maybe_render() {
308 if ( ! $this->check_capabilities() )
312 * Fires just before the current Customizer control is rendered.
316 * @param WP_Customize_Control $this WP_Customize_Control instance.
318 do_action( 'customize_render_control', $this );
321 * Fires just before a specific Customizer control is rendered.
323 * The dynamic portion of the hook name, `$this->id`, refers to
328 * @param WP_Customize_Control $this {@see WP_Customize_Control} instance.
330 do_action( 'customize_render_control_' . $this->id, $this );
336 * Renders the control wrapper and calls $this->render_content() for the internals.
340 protected function render() {
341 $id = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) );
342 $class = 'customize-control customize-control-' . $this->type;
344 ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>">
345 <?php $this->render_content(); ?>
350 * Get the data link attribute for a setting.
354 * @param string $setting_key
355 * @return string Data link parameter, if $setting_key is a valid setting, empty string otherwise.
357 public function get_link( $setting_key = 'default' ) {
358 if ( ! isset( $this->settings[ $setting_key ] ) )
361 return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
365 * Render the data link attribute for the control's input element.
368 * @uses WP_Customize_Control::get_link()
370 * @param string $setting_key
372 public function link( $setting_key = 'default' ) {
373 echo $this->get_link( $setting_key );
377 * Render the custom attributes for the control's input element.
382 public function input_attrs() {
383 foreach( $this->input_attrs as $attr => $value ) {
384 echo $attr . '="' . esc_attr( $value ) . '" ';
389 * Render the control's content.
391 * Allows the content to be overriden without having to rewrite the wrapper in $this->render().
393 * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
394 * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
396 * Control content can alternately be rendered in JS. See {@see WP_Customize_Control::print_template()}.
400 protected function render_content() {
401 switch( $this->type ) {
405 <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />
406 <?php echo esc_html( $this->label ); ?>
407 <?php if ( ! empty( $this->description ) ) : ?>
408 <span class="description customize-control-description"><?php echo $this->description; ?></span>
414 if ( empty( $this->choices ) )
417 $name = '_customize-radio-' . $this->id;
419 if ( ! empty( $this->label ) ) : ?>
420 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
422 if ( ! empty( $this->description ) ) : ?>
423 <span class="description customize-control-description"><?php echo $this->description ; ?></span>
426 foreach ( $this->choices as $value => $label ) :
429 <input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> />
430 <?php echo esc_html( $label ); ?><br/>
436 if ( empty( $this->choices ) )
441 <?php if ( ! empty( $this->label ) ) : ?>
442 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
444 if ( ! empty( $this->description ) ) : ?>
445 <span class="description customize-control-description"><?php echo $this->description; ?></span>
448 <select <?php $this->link(); ?>>
450 foreach ( $this->choices as $value => $label )
451 echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
460 <?php if ( ! empty( $this->label ) ) : ?>
461 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
463 if ( ! empty( $this->description ) ) : ?>
464 <span class="description customize-control-description"><?php echo $this->description; ?></span>
466 <textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
470 case 'dropdown-pages':
471 $dropdown = wp_dropdown_pages(
473 'name' => '_customize-dropdown-pages-' . $this->id,
475 'show_option_none' => __( '— Select —' ),
476 'option_none_value' => '0',
477 'selected' => $this->value(),
481 // Hackily add in the data link parameter.
482 $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
485 '<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>',
493 <?php if ( ! empty( $this->label ) ) : ?>
494 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
496 if ( ! empty( $this->description ) ) : ?>
497 <span class="description customize-control-description"><?php echo $this->description; ?></span>
499 <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
507 * Render the control's JS template.
509 * This function is only run for control types that have been registered with
510 * {@see WP_Customize_Manager::register_control_type()}.
512 * In the future, this will also print the template for the control's container
513 * element and be override-able.
517 final public function print_template() {
519 <script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content">
520 <?php $this->content_template(); ?>
526 * An Underscore (JS) template for this control's content (but not its container).
528 * Class variables for this control class are available in the `data` JS object;
529 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
531 * @see WP_Customize_Control::print_template()
535 protected function content_template() {}
540 * Customize Color Control Class
543 * @subpackage Customize
546 class WP_Customize_Color_Control extends WP_Customize_Control {
551 public $type = 'color';
563 * @uses WP_Customize_Control::__construct()
565 * @param WP_Customize_Manager $manager
569 public function __construct( $manager, $id, $args = array() ) {
570 $this->statuses = array( '' => __('Default') );
571 parent::__construct( $manager, $id, $args );
575 * Enqueue scripts/styles for the color picker.
579 public function enqueue() {
580 wp_enqueue_script( 'wp-color-picker' );
581 wp_enqueue_style( 'wp-color-picker' );
585 * Refresh the parameters passed to the JavaScript via JSON.
588 * @uses WP_Customize_Control::to_json()
590 public function to_json() {
592 $this->json['statuses'] = $this->statuses;
593 $this->json['defaultValue'] = $this->setting->default;
597 * Don't render the control content from PHP, as it's rendered via JS on load.
601 public function render_content() {}
604 * Render a JS template for the content of the color picker control.
608 public function content_template() {
610 <# var defaultValue = '';
611 if ( data.defaultValue ) {
612 if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
613 defaultValue = '#' + data.defaultValue;
615 defaultValue = data.defaultValue;
617 defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
620 <# if ( data.label ) { #>
621 <span class="customize-control-title">{{{ data.label }}}</span>
623 <# if ( data.description ) { #>
624 <span class="description customize-control-description">{{{ data.description }}}</span>
626 <div class="customize-control-content">
627 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />
635 * Customize Upload Control Class
638 * @subpackage Customize
641 class WP_Customize_Upload_Control extends WP_Customize_Control {
642 public $type = 'upload';
643 public $mime_type = '';
644 public $button_labels = array();
645 public $removed = ''; // unused
646 public $context; // unused
647 public $extensions = array(); // unused
654 * @param WP_Customize_Manager $manager {@see WP_Customize_Manager} instance.
656 public function __construct( $manager, $id, $args = array() ) {
657 parent::__construct( $manager, $id, $args );
659 $this->button_labels = array(
660 'select' => __( 'Select File' ),
661 'change' => __( 'Change File' ),
662 'default' => __( 'Default' ),
663 'remove' => __( 'Remove' ),
664 'placeholder' => __( 'No file selected' ),
665 'frame_title' => __( 'Select File' ),
666 'frame_button' => __( 'Choose File' ),
671 * Enqueue control related scripts/styles.
675 public function enqueue() {
680 * Refresh the parameters passed to the JavaScript via JSON.
683 * @uses WP_Customize_Control::to_json()
685 public function to_json() {
687 $this->json['mime_type'] = $this->mime_type;
688 $this->json['button_labels'] = $this->button_labels;
690 $value = $this->value();
692 if ( is_object( $this->setting ) ) {
693 if ( $this->setting->default ) {
694 // Fake an attachment model - needs all fields used by template.
695 $type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
696 $default_attachment = array(
698 'url' => $this->setting->default,
700 'icon' => wp_mime_type_icon( $type ),
701 'title' => basename( $this->setting->default ),
704 if ( 'image' === $type ) {
705 $default_attachment['sizes'] = array(
706 'full' => array( 'url' => $this->setting->default ),
710 $this->json['defaultAttachment'] = $default_attachment;
713 if ( $value && $this->setting->default && $value === $this->setting->default ) {
714 // Set the default as the attachment.
715 $this->json['attachment'] = $this->json['defaultAttachment'];
716 } elseif ( $value ) {
717 // Get the attachment model for the existing file.
718 $attachment_id = attachment_url_to_postid( $value );
719 if ( $attachment_id ) {
720 $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
727 * Don't render any content for this control from PHP.
729 * @see WP_Customize_Upload_Control::content_template()
732 public function render_content() {}
735 * Render a JS template for the content of the upload control.
739 public function content_template() {
741 <label for="{{ data.settings['default'] }}-button">
742 <# if ( data.label ) { #>
743 <span class="customize-control-title">{{ data.label }}</span>
745 <# if ( data.description ) { #>
746 <span class="description customize-control-description">{{{ data.description }}}</span>
750 <# if ( data.attachment && data.attachment.id ) { #>
751 <div class="current">
752 <div class="container">
753 <div class="attachment-media-view attachment-media-view-{{ data.attachment.type }} {{ data.attachment.orientation }}">
754 <div class="thumbnail thumbnail-{{ data.attachment.type }}">
755 <# if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.medium ) { #>
756 <img class="attachment-thumb" src="{{ data.attachment.sizes.medium.url }}" draggable="false" />
757 <# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #>
758 <img class="attachment-thumb" src="{{ data.attachment.sizes.full.url }}" draggable="false" />
759 <# } else if ( 'audio' === data.attachment.type ) { #>
760 <img class="attachment-thumb type-icon" src="{{ data.attachment.icon }}" class="icon" draggable="false" />
761 <p class="attachment-meta attachment-meta-title">“{{ data.attachment.title }}”</p>
762 <# if ( data.attachment.album || data.attachment.meta.album ) { #>
763 <p class="attachment-meta"><em>{{ data.attachment.album || data.attachment.meta.album }}</em></p>
765 <# if ( data.attachment.artist || data.attachment.meta.artist ) { #>
766 <p class="attachment-meta">{{ data.attachment.artist || data.attachment.meta.artist }}</p>
769 <img class="attachment-thumb type-icon" src="{{ data.attachment.icon }}" class="icon" draggable="false" />
770 <p class="attachment-title">{{ data.attachment.title }}</p>
776 <div class="actions">
777 <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
778 <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['change']; ?></button>
779 <div style="clear:both"></div>
782 <div class="current">
783 <div class="container">
784 <div class="placeholder">
787 <?php echo $this->button_labels['placeholder']; ?>
793 <div class="actions">
794 <# if ( data.defaultAttachment ) { #>
795 <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
797 <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['select']; ?></button>
798 <div style="clear:both"></div>
806 * Customize Image Control Class
809 * @subpackage Customize
812 class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
813 public $type = 'image';
814 public $mime_type = 'image';
820 * @uses WP_Customize_Upload_Control::__construct()
822 * @param WP_Customize_Manager $manager
826 public function __construct( $manager, $id, $args = array() ) {
827 parent::__construct( $manager, $id, $args );
829 $this->button_labels = array(
830 'select' => __( 'Select Image' ),
831 'change' => __( 'Change Image' ),
832 'remove' => __( 'Remove' ),
833 'default' => __( 'Default' ),
834 'placeholder' => __( 'No image selected' ),
835 'frame_title' => __( 'Select Image' ),
836 'frame_button' => __( 'Choose Image' ),
844 public function prepare_control() {}
851 * @param string $label
852 * @param mixed $callback
854 public function add_tab( $id, $label, $callback ) {}
862 public function remove_tab( $id ) {}
869 * @param string $thumbnail_url
871 public function print_tab_image( $url, $thumbnail_url = null ) {}
875 * Customize Background Image Control Class
878 * @subpackage Customize
881 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
882 public $type = 'background';
888 * @uses WP_Customize_Image_Control::__construct()
890 * @param WP_Customize_Manager $manager
892 public function __construct( $manager ) {
893 parent::__construct( $manager, 'background_image', array(
894 'label' => __( 'Background Image' ),
895 'section' => 'background_image',
900 * Enqueue control related scripts/styles.
904 public function enqueue() {
907 wp_localize_script( 'customize-controls', '_wpCustomizeBackground', array(
909 'add' => wp_create_nonce( 'background-add' ),
915 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
916 public $type = 'header';
917 public $uploaded_headers;
918 public $default_headers;
921 * @param WP_Customize_Manager $manager
923 public function __construct( $manager ) {
924 parent::__construct( $manager, 'header_image', array(
925 'label' => __( 'Header Image' ),
927 'default' => 'header_image',
928 'data' => 'header_image_data',
930 'section' => 'header_image',
931 'removed' => 'remove-header',
932 'get_url' => 'get_header_image',
937 public function to_json() {
941 public function enqueue() {
943 wp_enqueue_script( 'customize-views' );
945 $this->prepare_control();
947 wp_localize_script( 'customize-views', '_wpCustomizeHeader', array(
949 'width' => absint( get_theme_support( 'custom-header', 'width' ) ),
950 'height' => absint( get_theme_support( 'custom-header', 'height' ) ),
951 'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),
952 'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),
953 'currentImgSrc' => $this->get_current_image_src(),
956 'add' => wp_create_nonce( 'header-add' ),
957 'remove' => wp_create_nonce( 'header-remove' ),
959 'uploads' => $this->uploaded_headers,
960 'defaults' => $this->default_headers
966 public function prepare_control() {
967 global $custom_image_header;
968 if ( empty( $custom_image_header ) ) {
972 // Process default headers and uploaded headers.
973 $custom_image_header->process_default_headers();
974 $this->default_headers = $custom_image_header->get_default_header_images();
975 $this->uploaded_headers = $custom_image_header->get_uploaded_header_images();
978 function print_header_image_template() {
980 <script type="text/template" id="tmpl-header-choice">
981 <# if (data.random) { #>
982 <button type="button" class="button display-options random">
983 <span class="dashicons dashicons-randomize dice"></span>
984 <# if ( data.type === 'uploaded' ) { #>
985 <?php _e( 'Randomize uploaded headers' ); ?>
986 <# } else if ( data.type === 'default' ) { #>
987 <?php _e( 'Randomize suggested headers' ); ?>
993 <# if (data.type === 'uploaded') { #>
994 <div class="dashicons dashicons-no close"></div>
997 <button type="button" class="choice thumbnail"
998 data-customize-image-value="{{{data.header.url}}}"
999 data-customize-header-image-data="{{JSON.stringify(data.header)}}">
1000 <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
1001 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
1007 <script type="text/template" id="tmpl-header-current">
1008 <# if (data.choice) { #>
1009 <# if (data.random) { #>
1011 <div class="placeholder">
1013 <span><span class="dashicons dashicons-randomize dice"></span>
1014 <# if ( data.type === 'uploaded' ) { #>
1015 <?php _e( 'Randomizing uploaded headers' ); ?>
1016 <# } else if ( data.type === 'default' ) { #>
1017 <?php _e( 'Randomizing suggested headers' ); ?>
1025 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/>
1030 <div class="placeholder">
1033 <?php _e( 'No image set' ); ?>
1043 public function get_current_image_src() {
1044 $src = $this->value();
1045 if ( isset( $this->get_url ) ) {
1046 $src = call_user_func( $this->get_url, $src );
1052 public function render_content() {
1053 $this->print_header_image_template();
1054 $visibility = $this->get_current_image_src() ? '' : ' style="display:none" ';
1055 $width = absint( get_theme_support( 'custom-header', 'width' ) );
1056 $height = absint( get_theme_support( 'custom-header', 'height' ) );
1060 <div class="customize-control-content">
1061 <p class="customizer-section-intro">
1063 if ( $width && $height ) {
1064 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 );
1065 } elseif ( $width ) {
1066 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 );
1068 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 );
1072 <div class="current">
1073 <span class="customize-control-title">
1074 <?php _e( 'Current header' ); ?>
1076 <div class="container">
1079 <div class="actions">
1080 <?php /* translators: Hide as in hide header image via the Customizer */ ?>
1081 <button type="button"<?php echo $visibility ?> class="button remove"><?php _ex( 'Hide image', 'custom header' ); ?></button>
1082 <?php /* translators: New as in add new header image via the Customizer */ ?>
1083 <button type="button" class="button new"><?php _ex( 'Add new image', 'header image' ); ?></button>
1084 <div style="clear:both"></div>
1086 <div class="choices">
1087 <span class="customize-control-title header-previously-uploaded">
1088 <?php _ex( 'Previously uploaded', 'custom headers' ); ?>
1090 <div class="uploaded">
1094 <span class="customize-control-title header-default">
1095 <?php _ex( 'Suggested', 'custom headers' ); ?>
1097 <div class="default">
1108 * Widget Area Customize Control Class
1112 class WP_Widget_Area_Customize_Control extends WP_Customize_Control {
1113 public $type = 'sidebar_widgets';
1116 public function to_json() {
1118 $exported_properties = array( 'sidebar_id' );
1119 foreach ( $exported_properties as $key ) {
1120 $this->json[ $key ] = $this->$key;
1124 public function render_content() {
1126 <span class="button-secondary add-new-widget" tabindex="0">
1127 <?php _e( 'Add a Widget' ); ?>
1130 <span class="reorder-toggle" tabindex="0">
1131 <span class="reorder"><?php _ex( 'Reorder', 'Reorder widgets in Customizer' ); ?></span>
1132 <span class="reorder-done"><?php _ex( 'Done', 'Cancel reordering widgets in Customizer' ); ?></span>
1140 * Widget Form Customize Control Class
1144 class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
1145 public $type = 'widget_form';
1147 public $widget_id_base;
1149 public $is_new = false;
1152 public $is_wide = false;
1154 public function to_json() {
1156 $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
1157 foreach ( $exported_properties as $key ) {
1158 $this->json[ $key ] = $this->$key;
1162 public function render_content() {
1163 global $wp_registered_widgets;
1164 require_once ABSPATH . '/wp-admin/includes/widgets.php';
1166 $widget = $wp_registered_widgets[ $this->widget_id ];
1167 if ( ! isset( $widget['params'][0] ) ) {
1168 $widget['params'][0] = array();
1172 'widget_id' => $widget['id'],
1173 'widget_name' => $widget['name'],
1176 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
1177 echo $this->manager->widgets->get_widget_control( $args );
1181 * Whether the current widget is rendered on the page.
1186 * @return bool Whether the widget is rendered.
1188 function active_callback() {
1189 return $this->manager->widgets->is_widget_rendered( $this->widget_id );