Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use all_plugins filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
November 25, 2022
5 minutes read

all_plugins filter

To use the `all_plugins` filter, you first need to register it using `add_filter`. You can place this code into the `functions.php` file of your activated theme or in a custom WordPress Plugin.

We at WePlugins always prefer to create a custom WordPress Plugin when using hooks to ensure that nothing breaks when you update your WordPress Theme in the future.

In the example below, we’ve defined a function `weplugins_modify_all_plugins_defaults` which takes one parameter and is registered using `add_filter`. The first parameter, `all_plugins`, is the name of the hook. The second parameter, `weplugins_modify_all_plugins_defaults`, is the name of the function that needs to be called. The third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed to the registered function.

Sometimes, you may need to remove a registered hook, and you can use `remove_filter` to remove the `all_plugins` filter.

Parameters

Below the 1 parameter is required to use this hook.

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

Live Example

    apply_filters('all_plugins', array $all_plugins)
    

Below are some examples of how you can use this hook:

Example 1: Modify the list of all plugins

This example shows how to modify the `$all_plugins` array to suit your website requirements.

    function weplugins_modify_all_plugins_defaults($all_plugins) { 
        // Update the $all_plugins variable according to your website requirements and return this variable. 
        // You can modify the $all_plugins variable conditionally too if you want.
        return $all_plugins; 
    }
    // add the filter
    add_filter("all_plugins", "weplugins_modify_all_plugins_defaults", 10, 1);
    

Example 2: Remove the hook callback

To remove a hook callback, use the example below. Ensure you provide the same callback function name, priority, and number of arguments while removing the hook callback.

    remove_filter("all_plugins", "weplugins_modify_all_plugins_defaults", 10, 1);
    

Example 3: Conditional Plugin Modification

Here’s how you can modify the plugins array based on certain conditions.

    function weplugins_modify_all_plugins_on_condition($all_plugins) {
        if (is_admin()) {
            // Perform modifications only in the admin area
            $all_plugins['my-plugin/my-plugin.php'] = array(
                'Name' => 'My Plugin',
                'PluginURI' => 'https://example.com',
                'Version' => '1.0.0',
                'Description' => 'A sample plugin.',
                'Author' => 'WePlugins',
                'AuthorURI' => 'https://weplugins.com',
            );
        }
        return $all_plugins;
    }
    add_filter("all_plugins", "weplugins_modify_all_plugins_on_condition", 10, 1);
    

Access Premium WordPress Plugins

Contact Us

If you need customization or have any questions, feel free to contact us.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.