class-gutenberg-compatibility.php 2.4 KB

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