Parses the plugin contents to retrieve plugin's metadata.
Description
All plugin headers must be on their own line. Plugin description must not have any newlines, otherwise only parts of the description will be displayed.The below is formatted for printing. /*
Plugin Name: Name of the plugin.
Plugin URI: The home page of the plugin.
Description: Plugin description.
Author: Plugin author's name.
Author URI: Link to the author's website.
Version: Plugin version.
Text Domain: Optional. Unique identifier, should be same as the one used in
load_plugin_textdomain().
Domain Path: Optional. Only useful if the translations are located in a
folder above the plugin's base path. For example, if .mo files are
located in the locale folder then Domain Path will be "/locale/" and
must have the first slash. Defaults to the base folder the plugin is
located in.
Network: Optional. Specify "Network: true" to require that a plugin is activated
across all sites in an installation. This will prevent a plugin from being
activated on a single site when Multisite is enabled.
Requires at least: Optional. Specify the minimum required WordPress version.
Requires PHP: Optional. Specify the minimum required PHP version.
* / # Remove the space to close comment. The first 8 KB of the file will be pulled in and if the plugin data is not within that first 8 KB, then the plugin author should correct their plugin and move the plugin data headers to the top. The plugin file is assumed to have permissions to allow for scripts to read the file. This is not checked however and the file is only opened for reading.
Parameters
$plugin_filestring
Absolute path to the main plugin file.
$markupbooloptional
If the returned data should have HTML markup applied. Default true.Default: true
$translatebooloptional
If the returned data should be translated. Default true.Default: true
Return
array
Plugin data. Values will be empty if not supplied by the plugin.
$Namestring
Name of the plugin. Should be unique.
$PluginURIstring
Plugin URI.
$Versionstring
Plugin version.
$Descriptionstring
Plugin description.
$Authorstring
Plugin author's name.
$AuthorURIstring
Plugin author's website address (if set).
$TextDomainstring
Plugin textdomain.
$DomainPathstring
Plugin's relative directory path to .mo files.
$Networkbool
Whether the plugin can only be activated network-wide.
$RequiresWPstring
Minimum required version of WordPress.
$RequiresPHPstring
Minimum required version of PHP.
$UpdateURIstring
ID of the plugin for update purposes, should be a URI.
$RequiresPluginsstring
Comma separated list of dot org plugin slugs.
$Titlestring
Title of the plugin and link to the plugin's site (if set).
get_dropins()Checks the wp-content directory and retrieve all drop-ins with any plugin data.
get_mu_plugins()Checks the mu-plugins directory and retrieve all mu-plugin files with any plugin data.
get_plugins()Checks the plugins directory and retrieve all plugin files with plugin data.
is_network_only_plugin()Checks for "Network: true" in the plugin header to see if this should be activated only as a network wide plugin. The plugin would also work when Multisite is not enabled.
74functionget_plugin_data($plugin_file,$markup=true,$translate=true){7576$default_headers=array(77'Name'=>'Plugin Name',78'PluginURI'=>'Plugin URI',79'Version'=>'Version',80'Description'=>'Description',81'Author'=>'Author',82'AuthorURI'=>'Author URI',83'TextDomain'=>'Text Domain',84'DomainPath'=>'Domain Path',85'Network'=>'Network',86'RequiresWP'=>'Requires at least',87'RequiresPHP'=>'Requires PHP',88'UpdateURI'=>'Update URI',89'RequiresPlugins'=>'Requires Plugins',90// Site Wide Only is deprecated in favor of Network.91'_sitewide'=>'Site Wide Only',92);9394$plugin_data=get_file_data($plugin_file,$default_headers,'plugin');9596// Site Wide Only is the old header for Network.97if(!$plugin_data['Network']&&$plugin_data['_sitewide']){98/* translators: 1: Site Wide Only: true, 2: Network: true */99_deprecated_argument(__FUNCTION__,'3.0.0',sprintf(__('The %1$s plugin header is deprecated. Use %2$s instead.'),'<code>Site Wide Only: true</code>','<code>Network: true</code>'));100$plugin_data['Network']=$plugin_data['_sitewide'];101}102$plugin_data['Network']=('true'===strtolower($plugin_data['Network']));103unset($plugin_data['_sitewide']);104105// If no text domain is defined fall back to the plugin slug.106if(!$plugin_data['TextDomain']){107$plugin_slug=dirname(plugin_basename($plugin_file));108if('.'!==$plugin_slug&&!str_contains($plugin_slug,'/')){109$plugin_data['TextDomain']=$plugin_slug;110}111}112113if($markup||$translate){114$plugin_data=_get_plugin_data_markup_translate($plugin_file,$plugin_data,$markup,$translate);115}else{116$plugin_data['Title']=$plugin_data['Name'];117$plugin_data['AuthorName']=$plugin_data['Author'];118}119120return$plugin_data;121}
History
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.5.0
Added support for Requires Plugins header.from the docblock
5.8.0
Added support for Update URI header.from the docblock
5.3.0
Added support for Requires at least and Requires PHP headers.from the docblock
1.5.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-admin/includes/plugin.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.