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.2'; |
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
|
|
|
* For non-admin requests it will not be set. |
70
|
|
|
* |
71
|
|
|
* @since 2.0 |
72
|
|
|
* @var \EmailLog\Addon\License\Licenser |
73
|
|
|
*/ |
74
|
|
|
private $licenser = null; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* List of loadies. |
78
|
|
|
* |
79
|
|
|
* @var Loadie[] |
80
|
|
|
*/ |
81
|
|
|
private $loadies = array(); |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Initialize the plugin. |
85
|
|
|
* |
86
|
|
|
* @param string $file Plugin file. |
87
|
|
|
* @param EmailLogAutoloader $loader EmailLog Autoloader. |
88
|
|
|
* @param TableManager $table_manager Table Manager. |
89
|
|
|
*/ |
90
|
1 |
|
public function __construct( $file, $loader, $table_manager ) { |
91
|
1 |
|
$this->plugin_file = $file; |
92
|
1 |
|
$this->loader = $loader; |
93
|
1 |
|
$this->table_manager = $table_manager; |
94
|
|
|
|
95
|
1 |
|
$this->add_loadie( $table_manager ); |
96
|
|
|
|
97
|
1 |
|
$this->translations_path = dirname( plugin_basename( $this->plugin_file ) ) . '/languages/' ; |
98
|
1 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set Licenser. |
102
|
|
|
* |
103
|
|
|
* @param \EmailLog\Addon\License\Licenser $licenser Add-on Licenser. |
104
|
|
|
*/ |
105
|
|
|
public function set_licenser( $licenser ) { |
106
|
|
|
if ( $this->add_loadie( $licenser ) ) { |
107
|
|
|
$this->licenser = $licenser; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get Licenser. |
113
|
|
|
* |
114
|
|
|
* @return null|\EmailLog\Addon\License\Licenser |
115
|
|
|
*/ |
116
|
|
|
public function get_licenser() { |
117
|
|
|
return $this->licenser; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Add an Email Log Loadie. |
122
|
|
|
* The `load()` method of the Loadies will be called when Email Log is loaded. |
123
|
|
|
* |
124
|
|
|
* @param \EmailLog\Core\Loadie $loadie Loadie to be loaded. |
125
|
|
|
* |
126
|
|
|
* @return bool False if Email Log is already loaded or if $loadie is not of `Loadie` type. True otherwise. |
127
|
|
|
*/ |
128
|
1 |
|
public function add_loadie( $loadie ) { |
129
|
1 |
|
if ( $this->loaded ) { |
130
|
|
|
return false; |
131
|
|
|
} |
132
|
|
|
|
133
|
1 |
|
if ( ! $loadie instanceof Loadie ) { |
134
|
|
|
return false; |
135
|
|
|
} |
136
|
|
|
|
137
|
1 |
|
$this->loadies[] = $loadie; |
138
|
|
|
|
139
|
1 |
|
return true; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Load the plugin. |
144
|
|
|
*/ |
145
|
1 |
|
public function load() { |
146
|
1 |
|
if ( $this->loaded ) { |
147
|
|
|
return; |
148
|
|
|
} |
149
|
|
|
|
150
|
1 |
|
load_plugin_textdomain( 'email-log', false, $this->translations_path ); |
151
|
|
|
|
152
|
1 |
|
$this->table_manager->load(); |
153
|
|
|
|
154
|
1 |
|
foreach ( $this->loadies as $loadie ) { |
155
|
1 |
|
$loadie->load(); |
156
|
1 |
|
} |
157
|
|
|
|
158
|
1 |
|
$this->loaded = true; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Email Log plugin loaded. |
162
|
|
|
* |
163
|
|
|
* @since 2.0 |
164
|
|
|
*/ |
165
|
1 |
|
do_action( 'el_loaded' ); |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Shows the Email Log only to allowed User roles set in the Plugin's settings page. |
169
|
|
|
* |
170
|
|
|
* @since 2.1.0 |
171
|
|
|
*/ |
172
|
1 |
|
add_action( 'admin_init', array( $this, 'remove_email_log_menu_by_user_role' ) ); |
173
|
1 |
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Return Email Log version. |
177
|
|
|
* |
178
|
|
|
* @return string Email Log Version. |
179
|
|
|
*/ |
180
|
|
|
public function get_version() { |
181
|
|
|
return self::VERSION; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Return the Email Log plugin directory path. |
186
|
|
|
* |
187
|
|
|
* @return string Plugin directory path. |
188
|
|
|
*/ |
189
|
|
|
public function get_plugin_path() { |
190
|
|
|
return plugin_dir_path( $this->plugin_file ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Return the Email Log plugin file. |
195
|
|
|
* |
196
|
|
|
* @since 2.0.0 |
197
|
|
|
* |
198
|
|
|
* @return string Plugin directory path. |
199
|
|
|
*/ |
200
|
|
|
public function get_plugin_file() { |
201
|
|
|
return $this->plugin_file; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get Email Log Store URL. |
206
|
|
|
* |
207
|
|
|
* @since 2.0.0 |
208
|
|
|
* |
209
|
|
|
* @return string Store URL |
210
|
|
|
*/ |
211
|
|
|
public function get_store_url() { |
212
|
|
|
return self::STORE_URL; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Shows the Email Log only to allowed User roles set in the Plugin's settings page. |
217
|
|
|
*/ |
218
|
|
|
public function remove_email_log_menu_by_user_role() { |
219
|
|
|
if ( ! \EmailLog\Util\can_current_user_view_email_log() ) { |
220
|
|
|
remove_menu_page( 'email-log' ); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|