WPSEO_Plugin_Compatibility

Class WPSEO_Plugin_Compatibility.

Defined (1)

The class is defined in the following location(s).

/admin/class-plugin-compatibility.php  
  1. class WPSEO_Plugin_Compatibility { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. protected $current_wpseo_version; 
  7.  
  8. /** 
  9. * @var WPSEO_Plugin_Availability 
  10. */ 
  11. protected $availability_checker; 
  12.  
  13. /** 
  14. * @var array 
  15. */ 
  16. protected $installed_plugins; 
  17.  
  18. /** 
  19. * WPSEO_Plugin_Compatibility constructor. 
  20. * @param string $version The version to check against. 
  21. * @param null|class $availability_checker The checker to use. 
  22. */ 
  23. public function __construct( $version, $availability_checker = null ) { 
  24. // We trim off the patch version, as this shouldn't break the comparison. 
  25. $this->current_wpseo_version = $this->get_major_minor_version( $version ); 
  26. $this->availability_checker = $this->retrieve_availability_checker( $availability_checker ); 
  27. $this->installed_plugins = $this->availability_checker->get_installed_plugins(); 
  28.  
  29. /** 
  30. * Retrieves the availability checker. 
  31. * @param null|object $checker The checker to set. 
  32. * @return WPSEO_Plugin_Availability The checker to use. 
  33. */ 
  34. private function retrieve_availability_checker( $checker ) { 
  35. if ( is_null( $checker ) || ! is_object( $checker ) ) { 
  36. return new WPSEO_Plugin_Availability(); 
  37.  
  38. return $checker; 
  39.  
  40. /** 
  41. * Wraps the availability checker's get_installed_plugins method. 
  42. * @return array Array containing all the installed plugins. 
  43. */ 
  44. public function get_installed_plugins() { 
  45. return $this->installed_plugins; 
  46.  
  47. /** 
  48. * Creates a list of installed plugins and whether or not they are compatible. 
  49. * @return array Array containing the installed plugins and compatibility. 
  50. */ 
  51. public function get_installed_plugins_compatibility() { 
  52. foreach ( $this->installed_plugins as $key => $plugin ) { 
  53.  
  54. $this->installed_plugins[ $key ]['compatible'] = $this->is_compatible( $key ); 
  55.  
  56. return $this->installed_plugins; 
  57.  
  58. /** 
  59. * Checks whether or not a plugin is compatible. 
  60. * @param string $plugin The plugin to look for and match. 
  61. * @return bool Whether or not the plugin is compatible. 
  62. */ 
  63. public function is_compatible( $plugin ) { 
  64. $plugin = $this->availability_checker->get_plugin( $plugin ); 
  65. $plugin_version = $this->availability_checker->get_version( $plugin ); 
  66.  
  67. return $this->get_major_minor_version( $plugin_version ) === $this->current_wpseo_version; 
  68.  
  69. /** 
  70. * Gets the major/minor version of the plugin for easier comparing. 
  71. * @param string $version The version to trim. 
  72. * @return string The major/minor version of the plugin. 
  73. */ 
  74. protected function get_major_minor_version( $version ) { 
  75. return substr( $version, 0, 3 );