This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
plugins_api filter
Returning a non-false value will effectively short-circuit the WordPress.org API request. To use the plugins_api filter, you first need to register it using add_filter. This can be done in the functions.php file of your active theme or in a custom WordPress plugin. WePlugins always recommends creating a custom WordPress plugin when using hooks, ensuring nothing breaks during theme updates.
Sometimes, you might need to remove a registered hook; in such cases, you can use remove_filter to remove the plugins_api filter.
Modify Plugins API Defaults
In this example, we define a function modify_plugins_api_defaults which takes three parameters, and we register it using add_filter. The first parameter plugins_api is the name of the hook, the second parameter modify_plugins_api_defaults is the function name to be called, the third parameter is the priority for 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.
function modify_plugins_api_defaults($result, $action, $args) { // Update the $result variable according to your website requirements and return this variable. You can modify the $result variable conditionally too if you want. return $result; } // add the filter add_filter( "plugins_api", "modify_plugins_api_defaults", 10, 3 );
Remove Plugins API Hook
To remove a hook callback, use the example below. Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
remove_filter( "plugins_api", "modify_plugins_api_defaults", 10, 3 );
Custom Plugin Example
Here’s an example of how you might implement this in a custom plugin, ensuring that updates to your theme won’t affect the hook.
// In your custom plugin file function weplugins_custom_plugins_api($result, $action, $args) { // Custom logic here return $result; } add_filter('plugins_api', 'weplugins_custom_plugins_api', 10, 3);
Parameters
Below are the 3 parameters required to use this hook.
- $result: (false|object|array) The result object or array. Default false.
- $action: (string) The type of information being requested from the Plugin Installation API.
- $args: (object) Plugin API arguments.
Need Customization?
If you’re having any trouble using this hook or need custom solutions, please Contact Us. Our team at WePlugins would be happy to assist you!
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.