Changeset 20312
- Timestamp:
- 03/29/2012 02:59:48 AM (13 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-theme.php
r20233 r20312 196 196 } elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) { 197 197 $this->headers['Name'] = $this->stylesheet; 198 $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); 198 if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) 199 $this->errors = new WP_Error( 'theme_not_found', __( 'The theme directory does not exist.' ) ); 200 else 201 $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); 199 202 $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) ); 200 203 if ( ! file_exists( $this->theme_root ) ) // Don't cache this one. … … 385 388 return $this->get_stylesheet(); 386 389 case 'Template Files' : 387 $files = $this->get_files( 'php', true);388 foreach ( $files as &$file)389 $file = $this->theme_root . '/' . $file;390 $files = $this->get_files( 'php', 1 ); 391 if ( $this->parent() ) 392 $files = array_merge( $files, $this->parent()->get_files( 'php', 1 ) ); 390 393 return $files; 391 394 case 'Stylesheet Files' : 392 $files = $this->get_files( 'css', true);393 foreach ( $files as &$file)394 $file = $this->theme_root . '/' . $file;395 $files = $this->get_files( 'css' ); 396 if ( $this->parent() ) 397 $files = array_merge( $files, $this->parent()->get_files( 'css' ) ); 395 398 return $files; 396 399 case 'Template Dir' : … … 426 429 427 430 /** 431 * Whether the theme exists. 432 * 433 * A theme with errors exists. A theme with the error of 'theme_not_found', 434 * meaning that the theme directory was not found, does not exist. 435 * 436 * @since 3.4.0 437 * @access public 438 * 439 * @return bool Whether the theme exists. 440 */ 441 public function exists() { 442 return ! ( is_wp_error( $this->errors ) && in_array( 'theme_not_found', $this->errors->get_error_codes() ) ); 443 } 444 445 /** 428 446 * Returns reference to the parent theme. 429 447 * … … 475 493 */ 476 494 public function cache_delete() { 477 foreach ( array( 'theme', 'screenshot', 'screenshot_count', 'files', 'headers' ) as $key )495 foreach ( array( 'theme', 'screenshot', 'screenshot_count', 'files', 'headers', 'page_templates' ) as $key ) 478 496 wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); 479 497 } … … 892 910 893 911 $prefix = $this->get_stylesheet() . '/screenshot-'; 894 $files = self::scandir( $this->get_stylesheet_directory(), $this->get_stylesheet(), 'png' , 0);912 $files = self::scandir( $this->get_stylesheet_directory(), $this->get_stylesheet(), 'png' ); 895 913 896 914 $screenshot_count = 1; … … 926 944 927 945 /** 928 * Return files in the t emplate and stylesheet directories.946 * Return files in the theme's directory. Does not return files found in the parent theme. 929 947 * 930 948 * @since 3.4.0 … … 935 953 * returns an array, with the keys being the file types, and the values being an array of files for those type. 936 954 */ 937 public function get_files( $type = null, $ include_parent_files = false) {955 public function get_files( $type = null, $depth = 0 ) { 938 956 $files = $this->cache_get( 'files' ); 939 957 if ( ! is_array( $files ) ) { 940 if ( $include_parent_files || ! $this->is_child_theme() ) 941 // Template files can be one level down for the purposes of the theme editor, so this should be $depth = 1. 942 // Todo: We ignore this for now, but this is why the branching is weird. 943 $files = self::scandir( $this->get_template_directory(), $this->get_template(), array( 'php', 'css' ) ); 944 else 945 $files = array(); 946 if ( $this->is_child_theme() ) 947 $files = array_merge_recursive( $files, (array) self::scandir( $this->get_stylesheet_directory(), $this->get_stylesheet(), array( 'php', 'css' ) ) ); 958 $files = (array) self::scandir( $this->get_stylesheet_directory(), array( 'php', 'css' ), $depth ); 948 959 foreach ( $files as &$group ) 949 sort( $group ); 960 ksort( $group ); 961 unset( $group ); 950 962 $this->cache_add( 'files', $files ); 951 963 } … … 959 971 } 960 972 973 /** 974 * Returns the theme's page templates. 975 * 976 * @since 3.4.0 977 * @access public 978 * 979 * @return array Array of page templates, keyed by filename, with the value of the translated header name. 980 */ 961 981 public function get_page_templates() { 962 982 // If you screw up your current theme and we invalidate your parent, most things still work. Let it slide. … … 969 989 $page_templates = array(); 970 990 971 $files = (array) self::scandir( $this->get_template_directory(), $this->get_template_directory(),'php' );991 $files = (array) self::scandir( $this->get_template_directory(), 'php' ); 972 992 if ( $this->is_child_theme() ) 973 $files = array_merge_recursive( $files, (array) self::scandir( $this->get_stylesheet_directory(), $this->get_stylesheet_directory(),'php' ) );993 $files = array_merge_recursive( $files, (array) self::scandir( $this->get_stylesheet_directory(), 'php' ) ); 974 994 975 995 foreach ( $files['php'] as $file ) { … … 991 1011 * 992 1012 * @param string $path Absolute path to search. 1013 * @param array|string $extensions Array of extensions to find, or string of a single extension 1014 * @param int $depth How deep to search for files. Optional, defaults to a flat scan (0 depth). -1 depth is infinite. 993 1015 * @param string $relative_path The basename of the absolute path. Used to control the returned path 994 1016 * for the found files, particularly when this function recurses to lower depths. 995 * @param array|string $extensions Array of extensions to find, or string of a single extension. 996 * @depth int How deep to search for files. Optional, defaults to a flat scan (0 depth). 997 */ 998 private static function scandir( $path, $relative_path, $extensions, $depth = 0 ) { 1017 */ 1018 private static function scandir( $path, $extensions, $depth = 1, $relative_path = '' ) { 999 1019 if ( ! is_dir( $path ) ) 1000 1020 return false; … … 1004 1024 $extensions = (array) $extensions; 1005 1025 $files = array_fill_keys( $extensions, array() ); 1006 $extensions = implode( '|', $extensions ); 1026 $_extensions = implode( '|', $extensions ); 1027 1028 $relative_path = trailingslashit( $relative_path ); 1029 if ( '/' == $relative_path ) 1030 $relative_path = ''; 1007 1031 1008 1032 foreach ( $results as $result ) { 1009 if ( '.' == $result || '..' == $result)1033 if ( '.' == $result[0] ) 1010 1034 continue; 1011 1035 if ( is_dir( $path . '/' . $result ) ) { 1012 if ( ! $depth )1036 if ( ! $depth || 'CVS' == $result ) 1013 1037 continue; 1014 $found = self::scandir( $path . '/' . $result, $ relative_path . '/' . $result, $extensions, $depth - 1);1038 $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result ); 1015 1039 $files = array_merge_recursive( $files, $found ); 1016 } elseif ( preg_match( '~\.(' . $ extensions . ')$~', $result, $match ) ) {1017 $files[ $match[1] ][ ] = $relative_path . '/' . $result;1040 } elseif ( preg_match( '~\.(' . $_extensions . ')$~', $result, $match ) ) { 1041 $files[ $match[1] ][ $relative_path . $result ] = $path . '/' . $result; 1018 1042 } 1019 1043 } 1044 1020 1045 return $files; 1021 1046 } -
trunk/wp-includes/theme.php
r20269 r20312 88 88 * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() 89 89 * is used to calculate the theme root for the $stylesheet provided (or current theme). 90 * @return WP_Theme 90 * @return WP_Theme|bool WP_Theme object. False if the theme is not found. 91 91 */ 92 92 function wp_get_theme( $stylesheet = null, $theme_root = null ) { … … 98 98 if ( empty( $theme_root ) ) { 99 99 $theme_root = get_raw_theme_root( $stylesheet ); 100 if ( false === $theme_root ) 101 return false; 102 100 103 if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) 101 104 $theme_root = WP_CONTENT_DIR . $theme_root; 102 105 } 103 106 104 return new WP_Theme( $stylesheet, $theme_root ); 107 $theme = new WP_Theme( $stylesheet, $theme_root ); 108 if ( $theme->exists() ) 109 return $theme; 110 111 return false; 105 112 } 106 113
Note: See TracChangeset
for help on using the changeset viewer.