Make WordPress Core

Opened 10 years ago

Closed 4 years ago

#33387 closed defect (bug) (fixed)

get_file_data() should handle a <?php prefixed header

Reported by: dd32's profile dd32 Owned by: m_uysl's profile m_uysl
Milestone: 5.8 Priority: normal
Severity: normal Version:
Component: Themes Keywords: good-first-bug has-patch has-unit-tests
Focuses: Cc:

Description (last modified by dd32)

Currently get_file_data() fails when a file contains a header in the format <?php // Template Name: Something ?>.

WP_Theme currently doesn't use get_file_data() (but should IMHO: #33388) so isn't affected by this, but this feels like a common-enough case amongst themes that we should consider supporting, even if only to have a single method of extracting header data.

One method could be to use this as the regular expression, which allows for a PHP opening tag to start off the line (allowing for spaces/tabs before hand)

'/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $header, '/' ) . ':(.*)$/mi'

Attachments (3)

33387.diff (637 bytes) - added by m_uysl 9 years ago.
33387.2.diff (690 bytes) - added by Thomas Vitale 7 years ago.
Patch refreshed
33387.3.diff (1.8 KB) - added by boblinthorst 4 years ago.

Download all attachments as: .zip

Change History (15)

#1 @dd32
10 years ago

  • Description modified (diff)

#2 @ocean90
9 years ago

  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to Future Release

@m_uysl
9 years ago

#3 @m_uysl
9 years ago

patch added. +1 for #33388

#4 @DrewAPicture
9 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to m_uysl
  • Status changed from new to assigned

Assigning to mark the good-first-bug as "claimed".

#5 @Thomas Vitale
7 years ago

  • Keywords needs-refresh added

@Thomas Vitale
7 years ago

Patch refreshed

#6 @Thomas Vitale
7 years ago

  • Keywords needs-refresh removed

This ticket was mentioned in Slack in #core by sergey. View the logs.


4 years ago

#8 @SergeyBiryukov
4 years ago

  • Milestone changed from Future Release to 5.8

#9 @hellofromTonya
4 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from 5.8 to 5.9

Today is 5.8 Beta 1. Ran out of time for this one to land. Punting to 5.9.

Adding needs-unit-tests for review if there's test coverage.

@boblinthorst
4 years ago

#10 @SergeyBiryukov
4 years ago

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

#11 @SergeyBiryukov
4 years ago

  • Component changed from General to Themes
  • Milestone changed from 5.9 to 5.8

Thanks for adding the test! This seems straightforward enough to include in 5.8.

#12 @SergeyBiryukov
4 years ago

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

In 51182:

Themes: Make sure get_file_data() recognizes headers prefixed by <?php tag.

This allows for using headers in the format of <?php // Template Name: Something ?>, which previously could not be recognized correctly.

Props dd32, m_uysl, thomas-vitale, boblinthorst.
Fixes #33387.

Note: See TracTickets for help on using tickets.