Using WordPress ‘all_plugins’ PHP filter

The all_plugins WordPress PHP filter allows you to modify the full array of plugins that are displayed in the Plugins list table.

Usage

add_filter('all_plugins', 'your_custom_function_name');
function your_custom_function_name($all_plugins) {
    // your custom code here

    return $all_plugins;
}

Parameters

  • $all_plugins (array): An array of plugins to display in the list table.

More information

See WordPress Developer Resources: all_plugins

Examples

Hiding a specific plugin

Hide the “Hello Dolly” plugin from the Plugins list table.

add_filter('all_plugins', 'hide_hello_dolly_plugin');
function hide_hello_dolly_plugin($all_plugins) {
    unset($all_plugins['hello.php']);
    return $all_plugins;
}

Adding a custom plugin

Add a custom plugin to the Plugins list table.

add_filter('all_plugins', 'add_custom_plugin');
function add_custom_plugin($all_plugins) {
    $custom_plugin = array(
        'custom-plugin.php' => array(
            'Name' => 'Custom Plugin',
            'Description' => 'A custom plugin description.',
        )
    );
    $all_plugins = array_merge($all_plugins, $custom_plugin);
    return $all_plugins;
}

Alphabetically sorting plugins

Sort the plugins in the Plugins list table alphabetically by plugin name.

add_filter('all_plugins', 'sort_plugins_alphabetically');
function sort_plugins_alphabetically($all_plugins) {
    uasort($all_plugins, function($a, $b) {
        return strcmp($a['Name'], $b['Name']);
    });
    return $all_plugins;
}

Filtering plugins by author

Only display plugins by a specific author in the Plugins list table.

add_filter('all_plugins', 'filter_plugins_by_author');
function filter_plugins_by_author($all_plugins) {
    $filtered_plugins = array();
    foreach ($all_plugins as $key => $plugin) {
        if ($plugin['Author'] === 'Author Name') {
            $filtered_plugins[$key] = $plugin;
        }
    }
    return $filtered_plugins;
}

Hiding inactive plugins

Hide inactive plugins from the Plugins list table.

add_filter('all_plugins', 'hide_inactive_plugins');
function hide_inactive_plugins($all_plugins) {
    $active_plugins = get_option('active_plugins');
    $active_plugins = array_flip($active_plugins);
    return array_intersect_key($all_plugins, $active_plugins);
}