3

I want to find out the latest version of WordPress that is officially released. If possible, I'd like to get that version language specific for at least English and German.

I could try and parse the website https://wordpress.org/download/ but it doesn't have the version number in a specific place. I also know I could download the latest package (https://wordpress.org/latest.zip), but I don't need the whole package, just the version number.

Is there a reliable, stable way to just get the latest stable version number of WordPress?

This question is not about getting the version number of my WordPress installation. Actually I want to compare my installed version against the latest version by a script.

4

WordPress.org offers an api that includes a version checker. That version checker can return a json response (or a serialized string if that's your thing).

Example usage

$url = 'https://api.wordpress.org/core/version-check/1.7/';
$response = wp_remote_get($url);

$json = $response['body'];
$obj = json_decode($json);

The resulting $obj will contain an offers array, whose first element is an object that contains the information you want.

$upgrade = $obj->offers[0];
echo $upgrade->version;

$upgrade will also contain a lot of other useful information including the locale, where to download the current version, etc.

If you're going to be running this in a plugin, I'd recommend caching it with a transient that expires every 12 hours or something and not spamming the poor api on every page load.

Edit: Variable name spelling fail.

  • 2
    I adapted this to Python: rawjson = urllib2.urlopen("https://api.wordpress.org/core/version-check/1.7/").read() version = json.loads(rawjson) print(version["offers"][0]["version"]) – Thomas Weller Feb 3 '15 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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