@@ -19,859 +19,859 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | - * which will be used to store the plugin's activation history |
|
25 | - */ |
|
26 | - const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var $_version |
|
30 | - * @type string |
|
31 | - */ |
|
32 | - protected $_version = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var $_min_core_version |
|
36 | - * @type string |
|
37 | - */ |
|
38 | - protected $_min_core_version = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * derived from plugin 'main_file_path using plugin_basename() |
|
42 | - * |
|
43 | - * @type string $_plugin_basename |
|
44 | - */ |
|
45 | - protected $_plugin_basename = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | - * |
|
50 | - * @type string $_plugin_slug |
|
51 | - */ |
|
52 | - protected $_plugin_slug = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | - * |
|
57 | - * @type string _addon_name |
|
58 | - */ |
|
59 | - protected $_addon_name = ''; |
|
60 | - |
|
61 | - /** |
|
62 | - * one of the EE_System::req_type_* constants |
|
63 | - * |
|
64 | - * @type int $_req_type |
|
65 | - */ |
|
66 | - protected $_req_type; |
|
67 | - |
|
68 | - /** |
|
69 | - * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | - * |
|
71 | - * @type string $_plugin_action_slug |
|
72 | - */ |
|
73 | - protected $_plugin_action_slug = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | - * that can be used for adding upgrading/marketing info |
|
78 | - * |
|
79 | - * @type array $_plugins_page_row |
|
80 | - */ |
|
81 | - protected $_plugins_page_row = array(); |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | - * |
|
87 | - * @type string |
|
88 | - */ |
|
89 | - protected $_main_plugin_file; |
|
90 | - |
|
91 | - /** |
|
92 | - * This is the slug used to identify this add-on within the plugin update engine. |
|
93 | - * |
|
94 | - * @type string |
|
95 | - */ |
|
96 | - protected $pue_slug; |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @var EE_Dependency_Map $dependency_map |
|
101 | - */ |
|
102 | - private $dependency_map; |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @var DomainInterface $domain |
|
107 | - */ |
|
108 | - private $domain; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param EE_Dependency_Map $dependency_map [optional] |
|
113 | - * @param DomainInterface $domain [optional] |
|
114 | - */ |
|
115 | - public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
116 | - { |
|
117 | - if ($dependency_map instanceof EE_Dependency_Map) { |
|
118 | - $this->setDependencyMap($dependency_map); |
|
119 | - } |
|
120 | - if ($domain instanceof DomainInterface) { |
|
121 | - $this->setDomain($domain); |
|
122 | - } |
|
123 | - add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param EE_Dependency_Map $dependency_map |
|
129 | - */ |
|
130 | - public function setDependencyMap($dependency_map) |
|
131 | - { |
|
132 | - $this->dependency_map = $dependency_map; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return EE_Dependency_Map |
|
138 | - */ |
|
139 | - public function dependencyMap() |
|
140 | - { |
|
141 | - return $this->dependency_map; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param DomainInterface $domain |
|
147 | - */ |
|
148 | - public function setDomain(DomainInterface $domain) |
|
149 | - { |
|
150 | - $this->domain = $domain; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @return DomainInterface |
|
155 | - */ |
|
156 | - public function domain() |
|
157 | - { |
|
158 | - return $this->domain; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param mixed $version |
|
164 | - */ |
|
165 | - public function set_version($version = null) |
|
166 | - { |
|
167 | - $this->_version = $version; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * get__version |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function version() |
|
177 | - { |
|
178 | - return $this->_version; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param mixed $min_core_version |
|
184 | - */ |
|
185 | - public function set_min_core_version($min_core_version = null) |
|
186 | - { |
|
187 | - $this->_min_core_version = $min_core_version; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * get__min_core_version |
|
193 | - * |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public function min_core_version() |
|
197 | - { |
|
198 | - return $this->_min_core_version; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Sets addon_name |
|
204 | - * |
|
205 | - * @param string $addon_name |
|
206 | - * @return bool |
|
207 | - */ |
|
208 | - public function set_name($addon_name) |
|
209 | - { |
|
210 | - return $this->_addon_name = $addon_name; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Gets addon_name |
|
216 | - * |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - public function name() |
|
220 | - { |
|
221 | - return $this->_addon_name; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function plugin_basename() |
|
229 | - { |
|
230 | - |
|
231 | - return $this->_plugin_basename; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param string $plugin_basename |
|
237 | - */ |
|
238 | - public function set_plugin_basename($plugin_basename) |
|
239 | - { |
|
240 | - |
|
241 | - $this->_plugin_basename = $plugin_basename; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function plugin_slug() |
|
249 | - { |
|
250 | - |
|
251 | - return $this->_plugin_slug; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $plugin_slug |
|
257 | - */ |
|
258 | - public function set_plugin_slug($plugin_slug) |
|
259 | - { |
|
260 | - |
|
261 | - $this->_plugin_slug = $plugin_slug; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - public function plugin_action_slug() |
|
269 | - { |
|
270 | - |
|
271 | - return $this->_plugin_action_slug; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @param string $plugin_action_slug |
|
277 | - */ |
|
278 | - public function set_plugin_action_slug($plugin_action_slug) |
|
279 | - { |
|
280 | - |
|
281 | - $this->_plugin_action_slug = $plugin_action_slug; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function get_plugins_page_row() |
|
289 | - { |
|
290 | - |
|
291 | - return $this->_plugins_page_row; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @param array $plugins_page_row |
|
297 | - */ |
|
298 | - public function set_plugins_page_row($plugins_page_row = array()) |
|
299 | - { |
|
300 | - // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
301 | - if ( |
|
302 | - ! is_array($plugins_page_row) |
|
303 | - && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
304 | - ) { |
|
305 | - $plugins_page_row = array(); |
|
306 | - } |
|
307 | - $this->_plugins_page_row = (array) $plugins_page_row; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * Called when EE core detects this addon has been activated for the first time. |
|
313 | - * If the site isn't in maintenance mode, should setup the addon's database |
|
314 | - * |
|
315 | - * @return void |
|
316 | - * @throws EE_Error |
|
317 | - */ |
|
318 | - public function new_install() |
|
319 | - { |
|
320 | - $classname = get_class($this); |
|
321 | - do_action("AHEE__{$classname}__new_install"); |
|
322 | - do_action('AHEE__EE_Addon__new_install', $this); |
|
323 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
324 | - add_action( |
|
325 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
326 | - array($this, 'initialize_db_if_no_migrations_required') |
|
327 | - ); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * Called when EE core detects this addon has been reactivated. When this happens, |
|
333 | - * it's good to just check that your data is still intact |
|
334 | - * |
|
335 | - * @return void |
|
336 | - * @throws EE_Error |
|
337 | - */ |
|
338 | - public function reactivation() |
|
339 | - { |
|
340 | - $classname = get_class($this); |
|
341 | - do_action("AHEE__{$classname}__reactivation"); |
|
342 | - do_action('AHEE__EE_Addon__reactivation', $this); |
|
343 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
344 | - add_action( |
|
345 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
346 | - array($this, 'initialize_db_if_no_migrations_required') |
|
347 | - ); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * Called when the registered deactivation hook for this addon fires. |
|
353 | - * |
|
354 | - * @throws EE_Error |
|
355 | - */ |
|
356 | - public function deactivation() |
|
357 | - { |
|
358 | - $classname = get_class($this); |
|
359 | - do_action("AHEE__{$classname}__deactivation"); |
|
360 | - do_action('AHEE__EE_Addon__deactivation', $this); |
|
361 | - // check if the site no longer needs to be in maintenance mode |
|
362 | - EE_Register_Addon::deregister($this->name()); |
|
363 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * Takes care of double-checking that we're not in maintenance mode, and then |
|
369 | - * initializing this addon's necessary initial data. This is called by default on new activations |
|
370 | - * and reactivations. |
|
371 | - * |
|
372 | - * @param bool $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
373 | - * This is a resource-intensive job so we prefer to only do it when necessary |
|
374 | - * @return void |
|
375 | - * @throws EE_Error |
|
376 | - * @throws InvalidInterfaceException |
|
377 | - * @throws InvalidDataTypeException |
|
378 | - * @throws InvalidArgumentException |
|
379 | - * @throws ReflectionException |
|
380 | - */ |
|
381 | - public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
382 | - { |
|
383 | - if ($verify_schema === '') { |
|
384 | - // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
385 | - // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
386 | - // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
387 | - // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
388 | - $verify_schema = true; |
|
389 | - } |
|
390 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
391 | - if ($verify_schema) { |
|
392 | - $this->initialize_db(); |
|
393 | - } |
|
394 | - $this->initialize_default_data(); |
|
395 | - // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
396 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
397 | - array( |
|
398 | - 'slug' => $this->name(), |
|
399 | - 'version' => $this->version(), |
|
400 | - ) |
|
401 | - ); |
|
402 | - /* make sure core's data is a-ok |
|
22 | + /** |
|
23 | + * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | + * which will be used to store the plugin's activation history |
|
25 | + */ |
|
26 | + const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var $_version |
|
30 | + * @type string |
|
31 | + */ |
|
32 | + protected $_version = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var $_min_core_version |
|
36 | + * @type string |
|
37 | + */ |
|
38 | + protected $_min_core_version = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * derived from plugin 'main_file_path using plugin_basename() |
|
42 | + * |
|
43 | + * @type string $_plugin_basename |
|
44 | + */ |
|
45 | + protected $_plugin_basename = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | + * |
|
50 | + * @type string $_plugin_slug |
|
51 | + */ |
|
52 | + protected $_plugin_slug = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | + * |
|
57 | + * @type string _addon_name |
|
58 | + */ |
|
59 | + protected $_addon_name = ''; |
|
60 | + |
|
61 | + /** |
|
62 | + * one of the EE_System::req_type_* constants |
|
63 | + * |
|
64 | + * @type int $_req_type |
|
65 | + */ |
|
66 | + protected $_req_type; |
|
67 | + |
|
68 | + /** |
|
69 | + * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | + * |
|
71 | + * @type string $_plugin_action_slug |
|
72 | + */ |
|
73 | + protected $_plugin_action_slug = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | + * that can be used for adding upgrading/marketing info |
|
78 | + * |
|
79 | + * @type array $_plugins_page_row |
|
80 | + */ |
|
81 | + protected $_plugins_page_row = array(); |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | + * |
|
87 | + * @type string |
|
88 | + */ |
|
89 | + protected $_main_plugin_file; |
|
90 | + |
|
91 | + /** |
|
92 | + * This is the slug used to identify this add-on within the plugin update engine. |
|
93 | + * |
|
94 | + * @type string |
|
95 | + */ |
|
96 | + protected $pue_slug; |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @var EE_Dependency_Map $dependency_map |
|
101 | + */ |
|
102 | + private $dependency_map; |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @var DomainInterface $domain |
|
107 | + */ |
|
108 | + private $domain; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param EE_Dependency_Map $dependency_map [optional] |
|
113 | + * @param DomainInterface $domain [optional] |
|
114 | + */ |
|
115 | + public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
116 | + { |
|
117 | + if ($dependency_map instanceof EE_Dependency_Map) { |
|
118 | + $this->setDependencyMap($dependency_map); |
|
119 | + } |
|
120 | + if ($domain instanceof DomainInterface) { |
|
121 | + $this->setDomain($domain); |
|
122 | + } |
|
123 | + add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param EE_Dependency_Map $dependency_map |
|
129 | + */ |
|
130 | + public function setDependencyMap($dependency_map) |
|
131 | + { |
|
132 | + $this->dependency_map = $dependency_map; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return EE_Dependency_Map |
|
138 | + */ |
|
139 | + public function dependencyMap() |
|
140 | + { |
|
141 | + return $this->dependency_map; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param DomainInterface $domain |
|
147 | + */ |
|
148 | + public function setDomain(DomainInterface $domain) |
|
149 | + { |
|
150 | + $this->domain = $domain; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @return DomainInterface |
|
155 | + */ |
|
156 | + public function domain() |
|
157 | + { |
|
158 | + return $this->domain; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param mixed $version |
|
164 | + */ |
|
165 | + public function set_version($version = null) |
|
166 | + { |
|
167 | + $this->_version = $version; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * get__version |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function version() |
|
177 | + { |
|
178 | + return $this->_version; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param mixed $min_core_version |
|
184 | + */ |
|
185 | + public function set_min_core_version($min_core_version = null) |
|
186 | + { |
|
187 | + $this->_min_core_version = $min_core_version; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * get__min_core_version |
|
193 | + * |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public function min_core_version() |
|
197 | + { |
|
198 | + return $this->_min_core_version; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Sets addon_name |
|
204 | + * |
|
205 | + * @param string $addon_name |
|
206 | + * @return bool |
|
207 | + */ |
|
208 | + public function set_name($addon_name) |
|
209 | + { |
|
210 | + return $this->_addon_name = $addon_name; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Gets addon_name |
|
216 | + * |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + public function name() |
|
220 | + { |
|
221 | + return $this->_addon_name; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function plugin_basename() |
|
229 | + { |
|
230 | + |
|
231 | + return $this->_plugin_basename; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param string $plugin_basename |
|
237 | + */ |
|
238 | + public function set_plugin_basename($plugin_basename) |
|
239 | + { |
|
240 | + |
|
241 | + $this->_plugin_basename = $plugin_basename; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function plugin_slug() |
|
249 | + { |
|
250 | + |
|
251 | + return $this->_plugin_slug; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $plugin_slug |
|
257 | + */ |
|
258 | + public function set_plugin_slug($plugin_slug) |
|
259 | + { |
|
260 | + |
|
261 | + $this->_plugin_slug = $plugin_slug; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public function plugin_action_slug() |
|
269 | + { |
|
270 | + |
|
271 | + return $this->_plugin_action_slug; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @param string $plugin_action_slug |
|
277 | + */ |
|
278 | + public function set_plugin_action_slug($plugin_action_slug) |
|
279 | + { |
|
280 | + |
|
281 | + $this->_plugin_action_slug = $plugin_action_slug; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function get_plugins_page_row() |
|
289 | + { |
|
290 | + |
|
291 | + return $this->_plugins_page_row; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @param array $plugins_page_row |
|
297 | + */ |
|
298 | + public function set_plugins_page_row($plugins_page_row = array()) |
|
299 | + { |
|
300 | + // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
301 | + if ( |
|
302 | + ! is_array($plugins_page_row) |
|
303 | + && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
304 | + ) { |
|
305 | + $plugins_page_row = array(); |
|
306 | + } |
|
307 | + $this->_plugins_page_row = (array) $plugins_page_row; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * Called when EE core detects this addon has been activated for the first time. |
|
313 | + * If the site isn't in maintenance mode, should setup the addon's database |
|
314 | + * |
|
315 | + * @return void |
|
316 | + * @throws EE_Error |
|
317 | + */ |
|
318 | + public function new_install() |
|
319 | + { |
|
320 | + $classname = get_class($this); |
|
321 | + do_action("AHEE__{$classname}__new_install"); |
|
322 | + do_action('AHEE__EE_Addon__new_install', $this); |
|
323 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
324 | + add_action( |
|
325 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
326 | + array($this, 'initialize_db_if_no_migrations_required') |
|
327 | + ); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * Called when EE core detects this addon has been reactivated. When this happens, |
|
333 | + * it's good to just check that your data is still intact |
|
334 | + * |
|
335 | + * @return void |
|
336 | + * @throws EE_Error |
|
337 | + */ |
|
338 | + public function reactivation() |
|
339 | + { |
|
340 | + $classname = get_class($this); |
|
341 | + do_action("AHEE__{$classname}__reactivation"); |
|
342 | + do_action('AHEE__EE_Addon__reactivation', $this); |
|
343 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
344 | + add_action( |
|
345 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
346 | + array($this, 'initialize_db_if_no_migrations_required') |
|
347 | + ); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * Called when the registered deactivation hook for this addon fires. |
|
353 | + * |
|
354 | + * @throws EE_Error |
|
355 | + */ |
|
356 | + public function deactivation() |
|
357 | + { |
|
358 | + $classname = get_class($this); |
|
359 | + do_action("AHEE__{$classname}__deactivation"); |
|
360 | + do_action('AHEE__EE_Addon__deactivation', $this); |
|
361 | + // check if the site no longer needs to be in maintenance mode |
|
362 | + EE_Register_Addon::deregister($this->name()); |
|
363 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * Takes care of double-checking that we're not in maintenance mode, and then |
|
369 | + * initializing this addon's necessary initial data. This is called by default on new activations |
|
370 | + * and reactivations. |
|
371 | + * |
|
372 | + * @param bool $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
373 | + * This is a resource-intensive job so we prefer to only do it when necessary |
|
374 | + * @return void |
|
375 | + * @throws EE_Error |
|
376 | + * @throws InvalidInterfaceException |
|
377 | + * @throws InvalidDataTypeException |
|
378 | + * @throws InvalidArgumentException |
|
379 | + * @throws ReflectionException |
|
380 | + */ |
|
381 | + public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
382 | + { |
|
383 | + if ($verify_schema === '') { |
|
384 | + // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
385 | + // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
386 | + // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
387 | + // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
388 | + $verify_schema = true; |
|
389 | + } |
|
390 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
391 | + if ($verify_schema) { |
|
392 | + $this->initialize_db(); |
|
393 | + } |
|
394 | + $this->initialize_default_data(); |
|
395 | + // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
396 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
397 | + array( |
|
398 | + 'slug' => $this->name(), |
|
399 | + 'version' => $this->version(), |
|
400 | + ) |
|
401 | + ); |
|
402 | + /* make sure core's data is a-ok |
|
403 | 403 | * (at the time of writing, we especially want to verify all the caps are present |
404 | 404 | * because payment method type capabilities are added dynamically, and it's |
405 | 405 | * possible this addon added a payment method. But it's also possible |
406 | 406 | * other data needs to be verified) |
407 | 407 | */ |
408 | - EEH_Activation::initialize_db_content(); |
|
409 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
410 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
411 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
412 | - ); |
|
413 | - $rewrite_rules->flushRewriteRules(); |
|
414 | - // in case there are lots of addons being activated at once, let's force garbage collection |
|
415 | - // to help avoid memory limit errors |
|
416 | - // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
417 | - gc_collect_cycles(); |
|
418 | - } else { |
|
419 | - // ask the data migration manager to init this addon's data |
|
420 | - // when migrations are finished because we can't do it now |
|
421 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
422 | - } |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Used to setup this addon's database tables, but not necessarily any default |
|
428 | - * data in them. The default is to actually use the most up-to-date data migration script |
|
429 | - * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
430 | - * methods to setup the db. |
|
431 | - */ |
|
432 | - public function initialize_db() |
|
433 | - { |
|
434 | - // find the migration script that sets the database to be compatible with the code |
|
435 | - $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
436 | - if ($current_dms_name) { |
|
437 | - $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
438 | - $current_data_migration_script->set_migrating(false); |
|
439 | - $current_data_migration_script->schema_changes_before_migration(); |
|
440 | - $current_data_migration_script->schema_changes_after_migration(); |
|
441 | - if ($current_data_migration_script->get_errors()) { |
|
442 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
443 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
444 | - } |
|
445 | - } |
|
446 | - } |
|
447 | - // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
448 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
449 | - array( |
|
450 | - 'slug' => $this->name(), |
|
451 | - 'version' => $this->version(), |
|
452 | - ) |
|
453 | - ); |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * If you want to setup default data for the addon, override this method, and call |
|
459 | - * parent::initialize_default_data() from within it. This is normally called |
|
460 | - * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
461 | - * and should verify default data is present (but this is also called |
|
462 | - * on reactivations and just after migrations, so please verify you actually want |
|
463 | - * to ADD default data, because it may already be present). |
|
464 | - * However, please call this parent (currently it just fires a hook which other |
|
465 | - * addons may be depending on) |
|
466 | - */ |
|
467 | - public function initialize_default_data() |
|
468 | - { |
|
469 | - /** |
|
470 | - * Called when an addon is ensuring its default data is set (possibly called |
|
471 | - * on a reactivation, so first check for the absence of other data before setting |
|
472 | - * default data) |
|
473 | - * |
|
474 | - * @param EE_Addon $addon the addon that called this |
|
475 | - */ |
|
476 | - do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
477 | - // override to insert default data. It is safe to use the models here |
|
478 | - // because the site should not be in maintenance mode |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * EE Core detected that this addon has been upgraded. We should check if there |
|
484 | - * are any new migration scripts, and if so put the site into maintenance mode until |
|
485 | - * they're ran |
|
486 | - * |
|
487 | - * @return void |
|
488 | - * @throws EE_Error |
|
489 | - */ |
|
490 | - public function upgrade() |
|
491 | - { |
|
492 | - $classname = get_class($this); |
|
493 | - do_action("AHEE__{$classname}__upgrade"); |
|
494 | - do_action('AHEE__EE_Addon__upgrade', $this); |
|
495 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
496 | - // also it's possible there is new default data that needs to be added |
|
497 | - add_action( |
|
498 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
499 | - array($this, 'initialize_db_if_no_migrations_required') |
|
500 | - ); |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
506 | - */ |
|
507 | - public function downgrade() |
|
508 | - { |
|
509 | - $classname = get_class($this); |
|
510 | - do_action("AHEE__{$classname}__downgrade"); |
|
511 | - do_action('AHEE__EE_Addon__downgrade', $this); |
|
512 | - // it's possible there's old default data that needs to be double-checked |
|
513 | - add_action( |
|
514 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
515 | - array($this, 'initialize_db_if_no_migrations_required') |
|
516 | - ); |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * set_db_update_option_name |
|
522 | - * Until we do something better, we'll just check for migration scripts upon |
|
523 | - * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
524 | - * |
|
525 | - * @return bool |
|
526 | - */ |
|
527 | - public function set_db_update_option_name() |
|
528 | - { |
|
529 | - EE_Error::doing_it_wrong( |
|
530 | - __FUNCTION__, |
|
531 | - esc_html__( |
|
532 | - 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
533 | - 'event_espresso' |
|
534 | - ), |
|
535 | - '4.3.0.alpha.016' |
|
536 | - ); |
|
537 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
538 | - return $this->set_activation_indicator_option(); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * Returns the name of the activation indicator option |
|
544 | - * (an option which is set temporarily to indicate that this addon was just activated) |
|
545 | - * |
|
546 | - * @deprecated since version 4.3.0.alpha.016 |
|
547 | - * @return string |
|
548 | - */ |
|
549 | - public function get_db_update_option_name() |
|
550 | - { |
|
551 | - EE_Error::doing_it_wrong( |
|
552 | - __FUNCTION__, |
|
553 | - esc_html__( |
|
554 | - 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
555 | - 'event_espresso' |
|
556 | - ), |
|
557 | - '4.3.0.alpha.016' |
|
558 | - ); |
|
559 | - return $this->get_activation_indicator_option_name(); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * When the addon is activated, this should be called to set a wordpress option that |
|
565 | - * indicates it was activated. This is especially useful for detecting reactivations. |
|
566 | - * |
|
567 | - * @return bool |
|
568 | - */ |
|
569 | - public function set_activation_indicator_option() |
|
570 | - { |
|
571 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
572 | - return update_option($this->get_activation_indicator_option_name(), true); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
578 | - * |
|
579 | - * @return string |
|
580 | - */ |
|
581 | - public function get_activation_indicator_option_name() |
|
582 | - { |
|
583 | - return 'ee_activation_' . $this->name(); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
589 | - * |
|
590 | - * @param int $req_type |
|
591 | - */ |
|
592 | - public function set_req_type($req_type) |
|
593 | - { |
|
594 | - $this->_req_type = $req_type; |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
600 | - * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
601 | - * EE_System when it is checking for new install or upgrades of addons |
|
602 | - */ |
|
603 | - public function detect_req_type($redetect = false) |
|
604 | - { |
|
605 | - if ($this->_req_type === null || $redetect) { |
|
606 | - $this->detect_activation_or_upgrade(); |
|
607 | - } |
|
608 | - return $this->_req_type; |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
614 | - * Should only be called once per request |
|
615 | - * |
|
616 | - * @return void |
|
617 | - * @throws EE_Error |
|
618 | - */ |
|
619 | - public function detect_activation_or_upgrade() |
|
620 | - { |
|
621 | - $activation_history_for_addon = $this->get_activation_history(); |
|
622 | - $request_type = EE_System::detect_req_type_given_activation_history( |
|
623 | - $activation_history_for_addon, |
|
624 | - $this->get_activation_indicator_option_name(), |
|
625 | - $this->version() |
|
626 | - ); |
|
627 | - $this->set_req_type($request_type); |
|
628 | - $classname = get_class($this); |
|
629 | - switch ($request_type) { |
|
630 | - case EE_System::req_type_new_activation: |
|
631 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
632 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
633 | - $this->new_install(); |
|
634 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
635 | - break; |
|
636 | - case EE_System::req_type_reactivation: |
|
637 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
638 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
639 | - $this->reactivation(); |
|
640 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
641 | - break; |
|
642 | - case EE_System::req_type_upgrade: |
|
643 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
644 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
645 | - $this->upgrade(); |
|
646 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
647 | - break; |
|
648 | - case EE_System::req_type_downgrade: |
|
649 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
650 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
651 | - $this->downgrade(); |
|
652 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
653 | - break; |
|
654 | - case EE_System::req_type_normal: |
|
655 | - default: |
|
656 | - break; |
|
657 | - } |
|
658 | - |
|
659 | - do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * Updates the version history for this addon |
|
664 | - * |
|
665 | - * @param array $version_history |
|
666 | - * @param string $current_version_to_add |
|
667 | - * @return bool success |
|
668 | - */ |
|
669 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
670 | - { |
|
671 | - if (! $version_history) { |
|
672 | - $version_history = $this->get_activation_history(); |
|
673 | - } |
|
674 | - if ($current_version_to_add === null) { |
|
675 | - $current_version_to_add = $this->version(); |
|
676 | - } |
|
677 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
678 | - // resave |
|
679 | - return update_option($this->get_activation_history_option_name(), $version_history); |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * Gets the name of the wp option that stores the activation history |
|
684 | - * of this addon |
|
685 | - * |
|
686 | - * @return string |
|
687 | - */ |
|
688 | - public function get_activation_history_option_name() |
|
689 | - { |
|
690 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * Gets the wp option which stores the activation history for this addon |
|
696 | - * |
|
697 | - * @return array |
|
698 | - */ |
|
699 | - public function get_activation_history() |
|
700 | - { |
|
701 | - return get_option($this->get_activation_history_option_name(), null); |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - /** |
|
706 | - * @param string $config_section |
|
707 | - */ |
|
708 | - public function set_config_section($config_section = '') |
|
709 | - { |
|
710 | - $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
711 | - } |
|
712 | - |
|
713 | - /** |
|
714 | - * Sets the filepath to the main plugin file |
|
715 | - * |
|
716 | - * @param string $filepath |
|
717 | - */ |
|
718 | - public function set_main_plugin_file($filepath) |
|
719 | - { |
|
720 | - $this->_main_plugin_file = $filepath; |
|
721 | - } |
|
722 | - |
|
723 | - /** |
|
724 | - * gets the filepath to teh main file |
|
725 | - * |
|
726 | - * @return string |
|
727 | - */ |
|
728 | - public function get_main_plugin_file() |
|
729 | - { |
|
730 | - return $this->_main_plugin_file; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Gets the filename (no path) of the main file (the main file loaded |
|
735 | - * by WP) |
|
736 | - * |
|
737 | - * @return string |
|
738 | - */ |
|
739 | - public function get_main_plugin_file_basename() |
|
740 | - { |
|
741 | - return plugin_basename($this->get_main_plugin_file()); |
|
742 | - } |
|
743 | - |
|
744 | - /** |
|
745 | - * Gets the folder name which contains the main plugin file |
|
746 | - * |
|
747 | - * @return string |
|
748 | - */ |
|
749 | - public function get_main_plugin_file_dirname() |
|
750 | - { |
|
751 | - return dirname($this->get_main_plugin_file()); |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - /** |
|
756 | - * sets hooks used in the admin |
|
757 | - * |
|
758 | - * @return void |
|
759 | - */ |
|
760 | - public function admin_init() |
|
761 | - { |
|
762 | - // is admin and not in M-Mode ? |
|
763 | - if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
764 | - add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
765 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * plugin_actions |
|
772 | - * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
773 | - * |
|
774 | - * @param $links |
|
775 | - * @param $file |
|
776 | - * @return array |
|
777 | - */ |
|
778 | - public function plugin_action_links($links, $file) |
|
779 | - { |
|
780 | - if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
781 | - // before other links |
|
782 | - array_unshift( |
|
783 | - $links, |
|
784 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
785 | - . esc_html__('Settings', 'event_espresso') |
|
786 | - . '</a>' |
|
787 | - ); |
|
788 | - } |
|
789 | - return $links; |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * after_plugin_row |
|
795 | - * Add additional content to the plugins page plugin row |
|
796 | - * Inserts another row |
|
797 | - * |
|
798 | - * @param $plugin_file |
|
799 | - * @param $plugin_data |
|
800 | - * @param $status |
|
801 | - * @return void |
|
802 | - */ |
|
803 | - public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
804 | - { |
|
805 | - $after_plugin_row = ''; |
|
806 | - $plugins_page_row = $this->get_plugins_page_row(); |
|
807 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
808 | - $class = $status ? 'active' : 'inactive'; |
|
809 | - $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
810 | - $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
811 | - $description = isset($plugins_page_row['description']) |
|
812 | - ? $plugins_page_row['description'] |
|
813 | - : ''; |
|
814 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
815 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
816 | - $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
817 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
818 | - $after_plugin_row .= '<p class="ee-addon-upsell-info-dv"> |
|
408 | + EEH_Activation::initialize_db_content(); |
|
409 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
410 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
411 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
412 | + ); |
|
413 | + $rewrite_rules->flushRewriteRules(); |
|
414 | + // in case there are lots of addons being activated at once, let's force garbage collection |
|
415 | + // to help avoid memory limit errors |
|
416 | + // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
417 | + gc_collect_cycles(); |
|
418 | + } else { |
|
419 | + // ask the data migration manager to init this addon's data |
|
420 | + // when migrations are finished because we can't do it now |
|
421 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
422 | + } |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Used to setup this addon's database tables, but not necessarily any default |
|
428 | + * data in them. The default is to actually use the most up-to-date data migration script |
|
429 | + * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
430 | + * methods to setup the db. |
|
431 | + */ |
|
432 | + public function initialize_db() |
|
433 | + { |
|
434 | + // find the migration script that sets the database to be compatible with the code |
|
435 | + $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
436 | + if ($current_dms_name) { |
|
437 | + $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
438 | + $current_data_migration_script->set_migrating(false); |
|
439 | + $current_data_migration_script->schema_changes_before_migration(); |
|
440 | + $current_data_migration_script->schema_changes_after_migration(); |
|
441 | + if ($current_data_migration_script->get_errors()) { |
|
442 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
443 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
444 | + } |
|
445 | + } |
|
446 | + } |
|
447 | + // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
448 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
449 | + array( |
|
450 | + 'slug' => $this->name(), |
|
451 | + 'version' => $this->version(), |
|
452 | + ) |
|
453 | + ); |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * If you want to setup default data for the addon, override this method, and call |
|
459 | + * parent::initialize_default_data() from within it. This is normally called |
|
460 | + * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
461 | + * and should verify default data is present (but this is also called |
|
462 | + * on reactivations and just after migrations, so please verify you actually want |
|
463 | + * to ADD default data, because it may already be present). |
|
464 | + * However, please call this parent (currently it just fires a hook which other |
|
465 | + * addons may be depending on) |
|
466 | + */ |
|
467 | + public function initialize_default_data() |
|
468 | + { |
|
469 | + /** |
|
470 | + * Called when an addon is ensuring its default data is set (possibly called |
|
471 | + * on a reactivation, so first check for the absence of other data before setting |
|
472 | + * default data) |
|
473 | + * |
|
474 | + * @param EE_Addon $addon the addon that called this |
|
475 | + */ |
|
476 | + do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
477 | + // override to insert default data. It is safe to use the models here |
|
478 | + // because the site should not be in maintenance mode |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * EE Core detected that this addon has been upgraded. We should check if there |
|
484 | + * are any new migration scripts, and if so put the site into maintenance mode until |
|
485 | + * they're ran |
|
486 | + * |
|
487 | + * @return void |
|
488 | + * @throws EE_Error |
|
489 | + */ |
|
490 | + public function upgrade() |
|
491 | + { |
|
492 | + $classname = get_class($this); |
|
493 | + do_action("AHEE__{$classname}__upgrade"); |
|
494 | + do_action('AHEE__EE_Addon__upgrade', $this); |
|
495 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
496 | + // also it's possible there is new default data that needs to be added |
|
497 | + add_action( |
|
498 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
499 | + array($this, 'initialize_db_if_no_migrations_required') |
|
500 | + ); |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
506 | + */ |
|
507 | + public function downgrade() |
|
508 | + { |
|
509 | + $classname = get_class($this); |
|
510 | + do_action("AHEE__{$classname}__downgrade"); |
|
511 | + do_action('AHEE__EE_Addon__downgrade', $this); |
|
512 | + // it's possible there's old default data that needs to be double-checked |
|
513 | + add_action( |
|
514 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
515 | + array($this, 'initialize_db_if_no_migrations_required') |
|
516 | + ); |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * set_db_update_option_name |
|
522 | + * Until we do something better, we'll just check for migration scripts upon |
|
523 | + * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
524 | + * |
|
525 | + * @return bool |
|
526 | + */ |
|
527 | + public function set_db_update_option_name() |
|
528 | + { |
|
529 | + EE_Error::doing_it_wrong( |
|
530 | + __FUNCTION__, |
|
531 | + esc_html__( |
|
532 | + 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
533 | + 'event_espresso' |
|
534 | + ), |
|
535 | + '4.3.0.alpha.016' |
|
536 | + ); |
|
537 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
538 | + return $this->set_activation_indicator_option(); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * Returns the name of the activation indicator option |
|
544 | + * (an option which is set temporarily to indicate that this addon was just activated) |
|
545 | + * |
|
546 | + * @deprecated since version 4.3.0.alpha.016 |
|
547 | + * @return string |
|
548 | + */ |
|
549 | + public function get_db_update_option_name() |
|
550 | + { |
|
551 | + EE_Error::doing_it_wrong( |
|
552 | + __FUNCTION__, |
|
553 | + esc_html__( |
|
554 | + 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
555 | + 'event_espresso' |
|
556 | + ), |
|
557 | + '4.3.0.alpha.016' |
|
558 | + ); |
|
559 | + return $this->get_activation_indicator_option_name(); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * When the addon is activated, this should be called to set a wordpress option that |
|
565 | + * indicates it was activated. This is especially useful for detecting reactivations. |
|
566 | + * |
|
567 | + * @return bool |
|
568 | + */ |
|
569 | + public function set_activation_indicator_option() |
|
570 | + { |
|
571 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
572 | + return update_option($this->get_activation_indicator_option_name(), true); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
578 | + * |
|
579 | + * @return string |
|
580 | + */ |
|
581 | + public function get_activation_indicator_option_name() |
|
582 | + { |
|
583 | + return 'ee_activation_' . $this->name(); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
589 | + * |
|
590 | + * @param int $req_type |
|
591 | + */ |
|
592 | + public function set_req_type($req_type) |
|
593 | + { |
|
594 | + $this->_req_type = $req_type; |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
600 | + * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
601 | + * EE_System when it is checking for new install or upgrades of addons |
|
602 | + */ |
|
603 | + public function detect_req_type($redetect = false) |
|
604 | + { |
|
605 | + if ($this->_req_type === null || $redetect) { |
|
606 | + $this->detect_activation_or_upgrade(); |
|
607 | + } |
|
608 | + return $this->_req_type; |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
614 | + * Should only be called once per request |
|
615 | + * |
|
616 | + * @return void |
|
617 | + * @throws EE_Error |
|
618 | + */ |
|
619 | + public function detect_activation_or_upgrade() |
|
620 | + { |
|
621 | + $activation_history_for_addon = $this->get_activation_history(); |
|
622 | + $request_type = EE_System::detect_req_type_given_activation_history( |
|
623 | + $activation_history_for_addon, |
|
624 | + $this->get_activation_indicator_option_name(), |
|
625 | + $this->version() |
|
626 | + ); |
|
627 | + $this->set_req_type($request_type); |
|
628 | + $classname = get_class($this); |
|
629 | + switch ($request_type) { |
|
630 | + case EE_System::req_type_new_activation: |
|
631 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
632 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
633 | + $this->new_install(); |
|
634 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
635 | + break; |
|
636 | + case EE_System::req_type_reactivation: |
|
637 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
638 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
639 | + $this->reactivation(); |
|
640 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
641 | + break; |
|
642 | + case EE_System::req_type_upgrade: |
|
643 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
644 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
645 | + $this->upgrade(); |
|
646 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
647 | + break; |
|
648 | + case EE_System::req_type_downgrade: |
|
649 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
650 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
651 | + $this->downgrade(); |
|
652 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
653 | + break; |
|
654 | + case EE_System::req_type_normal: |
|
655 | + default: |
|
656 | + break; |
|
657 | + } |
|
658 | + |
|
659 | + do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * Updates the version history for this addon |
|
664 | + * |
|
665 | + * @param array $version_history |
|
666 | + * @param string $current_version_to_add |
|
667 | + * @return bool success |
|
668 | + */ |
|
669 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
670 | + { |
|
671 | + if (! $version_history) { |
|
672 | + $version_history = $this->get_activation_history(); |
|
673 | + } |
|
674 | + if ($current_version_to_add === null) { |
|
675 | + $current_version_to_add = $this->version(); |
|
676 | + } |
|
677 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
678 | + // resave |
|
679 | + return update_option($this->get_activation_history_option_name(), $version_history); |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * Gets the name of the wp option that stores the activation history |
|
684 | + * of this addon |
|
685 | + * |
|
686 | + * @return string |
|
687 | + */ |
|
688 | + public function get_activation_history_option_name() |
|
689 | + { |
|
690 | + return self::ee_addon_version_history_option_prefix . $this->name(); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * Gets the wp option which stores the activation history for this addon |
|
696 | + * |
|
697 | + * @return array |
|
698 | + */ |
|
699 | + public function get_activation_history() |
|
700 | + { |
|
701 | + return get_option($this->get_activation_history_option_name(), null); |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + /** |
|
706 | + * @param string $config_section |
|
707 | + */ |
|
708 | + public function set_config_section($config_section = '') |
|
709 | + { |
|
710 | + $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
711 | + } |
|
712 | + |
|
713 | + /** |
|
714 | + * Sets the filepath to the main plugin file |
|
715 | + * |
|
716 | + * @param string $filepath |
|
717 | + */ |
|
718 | + public function set_main_plugin_file($filepath) |
|
719 | + { |
|
720 | + $this->_main_plugin_file = $filepath; |
|
721 | + } |
|
722 | + |
|
723 | + /** |
|
724 | + * gets the filepath to teh main file |
|
725 | + * |
|
726 | + * @return string |
|
727 | + */ |
|
728 | + public function get_main_plugin_file() |
|
729 | + { |
|
730 | + return $this->_main_plugin_file; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Gets the filename (no path) of the main file (the main file loaded |
|
735 | + * by WP) |
|
736 | + * |
|
737 | + * @return string |
|
738 | + */ |
|
739 | + public function get_main_plugin_file_basename() |
|
740 | + { |
|
741 | + return plugin_basename($this->get_main_plugin_file()); |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Gets the folder name which contains the main plugin file |
|
746 | + * |
|
747 | + * @return string |
|
748 | + */ |
|
749 | + public function get_main_plugin_file_dirname() |
|
750 | + { |
|
751 | + return dirname($this->get_main_plugin_file()); |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + /** |
|
756 | + * sets hooks used in the admin |
|
757 | + * |
|
758 | + * @return void |
|
759 | + */ |
|
760 | + public function admin_init() |
|
761 | + { |
|
762 | + // is admin and not in M-Mode ? |
|
763 | + if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
764 | + add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
765 | + add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * plugin_actions |
|
772 | + * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
773 | + * |
|
774 | + * @param $links |
|
775 | + * @param $file |
|
776 | + * @return array |
|
777 | + */ |
|
778 | + public function plugin_action_links($links, $file) |
|
779 | + { |
|
780 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
781 | + // before other links |
|
782 | + array_unshift( |
|
783 | + $links, |
|
784 | + '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
785 | + . esc_html__('Settings', 'event_espresso') |
|
786 | + . '</a>' |
|
787 | + ); |
|
788 | + } |
|
789 | + return $links; |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * after_plugin_row |
|
795 | + * Add additional content to the plugins page plugin row |
|
796 | + * Inserts another row |
|
797 | + * |
|
798 | + * @param $plugin_file |
|
799 | + * @param $plugin_data |
|
800 | + * @param $status |
|
801 | + * @return void |
|
802 | + */ |
|
803 | + public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
804 | + { |
|
805 | + $after_plugin_row = ''; |
|
806 | + $plugins_page_row = $this->get_plugins_page_row(); |
|
807 | + if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
808 | + $class = $status ? 'active' : 'inactive'; |
|
809 | + $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
810 | + $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
811 | + $description = isset($plugins_page_row['description']) |
|
812 | + ? $plugins_page_row['description'] |
|
813 | + : ''; |
|
814 | + if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
815 | + $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
816 | + $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
817 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
818 | + $after_plugin_row .= '<p class="ee-addon-upsell-info-dv"> |
|
819 | 819 | <a class="ee-button" href="' . esc_url_raw($link_url) . '">' |
820 | - . $link_text |
|
821 | - . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
822 | - . '</a> |
|
820 | + . $link_text |
|
821 | + . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
822 | + . '</a> |
|
823 | 823 | </p>'; |
824 | - $after_plugin_row .= '</td>'; |
|
825 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
826 | - $after_plugin_row .= $description; |
|
827 | - $after_plugin_row .= '</td>'; |
|
828 | - $after_plugin_row .= '</tr>'; |
|
829 | - } else { |
|
830 | - $after_plugin_row .= $description; |
|
831 | - } |
|
832 | - } |
|
833 | - |
|
834 | - echo $after_plugin_row; |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - /** |
|
839 | - * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
840 | - * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
841 | - * for back compat reasons. |
|
842 | - * |
|
843 | - * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
844 | - * |
|
845 | - * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
846 | - * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
847 | - * callback does not get run/set in that request. |
|
848 | - * |
|
849 | - * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
850 | - * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
851 | - * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
852 | - * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
853 | - * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
854 | - * to call `parent::deactivation`. |
|
855 | - * |
|
856 | - * @since 4.9.26 |
|
857 | - */ |
|
858 | - public function after_registration() |
|
859 | - { |
|
860 | - // cricket chirp... cricket chirp... |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * @return string |
|
865 | - */ |
|
866 | - public function getPueSlug() |
|
867 | - { |
|
868 | - return $this->pue_slug; |
|
869 | - } |
|
870 | - /** |
|
871 | - * @param string $pue_slug |
|
872 | - */ |
|
873 | - public function setPueSlug($pue_slug) |
|
874 | - { |
|
875 | - $this->pue_slug = $pue_slug; |
|
876 | - } |
|
824 | + $after_plugin_row .= '</td>'; |
|
825 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
826 | + $after_plugin_row .= $description; |
|
827 | + $after_plugin_row .= '</td>'; |
|
828 | + $after_plugin_row .= '</tr>'; |
|
829 | + } else { |
|
830 | + $after_plugin_row .= $description; |
|
831 | + } |
|
832 | + } |
|
833 | + |
|
834 | + echo $after_plugin_row; |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + /** |
|
839 | + * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
840 | + * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
841 | + * for back compat reasons. |
|
842 | + * |
|
843 | + * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
844 | + * |
|
845 | + * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
846 | + * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
847 | + * callback does not get run/set in that request. |
|
848 | + * |
|
849 | + * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
850 | + * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
851 | + * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
852 | + * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
853 | + * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
854 | + * to call `parent::deactivation`. |
|
855 | + * |
|
856 | + * @since 4.9.26 |
|
857 | + */ |
|
858 | + public function after_registration() |
|
859 | + { |
|
860 | + // cricket chirp... cricket chirp... |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * @return string |
|
865 | + */ |
|
866 | + public function getPueSlug() |
|
867 | + { |
|
868 | + return $this->pue_slug; |
|
869 | + } |
|
870 | + /** |
|
871 | + * @param string $pue_slug |
|
872 | + */ |
|
873 | + public function setPueSlug($pue_slug) |
|
874 | + { |
|
875 | + $this->pue_slug = $pue_slug; |
|
876 | + } |
|
877 | 877 | } |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function get_activation_indicator_option_name() |
582 | 582 | { |
583 | - return 'ee_activation_' . $this->name(); |
|
583 | + return 'ee_activation_'.$this->name(); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | |
@@ -668,13 +668,13 @@ discard block |
||
668 | 668 | */ |
669 | 669 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
670 | 670 | { |
671 | - if (! $version_history) { |
|
671 | + if ( ! $version_history) { |
|
672 | 672 | $version_history = $this->get_activation_history(); |
673 | 673 | } |
674 | 674 | if ($current_version_to_add === null) { |
675 | 675 | $current_version_to_add = $this->version(); |
676 | 676 | } |
677 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
677 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
678 | 678 | // resave |
679 | 679 | return update_option($this->get_activation_history_option_name(), $version_history); |
680 | 680 | } |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | */ |
688 | 688 | public function get_activation_history_option_name() |
689 | 689 | { |
690 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
690 | + return self::ee_addon_version_history_option_prefix.$this->name(); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | // is admin and not in M-Mode ? |
763 | 763 | if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
764 | 764 | add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
765 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
765 | + add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | // before other links |
782 | 782 | array_unshift( |
783 | 783 | $links, |
784 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
784 | + '<a href="admin.php?page='.$this->plugin_action_slug().'">' |
|
785 | 785 | . esc_html__('Settings', 'event_espresso') |
786 | 786 | . '</a>' |
787 | 787 | ); |
@@ -804,19 +804,19 @@ discard block |
||
804 | 804 | { |
805 | 805 | $after_plugin_row = ''; |
806 | 806 | $plugins_page_row = $this->get_plugins_page_row(); |
807 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
807 | + if ( ! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
808 | 808 | $class = $status ? 'active' : 'inactive'; |
809 | 809 | $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
810 | 810 | $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
811 | 811 | $description = isset($plugins_page_row['description']) |
812 | 812 | ? $plugins_page_row['description'] |
813 | 813 | : ''; |
814 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
815 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
814 | + if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
815 | + $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">'; |
|
816 | 816 | $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
817 | 817 | $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
818 | 818 | $after_plugin_row .= '<p class="ee-addon-upsell-info-dv"> |
819 | - <a class="ee-button" href="' . esc_url_raw($link_url) . '">' |
|
819 | + <a class="ee-button" href="' . esc_url_raw($link_url).'">' |
|
820 | 820 | . $link_text |
821 | 821 | . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
822 | 822 | . '</a> |
@@ -13,228 +13,228 @@ |
||
13 | 13 | class AllowedTags |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array[] |
|
18 | - */ |
|
19 | - private static $attributes = [ |
|
20 | - 'accept-charset' => 1, |
|
21 | - 'action' => 1, |
|
22 | - 'alt' => 1, |
|
23 | - 'allow' => 1, |
|
24 | - 'allowfullscreen' => 1, |
|
25 | - 'align' => 1, |
|
26 | - 'aria-*' => 1, |
|
27 | - 'autocomplete' => 1, |
|
28 | - 'checked' => 1, |
|
29 | - 'class' => 1, |
|
30 | - 'cols' => 1, |
|
31 | - 'content' => 1, |
|
32 | - 'data-*' => 1, |
|
33 | - 'dir' => 1, |
|
34 | - 'disabled' => 1, |
|
35 | - 'enctype' => 1, |
|
36 | - 'for' => 1, |
|
37 | - 'frameborder' => 1, |
|
38 | - 'height' => 1, |
|
39 | - 'href' => 1, |
|
40 | - 'id' => 1, |
|
41 | - 'itemprop' => 1, |
|
42 | - 'itemscope' => 1, |
|
43 | - 'itemtype' => 1, |
|
44 | - 'label' => 1, |
|
45 | - 'lang' => 1, |
|
46 | - 'max' => 1, |
|
47 | - 'maxlength' => 1, |
|
48 | - 'method' => 1, |
|
49 | - 'min' => 1, |
|
50 | - 'multiple' => 1, |
|
51 | - 'name' => 1, |
|
52 | - 'novalidate' => 1, |
|
53 | - 'placeholder' => 1, |
|
54 | - 'readonly' => 1, |
|
55 | - 'rel' => 1, |
|
56 | - 'required' => 1, |
|
57 | - 'rows' => 1, |
|
58 | - 'selected' => 1, |
|
59 | - 'src' => 1, |
|
60 | - 'size' => 1, |
|
61 | - 'style' => 1, |
|
62 | - 'step' => 1, |
|
63 | - 'tabindex' => 1, |
|
64 | - 'target' => 1, |
|
65 | - 'title' => 1, |
|
66 | - 'type' => 1, |
|
67 | - 'value' => 1, |
|
68 | - 'width' => 1, |
|
69 | - ]; |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - private static $tags = [ |
|
76 | - 'a', |
|
77 | - 'abbr', |
|
78 | - 'b', |
|
79 | - 'br', |
|
80 | - 'code', |
|
81 | - 'div', |
|
82 | - 'em', |
|
83 | - 'h1', |
|
84 | - 'h2', |
|
85 | - 'h3', |
|
86 | - 'h4', |
|
87 | - 'h5', |
|
88 | - 'h6', |
|
89 | - 'hr', |
|
90 | - 'i', |
|
91 | - 'img', |
|
92 | - 'li', |
|
93 | - 'ol', |
|
94 | - 'p', |
|
95 | - 'pre', |
|
96 | - 'small', |
|
97 | - 'span', |
|
98 | - 'strong', |
|
99 | - 'table', |
|
100 | - 'td', |
|
101 | - 'tr', |
|
102 | - 'ul', |
|
103 | - ]; |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @var array |
|
108 | - */ |
|
109 | - private static $allowed_tags; |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - private static $allowed_with_embed_tags; |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @var array |
|
120 | - */ |
|
121 | - private static $allowed_with_form_tags; |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - private static $allowed_with_script_and_style_tags; |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * merges additional tags and attributes into the WP post tags |
|
132 | - */ |
|
133 | - private static function initializeAllowedTags() |
|
134 | - { |
|
135 | - $allowed_post_tags = wp_kses_allowed_html('post'); |
|
136 | - $allowed_tags = []; |
|
137 | - foreach (AllowedTags::$tags as $tag) { |
|
138 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
139 | - } |
|
140 | - AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * merges embed tags and attributes into the EE all tags |
|
146 | - */ |
|
147 | - private static function initializeWithEmbedTags() |
|
148 | - { |
|
149 | - $all_tags = AllowedTags::getAllowedTags(); |
|
150 | - $embed_tags = [ |
|
151 | - 'iframe' => AllowedTags::$attributes |
|
152 | - ]; |
|
153 | - AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * merges form tags and attributes into the EE all tags |
|
159 | - */ |
|
160 | - private static function initializeWithFormTags() |
|
161 | - { |
|
162 | - $all_tags = AllowedTags::getAllowedTags(); |
|
163 | - $form_tags = [ |
|
164 | - 'form' => AllowedTags::$attributes, |
|
165 | - 'label' => AllowedTags::$attributes, |
|
166 | - 'input' => AllowedTags::$attributes, |
|
167 | - 'select' => AllowedTags::$attributes, |
|
168 | - 'option' => AllowedTags::$attributes, |
|
169 | - 'optgroup' => AllowedTags::$attributes, |
|
170 | - 'textarea' => AllowedTags::$attributes, |
|
171 | - 'button' => AllowedTags::$attributes, |
|
172 | - 'fieldset' => AllowedTags::$attributes, |
|
173 | - 'output' => AllowedTags::$attributes, |
|
174 | - ]; |
|
175 | - AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * merges form script and style tags and attributes into the EE all tags |
|
181 | - */ |
|
182 | - private static function initializeWithScriptAndStyleTags() |
|
183 | - { |
|
184 | - $all_tags = AllowedTags::getAllowedTags(); |
|
185 | - $script_and_style_tags = [ |
|
186 | - 'script' => AllowedTags::$attributes, |
|
187 | - 'style' => AllowedTags::$attributes, |
|
188 | - 'link' => AllowedTags::$attributes, |
|
189 | - ]; |
|
190 | - AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @return array[] |
|
196 | - */ |
|
197 | - public static function getAllowedTags() |
|
198 | - { |
|
199 | - if (empty(AllowedTags::$allowed_tags)) { |
|
200 | - AllowedTags::initializeAllowedTags(); |
|
201 | - } |
|
202 | - return AllowedTags::$allowed_tags; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @return array[] |
|
208 | - */ |
|
209 | - public static function getWithEmbedTags() |
|
210 | - { |
|
211 | - if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
212 | - AllowedTags::initializeWithEmbedTags(); |
|
213 | - } |
|
214 | - return AllowedTags::$allowed_with_embed_tags; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * @return array[] |
|
220 | - */ |
|
221 | - public static function getWithFormTags() |
|
222 | - { |
|
223 | - if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
224 | - AllowedTags::initializeWithFormTags(); |
|
225 | - } |
|
226 | - return AllowedTags::$allowed_with_form_tags; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @return array[] |
|
232 | - */ |
|
233 | - public static function getWithScriptAndStyleTags() |
|
234 | - { |
|
235 | - if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
236 | - AllowedTags::initializeWithScriptAndStyleTags(); |
|
237 | - } |
|
238 | - return AllowedTags::$allowed_with_script_and_style_tags; |
|
239 | - } |
|
16 | + /** |
|
17 | + * @var array[] |
|
18 | + */ |
|
19 | + private static $attributes = [ |
|
20 | + 'accept-charset' => 1, |
|
21 | + 'action' => 1, |
|
22 | + 'alt' => 1, |
|
23 | + 'allow' => 1, |
|
24 | + 'allowfullscreen' => 1, |
|
25 | + 'align' => 1, |
|
26 | + 'aria-*' => 1, |
|
27 | + 'autocomplete' => 1, |
|
28 | + 'checked' => 1, |
|
29 | + 'class' => 1, |
|
30 | + 'cols' => 1, |
|
31 | + 'content' => 1, |
|
32 | + 'data-*' => 1, |
|
33 | + 'dir' => 1, |
|
34 | + 'disabled' => 1, |
|
35 | + 'enctype' => 1, |
|
36 | + 'for' => 1, |
|
37 | + 'frameborder' => 1, |
|
38 | + 'height' => 1, |
|
39 | + 'href' => 1, |
|
40 | + 'id' => 1, |
|
41 | + 'itemprop' => 1, |
|
42 | + 'itemscope' => 1, |
|
43 | + 'itemtype' => 1, |
|
44 | + 'label' => 1, |
|
45 | + 'lang' => 1, |
|
46 | + 'max' => 1, |
|
47 | + 'maxlength' => 1, |
|
48 | + 'method' => 1, |
|
49 | + 'min' => 1, |
|
50 | + 'multiple' => 1, |
|
51 | + 'name' => 1, |
|
52 | + 'novalidate' => 1, |
|
53 | + 'placeholder' => 1, |
|
54 | + 'readonly' => 1, |
|
55 | + 'rel' => 1, |
|
56 | + 'required' => 1, |
|
57 | + 'rows' => 1, |
|
58 | + 'selected' => 1, |
|
59 | + 'src' => 1, |
|
60 | + 'size' => 1, |
|
61 | + 'style' => 1, |
|
62 | + 'step' => 1, |
|
63 | + 'tabindex' => 1, |
|
64 | + 'target' => 1, |
|
65 | + 'title' => 1, |
|
66 | + 'type' => 1, |
|
67 | + 'value' => 1, |
|
68 | + 'width' => 1, |
|
69 | + ]; |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + private static $tags = [ |
|
76 | + 'a', |
|
77 | + 'abbr', |
|
78 | + 'b', |
|
79 | + 'br', |
|
80 | + 'code', |
|
81 | + 'div', |
|
82 | + 'em', |
|
83 | + 'h1', |
|
84 | + 'h2', |
|
85 | + 'h3', |
|
86 | + 'h4', |
|
87 | + 'h5', |
|
88 | + 'h6', |
|
89 | + 'hr', |
|
90 | + 'i', |
|
91 | + 'img', |
|
92 | + 'li', |
|
93 | + 'ol', |
|
94 | + 'p', |
|
95 | + 'pre', |
|
96 | + 'small', |
|
97 | + 'span', |
|
98 | + 'strong', |
|
99 | + 'table', |
|
100 | + 'td', |
|
101 | + 'tr', |
|
102 | + 'ul', |
|
103 | + ]; |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @var array |
|
108 | + */ |
|
109 | + private static $allowed_tags; |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + private static $allowed_with_embed_tags; |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @var array |
|
120 | + */ |
|
121 | + private static $allowed_with_form_tags; |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + private static $allowed_with_script_and_style_tags; |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * merges additional tags and attributes into the WP post tags |
|
132 | + */ |
|
133 | + private static function initializeAllowedTags() |
|
134 | + { |
|
135 | + $allowed_post_tags = wp_kses_allowed_html('post'); |
|
136 | + $allowed_tags = []; |
|
137 | + foreach (AllowedTags::$tags as $tag) { |
|
138 | + $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
139 | + } |
|
140 | + AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * merges embed tags and attributes into the EE all tags |
|
146 | + */ |
|
147 | + private static function initializeWithEmbedTags() |
|
148 | + { |
|
149 | + $all_tags = AllowedTags::getAllowedTags(); |
|
150 | + $embed_tags = [ |
|
151 | + 'iframe' => AllowedTags::$attributes |
|
152 | + ]; |
|
153 | + AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * merges form tags and attributes into the EE all tags |
|
159 | + */ |
|
160 | + private static function initializeWithFormTags() |
|
161 | + { |
|
162 | + $all_tags = AllowedTags::getAllowedTags(); |
|
163 | + $form_tags = [ |
|
164 | + 'form' => AllowedTags::$attributes, |
|
165 | + 'label' => AllowedTags::$attributes, |
|
166 | + 'input' => AllowedTags::$attributes, |
|
167 | + 'select' => AllowedTags::$attributes, |
|
168 | + 'option' => AllowedTags::$attributes, |
|
169 | + 'optgroup' => AllowedTags::$attributes, |
|
170 | + 'textarea' => AllowedTags::$attributes, |
|
171 | + 'button' => AllowedTags::$attributes, |
|
172 | + 'fieldset' => AllowedTags::$attributes, |
|
173 | + 'output' => AllowedTags::$attributes, |
|
174 | + ]; |
|
175 | + AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * merges form script and style tags and attributes into the EE all tags |
|
181 | + */ |
|
182 | + private static function initializeWithScriptAndStyleTags() |
|
183 | + { |
|
184 | + $all_tags = AllowedTags::getAllowedTags(); |
|
185 | + $script_and_style_tags = [ |
|
186 | + 'script' => AllowedTags::$attributes, |
|
187 | + 'style' => AllowedTags::$attributes, |
|
188 | + 'link' => AllowedTags::$attributes, |
|
189 | + ]; |
|
190 | + AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @return array[] |
|
196 | + */ |
|
197 | + public static function getAllowedTags() |
|
198 | + { |
|
199 | + if (empty(AllowedTags::$allowed_tags)) { |
|
200 | + AllowedTags::initializeAllowedTags(); |
|
201 | + } |
|
202 | + return AllowedTags::$allowed_tags; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @return array[] |
|
208 | + */ |
|
209 | + public static function getWithEmbedTags() |
|
210 | + { |
|
211 | + if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
212 | + AllowedTags::initializeWithEmbedTags(); |
|
213 | + } |
|
214 | + return AllowedTags::$allowed_with_embed_tags; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * @return array[] |
|
220 | + */ |
|
221 | + public static function getWithFormTags() |
|
222 | + { |
|
223 | + if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
224 | + AllowedTags::initializeWithFormTags(); |
|
225 | + } |
|
226 | + return AllowedTags::$allowed_with_form_tags; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @return array[] |
|
232 | + */ |
|
233 | + public static function getWithScriptAndStyleTags() |
|
234 | + { |
|
235 | + if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
236 | + AllowedTags::initializeWithScriptAndStyleTags(); |
|
237 | + } |
|
238 | + return AllowedTags::$allowed_with_script_and_style_tags; |
|
239 | + } |
|
240 | 240 | } |
@@ -14,22 +14,22 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function espresso_load_error_handling() |
16 | 16 | { |
17 | - static $error_handling_loaded = false; |
|
18 | - if ($error_handling_loaded) { |
|
19 | - return; |
|
20 | - } |
|
21 | - // load debugging tools |
|
22 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
23 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
24 | - EEH_Debug_Tools::instance(); |
|
25 | - } |
|
26 | - // load error handling |
|
27 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
28 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
29 | - } else { |
|
30 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
31 | - } |
|
32 | - $error_handling_loaded = true; |
|
17 | + static $error_handling_loaded = false; |
|
18 | + if ($error_handling_loaded) { |
|
19 | + return; |
|
20 | + } |
|
21 | + // load debugging tools |
|
22 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
23 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
24 | + EEH_Debug_Tools::instance(); |
|
25 | + } |
|
26 | + // load error handling |
|
27 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
28 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
29 | + } else { |
|
30 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
31 | + } |
|
32 | + $error_handling_loaded = true; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -43,19 +43,19 @@ discard block |
||
43 | 43 | */ |
44 | 44 | function espresso_load_required($classname, $full_path_to_file) |
45 | 45 | { |
46 | - if (is_readable($full_path_to_file)) { |
|
47 | - require_once $full_path_to_file; |
|
48 | - } else { |
|
49 | - throw new EE_Error( |
|
50 | - sprintf( |
|
51 | - esc_html__( |
|
52 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
53 | - 'event_espresso' |
|
54 | - ), |
|
55 | - $classname |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
46 | + if (is_readable($full_path_to_file)) { |
|
47 | + require_once $full_path_to_file; |
|
48 | + } else { |
|
49 | + throw new EE_Error( |
|
50 | + sprintf( |
|
51 | + esc_html__( |
|
52 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
53 | + 'event_espresso' |
|
54 | + ), |
|
55 | + $classname |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | |
@@ -73,52 +73,52 @@ discard block |
||
73 | 73 | */ |
74 | 74 | function bootstrap_espresso() |
75 | 75 | { |
76 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
77 | - try { |
|
78 | - espresso_load_error_handling(); |
|
79 | - // include WordPress shims for functions introduced in later versions of WordPress |
|
80 | - espresso_load_required( |
|
81 | - '', |
|
82 | - EE_CORE . 'wordpress-shims.php' |
|
83 | - ); |
|
84 | - espresso_load_required( |
|
85 | - '', |
|
86 | - EE_CORE . 'third-party-compatibility.php' |
|
87 | - ); |
|
88 | - espresso_load_required( |
|
89 | - 'EEH_Base', |
|
90 | - EE_CORE . 'helpers/EEH_Base.helper.php' |
|
91 | - ); |
|
92 | - espresso_load_required( |
|
93 | - 'EEH_File', |
|
94 | - EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
95 | - ); |
|
96 | - espresso_load_required( |
|
97 | - 'EEH_File', |
|
98 | - EE_CORE . 'helpers/EEH_File.helper.php' |
|
99 | - ); |
|
100 | - espresso_load_required( |
|
101 | - 'EEH_Array', |
|
102 | - EE_CORE . 'helpers/EEH_Array.helper.php' |
|
103 | - ); |
|
104 | - espresso_load_required( |
|
105 | - 'EE_Base', |
|
106 | - EE_CORE . 'EE_Base.core.php' |
|
107 | - ); |
|
108 | - // instantiate and configure PSR4 autoloader |
|
109 | - espresso_load_required( |
|
110 | - 'Psr4Autoloader', |
|
111 | - EE_CORE . 'Psr4Autoloader.php' |
|
112 | - ); |
|
113 | - espresso_load_required( |
|
114 | - 'EE_Psr4AutoloaderInit', |
|
115 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
116 | - ); |
|
117 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
118 | - $AutoloaderInit->initializeAutoloader(); |
|
119 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
120 | - } catch (Exception $e) { |
|
121 | - require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
122 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
123 | - } |
|
76 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
77 | + try { |
|
78 | + espresso_load_error_handling(); |
|
79 | + // include WordPress shims for functions introduced in later versions of WordPress |
|
80 | + espresso_load_required( |
|
81 | + '', |
|
82 | + EE_CORE . 'wordpress-shims.php' |
|
83 | + ); |
|
84 | + espresso_load_required( |
|
85 | + '', |
|
86 | + EE_CORE . 'third-party-compatibility.php' |
|
87 | + ); |
|
88 | + espresso_load_required( |
|
89 | + 'EEH_Base', |
|
90 | + EE_CORE . 'helpers/EEH_Base.helper.php' |
|
91 | + ); |
|
92 | + espresso_load_required( |
|
93 | + 'EEH_File', |
|
94 | + EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
95 | + ); |
|
96 | + espresso_load_required( |
|
97 | + 'EEH_File', |
|
98 | + EE_CORE . 'helpers/EEH_File.helper.php' |
|
99 | + ); |
|
100 | + espresso_load_required( |
|
101 | + 'EEH_Array', |
|
102 | + EE_CORE . 'helpers/EEH_Array.helper.php' |
|
103 | + ); |
|
104 | + espresso_load_required( |
|
105 | + 'EE_Base', |
|
106 | + EE_CORE . 'EE_Base.core.php' |
|
107 | + ); |
|
108 | + // instantiate and configure PSR4 autoloader |
|
109 | + espresso_load_required( |
|
110 | + 'Psr4Autoloader', |
|
111 | + EE_CORE . 'Psr4Autoloader.php' |
|
112 | + ); |
|
113 | + espresso_load_required( |
|
114 | + 'EE_Psr4AutoloaderInit', |
|
115 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
116 | + ); |
|
117 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
118 | + $AutoloaderInit->initializeAutoloader(); |
|
119 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
120 | + } catch (Exception $e) { |
|
121 | + require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
122 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
123 | + } |
|
124 | 124 | } |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | return; |
20 | 20 | } |
21 | 21 | // load debugging tools |
22 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
23 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
22 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
23 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
24 | 24 | EEH_Debug_Tools::instance(); |
25 | 25 | } |
26 | 26 | // load error handling |
27 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
28 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
27 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
28 | + require_once EE_CORE.'EE_Error.core.php'; |
|
29 | 29 | } else { |
30 | 30 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
31 | 31 | } |
@@ -73,52 +73,52 @@ discard block |
||
73 | 73 | */ |
74 | 74 | function bootstrap_espresso() |
75 | 75 | { |
76 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
76 | + require_once __DIR__.'/espresso_definitions.php'; |
|
77 | 77 | try { |
78 | 78 | espresso_load_error_handling(); |
79 | 79 | // include WordPress shims for functions introduced in later versions of WordPress |
80 | 80 | espresso_load_required( |
81 | 81 | '', |
82 | - EE_CORE . 'wordpress-shims.php' |
|
82 | + EE_CORE.'wordpress-shims.php' |
|
83 | 83 | ); |
84 | 84 | espresso_load_required( |
85 | 85 | '', |
86 | - EE_CORE . 'third-party-compatibility.php' |
|
86 | + EE_CORE.'third-party-compatibility.php' |
|
87 | 87 | ); |
88 | 88 | espresso_load_required( |
89 | 89 | 'EEH_Base', |
90 | - EE_CORE . 'helpers/EEH_Base.helper.php' |
|
90 | + EE_CORE.'helpers/EEH_Base.helper.php' |
|
91 | 91 | ); |
92 | 92 | espresso_load_required( |
93 | 93 | 'EEH_File', |
94 | - EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
94 | + EE_CORE.'interfaces/EEHI_File.interface.php' |
|
95 | 95 | ); |
96 | 96 | espresso_load_required( |
97 | 97 | 'EEH_File', |
98 | - EE_CORE . 'helpers/EEH_File.helper.php' |
|
98 | + EE_CORE.'helpers/EEH_File.helper.php' |
|
99 | 99 | ); |
100 | 100 | espresso_load_required( |
101 | 101 | 'EEH_Array', |
102 | - EE_CORE . 'helpers/EEH_Array.helper.php' |
|
102 | + EE_CORE.'helpers/EEH_Array.helper.php' |
|
103 | 103 | ); |
104 | 104 | espresso_load_required( |
105 | 105 | 'EE_Base', |
106 | - EE_CORE . 'EE_Base.core.php' |
|
106 | + EE_CORE.'EE_Base.core.php' |
|
107 | 107 | ); |
108 | 108 | // instantiate and configure PSR4 autoloader |
109 | 109 | espresso_load_required( |
110 | 110 | 'Psr4Autoloader', |
111 | - EE_CORE . 'Psr4Autoloader.php' |
|
111 | + EE_CORE.'Psr4Autoloader.php' |
|
112 | 112 | ); |
113 | 113 | espresso_load_required( |
114 | 114 | 'EE_Psr4AutoloaderInit', |
115 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
115 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
116 | 116 | ); |
117 | 117 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
118 | 118 | $AutoloaderInit->initializeAutoloader(); |
119 | 119 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
120 | 120 | } catch (Exception $e) { |
121 | - require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
121 | + require_once EE_CORE.'exceptions/ExceptionStackTraceDisplay.php'; |
|
122 | 122 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
123 | 123 | } |
124 | 124 | } |
@@ -20,161 +20,161 @@ discard block |
||
20 | 20 | class ExceptionStackTraceDisplay |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var string |
|
25 | - * @since 4.10.24.p |
|
26 | - */ |
|
27 | - private $class_name = ''; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + * @since 4.10.24.p |
|
26 | + */ |
|
27 | + private $class_name = ''; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var string |
|
31 | - * @since 4.10.24.p |
|
32 | - */ |
|
33 | - private $error_code = ''; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + * @since 4.10.24.p |
|
32 | + */ |
|
33 | + private $error_code = ''; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @param Exception $exception |
|
38 | - * @throws Exception |
|
39 | - */ |
|
40 | - public function __construct(Exception $exception) |
|
41 | - { |
|
42 | - if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
43 | - $this->displayException($exception); |
|
44 | - } else { |
|
45 | - throw $exception; |
|
46 | - } |
|
47 | - } |
|
36 | + /** |
|
37 | + * @param Exception $exception |
|
38 | + * @throws Exception |
|
39 | + */ |
|
40 | + public function __construct(Exception $exception) |
|
41 | + { |
|
42 | + if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
43 | + $this->displayException($exception); |
|
44 | + } else { |
|
45 | + throw $exception; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @access protected |
|
52 | - * @param Exception $exception |
|
53 | - * @throws ReflectionException |
|
54 | - */ |
|
55 | - protected function displayException(Exception $exception) |
|
56 | - { |
|
57 | - // get separate user and developer messages if they exist |
|
58 | - $msg = explode('||', $exception->getMessage()); |
|
59 | - $user_msg = $msg[0]; |
|
60 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
61 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
62 | - // process trace info |
|
63 | - $trace_details = $this->traceDetails($exception); |
|
64 | - $code = $exception->getCode() ?: $this->error_code; |
|
65 | - // add helpful developer messages if debugging is on |
|
66 | - // or generic non-identifying messages for non-privileged users |
|
67 | - $error_message = WP_DEBUG |
|
68 | - ? $this->developerError($exception, $msg, $code, $trace_details) |
|
69 | - : $this->genericError($msg, $code); |
|
70 | - // start gathering output |
|
71 | - $output = '<div id="ee-error-message" class="error"> |
|
50 | + /** |
|
51 | + * @access protected |
|
52 | + * @param Exception $exception |
|
53 | + * @throws ReflectionException |
|
54 | + */ |
|
55 | + protected function displayException(Exception $exception) |
|
56 | + { |
|
57 | + // get separate user and developer messages if they exist |
|
58 | + $msg = explode('||', $exception->getMessage()); |
|
59 | + $user_msg = $msg[0]; |
|
60 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
61 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
62 | + // process trace info |
|
63 | + $trace_details = $this->traceDetails($exception); |
|
64 | + $code = $exception->getCode() ?: $this->error_code; |
|
65 | + // add helpful developer messages if debugging is on |
|
66 | + // or generic non-identifying messages for non-privileged users |
|
67 | + $error_message = WP_DEBUG |
|
68 | + ? $this->developerError($exception, $msg, $code, $trace_details) |
|
69 | + : $this->genericError($msg, $code); |
|
70 | + // start gathering output |
|
71 | + $output = '<div id="ee-error-message" class="error"> |
|
72 | 72 | ' . $error_message . ' |
73 | 73 | </div>'; |
74 | - $scripts = $this->printScripts(true); |
|
75 | - if (defined('DOING_AJAX')) { |
|
76 | - echo wp_json_encode(array('error' => $output . $scripts)); |
|
77 | - exit(); |
|
78 | - } |
|
79 | - echo wp_kses($output . $scripts, AllowedTags::getWithScriptAndStyleTags()); |
|
80 | - } |
|
74 | + $scripts = $this->printScripts(true); |
|
75 | + if (defined('DOING_AJAX')) { |
|
76 | + echo wp_json_encode(array('error' => $output . $scripts)); |
|
77 | + exit(); |
|
78 | + } |
|
79 | + echo wp_kses($output . $scripts, AllowedTags::getWithScriptAndStyleTags()); |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - private function genericError($msg, $code) |
|
84 | - { |
|
85 | - return '<p> |
|
83 | + private function genericError($msg, $code) |
|
84 | + { |
|
85 | + return '<p> |
|
86 | 86 | <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> <sup>' . $code . '</sup> |
87 | 87 | </p>'; |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - /** |
|
92 | - * @param Exception $exception |
|
93 | - * @param $msg |
|
94 | - * @param $code |
|
95 | - * @param $trace_details |
|
96 | - * @return string |
|
97 | - * @throws ReflectionException |
|
98 | - */ |
|
99 | - private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
100 | - { |
|
101 | - $time = time(); |
|
102 | - return ' |
|
91 | + /** |
|
92 | + * @param Exception $exception |
|
93 | + * @param $msg |
|
94 | + * @param $code |
|
95 | + * @param $trace_details |
|
96 | + * @return string |
|
97 | + * @throws ReflectionException |
|
98 | + */ |
|
99 | + private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
100 | + { |
|
101 | + $time = time(); |
|
102 | + return ' |
|
103 | 103 | <div class="ee-error-dev-msg-dv"> |
104 | 104 | <p class="ee-error-dev-msg-pg"> |
105 | 105 | ' |
106 | - . sprintf( |
|
107 | - esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
108 | - '<strong class="ee-error-dev-msg-str">', |
|
109 | - get_class($exception), |
|
110 | - '</strong> <span>', |
|
111 | - $code . '</span>' |
|
112 | - ) |
|
113 | - . '<br /> |
|
106 | + . sprintf( |
|
107 | + esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
108 | + '<strong class="ee-error-dev-msg-str">', |
|
109 | + get_class($exception), |
|
110 | + '</strong> <span>', |
|
111 | + $code . '</span>' |
|
112 | + ) |
|
113 | + . '<br /> |
|
114 | 114 | <span class="big-text">"' . trim($msg) . '"</span><br/> |
115 | 115 | <a id="display-ee-error-trace-1' |
116 | - . $time |
|
117 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
118 | - . $time |
|
119 | - . '"> |
|
116 | + . $time |
|
117 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
118 | + . $time |
|
119 | + . '"> |
|
120 | 120 | ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . ' |
121 | 121 | </a><br /> |
122 | 122 | ' |
123 | - . $exception->getFile() |
|
124 | - . sprintf( |
|
125 | - esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
126 | - ' <span class="small-text lt-grey-text">', |
|
127 | - $exception->getLine(), |
|
128 | - '</span>' |
|
129 | - ) |
|
130 | - . ' |
|
123 | + . $exception->getFile() |
|
124 | + . sprintf( |
|
125 | + esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
126 | + ' <span class="small-text lt-grey-text">', |
|
127 | + $exception->getLine(), |
|
128 | + '</span>' |
|
129 | + ) |
|
130 | + . ' |
|
131 | 131 | </p> |
132 | 132 | <div id="ee-error-trace-1' |
133 | - . $time |
|
134 | - . '-dv" class="ee-error-trace-dv hidden"> |
|
133 | + . $time |
|
134 | + . '-dv" class="ee-error-trace-dv hidden"> |
|
135 | 135 | ' |
136 | - . $trace_details |
|
137 | - . $this->classDetails() . ' |
|
136 | + . $trace_details |
|
137 | + . $this->classDetails() . ' |
|
138 | 138 | </div> |
139 | 139 | </div>'; |
140 | - } |
|
140 | + } |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * @throws ReflectionException |
|
145 | - */ |
|
146 | - private function classDetails() |
|
147 | - { |
|
148 | - if (empty($this->class_name)) { |
|
149 | - return ''; |
|
150 | - } |
|
151 | - $a = new ReflectionClass($this->class_name); |
|
152 | - return ' |
|
143 | + /** |
|
144 | + * @throws ReflectionException |
|
145 | + */ |
|
146 | + private function classDetails() |
|
147 | + { |
|
148 | + if (empty($this->class_name)) { |
|
149 | + return ''; |
|
150 | + } |
|
151 | + $a = new ReflectionClass($this->class_name); |
|
152 | + return ' |
|
153 | 153 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
154 | 154 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
155 | 155 | <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3> |
156 | 156 | <pre>' . $a . '</pre> |
157 | 157 | </div> |
158 | 158 | </div>'; |
159 | - } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @param Exception $exception |
|
163 | - * @return string |
|
164 | - * @throws ReflectionException |
|
165 | - * @since 4.10.24.p |
|
166 | - */ |
|
167 | - private function traceDetails(Exception $exception) |
|
168 | - { |
|
169 | - $trace = $exception->getTrace(); |
|
170 | - if (empty($trace)) { |
|
171 | - return esc_html__( |
|
172 | - 'Sorry, but no trace information was available for this exception.', |
|
173 | - 'event_espresso' |
|
174 | - ); |
|
175 | - } |
|
161 | + /** |
|
162 | + * @param Exception $exception |
|
163 | + * @return string |
|
164 | + * @throws ReflectionException |
|
165 | + * @since 4.10.24.p |
|
166 | + */ |
|
167 | + private function traceDetails(Exception $exception) |
|
168 | + { |
|
169 | + $trace = $exception->getTrace(); |
|
170 | + if (empty($trace)) { |
|
171 | + return esc_html__( |
|
172 | + 'Sorry, but no trace information was available for this exception.', |
|
173 | + 'event_espresso' |
|
174 | + ); |
|
175 | + } |
|
176 | 176 | |
177 | - $trace_details = ' |
|
177 | + $trace_details = ' |
|
178 | 178 | <div id="ee-trace-details"> |
179 | 179 | <table> |
180 | 180 | <tr> |
@@ -183,189 +183,189 @@ discard block |
||
183 | 183 | <th scope="col" class="ee-align-left" style="width:40%;">File</th> |
184 | 184 | <th scope="col" class="ee-align-left"> |
185 | 185 | ' . esc_html__('Class', 'event_espresso') |
186 | - . '->' |
|
187 | - . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
186 | + . '->' |
|
187 | + . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
188 | 188 | </th> |
189 | 189 | </tr>'; |
190 | - $last_on_stack = count($trace) - 1; |
|
191 | - // reverse array so that stack is in proper chronological order |
|
192 | - $sorted_trace = array_reverse($trace); |
|
193 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
194 | - $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
195 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
196 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
197 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
198 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
199 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
200 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
201 | - if (empty($file) && ! empty($this->class_name)) { |
|
202 | - $a = new ReflectionClass($this->class_name); |
|
203 | - $file = $a->getFileName(); |
|
204 | - if (empty($line) && ! empty($function)) { |
|
205 | - try { |
|
206 | - // if $function is a closure, this throws an exception |
|
207 | - $b = new ReflectionMethod($this->class_name, $function); |
|
208 | - $line = $b->getStartLine(); |
|
209 | - } catch (Exception $closure_exception) { |
|
210 | - $line = 'unknown'; |
|
211 | - } |
|
212 | - } |
|
213 | - } |
|
214 | - if ($nmbr === $last_on_stack) { |
|
215 | - $file = $exception->getFile() ?: $file; |
|
216 | - $line = $exception->getLine() ?: $line; |
|
217 | - $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
218 | - } |
|
219 | - $file = EEH_File::standardise_directory_separators($file); |
|
220 | - $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
221 | - $line = ! empty($line) ? $line : ' '; |
|
222 | - $file = ! empty($file) ? $file : ' '; |
|
223 | - $type = ! empty($type) ? $type : ''; |
|
224 | - $function = ! empty($function) ? $function : ''; |
|
225 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
226 | - $trace_details .= ' |
|
190 | + $last_on_stack = count($trace) - 1; |
|
191 | + // reverse array so that stack is in proper chronological order |
|
192 | + $sorted_trace = array_reverse($trace); |
|
193 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
194 | + $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
195 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
196 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
197 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
198 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
199 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
200 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
201 | + if (empty($file) && ! empty($this->class_name)) { |
|
202 | + $a = new ReflectionClass($this->class_name); |
|
203 | + $file = $a->getFileName(); |
|
204 | + if (empty($line) && ! empty($function)) { |
|
205 | + try { |
|
206 | + // if $function is a closure, this throws an exception |
|
207 | + $b = new ReflectionMethod($this->class_name, $function); |
|
208 | + $line = $b->getStartLine(); |
|
209 | + } catch (Exception $closure_exception) { |
|
210 | + $line = 'unknown'; |
|
211 | + } |
|
212 | + } |
|
213 | + } |
|
214 | + if ($nmbr === $last_on_stack) { |
|
215 | + $file = $exception->getFile() ?: $file; |
|
216 | + $line = $exception->getLine() ?: $line; |
|
217 | + $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
218 | + } |
|
219 | + $file = EEH_File::standardise_directory_separators($file); |
|
220 | + $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
221 | + $line = ! empty($line) ? $line : ' '; |
|
222 | + $file = ! empty($file) ? $file : ' '; |
|
223 | + $type = ! empty($type) ? $type : ''; |
|
224 | + $function = ! empty($function) ? $function : ''; |
|
225 | + $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
226 | + $trace_details .= ' |
|
227 | 227 | <tr> |
228 | 228 | <td class="ee-align-right">' . $nmbr . '</td> |
229 | 229 | <td class="ee-align-right">' . $line . '</td> |
230 | 230 | <td class="ee-align-left">' . $file . '</td> |
231 | 231 | <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td> |
232 | 232 | </tr>'; |
233 | - } |
|
234 | - $trace_details .= ' |
|
233 | + } |
|
234 | + $trace_details .= ' |
|
235 | 235 | </table> |
236 | 236 | </div>'; |
237 | - return $trace_details; |
|
238 | - } |
|
237 | + return $trace_details; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | |
241 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
242 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
241 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
242 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
243 | 243 | |
244 | - /** |
|
245 | - * generate string from exception trace args |
|
246 | - * |
|
247 | - * @param array $arguments |
|
248 | - * @param int $indent |
|
249 | - * @param bool $array |
|
250 | - * @return string |
|
251 | - */ |
|
252 | - private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
253 | - { |
|
254 | - $args = array(); |
|
255 | - $args_count = count($arguments); |
|
256 | - if ($args_count > 2) { |
|
257 | - $indent++; |
|
258 | - $args[] = '<br />'; |
|
259 | - } |
|
260 | - $x = 0; |
|
261 | - foreach ($arguments as $arg) { |
|
262 | - $x++; |
|
263 | - for ($i = 0; $i < $indent; $i++) { |
|
264 | - $args[] = ' '; |
|
265 | - } |
|
266 | - if (is_string($arg)) { |
|
267 | - if (! $array && strlen($arg) > 75) { |
|
268 | - $args[] = '<br />'; |
|
269 | - for ($i = 0; $i <= $indent; $i++) { |
|
270 | - $args[] = ' '; |
|
271 | - } |
|
272 | - $args[] = "'" . $arg . "'<br />"; |
|
273 | - } else { |
|
274 | - $args[] = " '" . $arg . "'"; |
|
275 | - } |
|
276 | - } elseif (is_array($arg)) { |
|
277 | - $arg_count = count($arg); |
|
278 | - if ($arg_count > 2) { |
|
279 | - $indent++; |
|
280 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
281 | - $indent--; |
|
282 | - } elseif ($arg_count === 0) { |
|
283 | - $args[] = ' array()'; |
|
284 | - } else { |
|
285 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
286 | - } |
|
287 | - } elseif ($arg === null) { |
|
288 | - $args[] = ' null'; |
|
289 | - } elseif (is_bool($arg)) { |
|
290 | - $args[] = $arg ? ' true' : ' false'; |
|
291 | - } elseif (is_object($arg)) { |
|
292 | - $args[] = get_class($arg); |
|
293 | - } elseif (is_resource($arg)) { |
|
294 | - $args[] = get_resource_type($arg); |
|
295 | - } else { |
|
296 | - $args[] = $arg; |
|
297 | - } |
|
298 | - if ($x === $args_count) { |
|
299 | - if ($args_count > 2) { |
|
300 | - $args[] = '<br />'; |
|
301 | - $indent--; |
|
302 | - for ($i = 1; $i < $indent; $i++) { |
|
303 | - $args[] = ' '; |
|
304 | - } |
|
305 | - } |
|
306 | - } else { |
|
307 | - $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
308 | - } |
|
309 | - } |
|
310 | - return implode('', $args); |
|
311 | - } |
|
244 | + /** |
|
245 | + * generate string from exception trace args |
|
246 | + * |
|
247 | + * @param array $arguments |
|
248 | + * @param int $indent |
|
249 | + * @param bool $array |
|
250 | + * @return string |
|
251 | + */ |
|
252 | + private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
253 | + { |
|
254 | + $args = array(); |
|
255 | + $args_count = count($arguments); |
|
256 | + if ($args_count > 2) { |
|
257 | + $indent++; |
|
258 | + $args[] = '<br />'; |
|
259 | + } |
|
260 | + $x = 0; |
|
261 | + foreach ($arguments as $arg) { |
|
262 | + $x++; |
|
263 | + for ($i = 0; $i < $indent; $i++) { |
|
264 | + $args[] = ' '; |
|
265 | + } |
|
266 | + if (is_string($arg)) { |
|
267 | + if (! $array && strlen($arg) > 75) { |
|
268 | + $args[] = '<br />'; |
|
269 | + for ($i = 0; $i <= $indent; $i++) { |
|
270 | + $args[] = ' '; |
|
271 | + } |
|
272 | + $args[] = "'" . $arg . "'<br />"; |
|
273 | + } else { |
|
274 | + $args[] = " '" . $arg . "'"; |
|
275 | + } |
|
276 | + } elseif (is_array($arg)) { |
|
277 | + $arg_count = count($arg); |
|
278 | + if ($arg_count > 2) { |
|
279 | + $indent++; |
|
280 | + $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
281 | + $indent--; |
|
282 | + } elseif ($arg_count === 0) { |
|
283 | + $args[] = ' array()'; |
|
284 | + } else { |
|
285 | + $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
286 | + } |
|
287 | + } elseif ($arg === null) { |
|
288 | + $args[] = ' null'; |
|
289 | + } elseif (is_bool($arg)) { |
|
290 | + $args[] = $arg ? ' true' : ' false'; |
|
291 | + } elseif (is_object($arg)) { |
|
292 | + $args[] = get_class($arg); |
|
293 | + } elseif (is_resource($arg)) { |
|
294 | + $args[] = get_resource_type($arg); |
|
295 | + } else { |
|
296 | + $args[] = $arg; |
|
297 | + } |
|
298 | + if ($x === $args_count) { |
|
299 | + if ($args_count > 2) { |
|
300 | + $args[] = '<br />'; |
|
301 | + $indent--; |
|
302 | + for ($i = 1; $i < $indent; $i++) { |
|
303 | + $args[] = ' '; |
|
304 | + } |
|
305 | + } |
|
306 | + } else { |
|
307 | + $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
308 | + } |
|
309 | + } |
|
310 | + return implode('', $args); |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | - /** |
|
315 | - * create error code from filepath, function name, |
|
316 | - * and line number where exception or error was thrown |
|
317 | - * |
|
318 | - * @access protected |
|
319 | - * @param string $file |
|
320 | - * @param string $func |
|
321 | - * @param string $line |
|
322 | - * @return string |
|
323 | - */ |
|
324 | - protected function generate_error_code($file = '', $func = '', $line = '') |
|
325 | - { |
|
326 | - $file_bits = explode('.', basename($file)); |
|
327 | - $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
328 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
329 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
330 | - return $error_code; |
|
331 | - } |
|
314 | + /** |
|
315 | + * create error code from filepath, function name, |
|
316 | + * and line number where exception or error was thrown |
|
317 | + * |
|
318 | + * @access protected |
|
319 | + * @param string $file |
|
320 | + * @param string $func |
|
321 | + * @param string $line |
|
322 | + * @return string |
|
323 | + */ |
|
324 | + protected function generate_error_code($file = '', $func = '', $line = '') |
|
325 | + { |
|
326 | + $file_bits = explode('.', basename($file)); |
|
327 | + $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
328 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
329 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
330 | + return $error_code; |
|
331 | + } |
|
332 | 332 | |
333 | 333 | |
334 | - /** |
|
335 | - * @return string |
|
336 | - */ |
|
337 | - private function exceptionStyles() |
|
338 | - { |
|
339 | - return ''; |
|
340 | - } |
|
334 | + /** |
|
335 | + * @return string |
|
336 | + */ |
|
337 | + private function exceptionStyles() |
|
338 | + { |
|
339 | + return ''; |
|
340 | + } |
|
341 | 341 | |
342 | 342 | |
343 | - /** |
|
344 | - * _print_scripts |
|
345 | - * |
|
346 | - * @param bool $force_print |
|
347 | - * @return string |
|
348 | - */ |
|
349 | - private function printScripts($force_print = false) |
|
350 | - { |
|
351 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
352 | - // if script is already enqueued then we can just get out |
|
353 | - if (wp_script_is('ee_error_js')) { |
|
354 | - return ''; |
|
355 | - } |
|
356 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
357 | - wp_enqueue_style('espresso_default'); |
|
358 | - wp_enqueue_style('espresso_custom_css'); |
|
359 | - wp_enqueue_script('ee_error_js'); |
|
360 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
361 | - return ''; |
|
362 | - } |
|
363 | - } |
|
364 | - $jquery = includes_url() . 'js/jquery/jquery.js'; |
|
365 | - $core = EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version(); |
|
366 | - $ee_error = EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version(); |
|
367 | - $style = EE_GLOBAL_ASSETS_URL . 'css/ee-exception-stack-display.css'; |
|
368 | - return ' |
|
343 | + /** |
|
344 | + * _print_scripts |
|
345 | + * |
|
346 | + * @param bool $force_print |
|
347 | + * @return string |
|
348 | + */ |
|
349 | + private function printScripts($force_print = false) |
|
350 | + { |
|
351 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
352 | + // if script is already enqueued then we can just get out |
|
353 | + if (wp_script_is('ee_error_js')) { |
|
354 | + return ''; |
|
355 | + } |
|
356 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
357 | + wp_enqueue_style('espresso_default'); |
|
358 | + wp_enqueue_style('espresso_custom_css'); |
|
359 | + wp_enqueue_script('ee_error_js'); |
|
360 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
361 | + return ''; |
|
362 | + } |
|
363 | + } |
|
364 | + $jquery = includes_url() . 'js/jquery/jquery.js'; |
|
365 | + $core = EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version(); |
|
366 | + $ee_error = EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version(); |
|
367 | + $style = EE_GLOBAL_ASSETS_URL . 'css/ee-exception-stack-display.css'; |
|
368 | + return ' |
|
369 | 369 | <script> |
370 | 370 | const ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
371 | 371 | </script> |
@@ -374,5 +374,5 @@ discard block |
||
374 | 374 | <script src="' . esc_url_raw($ee_error) . '" type="text/javascript"></script> |
375 | 375 | <link href="' . esc_url_raw($style) . '" rel="stylesheet" /> |
376 | 376 | '; |
377 | - } |
|
377 | + } |
|
378 | 378 | } |
@@ -69,21 +69,21 @@ discard block |
||
69 | 69 | : $this->genericError($msg, $code); |
70 | 70 | // start gathering output |
71 | 71 | $output = '<div id="ee-error-message" class="error"> |
72 | - ' . $error_message . ' |
|
72 | + ' . $error_message.' |
|
73 | 73 | </div>'; |
74 | 74 | $scripts = $this->printScripts(true); |
75 | 75 | if (defined('DOING_AJAX')) { |
76 | - echo wp_json_encode(array('error' => $output . $scripts)); |
|
76 | + echo wp_json_encode(array('error' => $output.$scripts)); |
|
77 | 77 | exit(); |
78 | 78 | } |
79 | - echo wp_kses($output . $scripts, AllowedTags::getWithScriptAndStyleTags()); |
|
79 | + echo wp_kses($output.$scripts, AllowedTags::getWithScriptAndStyleTags()); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | |
83 | 83 | private function genericError($msg, $code) |
84 | 84 | { |
85 | 85 | return '<p> |
86 | - <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> <sup>' . $code . '</sup> |
|
86 | + <span class="ee-error-user-msg-spn">' . trim($msg).'</span> <sup>'.$code.'</sup> |
|
87 | 87 | </p>'; |
88 | 88 | } |
89 | 89 | |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | '<strong class="ee-error-dev-msg-str">', |
109 | 109 | get_class($exception), |
110 | 110 | '</strong> <span>', |
111 | - $code . '</span>' |
|
111 | + $code.'</span>' |
|
112 | 112 | ) |
113 | 113 | . '<br /> |
114 | - <span class="big-text">"' . trim($msg) . '"</span><br/> |
|
114 | + <span class="big-text">"' . trim($msg).'"</span><br/> |
|
115 | 115 | <a id="display-ee-error-trace-1' |
116 | 116 | . $time |
117 | 117 | . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
118 | 118 | . $time |
119 | 119 | . '"> |
120 | - ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . ' |
|
120 | + ' . esc_html__('click to view backtrace and class/method details', 'event_espresso').' |
|
121 | 121 | </a><br /> |
122 | 122 | ' |
123 | 123 | . $exception->getFile() |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | . '-dv" class="ee-error-trace-dv hidden"> |
135 | 135 | ' |
136 | 136 | . $trace_details |
137 | - . $this->classDetails() . ' |
|
137 | + . $this->classDetails().' |
|
138 | 138 | </div> |
139 | 139 | </div>'; |
140 | 140 | } |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | return ' |
153 | 153 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
154 | 154 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
155 | - <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3> |
|
156 | - <pre>' . $a . '</pre> |
|
155 | + <h3>' . esc_html__('Class Details', 'event_espresso').'</h3> |
|
156 | + <pre>' . $a.'</pre> |
|
157 | 157 | </div> |
158 | 158 | </div>'; |
159 | 159 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | <th scope="col" class="ee-align-left"> |
185 | 185 | ' . esc_html__('Class', 'event_espresso') |
186 | 186 | . '->' |
187 | - . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
187 | + . esc_html__('Method( arguments )', 'event_espresso').' |
|
188 | 188 | </th> |
189 | 189 | </tr>'; |
190 | 190 | $last_on_stack = count($trace) - 1; |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $type = isset($trace['type']) ? $trace['type'] : ''; |
197 | 197 | $function = isset($trace['function']) ? $trace['function'] : ''; |
198 | 198 | $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
199 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
199 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args; |
|
200 | 200 | $line = isset($trace['line']) ? $trace['line'] : ''; |
201 | 201 | if (empty($file) && ! empty($this->class_name)) { |
202 | 202 | $a = new ReflectionClass($this->class_name); |
@@ -222,13 +222,13 @@ discard block |
||
222 | 222 | $file = ! empty($file) ? $file : ' '; |
223 | 223 | $type = ! empty($type) ? $type : ''; |
224 | 224 | $function = ! empty($function) ? $function : ''; |
225 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
225 | + $args = ! empty($args) ? '( '.$args.' )' : '()'; |
|
226 | 226 | $trace_details .= ' |
227 | 227 | <tr> |
228 | - <td class="ee-align-right">' . $nmbr . '</td> |
|
229 | - <td class="ee-align-right">' . $line . '</td> |
|
230 | - <td class="ee-align-left">' . $file . '</td> |
|
231 | - <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td> |
|
228 | + <td class="ee-align-right">' . $nmbr.'</td> |
|
229 | + <td class="ee-align-right">' . $line.'</td> |
|
230 | + <td class="ee-align-left">' . $file.'</td> |
|
231 | + <td class="ee-align-left">' . $this->class_name.$type.$function.$args.'</td> |
|
232 | 232 | </tr>'; |
233 | 233 | } |
234 | 234 | $trace_details .= ' |
@@ -264,25 +264,25 @@ discard block |
||
264 | 264 | $args[] = ' '; |
265 | 265 | } |
266 | 266 | if (is_string($arg)) { |
267 | - if (! $array && strlen($arg) > 75) { |
|
267 | + if ( ! $array && strlen($arg) > 75) { |
|
268 | 268 | $args[] = '<br />'; |
269 | 269 | for ($i = 0; $i <= $indent; $i++) { |
270 | 270 | $args[] = ' '; |
271 | 271 | } |
272 | - $args[] = "'" . $arg . "'<br />"; |
|
272 | + $args[] = "'".$arg."'<br />"; |
|
273 | 273 | } else { |
274 | - $args[] = " '" . $arg . "'"; |
|
274 | + $args[] = " '".$arg."'"; |
|
275 | 275 | } |
276 | 276 | } elseif (is_array($arg)) { |
277 | 277 | $arg_count = count($arg); |
278 | 278 | if ($arg_count > 2) { |
279 | 279 | $indent++; |
280 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
280 | + $args[] = ' array('.$this->_convert_args_to_string($arg, $indent, true).')'; |
|
281 | 281 | $indent--; |
282 | 282 | } elseif ($arg_count === 0) { |
283 | 283 | $args[] = ' array()'; |
284 | 284 | } else { |
285 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
285 | + $args[] = ' array( '.$this->_convert_args_to_string($arg).' )'; |
|
286 | 286 | } |
287 | 287 | } elseif ($arg === null) { |
288 | 288 | $args[] = ' null'; |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | { |
326 | 326 | $file_bits = explode('.', basename($file)); |
327 | 327 | $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
328 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
329 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
328 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
329 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
330 | 330 | return $error_code; |
331 | 331 | } |
332 | 332 | |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | */ |
349 | 349 | private function printScripts($force_print = false) |
350 | 350 | { |
351 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
351 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
352 | 352 | // if script is already enqueued then we can just get out |
353 | 353 | if (wp_script_is('ee_error_js')) { |
354 | 354 | return ''; |
@@ -361,18 +361,18 @@ discard block |
||
361 | 361 | return ''; |
362 | 362 | } |
363 | 363 | } |
364 | - $jquery = includes_url() . 'js/jquery/jquery.js'; |
|
365 | - $core = EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version(); |
|
366 | - $ee_error = EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version(); |
|
367 | - $style = EE_GLOBAL_ASSETS_URL . 'css/ee-exception-stack-display.css'; |
|
364 | + $jquery = includes_url().'js/jquery/jquery.js'; |
|
365 | + $core = EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js?ver='.espresso_version(); |
|
366 | + $ee_error = EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js?ver='.espresso_version(); |
|
367 | + $style = EE_GLOBAL_ASSETS_URL.'css/ee-exception-stack-display.css'; |
|
368 | 368 | return ' |
369 | 369 | <script> |
370 | - const ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
370 | + const ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
371 | 371 | </script> |
372 | - <script src="' . esc_url_raw($jquery) . '" type="text/javascript"></script> |
|
373 | - <script src="' . esc_url_raw($core) . '" type="text/javascript"></script> |
|
374 | - <script src="' . esc_url_raw($ee_error) . '" type="text/javascript"></script> |
|
375 | - <link href="' . esc_url_raw($style) . '" rel="stylesheet" /> |
|
372 | + <script src="' . esc_url_raw($jquery).'" type="text/javascript"></script> |
|
373 | + <script src="' . esc_url_raw($core).'" type="text/javascript"></script> |
|
374 | + <script src="' . esc_url_raw($ee_error).'" type="text/javascript"></script> |
|
375 | + <link href="' . esc_url_raw($style).'" rel="stylesheet" /> |
|
376 | 376 | '; |
377 | 377 | } |
378 | 378 | } |