EmailLogAddon::load()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 18
ccs 0
cts 7
cp 0
crap 20
rs 9.9332
1
<?php namespace EmailLog\Addon;
2
3
use EmailLog\Core\Loadie;
4
5
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
6
7
/**
8
 * Base Email Log Addon.
9
 *
10
 * @since 2.0.0
11
 */
12
abstract class EmailLogAddon implements Loadie {
13
14
	protected $addon_file;
15
	protected $addon_name    = '';
16
	protected $addon_version = '';
17
	protected $addon_author  = 'Sudar Muthu';
18
19
	/**
20
	 * Addon Updater.
21
	 *
22
	 * @var \EmailLog\Addon\AddonUpdater
23
	 */
24
	private $updater;
25
26
	/**
27
	 * Initialize add-on data.
28
	 *
29
	 * @access protected
30
	 *
31
	 * @return void
32
	 */
33
	abstract protected function initialize();
34
35
	/**
36
	 * Construct a new EmailLogAddon instance.
37
	 *
38
	 * @param string                            $addon_file Addon main file.
39
	 * @param \EmailLog\Addon\AddonUpdater|null $updater    Addon Updater.
40
	 */
41
	public function __construct( $addon_file, $updater = null ) {
42
		$this->addon_file = $addon_file;
43
		$this->updater    = $updater;
44
45
		$this->initialize();
46
	}
47
48
	/**
49
	 * Load the add-on and setup hooks.
50
	 */
51
	public function load() {
52
		if ( \EmailLog\Util\is_admin_non_ajax_request() ) {
53
			$email_log = email_log();
54
55
			if ( ! $email_log->is_plugin_api_overridden() ) {
56
				$override_plugin_api = new \EmailLog\Core\Request\OverridePluginAPI();
57
				$override_plugin_api->load();
58
59
				$email_log->plugin_api_overridden();
60
			}
61
		}
62
63
		if ( is_null( $this->updater ) ) {
64
			return;
65
		}
66
67
		$this->updater->set_addon_data( $this->addon_name, $this->addon_version, $this->addon_author );
68
		$this->updater->load();
69
	}
70
}
71