| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Gutenberg_Compatibility |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Class WPSEO_Gutenberg_Compatibility |
| 10 |
*/ |
| 11 |
class WPSEO_Gutenberg_Compatibility { |
| 12 |
|
| 13 |
/** |
| 14 |
* The currently released version of Gutenberg. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
const CURRENT_RELEASE = '12.7.0'; |
| 19 |
|
| 20 |
/** |
| 21 |
* The minimally supported version of Gutenberg by the plugin. |
| 22 |
* |
| 23 |
* @var string |
| 24 |
*/ |
| 25 |
const MINIMUM_SUPPORTED = '12.7.0'; |
| 26 |
|
| 27 |
/** |
| 28 |
* Holds the current version. |
| 29 |
* |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
protected $current_version = ''; |
| 33 |
|
| 34 |
/** |
| 35 |
* WPSEO_Gutenberg_Compatibility constructor. |
| 36 |
*/ |
| 37 |
public function __construct() { |
| 38 |
$this->current_version = $this->detect_installed_gutenberg_version(); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Determines whether or not Gutenberg is installed. |
| 43 |
* |
| 44 |
* @return bool Whether or not Gutenberg is installed. |
| 45 |
*/ |
| 46 |
public function is_installed() { |
| 47 |
return $this->current_version !== ''; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Determines whether or not the currently installed version of Gutenberg is below the minimum supported version. |
| 52 |
* |
| 53 |
* @return bool True if the currently installed version is below the minimum supported version. False otherwise. |
| 54 |
*/ |
| 55 |
public function is_below_minimum() { |
| 56 |
return version_compare( $this->current_version, $this->get_minimum_supported_version(), '<' ); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Gets the currently installed version. |
| 61 |
* |
| 62 |
* @return string The currently installed version. |
| 63 |
*/ |
| 64 |
public function get_installed_version() { |
| 65 |
return $this->current_version; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Determines whether or not the currently installed version of Gutenberg is the latest, fully compatible version. |
| 70 |
* |
| 71 |
* @return bool Whether or not the currently installed version is fully compatible. |
| 72 |
*/ |
| 73 |
public function is_fully_compatible() { |
| 74 |
return version_compare( $this->current_version, $this->get_latest_release(), '>=' ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Gets the latest released version of Gutenberg. |
| 79 |
* |
| 80 |
* @return string The latest release. |
| 81 |
*/ |
| 82 |
protected function get_latest_release() { |
| 83 |
return self::CURRENT_RELEASE; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Gets the minimum supported version of Gutenberg. |
| 88 |
* |
| 89 |
* @return string The minumum supported release. |
| 90 |
*/ |
| 91 |
protected function get_minimum_supported_version() { |
| 92 |
return self::MINIMUM_SUPPORTED; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Detects the currently installed Gutenberg version. |
| 97 |
* |
| 98 |
* @return string The currently installed Gutenberg version. Empty if the version couldn't be detected. |
| 99 |
*/ |
| 100 |
protected function detect_installed_gutenberg_version() { |
| 101 |
if ( defined( 'GUTENBERG_VERSION' ) ) { |
| 102 |
return GUTENBERG_VERSION; |
| 103 |
} |
| 104 |
|
| 105 |
return ''; |
| 106 |
} |
| 107 |
} |
| 108 |
|