Make WordPress Core

Ticket #15926: therightone.patch

File therightone.patch, 34.3 KB (added by firetag, 14 years ago)
  • wp-admin/custom-header.php

     
    168168                        return;
    169169
    170170                $this->updated = true;
    171 
     171                check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    172172                if ( isset( $_POST['resetheader'] ) ) {
    173                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
     173                       
    174174                        remove_theme_mod( 'header_image' );
    175175                        return;
    176176                }
    177177
    178178                if ( isset( $_POST['resettext'] ) ) {
    179                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    180179                        remove_theme_mod('header_textcolor');
    181180                        return;
    182181                }
    183182
    184183                if ( isset( $_POST['removeheader'] ) ) {
    185                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    186184                        set_theme_mod( 'header_image', '' );
    187185                        return;
    188186                }
    189187
    190188                if ( isset( $_POST['text-color'] ) ) {
    191                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    192189                        $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] );
    193190                        if ( 'blank' == $_POST['text-color'] ) {
    194191                                set_theme_mod( 'header_textcolor', 'blank' );
     
    200197                }
    201198
    202199                if ( isset($_POST['default-header']) ) {
    203                         check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    204200                        $this->process_default_headers();
    205201                        if ( isset($this->default_headers[$_POST['default-header']]) )
    206202                                set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url']));
    207203                }
     204
     205                if ( isset($_POST['alt-text']) ) {
     206                        set_theme_mod('header_alt', esc_html($_POST['alt-text']));
     207                }
    208208        }
    209209
    210210        /**
     
    456456        <?php } ?>
    457457</td>
    458458</tr>
    459 <?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?>
     459
    460460<tr valign="top">
    461461<th scope="row"><?php _e( 'Upload Image' ); ?></th>
    462462<td>
     
    468468                <input type="file" id="upload" name="import" />
    469469                <input type="hidden" name="action" value="save" />
    470470                <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ) ?>
    471                 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
     471                <input type="submit" class="button" value="<?php esc_attr_e( 'Upload' ); ?>" />
    472472        </p>
    473473        </form>
    474474</td>
    475475</tr>
    476 <?php endif; ?>
     476
    477477</tbody>
    478478</table>
    479479
     
    484484<tr valign="top">
    485485<th scope="row"><?php _e( 'Default Images' ); ?></th>
    486486<td>
    487 <?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?>
    488487        <p><?php _e( 'If you don&lsquo;t want to upload your own image, you can use one of these cool headers.' ) ?></p>
    489 <?php else: ?>
    490         <p><?php _e( 'You can use one of these cool headers.' ) ?>
    491 <?php endif; ?>
    492488        <?php
    493489                $this->show_default_header_selector();
    494490        ?>
    495491</td>
    496492</tr>
    497493        <?php endif;
     494        if ( get_header_image() ) :
     495 ?>
     496<tr valign="top">
     497<th scope="row"><?php _e( 'Alternative Text' ); ?></th>
     498<td>
     499<fieldset>
     500    <legend class="screen-reader-text">
     501        <span><?php _e( 'Alternative Text' ); ?></span>
     502    </legend>
     503    <input type="text" name="alt-text" id="alt-text" value="<?php echo esc_html(get_background_alt()) ?>" />
     504</fieldset></td>
     505</tr>
    498506
    499         if ( get_header_image() ) : ?>
    500507<tr valign="top">
    501508<th scope="row"><?php _e( 'Remove Image' ); ?></th>
    502509<td>
    503510        <p><?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ) ?></p>
    504         <?php submit_button( __( 'Remove Header Image' ), 'button', 'removeheader', false ); ?>
     511        <input type="submit" class="button" name="removeheader" value="<?php esc_attr_e( 'Remove Header Image' ); ?>" />
    505512</td>
    506513</tr>
    507514        <?php endif;
     
    511518<th scope="row"><?php _e( 'Reset Image' ); ?></th>
    512519<td>
    513520        <p><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?></p>
    514         <?php submit_button( __( 'Restore Original Header Image' ), 'button', 'resetheader', false ); ?>
     521        <input type="submit" class="button" name="resetheader" value="<?php esc_attr_e( 'Restore Original Header Image' ); ?>" />
    515522</td>
    516523</tr>
    517524        <?php endif; ?>
     
    550557<th scope="row"><?php _e('Reset Text Color'); ?></th>
    551558<td>
    552559        <p><?php _e( 'This will restore the original header text. You will not be able to restore any customizations.' ) ?></p>
    553         <?php submit_button( __( 'Restore Original Header Text' ), 'button', 'resettext', false ); ?>
     560        <input type="submit" class="button" name="resettext" value="<?php esc_attr_e( 'Restore Original Header Text' ); ?>" />
    554561</td>
    555562</tr>
    556563        <?php } ?>
     
    559566</table>
    560567        <?php endif;
    561568
    562 do_action( 'custom_header_options' );
    563 
    564569wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
    565 
    566 <?php submit_button( null, 'primary', 'save-header-options' ); ?>
     570<p class="submit"><input type="submit" class="button-primary" name="save-header-options" value="<?php esc_attr_e( 'Save Changes' ); ?>" /></p>
    567571</form>
    568572</div>
    569573
     
    576580         */
    577581        function step_2() {
    578582                check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload');
    579                 if ( ! current_theme_supports( 'custom-header-uploads' ) )
    580                         wp_die( 'Cheatin&#8217; uh?' );
    581 
    582583                $overrides = array('test_form' => false);
    583584                $file = wp_handle_upload($_FILES['import'], $overrides);
    584585
     
    637638                <img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
    638639        </div>
    639640
     641        <p class="submit">
    640642        <input type="hidden" name="x1" id="x1" value="0"/>
    641643        <input type="hidden" name="y1" id="y1" value="0"/>
    642644        <input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/>
     
    644646        <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" />
    645647        <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
    646648        <?php wp_nonce_field( 'custom-header-crop-image' ) ?>
    647 
    648         <?php submit_button( __( 'Crop and Publish' ) ); ?>
     649        <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Crop and Publish' ); ?>" />
    649650        </p>
    650651</form>
    651652</div>
     
    659660         */
    660661        function step_3() {
    661662                check_admin_referer('custom-header-crop-image');
    662                 if ( ! current_theme_supports( 'custom-header-uploads' ) )
    663                         wp_die( 'Cheatin&#8217; uh?' );
    664 
    665663                if ( $_POST['oitar'] > 1 ) {
    666664                        $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
    667665                        $_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
  • wp-content/themes/twentyten/header.php

     
    7272                                                        ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
    7373                                                        $image[1] >= HEADER_IMAGE_WIDTH ) :
    7474                                                // Houston, we have a new header image!
    75                                                 echo get_the_post_thumbnail( $post->ID );
    76                                         elseif ( get_header_image() ) : ?>
    77                                                 <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
     75                                                echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
     76                                        else : ?>
     77                                <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="<?php header_alt(); ?>" />
    7878                                        <?php endif; ?>
    7979                        </div><!-- #branding -->
    8080
  • wp-includes/theme.php

     
    166166 * The description will have the tags filtered with the following HTML elements
    167167 * whitelisted. The <b>'a'</b> element with the <em>href</em> and <em>title</em>
    168168 * attributes. The <b>abbr</b> element with the <em>title</em> attribute. The
    169  * <b>acronym</b> element with the <em>title</em> attribute allowed. The
     169 * <b>acronym<b> element with the <em>title</em> attribute allowed. The
    170170 * <b>code</b>, <b>em</b>, and <b>strong</b> elements also allowed.
    171171 *
    172172 * The style.css file must contain theme name, theme URI, and description. The
     
    239239                if ( empty( $theme_data['AuthorURI'] ) ) {
    240240                        $theme_data['Author'] = $theme_data['AuthorName'];
    241241                } else {
    242                         $theme_data['Author'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], esc_attr__( 'Visit author homepage' ), $theme_data['AuthorName'] );
     242                        $theme_data['Author'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $theme_data['AuthorURI'], __( 'Visit author homepage' ), $theme_data['AuthorName'] );
    243243                }
    244244        }
    245245
     
    267267        if ( isset($wp_themes) )
    268268                return $wp_themes;
    269269
     270        /* Register the default root as a theme directory */
     271        register_theme_directory( get_theme_root() );
     272
    270273        if ( !$theme_files = search_theme_directories() )
    271274                return false;
    272275
     
    385388                $template_files = array_unique($template_files);
    386389                $stylesheet_files = array_unique($stylesheet_files);
    387390
    388                 $template_dir = $template_directory;
    389                 $stylesheet_dir = $theme_root . '/' . $stylesheet;
     391                $template_dir = dirname($template_files[0]);
     392                $stylesheet_dir = dirname($stylesheet_files[0]);
    390393
    391394                if ( empty($template_dir) )
    392395                        $template_dir = '/';
     
    396399                // Check for theme name collision.  This occurs if a theme is copied to
    397400                // a new theme directory and the theme header is not updated.  Whichever
    398401                // theme is first keeps the name.  Subsequent themes get a suffix applied.
    399                 // The Twenty Ten, Default and Classic themes always trump their pretenders.
     402                // The Default and Classic themes always trump their pretenders.
    400403                if ( isset($wp_themes[$name]) ) {
    401                         $trump_cards = array(
    402                                 'classic'   => 'WordPress Classic',
    403                                 'default'   => 'WordPress Default',
    404                                 'twentyten' => 'Twenty Ten',
    405                         );
    406                         if ( isset( $trump_cards[ $stylesheet ] ) && $name == $trump_cards[ $stylesheet ] ) {
     404                        if ( ('WordPress Default' == $name || 'WordPress Classic' == $name) &&
     405                                         ('default' == $stylesheet || 'classic' == $stylesheet) ) {
    407406                                // If another theme has claimed to be one of our default themes, move
    408407                                // them aside.
    409408                                $suffix = $wp_themes[$name]['Stylesheet'];
     
    467466 *
    468467 * @since 2.9.0
    469468 *
    470  * @return array|string An arry of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.
     469 * @return array Theme roots
    471470 */
    472471function get_theme_roots() {
    473         global $wp_theme_directories;
    474 
    475         if ( count($wp_theme_directories) <= 1 )
    476                 return '/themes';
    477 
    478472        $theme_roots = get_site_transient( 'theme_roots' );
    479473        if ( false === $theme_roots ) {
    480474                get_themes();
     
    519513        $theme_names = array_keys($themes);
    520514        $current_template = get_option('template');
    521515        $current_stylesheet = get_option('stylesheet');
    522         $current_theme = 'Twenty Ten';
     516        $current_theme = 'WordPress Default';
    523517
    524518        if ( $themes ) {
    525519                foreach ( (array) $theme_names as $theme_name ) {
     
    594588
    595589                while ( ($theme_dir = readdir($themes_dir)) !== false ) {
    596590                        if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
    597                                 if ( $theme_dir[0] == '.' || $theme_dir == 'CVS' )
     591                                if ( $theme_dir{0} == '.' || $theme_dir == 'CVS' )
    598592                                        continue;
    599593
    600594                                $stylish_dir = @opendir($theme_root . '/' . $theme_dir);
     
    617611                                        $found_subdir_themes = false;
    618612                                        while ( ($theme_subdir = readdir($theme_subdirs)) !== false ) {
    619613                                                if ( is_dir( $subdir . '/' . $theme_subdir) && is_readable($subdir . '/' . $theme_subdir) ) {
    620                                                         if ( $theme_subdir[0] == '.' || $theme_subdir == 'CVS' )
     614                                                        if ( $theme_subdir{0} == '.' || $theme_subdir == 'CVS' )
    621615                                                                continue;
    622616
    623617                                                        $stylish_dir = @opendir($subdir . '/' . $theme_subdir);
     
    651645 * Does not have trailing slash.
    652646 *
    653647 * @since 1.5.0
     648 * @param $stylesheet_or_template The stylesheet or template name of the theme
    654649 * @uses apply_filters() Calls 'theme_root' filter on path.
    655650 *
    656  * @param string $stylesheet_or_template The stylesheet or template name of the theme
    657651 * @return string Theme path.
    658652 */
    659653function get_theme_root( $stylesheet_or_template = false ) {
    660         if ( $stylesheet_or_template ) {
    661                 if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
    662                         $theme_root = WP_CONTENT_DIR . $theme_root;
     654        if ($stylesheet_or_template) {
     655                $theme_roots = get_theme_roots();
     656
     657                if ( ! empty( $theme_roots[$stylesheet_or_template] ) )
     658                        $theme_root = WP_CONTENT_DIR . $theme_roots[$stylesheet_or_template];
    663659                else
    664660                        $theme_root = WP_CONTENT_DIR . '/themes';
    665661        } else {
     
    675671 * Does not have trailing slash.
    676672 *
    677673 * @since 1.5.0
     674 * @param $stylesheet_or_template The stylesheet or template name of the theme
    678675 *
    679  * @param string $stylesheet_or_template The stylesheet or template name of the theme
    680676 * @return string Themes URI.
    681677 */
    682678function get_theme_root_uri( $stylesheet_or_template = false ) {
    683         if ( $stylesheet_or_template ) {
    684                 if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
    685                         $theme_root_uri = content_url( $theme_root );
    686                 else
    687                         $theme_root_uri = content_url( 'themes' );
    688         } else {
     679        $theme_roots = get_theme_roots();
     680
     681        if ( isset( $theme_roots[$stylesheet_or_template] ) && $theme_roots[$stylesheet_or_template] )
     682                $theme_root_uri = content_url( $theme_roots[$stylesheet_or_template] );
     683        else
    689684                $theme_root_uri = content_url( 'themes' );
    690         }
    691685
    692686        return apply_filters( 'theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template );
    693687}
    694688
    695689/**
    696  * Get the raw theme root relative to the content directory with no filters applied.
     690 * Retrieve path to file without the use of extension.
    697691 *
    698  * @since 3.1.0
    699  *
    700  * @param string $stylesheet_or_template The stylesheet or template name of the theme
    701  * @return string Theme root
    702  */
    703 function get_raw_theme_root( $stylesheet_or_template, $no_cache = false ) {
    704         global $wp_theme_directories;
    705 
    706         if ( count($wp_theme_directories) <= 1 )
    707                 return '/themes';
    708 
    709         $theme_root = false;
    710 
    711         // If requesting the root for the current theme, consult options to avoid calling get_theme_roots()
    712         if ( !$no_cache ) {
    713                 if ( get_option('stylesheet') == $stylesheet_or_template )
    714                         $theme_root = get_option('stylesheet_root');
    715                 elseif ( get_option('template') == $stylesheet_or_template )
    716                         $theme_root = get_option('template_root');
    717         }
    718 
    719         if ( empty($theme_root) ) {
    720                 $theme_roots = get_theme_roots();
    721                 if ( !empty($theme_roots[$stylesheet_or_template]) )
    722                         $theme_root = $theme_roots[$stylesheet_or_template];
    723         }
    724 
    725         return $theme_root;
    726 }
    727 
    728 /**
    729  * Retrieve path to a template
    730  *
    731  * Used to quickly retrieve the path of a template without including the file
    732  * extension. It will also check the parent theme, if the file exists, with
    733  * the use of {@link locate_template()}. Allows for more generic template location
     692 * Used to quickly retrieve the path of file without including the file
     693 * extension. It will also check the parent template, if the file exists, with
     694 * the use of {@link locate_template()}. Allows for more generic file location
    734695 * without the use of the other get_*_template() functions.
    735696 *
     697 * Can be used with include() or require() to retrieve path.
     698 * <code>
     699 * if( '' != get_query_template( '404' ) )
     700 *     include( get_query_template( '404' ) );
     701 * </code>
     702 * or the same can be accomplished with
     703 * <code>
     704 * if( '' != get_404_template() )
     705 *     include( get_404_template() );
     706 * </code>
     707 *
    736708 * @since 1.5.0
    737709 *
    738710 * @param string $type Filename without extension.
    739  * @param array $templates An optional list of template candidates
    740711 * @return string Full path to file.
    741712 */
    742 function get_query_template( $type, $templates = array() ) {
     713function get_query_template($type) {
    743714        $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
    744 
    745         if ( empty( $templates ) )
    746                 $templates = array("{$type}.php");
    747 
    748         $templates = apply_filters( "{$type}_template_hierarchy", $templates );
    749 
    750         return apply_filters( "{$type}_template", locate_template( $templates ) );
     715        return apply_filters("{$type}_template", locate_template(array("{$type}.php")));
    751716}
    752717
    753718/**
     
    780745 * @return string
    781746 */
    782747function get_archive_template() {
    783         $post_type = get_query_var( 'post_type' );
    784 
    785         $templates = array();
    786 
    787         if ( $post_type )
    788                 $templates[] = "archive-{$post_type}.php";
    789         $templates[] = 'archive.php';
    790 
    791         return get_query_template( 'archive', $templates );
     748        return get_query_template('archive');
    792749}
    793750
    794751/**
     
    799756 * @return string
    800757 */
    801758function get_author_template() {
    802         $author = get_queried_object();
     759        $author_id = absint( get_query_var( 'author' ) );
     760        $author = get_user_by( 'id', $author_id );
     761        $author = $author->user_nicename;
    803762
    804763        $templates = array();
    805764
    806         $templates[] = "author-{$author->user_nicename}.php";
    807         $templates[] = "author-{$author->ID}.php";
     765        if ( $author )
     766                $templates[] = "author-{$author}.php";
     767        if ( $author_id )
     768                $templates[] = "author-{$author_id}.php";
    808769        $templates[] = 'author.php';
    809770
    810         return get_query_template( 'author', $templates );
     771        $template = locate_template( $templates );
     772        return apply_filters( 'author_template', $template );
    811773}
    812774
    813775/**
     
    823785 * @return string
    824786 */
    825787function get_category_template() {
    826         $category = get_queried_object();
     788        $cat_ID = absint( get_query_var('cat') );
     789        $category = get_category( $cat_ID );
    827790
    828791        $templates = array();
    829792
    830         $templates[] = "category-{$category->slug}.php";
    831         $templates[] = "category-{$category->term_id}.php";
     793        if ( !is_wp_error($category) )
     794                $templates[] = "category-{$category->slug}.php";
     795
     796        $templates[] = "category-$cat_ID.php";
    832797        $templates[] = "category.php";
    833798
    834         return get_query_template( 'category', $templates );
     799        $template = locate_template($templates);
     800        return apply_filters('category_template', $template);
    835801}
    836802
    837803/**
     
    847813 * @return string
    848814 */
    849815function get_tag_template() {
    850         $tag = get_queried_object();
     816        $tag_id = absint( get_query_var('tag_id') );
     817        $tag_name = get_query_var('tag');
    851818
    852819        $templates = array();
    853820
    854         $templates[] = "tag-{$tag->slug}.php";
    855         $templates[] = "tag-{$tag->term_id}.php";
     821        if ( $tag_name )
     822                $templates[] = "tag-$tag_name.php";
     823        if ( $tag_id )
     824                $templates[] = "tag-$tag_id.php";
    856825        $templates[] = "tag.php";
    857826
    858         return get_query_template( 'tag', $templates );
     827        $template = locate_template($templates);
     828        return apply_filters('tag_template', $template);
    859829}
    860830
    861831/**
     
    870840 * template is used. If none of the files exist, then it will fall back on to
    871841 * index.php.
    872842 *
    873  * @since 2.5.0
     843 * @since unknown (2.6.0 most likely)
    874844 * @uses apply_filters() Calls 'taxonomy_template' filter on found path.
    875845 *
    876846 * @return string
    877847 */
    878848function get_taxonomy_template() {
    879         $term = get_queried_object();
    880         $taxonomy = $term->taxonomy;
     849        $taxonomy = get_query_var('taxonomy');
     850        $term = get_query_var('term');
    881851
    882852        $templates = array();
     853        if ( $taxonomy && $term )
     854                $templates[] = "taxonomy-$taxonomy-$term.php";
     855        if ( $taxonomy )
     856                $templates[] = "taxonomy-$taxonomy.php";
    883857
    884         $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
    885         $templates[] = "taxonomy-$taxonomy.php";
    886858        $templates[] = "taxonomy.php";
    887859
    888         return get_query_template( 'taxonomy', $templates );
     860        $template = locate_template($templates);
     861        return apply_filters('taxonomy_template', $template);
    889862}
    890863
    891864/**
     
    912885 * @return string
    913886 */
    914887function get_home_template() {
    915         $templates = array( 'home.php', 'index.php' );
    916 
    917         return get_query_template( 'home', $templates );
     888        $template = locate_template(array('home.php', 'index.php'));
     889        return apply_filters('home_template', $template);
    918890}
    919891
    920892/**
     
    928900 * @return string
    929901 */
    930902function get_front_page_template() {
    931         $templates = array('front-page.php');
    932 
    933         return get_query_template( 'front_page', $templates );
     903        return apply_filters( 'front_page_template', locate_template( array('front-page.php') ) );
    934904}
    935905
    936906/**
     
    945915 * @return string
    946916 */
    947917function get_page_template() {
    948         $id = get_queried_object_id();
     918        global $wp_query;
     919
     920        $id = (int) $wp_query->get_queried_object_id();
    949921        $template = get_post_meta($id, '_wp_page_template', true);
    950922        $pagename = get_query_var('pagename');
    951923
    952924        if ( !$pagename && $id > 0 ) {
    953925                // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
    954                 $post = get_queried_object();
     926                $post = $wp_query->get_queried_object();
    955927                $pagename = $post->post_name;
    956928        }
    957929
     
    967939                $templates[] = "page-$id.php";
    968940        $templates[] = "page.php";
    969941
    970         return get_query_template( 'page', $templates );
     942        return apply_filters('page_template', locate_template($templates));
    971943}
    972944
    973945/**
     
    1000972 * @return string
    1001973 */
    1002974function get_single_template() {
    1003         $object = get_queried_object();
     975        global $wp_query;
    1004976
    1005         $templates = array();
    1006 
    1007         $templates[] = "single-{$object->post_type}.php";
    1008         $templates[] = "single.php";
    1009 
    1010         return get_query_template( 'single', $templates );
     977        $object = $wp_query->get_queried_object();
     978        $templates = array('single-' . $object->post_type . '.php', 'single.php');
     979        return apply_filters('single_template', locate_template($templates));
    1011980}
    1012981
    1013982/**
     
    10501019 * @return string
    10511020 */
    10521021function get_comments_popup_template() {
    1053         $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) );
     1022        $template = locate_template(array("comments-popup.php"));
    10541023
    10551024        // Backward compat code will be removed in a future release
    10561025        if ('' == $template)
    10571026                $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php';
    10581027
    1059         return $template;
     1028        return apply_filters('comments_popup_template', $template);
    10601029}
    10611030
    10621031/**
     
    10671036 *
    10681037 * @since 2.7.0
    10691038 *
    1070  * @param string|array $template_names Template file(s) to search for, in order.
     1039 * @param array $template_names Array of template files to search for in priority order.
    10711040 * @param bool $load If true the template file will be loaded if it is found.
    10721041 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
    10731042 * @return string The template filename if one is located.
    10741043 */
    10751044function locate_template($template_names, $load = false, $require_once = true ) {
     1045        if ( !is_array($template_names) )
     1046                return '';
     1047
    10761048        $located = '';
    1077         foreach ( (array) $template_names as $template_name ) {
     1049        foreach ( $template_names as $template_name ) {
    10781050                if ( !$template_name )
    10791051                        continue;
    10801052                if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
     
    11431115        if ( !current_user_can( 'switch_themes' ) )
    11441116                return;
    11451117
    1146         // Admin Thickbox requests
    1147         if ( isset( $_GET['preview_iframe'] ) )
    1148                 show_admin_bar( false );
    1149 
    11501118        $_GET['template'] = preg_replace('|[^a-z0-9_./-]|i', '', $_GET['template']);
    11511119
    11521120        if ( validate_file($_GET['template']) )
     
    12391207/**
    12401208 * Switches current theme to new template and stylesheet names.
    12411209 *
    1242  * @since 2.5.0
     1210 * @since unknown
    12431211 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
    12441212 *
    12451213 * @param string $template Template name
    12461214 * @param string $stylesheet Stylesheet name.
    12471215 */
    12481216function switch_theme($template, $stylesheet) {
    1249         global $wp_theme_directories;
    1250 
    12511217        update_option('template', $template);
    12521218        update_option('stylesheet', $stylesheet);
    1253         if ( count($wp_theme_directories) > 1 ) {
    1254                 update_option('template_root', get_raw_theme_root($template, true));
    1255                 update_option('stylesheet_root', get_raw_theme_root($stylesheet, true));
    1256         }
    12571219        delete_option('current_theme');
    12581220        $theme = get_current_theme();
    1259         if ( is_admin() && false === get_option( "theme_mods_$stylesheet" ) ) {
    1260                 $default_theme_mods = (array) get_option( "mods_$theme" );
    1261                 add_option( "theme_mods_$stylesheet", $default_theme_mods );
    1262         }
    12631221        do_action('switch_theme', $theme);
    12641222}
    12651223
     
    12911249                return false;
    12921250        }
    12931251
    1294         if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
    1295                 switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME );
    1296                 return false;
    1297         }
    1298 
    12991252        return true;
    13001253}
    13011254
    13021255/**
    1303  * Retrieve all theme modifications.
    1304  *
    1305  * @since 3.1.0
    1306  *
    1307  * @return array Theme modifications.
    1308  */
    1309 function get_theme_mods() {
    1310         $theme_slug = get_option( 'stylesheet' );
    1311         if ( false === ( $mods = get_option( "theme_mods_$theme_slug" ) ) ) {
    1312                 $theme_name = get_current_theme();
    1313                 $mods = get_option( "mods_$theme_name" ); // Deprecated location.
    1314                 if ( is_admin() && false !== $mods ) {
    1315                         update_option( "theme_mods_$theme_slug", $mods );
    1316                         delete_option( "mods_$theme_name" );
    1317                 }
    1318         }
    1319         return $mods;
    1320 }
    1321 
    1322 /**
    13231256 * Retrieve theme modification value for the current theme.
    13241257 *
    13251258 * If the modification name does not exist, then the $default will be passed
     
    13341267 * @param bool|string $default
    13351268 * @return string
    13361269 */
    1337 function get_theme_mod( $name, $default = false ) {
    1338         $mods = get_theme_mods();
     1270function get_theme_mod($name, $default = false) {
     1271        $theme = get_current_theme();
    13391272
    1340         if ( isset( $mods[ $name ] ) )
    1341                 return apply_filters( "theme_mod_$name", $mods[ $name ] );
     1273        $mods = get_option( "mods_$theme" );
    13421274
    1343         return apply_filters( "theme_mod_$name", sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ) );
     1275        if ( isset($mods[$name]) )
     1276                return apply_filters( "theme_mod_$name", $mods[$name] );
     1277
     1278        return apply_filters( "theme_mod_$name", sprintf($default, get_template_directory_uri(), get_stylesheet_directory_uri()) );
    13441279}
    13451280
    13461281/**
     
    13511286 * @param string $name Theme modification name.
    13521287 * @param string $value theme modification value.
    13531288 */
    1354 function set_theme_mod( $name, $value ) {
    1355         $mods = get_theme_mods();
     1289function set_theme_mod($name, $value) {
     1290        $theme = get_current_theme();
    13561291
    1357         $mods[ $name ] = $value;
     1292        $mods = get_option("mods_$theme");
    13581293
    1359         $theme = get_option( 'stylesheet' );
    1360         update_option( "theme_mods_$theme", $mods );
     1294        $mods[$name] = $value;
     1295
     1296        update_option("mods_$theme", $mods);
     1297        wp_cache_delete("mods_$theme", 'options');
    13611298}
    13621299
    13631300/**
     
    13721309 * @return null
    13731310 */
    13741311function remove_theme_mod( $name ) {
    1375         $mods = get_theme_mods();
     1312        $theme = get_current_theme();
    13761313
    1377         if ( ! isset( $mods[ $name ] ) )
     1314        $mods = get_option("mods_$theme");
     1315
     1316        if ( !isset($mods[$name]) )
    13781317                return;
    13791318
    1380         unset( $mods[ $name ] );
     1319        unset($mods[$name]);
    13811320
    1382         if ( empty( $mods ) )
     1321        if ( empty($mods) )
    13831322                return remove_theme_mods();
    13841323
    1385         $theme = get_option( 'stylesheet' );
    1386         update_option( "theme_mods_$theme", $mods );
     1324        update_option("mods_$theme", $mods);
     1325        wp_cache_delete("mods_$theme", 'options');
    13871326}
    13881327
    13891328/**
     
    13921331 * @since 2.1.0
    13931332 */
    13941333function remove_theme_mods() {
    1395         delete_option( 'theme_mods_' . get_option( 'stylesheet' ) );
    1396         delete_option( 'mods_' . get_current_theme() );
     1334        $theme = get_current_theme();
     1335
     1336        delete_option("mods_$theme");
    13971337}
    13981338
    13991339/**
     
    14281368 * @return string
    14291369 */
    14301370function get_header_image() {
    1431         $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';
     1371        $default = defined('HEADER_IMAGE') ? HEADER_IMAGE : '';
    14321372
    1433         $url = get_theme_mod( 'header_image', $default );
    1434 
    1435         if ( is_ssl() )
    1436                 $url = str_replace( 'http://', 'https://', $url );
    1437         else
    1438                 $url = str_replace( 'https://', 'http://', $url );
    1439 
    1440         return $url;
     1373        return get_theme_mod('header_image', $default);
    14411374}
    14421375
    14431376/**
     
    14641397 * @param callback $admin_header_callback Call on custom header administration screen.
    14651398 * @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional.
    14661399 */
    1467 function add_custom_image_header( $header_callback, $admin_header_callback, $admin_image_div_callback = '' ) {
    1468         if ( ! empty( $header_callback ) )
     1400function add_custom_image_header($header_callback, $admin_header_callback, $admin_image_div_callback = '') {
     1401        if ( ! empty($header_callback) )
    14691402                add_action('wp_head', $header_callback);
    14701403
    1471         add_theme_support( 'custom-header', array( 'callback' => $header_callback ) );
    1472         add_theme_support( 'custom-header-uploads' );
     1404        add_theme_support( 'custom-header' );
    14731405
    14741406        if ( ! is_admin() )
    14751407                return;
    1476 
    1477         global $custom_image_header;
    1478 
    1479         require_once( ABSPATH . 'wp-admin/custom-header.php' );
    1480         $custom_image_header = new Custom_Image_Header( $admin_header_callback, $admin_image_div_callback );
    1481         add_action( 'admin_menu', array( &$custom_image_header, 'init' ) );
     1408        require_once(ABSPATH . 'wp-admin/custom-header.php');
     1409        $GLOBALS['custom_image_header'] =& new Custom_Image_Header($admin_header_callback, $admin_image_div_callback);
     1410        add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init'));
    14821411}
    14831412
    14841413/**
    1485  * Remove image header support.
    1486  *
    1487  * @since 3.1.0
    1488  * @see add_custom_image_header()
    1489  *
    1490  * @return bool Whether support was removed.
    1491  */
    1492 function remove_custom_image_header() {
    1493         if ( ! current_theme_supports( 'custom-header' ) )
    1494                 return false;
    1495 
    1496         $callback = get_theme_support( 'custom-header' );
    1497         remove_action( 'wp_head', $callback[0]['callback'] );
    1498         _remove_theme_support( 'custom-header' );
    1499         remove_theme_support( 'custom-header-uploads' );
    1500 
    1501         if ( is_admin() ) {
    1502                 remove_action( 'admin_menu', array( &$GLOBALS['custom_image_header'], 'init' ) );
    1503                 unset( $GLOBALS['custom_image_header'] );
    1504         }
    1505 
    1506         return true;
    1507 }
    1508 
    1509 /**
    15101414 * Register a selection of default headers to be displayed by the custom header admin UI.
    15111415 *
    15121416 * @since 3.0.0
     
    15281432 * @see register_default_headers()
    15291433 * @since 3.0.0
    15301434 *
    1531  * @param string|array $header The header string id (key of array) to remove, or an array thereof.
     1435 * @param string|array The header string id (key of array) to remove, or an array thereof.
    15321436 * @return True on success, false on failure.
    15331437 */
    15341438function unregister_default_headers( $header ) {
     
    15661470}
    15671471
    15681472/**
     1473 * Retrieve background image alt attribute for custom background.
     1474 *
     1475 * @uses HEADER_ALT
     1476 *
     1477 * @return string
     1478 */
     1479function get_header_alt() {
     1480        $default = defined('HEADER_ALT') ? HEADER_ALT : '';
     1481
     1482        return get_theme_mod('header_alt', $default);
     1483}
     1484
     1485/**
     1486 * Display background image alt attribute.
     1487 *
     1488 *
     1489 */
     1490function header_alt() {
     1491        echo get_header_alt();
     1492}
     1493
     1494/**
    15691495 * Retrieve value for custom background color.
    15701496 *
    15711497 * @since 3.0.0
     
    16031529 * @param callback $admin_header_callback Call on custom background administration screen.
    16041530 * @param callback $admin_image_div_callback Output a custom background image div on the custom background administration screen. Optional.
    16051531 */
    1606 function add_custom_background( $header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '' ) {
    1607         if ( isset( $GLOBALS['custom_background'] ) )
     1532function add_custom_background($header_callback = '', $admin_header_callback = '', $admin_image_div_callback = '') {
     1533        if ( isset($GLOBALS['custom_background']) )
    16081534                return;
    16091535
    1610         if ( empty( $header_callback ) )
     1536        if ( empty($header_callback) )
    16111537                $header_callback = '_custom_background_cb';
    16121538
    1613         add_action( 'wp_head', $header_callback );
     1539        add_action('wp_head', $header_callback);
    16141540
    1615         add_theme_support( 'custom-background', array( 'callback' => $header_callback ) );
     1541        add_theme_support( 'custom-background' );
    16161542
    16171543        if ( ! is_admin() )
    16181544                return;
    1619         require_once( ABSPATH . 'wp-admin/custom-background.php' );
    1620         $GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback );
    1621         add_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) );
     1545        require_once(ABSPATH . 'wp-admin/custom-background.php');
     1546        $GLOBALS['custom_background'] =& new Custom_Background($admin_header_callback, $admin_image_div_callback);
     1547        add_action('admin_menu', array(&$GLOBALS['custom_background'], 'init'));
    16221548}
    16231549
    16241550/**
    1625  * Remove custom background support.
    1626  *
    1627  * @since 3.1.0
    1628  * @see add_custom_background()
    1629  *
    1630  * @return bool Whether support was removed.
    1631  */
    1632 function remove_custom_background() {
    1633         if ( ! current_theme_supports( 'custom-background' ) )
    1634                 return false;
    1635 
    1636         $callback = get_theme_support( 'custom-background' );
    1637         remove_action( 'wp_head', $callback[0]['callback'] );
    1638         _remove_theme_support( 'custom-background' );
    1639 
    1640         if ( is_admin() ) {
    1641                 remove_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) );
    1642                 unset( $GLOBALS['custom_background'] );
    1643         }
    1644 
    1645         return true;
    1646 }
    1647 
    1648 /**
    16491551 * Default custom background callback.
    16501552 *
    16511553 * @since 3.0.0
     
    16941596 * the theme root. It also accepts an array of stylesheets.
    16951597 * It is optional and defaults to 'editor-style.css'.
    16961598 *
    1697  * Supports RTL stylesheets automatically by searching for the -rtl prefix, e.g.
    1698  * editor-style-rtl.css. If an array of stylesheets is passed to add_editor_style(),
    1699  * RTL is only added for the first stylesheet.
    1700  *
    17011599 * @since 3.0.0
    17021600 *
    17031601 * @param mixed $stylesheet Optional. Stylesheet name or array thereof, relative to theme root.
     
    17221620}
    17231621
    17241622/**
    1725  * Removes all visual editor stylesheets.
    1726  *
    1727  * @since 3.1.0
    1728  *
    1729  * @return bool True on success, false if there were no stylesheets to remove.
    1730  */
    1731 function remove_editor_styles() {
    1732         if ( ! current_theme_supports( 'editor-style' ) )
    1733                 return false;
    1734         _remove_theme_support( 'editor-style' );
    1735         if ( is_admin() )
    1736                 $GLOBALS['editor_styles'] = array();
    1737         return true;
    1738 }
    1739 
    1740 /**
    17411623 * Allows a theme to register its support of a certain feature
    17421624 *
    17431625 * Must be called in the theme's functions.php file to work.
     
    17541636                $_wp_theme_features[$feature] = true;
    17551637        else
    17561638                $_wp_theme_features[$feature] = array_slice( func_get_args(), 1 );
    1757 
    1758         if ( $feature == 'post-formats' && is_array( $_wp_theme_features[$feature][0] ) )
    1759                 $_wp_theme_features[$feature][0] = array_intersect( $_wp_theme_features[$feature][0], array_keys( get_post_format_slugs() ) );
    17601639}
    17611640
    17621641/**
    1763  * Gets the theme support arguments passed when registering that support
    1764  *
    1765  * @since 3.1
    1766  * @param string $feature the feature to check
    1767  * @return array The array of extra arguments
    1768  */
    1769 function get_theme_support( $feature ) {
    1770         global $_wp_theme_features;
    1771         if ( !isset( $_wp_theme_features[$feature] ) )
    1772                 return false;
    1773         else
    1774                 return $_wp_theme_features[$feature];
    1775 }
    1776 
    1777 /**
    17781642 * Allows a theme to de-register its support of a certain feature
    17791643 *
    17801644 * Should be called in the theme's functions.php file. Generally would
     
    17891653        // Blacklist: for internal registrations not used directly by themes.
    17901654        if ( in_array( $feature, array( 'custom-background', 'custom-header', 'editor-style', 'widgets', 'menus' ) ) )
    17911655                return false;
    1792         return _remove_theme_support( $feature );
    1793 }
    17941656
    1795 /**
    1796  * Do not use. Removes theme support internally, ignorant of the blacklist.
    1797  *
    1798  * @access private
    1799  * @since 3.1.0
    1800  */
    1801 function _remove_theme_support( $feature ) {
    18021657        global $_wp_theme_features;
    18031658
    18041659        if ( ! isset( $_wp_theme_features[$feature] ) )