Yoast_Theme_Update_Manager

The Google Analytics by Yoast Yoast 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 Yoast_Theme_Update_Manager extends Yoast_Update_Manager { 
  2.  
  3. /** 
  4. * Constructor 
  5. * @param string $api_url 
  6. * @param string $item_name 
  7. * @param string $license_key 
  8. * @param string $slug 
  9. * @param string $theme_version 
  10. * @param string $author (optional) 
  11. */ 
  12. public function __construct( Yoast_Product $product, $license_key ) { 
  13.  
  14. parent::__construct( $product, $license_key ); 
  15.  
  16. // setup hooks 
  17. $this->setup_hooks(); 
  18.  
  19. /** 
  20. * Get the current theme version 
  21. * @return string The version number 
  22. */ 
  23. private function get_theme_version() { 
  24.  
  25. // if version was not set, get it from the Theme stylesheet 
  26. if( $this->product->get_version() === '' ) { 
  27. $theme = wp_get_theme( $this->product->get_slug() ); 
  28. return $theme->get( 'Version' ); 
  29.  
  30. return $this->product->get_version(); 
  31.  
  32. /** 
  33. * Setup hooks 
  34. */ 
  35. private function setup_hooks() { 
  36. add_filter( 'site_transient_update_themes', array( $this, 'set_theme_update_transient' ) ); 
  37. add_action( 'load-themes.php', array( $this, 'load_themes_screen' ) ); 
  38.  
  39. /** 
  40. * Set "updates available" transient 
  41. */ 
  42. public function set_theme_update_transient( $value ) { 
  43.  
  44. $update_data = $this->get_update_data(); 
  45.  
  46. if( $update_data === false ) { 
  47. return $value; 
  48.  
  49. // add update data to "updates available" array. convert object to array. 
  50. $value->response[ $this->product->get_slug() ] = (array) $update_data; 
  51.  
  52. return $value; 
  53.  
  54. /** 
  55. * Add hooks and scripts to the Appearance > Themes screen 
  56. */ 
  57. public function load_themes_screen() { 
  58.  
  59. $update_data = $this->get_update_data(); 
  60.  
  61. // only do if an update is available 
  62. if( $update_data === false ) { 
  63. return; 
  64.  
  65. add_thickbox(); 
  66. add_action( 'admin_notices', array( $this, 'show_update_details' ) ); 
  67.  
  68. /** 
  69. * Show update link.  
  70. * Opens Thickbox with Changelog. 
  71. */ 
  72. public function show_update_details() { 
  73.  
  74. $update_data = $this->get_update_data(); 
  75.  
  76. // only show if an update is available 
  77. if( $update_data === false ) { 
  78. return; 
  79.  
  80. $update_url = wp_nonce_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $this->product->get_slug() ), 'upgrade-theme_' . $this->product->get_slug() ); 
  81. $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;"'; 
  82. ?> 
  83. <div id="update-nag"> 
  84. <?php 
  85. printf(  
  86. __( '<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>.' ),  
  87. $this->product->get_item_name(),  
  88. $update_data->new_version,  
  89. '#TB_inline?width=640&inlineId=' . $this->product->get_slug() . '_changelog',  
  90. $this->get_item_name(),  
  91. $update_url,  
  92. $update_onclick 
  93. ); 
  94. ?> 
  95. </div> 
  96. <div id="<?php echo $this->product->get_slug(); ?>_changelog" style="display: none;"> 
  97. <?php echo wpautop( $update_data->sections['changelog'] ); ?> 
  98. </div>  
  99. <?php 
  100.  
  101.  
  102. /** 
  103. * Get update data 
  104. * This gets the update data from a transient (12 hours), if set. 
  105. * If not, it will make a remote request and get the update data. 
  106. * @return object $update_data Object containing the update data 
  107. */ 
  108. public function get_update_data() { 
  109.  
  110. $api_response = $this->get_remote_data(); 
  111.  
  112. if( false === $api_response ) { 
  113. return false; 
  114.  
  115. $update_data = $api_response; 
  116.  
  117. // check if a new version is available.  
  118. if ( version_compare( $this->get_theme_version(), $update_data->new_version, '>=' ) ) { 
  119. return false; 
  120.  
  121.  
  122. // an update is available 
  123. return $update_data; 
  124.  
  125.