211 $this->$key = $args[ $key ]; |
209 $this->$key = $args[ $key ]; |
212 } |
210 } |
213 } |
211 } |
214 |
212 |
215 $this->manager = $manager; |
213 $this->manager = $manager; |
216 $this->id = $id; |
214 $this->id = $id; |
217 if ( empty( $this->active_callback ) ) { |
215 if ( empty( $this->active_callback ) ) { |
218 $this->active_callback = array( $this, 'active_callback' ); |
216 $this->active_callback = array( $this, 'active_callback' ); |
219 } |
217 } |
220 self::$instance_count += 1; |
218 self::$instance_count += 1; |
221 $this->instance_number = self::$instance_count; |
219 $this->instance_number = self::$instance_count; |
228 $settings = array(); |
226 $settings = array(); |
229 if ( is_array( $this->settings ) ) { |
227 if ( is_array( $this->settings ) ) { |
230 foreach ( $this->settings as $key => $setting ) { |
228 foreach ( $this->settings as $key => $setting ) { |
231 $settings[ $key ] = $this->manager->get_setting( $setting ); |
229 $settings[ $key ] = $this->manager->get_setting( $setting ); |
232 } |
230 } |
233 } else if ( is_string( $this->settings ) ) { |
231 } elseif ( is_string( $this->settings ) ) { |
234 $this->setting = $this->manager->get_setting( $this->settings ); |
232 $this->setting = $this->manager->get_setting( $this->settings ); |
235 $settings['default'] = $this->setting; |
233 $settings['default'] = $this->setting; |
236 } |
234 } |
237 $this->settings = $settings; |
235 $this->settings = $settings; |
238 } |
236 } |
239 |
237 |
251 * |
249 * |
252 * @return bool Whether the control is active to the current preview. |
250 * @return bool Whether the control is active to the current preview. |
253 */ |
251 */ |
254 final public function active() { |
252 final public function active() { |
255 $control = $this; |
253 $control = $this; |
256 $active = call_user_func( $this->active_callback, $this ); |
254 $active = call_user_func( $this->active_callback, $this ); |
257 |
255 |
258 /** |
256 /** |
259 * Filters response of WP_Customize_Control::active(). |
257 * Filters response of WP_Customize_Control::active(). |
260 * |
258 * |
261 * @since 4.0.0 |
259 * @since 4.0.0 |
306 $this->json['settings'] = array(); |
304 $this->json['settings'] = array(); |
307 foreach ( $this->settings as $key => $setting ) { |
305 foreach ( $this->settings as $key => $setting ) { |
308 $this->json['settings'][ $key ] = $setting->id; |
306 $this->json['settings'][ $key ] = $setting->id; |
309 } |
307 } |
310 |
308 |
311 $this->json['type'] = $this->type; |
309 $this->json['type'] = $this->type; |
312 $this->json['priority'] = $this->priority; |
310 $this->json['priority'] = $this->priority; |
313 $this->json['active'] = $this->active(); |
311 $this->json['active'] = $this->active(); |
314 $this->json['section'] = $this->section; |
312 $this->json['section'] = $this->section; |
315 $this->json['content'] = $this->get_content(); |
313 $this->json['content'] = $this->get_content(); |
316 $this->json['label'] = $this->label; |
314 $this->json['label'] = $this->label; |
317 $this->json['description'] = $this->description; |
315 $this->json['description'] = $this->description; |
318 $this->json['instanceNumber'] = $this->instance_number; |
316 $this->json['instanceNumber'] = $this->instance_number; |
319 |
317 |
320 if ( 'dropdown-pages' === $this->type ) { |
318 if ( 'dropdown-pages' === $this->type ) { |
321 $this->json['allow_addition'] = $this->allow_addition; |
319 $this->json['allow_addition'] = $this->allow_addition; |
322 } |
320 } |
478 * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
477 * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
479 * |
478 * |
480 * @since 3.4.0 |
479 * @since 3.4.0 |
481 */ |
480 */ |
482 protected function render_content() { |
481 protected function render_content() { |
483 $input_id = '_customize-input-' . $this->id; |
482 $input_id = '_customize-input-' . $this->id; |
484 $description_id = '_customize-description-' . $this->id; |
483 $description_id = '_customize-description-' . $this->id; |
485 $describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : ''; |
484 $describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : ''; |
486 switch ( $this->type ) { |
485 switch ( $this->type ) { |
487 case 'checkbox': |
486 case 'checkbox': |
488 ?> |
487 ?> |
489 <span class="customize-inside-control-row"> |
488 <span class="customize-inside-control-row"> |
511 ?> |
510 ?> |
512 <?php if ( ! empty( $this->label ) ) : ?> |
511 <?php if ( ! empty( $this->label ) ) : ?> |
513 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
512 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
514 <?php endif; ?> |
513 <?php endif; ?> |
515 <?php if ( ! empty( $this->description ) ) : ?> |
514 <?php if ( ! empty( $this->description ) ) : ?> |
516 <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description ; ?></span> |
515 <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
517 <?php endif; ?> |
516 <?php endif; ?> |
518 |
517 |
519 <?php foreach ( $this->choices as $value => $label ) : ?> |
518 <?php foreach ( $this->choices as $value => $label ) : ?> |
520 <span class="customize-inside-control-row"> |
519 <span class="customize-inside-control-row"> |
521 <input |
520 <input |
565 <textarea |
564 <textarea |
566 id="<?php echo esc_attr( $input_id ); ?>" |
565 id="<?php echo esc_attr( $input_id ); ?>" |
567 rows="5" |
566 rows="5" |
568 <?php echo $describedby_attr; ?> |
567 <?php echo $describedby_attr; ?> |
569 <?php $this->input_attrs(); ?> |
568 <?php $this->input_attrs(); ?> |
570 <?php $this->link(); ?>> |
569 <?php $this->link(); ?> |
571 <?php echo esc_textarea( $this->value() ); ?> |
570 ><?php echo esc_textarea( $this->value() ); ?></textarea> |
572 </textarea> |
|
573 <?php |
571 <?php |
574 break; |
572 break; |
575 case 'dropdown-pages': |
573 case 'dropdown-pages': |
576 ?> |
574 ?> |
577 <?php if ( ! empty( $this->label ) ) : ?> |
575 <?php if ( ! empty( $this->label ) ) : ?> |
580 <?php if ( ! empty( $this->description ) ) : ?> |
578 <?php if ( ! empty( $this->description ) ) : ?> |
581 <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
579 <span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span> |
582 <?php endif; ?> |
580 <?php endif; ?> |
583 |
581 |
584 <?php |
582 <?php |
585 $dropdown_name = '_customize-dropdown-pages-' . $this->id; |
583 $dropdown_name = '_customize-dropdown-pages-' . $this->id; |
586 $show_option_none = __( '— Select —' ); |
584 $show_option_none = __( '— Select —' ); |
587 $option_none_value = '0'; |
585 $option_none_value = '0'; |
588 $dropdown = wp_dropdown_pages( |
586 $dropdown = wp_dropdown_pages( |
589 array( |
587 array( |
590 'name' => $dropdown_name, |
588 'name' => $dropdown_name, |
591 'echo' => 0, |
589 'echo' => 0, |
592 'show_option_none' => $show_option_none, |
590 'show_option_none' => $show_option_none, |
593 'option_none_value' => $option_none_value, |
591 'option_none_value' => $option_none_value, |
594 'selected' => $this->value(), |
592 'selected' => $this->value(), |
595 ) |
593 ) |
596 ); |
594 ); |
597 if ( empty( $dropdown ) ) { |
595 if ( empty( $dropdown ) ) { |
598 $dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) ); |
596 $dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) ); |
599 $dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) ); |
597 $dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) ); |
600 $dropdown .= '</select>'; |
598 $dropdown .= '</select>'; |
601 } |
599 } |
602 |
600 |
603 // Hackily add in the data link parameter. |
601 // Hackily add in the data link parameter. |