class-plugin-compatibility.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Plugin_Compatibility
  6. */
  7. /**
  8. * Class WPSEO_Plugin_Compatibility.
  9. *
  10. * @codeCoverageIgnore
  11. * @deprecated 12.3
  12. */
  13. class WPSEO_Plugin_Compatibility {
  14. /**
  15. * Holds the current WPSEO version.
  16. *
  17. * @var string
  18. */
  19. protected $current_wpseo_version;
  20. /**
  21. * Holds the availability checker.
  22. *
  23. * @var WPSEO_Plugin_Availability
  24. */
  25. protected $availability_checker;
  26. /**
  27. * Holds the installed plugins.
  28. *
  29. * @var array
  30. */
  31. protected $installed_plugins;
  32. /**
  33. * WPSEO_Plugin_Compatibility constructor.
  34. *
  35. * @deprecated 12.3
  36. * @codeCoverageIgnore
  37. *
  38. * @param string $version The version to check against.
  39. * @param null|class $availability_checker The checker to use.
  40. */
  41. public function __construct( $version, $availability_checker = null ) {
  42. _deprecated_function( __METHOD__, '12.3' );
  43. // We trim off the patch version, as this shouldn't break the comparison.
  44. $this->current_wpseo_version = $this->get_major_minor_version( $version );
  45. $this->availability_checker = $this->retrieve_availability_checker( $availability_checker );
  46. $this->installed_plugins = $this->availability_checker->get_installed_plugins();
  47. }
  48. /**
  49. * Retrieves the availability checker.
  50. *
  51. * @deprecated 12.3
  52. * @codeCoverageIgnore
  53. *
  54. * @param null|object $checker The checker to set.
  55. *
  56. * @return WPSEO_Plugin_Availability The checker to use.
  57. */
  58. private function retrieve_availability_checker( $checker ) {
  59. _deprecated_function( __METHOD__, '12.3' );
  60. if ( is_null( $checker ) || ! is_object( $checker ) ) {
  61. $checker = new WPSEO_Plugin_Availability();
  62. $checker->register();
  63. }
  64. return $checker;
  65. }
  66. /**
  67. * Wraps the availability checker's get_installed_plugins method.
  68. *
  69. * @deprecated 12.3
  70. * @codeCoverageIgnore
  71. *
  72. * @return array Array containing all the installed plugins.
  73. */
  74. public function get_installed_plugins() {
  75. _deprecated_function( __METHOD__, '12.3' );
  76. return $this->installed_plugins;
  77. }
  78. /**
  79. * Creates a list of installed plugins and whether or not they are compatible.
  80. *
  81. * @deprecated 12.3
  82. * @codeCoverageIgnore
  83. *
  84. * @return array Array containing the installed plugins and compatibility.
  85. */
  86. public function get_installed_plugins_compatibility() {
  87. _deprecated_function( __METHOD__, '12.3' );
  88. foreach ( $this->installed_plugins as $key => $plugin ) {
  89. $this->installed_plugins[ $key ]['compatible'] = $this->is_compatible( $key );
  90. }
  91. return $this->installed_plugins;
  92. }
  93. /**
  94. * Checks whether or not a plugin is compatible.
  95. *
  96. * @deprecated 12.3
  97. * @codeCoverageIgnore
  98. *
  99. * @param string $plugin The plugin to look for and match.
  100. *
  101. * @return bool Whether or not the plugin is compatible.
  102. */
  103. public function is_compatible( $plugin ) {
  104. _deprecated_function( __METHOD__, '12.3' );
  105. $plugin = $this->availability_checker->get_plugin( $plugin );
  106. // If we are not syncing versions, we are always compatible.
  107. if ( ! isset( $plugin['version_sync'] ) || $plugin['version_sync'] !== true ) {
  108. return true;
  109. }
  110. $plugin_version = $this->availability_checker->get_version( $plugin );
  111. return $this->get_major_minor_version( $plugin_version ) === $this->current_wpseo_version;
  112. }
  113. /**
  114. * Gets the major/minor version of the plugin for easier comparing.
  115. *
  116. * @deprecated 12.3
  117. * @codeCoverageIgnore
  118. *
  119. * @param string $version The version to trim.
  120. *
  121. * @return string The major/minor version of the plugin.
  122. */
  123. protected function get_major_minor_version( $version ) {
  124. _deprecated_function( __METHOD__, '12.3' );
  125. return substr( $version, 0, 3 );
  126. }
  127. }