Introduce WP_Theme->exists() to check if the queried theme actually exists. WP_Theme->exists() is a subset of errors() -- a theme with errors may still exist, but a theme that does not exist has an error of theme_not_found. wp_get_theme() now returns false if the theme does not exist. Improve scandir() and get_files() logic. see #20103.

git-svn-id: http://svn.automattic.com/wordpress/trunk@20312 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin
2012-03-29 02:59:48 +00:00
parent 3a722f41d7
commit bb4cca4c55
2 changed files with 65 additions and 33 deletions

View File

@@ -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
* @return WP_Theme|bool WP_Theme object. False if the theme is not found.
*/
function wp_get_theme( $stylesheet = null, $theme_root = null ) {
global $wp_theme_directories;
@@ -97,11 +97,18 @@ function wp_get_theme( $stylesheet = null, $theme_root = null ) {
if ( empty( $theme_root ) ) {
$theme_root = get_raw_theme_root( $stylesheet );
if ( false === $theme_root )
return false;
if ( ! in_array( $theme_root, (array) $wp_theme_directories ) )
$theme_root = WP_CONTENT_DIR . $theme_root;
}
return new WP_Theme( $stylesheet, $theme_root );
$theme = new WP_Theme( $stylesheet, $theme_root );
if ( $theme->exists() )
return $theme;
return false;
}
/**