Make WordPress Core

Changeset 15641


Ignore:
Timestamp:
09/21/2010 07:41:35 PM (14 years ago)
Author:
ryan
Message:

Don't fetch theme_roots transient on every page load. Avoid it altogether if there is only one theme dir. fixes #14911

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/theme.php

    r15613 r15641  
    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 ) {
     
    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';
     
    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 );
     692}
     693
     694/**
     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;
    687723}
    688724
     
    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();
Note: See TracChangeset for help on using the changeset viewer.