HOW to get active plugins, inactive plugins information in WordPress?

There are many scenarios where you want to get Active plugins, In Active plugins information programmatically to check few dependency or show some warning message or add new features.

Here are the simple custom functions which you can add to your code and start using it.

function get_plugins( $status = 'all', $details = false ) {

    $plugins = array(
        'active_plugins'   => array(),
        'inactive_plugins' => array()
    );

    // Check if get_plugins() function exists. This is required on the front end of the
    // site, since it is in a file that is normally only loaded in the admin.
    if ( ! function_exists( 'get_plugins' ) ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }

    $all_plugins    = get_plugins();
    $active_plugins = get_option( 'active_plugins', array() );

    if ( is_multisite() ) {
        $sitewide_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
        $active_plugins             = ! empty( $active_plugins ) ? array_merge( $sitewide_activated_plugins, $active_plugins ) : $sitewide_activated_plugins;
    }

    foreach ( $all_plugins as $plugin_path => $plugin ) {
        if ( in_array( $plugin_path, $active_plugins ) ) {
            $slug      = 'active_plugins';
            $is_active = 1;
        } else {
            $slug      = 'inactive_plugins';
            $is_active = 0;
        }

        if ( $details ) {

            $plugin_data = array(
                'name'       => $plugin['Name'],
                'version'    => $plugin['Version'],
                'author'     => $plugin['Author'],
                'author_uri' => $plugin['AuthorURI'],
                'plugin_uri' => $plugin['PluginURI'],
                'is_active'  => $is_active
            );

            $plugins[ $slug ][ $plugin_path ] = $plugin_data;
        } else {
            $plugins[ $slug ][] = $plugin_path;
        }
    }

    if ( 'active' === $status ) {
        return $plugins['active_plugins'];
    } elseif ( 'inactive' === $status ) {
        return $plugins['inactive_plugins'];
    } else {
        return array_merge( $plugins['active_plugins'], $plugins['inactive_plugins'] );
    }
}

get_plugins function take 2 arguments.

  1. $status
    all – It will return all plugins (active & inactive)
    active – Will return only active plugins
    inactive – Will return only inactive plugins

  2. $details – Do you want to include details of a plugin like name, version, author, author url, plugin url etc? Set this argument to “true”

Following PHP code will give you all active plugins without their details

$plugins = get_plugins('active', false);

Output of the above code will be

Array
(
    [0] => icegram/icegram.php
    [1] => temporary-login-without-password/temporary-login-without-password.php
)

If we want to get the details also

$plugins = get_plugins('active', true);
Array
(
    [icegram/icegram.php] => Array
        (
            [name] => Icegram - Popups, Optins, CTAs & lot more...
            [version] => 1.10.38
            [author] => icegram
            [author_uri] => https://www.icegram.com/
            [plugin_uri] => https://www.icegram.com/
            [is_active] => 1
        )

    [temporary-login-without-password/temporary-login-without-password.php] => Array
        (
            [name] => Temporary Login Without Password
            [version] => 1.6.0
            [author] => StoreApps
            [author_uri] => https://storeapps.org
            [plugin_uri] => http://www.storeapps.org/create-secure-login-without-password-for-wordpress/
            [is_active] => 1
        )
)

Similarly, we can get the information of inactive plugins using

$plugins = get_plugins('inactive');

And get the all plugins info using

$plugins = get_plugins();

Scroll to Top