[wp-hackers] Accessing Update Check API Outside of WordPress

David Anderson david at wordshell.net
Tue Nov 20 13:00:45 UTC 2012


>
> You could prob use sed/awk, I used that for a shell script I wrote to
> install wp by specifying the version, if not get the current version.
>
> Here are two diff ways I used.
>
>              wp_current_version=`curl -s
> http://api.wordpress.org/core/version-check/1.6/  | awk -F\" '{print $34}'`
>              wp_current_version=`curl -s
> http://api.wordpress.org/core/version-check/1.6/  | sed -e
> 's/.*s:7:"current";s:5:"//;s/".*//'`
>
> of course this is just for wp version not plugin, but you get the idea.
That particular one's not necessary, as if you specify version 1.5 
instead of 1.6, you get plain text:

    curl -s http://api.wordpress.org/core/version-check/1.5/
    upgrade
    http://wordpress.org/download/
    http://wordpress.org/wordpress-3.4.2.zip
    3.4.2
    en_US
    5.2.4
    5.0

Trying to process PHP serialized data using sed and awk is probably 
enough to get you put in an institution in many jurisdictions. If I want 
to parse something like this to answer a question "is version Y of this 
plugin tested with version X of WordPress", the only reliable way to do 
it is to write a complete shell implementation of PHP's "unserialize" 
function to process this:

O:8:"stdClass":18:{s:4:"name";s:29:"Print Friendly and PDF 
Button";s:4:"slug";s:13:"printfriendly";s:7:"version";s:5:"3.1.4";s:6:"author";s:57:"<a 
href="http://www.PrintFriendly.com">Print 
Friendly</a>";s:14:"author_profile";s:43:"http://profiles.wordpress.org/printfriendly";s:12:"contributors";a:2:{s:13:"printfriendly";s:43:"http://profiles.wordpress.org/printfriendly";s:11:"joostdevalk";s:41:"http://profiles.wordpress.org/joostdevalk";}s:8:"requires";s:3:"2.8";s:6:"tested";s:5:"3.4.2";s:13:"compatibility";a:20:{s:5:"2.8.5";a:1:{s:3:"1.3";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}}s:5:"2.9.1";a:2:{s:3:"1.3";a:3:{i:0;i:100;i:1;i:3;i:2;i:3;}s:5:"3.0.6";a:3:{i:0;i:0;i:1;i:1;i:2;i:0;}}s:5:"2.9.2";a:1:{s:3:"1.3";a:3:{i:0;i:67;i:1;i:3;i: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3:"3.0";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}}s:5:"3.2.1";a:6:{s:3:"3.0";a:3:{i:0;i:100;i:1;i:3;i:2;i:3;}s:5:"3.0.2";a:3:{i:0;i:100;i:1;i:2;i:2;i:2;}s:5:"3.0.3";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}s:5:"3.0.4";a:3:{i:0;i:78;i:1;i:9;i:2;i:7;}s:5:"3.0.6";a:3:{i:0;i:88;i:1;i:16;i:2;i:14;}s:5:"3.0.8";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}}s:3:"3.3";a:3:{s:5:"3.0.6";a:3:{i:0;i:100;i:1;i:4;i:2;i:4;}s:5:"3.0.7";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}s:5:"3.0.8";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}}s:5:"3.3.1";a:2:{s:5:"3.0.6";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}s:5:"3.0.8";a:3:{i:0;i:83;i:1;i:24;i:2;i:20;}}s:5:"3.3.2";a:1:{s:5:"3.0.8";a:3:{i:0;i:90;i:1;i:10;i:2;i:9;}}s:3:"3.4";a:1:{s:5:"3.0.8";a:3:{i:0;i:100;i:1;i:5;i:2;i:5;}}s:5:"3.4.1";a:1:{s:5:"3.0.8";a:3:{i:0;i:100;i:1;i:16;i:2;i:16;}}s:5:"3.4.2";a:3:{s:5:"3.0.8";a:3:{i:0;i:100;i:1;i:2;i:2;i:2;}s:5:"3.1.1";a:3:{i:0;i:100;i:1;i:4;i:2;i:4;}s:5:"3.1.3";a:3:{i:0;i:100;i:1;i:1;i:2;i:1;}}}s:6:"rating";d:86.7999999999999971578290569595992565155029296875;s:11:"num_ratings";i:188;s:10:"downloaded";i:164030;s:12:"last_updated";s:10:"2012-11-19";s:5:"added";s:10:"2009-05-01";s:8:"homepage";s:28:"http://www.printfriendly.com";s:8:"sections";a:5:{s:11:"description";s:2466:"<p>The 
Print Friendly &#38; PDF button saves paper and ink when printing or 
creating a PDF. It's fast, easy, and looks great when printed. Add the 
button now, and your users will see the difference.</p> (etc.)

That kind of task reminds me of when I was at school and someone gave me 
a handbook for learning machine code. Fun, if you have a long time to 
invest in it.

JSON is similar, but less complex and easier to write a parser for, but 
still a long job. I hadn't realised that api.wordpress.org output JSON 
until Andrew mentioned it yesterday - I'd only know of the serialized 
and XML. Now I've Googled, it seems that there is a MIT-licensed 
pure-shell parser for JSON, here which I'm about to investigate: 
https://github.com/dominictarr/JSON.sh. Looks promising.

David

-- 
WordShell - WordPress fast from the CLI - www.wordshell.net



More information about the wp-hackers mailing list