3
* Customize API: WP_Customize_Header_Image_Control class
6
* @subpackage Customize
11
* Customize Header Image Control class.
15
* @see WP_Customize_Image_Control
17
class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
18
public $type = 'header';
19
public $uploaded_headers;
20
public $default_headers;
27
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
29
public function __construct( $manager ) {
30
parent::__construct( $manager, 'header_image', array(
31
'label' => __( 'Header Image' ),
33
'default' => 'header_image',
34
'data' => 'header_image_data',
36
'section' => 'header_image',
37
'removed' => 'remove-header',
38
'get_url' => 'get_header_image',
46
public function enqueue() {
48
wp_enqueue_script( 'customize-views' );
50
$this->prepare_control();
52
wp_localize_script( 'customize-views', '_wpCustomizeHeader', array(
54
'width' => absint( get_theme_support( 'custom-header', 'width' ) ),
55
'height' => absint( get_theme_support( 'custom-header', 'height' ) ),
56
'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),
57
'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),
58
'currentImgSrc' => $this->get_current_image_src(),
61
'add' => wp_create_nonce( 'header-add' ),
62
'remove' => wp_create_nonce( 'header-remove' ),
64
'uploads' => $this->uploaded_headers,
65
'defaults' => $this->default_headers
73
* @global Custom_Image_Header $custom_image_header
75
public function prepare_control() {
76
global $custom_image_header;
77
if ( empty( $custom_image_header ) ) {
81
// Process default headers and uploaded headers.
82
$custom_image_header->process_default_headers();
83
$this->default_headers = $custom_image_header->get_default_header_images();
84
$this->uploaded_headers = $custom_image_header->get_uploaded_header_images();
90
public function print_header_image_template() {
92
<script type="text/template" id="tmpl-header-choice">
93
<# if (data.random) { #>
94
<button type="button" class="button display-options random">
95
<span class="dashicons dashicons-randomize dice"></span>
96
<# if ( data.type === 'uploaded' ) { #>
97
<?php _e( 'Randomize uploaded headers' ); ?>
98
<# } else if ( data.type === 'default' ) { #>
99
<?php _e( 'Randomize suggested headers' ); ?>
105
<# if (data.type === 'uploaded') { #>
106
<button type="button" class="dashicons dashicons-no close"><span class="screen-reader-text"><?php _e( 'Remove image' ); ?></span></button>
109
<button type="button" class="choice thumbnail"
110
data-customize-image-value="{{{data.header.url}}}"
111
data-customize-header-image-data="{{JSON.stringify(data.header)}}">
112
<span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
113
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
119
<script type="text/template" id="tmpl-header-current">
120
<# if (data.choice) { #>
121
<# if (data.random) { #>
123
<div class="placeholder">
125
<span><span class="dashicons dashicons-randomize dice"></span>
126
<# if ( data.type === 'uploaded' ) { #>
127
<?php _e( 'Randomizing uploaded headers' ); ?>
128
<# } else if ( data.type === 'default' ) { #>
129
<?php _e( 'Randomizing suggested headers' ); ?>
137
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/>
142
<div class="placeholder">
145
<?php _e( 'No image set' ); ?>
156
* @return string|void
158
public function get_current_image_src() {
159
$src = $this->value();
160
if ( isset( $this->get_url ) ) {
161
$src = call_user_func( $this->get_url, $src );
169
public function render_content() {
170
$this->print_header_image_template();
171
$visibility = $this->get_current_image_src() ? '' : ' style="display:none" ';
172
$width = absint( get_theme_support( 'custom-header', 'width' ) );
173
$height = absint( get_theme_support( 'custom-header', 'height' ) );
175
<div class="customize-control-content">
176
<p class="customizer-section-intro">
178
if ( $width && $height ) {
179
printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header size of <strong>%s × %s</strong> pixels.' ), $width, $height );
180
} elseif ( $width ) {
181
printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header width of <strong>%s</strong> pixels.' ), $width );
183
printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header height of <strong>%s</strong> pixels.' ), $height );
187
<div class="current">
188
<label for="header_image-button">
189
<span class="customize-control-title">
190
<?php _e( 'Current header' ); ?>
193
<div class="container">
196
<div class="actions">
197
<?php if ( current_user_can( 'upload_files' ) ): ?>
198
<button type="button"<?php echo $visibility; ?> class="button remove" aria-label="<?php esc_attr_e( 'Hide header image' ); ?>"><?php _e( 'Hide image' ); ?></button>
199
<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>
200
<div style="clear:both"></div>
203
<div class="choices">
204
<span class="customize-control-title header-previously-uploaded">
205
<?php _ex( 'Previously uploaded', 'custom headers' ); ?>
207
<div class="uploaded">
211
<span class="customize-control-title header-default">
212
<?php _ex( 'Suggested', 'custom headers' ); ?>
214
<div class="default">