| 1 |
<?php namespace EmailLog\Addon; |
| 2 |
|
| 3 |
use EmailLog\Addon\API\EDDUpdater; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 6 |
|
| 7 |
/** |
| 8 |
* Add-on Updater. |
| 9 |
* Auto updates add-on based on EDD SL API. |
| 10 |
* |
| 11 |
* @since 2.0.0 |
| 12 |
*/ |
| 13 |
class AddonUpdater { |
| 14 |
|
| 15 |
private $addon_file; |
| 16 |
private $addon_name; |
| 17 |
private $addon_version; |
| 18 |
private $addon_author; |
| 19 |
|
| 20 |
/** |
| 21 |
* Create a new instance of AddonUpdater. |
| 22 |
* |
| 23 |
* @param string $addon_file Add-on main file. |
| 24 |
*/ |
| 25 |
public function __construct( $addon_file ) { |
| 26 |
$this->addon_file = $addon_file; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Set Add-on data. |
| 31 |
* |
| 32 |
* @param string $addon_name Add-on Name. |
| 33 |
* @param string $addon_version Add-on Version. |
| 34 |
* @param string $addon_author Add-on Author. |
| 35 |
*/ |
| 36 |
public function set_addon_data( $addon_name, $addon_version, $addon_author ) { |
| 37 |
$this->addon_name = $addon_name; |
| 38 |
$this->addon_version = $addon_version; |
| 39 |
$this->addon_author = $addon_author; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Set up hooks and load the license handler. |
| 44 |
* This method is called on `wp-loaded` hook. |
| 45 |
*/ |
| 46 |
public function load() { |
| 47 |
add_action( 'admin_init', array( $this, 'setup_updater' ) ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Setup up Add-on auto-updater using EDD library. |
| 52 |
*/ |
| 53 |
public function setup_updater() { |
| 54 |
$email_log = email_log(); |
| 55 |
$licenser = $email_log->get_licenser(); |
| 56 |
|
| 57 |
if ( is_null( $licenser ) ) { |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
$license_key = $licenser->get_addon_license_key( $this->addon_name ); |
| 62 |
|
| 63 |
$updater = new EDDUpdater( $email_log->get_store_url(), $this->addon_file, array( |
| 64 |
'version' => $this->addon_version, |
| 65 |
'license' => $license_key, |
| 66 |
'item_name' => $this->addon_name, |
| 67 |
'author' => $this->addon_author, |
| 68 |
) |
| 69 |
); |
| 70 |
|
| 71 |
$licenser->add_updater( $updater ); |
| 72 |
} |
| 73 |
} |
| 74 |
|