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().



git-svn-id: https://develop.svn.wordpress.org/trunk@20193 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin
2012-03-15 15:39:21 +00:00
parent 8715cf588b
commit e71167bbee
4 changed files with 43 additions and 33 deletions
+12 -12
View File
@@ -384,12 +384,12 @@ final class WP_Theme implements ArrayAccess {
case 'Stylesheet' :
return $this->get_stylesheet();
case 'Template Files' :
$files = $this->get_files('php');
$files = $this->get_files('php', true);
foreach ( $files as &$file )
$file = $this->theme_root . '/' . $file;
return $files;
case 'Stylesheet Files' :
$files = $this->get_files('css');
$files = $this->get_files('css', true);
foreach ( $files as &$file )
$file = $this->theme_root . '/' . $file;
return $files;
@@ -555,7 +555,6 @@ final class WP_Theme implements ArrayAccess {
}
// Fall through otherwise.
case 'Name' :
case 'Author' :
static $header_tags = array(
'abbr' => array( 'title' => true ),
'acronym' => array( 'title' => true ),
@@ -565,6 +564,8 @@ final class WP_Theme implements ArrayAccess {
);
$value = wp_kses( $value, $header_tags );
break;
case 'Author' :
// There shouldn't be anchor tags in Author, but some themes like to be challenging.
case 'Description' :
static $header_tags_with_a = array(
'a' => array( 'href' => true, 'title' => true ),
@@ -935,7 +936,9 @@ final class WP_Theme implements ArrayAccess {
if ( $include_parent_files || ! $this->is_child_theme() )
// Template files can be one level down for the purposes of the theme editor, so this should be $depth = 1.
// Todo: We ignore this for now, but this is why the branching is weird.
$files = (array) self::scandir( $this->get_template_directory(), $this->get_template(), array( 'php', 'css' ) );
$files = self::scandir( $this->get_template_directory(), $this->get_template(), array( 'php', 'css' ) );
else
$files = array();
if ( $this->is_child_theme() )
$files = array_merge_recursive( $files, (array) self::scandir( $this->get_stylesheet_directory(), $this->get_stylesheet(), array( 'php', 'css' ) ) );
foreach ( $files as &$group )
@@ -989,14 +992,14 @@ final class WP_Theme implements ArrayAccess {
* @depth int How deep to search for files. Optional, defaults to a flat scan (0 depth).
*/
private static function scandir( $path, $relative_path, $extensions, $depth = 0 ) {
if ( is_array( $extensions ) )
$extensions = implode( '|', $extensions );
if ( ! is_dir( $path ) )
return false;
$results = scandir( $path );
$files = array();
$extensions = (array) $extensions;
$files = array_fill_keys( $extensions, array() );
$extensions = implode( '|', $extensions );
foreach ( $results as $result ) {
if ( '.' == $result || '..' == $result )
@@ -1007,10 +1010,7 @@ final class WP_Theme implements ArrayAccess {
$found = self::scandir( $path . '/' . $result, $relative_path . '/' . $result, $extensions, $depth - 1 );
$files = array_merge_recursive( $files, $found );
} elseif ( preg_match( '~\.(' . $extensions . ')$~', $result, $match ) ) {
if ( ! isset( $files[ $match[1] ] ) )
$files[ $match[1] ] = array( $relative_path . '/'. $result );
else
$files[ $match[1] ][] = $relative_path . '/' . $result;
$files[ $match[1] ][] = $relative_path . '/' . $result;
}
}
return $files;