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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * @var string
  24. */
  25. public $type = 'site_icon';
  26. /**
  27. * Constructor.
  28. *
  29. * @since 4.3.0
  30. *
  31. * @see WP_Customize_Control::__construct()
  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. * See WP_Customize_Control::__construct() for information
  37. * on accepted arguments. Default empty array.
  38. */
  39. public function __construct( $manager, $id, $args = array() ) {
  40. parent::__construct( $manager, $id, $args );
  41. add_action( 'customize_controls_print_styles', 'wp_site_icon', 99 );
  42. }
  43. /**
  44. * Renders a JS template for the content of the site icon control.
  45. *
  46. * @since 4.5.0
  47. */
  48. public function content_template() {
  49. ?>
  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. <# if ( data.attachment && data.attachment.id ) { #>
  57. <div class="attachment-media-view">
  58. <# if ( data.attachment.sizes ) { #>
  59. <div class="site-icon-preview wp-clearfix">
  60. <div class="favicon-preview">
  61. <img src="<?php echo esc_url( admin_url( 'images/' . ( is_rtl() ? 'browser-rtl.png' : 'browser.png' ) ) ); ?>" class="browser-preview" width="182" alt="" />
  62. <div class="favicon">
  63. <img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>" />
  64. </div>
  65. <span class="browser-title" aria-hidden="true"><# print( '<?php echo esc_js( get_bloginfo( 'name' ) ); ?>' ) #></span>
  66. </div>
  67. <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' ); ?>" />
  68. </div>
  69. <# } #>
  70. <div class="actions">
  71. <# if ( data.canUpload ) { #>
  72. <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
  73. <button type="button" class="button upload-button"><?php echo $this->button_labels['change']; ?></button>
  74. <# } #>
  75. </div>
  76. </div>
  77. <# } else { #>
  78. <div class="attachment-media-view">
  79. <# if ( data.canUpload ) { #>
  80. <button type="button" class="upload-button button-add-media"><?php echo $this->button_labels['site_icon']; ?></button>
  81. <# } #>
  82. <div class="actions">
  83. <# if ( data.defaultAttachment ) { #>
  84. <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
  85. <# } #>
  86. </div>
  87. </div>
  88. <# } #>
  89. <?php
  90. }
  91. }