Make WordPress Core

Ticket #14911: 14911.diff

File 14911.diff, 2.7 KB (added by ryan, 14 years ago)
  • wp-includes/theme.php

     
    651651 * @return string Theme path.
    652652 */
    653653function 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];
     654        if ( $stylesheet_or_template ) {
     655                if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
     656                        $theme_root = WP_CONTENT_DIR . $theme_root;
    659657                else
    660658                        $theme_root = WP_CONTENT_DIR . '/themes';
    661659        } else {
     
    676674 * @return string Themes URI.
    677675 */
    678676function get_theme_root_uri( $stylesheet_or_template = false ) {
    679         $theme_roots = get_theme_roots();
    680677
    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
     678        if ($stylesheet_or_template) {
     679                if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
     680                        $theme_root_uri = content_url( $theme_root );
     681                else
     682                        $theme_root_uri = content_url( 'themes' );
     683        } else {
    684684                $theme_root_uri = content_url( 'themes' );
     685        }
    685686
    686687        return apply_filters( 'theme_root_uri', $theme_root_uri, get_option('siteurl'), $stylesheet_or_template );
    687688}
    688689
    689690/**
     691 * Get the raw theme root relative to the content directory with no filters applied.
     692 *
     693 * @since 3.1.0
     694 *
     695 * @param string $stylesheet_or_template The stylesheet or template name of the theme
     696 * @return string Theme root
     697 */
     698function get_raw_theme_root( $stylesheet_or_template ) {
     699        $theme_root = false;
     700
     701        // If requesting the root for the current theme, consult options to avoid calling get_theme_roots()
     702        if ( get_option('stylesheet') == $stylesheet_or_template )
     703                $theme_root = get_option('stylesheet_root');
     704        elseif ( get_option('template') == $stylesheet_or_template )
     705                $theme_root = get_option('template_root');
     706
     707        if ( empty($theme_root) ) {
     708                $theme_roots = get_theme_roots();
     709                if ( !empty($theme_roots[$stylesheet_or_template]) )
     710                        $theme_root = $theme_roots[$stylesheet_or_template];
     711        }
     712
     713        return $theme_root;
     714}
     715
     716/**
    690717 * Retrieve path to a template
    691718 *
    692719 * Used to quickly retrieve the path of a template without including the file
     
    12151242function switch_theme($template, $stylesheet) {
    12161243        update_option('template', $template);
    12171244        update_option('stylesheet', $stylesheet);
     1245        update_option('template_root', get_raw_theme_root($template));
     1246        update_option('stylesheet_root', get_raw_theme_root($stylesheet));
    12181247        delete_option('current_theme');
    12191248        $theme = get_current_theme();
    12201249        do_action('switch_theme', $theme);