Using WordPress ‘get_plugins()’ PHP function

The get_plugins() WordPress PHP function checks the plugins directory and retrieves all plugin files with plugin data.

Usage

To use the get_plugins() function, you need to check if it exists and then call it:

if ( ! function_exists( 'get_plugins' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();

Parameters

  • $plugin_folder (string) – Optional. Relative path to a single plugin folder. Default is an empty string (”).

More information

See WordPress Developer Resources: get_plugins()

Examples

Get all installed plugins

This example retrieves all installed plugins on your site (not just activated ones) and saves the data to the error log:

if ( ! function_exists( 'get_plugins' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();
error_log( print_r( $all_plugins, true ) );

Get all active plugins

This example retrieves all active plugins on your site:

$active_plugins = get_option( 'active_plugins' );
foreach ( $active_plugins as $plugin ) {
    echo $plugin . '<br>';
}

Display all plugin names and authors

This example shows how to display the names and authors of all installed plugins:

if ( ! function_exists( 'get_plugins' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();
foreach ( $all_plugins as $plugin ) {
    echo 'Plugin Name: ' . $plugin['Name'] . '<br>';
    echo 'Author: ' . $plugin['AuthorName'] . '<br><br>';
}

Get plugins from a specific folder

This example retrieves all plugins from a specific folder:

$folder = '/custom-folder';
if ( ! function_exists( 'get_plugins' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugins_from_folder = get_plugins( $folder );
print_r( $plugins_from_folder );

Check if a specific plugin is installed

This example checks if a specific plugin is installed:

$plugin_to_check = 'hello-dolly/hello.php';
if ( ! function_exists( 'get_plugins' ) ) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();

if ( array_key_exists( $plugin_to_check, $all_plugins ) ) {
    echo 'The plugin "' . $all_plugins[$plugin_to_check]['Name'] . '" is installed.';
} else {
    echo 'The plugin is not installed.';
}