Completed
Push — master ( 186893...053e09 )
by Sudar
02:09
created

EmailLog::load()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 22
ccs 0
cts 0
cp 0
crap 12
rs 9.2
c 1
b 0
f 0
1
<?php namespace EmailLog\Core;
2
3
use EmailLog\Core\DB\TableManager;
4
use EmailLog\EmailLogAutoloader;
5
6
/**
7
 * The main plugin class.
8
 *
9
 * @since Genesis
10
 */
11
class EmailLog {
12
13
	/**
14
	 * Plugin Version number.
15
	 *
16
	 * @since Genesis
17
	 * @var string
18
	 */
19
	const VERSION = '2.0.0';
20
21
	/**
22
	 * Email Log Store URL.
23
	 */
24
	const STORE_URL = 'https://wpemaillog.com';
25
26
	/**
27
	 * Flag to track if the plugin is loaded.
28
	 *
29
	 * @since 2.0
30
	 * @access private
31
	 * @var bool
32
	 */
33
	private $loaded = false;
34
35
	/**
36
	 * Plugin file path.
37
	 *
38
	 * @since 2.0
39
	 * @access private
40
	 * @var string
41
	 */
42
	private $plugin_file;
43
44
	/**
45
	 * Filesystem directory path where translations are stored.
46
	 *
47
	 * @since 2.0
48
	 * @var string
49
	 */
50
	public $translations_path;
51
52
	/**
53
	 * Auto loader.
54
	 *
55
	 * @var \EmailLog\EmailLogAutoloader
56
	 */
57
	public $loader;
58
59
	/**
60
	 * Database Table Manager.
61
	 *
62
	 * @since 2.0
63
	 * @var \EmailLog\Core\DB\TableManager
64
	 */
65
	public $table_manager;
66
67
	/**
68
	 * Add-on Licenser.
69
	 *
70
	 * @since 2.0
71
	 * @var \EmailLog\License\Licenser
72
	 */
73
	private $licenser;
74 2
75 2
	/**
76 2
	 * List of loadies.
77 2
	 *
78
	 * @var Loadie[]
79
	 */
80
	private $loadies = array();
81
82 2
	/**
83 2
	 * Initialize the plugin.
84
	 *
85
	 * @param string             $file          Plugin file.
86
	 * @param EmailLogAutoloader $loader        EmailLog Autoloader.
87 2
	 * @param TableManager       $table_manager Table Manager.
88
	 */
89 2
	public function __construct( $file, $loader, $table_manager ) {
90 2
		$this->plugin_file = $file;
91 2
		$this->loader = $loader;
92
		$this->table_manager = $table_manager;
93 2
94 2
		$this->add_loadie( $table_manager );
95
96
		$this->translations_path = dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' ;
97
	}
98
99
	/**
100
	 * Set Licenser.
101
	 *
102
	 * @param \EmailLog\License\Licenser $licenser Add-on Licenser.
103
	 */
104
	public function set_licenser( $licenser ) {
105
		if ( $this->add_loadie( $licenser ) ) {
106
			$this->licenser = $licenser;
107
		}
108
	}
109
110
	/**
111
	 * Get Licenser.
112
	 *
113
	 * @return \EmailLog\License\Licenser
114
	 */
115
	public function get_licenser() {
116
		return $this->licenser;
117
	}
118
119
	/**
120
	 * Add an Email Log Loadie.
121
	 * The `load()` method of the Loadies will be called when Email Log is loaded.
122
	 *
123
	 * @param \EmailLog\Core\Loadie $loadie Loadie to be loaded.
124
	 *
125
	 * @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise.
126
	 */
127
	public function add_loadie( $loadie ) {
128
		if ( $this->loaded ) {
129
			return false;
130
		}
131
132
		if ( ! $loadie instanceof Loadie ) {
133
			return false;
134
		}
135
136
		$this->loadies[] = $loadie;
137
138
		return true;
139
	}
140
141
	/**
142
	 * Load the plugin.
143
	 */
144
	public function load() {
145
		if ( $this->loaded ) {
146
			return;
147
		}
148
149
		load_plugin_textdomain( 'email-log', false, $this->translations_path );
150
151
		$this->table_manager->load();
152
153
		foreach ( $this->loadies as $loadie ) {
154
			$loadie->load();
155
		}
156
157
		$this->loaded = true;
158
159
		/**
160
		 * Email Log plugin loaded.
161
		 *
162
		 * @since 2.0
163
		 */
164
		do_action( 'el_loaded' );
165
	}
166
167
	/**
168
	 * Return Email Log version.
169
	 *
170
	 * @return string Email Log Version.
171
	 */
172
	public function get_version() {
173
		return self::VERSION;
174
	}
175
176
	/**
177
	 * Return the Email Log plugin directory path.
178
	 *
179
	 * @return string Plugin directory path.
180
	 */
181
	public function get_plugin_path() {
182
		return plugin_dir_path( $this->plugin_file );
183
	}
184
185
	/**
186
	 * Return the Email Log plugin file.
187
	 *
188
	 * @since 2.0.0
189
	 *
190
	 * @return string Plugin directory path.
191
	 */
192
	public function get_plugin_file() {
193
		return $this->plugin_file;
194
	}
195
196
	/**
197
	 * Get Email Log Store URL.
198
	 *
199
	 * @since 2.0.0
200
	 *
201
	 * @return string Store URL
202
	 */
203
	public function get_store_url() {
204
		return self::STORE_URL;
205
	}
206
}
207