From 02979900ea2f24a5895a136825236dbc3b647f04 Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 29 Mar 2012 04:29:58 +0000 Subject: [PATCH] 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. git-svn-id: http://svn.automattic.com/wordpress/trunk@20316 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index 3217940bb..d35e92f75 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -161,9 +161,10 @@ final class WP_Theme implements ArrayAccess { * * @param string $theme_dir Directory of the theme within the theme_root. * @param string $theme_root Theme root. - * @param WP_Error|null $child If this theme is a parent theme, the child may be passed for validation purposes. + * @param WP_Error|null $_child If this theme is a parent theme, the child may be passed for validation purposes. */ - public function __construct( $theme_dir, $theme_root, $child = null ) { + public function __construct( $theme_dir, $theme_root, $_child = null ) { + global $wp_theme_directories; // Initialize caching on first run. if ( ! isset( self::$persistently_cache ) ) { @@ -179,6 +180,13 @@ final class WP_Theme implements ArrayAccess { $this->theme_root = $theme_root; $this->stylesheet = $theme_dir; + + // Correct a situation where the theme is 'some-directory/some-theme' but 'some-directory' was passed in as part of the theme root instead. + if ( ! in_array( $theme_root, (array) $wp_theme_directories ) && in_array( dirname( $theme_root ), (array) $wp_theme_directories ) ) { + $this->stylesheet = basename( $this->theme_root ) . '/' . $this->stylesheet; + $this->theme_root = dirname( $theme_root ); + } + $this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet ); $theme_file = $this->stylesheet . '/style.css'; @@ -252,12 +260,12 @@ final class WP_Theme implements ArrayAccess { // Set the parent, if we're a child theme. if ( $this->template != $this->stylesheet ) { // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out. - if ( is_a( $child, 'WP_Theme' ) && $child->template == $this->stylesheet ) { - $child->parent = null; - $child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $child->template ) ); - $child->cache_add( 'theme', array( 'headers' => $child->headers, 'errors' => $child->errors, 'stylesheet' => $child->stylesheet, 'template' => $child->template ) ); + if ( is_a( $_child, 'WP_Theme' ) && $_child->template == $this->stylesheet ) { + $_child->parent = null; + $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $_child->template ) ); + $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) ); // The two themes actually reference each other with the Template header. - if ( $child->stylesheet == $this->template ) { + if ( $_child->stylesheet == $this->template ) { $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), $this->template ) ); $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) ); }