2015-10-24 14:57:25 -04:00
< ? php
/**
* Customize API : WP_Customize_Header_Image_Control class
*
* @ package WordPress
* @ subpackage Customize
* @ since 4.4 . 0
*/
/**
* Customize Header Image Control class .
*
* @ since 3.4 . 0
*
* @ see WP_Customize_Image_Control
*/
class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
2022-05-18 11:24:14 -04:00
2019-01-15 00:54:48 -05:00
/**
* Customize control type .
*
* @ since 4.2 . 0
* @ var string
*/
2015-10-24 14:57:25 -04:00
public $type = 'header' ;
2019-01-15 00:54:48 -05:00
/**
* Uploaded header images .
*
* @ since 3.9 . 0
* @ var string
*/
2015-10-24 14:57:25 -04:00
public $uploaded_headers ;
2019-01-15 00:54:48 -05:00
/**
* Default header images .
*
* @ since 3.9 . 0
* @ var string
*/
2015-10-24 14:57:25 -04:00
public $default_headers ;
/**
* Constructor .
*
* @ since 3.4 . 0
*
* @ param WP_Customize_Manager $manager Customizer bootstrap instance .
*/
public function __construct ( $manager ) {
2017-11-30 18:11:00 -05:00
parent :: __construct (
2018-08-16 21:51:36 -04:00
$manager ,
'header_image' ,
array (
2017-11-30 18:11:00 -05:00
'label' => __ ( 'Header Image' ),
'settings' => array (
'default' => 'header_image' ,
'data' => 'header_image_data' ,
),
'section' => 'header_image' ,
'removed' => 'remove-header' ,
'get_url' => 'get_header_image' ,
)
);
2015-10-24 14:57:25 -04:00
}
/**
*/
public function enqueue () {
wp_enqueue_media ();
wp_enqueue_script ( 'customize-views' );
$this -> prepare_control ();
2017-11-30 18:11:00 -05:00
wp_localize_script (
2018-08-16 21:51:36 -04:00
'customize-views' ,
'_wpCustomizeHeader' ,
array (
2017-11-30 18:11:00 -05:00
'data' => array (
'width' => absint ( get_theme_support ( 'custom-header' , 'width' ) ),
'height' => absint ( get_theme_support ( 'custom-header' , 'height' ) ),
'flex-width' => absint ( get_theme_support ( 'custom-header' , 'flex-width' ) ),
'flex-height' => absint ( get_theme_support ( 'custom-header' , 'flex-height' ) ),
'currentImgSrc' => $this -> get_current_image_src (),
),
'nonces' => array (
'add' => wp_create_nonce ( 'header-add' ),
'remove' => wp_create_nonce ( 'header-remove' ),
),
'uploads' => $this -> uploaded_headers ,
'defaults' => $this -> default_headers ,
)
);
2015-10-24 14:57:25 -04:00
parent :: enqueue ();
}
/**
* @ global Custom_Image_Header $custom_image_header
*/
public function prepare_control () {
global $custom_image_header ;
if ( empty ( $custom_image_header ) ) {
return ;
}
2017-10-18 23:04:49 -04:00
add_action ( 'customize_controls_print_footer_scripts' , array ( $this , 'print_header_image_template' ) );
2015-10-24 14:57:25 -04:00
// Process default headers and uploaded headers.
$custom_image_header -> process_default_headers ();
2017-11-30 18:11:00 -05:00
$this -> default_headers = $custom_image_header -> get_default_header_images ();
2015-10-24 14:57:25 -04:00
$this -> uploaded_headers = $custom_image_header -> get_uploaded_header_images ();
}
/**
*/
public function print_header_image_template () {
?>
< script type = " text/template " id = " tmpl-header-choice " >
< # if (data.random) { #>
< button type = " button " class = " button display-options random " >
< span class = " dashicons dashicons-randomize dice " ></ span >
< # if ( data.type === 'uploaded' ) { #>
< ? php _e ( 'Randomize uploaded headers' ); ?>
< # } else if ( data.type === 'default' ) { #>
< ? php _e ( 'Randomize suggested headers' ); ?>
< # } #>
</ button >
< # } else { #>
< button type = " button " class = " choice thumbnail "
2022-10-17 07:26:11 -04:00
data - customize - image - value = " { { data.header.url}} "
2015-10-24 14:57:25 -04:00
data - customize - header - image - data = " { { JSON.stringify(data.header)}} " >
I18N: Mark screen reader strings as such with translator comments.
This aims to provide better context for translators and make it easier to determine that some strings contain hidden accessibility text and are not displayed in the UI.
Props kebbet, mercime, pavelevap, ocean90, swissspidy, Chouby, jipmoors, afercia, desrosj, costdev, audrasjb, SergeyBiryukov.
Fixes #29748.
Built from https://develop.svn.wordpress.org/trunk@55276
git-svn-id: http://core.svn.wordpress.org/trunk@54809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-07 12:10:21 -05:00
< span class = " screen-reader-text " >
< ? php
/* translators: Hidden accessibility text. */
_e ( 'Set image' );
?>
</ span >
2022-10-17 07:26:11 -04:00
< img src = " { { data.header.thumbnail_url}} " alt = " { { data.header.alt_text || data.header.description}} " />
2015-10-24 14:57:25 -04:00
</ button >
2016-10-23 15:57:32 -04:00
< # if ( data.type === 'uploaded' ) { #>
I18N: Mark screen reader strings as such with translator comments.
This aims to provide better context for translators and make it easier to determine that some strings contain hidden accessibility text and are not displayed in the UI.
Props kebbet, mercime, pavelevap, ocean90, swissspidy, Chouby, jipmoors, afercia, desrosj, costdev, audrasjb, SergeyBiryukov.
Fixes #29748.
Built from https://develop.svn.wordpress.org/trunk@55276
git-svn-id: http://core.svn.wordpress.org/trunk@54809 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-02-07 12:10:21 -05:00
< button type = " button " class = " dashicons dashicons-no close " >
< span class = " screen-reader-text " >
< ? php
/* translators: Hidden accessibility text. */
_e ( 'Remove image' );
?>
</ span >
</ button >
2016-10-23 15:57:32 -04:00
< # } #>
2015-10-24 14:57:25 -04:00
< # } #>
</ script >
< script type = " text/template " id = " tmpl-header-current " >
< # if (data.choice) { #>
< # if (data.random) { #>
< div class = " placeholder " >
2016-05-12 16:23:54 -04:00
< span class = " dashicons dashicons-randomize dice " ></ span >
< # if ( data.type === 'uploaded' ) { #>
< ? php _e ( 'Randomizing uploaded headers' ); ?>
< # } else if ( data.type === 'default' ) { #>
< ? php _e ( 'Randomizing suggested headers' ); ?>
< # } #>
2015-10-24 14:57:25 -04:00
</ div >
< # } else { #>
2022-10-17 07:26:11 -04:00
< img src = " { { data.header.thumbnail_url}} " alt = " { { data.header.alt_text || data.header.description}} " />
2015-10-24 14:57:25 -04:00
< # } #>
< # } else { #>
< div class = " placeholder " >
2016-05-12 16:23:54 -04:00
< ? php _e ( 'No image set' ); ?>
2015-10-24 14:57:25 -04:00
</ div >
< # } #>
</ script >
< ? php
}
/**
* @ return string | void
*/
public function get_current_image_src () {
$src = $this -> value ();
if ( isset ( $this -> get_url ) ) {
$src = call_user_func ( $this -> get_url , $src );
return $src ;
}
}
/**
*/
public function render_content () {
$visibility = $this -> get_current_image_src () ? '' : ' style="display:none" ' ;
2017-11-30 18:11:00 -05:00
$width = absint ( get_theme_support ( 'custom-header' , 'width' ) );
$height = absint ( get_theme_support ( 'custom-header' , 'height' ) );
2015-10-24 14:57:25 -04:00
?>
< div class = " customize-control-content " >
2017-11-30 18:11:00 -05:00
< ? php
if ( current_theme_supports ( 'custom-header' , 'video' ) ) {
2016-10-27 17:51:31 -04:00
echo '<span class="customize-control-title">' . $this -> label . '</span>' ;
2017-11-30 18:11:00 -05:00
}
?>
2016-11-04 19:15:33 -04:00
< div class = " customize-control-notifications-container " ></ div >
2016-10-27 17:51:31 -04:00
< p class = " customizer-section-intro customize-control-description " >
2015-10-24 14:57:25 -04:00
< ? php
2016-10-27 17:51:31 -04:00
if ( current_theme_supports ( 'custom-header' , 'video' ) ) {
2017-10-04 15:35:47 -04:00
_e ( 'Click “Add new image” to upload an image file from your computer. Your theme works best with an image that matches the size of your video — you’ll be able to crop your image once you upload it for a perfect fit.' );
2016-10-27 17:51:31 -04:00
} elseif ( $width && $height ) {
2017-11-30 18:11:00 -05:00
printf (
2019-09-02 20:41:05 -04:00
/* translators: %s: Header size in pixels. */
2017-11-30 18:11:00 -05:00
__ ( 'Click “Add new image” to upload an image file from your computer. Your theme works best with an image with a header size of %s pixels — you’ll be able to crop your image once you upload it for a perfect fit.' ),
2015-12-14 07:54:27 -05:00
sprintf ( '<strong>%s × %s</strong>' , $width , $height )
);
2015-10-24 14:57:25 -04:00
} elseif ( $width ) {
2017-11-30 18:11:00 -05:00
printf (
2019-09-02 20:41:05 -04:00
/* translators: %s: Header width in pixels. */
2017-11-30 18:11:00 -05:00
__ ( 'Click “Add new image” to upload an image file from your computer. Your theme works best with an image with a header width of %s pixels — you’ll be able to crop your image once you upload it for a perfect fit.' ),
2015-12-14 07:54:27 -05:00
sprintf ( '<strong>%s</strong>' , $width )
);
2015-10-24 14:57:25 -04:00
} else {
2017-11-30 18:11:00 -05:00
printf (
2019-09-02 20:41:05 -04:00
/* translators: %s: Header height in pixels. */
2017-11-30 18:11:00 -05:00
__ ( 'Click “Add new image” to upload an image file from your computer. Your theme works best with an image with a header height of %s pixels — you’ll be able to crop your image once you upload it for a perfect fit.' ),
2015-12-14 07:54:27 -05:00
sprintf ( '<strong>%s</strong>' , $height )
);
2015-10-24 14:57:25 -04:00
}
?>
</ p >
< div class = " current " >
< label for = " header_image-button " >
< span class = " customize-control-title " >
< ? php _e ( 'Current header' ); ?>
</ span >
</ label >
< div class = " container " >
</ div >
</ div >
< div class = " actions " >
2017-11-30 18:11:00 -05:00
< ? php if ( current_user_can ( 'upload_files' ) ) : ?>
2015-10-24 14:57:25 -04:00
< button type = " button " < ? php echo $visibility ; ?> class="button remove" aria-label="<?php esc_attr_e( 'Hide header image' ); ?>"><?php _e( 'Hide image' ); ?></button>
2017-05-15 14:51:41 -04:00
< 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>
2015-10-24 14:57:25 -04:00
< ? php endif ; ?>
</ div >
< div class = " choices " >
< span class = " customize-control-title header-previously-uploaded " >
< ? php _ex ( 'Previously uploaded' , 'custom headers' ); ?>
</ span >
< div class = " uploaded " >
< div class = " list " >
</ div >
</ div >
< span class = " customize-control-title header-default " >
< ? php _ex ( 'Suggested' , 'custom headers' ); ?>
</ span >
< div class = " default " >
< div class = " list " >
</ div >
</ div >
</ div >
</ div >
< ? php
}
}