[wp-trac] [WordPress Trac] #40933: Improvements for get_file_data() function
WordPress Trac
noreply at wordpress.org
Tue Jun 6 20:28:39 UTC 2017
#40933: Improvements for get_file_data() function
-------------------------+-----------------------------
Reporter: Tkama | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version: 4.7.5
Severity: normal | Keywords:
Focuses: template |
-------------------------+-----------------------------
It seams as a bug or as imperfection at least.
I try to explain in example.
Assume we have such comments in file:
{{{#!php
<?php
/*
Plugin Name: My plug
Version: 1.0
*/
// and trying to get file data like:
$data = get_file_data( __FILE__, ['ver'=>'Version'] );
echo $data['ver']; //> 1.0
}}}
This is works as we need.
BUT if we change comments a little, the get_file_data() becomes broken:
{{{#!php
<?php
/*
Plugin Name : My plug
Version : 1.0
*/
// and trying to get file data like^
$data = get_file_data( __FILE__, ['ver'=>'Version'] );
echo $data['ver']; //> ''
}}}
All we do just add spaces before `:` to make comments more readable...
-
Solution
I think it's better to improve regular expression of the get_file_data()
and add `[\t ]*` before `:`
{{{#!php
<?php
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) .
':(.*)$/mi', $file_data, $match ) && $match[1] )
to
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . '[\t
]*:(.*)$/mi', $file_data, $match ) && $match[1] )
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40933>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list