Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#40933 new enhancement

Improvements for get_file_data() function

Reported by: tkama's profile Tkama Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.5
Component: Formatting Keywords: has-patch
Focuses: template Cc:


It seams as a bug or as imperfection at least.

I try to explain in example.

Assume we have such comments in file:

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:

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...



I think it's better to improve regular expression of the get_file_data() and add [\t ]* before :


if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] )


if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . '[\t ]*:(.*)$/mi', $file_data, $match ) && $match[1] )

Attachments (1)

40933.patch (593 bytes) - added by subrataemfluence 7 years ago.

Download all attachments as: .zip

Change History (7)

#1 @Tkama
7 years ago

The same applies to function get_plugin_data(), bacause it relies on get_file_data()

#2 @subrataemfluence
7 years ago

  • Keywords has-patch added

#3 @subrataemfluence
7 years ago

Good catch! :)

#4 follow-up: @Tkama
7 years ago

Thanks a lot! :)

#5 in reply to: ↑ 4 @subrataemfluence
7 years ago

Replying to Tkama:

Thanks a lot! :)

You are welcome:) Would you mind testing the patch and see if it works as desired?
Thank you.

#6 @Tkama
7 years ago

I already tested code I suggested - it works fine!

But, off course if I will see troubles about this issue and give to know...

Last edited 7 years ago by Tkama (previous) (diff)
Note: See TracTickets for help on using tickets.