Changeset 41806 for trunk/src/wp-includes/class-wp-theme.php
- Timestamp:
- 10/10/2017 05:33:57 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme.php
r41688 r41806 982 982 * @param bool $search_parent Optional. Whether to return parent files. Defaults to false. 983 983 * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values 984 * 984 * being absolute paths. 985 985 */ 986 986 public function get_files( $type = null, $depth = 0, $search_parent = false ) { 987 $files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); 988 989 if ( $search_parent && $this->parent() ) 990 $files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); 987 // get and cache all theme files to start with. 988 $label = sanitize_key( 'files_' . $this->cache_hash . '-' . $this->get( 'Version' ) ); 989 $transient_key = substr( $label, 0, 29 ) . md5( $label ); 990 991 $all_files = get_transient( $transient_key ); 992 if ( false === $all_files ) { 993 $all_files = (array) self::scandir( $this->get_stylesheet_directory(), null, -1 ); 994 995 if ( $search_parent && $this->parent() ) { 996 $all_files += (array) self::scandir( $this->get_template_directory(), null, -1 ); 997 } 998 999 set_transient( $transient_key, $all_files, HOUR_IN_SECONDS ); 1000 } 1001 1002 // Filter $all_files by $type & $depth. 1003 $files = array(); 1004 if ( $type ) { 1005 $type = (array) $type; 1006 $_extensions = implode( '|', $type ); 1007 } 1008 foreach ( $all_files as $key => $file ) { 1009 if ( $depth >= 0 && substr_count( $key, '/' ) > $depth ) { 1010 continue; // Filter by depth. 1011 } 1012 if ( ! $type || preg_match( '~\.(' . $_extensions . ')$~', $file ) ) { // Filter by type. 1013 $files[ $key ] = $file; 1014 } 1015 } 991 1016 992 1017 return $files; … … 1108 1133 */ 1109 1134 private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { 1110 if ( ! is_dir( $path ) ) 1135 if ( ! is_dir( $path ) ) { 1111 1136 return false; 1137 } 1112 1138 1113 1139 if ( $extensions ) { … … 1117 1143 1118 1144 $relative_path = trailingslashit( $relative_path ); 1119 if ( '/' == $relative_path ) 1145 if ( '/' == $relative_path ) { 1120 1146 $relative_path = ''; 1147 } 1121 1148 1122 1149 $results = scandir( $path ); … … 1126 1153 * Filters the array of excluded directories and files while scanning theme folder. 1127 1154 * 1128 1155 * @since 4.7.4 1129 1156 * 1130 1157 * @param array $exclusions Array of excluded directories and files. 1131 1158 */ 1132 $exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules' ) );1159 $exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) ); 1133 1160 1134 1161 foreach ( $results as $result ) { … … 1137 1164 } 1138 1165 if ( is_dir( $path . '/' . $result ) ) { 1139 if ( ! $depth ) 1166 if ( ! $depth ) { 1140 1167 continue; 1168 } 1141 1169 $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); 1142 1170 $files = array_merge_recursive( $files, $found );
Note: See TracChangeset
for help on using the changeset viewer.