3 if( class_exists( 'Yoast_Update_Manager' ) && ! class_exists( "Yoast_Theme_Update_Manager", false ) ) {
5 class Yoast_Theme_Update_Manager extends Yoast_Update_Manager {
10 * @param string $api_url
11 * @param string $item_name
12 * @param string $license_key
14 * @param string $theme_version
15 * @param string $author (optional)
17 public function __construct( Yoast_Product $product, $license_key ) {
19 parent::__construct( $product, $license_key );
26 * Get the current theme version
28 * @return string The version number
30 private function get_theme_version() {
32 // if version was not set, get it from the Theme stylesheet
33 if( $this->product->get_version() === '' ) {
34 $theme = wp_get_theme( $this->product->get_slug() );
35 return $theme->get( 'Version' );
38 return $this->product->get_version();
44 private function setup_hooks() {
45 add_filter( 'site_transient_update_themes', array( $this, 'set_theme_update_transient' ) );
46 add_action( 'load-themes.php', array( $this, 'load_themes_screen' ) );
50 * Set "updates available" transient
52 public function set_theme_update_transient( $value ) {
54 $update_data = $this->get_update_data();
56 if( $update_data === false ) {
60 // add update data to "updates available" array. convert object to array.
61 $value->response[ $this->product->get_slug() ] = (array) $update_data;
67 * Add hooks and scripts to the Appearance > Themes screen
69 public function load_themes_screen() {
71 $update_data = $this->get_update_data();
73 // only do if an update is available
74 if( $update_data === false ) {
79 add_action( 'admin_notices', array( $this, 'show_update_details' ) );
84 * Opens Thickbox with Changelog.
86 public function show_update_details() {
88 $update_data = $this->get_update_data();
90 // only show if an update is available
91 if( $update_data === false ) {
95 $update_url = wp_nonce_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $this->product->get_slug() ), 'upgrade-theme_' . $this->product->get_slug() );
96 $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;"';
101 __( '<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>.' ),
102 $this->product->get_item_name(),
103 $update_data->new_version,
104 '#TB_inline?width=640&inlineId=' . $this->product->get_slug() . '_changelog',
105 $this->get_item_name(),
111 <div id="<?php echo $this->product->get_slug(); ?>_changelog" style="display: none;">
112 <?php echo wpautop( $update_data->sections['changelog'] ); ?>
121 * This gets the update data from a transient (12 hours), if set.
122 * If not, it will make a remote request and get the update data.
124 * @return object $update_data Object containing the update data
126 public function get_update_data() {
128 $api_response = $this->get_remote_data();
130 if( false === $api_response ) {
134 $update_data = $api_response;
136 // check if a new version is available.
137 if ( version_compare( $this->get_theme_version(), $update_data->new_version, '>=' ) ) {
142 // an update is available