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.4'; |
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 ) { |
|
|
|
|
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
|
|
|
load_plugin_textdomain( 'email-log', false, $this->translations_path ); |
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
|
|
|
* Plugin API has been overridden. |
186
|
|
|
* |
187
|
|
|
* @since 2.4.5 |
188
|
|
|
*/ |
189
|
|
|
public function plugin_api_overridden() { |
190
|
|
|
$this->plugins_api_overridden = true; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Has the plugin API have been overridden? |
195
|
|
|
* |
196
|
|
|
* @since 2.4.5 |
197
|
|
|
* |
198
|
|
|
* @return bool True if overridden, False otherwise. |
199
|
|
|
*/ |
200
|
|
|
public function is_plugin_api_overridden() { |
201
|
|
|
return $this->plugins_api_overridden; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Return Email Log version. |
206
|
|
|
* |
207
|
|
|
* @return string Email Log Version. |
208
|
|
|
*/ |
209
|
|
|
public function get_version() { |
210
|
|
|
return self::VERSION; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Return the Email Log plugin directory path. |
215
|
|
|
* |
216
|
|
|
* @return string Plugin directory path. |
217
|
|
|
*/ |
218
|
|
|
public function get_plugin_path() { |
219
|
|
|
return plugin_dir_path( $this->plugin_file ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Return the Email Log plugin file. |
224
|
|
|
* |
225
|
|
|
* @since 2.0.0 |
226
|
|
|
* |
227
|
|
|
* @return string Plugin directory path. |
228
|
|
|
*/ |
229
|
|
|
public function get_plugin_file() { |
230
|
|
|
return $this->plugin_file; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get Email Log Store URL. |
235
|
|
|
* |
236
|
|
|
* @since 2.0.0 |
237
|
|
|
* |
238
|
|
|
* @return string Store URL |
239
|
|
|
*/ |
240
|
|
|
public function get_store_url() { |
241
|
|
|
return self::STORE_URL; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|