362 * @uses WP_Customize_Control::to_json() |
594 * @uses WP_Customize_Control::to_json() |
363 */ |
595 */ |
364 public function to_json() { |
596 public function to_json() { |
365 parent::to_json(); |
597 parent::to_json(); |
366 $this->json['statuses'] = $this->statuses; |
598 $this->json['statuses'] = $this->statuses; |
367 } |
599 $this->json['defaultValue'] = $this->setting->default; |
368 |
600 } |
369 /** |
601 |
370 * Render the control's content. |
602 /** |
371 * |
603 * Don't render the control content from PHP, as it's rendered via JS on load. |
372 * @since 3.4.0 |
604 * |
373 */ |
605 * @since 3.4.0 |
374 public function render_content() { |
606 */ |
375 $this_default = $this->setting->default; |
607 public function render_content() {} |
376 $default_attr = ''; |
608 |
377 if ( $this_default ) { |
609 /** |
378 if ( false === strpos( $this_default, '#' ) ) |
610 * Render a JS template for the content of the color picker control. |
379 $this_default = '#' . $this_default; |
611 * |
380 $default_attr = ' data-default-color="' . esc_attr( $this_default ) . '"'; |
612 * @since 4.1.0 |
381 } |
613 */ |
382 // The input's value gets set by JS. Don't fill it. |
614 public function content_template() { |
383 ?> |
615 ?> |
|
616 <# var defaultValue = ''; |
|
617 if ( data.defaultValue ) { |
|
618 if ( '#' !== data.defaultValue.substring( 0, 1 ) ) { |
|
619 defaultValue = '#' + data.defaultValue; |
|
620 } else { |
|
621 defaultValue = data.defaultValue; |
|
622 } |
|
623 defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
|
624 } #> |
384 <label> |
625 <label> |
385 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
626 <# if ( data.label ) { #> |
|
627 <span class="customize-control-title">{{{ data.label }}}</span> |
|
628 <# } #> |
|
629 <# if ( data.description ) { #> |
|
630 <span class="description customize-control-description">{{{ data.description }}}</span> |
|
631 <# } #> |
386 <div class="customize-control-content"> |
632 <div class="customize-control-content"> |
387 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>"<?php echo $default_attr; ?> /> |
633 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} /> |
388 </div> |
634 </div> |
389 </label> |
635 </label> |
390 <?php |
636 <?php |
391 } |
637 } |
392 } |
638 } |
393 |
639 |
394 /** |
640 /** |
395 * Customize Upload Control Class |
641 * Customize Media Control class. |
396 * |
642 * |
397 * @package WordPress |
643 * @since 4.2.0 |
398 * @subpackage Customize |
644 * |
399 * @since 3.4.0 |
645 * @see WP_Customize_Control |
400 */ |
646 */ |
401 class WP_Customize_Upload_Control extends WP_Customize_Control { |
647 class WP_Customize_Media_Control extends WP_Customize_Control { |
402 public $type = 'upload'; |
648 /** |
403 public $removed = ''; |
649 * Control type. |
404 public $context; |
650 * |
405 public $extensions = array(); |
651 * @since 4.2.0 |
|
652 * @access public |
|
653 * @var string |
|
654 */ |
|
655 public $type = 'media'; |
|
656 |
|
657 /** |
|
658 * Media control mime type. |
|
659 * |
|
660 * @since 4.2.0 |
|
661 * @access public |
|
662 * @var string |
|
663 */ |
|
664 public $mime_type = ''; |
|
665 |
|
666 /** |
|
667 * Button labels. |
|
668 * |
|
669 * @since 4.2.0 |
|
670 * @access public |
|
671 * @var array |
|
672 */ |
|
673 public $button_labels = array(); |
|
674 |
|
675 /** |
|
676 * Constructor. |
|
677 * |
|
678 * @since 4.1.0 |
|
679 * @since 4.2.0 Moved from WP_Customize_Upload_Control. |
|
680 * |
|
681 * @param WP_Customize_Manager $manager {@see WP_Customize_Manager} instance. |
|
682 */ |
|
683 public function __construct( $manager, $id, $args = array() ) { |
|
684 parent::__construct( $manager, $id, $args ); |
|
685 |
|
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' ), |
|
694 ); |
|
695 } |
406 |
696 |
407 /** |
697 /** |
408 * Enqueue control related scripts/styles. |
698 * Enqueue control related scripts/styles. |
409 * |
699 * |
410 * @since 3.4.0 |
700 * @since 3.4.0 |
|
701 * @since 4.2.0 Moved from WP_Customize_Upload_Control. |
411 */ |
702 */ |
412 public function enqueue() { |
703 public function enqueue() { |
413 wp_enqueue_script( 'wp-plupload' ); |
704 wp_enqueue_media(); |
414 } |
705 } |
415 |
706 |
416 /** |
707 /** |
417 * Refresh the parameters passed to the JavaScript via JSON. |
708 * Refresh the parameters passed to the JavaScript via JSON. |
418 * |
709 * |
419 * @since 3.4.0 |
710 * @since 3.4.0 |
420 * @uses WP_Customize_Control::to_json() |
711 * @since 4.2.0 Moved from WP_Customize_Upload_Control. |
|
712 * |
|
713 * @see WP_Customize_Control::to_json() |
421 */ |
714 */ |
422 public function to_json() { |
715 public function to_json() { |
423 parent::to_json(); |
716 parent::to_json(); |
424 |
717 $this->json['mime_type'] = $this->mime_type; |
425 $this->json['removed'] = $this->removed; |
718 $this->json['button_labels'] = $this->button_labels; |
426 |
719 |
427 if ( $this->context ) |
720 $value = $this->value(); |
428 $this->json['context'] = $this->context; |
721 |
429 |
722 if ( is_object( $this->setting ) ) { |
430 if ( $this->extensions ) |
723 if ( $this->setting->default ) { |
431 $this->json['extensions'] = implode( ',', $this->extensions ); |
724 // Fake an attachment model - needs all fields used by template. |
432 } |
725 // Note that the default value must be a URL, NOT an attachment ID. |
433 |
726 $type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document'; |
434 /** |
727 $default_attachment = array( |
435 * Render the control's content. |
728 'id' => 1, |
436 * |
729 'url' => $this->setting->default, |
437 * @since 3.4.0 |
730 'type' => $type, |
438 */ |
731 'icon' => wp_mime_type_icon( $type ), |
439 public function render_content() { |
732 'title' => basename( $this->setting->default ), |
|
733 ); |
|
734 |
|
735 if ( 'image' === $type ) { |
|
736 $default_attachment['sizes'] = array( |
|
737 'full' => array( 'url' => $this->setting->default ), |
|
738 ); |
|
739 } |
|
740 |
|
741 $this->json['defaultAttachment'] = $default_attachment; |
|
742 } |
|
743 |
|
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 ); |
|
749 } |
|
750 } |
|
751 } |
|
752 |
|
753 /** |
|
754 * Don't render any content for this control from PHP. |
|
755 * |
|
756 * @since 3.4.0 |
|
757 * @since 4.2.0 Moved from WP_Customize_Upload_Control. |
|
758 * |
|
759 * @see WP_Customize_Media_Control::content_template() |
|
760 */ |
|
761 public function render_content() {} |
|
762 |
|
763 /** |
|
764 * Render a JS template for the content of the media control. |
|
765 * |
|
766 * @since 4.1.0 |
|
767 * @since 4.2.0 Moved from WP_Customize_Upload_Control. |
|
768 */ |
|
769 public function content_template() { |
440 ?> |
770 ?> |
441 <label> |
771 <label for="{{ data.settings['default'] }}-button"> |
442 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
772 <# if ( data.label ) { #> |
443 <div> |
773 <span class="customize-control-title">{{ data.label }}</span> |
444 <a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a> |
774 <# } #> |
445 <a href="#" class="remove"><?php _e( 'Remove' ); ?></a> |
775 <# if ( data.description ) { #> |
|
776 <span class="description customize-control-description">{{{ data.description }}}</span> |
|
777 <# } #> |
|
778 </label> |
|
779 |
|
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" /> |
|
792 <# } else { #> |
|
793 <img src="{{ data.attachment.icon }}" class="attachment-thumb type-icon" draggable="false" /> |
|
794 <# } #> |
|
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> |
|
798 <# } #> |
|
799 <# if ( data.attachment.artist || data.attachment.meta.artist ) { #> |
|
800 <p class="attachment-meta">{{ data.attachment.artist || data.attachment.meta.artist }}</p> |
|
801 <# } #> |
|
802 <audio style="visibility: hidden" controls class="wp-audio-shortcode" width="100%" preload="none"> |
|
803 <source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}"/> |
|
804 </audio> |
|
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 }}"/> |
|
810 </video> |
|
811 </div> |
|
812 <# } else { #> |
|
813 <img class="attachment-thumb type-icon" src="{{ data.attachment.icon }}" class="icon" draggable="false" /> |
|
814 <p class="attachment-title">{{ data.attachment.title }}</p> |
|
815 <# } #> |
|
816 </div> |
|
817 </div> |
|
818 </div> |
446 </div> |
819 </div> |
447 </label> |
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> |
|
824 </div> |
|
825 <# } else { #> |
|
826 <div class="current"> |
|
827 <div class="container"> |
|
828 <div class="placeholder"> |
|
829 <div class="inner"> |
|
830 <span> |
|
831 <?php echo $this->button_labels['placeholder']; ?> |
|
832 </span> |
|
833 </div> |
|
834 </div> |
|
835 </div> |
|
836 </div> |
|
837 <div class="actions"> |
|
838 <# if ( data.defaultAttachment ) { #> |
|
839 <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button> |
|
840 <# } #> |
|
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> |
|
843 </div> |
|
844 <# } #> |
448 <?php |
845 <?php |
449 } |
846 } |
450 } |
847 } |
451 |
848 |
452 /** |
849 /** |
453 * Customize Image Control Class |
850 * Customize Upload Control Class. |
454 * |
851 * |
455 * @package WordPress |
|
456 * @subpackage Customize |
|
457 * @since 3.4.0 |
852 * @since 3.4.0 |
|
853 * |
|
854 * @see WP_Customize_Media_Control |
|
855 */ |
|
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 |
|
863 |
|
864 /** |
|
865 * Refresh the parameters passed to the JavaScript via JSON. |
|
866 * |
|
867 * @since 3.4.0 |
|
868 * |
|
869 * @uses WP_Customize_Media_Control::to_json() |
|
870 */ |
|
871 public function to_json() { |
|
872 parent::to_json(); |
|
873 |
|
874 $value = $this->value(); |
|
875 if ( $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 ); |
|
880 } |
|
881 } |
|
882 } |
|
883 } |
|
884 |
|
885 /** |
|
886 * Customize Image Control class. |
|
887 * |
|
888 * @since 3.4.0 |
|
889 * |
|
890 * @see WP_Customize_Upload_Control |
458 */ |
891 */ |
459 class WP_Customize_Image_Control extends WP_Customize_Upload_Control { |
892 class WP_Customize_Image_Control extends WP_Customize_Upload_Control { |
460 public $type = 'image'; |
893 public $type = 'image'; |
461 public $get_url; |
894 public $mime_type = 'image'; |
462 public $statuses; |
|
463 public $extensions = array( 'jpg', 'jpeg', 'gif', 'png' ); |
|
464 |
|
465 protected $tabs = array(); |
|
466 |
895 |
467 /** |
896 /** |
468 * Constructor. |
897 * Constructor. |
469 * |
|
470 * If $args['settings'] is not defined, use the $id as the setting ID. |
|
471 * |
898 * |
472 * @since 3.4.0 |
899 * @since 3.4.0 |
473 * @uses WP_Customize_Upload_Control::__construct() |
900 * @uses WP_Customize_Upload_Control::__construct() |
474 * |
901 * |
475 * @param WP_Customize_Manager $manager |
902 * @param WP_Customize_Manager $manager |
476 * @param string $id |
903 * @param string $id |
477 * @param array $args |
904 * @param array $args |
478 */ |
905 */ |
479 public function __construct( $manager, $id, $args ) { |
906 public function __construct( $manager, $id, $args = array() ) { |
480 $this->statuses = array( '' => __('No Image') ); |
|
481 |
|
482 parent::__construct( $manager, $id, $args ); |
907 parent::__construct( $manager, $id, $args ); |
483 |
908 |
484 $this->add_tab( 'upload-new', __('Upload New'), array( $this, 'tab_upload_new' ) ); |
909 $this->button_labels = array( |
485 $this->add_tab( 'uploaded', __('Uploaded'), array( $this, 'tab_uploaded' ) ); |
910 'select' => __( 'Select Image' ), |
486 |
911 'change' => __( 'Change Image' ), |
487 // Early priority to occur before $this->manager->prepare_controls(); |
912 'remove' => __( 'Remove' ), |
488 add_action( 'customize_controls_init', array( $this, 'prepare_control' ), 5 ); |
913 'default' => __( 'Default' ), |
489 } |
914 'placeholder' => __( 'No image selected' ), |
490 |
915 'frame_title' => __( 'Select Image' ), |
491 /** |
916 'frame_button' => __( 'Choose Image' ), |
492 * Prepares the control. |
917 ); |
493 * |
918 } |
494 * If no tabs exist, removes the control from the manager. |
919 |
495 * |
920 /** |
496 * @since 3.4.2 |
921 * @since 3.4.2 |
497 */ |
922 * @deprecated 4.1.0 |
498 public function prepare_control() { |
923 */ |
499 if ( ! $this->tabs ) |
924 public function prepare_control() {} |
500 $this->manager->remove_control( $this->id ); |
925 |
501 } |
926 /** |
502 |
927 * @since 3.4.0 |
503 /** |
928 * @deprecated 4.1.0 |
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 */ |
|
509 public function to_json() { |
|
510 parent::to_json(); |
|
511 $this->json['statuses'] = $this->statuses; |
|
512 } |
|
513 |
|
514 /** |
|
515 * Render the control's content. |
|
516 * |
|
517 * @since 3.4.0 |
|
518 */ |
|
519 public function render_content() { |
|
520 $src = $this->value(); |
|
521 if ( isset( $this->get_url ) ) |
|
522 $src = call_user_func( $this->get_url, $src ); |
|
523 |
|
524 ?> |
|
525 <div class="customize-image-picker"> |
|
526 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
527 |
|
528 <div class="customize-control-content"> |
|
529 <div class="dropdown preview-thumbnail" tabindex="0"> |
|
530 <div class="dropdown-content"> |
|
531 <?php if ( empty( $src ) ): ?> |
|
532 <img style="display:none;" /> |
|
533 <?php else: ?> |
|
534 <img src="<?php echo esc_url( set_url_scheme( $src ) ); ?>" /> |
|
535 <?php endif; ?> |
|
536 <div class="dropdown-status"></div> |
|
537 </div> |
|
538 <div class="dropdown-arrow"></div> |
|
539 </div> |
|
540 </div> |
|
541 |
|
542 <div class="library"> |
|
543 <ul> |
|
544 <?php foreach ( $this->tabs as $id => $tab ): ?> |
|
545 <li data-customize-tab='<?php echo esc_attr( $id ); ?>' tabindex='0'> |
|
546 <?php echo esc_html( $tab['label'] ); ?> |
|
547 </li> |
|
548 <?php endforeach; ?> |
|
549 </ul> |
|
550 <?php foreach ( $this->tabs as $id => $tab ): ?> |
|
551 <div class="library-content" data-customize-tab='<?php echo esc_attr( $id ); ?>'> |
|
552 <?php call_user_func( $tab['callback'] ); ?> |
|
553 </div> |
|
554 <?php endforeach; ?> |
|
555 </div> |
|
556 |
|
557 <div class="actions"> |
|
558 <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a> |
|
559 </div> |
|
560 </div> |
|
561 <?php |
|
562 } |
|
563 |
|
564 /** |
|
565 * Add a tab to the control. |
|
566 * |
|
567 * @since 3.4.0 |
|
568 * |
929 * |
569 * @param string $id |
930 * @param string $id |
570 * @param string $label |
931 * @param string $label |
571 * @param mixed $callback |
932 * @param mixed $callback |
572 */ |
933 */ |
573 public function add_tab( $id, $label, $callback ) { |
934 public function add_tab( $id, $label, $callback ) {} |
574 $this->tabs[ $id ] = array( |
935 |
575 'label' => $label, |
936 /** |
576 'callback' => $callback, |
937 * @since 3.4.0 |
577 ); |
938 * @deprecated 4.1.0 |
578 } |
|
579 |
|
580 /** |
|
581 * Remove a tab from the control. |
|
582 * |
|
583 * @since 3.4.0 |
|
584 * |
939 * |
585 * @param string $id |
940 * @param string $id |
586 */ |
941 */ |
587 public function remove_tab( $id ) { |
942 public function remove_tab( $id ) {} |
588 unset( $this->tabs[ $id ] ); |
943 |
589 } |
944 /** |
590 |
945 * @since 3.4.0 |
591 /** |
946 * @deprecated 4.1.0 |
592 * @since 3.4.0 |
|
593 */ |
|
594 public function tab_upload_new() { |
|
595 if ( ! _device_can_upload() ) { |
|
596 echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'http://wordpress.org/mobile/' ) . '</p>'; |
|
597 } else { |
|
598 ?> |
|
599 <div class="upload-dropzone"> |
|
600 <?php _e('Drop a file here or <a href="#" class="upload">select a file</a>.'); ?> |
|
601 </div> |
|
602 <div class="upload-fallback"> |
|
603 <span class="button-secondary"><?php _e('Select File'); ?></span> |
|
604 </div> |
|
605 <?php |
|
606 } |
|
607 } |
|
608 |
|
609 /** |
|
610 * @since 3.4.0 |
|
611 */ |
|
612 public function tab_uploaded() { |
|
613 ?> |
|
614 <div class="uploaded-target"></div> |
|
615 <?php |
|
616 } |
|
617 |
|
618 /** |
|
619 * @since 3.4.0 |
|
620 * |
947 * |
621 * @param string $url |
948 * @param string $url |
622 * @param string $thumbnail_url |
949 * @param string $thumbnail_url |
623 */ |
950 */ |
624 public function print_tab_image( $url, $thumbnail_url = null ) { |
951 public function print_tab_image( $url, $thumbnail_url = null ) {} |
625 $url = set_url_scheme( $url ); |
|
626 $thumbnail_url = ( $thumbnail_url ) ? set_url_scheme( $thumbnail_url ) : $url; |
|
627 ?> |
|
628 <a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $url ); ?>"> |
|
629 <img src="<?php echo esc_url( $thumbnail_url ); ?>" /> |
|
630 </a> |
|
631 <?php |
|
632 } |
|
633 } |
952 } |
634 |
953 |
635 /** |
954 /** |
636 * Customize Background Image Control Class |
955 * Customize Background Image Control class. |
637 * |
956 * |
638 * @package WordPress |
|
639 * @subpackage Customize |
|
640 * @since 3.4.0 |
957 * @since 3.4.0 |
|
958 * |
|
959 * @see WP_Customize_Image_Control |
641 */ |
960 */ |
642 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { |
961 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { |
|
962 public $type = 'background'; |
643 |
963 |
644 /** |
964 /** |
645 * Constructor. |
965 * Constructor. |
646 * |
966 * |
647 * @since 3.4.0 |
967 * @since 3.4.0 |
651 */ |
971 */ |
652 public function __construct( $manager ) { |
972 public function __construct( $manager ) { |
653 parent::__construct( $manager, 'background_image', array( |
973 parent::__construct( $manager, 'background_image', array( |
654 'label' => __( 'Background Image' ), |
974 'label' => __( 'Background Image' ), |
655 'section' => 'background_image', |
975 'section' => 'background_image', |
656 'context' => 'custom-background', |
|
657 'get_url' => 'get_background_image', |
|
658 ) ); |
976 ) ); |
659 |
977 } |
660 if ( $this->setting->default ) |
978 |
661 $this->add_tab( 'default', __('Default'), array( $this, 'tab_default_background' ) ); |
979 /** |
662 } |
980 * Enqueue control related scripts/styles. |
663 |
981 * |
664 /** |
982 * @since 4.1.0 |
665 * @since 3.4.0 |
983 */ |
666 */ |
984 public function enqueue() { |
667 public function tab_uploaded() { |
985 parent::enqueue(); |
668 $backgrounds = get_posts( array( |
986 |
669 'post_type' => 'attachment', |
987 wp_localize_script( 'customize-controls', '_wpCustomizeBackground', array( |
670 'meta_key' => '_wp_attachment_is_custom_background', |
988 'nonces' => array( |
671 'meta_value' => $this->manager->get_stylesheet(), |
989 'add' => wp_create_nonce( 'background-add' ), |
672 'orderby' => 'none', |
990 ), |
673 'nopaging' => true, |
|
674 ) ); |
991 ) ); |
675 |
|
676 ?><div class="uploaded-target"></div><?php |
|
677 |
|
678 if ( empty( $backgrounds ) ) |
|
679 return; |
|
680 |
|
681 foreach ( (array) $backgrounds as $background ) |
|
682 $this->print_tab_image( esc_url_raw( $background->guid ) ); |
|
683 } |
|
684 |
|
685 /** |
|
686 * @since 3.4.0 |
|
687 * @uses WP_Customize_Image_Control::print_tab_image() |
|
688 */ |
|
689 public function tab_default_background() { |
|
690 $this->print_tab_image( $this->setting->default ); |
|
691 } |
992 } |
692 } |
993 } |
693 |
994 |
694 /** |
995 /** |
695 * Customize Header Image Control Class |
996 * Customize Header Image Control class. |
696 * |
997 * |
697 * @package WordPress |
|
698 * @subpackage Customize |
|
699 * @since 3.4.0 |
998 * @since 3.4.0 |
|
999 * |
|
1000 * @see WP_Customize_Image_Control |
700 */ |
1001 */ |
701 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { |
1002 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { |
702 /** |
1003 public $type = 'header'; |
703 * The processed default headers. |
1004 public $uploaded_headers; |
704 * @since 3.4.2 |
1005 public $default_headers; |
705 * @var array |
1006 |
706 */ |
1007 /** |
707 protected $default_headers; |
|
708 |
|
709 /** |
|
710 * The uploaded headers. |
|
711 * @since 3.4.2 |
|
712 * @var array |
|
713 */ |
|
714 protected $uploaded_headers; |
|
715 |
|
716 /** |
|
717 * Constructor. |
|
718 * |
|
719 * @since 3.4.0 |
|
720 * @uses WP_Customize_Image_Control::__construct() |
|
721 * @uses WP_Customize_Image_Control::add_tab() |
|
722 * |
|
723 * @param WP_Customize_Manager $manager |
1008 * @param WP_Customize_Manager $manager |
724 */ |
1009 */ |
725 public function __construct( $manager ) { |
1010 public function __construct( $manager ) { |
726 parent::__construct( $manager, 'header_image', array( |
1011 parent::__construct( $manager, 'header_image', array( |
727 'label' => __( 'Header Image' ), |
1012 'label' => __( 'Header Image' ), |
728 'settings' => array( |
1013 'settings' => array( |
729 'default' => 'header_image', |
1014 'default' => 'header_image', |
730 'data' => 'header_image_data', |
1015 'data' => 'header_image_data', |
731 ), |
1016 ), |
732 'section' => 'header_image', |
1017 'section' => 'header_image', |
733 'context' => 'custom-header', |
|
734 'removed' => 'remove-header', |
1018 'removed' => 'remove-header', |
735 'get_url' => 'get_header_image', |
1019 'get_url' => 'get_header_image', |
736 'statuses' => array( |
|
737 '' => __('Default'), |
|
738 'remove-header' => __('No Image'), |
|
739 'random-default-image' => __('Random Default Image'), |
|
740 'random-uploaded-image' => __('Random Uploaded Image'), |
|
741 ) |
|
742 ) ); |
1020 ) ); |
743 |
1021 |
744 // Remove the upload tab. |
1022 } |
745 $this->remove_tab( 'upload-new' ); |
1023 |
746 } |
1024 public function enqueue() { |
747 |
1025 wp_enqueue_media(); |
748 /** |
1026 wp_enqueue_script( 'customize-views' ); |
749 * Prepares the control. |
1027 |
750 * |
1028 $this->prepare_control(); |
751 * If no tabs exist, removes the control from the manager. |
1029 |
752 * |
1030 wp_localize_script( 'customize-views', '_wpCustomizeHeader', array( |
753 * @since 3.4.2 |
1031 'data' => array( |
754 */ |
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(), |
|
1037 ), |
|
1038 'nonces' => array( |
|
1039 'add' => wp_create_nonce( 'header-add' ), |
|
1040 'remove' => wp_create_nonce( 'header-remove' ), |
|
1041 ), |
|
1042 'uploads' => $this->uploaded_headers, |
|
1043 'defaults' => $this->default_headers |
|
1044 ) ); |
|
1045 |
|
1046 parent::enqueue(); |
|
1047 } |
|
1048 |
755 public function prepare_control() { |
1049 public function prepare_control() { |
756 global $custom_image_header; |
1050 global $custom_image_header; |
757 if ( empty( $custom_image_header ) ) |
1051 if ( empty( $custom_image_header ) ) { |
758 return parent::prepare_control(); |
1052 return; |
|
1053 } |
759 |
1054 |
760 // Process default headers and uploaded headers. |
1055 // Process default headers and uploaded headers. |
761 $custom_image_header->process_default_headers(); |
1056 $custom_image_header->process_default_headers(); |
762 $this->default_headers = $custom_image_header->default_headers; |
1057 $this->default_headers = $custom_image_header->get_default_header_images(); |
763 $this->uploaded_headers = get_uploaded_header_images(); |
1058 $this->uploaded_headers = $custom_image_header->get_uploaded_header_images(); |
764 |
1059 } |
765 if ( $this->default_headers ) |
1060 |
766 $this->add_tab( 'default', __('Default'), array( $this, 'tab_default_headers' ) ); |
1061 public function print_header_image_template() { |
767 |
|
768 if ( ! $this->uploaded_headers ) |
|
769 $this->remove_tab( 'uploaded' ); |
|
770 |
|
771 return parent::prepare_control(); |
|
772 } |
|
773 |
|
774 /** |
|
775 * @since 3.4.0 |
|
776 * |
|
777 * @param mixed $choice Which header image to select. (@see Custom_Image_Header::get_header_image() ) |
|
778 * @param array $header |
|
779 */ |
|
780 public function print_header_image( $choice, $header ) { |
|
781 $header['url'] = set_url_scheme( $header['url'] ); |
|
782 $header['thumbnail_url'] = set_url_scheme( $header['thumbnail_url'] ); |
|
783 |
|
784 $header_image_data = array( 'choice' => $choice ); |
|
785 foreach ( array( 'attachment_id', 'width', 'height', 'url', 'thumbnail_url' ) as $key ) { |
|
786 if ( isset( $header[ $key ] ) ) |
|
787 $header_image_data[ $key ] = $header[ $key ]; |
|
788 } |
|
789 |
|
790 |
|
791 ?> |
1062 ?> |
792 <a href="#" class="thumbnail" |
1063 <script type="text/template" id="tmpl-header-choice"> |
793 data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>" |
1064 <# if (data.random) { #> |
794 data-customize-header-image-data="<?php echo esc_attr( json_encode( $header_image_data ) ); ?>"> |
1065 <button type="button" class="button display-options random"> |
795 <img src="<?php echo esc_url( $header['thumbnail_url'] ); ?>" /> |
1066 <span class="dashicons dashicons-randomize dice"></span> |
796 </a> |
1067 <# if ( data.type === 'uploaded' ) { #> |
|
1068 <?php _e( 'Randomize uploaded headers' ); ?> |
|
1069 <# } else if ( data.type === 'default' ) { #> |
|
1070 <?php _e( 'Randomize suggested headers' ); ?> |
|
1071 <# } #> |
|
1072 </button> |
|
1073 |
|
1074 <# } else { #> |
|
1075 |
|
1076 <# if (data.type === 'uploaded') { #> |
|
1077 <div class="dashicons dashicons-no close"></div> |
|
1078 <# } #> |
|
1079 |
|
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}}}"> |
|
1085 </button> |
|
1086 |
|
1087 <# } #> |
|
1088 </script> |
|
1089 |
|
1090 <script type="text/template" id="tmpl-header-current"> |
|
1091 <# if (data.choice) { #> |
|
1092 <# if (data.random) { #> |
|
1093 |
|
1094 <div class="placeholder"> |
|
1095 <div class="inner"> |
|
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' ); ?> |
|
1101 <# } #> |
|
1102 </span> |
|
1103 </div> |
|
1104 </div> |
|
1105 |
|
1106 <# } else { #> |
|
1107 |
|
1108 <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/> |
|
1109 |
|
1110 <# } #> |
|
1111 <# } else { #> |
|
1112 |
|
1113 <div class="placeholder"> |
|
1114 <div class="inner"> |
|
1115 <span> |
|
1116 <?php _e( 'No image set' ); ?> |
|
1117 </span> |
|
1118 </div> |
|
1119 </div> |
|
1120 |
|
1121 <# } #> |
|
1122 </script> |
797 <?php |
1123 <?php |
798 } |
1124 } |
799 |
1125 |
800 /** |
1126 public function get_current_image_src() { |
801 * @since 3.4.0 |
1127 $src = $this->value(); |
802 */ |
1128 if ( isset( $this->get_url ) ) { |
803 public function tab_uploaded() { |
1129 $src = call_user_func( $this->get_url, $src ); |
804 ?><div class="uploaded-target"></div><?php |
1130 return $src; |
805 |
1131 } |
806 foreach ( $this->uploaded_headers as $choice => $header ) |
1132 return null; |
807 $this->print_header_image( $choice, $header ); |
1133 } |
808 } |
1134 |
809 |
1135 public function render_content() { |
810 /** |
1136 $this->print_header_image_template(); |
811 * @since 3.4.0 |
1137 $visibility = $this->get_current_image_src() ? '' : ' style="display:none" '; |
812 */ |
1138 $width = absint( get_theme_support( 'custom-header', 'width' ) ); |
813 public function tab_default_headers() { |
1139 $height = absint( get_theme_support( 'custom-header', 'height' ) ); |
814 foreach ( $this->default_headers as $choice => $header ) |
1140 ?> |
815 $this->print_header_image( $choice, $header ); |
1141 |
|
1142 |
|
1143 <div class="customize-control-content"> |
|
1144 <p class="customizer-section-intro"> |
|
1145 <?php |
|
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 ); |
|
1150 } else { |
|
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 ); |
|
1152 } |
|
1153 ?> |
|
1154 </p> |
|
1155 <div class="current"> |
|
1156 <span class="customize-control-title"> |
|
1157 <?php _e( 'Current header' ); ?> |
|
1158 </span> |
|
1159 <div class="container"> |
|
1160 </div> |
|
1161 </div> |
|
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> |
|
1168 </div> |
|
1169 <div class="choices"> |
|
1170 <span class="customize-control-title header-previously-uploaded"> |
|
1171 <?php _ex( 'Previously uploaded', 'custom headers' ); ?> |
|
1172 </span> |
|
1173 <div class="uploaded"> |
|
1174 <div class="list"> |
|
1175 </div> |
|
1176 </div> |
|
1177 <span class="customize-control-title header-default"> |
|
1178 <?php _ex( 'Suggested', 'custom headers' ); ?> |
|
1179 </span> |
|
1180 <div class="default"> |
|
1181 <div class="list"> |
|
1182 </div> |
|
1183 </div> |
|
1184 </div> |
|
1185 </div> |
|
1186 <?php |
816 } |
1187 } |
817 } |
1188 } |
|
1189 |
|
1190 /** |
|
1191 * Customize Theme Control class. |
|
1192 * |
|
1193 * @since 4.2.0 |
|
1194 * |
|
1195 * @see WP_Customize_Control |
|
1196 */ |
|
1197 class WP_Customize_Theme_Control extends WP_Customize_Control { |
|
1198 |
|
1199 /** |
|
1200 * Customize control type. |
|
1201 * |
|
1202 * @since 4.2.0 |
|
1203 * @access public |
|
1204 * @var string |
|
1205 */ |
|
1206 public $type = 'theme'; |
|
1207 |
|
1208 /** |
|
1209 * Theme object. |
|
1210 * |
|
1211 * @since 4.2.0 |
|
1212 * @access public |
|
1213 * @var WP_Theme |
|
1214 */ |
|
1215 public $theme; |
|
1216 |
|
1217 /** |
|
1218 * Refresh the parameters passed to the JavaScript via JSON. |
|
1219 * |
|
1220 * @since 4.2.0 |
|
1221 * @access public |
|
1222 * |
|
1223 * @see WP_Customize_Control::to_json() |
|
1224 */ |
|
1225 public function to_json() { |
|
1226 parent::to_json(); |
|
1227 $this->json['theme'] = $this->theme; |
|
1228 } |
|
1229 |
|
1230 /** |
|
1231 * Don't render the control content from PHP, as it's rendered via JS on load. |
|
1232 * |
|
1233 * @since 4.2.0 |
|
1234 * @access public |
|
1235 */ |
|
1236 public function render_content() {} |
|
1237 |
|
1238 /** |
|
1239 * Render a JS template for theme display. |
|
1240 * |
|
1241 * @since 4.2.0 |
|
1242 * @access public |
|
1243 */ |
|
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 ); |
|
1249 ?> |
|
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"> |
|
1252 <# } else { #> |
|
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"> |
|
1254 <# } #> |
|
1255 |
|
1256 <# if ( data.theme.screenshot[0] ) { #> |
|
1257 <div class="theme-screenshot"> |
|
1258 <img data-src="{{ data.theme.screenshot[0] }}" alt="" /> |
|
1259 </div> |
|
1260 <# } else { #> |
|
1261 <div class="theme-screenshot blank"></div> |
|
1262 <# } #> |
|
1263 |
|
1264 <# if ( data.theme.isActiveTheme ) { #> |
|
1265 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Customize' ); ?></span> |
|
1266 <# } else { #> |
|
1267 <span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Live Preview' ); ?></span> |
|
1268 <# } #> |
|
1269 |
|
1270 <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.theme.author }}' ); ?></div> |
|
1271 |
|
1272 <# if ( data.theme.isActiveTheme ) { #> |
|
1273 <h3 class="theme-name" id="{{ data.theme.id }}-name"> |
|
1274 <?php |
|
1275 /* translators: %s: theme name */ |
|
1276 printf( __( '<span>Active:</span> %s' ), '{{ data.theme.name }}' ); |
|
1277 ?> |
|
1278 </h3> |
|
1279 <# } else { #> |
|
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> |
|
1283 </div> |
|
1284 <# } #> |
|
1285 </div> |
|
1286 <?php |
|
1287 } |
|
1288 } |
|
1289 |
|
1290 /** |
|
1291 * Widget Area Customize Control class. |
|
1292 * |
|
1293 * @since 3.9.0 |
|
1294 * |
|
1295 * @see WP_Customize_Control |
|
1296 */ |
|
1297 class WP_Widget_Area_Customize_Control extends WP_Customize_Control { |
|
1298 public $type = 'sidebar_widgets'; |
|
1299 public $sidebar_id; |
|
1300 |
|
1301 public function to_json() { |
|
1302 parent::to_json(); |
|
1303 $exported_properties = array( 'sidebar_id' ); |
|
1304 foreach ( $exported_properties as $key ) { |
|
1305 $this->json[ $key ] = $this->$key; |
|
1306 } |
|
1307 } |
|
1308 |
|
1309 public function render_content() { |
|
1310 ?> |
|
1311 <span class="button-secondary add-new-widget" tabindex="0"> |
|
1312 <?php _e( 'Add a Widget' ); ?> |
|
1313 </span> |
|
1314 |
|
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> |
|
1318 </span> |
|
1319 <?php |
|
1320 } |
|
1321 |
|
1322 } |
|
1323 |
|
1324 /** |
|
1325 * Widget Form Customize Control class. |
|
1326 * |
|
1327 * @since 3.9.0 |
|
1328 * |
|
1329 * @see WP_Customize_Control |
|
1330 */ |
|
1331 class WP_Widget_Form_Customize_Control extends WP_Customize_Control { |
|
1332 public $type = 'widget_form'; |
|
1333 public $widget_id; |
|
1334 public $widget_id_base; |
|
1335 public $sidebar_id; |
|
1336 public $is_new = false; |
|
1337 public $width; |
|
1338 public $height; |
|
1339 public $is_wide = false; |
|
1340 |
|
1341 public function to_json() { |
|
1342 parent::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; |
|
1346 } |
|
1347 } |
|
1348 |
|
1349 public function render_content() { |
|
1350 global $wp_registered_widgets; |
|
1351 require_once ABSPATH . '/wp-admin/includes/widgets.php'; |
|
1352 |
|
1353 $widget = $wp_registered_widgets[ $this->widget_id ]; |
|
1354 if ( ! isset( $widget['params'][0] ) ) { |
|
1355 $widget['params'][0] = array(); |
|
1356 } |
|
1357 |
|
1358 $args = array( |
|
1359 'widget_id' => $widget['id'], |
|
1360 'widget_name' => $widget['name'], |
|
1361 ); |
|
1362 |
|
1363 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) ); |
|
1364 echo $this->manager->widgets->get_widget_control( $args ); |
|
1365 } |
|
1366 |
|
1367 /** |
|
1368 * Whether the current widget is rendered on the page. |
|
1369 * |
|
1370 * @since 4.0.0 |
|
1371 * @access public |
|
1372 * |
|
1373 * @return bool Whether the widget is rendered. |
|
1374 */ |
|
1375 public function active_callback() { |
|
1376 return $this->manager->widgets->is_widget_rendered( $this->widget_id ); |
|
1377 } |
|
1378 } |