Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#20955 closed defect (bug) (fixed)

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

Reported by: nacin Owned by:
Priority: normal Milestone: 3.4.1
Component: Themes Version: 3.4
Severity: major Keywords: has-patch commit
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)

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?

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.

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

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.

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

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.

  • Resolution set to fixed
  • Status changed from new to closed
  • Version set to 3.4
Note: See TracTickets for help on using tickets.