| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\utils; |
| 4 |
|
| 5 |
/** |
| 6 |
* Static class containing all the utility functions related to versioning. |
| 7 |
*/ |
| 8 |
class Versions { |
| 9 |
/** |
| 10 |
* Return the given version until the patch version |
| 11 |
* eg: 6.4.2.1-beta => 6.4.2 |
| 12 |
* |
| 13 |
* @param String $version version. |
| 14 |
*/ |
| 15 |
private static function parse_version( $version ) { |
| 16 |
preg_match( '/^\d+(\.\d+){0,2}/', $version, $match ); |
| 17 |
if ( empty( $match ) ) { |
| 18 |
return ''; |
| 19 |
} |
| 20 |
return $match[0]; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Return the current WordPress version. |
| 25 |
*/ |
| 26 |
public static function get_wp_version() { |
| 27 |
global $wp_version; |
| 28 |
return self::parse_version( $wp_version ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Return the current PHP version. |
| 33 |
*/ |
| 34 |
public static function get_php_version() { |
| 35 |
return self::parse_version( phpversion() ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Return true if the current PHP version is not supported. |
| 40 |
*/ |
| 41 |
public static function is_php_version_not_supported() { |
| 42 |
return version_compare( phpversion(), LEADIN_REQUIRED_PHP_VERSION, '<' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Return true if the current WordPress version is not supported. |
| 47 |
*/ |
| 48 |
public static function is_wp_version_not_supported() { |
| 49 |
global $wp_version; |
| 50 |
return version_compare( $wp_version, LEADIN_REQUIRED_WP_VERSION, '<' ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Return true if a given version is less than the supported version |
| 55 |
* |
| 56 |
* @param String $version Given version to check. |
| 57 |
* @param String $version_to_compare The version number to test the given version against. |
| 58 |
*/ |
| 59 |
public static function is_version_less_than( $version, $version_to_compare ) { |
| 60 |
return version_compare( $version, $version_to_compare, '<' ); |
| 61 |
} |
| 62 |
} |
| 63 |
|