Completed
Push — master ( f42369...8f9e2d )
by Sudar
14:23
created

AddonLicenseHandler::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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