Make WordPress Core


Ignore:
Timestamp:
09/28/2015 03:10:08 AM (8 years ago)
Author:
wonderboymusic
Message:

Theme Editor: ensure that files named index.php in theme subfolders are not labeled as "Main Index Template"

Props MikeHansenMe, wonderboymusic, bravokeyl, Shelob9.
Fixes #27201.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r34566 r34658  
    5252 * @global array $wp_file_descriptions
    5353 * @param string $file Filesystem path or filename
    54  * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist
     54 * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist.
     55 *                Appends 'Page Template' to basename of $file if the file is a page template
    5556 */
    5657function get_file_description( $file ) {
    57     global $wp_file_descriptions;
    58 
    59     if ( isset( $wp_file_descriptions[basename( $file )] ) ) {
    60         return $wp_file_descriptions[basename( $file )];
    61     }
    62     elseif ( file_exists( $file ) && is_file( $file ) ) {
    63         $template_data = implode( '', file( $file ) );
    64         if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ))
    65             return sprintf( __( '%s Page Template' ), _cleanup_header_comment($name[1]) );
     58    global $wp_file_descriptions, $allowed_files;
     59
     60    $relative_pathinfo = pathinfo( $file );
     61    $file_path = $allowed_files[ $file ];
     62    if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $relative_pathinfo['dirname'] ) {
     63        return $wp_file_descriptions[ basename( $file ) ];
     64    } elseif ( file_exists( $file_path ) && is_file( $file_path ) ) {
     65        $template_data = implode( '', file( $file_path ) );
     66        if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) {
     67            return sprintf( __( '%s Page Template' ), _cleanup_header_comment( $name[1] ) );
     68        }
    6669    }
    6770
Note: See TracChangeset for help on using the changeset viewer.