Getting version number of latest WordPress release

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)