Make WordPress Core


Ignore:
Timestamp:
03/29/2012 02:59:48 AM (10 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

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

    r20269 r20312  
    8888 * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root()
    8989 *  is used to calculate the theme root for the $stylesheet provided (or current theme).
    90  * @return WP_Theme
     90 * @return WP_Theme|bool WP_Theme object. False if the theme is not found.
    9191 */
    9292function wp_get_theme( $stylesheet = null, $theme_root = null ) {
     
    9898    if ( empty( $theme_root ) ) {
    9999        $theme_root = get_raw_theme_root( $stylesheet );
     100        if ( false === $theme_root )
     101            return false;
     102
    100103        if ( ! in_array( $theme_root, (array) $wp_theme_directories ) )
    101104            $theme_root = WP_CONTENT_DIR . $theme_root;
    102105    }
    103106
    104     return new WP_Theme( $stylesheet, $theme_root );
     107    $theme = new WP_Theme( $stylesheet, $theme_root );
     108    if ( $theme->exists() )
     109        return $theme;
     110
     111    return false;
    105112}
    106113
Note: See TracChangeset for help on using the changeset viewer.