0

In the WordPress repo, on the main page for every plugin, it displays the date of the plugin's last update (screenshot). From my own WordPress site, is it possible to fetch this data with custom PHP and/or JavaScript code? I would like to fetch this information for each plugin that is installed on my site, then display it on the Dashboard-->Plugins page.

Perhaps there is some sort of API available which makes this data accessible for all plugins in the WordPress repo?

If possible, I might also want to fetch other data related to the plugin, e.g. 'WordPress version' and 'Tested up to.'

4
  • 1
    See this (and check the examples linked from there).
    – Sally CJ
    Commented Aug 16, 2019 at 9:56
  • 1
    @SallyCJ Bringo, that's exactly what I wanted--thanks. Am I allowed to mark this as the solution? Or do you need to formally add it as an answer first?
    – cag8f
    Commented Aug 17, 2019 at 14:22
  • I've just posted an answer.. :)
    – Sally CJ
    Commented Aug 18, 2019 at 12:25
  • hello and good day I'm currently working on a parser to fetch metadata on the newest plugins in wordpress. stackoverflow.com/questions/61679425/… your approach is much simple - many thanks
    – zero
    Commented Jun 1, 2020 at 7:19

1 Answer 1

3

Perhaps there is some sort of API available

Yes, there is, and you can check it out here.

There are examples linked from that Codex page, and you might want to use version 1.2 (GET requests only) or 1.1 of the API where these versions both have the response format in JSON.

And actually, there's also plugins_api() which make things easy for you; however, you'd need to manually load the file where the function is defined (wp-admin/includes/plugin-install.php).

Example using plugins_api()

// You may comment this out IF you're sure the function exists.
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';

$args = [
    'slug' => 'woocommerce',
];

$data = plugins_api( 'plugin_information', $args );
//var_dump( $data );

if ( $data && ! is_wp_error( $data ) ) {
    echo 'Latest version: ' . $data->version;
}

Example with manual HTTP requests

$args = [
    'slug' => 'woocommerce',
];

$url = 'http://api.wordpress.org/plugins/info/1.2/';
$url = add_query_arg( [
    'action'  => 'plugin_information', // first param for plugins_api()
    'request' => $args,                // second param for plugins_api()
], $url );

$res = wp_remote_get( $url );
if ( ! is_wp_error( $res ) ) {
    $data = json_decode( wp_remote_retrieve_body( $res ) );
    //var_dump( $data );
    echo 'Latest version: ' . $data->version;
}

Either way, if you want to exclude certain fields like reviews and read-me sections like "description" and "installation", you can use the fields argument like so:

$args = [
    'slug' => 'woocommerce',
    'fields' => [
        'sections' => false, // excludes all readme sections
        'reviews'  => false, // excludes all reviews
    ],
];
7
  • OK thanks for that. In the plugins_api() example you gave, you require()d plugin-install.php, with the caveat, // You may comment this out IF you're sure the function exists. Why wouldn't the function exist? If I was using a version of WordPress before 2.7?
    – cag8f
    Commented Aug 20, 2019 at 14:22
  • Hi. Sorry, what I meant with that is, cases such as a plugin may have already included the file on the page.
    – Sally CJ
    Commented Aug 21, 2019 at 6:19
  • 1
    OK got it--thanks very much!
    – cag8f
    Commented Aug 21, 2019 at 13:04
  • 1
    @zero You can do var_dump( $data ); to see the available information in $data. And you should also check the plugins_api() reference.
    – Sally CJ
    Commented Jun 2, 2020 at 13:32
  • 1
    hello dear Sally CJ - many many thanks for the hints: awesome! really overwhelming the plugins api. You hit the point. Many many thanks for all you did!!! keep up the great work here. You rock - cf cf stackoverflow.com/questions/51990613/…
    – zero
    Commented Jun 3, 2020 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.