MI_Theme_Update_Manager

The Google Analytics by MonsterInsights MI Theme Update Manager class.

Defined (1)

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

/vendor/yoast/license-manager/class-theme-update-manager.php  
  1. class MI_Theme_Update_Manager extends MI_Update_Manager { 
  2.  
  3. /** 
  4. * Constructor 
  5. * @param MI_Product $product The Product. 
  6. * @param string $license_key The License key. 
  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. * Get the current theme version 
  16. * @return string The version number 
  17. */ 
  18. private function get_theme_version() { 
  19.  
  20. // if version was not set, get it from the Theme stylesheet 
  21. if ( $this->product->get_version() === '' ) { 
  22. $theme = wp_get_theme( $this->product->get_slug() ); 
  23.  
  24. return $theme->get( 'Version' ); 
  25.  
  26. return $this->product->get_version(); 
  27.  
  28. /** 
  29. * Setup hooks 
  30. */ 
  31. private function setup_hooks() { 
  32. add_filter( 'site_transient_update_themes', array( $this, 'set_theme_update_transient' ) ); 
  33. add_action( 'load-themes.php', array( $this, 'load_themes_screen' ) ); 
  34.  
  35. /** 
  36. * Set "updates available" transient 
  37. */ 
  38. public function set_theme_update_transient( $value ) { 
  39.  
  40. $update_data = $this->get_update_data(); 
  41.  
  42. if ( $update_data === false ) { 
  43. return $value; 
  44.  
  45. // add update data to "updates available" array. convert object to array. 
  46. $value->response[ $this->product->get_slug() ] = (array) $update_data; 
  47.  
  48. return $value; 
  49.  
  50. /** 
  51. * Add hooks and scripts to the Appearance > Themes screen 
  52. */ 
  53. public function load_themes_screen() { 
  54.  
  55. $update_data = $this->get_update_data(); 
  56.  
  57. // only do if an update is available 
  58. if ( $update_data === false ) { 
  59. return; 
  60.  
  61. add_thickbox(); 
  62. add_action( 'admin_notices', array( $this, 'show_update_details' ) ); 
  63.  
  64. /** 
  65. * Show update link. 
  66. * Opens Thickbox with Changelog. 
  67. */ 
  68. public function show_update_details() { 
  69.  
  70. $update_data = $this->get_update_data(); 
  71.  
  72. // only show if an update is available 
  73. if ( $update_data === false ) { 
  74. return; 
  75.  
  76. $update_url = wp_nonce_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $this->product->get_slug() ), 'upgrade-theme_' . $this->product->get_slug() ); 
  77. $update_onclick = ' onclick="if ( confirm(\'' . esc_js( __( "Updating this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to update." ) ) . '\') ) {return true;}return false;"'; 
  78. ?> 
  79. <div id="update-nag"> 
  80. <?php 
  81. printf( 
  82. __( '<strong>%s version %s</strong> is available. <a href="%s" class="thickbox" title="%s">Check out what\'s new</a> or <a href="%s" %s>update now</a>.' ),  
  83. $this->product->get_item_name(),  
  84. $update_data->new_version,  
  85. '#TB_inline?width=640&inlineId=' . $this->product->get_slug() . '_changelog',  
  86. $this->get_item_name(),  
  87. $update_url,  
  88. $update_onclick 
  89. ); 
  90. ?> 
  91. </div> 
  92. <div id="<?php echo $this->product->get_slug(); ?>_changelog" style="display: none;"> 
  93. <?php echo wpautop( $update_data->sections['changelog'] ); ?> 
  94. </div> 
  95. <?php 
  96.  
  97. /** 
  98. * Get update data 
  99. * This gets the update data from a transient (12 hours), if set. 
  100. * If not, it will make a remote request and get the update data. 
  101. * @return object $update_data Object containing the update data 
  102. */ 
  103. public function get_update_data() { 
  104.  
  105. $api_response = $this->get_remote_data(); 
  106.  
  107. if ( false === $api_response ) { 
  108. return false; 
  109.  
  110. $update_data = $api_response; 
  111.  
  112. // check if a new version is available.  
  113. if ( version_compare( $this->get_theme_version(), $update_data->new_version, '>=' ) ) { 
  114. return false; 
  115.  
  116. // an update is available 
  117. return $update_data;