The get_plugin_data() WordPress PHP function parses the plugin contents to retrieve plugin’s metadata.
Usage
$plugin_data = get_plugin_data($plugin_file, $markup = true, $translate = true);
Parameters
- $plugin_file (string) – Required. Absolute path to the main plugin file.
- $markup (bool) – Optional. If the returned data should have HTML markup applied. Default: true
- $translate (bool) – Optional. If the returned data should be translated. Default: true
More information
See WordPress Developer Resources: get_plugin_data()
Examples
Retrieve plugin data in the admin area
This code retrieves the plugin data and displays it in the admin area.
if (is_admin()) {
if (!function_exists('get_plugin_data')) {
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
$plugin_data = get_plugin_data(__FILE__);
echo "<pre>";
print_r($plugin_data);
echo "</pre>";
}
Retrieve plugin data without HTML markup
This code retrieves the plugin data without applying any HTML markup.
$plugin_data = get_plugin_data(__FILE__, false); echo "<pre>"; print_r($plugin_data); echo "</pre>";
Retrieve plugin data without translation
This code retrieves the plugin data without translating the content.
$plugin_data = get_plugin_data(__FILE__, true, false); echo "<pre>"; print_r($plugin_data); echo "</pre>";
Retrieve specific plugin information
This code retrieves the plugin name and version from the plugin data.
$plugin_data = get_plugin_data(__FILE__); $plugin_name = $plugin_data['Name']; $plugin_version = $plugin_data['Version']; echo "Plugin Name: " . $plugin_name . "<br />"; echo "Plugin Version: " . $plugin_version;
Check if the plugin requires a minimum WordPress version
This code checks if the plugin requires a specific minimum WordPress version.
$plugin_data = get_plugin_data(__FILE__);
$required_wp_version = $plugin_data['Requires at least'];
if (!empty($required_wp_version)) {
echo "This plugin requires WordPress version " . $required_wp_version . " or higher.";
} else {
echo "No minimum WordPress version requirement.";
}