BlockHooksTrait.php
4 weeks ago
BlockTemplateUtils.php
2 months ago
BlocksSharedState.php
3 months ago
BlocksWpQuery.php
2 years ago
CartCheckoutUtils.php
4 weeks ago
MiniCartUtils.php
1 year ago
ProductAvailabilityUtils.php
11 months ago
ProductDataUtils.php
1 year ago
ProductGalleryUtils.php
4 weeks ago
StyleAttributesUtils.php
1 year ago
Utils.php
2 years ago
Utils.php
32 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Blocks\Utils; |
| 3 | |
| 4 | /** |
| 5 | * Utils class |
| 6 | */ |
| 7 | class Utils { |
| 8 | |
| 9 | /** |
| 10 | * Compare the current WordPress version with a given version. It's a wrapper around `version-compare` |
| 11 | * that additionally takes into account the suffix (like `-RC1`). |
| 12 | * For example: version 6.3 is considered lower than 6.3-RC2, so you can do |
| 13 | * wp_version_compare( '6.3', '>=' ) and that will return true for 6.3-RC2. |
| 14 | * |
| 15 | * @param string $version The version to compare against. |
| 16 | * @param string|null $operator Optional. The comparison operator. Defaults to null. |
| 17 | * @return bool|int Returns true if the current WordPress version satisfies the comparison, false otherwise. |
| 18 | */ |
| 19 | public static function wp_version_compare( $version, $operator = null ) { |
| 20 | $current_wp_version = get_bloginfo( 'version' ); |
| 21 | if ( preg_match( '/^([0-9]+\.[0-9]+)/', $current_wp_version, $matches ) ) { |
| 22 | $current_wp_version = (float) $matches[1]; |
| 23 | } |
| 24 | |
| 25 | // Replace non-alphanumeric characters with a dot. |
| 26 | $current_wp_version = preg_replace( '/[^0-9a-zA-Z\.]+/i', '.', $current_wp_version ); |
| 27 | $version = preg_replace( '/[^0-9a-zA-Z\.]+/i', '.', $version ); |
| 28 | |
| 29 | return version_compare( $current_wp_version, $version, $operator ); |
| 30 | } |
| 31 | } |
| 32 |