5

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.

3 Answers 3

5

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.

1
  • 3
    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"]) Feb 3, 2015 at 21:40
3

For bash users a one liner: (Install jq if not there)

curl -s "https://api.wordpress.org/core/version-check/1.7/" | jq -r '[.offers[]|select(.response=="upgrade")][0].version'
1
0
#For the PowerShell users
#One liner using aliases to retrieve latest WP version
((irm 'https://api.wordpress.org/core/version-check/1.7/').offers | ? response -eq upgrade).version

#WP Version Check API URL
$API = 'https://api.wordpress.org/core/version-check/1.7/'
#Invoke-RestMethod automatically converts JSON to PowerShell objects
$WPreleases = Invoke-RestMethod -Uri $API
#Get latest version number based on JSON response having a single "upgrade" offering
$WPlatestVersionNum = ($WPreleases.offers | Where-Object response -eq upgrade).version
#Get download URL for latest version
$WPlatestDownloadURL = ($WPreleases.offers | Where-Object response -eq upgrade).download
#Get download URL for latest version without content folder (no themes or default plugins)
$WPlatestDownloadNoContentURL = ($WPreleases.offers | Where-Object response -eq upgrade).packages.no_content
#Create variable holding all release version numbers as version type (instead of strings)
$WPallVersions = $WPreleases.offers | Where-Object response -eq autoupdate | foreach { [version]$_.version }
#Get latest version number
$WPlatestVersion = ($WPallVersions | sort -Descending)[0].ToString()
#Get latest 6.2 release version number
$WPlatestVersion62 = ($WPallVersions | Where-Object {($_.Major -eq 6) -and ($_.Minor -eq 2)} | sort -Descending)[0].ToString()
#Get latest 6.1 release version number
$WPlatestVersion61 = ($WPallVersions | Where-Object {($_.Major -eq 6) -and ($_.Minor -eq 1)} | sort -Descending)[0].ToString()
#Get latest 5 release version number
$WPlatestVersion5 = ($WPallVersions | Where-Object Major -eq 5 | sort -Descending)[0].ToString()
#Get latest 4 release version number
$WPlatestVersion4 = ($WPallVersions | Where-Object Major -eq 4 | sort -Descending)[0].ToString()
#Get download URL for latest release based on version number
$WPlatestVersionDownloadURL = ($WPreleases.offers | Where-Object version -eq $WPlatestVersion).download[0]

#WP Translation API URL
$APtranslations = 'https://api.wordpress.org/translations/core/1.0/?version='
#Language to retrieve
$Language = 'de_DE'
#Get all translations for latest WP version
$WPtranslations = Invoke-RestMethod -Uri "$APtranslations$WPlatestVersionNum"
#Does the language have support for the latest version of WP?
if (($WPtranslations.translations | Where-Object language -eq $Language).version -eq $WPlatestVersionNum) {'ja'}else{'nein'}
#Get translation download URL for latest release for German
$WPgermanDownloadURL = ($WPtranslations.translations | Where-Object language -eq $Language).package

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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