class-wp-customize-site-icon-control.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Customize API: WP_Customize_Site_Icon_Control class
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.4.0
  8. */
  9. /**
  10. * Customize Site Icon control class.
  11. *
  12. * Used only for custom functionality in JavaScript.
  13. *
  14. * @since 4.3.0
  15. *
  16. * @see WP_Customize_Cropped_Image_Control
  17. */
  18. class WP_Customize_Site_Icon_Control extends WP_Customize_Cropped_Image_Control {
  19. /**
  20. * Control type.
  21. *
  22. * @since 4.3.0
  23. * @access public
  24. * @var string
  25. */
  26. public $type = 'site_icon';
  27. /**
  28. * Constructor.
  29. *
  30. * @since 4.3.0
  31. * @access public
  32. *
  33. * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  34. * @param string $id Control ID.
  35. * @param array $args Optional. Arguments to override class property defaults.
  36. */
  37. public function __construct( $manager, $id, $args = array() ) {
  38. parent::__construct( $manager, $id, $args );
  39. add_action( 'customize_controls_print_styles', 'wp_site_icon', 99 );
  40. }
  41. /**
  42. * Renders a JS template for the content of the site icon control.
  43. *
  44. * @since 4.5.0
  45. * @access public
  46. */
  47. public function content_template() {
  48. ?>
  49. <label for="{{ data.settings['default'] }}-button">
  50. <# if ( data.label ) { #>
  51. <span class="customize-control-title">{{ data.label }}</span>
  52. <# } #>
  53. <# if ( data.description ) { #>
  54. <span class="description customize-control-description">{{{ data.description }}}</span>
  55. <# } #>
  56. </label>
  57. <# if ( data.attachment && data.attachment.id ) { #>
  58. <div class="attachment-media-view">
  59. <# if ( data.attachment.sizes ) { #>
  60. <div class="site-icon-preview wp-clearfix">
  61. <div class="favicon-preview">
  62. <img src="<?php echo esc_url( admin_url( 'images/' . ( is_rtl() ? 'browser-rtl.png' : 'browser.png' ) ) ); ?>" class="browser-preview" width="182" alt="" />
  63. <div class="favicon">
  64. <img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
  65. </div>
  66. <span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
  67. </div>
  68. <img class="app-icon-preview" src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as an app icon' ); ?>"/>
  69. </div>
  70. <# } #>
  71. <div class="actions">
  72. <# if ( data.canUpload ) { #>
  73. <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
  74. <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['change']; ?></button>
  75. <# } #>
  76. </div>
  77. </div>
  78. <# } else { #>
  79. <div class="attachment-media-view">
  80. <div class="placeholder">
  81. <?php echo $this->button_labels['placeholder']; ?>
  82. </div>
  83. <div class="actions">
  84. <# if ( data.defaultAttachment ) { #>
  85. <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
  86. <# } #>
  87. <# if ( data.canUpload ) { #>
  88. <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['select']; ?></button>
  89. <# } #>
  90. </div>
  91. </div>
  92. <# } #>
  93. <?php
  94. }
  95. }