Get Latest Plugin Version from WP API

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/

Leave a Comment