The plugins_api WordPress PHP filter allows you to modify the response for the current WordPress.org Plugin Installation API request. By returning a non-false value, you can effectively short-circuit the WordPress.org API request. For $action
values ‘query_plugins’ or ‘plugin_information’, an object must be passed. For ‘hot_tags’ or ‘hot_categories’, an array should be passed.
Usage
add_filter('plugins_api', 'my_custom_plugins_api', 10, 3); function my_custom_plugins_api($result, $action, $args) { // Your custom code here return $result; }
Parameters
$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.
More information
See WordPress Developer Resources: plugins_api
Examples
Modify plugin information
In this example, we will modify the plugin information by changing the name and the author of the plugin.
add_filter('plugins_api', 'modify_plugin_information', 10, 3); function modify_plugin_information($result, $action, $args) { if ($action === 'plugin_information') { $result->name = 'My Custom Plugin Name'; $result->author = 'John Doe'; } return $result; }
Prevent plugin update
In this example, we will prevent a specific plugin from updating by checking the plugin’s slug and modifying the version
property.
add_filter('plugins_api', 'prevent_plugin_update', 10, 3); function prevent_plugin_update($result, $action, $args) { if ($action === 'plugin_information' && $args->slug === 'plugin-slug-to-disable') { $result->version = '1.0.0'; } return $result; }
Add custom tags to plugins
In this example, we will add custom tags to the plugins when $action
is ‘hot_tags’.
add_filter('plugins_api', 'add_custom_tags', 10, 3); function add_custom_tags($result, $action, $args) { if ($action === 'hot_tags') { $result[] = array('tag' => 'custom-tag', 'display_name' => 'Custom Tag', 'count' => 1); } return $result; }