3 //set_site_transient( 'update_plugins', null );
5 if( class_exists( 'Yoast_Update_Manager' ) && ! class_exists( "Yoast_Plugin_Update_Manager", false ) ) {
7 class Yoast_Plugin_Update_Manager extends Yoast_Update_Manager {
12 * @param string $api_url
13 * @param string $item_name
14 * @param string $license_key
15 * @param string $slug The path to the main plugin file, relative to plugins dir
16 * @param string $version
17 * @param string $author (optional)
18 * @param string $text_domain
20 public function __construct( Yoast_Product $product, $license_key ) {
21 parent::__construct( $product, $license_key );
31 private function setup_hooks() {
34 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'set_updates_available_data' ) );
36 // get correct plugin information (when viewing details)
37 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
41 * Check for updates and if so, add to "updates available" data
44 * @return object $data
46 public function set_updates_available_data( $data ) {
48 if ( empty( $data ) ) {
52 // send of API request to check for updates
53 $remote_data = $this->get_remote_data();
55 // did we get a response?
56 if( $remote_data === false ) {
60 // compare local version with remote version
61 if ( version_compare( $this->product->get_version(), $remote_data->new_version, '<' ) ) {
63 // remote version is newer, add to data
64 $data->response[ $this->product->get_slug() ] = $remote_data;
72 * Gets new plugin version details (view version x.x.x details)
77 * @param string $action
78 * @param object $args (optional)
80 * @return object $data
82 public function plugins_api_filter( $data, $action = '', $args = null ) {
84 // only do something if we're checking for our plugin
85 if ( $action !== 'plugin_information' || ! isset( $args->slug ) || $args->slug !== $this->product->get_slug() ) {
89 $api_response = $this->get_remote_data();
91 // did we get a response?
92 if ( $api_response === false ) {
96 // return api response