WordPress.org

Make WordPress Core

Ticket #14911: 14911.2.diff

File 14911.2.diff, 3.4 KB (added by ryan, 8 years ago)

Don't bother caching at all if only one theme dir registered.

  • wp-includes/theme.php

     
    466466 *
    467467 * @since 2.9.0
    468468 *
    469  * @return array Theme roots
     469 * @return array|string An arry of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.
    470470 */
    471471function get_theme_roots() {
     472        global $wp_theme_directories;
     473
     474        if ( count($wp_theme_directories <= 1) )
     475                return '/themes';
     476
    472477        $theme_roots = get_site_transient( 'theme_roots' );
    473478        if ( false === $theme_roots ) {
    474479                get_themes();
     
    651656 * @return string Theme path.
    652657 */
    653658function get_theme_root( $stylesheet_or_template = false ) {
    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];
     659        if ( $stylesheet_or_template ) {
     660                if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
     661                        $theme_root = WP_CONTENT_DIR . $theme_root;
    659662                else
    660663                        $theme_root = WP_CONTENT_DIR . '/themes';
    661664        } else {
     
    676679 * @return string Themes URI.
    677680 */
    678681function get_theme_root_uri( $stylesheet_or_template = false ) {
    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
     682        if ( $stylesheet_or_template ) {
     683                if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
     684                        $theme_root_uri = content_url( $theme_root );
     685                else
     686                        $theme_root_uri = content_url( 'themes' );
     687        } else {
    684688                $theme_root_uri = content_url( 'themes' );
     689        }
    685690
    686691        return apply_filters( 'theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template );
    687692}
    688693
    689694/**
     695 * Get the raw theme root relative to the content directory with no filters applied.
     696 *
     697 * @since 3.1.0
     698 *
     699 * @param string $stylesheet_or_template The stylesheet or template name of the theme
     700 * @return string Theme root
     701 */
     702function get_raw_theme_root( $stylesheet_or_template ) {
     703        global $wp_theme_directories;
     704
     705        if ( count($wp_theme_directories <= 1) )
     706                return '/themes';
     707
     708        $theme_root = false;
     709
     710        // If requesting the root for the current theme, consult options to avoid calling get_theme_roots()
     711        if ( get_option('stylesheet') == $stylesheet_or_template )
     712                $theme_root = get_option('stylesheet_root');
     713        elseif ( get_option('template') == $stylesheet_or_template )
     714                $theme_root = get_option('template_root');
     715
     716        if ( empty($theme_root) ) {
     717                $theme_roots = get_theme_roots();
     718                if ( !empty($theme_roots[$stylesheet_or_template]) )
     719                        $theme_root = $theme_roots[$stylesheet_or_template];
     720        }
     721
     722        return $theme_root;
     723}
     724
     725/**
    690726 * Retrieve path to a template
    691727 *
    692728 * Used to quickly retrieve the path of a template without including the file
     
    12131249 * @param string $stylesheet Stylesheet name.
    12141250 */
    12151251function switch_theme($template, $stylesheet) {
     1252        global $wp_theme_directories;
     1253
    12161254        update_option('template', $template);
    12171255        update_option('stylesheet', $stylesheet);
     1256        if ( count($wp_theme_directories) > 1 ) {
     1257                update_option('template_root', get_raw_theme_root($template));
     1258                update_option('stylesheet_root', get_raw_theme_root($stylesheet));
     1259        }
    12181260        delete_option('current_theme');
    12191261        $theme = get_current_theme();
    12201262        do_action('switch_theme', $theme);