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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. <# if ( data.label ) { #>
  47. <span class="customize-control-title">{{ data.label }}</span>
  48. <# } #>
  49. <# if ( data.description ) { #>
  50. <span class="description customize-control-description">{{{ data.description }}}</span>
  51. <# } #>
  52. <# if ( data.attachment && data.attachment.id ) { #>
  53. <div class="attachment-media-view">
  54. <# if ( data.attachment.sizes ) { #>
  55. <div class="site-icon-preview wp-clearfix">
  56. <div class="favicon-preview">
  57. <img src="<?php echo esc_url( admin_url( 'images/' . ( is_rtl() ? 'browser-rtl.png' : 'browser.png' ) ) ); ?>" class="browser-preview" width="182" alt="" />
  58. <div class="favicon">
  59. <img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>"/>
  60. </div>
  61. <span class="browser-title" aria-hidden="true"><# print( '<?php bloginfo( 'name' ); ?>' ) #></span>
  62. </div>
  63. <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' ); ?>"/>
  64. </div>
  65. <# } #>
  66. <div class="actions">
  67. <# if ( data.canUpload ) { #>
  68. <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
  69. <button type="button" class="button upload-button"><?php echo $this->button_labels['change']; ?></button>
  70. <# } #>
  71. </div>
  72. </div>
  73. <# } else { #>
  74. <div class="attachment-media-view">
  75. <# if ( data.canUpload ) { #>
  76. <button type="button" class="upload-button button-add-media"><?php echo $this->button_labels['site_icon']; ?></button>
  77. <# } #>
  78. <div class="actions">
  79. <# if ( data.defaultAttachment ) { #>
  80. <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
  81. <# } #>
  82. </div>
  83. </div>
  84. <# } #>
  85. <?php
  86. }
  87. }