| 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 |
* Get add-on slug. |
| 41 |
* |
| 42 |
* @return string Add-on slug. |
| 43 |
*/ |
| 44 |
public function get_slug() { |
| 45 |
return $this->addon_slug; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get Download URL. |
| 50 |
* We can't call `api_request` method directly since it is declared as private in parent class. |
| 51 |
* So we call the `plugins_api_filter` method instead. |
| 52 |
* |
| 53 |
* @return string Download url. |
| 54 |
*/ |
| 55 |
public function get_download_url() { |
| 56 |
$args = new \stdClass(); |
| 57 |
$args->slug = $this->addon_slug; |
| 58 |
|
| 59 |
$response = $this->plugins_api_filter( null, 'plugin_information', $args ); |
| 60 |
|
| 61 |
if ( ! $response instanceof \stdClass || ! property_exists( $response, 'package' ) ) { |
| 62 |
return ''; |
| 63 |
} |
| 64 |
|
| 65 |
return $response->package; |
| 66 |
} |
| 67 |
} |
| 68 |
|