From 8bb4c2c2e9f52808abe3ae68da64a7b54c3ae8af Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 28 Sep 2015 03:11:24 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@34658 git-svn-id: http://core.svn.wordpress.org/trunk@34622 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 21 ++++++++++++--------- wp-admin/theme-editor.php | 12 +++++++----- wp-includes/version.php | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 5e46478827..a11bc95851 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -51,18 +51,21 @@ $wp_file_descriptions = array( * * @global array $wp_file_descriptions * @param string $file Filesystem path or filename - * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist + * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist. + * Appends 'Page Template' to basename of $file if the file is a page template */ function get_file_description( $file ) { - global $wp_file_descriptions; + global $wp_file_descriptions, $allowed_files; - if ( isset( $wp_file_descriptions[basename( $file )] ) ) { - return $wp_file_descriptions[basename( $file )]; - } - elseif ( file_exists( $file ) && is_file( $file ) ) { - $template_data = implode( '', file( $file ) ); - if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name )) - return sprintf( __( '%s Page Template' ), _cleanup_header_comment($name[1]) ); + $relative_pathinfo = pathinfo( $file ); + $file_path = $allowed_files[ $file ]; + if ( isset( $wp_file_descriptions[ basename( $file ) ] ) && '.' === $relative_pathinfo['dirname'] ) { + return $wp_file_descriptions[ basename( $file ) ]; + } elseif ( file_exists( $file_path ) && is_file( $file_path ) ) { + $template_data = implode( '', file( $file_path ) ); + if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) { + return sprintf( __( '%s Page Template' ), _cleanup_header_comment( $name[1] ) ); + } } return trim( basename( $file ) ); diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php index 328577de9b..3c28ff1028 100644 --- a/wp-admin/theme-editor.php +++ b/wp-admin/theme-editor.php @@ -25,7 +25,7 @@ get_current_screen()->add_help_tab( array( 'title' => __('Overview'), 'content' => '

' . __('You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.') . '

-

' . __('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.') . '

+

' . __("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.") . '

' . __('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.') . '

' . __( '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.' ) . '

' . __('After typing in your edits, click Update File.') . '

@@ -125,7 +125,7 @@ default:

(' . $file_show . ')'; @@ -177,12 +177,14 @@ if ( $allowed_files ) : if ( 'style.css' == $filename ) echo "\t\n\t

" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "

\n\t