5

I'm writing a plugin that checks and collects data from WP - including info about installed plugins.

I can get most of the data I require using get_plugins() - however, I'd also like to check for the latest repository hosted version of each plugin - but I can't seem to find an API method for this.

Sorry, I've got no code to paste for commenting.. but I've had a good search around - honest!

Where I can find a simple and efficient way to check?

1

2 Answers 2

7

Ok - here is a method - thanks to @Rarst for pointing me in the right direction.

Include the require file if the plugins_api function is not found:

if ( ! function_exists( 'plugins_api' ) ) {
      require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
}

Then, prepare a query to pass to plugins_api():

// set the arguments to get latest info from repository via API ##
$args = array(
    'slug' => 'plugin-slug-name',
    'fields' => array(
        'version' => true,
    )
);

/** Prepare our query */
$call_api = plugins_api( 'plugin_information', $args );

/** Check for Errors & Display the results */
if ( is_wp_error( $call_api ) ) {

    $api_error = $call_api->get_error_message();

} else {

    //echo $call_api; // everything ##

    if ( ! empty( $call_api->version ) ) {

        $version_latest = $call_api->version;

    }

}

ref: http://wp.tutsplus.com/tutorials/plugins/communicating-with-the-wordpress-org-plugin-api/

3
  • 1
    The API call is slow and costly - so results should be cached in transients..
    – Q Studio
    Commented Nov 19, 2013 at 13:23
  • How to get slug name of all plugins Commented May 13, 2016 at 10:12
  • 1
    @SuneelOmrey plugins.svn.wordpress.org
    – majick
    Commented Jul 6, 2016 at 3:02
2

There is not quite simple way to do it, since WP check for plugin updates by submitting all their data in bulk and it's pretty buried in wp_update_plugins().

It performs request to http://api.wordpress.org/plugins/update-check/1.1/ API endpoint and gets data about all updates. It's not available as more contained function for individual checks.

You could also look into Plugin Information API to approach this from repository side.

2
  • Thanks @Rarst - I found the plugins_api function which got me to what I needed..
    – Q Studio
    Commented Nov 19, 2013 at 13:23
  • hi there - well watch this here stackoverflow.com/questions/51990613/… give it a try buddy
    – zero
    Commented Jun 14, 2020 at 15:30

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.