MI_Plugin_Update_Manager

The Google Analytics by MonsterInsights MI Plugin Update Manager class.

Defined (1)

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

/vendor/yoast/license-manager/class-plugin-update-manager.php  
  1. class MI_Plugin_Update_Manager extends MI_Update_Manager { 
  2.  
  3. /** 
  4. * Constructor 
  5. * @param MI_Product $product The Product. 
  6. * @param string $license_key The License entered. 
  7. */ 
  8. public function __construct( MI_Product $product, $license_key ) { 
  9. parent::__construct( $product, $license_key ); 
  10.  
  11. // setup hooks 
  12. $this->setup_hooks(); 
  13.  
  14. /** 
  15. * Setup hooks 
  16. */ 
  17. private function setup_hooks() { 
  18.  
  19. // check for updates 
  20. add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'set_updates_available_data' ) ); 
  21.  
  22. // get correct plugin information (when viewing details) 
  23. add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); 
  24.  
  25. /** 
  26. * Check for updates and if so, add to "updates available" data 
  27. * @param object $data 
  28. * @return object $data 
  29. */ 
  30. public function set_updates_available_data( $data ) { 
  31.  
  32. if ( empty( $data ) ) { 
  33. return $data; 
  34.  
  35. // send of API request to check for updates 
  36. $remote_data = $this->get_remote_data(); 
  37.  
  38. // did we get a response? 
  39. if( $remote_data === false ) { 
  40. return $data; 
  41.  
  42. // compare local version with remote version 
  43. if ( version_compare( $this->product->get_version(), $remote_data->new_version, '<' ) ) { 
  44.  
  45. // remote version is newer, add to data 
  46. $data->response[ $this->product->get_file() ] = $remote_data; 
  47.  
  48.  
  49. return $data; 
  50.  
  51. /** 
  52. * Gets new plugin version details (view version x.x.x details) 
  53. * @uses api_request() 
  54. * @param object $data 
  55. * @param string $action 
  56. * @param object $args (optional) 
  57. * @return object $data 
  58. */ 
  59. public function plugins_api_filter( $data, $action = '', $args = null ) { 
  60.  
  61. // only do something if we're checking for our plugin 
  62. if ( $action !== 'plugin_information' || ! isset( $args->slug ) || $args->slug !== $this->product->get_slug() ) { 
  63. return $data; 
  64.  
  65. $api_response = $this->get_remote_data(); 
  66.  
  67. // did we get a response? 
  68. if ( $api_response === false ) { 
  69. return $data;  
  70.  
  71. // return api response 
  72. return $api_response;