Passed
Pull Request — master (#356)
by
unknown
13:27
created

EmailLog::load_textdomain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
ccs 1
cts 1
cp 1
crap 2
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
	 *
18
	 * @var string
19
	 */
20
	const VERSION = '2.4.9';
21
22
	/**
23
	 * Email Log Store URL.
24
	 */
25
	const STORE_URL = 'https://wpemaillog.com';
26
27
	/**
28
	 * Flag to track if the plugin is loaded.
29
	 *
30
	 * @since 2.0
31
	 *
32
	 * @access private
33
	 *
34
	 * @var bool
35
	 */
36
	private $loaded = false;
37
38
	/**
39
	 * Flag to override plugin API.
40
	 *
41
	 * @since 2.4.5
42
	 *
43
	 * @access private
44
	 *
45
	 * @var bool
46
	 */
47
	private $plugins_api_overridden = false;
48
49
	/**
50
	 * Plugin file path.
51
	 *
52
	 * @since 2.0
53
	 *
54
	 * @access private
55
	 *
56
	 * @var string
57
	 */
58
	private $plugin_file;
59
60
	/**
61
	 * Filesystem directory path where translations are stored.
62
	 *
63
	 * @since 2.0
64
	 *
65
	 * @var string
66
	 */
67
	public $translations_path;
68
69
	/**
70
	 * Auto loader.
71
	 *
72
	 * @var \EmailLog\EmailLogAutoloader
73
	 */
74
	public $loader;
75
76
	/**
77
	 * Database Table Manager.
78
	 *
79
	 * @since 2.0
80
	 *
81
	 * @var \EmailLog\Core\DB\TableManager
82
	 */
83
	public $table_manager;
84
85
	/**
86
	 * Add-on Licenser.
87
	 * For non-admin requests it will not be set.
88
	 *
89
	 * @since 2.0
90
	 *
91
	 * @var \EmailLog\Addon\License\Licenser
92
	 */
93
	private $licenser = null;
94
95
	/**
96 1
	 * List of loadies.
97 1
	 *
98 1
	 * @var Loadie[]
99 1
	 */
100
	private $loadies = array();
101 1
102
	/**
103 1
	 * Initialize the plugin.
104 1
	 *
105
	 * @param string             $file          Plugin file.
106
	 * @param EmailLogAutoloader $loader        EmailLog Autoloader.
107
	 * @param TableManager       $table_manager Table Manager.
108
	 */
109
	public function __construct( $file, $loader, $table_manager ) {
110
		$this->plugin_file   = $file;
111
		$this->loader        = $loader;
112
		$this->table_manager = $table_manager;
113
114
		$this->add_loadie( $table_manager );
115
116
		$this->translations_path = dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' ;
117
	}
118
119
	/**
120
	 * Set Licenser.
121
	 *
122
	 * @param \EmailLog\Addon\License\Licenser $licenser Add-on Licenser.
123
	 */
124
	public function set_licenser( $licenser ) {
125
		if ( $this->add_loadie( $licenser ) ) {
126
			$this->licenser = $licenser;
127
		}
128
	}
129
130
	/**
131
	 * Get Licenser.
132
	 *
133
	 * @return \EmailLog\Addon\License\Licenser|null
134 1
	 */
135 1
	public function get_licenser() {
136
		return $this->licenser;
137
	}
138
139 1
	/**
140
	 * Add an Email Log Loadie.
141
	 * The `load()` method of the Loadies will be called when Email Log is loaded.
142
	 *
143 1
	 * @param \EmailLog\Core\Loadie $loadie Loadie to be loaded.
144
	 *
145 1
	 * @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise.
146
	 */
147
	public function add_loadie( $loadie ) {
148
		if ( $this->loaded ) {
149
			return false;
150
		}
151 1
152 1
		if ( ! $loadie instanceof Loadie ) {
0 ignored issues
show
introduced by
$loadie is always a sub-type of EmailLog\Core\Loadie.
Loading history...
153
			return false;
154
		}
155
156 1
		$this->loadies[] = $loadie;
157
158 1
		return true;
159
	}
160 1
161 1
	/**
162
	 * Load Textdomain.
163
	 */
164 1
	public function load_textdomain() {
165
		if ( $this->loaded ) {
166
			return;
167
		}
168
169
		load_plugin_textdomain( 'email-log', false, $this->translations_path );
170
	}
171 1
172 1
	/**
173
	 * Load the plugin.
174
	 */
175
	public function load() {
176
		if ( $this->loaded ) {
177
			return;
178
		}
179
180
		$this->table_manager->load();
181
182
		foreach ( $this->loadies as $loadie ) {
183
			$loadie->load();
184
		}
185
186
		$this->loaded = true;
187
188
		/**
189
		 * Email Log plugin loaded.
190
		 *
191
		 * @since 2.0
192
		 */
193
		do_action( 'el_loaded' );
194
	}
195
196
	/**
197
	 * Plugin API has been overridden.
198
	 *
199
	 * @since 2.4.5
200
	 */
201
	public function plugin_api_overridden() {
202
		$this->plugins_api_overridden = true;
203
	}
204
205
	/**
206
	 * Has the plugin API have been overridden?
207
	 *
208
	 * @since 2.4.5
209
	 *
210
	 * @return bool True if overridden, False otherwise.
211
	 */
212
	public function is_plugin_api_overridden() {
213
		return $this->plugins_api_overridden;
214
	}
215
216
	/**
217
	 * Return Email Log version.
218
	 *
219
	 * @return string Email Log Version.
220
	 */
221
	public function get_version() {
222
		return self::VERSION;
223
	}
224
225
	/**
226
	 * Return the Email Log plugin directory path.
227
	 *
228
	 * @return string Plugin directory path.
229
	 */
230
	public function get_plugin_path() {
231
		return plugin_dir_path( $this->plugin_file );
232
	}
233
234
	/**
235
	 * Return the Email Log plugin file.
236
	 *
237
	 * @since 2.0.0
238
	 *
239
	 * @return string Plugin directory path.
240
	 */
241
	public function get_plugin_file() {
242
		return $this->plugin_file;
243
	}
244
245
	/**
246
	 * Get Email Log Store URL.
247
	 *
248
	 * @since 2.0.0
249
	 *
250
	 * @return string Store URL
251
	 */
252
	public function get_store_url() {
253
		return self::STORE_URL;
254
	}
255
}
256