[wp-trac] [WordPress Trac] #42517: get_file_data() doesn't support the single-line variant of post template headers
WordPress Trac
noreply at wordpress.org
Sun Nov 12 18:23:41 UTC 2017
#42517: get_file_data() doesn't support the single-line variant of post template
headers
----------------------------------------+------------------------------
Reporter: gschoppe | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.9
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests | Focuses:
----------------------------------------+------------------------------
Changes (by birgire):
* keywords: => has-patch needs-unit-tests
Comment:
It sounds reasonable to extend it to support single headers.
Thanks for the patch @gschoppe
The [attachment:refactor_get_file_data_regex.patch] also introduces a new
support for opening and closing php tags in multiple lines, like:
{{{
<?php // Plugin Name: Test ?>
<?php // Version: 1.2.3 ?>
<?php /* Plugin Name: Test */ ?>
<?php /* Version: 1.2.3 */ ?>
<?php # Plugin Name: Test ?>
<?php # Version: 1.2.3 ?>
}}}
Another approach that comes to mind, if we only want to allow a single
opening php tag and a possible single closing php tag, around the header,
is to replace the first php opening and the first possible closing tag,
before running the unchanged match-regex in {{{get_file_data()}}}.
Example:
{{{
$file_data = preg_replace( '#<\?(php)?#i', '', $file_data, 1 );
$file_data = preg_replace( '#\?>#', '', $file_data, 1 );
}}}
We could try to combine it into a single preg replace and the first that
comes to mind is something like:
{{{
$file_data = preg_replace( '#\s*(?:<\?(?:php)?)?(.*?)(?:\?>)?#i', '$1',
$file_data, 1 );
}}}
but that would not replace the optional {{{?>}}} ;-)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42517#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list