get_plugins()
Gets all plugins data (active and inactive): file, name, author, etc. Works with the plugins directory.
The function will collect data from all main plugin files. These are files that have PHP comments describing the plugin (plugin headers). The data will contain a relative path to the plugin file and all the data from the comment of the file itself.
WordPress works with plugins located only in directories: wp-content/plugins
and wp-content/mu-plugins
. This function searches plugins files in these two directories only, so it is recommended to all plugin files be located in these directories.
There's a similiar function wp_get_themes()
The function caches the result when the parameter $plugin_folder is specified.
To use this function on front-end or in early state, you should include this file:
require_once ABSPATH . 'wp-admin/includes/plugin.php';
No Hooks.
Return
Array[]
. Array of arrays of plugin data, keyed by plugin file name. See get_plugin_data().
Usage
get_plugins( $plugin_folder );
- $plugin_folder(string)
- Relative path to single plugin folder.
Default: ''
Examples
#1 Get the data of all plugins
The following code will return the data of all installed (maybe not active) plugins.
// Check if the get_plugins() if registered. If you're out of the dashboard // Usually get_plugins() works only on the dashboard if ( ! function_exists( 'get_plugins' ) ) { // include the file with get_plugins() require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // get the plugins data $all_plugins = get_plugins(); // Save the data to the error log, where you can see the resulting array error_log( print_r( $all_plugins, true ) );
And the log contains:
Array( [hello-dolly/hello.php] => Array ( [Name] => Hello Dolly [PluginURI] => http://wordpress.org/extend/plugins/hello-dolly/ [Version] => 1.6 [Description] => This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page. [Author] => Matt Mullenweg [AuthorURI] => http://ma.tt/ [TextDomain] => [DomainPath] => [Network] => [Title] => Hello Dolly [AuthorName] => Matt Mullenweg ) ... ...
Changelog
Since 1.5.0 | Introduced. |