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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * @param WP_Customize_Manager $manager Customizer bootstrap instance.
  32. * @param string $id Control ID.
  33. * @param array $args Optional. Arguments to override class property defaults.
  34. */
  35. public function __construct( $manager, $id, $args = array() ) {
  36. parent::__construct( $manager, $id, $args );
  37. add_action( 'customize_controls_print_styles', 'wp_site_icon', 99 );
  38. }
  39. /**
  40. * Renders a JS template for the content of the site icon control.
  41. *
  42. * @since 4.5.0
  43. */
  44. public function content_template() {
  45. ?>
  46. <label for="{{ data.settings['default'] }}-button">
  47. <# if ( data.label ) { #>
  48. <span class="customize-control-title">{{ data.label }}</span>
  49. <# } #>
  50. <# if ( data.description ) { #>
  51. <span class="description customize-control-description">{{{ data.description }}}</span>
  52. <# } #>
  53. </label>
  54. <# if ( data.attachment && data.attachment.id ) { #>
  55. <div class="attachment-media-view">
  56. <# if ( data.attachment.sizes ) { #>
  57. <div class="site-icon-preview wp-clearfix">
  58. <div class="favicon-preview">
  59. <img src="<?php echo esc_url( admin_url( 'images/' . ( is_rtl() ? 'browser-rtl.png' : 'browser.png' ) ) ); ?>" class="browser-preview" width="182" alt="" />
  60. <div class="favicon">
  61. <img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
  62. </div>
  63. <span class="browser-title" aria-hidden="true"><?php bloginfo( 'name' ); ?></span>
  64. </div>
  65. <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' ); ?>"/>
  66. </div>
  67. <# } #>
  68. <div class="actions">
  69. <# if ( data.canUpload ) { #>
  70. <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
  71. <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['change']; ?></button>
  72. <# } #>
  73. </div>
  74. </div>
  75. <# } else { #>
  76. <div class="attachment-media-view">
  77. <div class="placeholder">
  78. <?php echo $this->button_labels['placeholder']; ?>
  79. </div>
  80. <div class="actions">
  81. <# if ( data.defaultAttachment ) { #>
  82. <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
  83. <# } #>
  84. <# if ( data.canUpload ) { #>
  85. <button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['select']; ?></button>
  86. <# } #>
  87. </div>
  88. </div>
  89. <# } #>
  90. <?php
  91. }
  92. }