Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-header.php

    r18023 r18298  
    4343    var $default_headers = array();
    4444
     45
     46    /**
     47     * Holds custom headers uploaded by the user
     48     *
     49     * @var array
     50     * @since 3.2.0
     51     * @access private
     52     */
     53    var $uploaded_headers = array();
     54
    4555    /**
    4656     * Holds the page menu hook.
     
    5363
    5464    /**
    55      * PHP4 Constructor - Register administration header callback.
     65     * Constructor - Register administration header callback.
    5666     *
    5767     * @since 2.1.0
     
    6070     * @return Custom_Image_Header
    6171     */
    62     function Custom_Image_Header($admin_header_callback, $admin_image_div_callback = '') {
     72    function __construct($admin_header_callback, $admin_image_div_callback = '') {
    6373        $this->admin_header_callback = $admin_header_callback;
    6474        $this->admin_image_div_callback = $admin_image_div_callback;
     
    94104        '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you&#8217;d like and click the Save Changes button.' ) . '</p>' .
    95105        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    96         '<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Header_SubPanel" target="_blank">Documentation on Custom Header</a>' ) . '</p>' .
     106        '<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Header_Screen" target="_blank">Documentation on Custom Header</a>' ) . '</p>' .
    97107        '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' );
    98108    }
     
    184194        if ( isset( $_POST['removeheader'] ) ) {
    185195            check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    186             set_theme_mod( 'header_image', '' );
     196            set_theme_mod( 'header_image', 'remove-header' );
    187197            return;
    188198        }
     
    200210        }
    201211
    202         if ( isset($_POST['default-header']) ) {
     212        if ( isset( $_POST['default-header'] ) ) {
    203213            check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    204             $this->process_default_headers();
    205             if ( isset($this->default_headers[$_POST['default-header']]) )
    206                 set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url']));
     214            if ( 'random-default-image' == $_POST['default-header'] ) {
     215                set_theme_mod( 'header_image', 'random-default-image' );
     216            } elseif ( 'random-uploaded-image' == $_POST['default-header'] ) {
     217                set_theme_mod( 'header_image', 'random-uploaded-image' );
     218            } else {
     219                $this->process_default_headers();
     220                $uploaded = get_uploaded_header_images();
     221                if ( isset( $uploaded[$_POST['default-header']] ) )
     222                    set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) );
     223                elseif ( isset( $this->default_headers[$_POST['default-header']] ) )
     224                    set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) );
     225            }
    207226        }
    208227    }
     
    227246            $this->default_headers[$header]['thumbnail_url'] =  sprintf( $this->default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
    228247        }
     248
    229249    }
    230250
     
    232252     * Display UI for selecting one of several default headers.
    233253     *
     254     * Show the random image option if this theme has multiple header images.
     255     * Random image option is on by default if no header has been set.
     256     *
    234257     * @since 3.0.0
    235258     */
    236     function show_default_header_selector() {
    237         echo '<div id="available-headers">';
    238         foreach ( $this->default_headers as $header_key => $header ) {
     259    function show_header_selector( $type = 'default' ) {
     260        if ( 'default' == $type ) {
     261            $headers = $this->default_headers;
     262        } else {
     263            $headers = get_uploaded_header_images();
     264            $type = 'uploaded';
     265        }
     266
     267        if ( 1 < count( $headers ) ) {
     268            echo '<div class="random-header">';
     269            echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />';
     270            echo __( '<strong>Random:</strong> Show a different image on each page.' );
     271            echo '</label>';
     272            echo '</div>';
     273        }
     274
     275        echo '<div class="available-headers">';
     276        foreach ( $headers as $header_key => $header ) {
    239277            $header_thumbnail = $header['thumbnail_url'];
    240278            $header_url = $header['url'];
    241             $header_desc = $header['description'];
     279            $header_desc = empty( $header['description'] ) ? '' : $header['description'];
    242280            echo '<div class="default-header">';
    243             echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_theme_mod( 'header_image' ), false) . ' />';
    244             echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" title="' . esc_attr($header_desc) .'" /></label>';
     281            echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />';
     282            $width = '';
     283            if ( !empty( $header['uploaded'] ) )
     284                $width = ' width="230"';
     285            echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr( $header_desc ) .'" title="' . esc_attr( $header_desc ) . '"' . $width . ' /></label>';
    245286            echo '</div>';
    246287        }
     
    348389        toggle_text();
    349390        <?php } ?>
    350         });
     391    });
     392/* ]]> */
    351393</script>
    352394<?php
     
    432474<?php } ?>
    433475
    434 <h3><?php _e( 'Header Image' ) ?></h3>
    435476<table class="form-table">
    436477<tbody>
     
    481522<table class="form-table">
    482523<tbody>
    483     <?php if ( ! empty( $this->default_headers ) ) : ?>
     524    <?php if ( get_uploaded_header_images() ) : ?>
     525<tr valign="top">
     526<th scope="row"><?php _e( 'Uploaded Images' ); ?></th>
     527<td>
     528    <p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ) ?></p>
     529    <?php
     530        $this->show_header_selector( 'uploaded' );
     531    ?>
     532</td>
     533</tr>
     534    <?php endif;
     535    if ( ! empty( $this->default_headers ) ) : ?>
    484536<tr valign="top">
    485537<th scope="row"><?php _e( 'Default Images' ); ?></th>
    486538<td>
    487539<?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?>
    488     <p><?php _e( 'If you don&lsquo;t want to upload your own image, you can use one of these cool headers.' ) ?></p>
     540    <p><?php _e( 'If you don&lsquo;t want to upload your own image, you can use one of these cool headers, or show a random one.' ) ?></p>
    489541<?php else: ?>
    490     <p><?php _e( 'You can use one of these cool headers.' ) ?>
     542    <p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ) ?></p>
    491543<?php endif; ?>
    492544    <?php
    493         $this->show_default_header_selector();
     545        $this->show_header_selector( 'default' );
    494546    ?>
    495547</td>
    496548</tr>
    497549    <?php endif;
    498 
    499550    if ( get_header_image() ) : ?>
    500551<tr valign="top">
     
    507558    <?php endif;
    508559
    509     if ( defined( 'HEADER_IMAGE' ) ) : ?>
     560    if ( defined( 'HEADER_IMAGE' ) && '' != HEADER_IMAGE ) : ?>
    510561<tr valign="top">
    511562<th scope="row"><?php _e( 'Reset Image' ); ?></th>
     
    520571
    521572    <?php if ( $this->header_text() ) : ?>
    522 <h3><?php _e( 'Header Text' ) ?></h3>
    523573<table class="form-table">
    524574<tbody>
     
    607657            // Add the meta-data
    608658            wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
     659            update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
    609660
    610661            set_theme_mod('header_image', esc_url($url));
     
    671722        }
    672723
    673         $original = get_attached_file( $_POST['attachment_id'] );
    674 
    675         $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);
     724        $attachment_id = absint( $_POST['attachment_id'] );
     725        $original = get_attached_file($attachment_id);
     726
     727        $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
    676728        if ( is_wp_error( $cropped ) )
    677729            wp_die( __( 'Image could not be processed.  Please go back and try again.' ), __( 'Image Processing Error' ) );
    678730
    679         $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication
    680 
    681         $parent = get_post($_POST['attachment_id']);
     731        $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
     732
     733        $parent = get_post($attachment_id);
    682734        $parent_url = $parent->guid;
    683735        $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
     
    685737        // Construct the object array
    686738        $object = array(
    687             'ID' => $_POST['attachment_id'],
     739            'ID' => $attachment_id,
    688740            'post_title' => basename($cropped),
    689741            'post_content' => $url,
     
    695747        // Update the attachment
    696748        wp_insert_attachment($object, $cropped);
    697         wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) );
     749        wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) );
     750        update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
    698751
    699752        set_theme_mod('header_image', $url);
Note: See TracChangeset for help on using the changeset viewer.