X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0b8a53f298029318648c37e477703e903dfcb82b..96bc8e88cf39086a9e0a883b8e2c311fe82a5e97:/wp-admin/custom-header.php diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index bf5f4157..ebeb2a5a 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -42,6 +42,16 @@ class Custom_Image_Header { */ var $default_headers = array(); + + /** + * Holds custom headers uploaded by the user + * + * @var array + * @since 3.2.0 + * @access private + */ + var $uploaded_headers = array(); + /** * Holds the page menu hook. * @@ -52,14 +62,14 @@ class Custom_Image_Header { var $page = ''; /** - * PHP4 Constructor - Register administration header callback. + * Constructor - Register administration header callback. * * @since 2.1.0 * @param callback $admin_header_callback * @param callback $admin_image_div_callback Optional custom image div output callback. * @return Custom_Image_Header */ - function Custom_Image_Header($admin_header_callback, $admin_image_div_callback = '') { + function __construct($admin_header_callback, $admin_image_div_callback = '') { $this->admin_header_callback = $admin_header_callback; $this->admin_image_div_callback = $admin_image_div_callback; } @@ -89,12 +99,20 @@ class Custom_Image_Header { * @since 3.0.0 */ function help() { - add_contextual_help( $this->page, '

' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately.' ) . '

' . - '

' . __( 'If you want to discard your custom header and go back to the default included in your theme, click on the buttons to remove the custom image and restore the original header image.' ) . '

' . - '

' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you’d like and click the Save Changes button.' ) . '

' . - '

' . __( 'For more information:' ) . '

' . - '

' . __( 'Documentation on Custom Header' ) . '

' . - '

' . __( 'Support Forums' ) . '

' ); + get_current_screen()->add_help_tab( array( + 'id' => 'overview', + 'title' => __('Overview'), + 'content' => + '

' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately.' ) . '

' . + '

' . __( 'If you want to discard your custom header and go back to the default included in your theme, click on the buttons to remove the custom image and restore the original header image.' ) . '

' . + '

' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you’d like and click the Save Changes button.' ) . '

' + ) ); + + get_current_screen()->set_help_sidebar( + '

' . __( 'For more information:' ) . '

' . + '

' . __( 'Documentation on Custom Header' ) . '

' . + '

' . __( 'Support Forums' ) . '

' + ); } /** @@ -183,7 +201,7 @@ class Custom_Image_Header { if ( isset( $_POST['removeheader'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); - set_theme_mod( 'header_image', '' ); + set_theme_mod( 'header_image', 'remove-header' ); return; } @@ -199,11 +217,20 @@ class Custom_Image_Header { } } - if ( isset($_POST['default-header']) ) { + if ( isset( $_POST['default-header'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); - $this->process_default_headers(); - if ( isset($this->default_headers[$_POST['default-header']]) ) - set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url'])); + if ( 'random-default-image' == $_POST['default-header'] ) { + set_theme_mod( 'header_image', 'random-default-image' ); + } elseif ( 'random-uploaded-image' == $_POST['default-header'] ) { + set_theme_mod( 'header_image', 'random-uploaded-image' ); + } else { + $this->process_default_headers(); + $uploaded = get_uploaded_header_images(); + if ( isset( $uploaded[$_POST['default-header']] ) ) + set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) ); + elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) + set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); + } } } @@ -222,26 +249,50 @@ class Custom_Image_Header { return; $this->default_headers = $_wp_default_headers; + $template_directory_uri = get_template_directory_uri(); + $stylesheet_directory_uri = get_stylesheet_directory_uri(); foreach ( array_keys($this->default_headers) as $header ) { - $this->default_headers[$header]['url'] = sprintf( $this->default_headers[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); - $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); + $this->default_headers[$header]['url'] = sprintf( $this->default_headers[$header]['url'], $template_directory_uri, $stylesheet_directory_uri ); + $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri ); } + } /** * Display UI for selecting one of several default headers. * + * Show the random image option if this theme has multiple header images. + * Random image option is on by default if no header has been set. + * * @since 3.0.0 */ - function show_default_header_selector() { - echo '
'; - foreach ( $this->default_headers as $header_key => $header ) { + function show_header_selector( $type = 'default' ) { + if ( 'default' == $type ) { + $headers = $this->default_headers; + } else { + $headers = get_uploaded_header_images(); + $type = 'uploaded'; + } + + if ( 1 < count( $headers ) ) { + echo '
'; + echo ''; + echo '
'; + } + + echo '
'; + foreach ( $headers as $header_key => $header ) { $header_thumbnail = $header['thumbnail_url']; $header_url = $header['url']; - $header_desc = $header['description']; + $header_desc = empty( $header['description'] ) ? '' : $header['description']; echo '
'; - echo ''; + echo ''; echo '
'; } echo '
'; @@ -347,7 +398,8 @@ class Custom_Image_Header { header_text() ) { ?> toggle_text(); - }); + }); +/* ]]> */ -

@@ -480,22 +531,32 @@ class Custom_Image_Header {
- default_headers ) ) : ?> + + + + + + default_headers ) ) : ?> @@ -506,7 +567,7 @@ class Custom_Image_Header { + if ( defined( 'HEADER_IMAGE' ) && '' != HEADER_IMAGE ) : ?>
+

+ show_header_selector( 'uploaded' ); + ?> +
-

+

-

+

show_default_header_selector(); + $this->show_header_selector( 'default' ); ?>
@@ -519,7 +580,6 @@ class Custom_Image_Header {
header_text() ) : ?> -

@@ -577,7 +637,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> function step_2() { check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload'); if ( ! current_theme_supports( 'custom-header-uploads' ) ) - wp_die( 'Cheatin’ uh?' ); + wp_die( __( 'Cheatin’ uh?' ) ); $overrides = array('test_form' => false); $file = wp_handle_upload($_FILES['import'], $overrides); @@ -596,7 +656,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 'post_content' => $url, 'post_mime_type' => $type, 'guid' => $url, - 'context' => 'custom-header'); + 'context' => 'custom-header' + ); // Save the data $id = wp_insert_attachment($object, $file); @@ -606,6 +667,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { // Add the meta-data wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); set_theme_mod('header_image', esc_url($url)); do_action('wp_create_file_in_uploads', $file, $id); // For replication @@ -661,7 +723,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> function step_3() { check_admin_referer('custom-header-crop-image'); if ( ! current_theme_supports( 'custom-header-uploads' ) ) - wp_die( 'Cheatin’ uh?' ); + wp_die( __( 'Cheatin’ uh?' ) ); if ( $_POST['oitar'] > 1 ) { $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; @@ -670,21 +732,22 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> $_POST['height'] = $_POST['height'] * $_POST['oitar']; } - $original = get_attached_file( $_POST['attachment_id'] ); + $attachment_id = absint( $_POST['attachment_id'] ); + $original = get_attached_file($attachment_id); - $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); + $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); if ( is_wp_error( $cropped ) ) wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); - $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication + $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication - $parent = get_post($_POST['attachment_id']); + $parent = get_post($attachment_id); $parent_url = $parent->guid; $url = str_replace(basename($parent_url), basename($cropped), $parent_url); // Construct the object array $object = array( - 'ID' => $_POST['attachment_id'], + 'ID' => $attachment_id, 'post_title' => basename($cropped), 'post_content' => $url, 'post_mime_type' => 'image/jpeg', @@ -694,7 +757,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> // Update the attachment wp_insert_attachment($object, $cropped); - wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) ); + wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); + update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); set_theme_mod('header_image', $url);