From a54b4f9c9e2c1b5154af4d8d456b78a7595c3c45 Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 5 Apr 2012 01:05:49 +0000 Subject: [PATCH] Always return a WP_Theme object from wp_get_theme(). Check \$theme->exists() or \$theme->errors() to confirm the requested theme actually exists. see #20361. git-svn-id: http://svn.automattic.com/wordpress/trunk@20363 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/schema.php | 2 +- wp-includes/theme.php | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 1e58251bd..bba0871d6 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -344,7 +344,7 @@ function populate_options() { $template = WP_DEFAULT_THEME; // If default theme is a child theme, we need to get its template $theme = wp_get_theme( $template ); - if ( $theme && ! $theme->errors() ) + if ( ! $theme->errors() ) $template = $theme->get_template(); $timezone_string = ''; diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 14311b268..997870736 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -87,7 +87,7 @@ function wp_get_themes( $args = array() ) { * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme. * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() * is used to calculate the theme root for the $stylesheet provided (or current theme). - * @return WP_Theme|bool WP_Theme object. False if the theme is not found. + * @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence. */ function wp_get_theme( $stylesheet = null, $theme_root = null ) { global $wp_theme_directories; @@ -104,11 +104,7 @@ function wp_get_theme( $stylesheet = null, $theme_root = null ) { $theme_root = WP_CONTENT_DIR . $theme_root; } - $theme = new WP_Theme( $stylesheet, $theme_root ); - if ( $theme->exists() ) - return $theme; - - return false; + return new WP_Theme( $stylesheet, $theme_root ); } /** @@ -1556,8 +1552,7 @@ function check_theme_switched() { if ( $stylesheet = get_option( 'theme_switched' ) ) { $old_theme = wp_get_theme( $stylesheet ); - // If we can't find the old theme then fallback to passing the raw data to the action like we did pre-3.4 - if ( $old_theme ) + if ( $old_theme->exists() ) do_action( 'after_switch_theme', $old_theme->get('Name'), $old_theme ); else do_action( 'after_switch_theme', $stylesheet );