1
|
|
|
<?php namespace EmailLog\Addon\API; |
2
|
|
|
|
3
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
4
|
|
|
|
5
|
|
|
if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
6
|
|
|
$email_log = email_log(); |
7
|
|
|
require_once $email_log->get_plugin_path() . 'include/libraries/EDD_SL_Plugin_Updater.php'; |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Update add-on using EDD API. |
12
|
|
|
* |
13
|
|
|
* @since 2.0.0 |
14
|
|
|
*/ |
15
|
|
|
class EDDUpdater extends \EDD_SL_Plugin_Updater { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Add-on slug. |
19
|
|
|
* The base class already has a slug property but it is private. |
20
|
|
|
* So we have to create a duplicate to handle that. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $addon_slug; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Extract add-on slug alone and then pass everything to parent. |
28
|
|
|
* |
29
|
|
|
* @param string $_api_url The URL pointing to the custom API endpoint. |
30
|
|
|
* @param string $_plugin_file Path to the plugin file. |
31
|
|
|
* @param array|null $_api_data Optional data to send with API calls. |
32
|
|
|
*/ |
33
|
|
|
public function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
34
|
|
|
$this->addon_slug = basename( $_plugin_file, '.php' ); |
35
|
|
|
|
36
|
|
|
parent::__construct( $_api_url, $_plugin_file, $_api_data ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Overridden to disable `check_update` on the add-ons that are not installed. |
41
|
|
|
* |
42
|
|
|
* @inheritdoc |
43
|
|
|
* |
44
|
|
|
* @since 2.2.0 |
45
|
|
|
*/ |
46
|
|
|
public function init() { |
47
|
|
|
parent::init(); |
48
|
|
|
|
49
|
|
|
$installed_plugins = array_keys( get_plugins() ); |
50
|
|
|
|
51
|
|
|
if ( in_array( $this->addon_slug, $installed_plugins, true ) ) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Get add-on slug. |
60
|
|
|
* |
61
|
|
|
* @return string Add-on slug. |
62
|
|
|
*/ |
63
|
|
|
public function get_slug() { |
64
|
|
|
return $this->addon_slug; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get Download URL. |
69
|
|
|
* We can't call `api_request` method directly since it is declared as private in parent class. |
70
|
|
|
* So we call the `plugins_api_filter` method instead. |
71
|
|
|
* |
72
|
|
|
* @return string Download url. |
73
|
|
|
*/ |
74
|
|
|
public function get_download_url() { |
75
|
|
|
$args = new \stdClass(); |
76
|
|
|
$args->slug = $this->addon_slug; |
77
|
|
|
|
78
|
|
|
$response = $this->plugins_api_filter( null, 'plugin_information', $args ); |
79
|
|
|
|
80
|
|
|
if ( ! $response instanceof \stdClass || ! property_exists( $response, 'package' ) ) { |
81
|
|
|
return ''; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $response->package; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|