Using WordPress ‘plugins_api()’ PHP function

The plugins_api() WordPress PHP function retrieves plugin installer pages from the WordPress.org Plugins API.

Usage

$result = plugins_api($action, $args);

Parameters

  • $action (string) – API action to perform: ‘query_plugins’, ‘plugin_information’, ‘hot_tags’, or ‘hot_categories’.
  • $args (array|object) – Array or object of arguments to serialize for the Plugin Info API. Arguments include slug, per_page, page, number, search, tag, author, user, browse, locale, installed_plugins, is_ssl, and fields.

More information

See WordPress Developer Resources: plugins_api()

Examples

Search for plugins by keyword

$args = array(
    'search' => 'gallery'
);
$result = plugins_api('query_plugins', $args);

// Display plugin names
foreach ($result->plugins as $plugin) {
    echo $plugin->name . '<br>';
}

Get plugin information

$args = array(
    'slug' => 'akismet'
);
$result = plugins_api('plugin_information', $args);

// Display plugin information
echo 'Plugin Name: ' . $result->name . '<br>';
echo 'Version: ' . $result->version . '<br>';
echo 'Author: ' . $result->author . '<br>';
$args = array(
    'browse' => 'popular',
    'per_page' => 5
);
$result = plugins_api('query_plugins', $args);

// Display popular plugin names
foreach ($result->plugins as $plugin) {
    echo $plugin->name . '<br>';
}

Get plugins by author

$args = array(
    'author' => 'automattic'
);
$result = plugins_api('query_plugins', $args);

// Display plugin names by the author
foreach ($result->plugins as $plugin) {
    echo $plugin->name . '<br>';
}

Get a user’s favorite plugins

$args = array(
    'user' => 'john_doe'
);
$result = plugins_api('query_plugins', $args);

// Display user's favorite plugin names
foreach ($result->plugins as $plugin) {
    echo $plugin->name . '<br>';
}