Opened 13 months ago
Closed 13 months ago
#20718 closed defect (bug) (fixed)
Function get_file_description() Always Returns File Name Instead of Template Name
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.4 |
| Component: | Themes | Version: | 3.4 |
| Severity: | trivial | Keywords: | has-patch commit |
| Cc: |
Description (last modified by SergeyBiryukov)
When there's a custom page template named "something.php" defined with
/* Template Name: Something */
On the theme editor, the file list supposed to returns:
"Something" (something.php)
where it is displaying only the file name:
"something.php"
Well it doesn't affect the functionality but it IS annoying.
I found the problem is on the:
file: wp-admin/includes/file.php
line: 62
where:
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]) );
Well, it will always returns the filename instead of the template name since it will never find the $file on the defined path.
It should be something like:
elseif ( file_exists( get_template_directory() . '/' . $file ) && is_file( get_template_directory() . '/' . $file ) ) {
$template_data = implode( '', file( get_template_directory() . '/' . $file ) );
if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ))
return sprintf( __( '%s Page Template' ), _cleanup_header_comment($name[1]) );
Again, it's nothing but annoying
Attachments (1)
Change History (7)
comment:1
SergeyBiryukov
— 13 months ago
- Description modified (diff)
comment:2
arieputranto
— 13 months ago
SergeyBiryukov
— 13 months ago
comment:3
SergeyBiryukov
— 13 months ago
- Component changed from Administration to Themes
- Keywords has-patch added; needs-patch removed
- Milestone changed from Awaiting Review to 3.4
Introduced in [20313].
Found better fix.
Instead of fixing the file.php, it will be better to change the;
File: wp-admin/theme-editor.php
Line: 183
Before:
$file_description = get_file_description( $filename );
After:
$file_description = get_file_description( $theme->theme_root . '/' . $theme->stylesheet . '/' . $filename );