]> _ Git - couzy.git/blob
91ea40b27615ba46c51924acb4b24fc771eb680f
[couzy.git] /
1 <?php
2
3 //set_site_transient( 'update_plugins', null );
4
5 if( class_exists( 'Yoast_Update_Manager' ) && ! class_exists( "Yoast_Plugin_Update_Manager", false ) ) {
6
7         class Yoast_Plugin_Update_Manager extends Yoast_Update_Manager {
8
9                 /**
10                 * Constructor
11                 *
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 
19                 */
20                 public function __construct( Yoast_Product $product, $license_key ) {
21                         parent::__construct( $product, $license_key );
22
23                         // setup hooks
24                         $this->setup_hooks();
25
26                 }
27
28                 /**
29                 * Setup hooks
30                 */
31                 private function setup_hooks() {
32
33                         // check for updates
34                         add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'set_updates_available_data' ) );
35                         
36                         // get correct plugin information (when viewing details)
37                         add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
38                 }
39
40                 /**
41                 * Check for updates and if so, add to "updates available" data
42                 *
43                 * @param object $data
44                 * @return object $data
45                 */
46                 public function set_updates_available_data( $data ) {
47
48                         if ( empty( $data ) ) {
49                                 return $data;
50                         }
51
52                         // send of API request to check for updates
53                         $remote_data = $this->get_remote_data();
54
55                         // did we get a response?
56                         if( $remote_data === false ) {
57                                 return $data;
58                         }
59
60                         // compare local version with remote version
61                         if ( version_compare( $this->product->get_version(), $remote_data->new_version, '<' ) ) {
62
63                                 // remote version is newer, add to data
64                                 $data->response[ $this->product->get_slug() ] = $remote_data;
65
66                         }
67
68                         return $data;
69                 }
70
71                 /**
72                  * Gets new plugin version details (view version x.x.x details)
73                  *
74                  * @uses api_request()
75                  *
76                  * @param object $data
77                  * @param string $action
78                  * @param object $args (optional)
79                  *
80                  * @return object $data
81                  */
82                 public function plugins_api_filter( $data, $action = '', $args = null ) {
83
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() ) {
86                                 return $data;
87                         }
88
89                         $api_response = $this->get_remote_data();
90                         
91                         // did we get a response?
92                         if ( $api_response === false ) {
93                                 return $data;   
94                         }
95
96                         // return api response
97                         return $api_response;
98                 }
99
100         }
101
102 }