Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20955 closed defect (bug) (fixed)

get_file_data() is more strict than get_page_templates() was in 3.3

Reported by: nacin's profile nacin Owned by:
Milestone: 3.4.1 Priority: normal
Severity: major Version: 3.4
Component: Themes Keywords: has-patch commit
Focuses: Cc:

Description

get_page_templates() read in a file's contents and then matched '|Template Name:(.*)$|mi'. get_file_data() is much more strict about what it will accept. In particular, this will not work:

<?php /* Template Name: My Template */ ?>

I like the idea of using get_file_data(), but I don't know if it will be tenable to keep using it. We can revert to the same operations in 3.3 inside WP_Theme->get_page_templates() and be much safer.

Change History (8)

#1 @Otto42
12 years ago

Is it possible to make get_file_data more forgiving, without breaking other things? Or maybe add a $strict flag to get_file_data to allow it to be more or less strict for this use?

#2 @nacin
12 years ago

Yes, we could make it more forgiving, but I'm not sure how much we could get away with, without then breaking other uses by being too liberal in what we accept. Especially since the regular expression for 'Template Name' was as forgiving as it gets. We'll have to come up with a set of tests and then pick a path.

#3 @nacin
12 years ago

Introduced in the main WP_Theme commit, [20029], on February 28. Took a release almost four months later to trigger a bug report.

#4 @nacin
12 years ago

In [21117]:

Revert detection of page templates to 3.3 functionality.

WP_Theme in 3.4.0 used get_file_data(), which is far too strict when
compared to the original regular expression in get_page_templates().
This causes missing templates when, for example, the PHP comment
starts on the same line as the header.

see #20955 for trunk.

#5 @nacin
12 years ago

  • Keywords has-patch commit added; needs-patch needs-unit-tests removed

#6 @nacin
12 years ago

In [21120]:

Revert detection of page templates to 3.3 functionality.

WP_Theme in 3.4.0 used get_file_data(), which is far too strict when
compared to the original regular expression in get_page_templates().
This causes missing templates when, for example, the PHP comment
starts on the same line as the header.

see #20955 for 3.4.

#7 @nacin
12 years ago

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

#8 @nacin
12 years ago

  • Version set to 3.4
Note: See TracTickets for help on using tickets.