The get_plugins()
WordPress function is used to retrieve an array of installed plugins on a WordPress site. It returns an array of plugin objects that contain information about each plugin, such as the plugin name, plugin version, plugin author, plugin description, file path, and other useful information.
This function is useful for developers who want to programmatically access information about installed plugins on a WordPress site. For example, you could use this function to build a dashboard widget that displays the version numbers of all installed plugins.
Here’s an example of how to use the get_plugins()
function to retrieve an array of installed plugins:
$plugins = get_plugins();
foreach ($plugins as $plugin_file => $plugin_data) {
echo 'Plugin Name: ' . $plugin_data['Name'] . '<br />';
echo 'Plugin Version: ' . $plugin_data['Version'] . '<br />';
echo 'Plugin Author: ' . $plugin_data['Author'] . '<br />';
echo 'Plugin Description: ' . $plugin_data['Description'] . '<br />';
echo 'Plugin File Path: ' . $plugin_file . '<br />';
echo '<br />';
}
In this example, we’re using a foreach
loop to iterate over the array of plugin objects returned by get_plugins()
. For each plugin, we’re printing out the plugin name, version, author, description, and file path.