Make WordPress Core

Changeset 20193


Ignore:
Timestamp:
03/15/2012 03:39:21 PM (15 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().
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/deprecated.php

    r20029 r20193  
    918918        $broken = array();
    919919        foreach ( $themes as $theme ) {
    920                 $broken[ $theme->get('Name') ] = array(
    921                         'Title' => $theme->get('Name'),
     920                $name = $theme->get('Name');
     921                $broken[ $name ] = array(
     922                        'Name' => $name,
     923                        'Title' => $name,
    922924                        'Description' => $theme->errors()->get_error_message(),
    923925                );
  • trunk/wp-includes/class-wp-theme.php

    r20176 r20193  
    385385                                return $this->get_stylesheet();
    386386                        case 'Template Files' :
    387                                 $files = $this->get_files('php');
     387                                $files = $this->get_files('php', true);
    388388                                foreach ( $files as &$file )
    389389                                        $file = $this->theme_root . '/' . $file;
    390390                                return $files;
    391391                        case 'Stylesheet Files' :
    392                                 $files = $this->get_files('css');
     392                                $files = $this->get_files('css', true);
    393393                                foreach ( $files as &$file )
    394394                                        $file = $this->theme_root . '/' . $file;
    … …  
    556556                                // Fall through otherwise.
    557557                        case 'Name' :
    558                         case 'Author' :
    559558                                static $header_tags = array(
    560559                                        'abbr'    => array( 'title' => true ),
    … …  
    566565                                $value = wp_kses( $value, $header_tags );
    567566                                break;
     567                        case 'Author' :
     568                                // There shouldn't be anchor tags in Author, but some themes like to be challenging.
    568569                        case 'Description' :
    569570                                static $header_tags_with_a = array(
    … …  
    936937                                // Template files can be one level down for the purposes of the theme editor, so this should be $depth = 1.
    937938                                // Todo: We ignore this for now, but this is why the branching is weird.
    938                                 $files = (array) self::scandir( $this->get_template_directory(), $this->get_template(), array( 'php', 'css' ) );
     939                                $files = self::scandir( $this->get_template_directory(), $this->get_template(), array( 'php', 'css' ) );
     940                        else
     941                                $files = array();
    939942                        if ( $this->is_child_theme() )
    940943                                $files = array_merge_recursive( $files, (array) self::scandir( $this->get_stylesheet_directory(), $this->get_stylesheet(), array( 'php', 'css' ) ) );
    … …  
    990993         */
    991994        private static function scandir( $path, $relative_path, $extensions, $depth = 0 ) {
    992                 if ( is_array( $extensions ) )
    993                         $extensions = implode( '|', $extensions );
    994 
    995995                if ( ! is_dir( $path ) )
    996996                        return false;
    997997
    998998                $results = scandir( $path );
    999                 $files = array();
     999
     1000                $extensions = (array) $extensions;
     1001                $files = array_fill_keys( $extensions, array() );
     1002                $extensions = implode( '|', $extensions );
    10001003
    10011004                foreach ( $results as $result ) {
    … …  
    10081011                                $files = array_merge_recursive( $files, $found );
    10091012                        } elseif ( preg_match( '~\.(' . $extensions . ')$~', $result, $match ) ) {
    1010                                 if ( ! isset( $files[ $match[1] ] ) )
    1011                                         $files[ $match[1] ] = array( $relative_path . '/'. $result );
    1012                                 else
    1013                                         $files[ $match[1] ][] = $relative_path . '/' . $result;
     1013                                $files[ $match[1] ][] = $relative_path . '/' . $result;
    10141014                        }
    10151015                }
  • trunk/wp-includes/deprecated.php

    r20042 r20193  
    29342934
    29352935        foreach ( $themes as $theme ) {
    2936                 $wp_themes[ $theme->get('Name') ] = $theme;
     2936                $name = $theme->get('Name');
     2937                if ( isset( $wp_themes[ $name ] ) )
     2938                        $wp_themes[ $name . '/' . $theme->get_stylesheet() ] = $theme;
     2939                else
     2940                        $wp_themes[ $name ] = $theme;
    29372941        }
    29382942
  • 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.