Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#20718 closed defect (bug) (fixed)

Function get_file_description() Always Returns File Name Instead of Template Name

Reported by: arieputranto Owned by: ryan
Milestone: 3.4 Priority: normal
Severity: trivial Version: 3.4
Component: Themes Keywords: has-patch commit
Focuses: 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:


where it is displaying only the file name:


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


	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)

20718.patch (625 bytes) - added by SergeyBiryukov 3 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 @SergeyBiryukov3 years ago

  • Description modified (diff)

comment:2 @arieputranto3 years ago

Found better fix.
Instead of fixing the file.php, it will be better to change the;

File: wp-admin/theme-editor.php

Line: 183


$file_description = get_file_description( $filename );


$file_description = get_file_description( $theme->theme_root . '/' . $theme->stylesheet . '/' . $filename );

Version 0, edited 3 years ago by arieputranto (next)

@SergeyBiryukov3 years ago

comment:3 @SergeyBiryukov3 years 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].

comment:4 @nacin3 years ago

I think get_file_description() should use wp_get_theme()->get_page_templates(). Would be nice, but for 3.4 though.

get_file_description() could become a method in WP_Theme, which would make things a bit easier.

Patch looks good.

comment:5 @nacin3 years ago

  • Keywords commit added; dev-feedback removed

comment:6 @ryan3 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [20844]:

Show the template name instead of just the filename. Props arieputranto, SergeyBiryukov. fixes #20718

Note: See TracTickets for help on using tickets.