WordPress.org

Make WordPress Core

Ticket #17597: get_raw_theme_root.diff

File get_raw_theme_root.diff, 3.1 KB (added by nacin, 2 years ago)
  • wp-includes/theme.php

     
    475475        global $wp_theme_directories; 
    476476 
    477477        if ( count($wp_theme_directories) <= 1 ) 
    478                 return '/themes'; 
     478                return get_theme_root(); 
    479479 
    480480        $theme_roots = get_site_transient( 'theme_roots' ); 
    481481        if ( false === $theme_roots ) { 
     
    547547 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR 
    548548 * @return bool 
    549549 */ 
    550 function register_theme_directory( $directory) { 
     550function register_theme_directory( $directory ) { 
    551551        global $wp_theme_directories; 
    552552 
    553         /* If this folder does not exist, return and do not register */ 
    554         if ( !file_exists( $directory ) ) 
    555                         /* Try prepending as the theme directory could be relative to the content directory */ 
    556                 $registered_directory = WP_CONTENT_DIR . '/' . $directory; 
    557         else 
    558                 $registered_directory = $directory; 
     553        if ( ! file_exists( $directory ) ) { 
     554                // Try prepending as the theme directory could be relative to the content directory 
     555                $directory = WP_CONTENT_DIR . '/' . $directory; 
     556                // If this directory does not exist, return and do not register 
     557                if ( ! file_exists( $directory ) ) 
     558                        return false; 
     559        } 
    559560 
    560         /* If this folder does not exist, return and do not register */ 
    561         if ( !file_exists( $registered_directory ) ) 
    562                 return false; 
     561        $wp_theme_directories[] = $directory; 
    563562 
    564         $wp_theme_directories[] = $registered_directory; 
    565  
    566563        return true; 
    567564} 
    568565 
     
    660657 * @return string Theme path. 
    661658 */ 
    662659function get_theme_root( $stylesheet_or_template = false ) { 
    663         if ( $stylesheet_or_template ) { 
    664                 if ( $theme_root = get_raw_theme_root($stylesheet_or_template) ) 
    665                         $theme_root = WP_CONTENT_DIR . $theme_root; 
    666                 else 
    667                         $theme_root = WP_CONTENT_DIR . '/themes'; 
    668         } else { 
     660        if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) 
     661                $theme_root = $theme_root; 
     662        else 
    669663                $theme_root = WP_CONTENT_DIR . '/themes'; 
    670         } 
    671664 
    672665        return apply_filters( 'theme_root', $theme_root ); 
    673666} 
     
    685678function get_theme_root_uri( $stylesheet_or_template = false ) { 
    686679        if ( $stylesheet_or_template ) { 
    687680                if ( $theme_root = get_raw_theme_root($stylesheet_or_template) ) 
    688                         $theme_root_uri = content_url( $theme_root ); 
     681                        $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); 
    689682                else 
    690683                        $theme_root_uri = content_url( 'themes' ); 
    691684        } else { 
     
    696689} 
    697690 
    698691/** 
    699  * Get the raw theme root relative to the content directory with no filters applied. 
     692 * Get the raw theme root with no filters applied. 
    700693 * 
    701694 * @since 3.1.0 
    702695 * 
     696 * Before 3.4.0, this incorrectly returned a path relative to the content directory ("/themes") when 
     697 * only one theme directory was registered. Absolute paths are now always returned. 
     698 * 
    703699 * @param string $stylesheet_or_template The stylesheet or template name of the theme 
    704700 * @return string Theme root 
    705701 */ 
     
    707703        global $wp_theme_directories; 
    708704 
    709705        if ( count($wp_theme_directories) <= 1 ) 
    710                 return '/themes'; 
     706                return WP_CONTENT_DIR . '/themes'; 
    711707 
    712708        $theme_root = false; 
    713709