Using WordPress ‘plugins_api_args’ PHP filter

The plugins_api_args WordPress PHP filter allows you to modify the arguments sent to the WordPress.org Plugin Installation API.

Usage

add_filter('plugins_api_args', 'my_custom_plugins_api_args', 10, 2);
function my_custom_plugins_api_args($args, $action) {
  // your custom code here
  return $args;
}

Parameters

  • $args (object): Plugin API arguments.
  • $action (string): The type of information being requested from the Plugin Installation API.

More information

See WordPress Developer Resources: plugins_api_args

Important: An object MUST be returned to this filter.

Examples

Set the number of plugin results

Set the number of plugin results to 15.

add_filter('plugins_api_args', 'my_custom_plugins_api_args', 10, 2);
function my_custom_plugins_api_args($args, $action) {
  if ($action == 'query_plugins') {
    $args->per_page = 15;
  }
  return $args;
}

Exclude certain plugins

Exclude certain plugins from the search results.

add_filter('plugins_api_args', 'exclude_specific_plugins', 10, 2);
function exclude_specific_plugins($args, $action) {
  if ($action == 'query_plugins') {
    $args->exclude = array('plugin-slug-one', 'plugin-slug-two');
  }
  return $args;
}

Change the search term

Change the search term to show only plugins with ‘gallery’ in their name.

add_filter('plugins_api_args', 'change_search_term', 10, 2);
function change_search_term($args, $action) {
  if ($action == 'query_plugins') {
    $args->search = 'gallery';
  }
  return $args;
}

Order plugins by most recent

Order the plugin results by the most recently updated plugins.

add_filter('plugins_api_args', 'order_plugins_by_recent', 10, 2);
function order_plugins_by_recent($args, $action) {
  if ($action == 'query_plugins') {
    $args->orderby = 'updated';
  }
  return $args;
}

Show only plugins created by a specific author.

add_filter('plugins_api_args', 'set_custom_author', 10, 2);
function set_custom_author($args, $action) {
  if ($action == 'query_plugins') {
    $args->author = 'your-author-slug';
  }
  return $args;
}