Make WordPress Core


Ignore:
Timestamp:
02/28/2012 06:02:21 PM (13 years ago)
Author:
nacin
Message:

Fix the return value of get_theme_root() when the theme root is outside of WP_CONTENT_DIR, thus making it absolute rather than the typical relative theme root.

Make get_theme_root_uri() tolerate an absolute path for a theme root. It will now make an attempt to find a corresponding URL for absolute paths as well.

see #17597.

File:
1 edited

Legend:

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

    r20015 r20016  
    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;
    559 
    560     /* If this folder does not exist, return and do not register */
    561     if ( !file_exists( $registered_directory ) )
    562         return false;
    563 
    564     $wp_theme_directories[] = $registered_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    }
     560
     561    $wp_theme_directories[] = $directory;
    565562
    566563    return true;
     
    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) )
     660    global $wp_theme_directories;
     661
     662    if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) {
     663        // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
     664        // This gives relative theme roots the benefit of the doubt when things go haywire.
     665        if ( ! in_array( $theme_root, $wp_theme_directories ) )
    665666            $theme_root = WP_CONTENT_DIR . $theme_root;
    666         else
    667             $theme_root = WP_CONTENT_DIR . '/themes';
    668667    } else {
    669668        $theme_root = WP_CONTENT_DIR . '/themes';
     
    684683 */
    685684function get_theme_root_uri( $stylesheet_or_template = false ) {
    686     if ( $stylesheet_or_template ) {
    687         if ( $theme_root = get_raw_theme_root($stylesheet_or_template) )
     685    global $wp_theme_directories;
     686
     687    if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) {
     688        if ( in_array( $theme_root, $wp_theme_directories ) ) {
     689            // Absolute path. Make an educated guess. YMMV -- but note the filter below.
     690            if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) )
     691                $theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) );
     692            elseif ( 0 === strpos( $theme_root, ABSPATH ) )
     693                $theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) );
     694            elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) )
     695                $theme_root_uri = plugins_url( basename( $theme_root ), $theme_root );
     696            else
     697                $theme_root_uri = $theme_root;
     698        } else {
    688699            $theme_root_uri = content_url( $theme_root );
    689         else
    690             $theme_root_uri = content_url( 'themes' );
     700        }
    691701    } else {
    692702        $theme_root_uri = content_url( 'themes' );
Note: See TracChangeset for help on using the changeset viewer.