Completed
Push — master ( 0b3c82...08da20 )
by Sudar
02:06
created

AddonUpdater::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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