WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/15/2012 03:39:21 PM (10 years ago)
Author:
nacin
Message:

Updates to WP_Theme, wp_get_themes(), and related deprecated functions, after [UT570] [UT578] [UT579]. see #20103.

  • Template Files? and Stylesheet Files? need to return files from the parent theme as well.
  • Don't strip links from the Author header. Some themes rely on the previous behavior, such as to link multiple authors (Sandbox, for example.) Don't restore links to the Name, that's just a bad idea.
  • Ensure we are always passing around arrays in get_files/scandir.
  • Better inline doc for wp_get_themes() arguments.
  • Introduce a 'force' flag for search_theme_directories() to re-scan, rather than return the cache. We will use this to re-build the theme_roots transient in get_theme_roots(), but it is more helpful for unit tests. Since search_theme_directories() is cached, don't cache again in wp_get_themes(). (Again benefits testing.)
  • Handle duplicate theme names in the old get_themes() when two themes match (and neither are a default theme, which is already handled). wp_get_themes() will consider both names to be the same; this is just for back compat since get_themes() is keyed by name.
  • Include an old array key in wp_broken_themes().
File:
1 edited

Legend:

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

    r20163 r20193  
    1010 * Returns an array of WP_Theme objects based on the arguments.
    1111 *
    12  * Despite advances over get_themes(), this function is still quite expensive, and grows
     12 * Despite advances over get_themes(), this function is quite expensive, and grows
    1313 * linearly with additional themes. Stick to wp_get_theme() if possible.
    1414 *
    1515 * @since 3.4.0
    1616 *
    17  * @param array $args Arguments. Currently 'errors' (defaults to false), 'allowed'
    18  *  (true, false; null for either; defaults to null; only applies to multisite), and 'blog_id'
    19  *  (defaults to current blog; used to find allowed themes; only applies to multisite).
     17 * @param array $args The search arguments. Optional.
     18 * - errors      mixed  True to return themes with errors, false to return themes without errors, null
     19 *                      to return all themes. Defaults to false.
     20 * - allowed     mixed  (Multisite) True to return only allowed themes for a site. False to return only
     21 *                      disallowed themes for a site. 'site' to return only site-allowed themes. 'network'
     22 *                      to return only network-allowed themes. Null to return all themes. Defaults to null.
     23 * - blog_id     int    (Multisite) The blog ID used to calculate which themes are allowed. Defaults to 0,
     24 *                      synonymous for the current blog.
    2025 * @return Array of WP_Theme objects.
    2126 */
     
    2631    $args = wp_parse_args( $args, $defaults );
    2732
    28     static $_theme_directories, $_themes = array();
    29     if ( ! isset( $_theme_directories ) ) {
    30         $_theme_directories = search_theme_directories();
    31         if ( count( $wp_theme_directories ) > 1 ) {
    32             // Make sure the current theme wins out, in case search_theme_directories() picks the wrong
    33             // one in the case of a conflict. (Normally, last registered theme root wins.)
    34             $current_theme = get_stylesheet();
     33    $theme_directories = search_theme_directories();
     34
     35    if ( count( $wp_theme_directories ) > 1 ) {
     36        // Make sure the current theme wins out, in case search_theme_directories() picks the wrong
     37        // one in the case of a conflict. (Normally, last registered theme root wins.)
     38        $current_theme = get_stylesheet();
     39        if ( isset( $theme_directories[ $current_theme ] ) ) {
    3540            $root_of_current_theme = get_raw_theme_root( $current_theme );
    3641            if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) )
    3742                $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme;
    38             $_theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
     43            $theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
    3944        }
    4045    }
    4146
    42     if ( empty( $_theme_directories ) )
     47    if ( empty( $theme_directories ) )
    4348        return array();
    44 
    45     $theme_directories = $_theme_directories;
    4649
    4750    if ( is_multisite() && null !== $args['allowed'] ) {
     
    356359    $theme_roots = get_site_transient( 'theme_roots' );
    357360    if ( false === $theme_roots ) {
    358         search_theme_directories(); // Regenerate the transient.
     361        search_theme_directories( true ); // Regenerate the transient.
    359362        $theme_roots = get_site_transient( 'theme_roots' );
    360363    }
     
    391394 * @since 2.9.0
    392395 *
     396 * @param bool $force Optional. Whether to force a new directory scan. Defaults to false.
    393397 * @return array Valid themes found
    394398 */
    395 function search_theme_directories() {
     399function search_theme_directories( $force = false ) {
    396400    global $wp_theme_directories;
    397401    if ( empty( $wp_theme_directories ) )
     
    399403
    400404    static $found_themes;
    401     if ( isset( $found_themes ) )
     405    if ( ! $force && isset( $found_themes ) )
    402406        return $found_themes;
    403407
Note: See TracChangeset for help on using the changeset viewer.