WordPress Plugin Development :: Getting the current plugin header information

17 September 2010, Comments: 0

You are developing a plugin and you wonder actually how you can access in the plugin itself the variables, which are shown in the plugin manager?

And why should we always redefine the information in the plugin itself?

We can easily use the WordPress function:

$plugin_data = get_file_data( __FILE__, $headers, 'plugin');

So here is an example how it works:


* Plugin Name: Pluginformation
* Version: 1.0.0
* Plugin URI: http://ieservices.de/
* Description: Simple plugin to display the plugins information
* Author: Martin Andreas Woerz
* Author URI: mailto:martin[at]ieservices[dot]de?subject=ieServices%20Plugin%20Pluginformation
* Text Domain: pluginformation
* Domain Path: plugins
* Network: ieservices.de
*/
// define which header we want to retrieve from the plugin declaration
$headers = array
(
'Name' => 'Plugin Name',
'PluginURI' => 'Plugin URI',
'Version' => 'Version',
'Description' => 'Description',
'Author' => 'Author',
'AuthorURI' => 'Author URI',
'TextDomain' => 'Text Domain',
'DomainPath' => 'Domain Path',
'Network' => 'Network',
// Site Wide Only is deprecated in favor of Network.
'_sitewide' => 'Site Wide Only',
);
// get the current file with __FILE__ and query the data from the WordPress function get_file_data()
$plugin_data = get_file_data( __FILE__, $headers, 'plugin');
echo '<pre>';
print_r($plugin_data);
echo '</pre>';


The result will be:

Array
(
[Name] => Pluginformation
[PluginURI] => http://ieservices.de/
[Version] => 1.0.0
[Description] => Simple plugin to display the plugins information
[Author] => Martin Andreas Woerz
[AuthorURI] => mailto:martin[at]ieservices[dot]de?subject=ieServices%20Plugin%20Pluginformation
[TextDomain] => pluginformation
[DomainPath] => plugins
[Network] => ieservices.de
)


Surely you can alter the headers, but those are the standards.
For example you can add an Author E-Mail address or a Authors Website

Leave a Reply