[wp-hackers] Checking plugin version

Otto otto at ottodestruct.com
Sat Sep 22 12:02:22 UTC 2012

On Sat, Sep 22, 2012 at 6:50 AM, Chris McCoy <chris at lod.com> wrote:
> To get the plugin ver you can do something like this
>     $url = 'http://api.wordpress.org/plugins/info/1.0/wordpress-seo/';
>     $ch = curl_init();
>     curl_setopt($ch, CURLOPT_URL, $url);
>     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>     $result = curl_exec($ch);
>     curl_close($ch);
>     $result = unserialize($result);
>     echo $result->version;

While that works, I cannot guarantee that it will continue to work in
the future. It's not the way the WordPress core itself uses to talk to
the API server.

You should be doing an HTTP POST to: http://api.wordpress.org/plugins/info/1.0/

The parameters in the body of the POST for the plugin info request should be:
'action' = 'plugin_information'
'request' = PHP serialized version of array('slug'=>'whatever')

If you want to not get certain parts of the request (like all the
sections stuff from the readme), you can add an optional fields
parameter to that request array, like so:
array( 'slug'=>'whatever', 'fields' => array('sections' => false) )

That would make it not return the "sections" section in the response.


More information about the wp-hackers mailing list