Make WordPress Core

Changeset 20316


Ignore:
Timestamp:
03/29/2012 04:29:58 AM (13 years ago)
Author:
nacin
Message:

Correct the values for theme_root and stylesheet when the values passed to the WP_Theme constructor have a directory appended to the theme root when it should actually be prepended to the stylesheet (when the theme is in a directory of themes inside a theme root). see #20313.

File:
1 edited

Legend:

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

    r20315 r20316  
    162162     * @param string $theme_dir Directory of the theme within the theme_root.
    163163     * @param string $theme_root Theme root.
    164      * @param WP_Error|null $child If this theme is a parent theme, the child may be passed for validation purposes.
    165      */
    166     public function __construct( $theme_dir, $theme_root, $child = null ) {
     164     * @param WP_Error|null $_child If this theme is a parent theme, the child may be passed for validation purposes.
     165     */
     166    public function __construct( $theme_dir, $theme_root, $_child = null ) {
     167        global $wp_theme_directories;
    167168
    168169        // Initialize caching on first run.
     
    180181        $this->theme_root = $theme_root;
    181182        $this->stylesheet = $theme_dir;
     183
     184        // Correct a situation where the theme is 'some-directory/some-theme' but 'some-directory' was passed in as part of the theme root instead.
     185        if ( ! in_array( $theme_root, (array) $wp_theme_directories ) && in_array( dirname( $theme_root ), (array) $wp_theme_directories ) ) {
     186            $this->stylesheet = basename( $this->theme_root ) . '/' . $this->stylesheet;
     187            $this->theme_root = dirname( $theme_root );
     188        }
     189
    182190        $this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet );
    183191        $theme_file = $this->stylesheet . '/style.css';
     
    253261        if ( $this->template != $this->stylesheet ) {
    254262            // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out.
    255             if ( is_a( $child, 'WP_Theme' ) && $child->template == $this->stylesheet ) {
    256                 $child->parent = null;
    257                 $child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $child->template ) );
    258                 $child->cache_add( 'theme', array( 'headers' => $child->headers, 'errors' => $child->errors, 'stylesheet' => $child->stylesheet, 'template' => $child->template ) );
     263            if ( is_a( $_child, 'WP_Theme' ) && $_child->template == $this->stylesheet ) {
     264                $_child->parent = null;
     265                $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $_child->template ) );
     266                $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) );
    259267                // The two themes actually reference each other with the Template header.
    260                 if ( $child->stylesheet == $this->template ) {
     268                if ( $_child->stylesheet == $this->template ) {
    261269                    $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $this->template ) );
    262270                    $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
Note: See TracChangeset for help on using the changeset viewer.