Passed
Pull Request — master (#357)
by Stiofan
13:41
created

EmailLog::init_actions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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