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 {
public $type = 'header' ;
public $uploaded_headers ;
public $default_headers ;
/**
* Constructor .
*
* @ since 3.4 . 0
*
* @ param WP_Customize_Manager $manager Customizer bootstrap instance .
*/
public function __construct ( $manager ) {
parent :: __construct ( $manager , 'header_image' , array (
'label' => __ ( 'Header Image' ),
'settings' => array (
'default' => 'header_image' ,
'data' => 'header_image_data' ,
),
'section' => 'header_image' ,
'removed' => 'remove-header' ,
'get_url' => 'get_header_image' ,
) );
}
/**
* @ access public
*/
public function enqueue () {
wp_enqueue_media ();
wp_enqueue_script ( 'customize-views' );
$this -> prepare_control ();
wp_localize_script ( 'customize-views' , '_wpCustomizeHeader' , array (
'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
) );
parent :: enqueue ();
}
/**
*
* @ global Custom_Image_Header $custom_image_header
*/
public function prepare_control () {
global $custom_image_header ;
if ( empty ( $custom_image_header ) ) {
return ;
}
// Process default headers and uploaded headers.
$custom_image_header -> process_default_headers ();
$this -> default_headers = $custom_image_header -> get_default_header_images ();
$this -> uploaded_headers = $custom_image_header -> get_uploaded_header_images ();
}
/**
* @ access public
*/
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 { #>
< # if (data.type === 'uploaded') { #>
< button type = " button " class = " dashicons dashicons-no close " >< span class = " screen-reader-text " >< ? php _e ( 'Remove image' ); ?> </span></button>
< # } #>
< button type = " button " class = " choice thumbnail "
Grouped backports to the 4.6 branch.
- Posts, Post types: Apply KSES to post-by-email content,
- General: Validate host on "Are you sure?" screen,
- Posts, Post types: Remove emails from post-by-email logs,
- Pings/trackbacks: Apply KSES to all trackbacks,
- Comments: Apply kses when editing comments,
- Customize: Escape blogname option in underscores templates,
- Mail: Reset PHPMailer properties between use,
- Query: Validate relation in `WP_Date_Query`,
- Widgets: Escape RSS error messages for display.
Merges [54521], [54522], [54523], [54525], [54526], [54527], [54529], [54530], [54541] to the 4.6 branch.
Props voldemortensen, johnbillion, paulkevan, peterwilsoncc, xknown, dd32, audrasjb, martinkrcho, davidbaumwald, tykoted, johnjamesjacoby, ehtis, matveb, talldanwp.
Built from https://develop.svn.wordpress.org/branches/4.6@54561
git-svn-id: http://core.svn.wordpress.org/branches/4.6@54116 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-17 14:04:22 -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)}} " >
< span class = " screen-reader-text " >< ? php _e ( 'Set image' ); ?> </span>
Grouped backports to the 4.6 branch.
- Posts, Post types: Apply KSES to post-by-email content,
- General: Validate host on "Are you sure?" screen,
- Posts, Post types: Remove emails from post-by-email logs,
- Pings/trackbacks: Apply KSES to all trackbacks,
- Comments: Apply kses when editing comments,
- Customize: Escape blogname option in underscores templates,
- Mail: Reset PHPMailer properties between use,
- Query: Validate relation in `WP_Date_Query`,
- Widgets: Escape RSS error messages for display.
Merges [54521], [54522], [54523], [54525], [54526], [54527], [54529], [54530], [54541] to the 4.6 branch.
Props voldemortensen, johnbillion, paulkevan, peterwilsoncc, xknown, dd32, audrasjb, martinkrcho, davidbaumwald, tykoted, johnjamesjacoby, ehtis, matveb, talldanwp.
Built from https://develop.svn.wordpress.org/branches/4.6@54561
git-svn-id: http://core.svn.wordpress.org/branches/4.6@54116 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-10-17 14:04:22 -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 >
< # } #>
</ 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 { #>
< img src = " { { { data.header.thumbnail_url}}} " alt = " { { { data.header.alt_text || data.header.description}}} " tabindex = " 0 " />
< # } #>
< # } 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 ;
}
}
/**
* @ access public
*/
public function render_content () {
$this -> print_header_image_template ();
$visibility = $this -> get_current_image_src () ? '' : ' style="display:none" ' ;
$width = absint ( get_theme_support ( 'custom-header' , 'width' ) );
$height = absint ( get_theme_support ( 'custom-header' , 'height' ) );
?>
< div class = " customize-control-content " >
< p class = " customizer-section-intro " >
< ? php
if ( $width && $height ) {
2015-12-14 07:54:27 -05:00
/* translators: %s: header size in pixels */
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.' ),
sprintf ( '<strong>%s × %s</strong>' , $width , $height )
);
2015-10-24 14:57:25 -04:00
} elseif ( $width ) {
2015-12-14 07:54:27 -05:00
/* translators: %s: header width in pixels */
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.' ),
sprintf ( '<strong>%s</strong>' , $width )
);
2015-10-24 14:57:25 -04:00
} else {
2015-12-14 07:54:27 -05:00
/* translators: %s: header height in pixels */
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.' ),
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 " >
< ? php if ( current_user_can ( 'upload_files' ) ) : ?>
< button type = " button " < ? php echo $visibility ; ?> class="button remove" aria-label="<?php esc_attr_e( 'Hide header image' ); ?>"><?php _e( 'Hide image' ); ?></button>
< 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>
< div style = " clear:both " ></ div >
< ? 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
}
}