Make WordPress Core


Ignore:
Timestamp:
03/15/2012 03:39:21 PM (13 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/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        }
Note: See TracChangeset for help on using the changeset viewer.