WP_Customize_Header_Image_Control

Customize Header Image Control class.

Defined (1)

The class is defined in the following location(s).

/wp-includes/customize/class-wp-customize-header-image-control.php  
  1. class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { 
  2. public $type = 'header'; 
  3. public $uploaded_headers; 
  4. public $default_headers; 
  5.  
  6. /** 
  7. * Constructor. 
  8. * @since 3.4.0 
  9. * @param WP_Customize_Manager $manager Customizer bootstrap instance. 
  10. */ 
  11. public function __construct( $manager ) { 
  12. parent::__construct( $manager, 'header_image', array( 
  13. 'label' => __( 'Header Image' ),  
  14. 'settings' => array( 
  15. 'default' => 'header_image',  
  16. 'data' => 'header_image_data',  
  17. ),  
  18. 'section' => 'header_image',  
  19. 'removed' => 'remove-header',  
  20. 'get_url' => 'get_header_image',  
  21. ) ); 
  22.  
  23.  
  24. /** 
  25. * @access public 
  26. */ 
  27. public function enqueue() { 
  28. wp_enqueue_media(); 
  29. wp_enqueue_script( 'customize-views' ); 
  30.  
  31. $this->prepare_control(); 
  32.  
  33. wp_localize_script( 'customize-views', '_wpCustomizeHeader', array( 
  34. 'data' => array( 
  35. 'width' => absint( get_theme_support( 'custom-header', 'width' ) ),  
  36. 'height' => absint( get_theme_support( 'custom-header', 'height' ) ),  
  37. 'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),  
  38. 'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),  
  39. 'currentImgSrc' => $this->get_current_image_src(),  
  40. ),  
  41. 'nonces' => array( 
  42. 'add' => wp_create_nonce( 'header-add' ),  
  43. 'remove' => wp_create_nonce( 'header-remove' ),  
  44. ),  
  45. 'uploads' => $this->uploaded_headers,  
  46. 'defaults' => $this->default_headers 
  47. ) ); 
  48.  
  49. parent::enqueue(); 
  50.  
  51. /** 
  52. * @global Custom_Image_Header $custom_image_header 
  53. */ 
  54. public function prepare_control() { 
  55. global $custom_image_header; 
  56. if ( empty( $custom_image_header ) ) { 
  57. return; 
  58.  
  59. // Process default headers and uploaded headers. 
  60. $custom_image_header->process_default_headers(); 
  61. $this->default_headers = $custom_image_header->get_default_header_images(); 
  62. $this->uploaded_headers = $custom_image_header->get_uploaded_header_images(); 
  63.  
  64. /** 
  65. * @access public 
  66. */ 
  67. public function print_header_image_template() { 
  68. ?> 
  69. <script type="text/template" id="tmpl-header-choice"> 
  70. <# if (data.random) { #> 
  71. <button type="button" class="button display-options random"> 
  72. <span class="dashicons dashicons-randomize dice"></span> 
  73. <# if ( data.type === 'uploaded' ) { #> 
  74. <?php _e( 'Randomize uploaded headers' ); ?> 
  75. <# } else if ( data.type === 'default' ) { #> 
  76. <?php _e( 'Randomize suggested headers' ); ?> 
  77. <# } #> 
  78. </button> 
  79.  
  80. <# } else { #> 
  81.  
  82. <# if (data.type === 'uploaded') { #> 
  83. <button type="button" class="dashicons dashicons-no close"><span class="screen-reader-text"><?php _e( 'Remove image' ); ?></span></button> 
  84. <# } #> 
  85.  
  86. <button type="button" class="choice thumbnail" 
  87. data-customize-image-value="{{{data.header.url}}}" 
  88. data-customize-header-image-data="{{JSON.stringify(data.header)}}"> 
  89. <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span> 
  90. <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}"> 
  91. </button> 
  92.  
  93. <# } #> 
  94. </script> 
  95.  
  96. <script type="text/template" id="tmpl-header-current"> 
  97. <# if (data.choice) { #> 
  98. <# if (data.random) { #> 
  99.  
  100. <div class="placeholder"> 
  101. <span class="dashicons dashicons-randomize dice"></span> 
  102. <# if ( data.type === 'uploaded' ) { #> 
  103. <?php _e( 'Randomizing uploaded headers' ); ?> 
  104. <# } else if ( data.type === 'default' ) { #> 
  105. <?php _e( 'Randomizing suggested headers' ); ?> 
  106. <# } #> 
  107. </div> 
  108.  
  109. <# } else { #> 
  110.  
  111. <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/> 
  112.  
  113. <# } #> 
  114. <# } else { #> 
  115.  
  116. <div class="placeholder"> 
  117. <?php _e( 'No image set' ); ?> 
  118. </div> 
  119.  
  120. <# } #> 
  121. </script> 
  122. <?php 
  123.  
  124. /** 
  125. * @return string|void 
  126. */ 
  127. public function get_current_image_src() { 
  128. $src = $this->value(); 
  129. if ( isset( $this->get_url ) ) { 
  130. $src = call_user_func( $this->get_url, $src ); 
  131. return $src; 
  132.  
  133. /** 
  134. * @access public 
  135. */ 
  136. public function render_content() { 
  137. $this->print_header_image_template(); 
  138. $visibility = $this->get_current_image_src() ? '' : ' style="display:none" '; 
  139. $width = absint( get_theme_support( 'custom-header', 'width' ) ); 
  140. $height = absint( get_theme_support( 'custom-header', 'height' ) ); 
  141. ?> 
  142. <div class="customize-control-content"> 
  143. <p class="customizer-section-intro"> 
  144. <?php 
  145. if ( $width && $height ) { 
  146. /** translators: %s: header size in pixels */ 
  147. printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header size of %s pixels.' ),  
  148. sprintf( '<strong>%s × %s</strong>', $width, $height ) 
  149. ); 
  150. } elseif ( $width ) { 
  151. /** translators: %s: header width in pixels */ 
  152. printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header width of %s pixels.' ),  
  153. sprintf( '<strong>%s</strong>', $width ) 
  154. ); 
  155. } else { 
  156. /** translators: %s: header height in pixels */ 
  157. printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header height of %s pixels.' ),  
  158. sprintf( '<strong>%s</strong>', $height ) 
  159. ); 
  160. ?> 
  161. </p> 
  162. <div class="current"> 
  163. <label for="header_image-button"> 
  164. <span class="customize-control-title"> 
  165. <?php _e( 'Current header' ); ?> 
  166. </span> 
  167. </label> 
  168. <div class="container"> 
  169. </div> 
  170. </div> 
  171. <div class="actions"> 
  172. <?php if ( current_user_can( 'upload_files' ) ): ?> 
  173. <button type="button"<?php echo $visibility; ?> class="button remove" aria-label="<?php esc_attr_e( 'Hide header image' ); ?>"><?php _e( 'Hide image' ); ?></button> 
  174. <button type="button" class="button new" id="header_image-button" aria-label="<?php esc_attr_e( 'Add new header image' ); ?>"><?php _e( 'Add new image' ); ?></button> 
  175. <div style="clear:both"></div> 
  176. <?php endif; ?> 
  177. </div> 
  178. <div class="choices"> 
  179. <span class="customize-control-title header-previously-uploaded"> 
  180. <?php _ex( 'Previously uploaded', 'custom headers' ); ?> 
  181. </span> 
  182. <div class="uploaded"> 
  183. <div class="list"> 
  184. </div> 
  185. </div> 
  186. <span class="customize-control-title header-default"> 
  187. <?php _ex( 'Suggested', 'custom headers' ); ?> 
  188. </span> 
  189. <div class="default"> 
  190. <div class="list"> 
  191. </div> 
  192. </div> 
  193. </div> 
  194. </div> 
  195. <?php