class-gutenberg-compatibility.php 2.4 KB

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