Make WordPress Core

Changeset 13403


Ignore:
Timestamp:
02/25/2010 07:18:44 PM (15 years ago)
Author:
ryan
Message:

Default header selector, first pass. see #12343

Location:
trunk
Files:
3 edited

Legend:

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

    r13339 r13403  
    3333     */
    3434    var $admin_image_div_callback;
     35
     36    var $default_headers = array();
    3537
    3638    /**
     
    134136            remove_theme_mods();
    135137        }
     138
     139        if ( isset($_POST['default-header']) ) {
     140            $this->process_default_headers();
     141            if ( isset($this->default_headers[$_POST['default-header']]) )
     142                set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url']));
     143        }
     144    }
     145
     146    /**
     147     * Process the default headers
     148     *
     149     *  @since 3.0.0
     150     */
     151    function process_default_headers() {
     152        global $_wp_default_headers;
     153
     154        if ( !empty($this->headers) )
     155            return;
     156
     157        if ( !isset($_wp_default_headers) )
     158            return;
     159
     160        $this->default_headers = $_wp_default_headers;
     161        foreach ( array_keys($this->default_headers) as $header ) {
     162            $this->default_headers[$header]['url'] =  sprintf( $this->default_headers[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
     163            $this->default_headers[$header]['thumbnail_url'] =  sprintf( $this->default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
     164        }
     165    }
     166
     167    /**
     168     * Display UI for selecting one of several default headers.
     169     *
     170     * @since 3.0.0
     171     */
     172    function show_default_header_selector() {
     173        echo '<table id="available-headers" cellspacing="0" cellpadding="0">';
     174
     175        $headers = array_keys($this->default_headers);
     176        $table = array();
     177        $rows = ceil(count($headers) / 3);
     178        for ( $row = 1; $row <= $rows; $row++ ) {
     179            for ( $col = 1; $col <= 3; $col++ ) {
     180                $table[$row][$col] = array_shift($headers);
     181            }
     182        }
     183
     184        foreach ( $table as $row => $cols ) {
     185            echo '<tr>';
     186            foreach ( $cols as $col => $header_key ) {
     187                if ( !$header_key )
     188                    continue;
     189                $class = array('available-theme');
     190                if ( $row == 1 ) $class[] = 'top';
     191                if ( $col == 1 ) $class[] = 'left';
     192                if ( $row == $rows ) $class[] = 'bottom';
     193                if ( $col == 3 ) $class[] = 'right';
     194                if ( !isset($this->headers[$header_key]))
     195                echo '<td class="' . join(' ', $class) . '">';
     196                $header_thumbnail = $this->default_headers[$header_key]['thumbnail_url'];
     197                $header_url = $this->default_headers[$header_key]['url'];
     198                $header_desc = $this->default_headers[$header_key]['description'];
     199                echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_header_image(), false) . ' />';
     200                echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" /></label>';
     201                echo  '</td>';
     202            }
     203            echo '</tr>';
     204        }
     205        echo '</table>';
    136206    }
    137207
     
    285355     */
    286356    function step_1() {
     357        $this->process_default_headers();
    287358        if ( isset($_GET['updated']) && $_GET['updated'] ) { ?>
    288359<div id="message" class="updated">
     
    294365<?php screen_icon(); ?>
    295366<h2><?php _e('Your Header Image'); ?></h2>
     367<?php
     368if ( get_theme_mod('header_image') || empty($this->default_headers) ) :
     369?>
    296370<p><?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?></p>
    297371<?php
     
    311385<input type="button" class="button" value="<?php esc_attr_e('Hide Text'); ?>" onclick="hide_text()" id="hidetext" />
    312386<input type="button" class="button" value="<?php esc_attr_e('Select a Text Color'); ?>" id="pickcolor" /><input type="button" class="button" value="<?php esc_attr_e('Use Original Color'); ?>" onclick="colorDefault()" id="defaultcolor" />
    313 <?php wp_nonce_field('custom-header') ?>
     387<?php wp_nonce_field('custom-header'); ?>
    314388<input type="hidden" name="textcolor" id="textcolor" value="#<?php esc_attr(header_textcolor()) ?>" /><input name="submit" type="submit" class="button" value="<?php esc_attr_e('Save Changes'); ?>" /></form>
    315389<?php } ?>
     
    317391<div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"> </div>
    318392</div>
     393<?php
     394else:
     395    echo '<p>' . __('Choose one of these cool headers, or upload your own image below.') . '</p>';
     396    echo '<form method="post" action="' . admin_url('themes.php?page=custom-header&amp;updated=true') . '">';
     397    wp_nonce_field('custom-header');
     398    $this->show_default_header_selector();
     399    echo '<input type="submit" class="button" value="' . esc_attr__('Save Your Choice') . '"  />';
     400    echo '</form>';
     401    echo '</div>';
     402endif;
     403?>
    319404<div class="wrap">
    320405<h2><?php _e('Upload New Header Image'); ?></h2><p><?php _e('Here you can upload a custom header image to be shown at the top of your blog instead of the default one. On the next screen you will be able to crop the image.'); ?></p>
  • trunk/wp-content/themes/twentyten/functions.php

    r13398 r13403  
    1010    // No CSS, just IMG call
    1111    define( 'HEADER_TEXTCOLOR', '');
    12     define( 'HEADER_IMAGE', '%s/images/header-1.jpg'); // %s is theme dir uri
     12    define( 'HEADER_IMAGE', '%s/images/headers/forestfloor.jpg'); // %s is theme dir uri
    1313    define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width',  940 ) );
    1414    define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height',  198 ) );
     
    1717    add_custom_image_header( '', 'twentyten_admin_header_style' );
    1818    // and thus ends the changeable header business
     19
     20    register_default_headers( array('berries' => array('url' => '%s/images/headers/berries.jpg', 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg', 'description' => __('Berries')),
     21                                    'cherryblossom' => array( 'url' => '%s/images/headers/cherryblossoms.jpg', 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg', 'description' => __('Cherry Blossoms')),
     22                                    'concave' => array('url' => '%s/images/headers/concave.jpg', 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg', 'description' => __('Concave')),
     23                                    'fern' => array('url' => '%s/images/headers/fern.jpg', 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg', 'description' => __('Fern')),
     24                                    'forestfloor' => array('url' => '%s/images/headers/forestfloor.jpg', 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg', 'description' => __('Forest Floor')),
     25                                    'inkwell' => array('url' => '%s/images/headers/inkwell.jpg', 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg', 'description' => __('Ink Well')),
     26                                    'path' => array('url' => '%s/images/headers/path.jpg', 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', 'description' => __('Path')),
     27                                    'sunset' => array('url' => '%s/images/headers/sunset.jpg', 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', 'description' => __('Sunset')) ) );
    1928
    2029    add_custom_background();
  • trunk/wp-includes/theme.php

    r13377 r13403  
    13331333    $GLOBALS['custom_image_header'] =& new Custom_Image_Header($admin_header_callback, $admin_image_div_callback);
    13341334    add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init'));
     1335}
     1336
     1337/**
     1338 * Register a selection of default headers to be displayed by the custom header admin UI.
     1339 *
     1340 * @since 3.0.0
     1341 *
     1342 * @param array $headers Array of headers keyed by a string id.  The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys.
     1343 */
     1344function register_default_headers( $headers ) {
     1345    global $_wp_default_headers;
     1346
     1347    $_wp_default_headers = $headers;
    13351348}
    13361349
Note: See TracChangeset for help on using the changeset viewer.