Core_Upgrader::parse_version_string( string $version )
Parses a version string into an array of parts with named keys.
Description
For valid version strings, returns an array with keys (major
, minor
, patch
, prerelease
, and nightly
). The first three are always present and always an integer, and the rest are always present but may be false
.
If the version string is not of a format recognized by the automatic update system, then this function returns null
.
Parameters
- $version
-
(Required) The version string.
Return
(array|null) An array of version parts, or null
.
Source
File: wp-admin/includes/class-core-upgrader.php
public static function parse_version_string( $version ) {
$ok = preg_match(
// Start of version string.
'#^' .
// First 3 parts must be numbers.
'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)' .
// Optional pre-release version (-alpha1, -beta2, -rc1).
'(-(?P<prerelease>[[:alnum:]]+))?' .
// Optional migration or nightly build (+nightly.20190208 or
// +migration.20181220). Migration builds are treated the same as
// the corresponding release build.
'(\+(?P<build_type>migration|nightly)\.(?P<build_number>\d{8}))?' .
// End of version string.
'$#',
$version,
$matches
);
if ( ! $ok ) {
return null;
}
if ( empty( $matches['prerelease'] ) ) {
$matches['prerelease'] = false;
}
if ( isset( $matches['build_type'] ) && $matches['build_type'] === 'nightly' ) {
$nightly_build = $matches['build_number'];
} else {
$nightly_build = false;
}
return [
'major' => intval( $matches['major'] ),
'minor' => intval( $matches['minor'] ),
'patch' => intval( $matches['patch'] ),
'prerelease' => $matches['prerelease'],
'nightly' => $nightly_build,
];
}