Changeset 20588
- Timestamp:
- 04/25/2012 05:31:39 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/class-wp-theme.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-theme.php
r20586 r20588 402 402 return $this->get_stylesheet(); 403 403 case 'Template Files' : 404 $files = $this->get_files( 'php' ); 405 if ( $this->parent() ) 406 $files = array_merge( $this->parent()->get_files( 'php' ), $files ); 407 return $files; 404 return $this->get_files( 'php', 1, true ); 408 405 case 'Stylesheet Files' : 409 $files = $this->get_files( 'css' ); 410 if ( $this->parent() ) 411 $files = array_merge( $this->parent()->get_files( 'css' ), $files ); 412 return $files; 406 return $this->get_files( 'css', 0, false ); 413 407 case 'Template Dir' : 414 408 return $this->get_template_directory(); … … 507 501 */ 508 502 public function cache_delete() { 509 foreach ( array( 'theme', 'screenshot', 'screenshot_count', ' files', 'headers', 'page_templates' ) as $key )503 foreach ( array( 'theme', 'screenshot', 'screenshot_count', 'headers', 'page_templates' ) as $key ) 510 504 wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); 511 505 $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null; … … 967 961 968 962 /** 969 * Return files in the theme's directory. Does not return files found in the parent theme. 970 * 971 * @since 3.4.0 972 * @access public 973 * 974 * @param string|null $type Optional. Type of files to return, either 'php' or 'css'. Defaults to null, for both. 975 * @return array If a specific $type is requested, returns an array of PHP files. If no $type is requested, 976 * returns an array, with the keys being the file types, and the values being an array of files for those type. 977 */ 978 public function get_files( $type ) { 979 $files = $this->cache_get( 'files' ); 980 if ( ! is_array( $files ) ) { 981 $files = (array) self::scandir( $this->get_stylesheet_directory(), array( 'php', 'css' ), 1 ); 982 foreach ( $files as &$group ) 983 ksort( $group ); 984 $this->cache_add( 'files', $files ); 985 } 986 987 if ( null === $type ) 988 return $files; 989 elseif ( isset( $files[ $type ] ) ) 990 return $files[ $type ]; 991 992 return array(); 963 * Return files in the theme's directory. 964 * 965 * @since 3.4.0 966 * @access public 967 * 968 * @param mixed $type Optional. Array of extensions to return. Defaults to all files (null). 969 * @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite. 970 * @param bool $search_parent Optional. Whether to return parent files. Defaults to false. 971 * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values 972 * being absolute paths. 973 */ 974 public function get_files( $type = null, $depth = 0, $search_parent = false ) { 975 $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); 976 977 if ( $search_parent && $this->parent() ) 978 $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); 979 980 return $files; 993 981 } 994 982 … … 1011 999 $page_templates = array(); 1012 1000 1013 $files = (array) self::scandir( $this->get_stylesheet_directory(),'php', 1 );1014 1015 foreach ( $files ['php']as $file => $full_path ) {1001 $files = (array) $this->get_files( 'php', 1 ); 1002 1003 foreach ( $files as $file => $full_path ) { 1016 1004 $headers = get_file_data( $full_path, array( 'Template Name' => 'Template Name' ) ); 1017 1005 if ( empty( $headers['Template Name'] ) ) … … 1047 1035 * for the found files, particularly when this function recurses to lower depths. 1048 1036 */ 1049 private static function scandir( $path, $extensions , $depth = 0, $relative_path = '' ) {1037 private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { 1050 1038 if ( ! is_dir( $path ) ) 1051 1039 return false; 1052 1040 1053 $results = scandir( $path ); 1054 1055 $extensions = (array) $extensions; 1056 $files = array_fill_keys( $extensions, array() ); 1057 $_extensions = implode( '|', $extensions ); 1041 if ( $extensions ) { 1042 $extensions = (array) $extensions; 1043 $_extensions = implode( '|', $extensions ); 1044 } 1058 1045 1059 1046 $relative_path = trailingslashit( $relative_path ); 1060 1047 if ( '/' == $relative_path ) 1061 1048 $relative_path = ''; 1049 1050 $results = scandir( $path ); 1051 $files = array(); 1062 1052 1063 1053 foreach ( $results as $result ) { … … 1069 1059 $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); 1070 1060 $files = array_merge_recursive( $files, $found ); 1071 } elseif ( preg_match( '~\.(' . $_extensions . ')$~', $result, $match) ) {1072 $files[ $ match[1] ][ $relative_path . $result ] = $path . '/' . $result;1061 } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) { 1062 $files[ $relative_path . $result ] = $path . '/' . $result; 1073 1063 } 1074 1064 }
Note: See TracChangeset
for help on using the changeset viewer.