WordPress.org

Make WordPress Core

Changeset 34658


Ignore:
Timestamp:
09/28/2015 03:10:08 AM (4 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.

Location:
trunk/src/wp-admin
Files:
2 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
  • trunk/src/wp-admin/theme-editor.php

    r34066 r34658  
    2626'content'   =>
    2727    '<p>' . __('You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.') . '</p>
    28     <p>' . __('Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list then appears of all the template files. Clicking once on any file name causes the file to appear in the large Editor box.') . '</p>
     28    <p>' . __("Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list then appears of the theme's template files. Clicking once on any file name causes the file to appear in the large Editor box.") . '</p>
    2929    <p>' . __('For PHP files, you can use the Documentation dropdown to select from functions recognized in that file. Look Up takes you to a web page with reference material about that particular function.') . '</p>
    3030    <p id="newcontent-description">' . __( 'In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key. In some cases the Esc key will need to be pressed twice before the Tab key will allow you to continue.' ) . '</p>
     
    126126<?php endif;
    127127
    128 $description = get_file_description( $file );
     128$description = get_file_description( $relative_file );
    129129$file_show = array_search( $file, array_filter( $allowed_files ) );
    130130if ( $description != $file_show )
     
    178178            echo "\t</ul>\n\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n\t<ul>\n";
    179179
    180         $file_description = get_file_description( $absolute_filename );
    181         if ( $file_description != basename( $filename ) )
     180        $file_description = get_file_description( $filename );
     181        if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) {
    182182            $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>';
    183 
    184         if ( $absolute_filename == $file )
     183        }
     184
     185        if ( $absolute_filename === $file ) {
    185186            $file_description = '<span class="highlight">' . $file_description . '</span>';
     187        }
    186188?>
    187189        <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&amp;theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li>
Note: See TracChangeset for help on using the changeset viewer.