Make WordPress Core


Ignore:
Timestamp:
03/30/2012 02:06:33 PM (13 years ago)
Author:
nacin
Message:

Set WP_Theme::scandir()'s default depth to 0 (flat), as intended. Cache untranslated page template names. Properly merge in a parent theme's templates when dealing with cached values. Always look one level deep for WP_Theme->get_files() regardless of file type. see #20103. see #11216.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-theme.php

    r20324 r20327  
    397397                return $this->get_stylesheet();
    398398            case 'Template Files' :
    399                 $files = $this->get_files( 'php', 1 );
     399                $files = $this->get_files( 'php' );
    400400                if ( $this->parent() )
    401                     $files = array_merge( $files, $this->parent()->get_files( 'php', 1 ) );
     401                    $files = array_merge( $files, $this->parent()->get_files( 'php' ) );
    402402                return $files;
    403403            case 'Stylesheet Files' :
     
    962962     *  returns an array, with the keys being the file types, and the values being an array of files for those type.
    963963     */
    964     public function get_files( $type = null, $depth = 0 ) {
     964    public function get_files( $type ) {
    965965        $files = $this->cache_get( 'files' );
    966966        if ( ! is_array( $files ) ) {
    967             $files = (array) self::scandir( $this->get_stylesheet_directory(), array( 'php', 'css' ), $depth );
     967            $files = (array) self::scandir( $this->get_stylesheet_directory(), array( 'php', 'css' ), 1 );
    968968            foreach ( $files as &$group )
    969969                ksort( $group );
    970             unset( $group );
    971970            $this->cache_add( 'files', $files );
    972971        }
     
    994993
    995994        $page_templates = $this->cache_get( 'page_templates' );
    996         if ( is_array( $page_templates ) )
    997             return $page_templates;
    998         $page_templates = array();
    999 
    1000         $files = (array) self::scandir( $this->get_stylesheet_directory(), 'php', 1 );
    1001 
    1002         foreach ( $files['php'] as $file => $full_path ) {
    1003             $headers = get_file_data( $full_path, array( 'Template Name' => 'Template Name' ) );
    1004             if ( empty( $headers['Template Name'] ) )
    1005                 continue;
    1006             $page_templates[ $file ] = $this->translate_header( 'Template Name', $headers['Template Name'] );
    1007         }
    1008 
    1009         $this->cache_add( 'page_templates', $page_templates );
     995
     996        if ( ! is_array( $page_templates ) ) {
     997            $page_templates = array();
     998
     999            $files = (array) self::scandir( $this->get_stylesheet_directory(), 'php', 1 );
     1000
     1001            foreach ( $files['php'] as $file => $full_path ) {
     1002                $headers = get_file_data( $full_path, array( 'Template Name' => 'Template Name' ) );
     1003                if ( empty( $headers['Template Name'] ) )
     1004                    continue;
     1005                $page_templates[ $file ] = $headers['Template Name'];
     1006            }
     1007
     1008            $this->cache_add( 'page_templates', $page_templates );
     1009        }
     1010
     1011        if ( $this->load_textdomain() ) {
     1012            foreach ( $page_templates as &$page_template ) {
     1013                $page_template = $this->translate_header( 'Template Name', $page_template );
     1014            }
     1015        }
    10101016
    10111017        if ( $this->parent() )
     
    10271033     *  for the found files, particularly when this function recurses to lower depths.
    10281034     */
    1029     private static function scandir( $path, $extensions, $depth = 1, $relative_path = '' ) {
     1035    private static function scandir( $path, $extensions, $depth = 0, $relative_path = '' ) {
    10301036        if ( ! is_dir( $path ) )
    10311037            return false;
Note: See TracChangeset for help on using the changeset viewer.