@@ -24,1264 +24,1264 @@ |
||
24 | 24 | */ |
25 | 25 | class EE_Register_Addon implements EEI_Plugin_API |
26 | 26 | { |
27 | - /** |
|
28 | - * possibly truncated version of the EE core version string |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected static $_core_version = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * Holds values for registered addons |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected static $_settings = []; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
43 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
44 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
45 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
46 | - * EE core with knowledge of ALL the addons out there. |
|
47 | - * If you want NO versions of an addon to run with a certain version of core, |
|
48 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
49 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
50 | - * minimum plugin version. |
|
51 | - * @access protected |
|
52 | - */ |
|
53 | - protected static $_incompatible_addons = [ |
|
54 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
55 | - 'Promotions' => '1.0.0.rc.084', |
|
56 | - ]; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var LoaderInterface |
|
60 | - */ |
|
61 | - protected static $loader; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
66 | - * not just '4.3.0'. |
|
67 | - * So if the addon developer doesn't provide that full version string, |
|
68 | - * fill in the blanks for them |
|
69 | - * |
|
70 | - * @param string $min_core_version |
|
71 | - * @return string always like '4.3.0.rc.000' |
|
72 | - */ |
|
73 | - protected static function _effective_version(string $min_core_version): string |
|
74 | - { |
|
75 | - // versions: 4 . 3 . 1 . p . 123 |
|
76 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
77 | - $version_parts = explode('.', $min_core_version); |
|
78 | - // check they specified the micro version (after 2nd period) |
|
79 | - if (! isset($version_parts[2])) { |
|
80 | - $version_parts[2] = '0'; |
|
81 | - } |
|
82 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
83 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
84 | - if (! isset($version_parts[3])) { |
|
85 | - $version_parts[3] = 'dev'; |
|
86 | - } |
|
87 | - if (! isset($version_parts[4])) { |
|
88 | - $version_parts[4] = '000'; |
|
89 | - } |
|
90 | - return implode('.', $version_parts); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Returns whether or not the min core version requirement of the addon is met |
|
96 | - * |
|
97 | - * @param string $min_core_version the minimum core version required by the addon |
|
98 | - * @param string $actual_core_version the actual core version, optional |
|
99 | - * @return boolean |
|
100 | - */ |
|
101 | - public static function _meets_min_core_version_requirement( |
|
102 | - string $min_core_version, |
|
103 | - string $actual_core_version = EVENT_ESPRESSO_VERSION |
|
104 | - ): bool { |
|
105 | - return version_compare( |
|
106 | - self::_effective_version($actual_core_version), |
|
107 | - self::_effective_version($min_core_version), |
|
108 | - '>=' |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Method for registering new EE_Addons. |
|
115 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
116 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
117 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
118 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
119 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
120 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
121 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
122 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
123 | - * |
|
124 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
125 | - * @param array $setup_args { |
|
126 | - * An array of arguments provided for registering |
|
127 | - * the message type. |
|
128 | - * @type string $class_name the addon's main file name. |
|
129 | - * If left blank, generated from the addon name, |
|
130 | - * changes something like "calendar" to |
|
131 | - * "EE_Calendar" |
|
132 | - * @type string $min_core_version the minimum version of EE Core that the |
|
133 | - * addon will work with. eg "4.8.1.rc.084" |
|
134 | - * @type string $version the "software" version for the addon. eg |
|
135 | - * "1.0.0.p" for a first stable release, or |
|
136 | - * "1.0.0.rc.043" for a version in progress |
|
137 | - * @type string $main_file_path the full server path to the main file |
|
138 | - * loaded directly by WP |
|
139 | - * @type DomainInterface $domain child class of |
|
140 | - * EventEspresso\core\domain\DomainBase |
|
141 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
142 | - * for the addon's Domain class |
|
143 | - * (see EventEspresso\core\domain\Domain) |
|
144 | - * @type string $admin_path full server path to the folder where the |
|
145 | - * addon\'s admin files reside |
|
146 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
147 | - * first invoked, can be used for hooking into |
|
148 | - * any admin page |
|
149 | - * @type string $config_section the section name for this addon's |
|
150 | - * configuration settings section |
|
151 | - * (defaults to "addons") |
|
152 | - * @type string $config_class the class name for this addon's |
|
153 | - * configuration settings object |
|
154 | - * @type string $config_name the class name for this addon's |
|
155 | - * configuration settings object |
|
156 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
157 | - * server paths to those files. |
|
158 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
159 | - * folders containing classes that might be |
|
160 | - * invoked by the addon |
|
161 | - * @type string $dms_paths [Required] an array of full server paths to |
|
162 | - * folders that contain data migration scripts. |
|
163 | - * The key should be the EE_Addon class name that |
|
164 | - * this set of data migration scripts belongs to. |
|
165 | - * If the EE_Addon class is namespaced, then this |
|
166 | - * needs to be the Fully Qualified Class Name |
|
167 | - * @type string $module_paths an array of full server paths to any |
|
168 | - * EED_Modules used by the addon |
|
169 | - * @type string $shortcode_paths an array of full server paths to folders |
|
170 | - * that contain EES_Shortcodes |
|
171 | - * @type string $widget_paths an array of full server paths to folders |
|
172 | - * that contain WP_Widgets |
|
173 | - * @type string $pue_options |
|
174 | - * @type array $capabilities an array indexed by role name |
|
175 | - * (i.e administrator,author ) and the values |
|
176 | - * are an array of caps to add to the role. |
|
177 | - * 'administrator' => array( |
|
178 | - * 'read_addon', |
|
179 | - * 'edit_addon', |
|
180 | - * etc. |
|
181 | - * ). |
|
182 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
183 | - * for any addons that need to register any |
|
184 | - * special meta mapped capabilities. Should |
|
185 | - * be indexed where the key is the |
|
186 | - * EE_Meta_Capability_Map class name and the |
|
187 | - * values are the arguments sent to the class. |
|
188 | - * @type array $model_paths array of folders containing DB models |
|
189 | - * @return boolean |
|
190 | - * @throws DomainException |
|
191 | - * @throws EE_Error |
|
192 | - * @throws InvalidArgumentException |
|
193 | - * @throws InvalidDataTypeException |
|
194 | - * @throws InvalidInterfaceException |
|
195 | - * @since 4.3.0 |
|
196 | - * @see EE_Register_Model |
|
197 | - * @type array $class_paths array of folders containing DB classes |
|
198 | - * @see EE_Register_Model |
|
199 | - * @type array $model_extension_paths array of folders containing DB model |
|
200 | - * extensions |
|
201 | - * @see EE_Register_Model_Extension |
|
202 | - * @type array $class_extension_paths array of folders containing DB class |
|
203 | - * extensions |
|
204 | - * @see EE_Register_Model_Extension |
|
205 | - * @type array message_types { |
|
206 | - * An array of message types with the key as |
|
207 | - * the message type name and the values as |
|
208 | - * below: |
|
209 | - * @type string $mtfilename [Required] The filename of the message type |
|
210 | - * being registered. This will be the main |
|
211 | - * EE_{Message Type Name}_message_type class. |
|
212 | - * for example: |
|
213 | - * EE_Declined_Registration_message_type.class.php |
|
214 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
215 | - * messages autoloader for the new message type. |
|
216 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
217 | - * type should activate with. Each value in |
|
218 | - * the |
|
219 | - * array |
|
220 | - * should match the name property of a |
|
221 | - * EE_messenger. Optional. |
|
222 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
223 | - * type should validate with. Each value in |
|
224 | - * the |
|
225 | - * array |
|
226 | - * should match the name property of an |
|
227 | - * EE_messenger. |
|
228 | - * Optional. |
|
229 | - * } |
|
230 | - * @type array $custom_post_types |
|
231 | - * @type array $custom_taxonomies |
|
232 | - * @type array $payment_method_paths each element is the folder containing the |
|
233 | - * EE_PMT_Base child class |
|
234 | - * (eg, |
|
235 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
236 | - * which contains the files |
|
237 | - * EE_PMT_Payomatic.pm.php) |
|
238 | - * @type array $default_terms |
|
239 | - * @type array $namespace { |
|
240 | - * An array with two items for registering the |
|
241 | - * addon's namespace. (If, for some reason, you |
|
242 | - * require additional namespaces, |
|
243 | - * use |
|
244 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
245 | - * directly) |
|
246 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
247 | - * @type string $FQNS the namespace prefix |
|
248 | - * @type string $DIR a base directory for class files in the |
|
249 | - * namespace. |
|
250 | - * } |
|
251 | - * } |
|
252 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
253 | - * privacy policy classes) or FQCNs (specific |
|
254 | - * classnames of privacy policy classes) |
|
255 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
256 | - * privacy policy classes) or FQCNs (specific |
|
257 | - * classnames of privacy policy classes) |
|
258 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
259 | - * privacy policy classes) or FQCNs (specific |
|
260 | - * classnames of privacy policy classes) |
|
261 | - */ |
|
262 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
263 | - { |
|
264 | - if (! self::$loader instanceof LoaderInterface) { |
|
265 | - self::$loader = LoaderFactory::getLoader(); |
|
266 | - } |
|
267 | - // make sure this was called in the right place! |
|
268 | - if ( |
|
269 | - ! did_action('activate_plugin') |
|
270 | - && ( |
|
271 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
272 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
273 | - ) |
|
274 | - ) { |
|
275 | - EE_Error::doing_it_wrong( |
|
276 | - __METHOD__, |
|
277 | - sprintf( |
|
278 | - esc_html__( |
|
279 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
280 | - 'event_espresso' |
|
281 | - ), |
|
282 | - $addon_name |
|
283 | - ), |
|
284 | - '4.3.0' |
|
285 | - ); |
|
286 | - return false; |
|
287 | - } |
|
288 | - // required fields MUST be present, so let's make sure they are. |
|
289 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
290 | - // get class name for addon |
|
291 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
292 | - // setup $_settings array from incoming values. |
|
293 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
294 | - // setup PUE |
|
295 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
296 | - // does this addon work with this version of core or WordPress ? |
|
297 | - // does this addon work with this version of core or WordPress ? |
|
298 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
299 | - return false; |
|
300 | - } |
|
301 | - // register namespaces |
|
302 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
303 | - // check if this is an activation request |
|
304 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
305 | - // dont bother setting up the rest of the addon atm |
|
306 | - return false; |
|
307 | - } |
|
308 | - // we need cars |
|
309 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
310 | - // register new models and extensions |
|
311 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
312 | - // setup DMS |
|
313 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
314 | - // if config_class is present let's register config. |
|
315 | - EE_Register_Addon::_register_config($addon_name); |
|
316 | - // register admin pages |
|
317 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
318 | - // add to list of modules to be registered |
|
319 | - EE_Register_Addon::_register_modules($addon_name); |
|
320 | - // add to list of shortcodes to be registered |
|
321 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
322 | - // add to list of widgets to be registered |
|
323 | - EE_Register_Addon::_register_widgets($addon_name); |
|
324 | - // register capability related stuff. |
|
325 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
326 | - // any message type to register? |
|
327 | - EE_Register_Addon::_register_message_types($addon_name); |
|
328 | - // any custom post type/ custom capabilities or default terms to register |
|
329 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
330 | - // and any payment methods |
|
331 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
332 | - // and privacy policy generators |
|
333 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
334 | - // and privacy policy generators |
|
335 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
336 | - // and privacy policy generators |
|
337 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
338 | - // load and instantiate main addon class |
|
339 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
340 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
341 | - add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
342 | - return $addon instanceof EE_Addon; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $addon_name |
|
348 | - * @param array $setup_args |
|
349 | - * @return void |
|
350 | - * @throws EE_Error |
|
351 | - */ |
|
352 | - private static function _verify_parameters(string $addon_name, array $setup_args) |
|
353 | - { |
|
354 | - // required fields MUST be present, so let's make sure they are. |
|
355 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
356 | - throw new EE_Error( |
|
357 | - esc_html__( |
|
358 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
359 | - 'event_espresso' |
|
360 | - ) |
|
361 | - ); |
|
362 | - } |
|
363 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
364 | - throw new EE_Error( |
|
365 | - sprintf( |
|
366 | - esc_html__( |
|
367 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
368 | - 'event_espresso' |
|
369 | - ), |
|
370 | - implode(',', array_keys($setup_args)) |
|
371 | - ) |
|
372 | - ); |
|
373 | - } |
|
374 | - // check that addon has not already been registered with that name |
|
375 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
376 | - throw new EE_Error( |
|
377 | - sprintf( |
|
378 | - esc_html__( |
|
379 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
380 | - 'event_espresso' |
|
381 | - ), |
|
382 | - $addon_name |
|
383 | - ) |
|
384 | - ); |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @param string $addon_name |
|
391 | - * @param array $setup_args |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
395 | - { |
|
396 | - if (empty($setup_args['class_name'])) { |
|
397 | - // generate one by first separating name with spaces |
|
398 | - $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
399 | - // capitalize, then replace spaces with underscores |
|
400 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
401 | - } else { |
|
402 | - $class_name = $setup_args['class_name']; |
|
403 | - } |
|
404 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
405 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
406 | - ? $class_name |
|
407 | - : 'EE_' . $class_name; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * @param string $class_name |
|
413 | - * @param array $setup_args |
|
414 | - * @return array |
|
415 | - */ |
|
416 | - private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
417 | - { |
|
418 | - // setup $_settings array from incoming values. |
|
419 | - $addon_settings = [ |
|
420 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
421 | - 'class_name' => $class_name, |
|
422 | - // the addon slug for use in URLs, etc |
|
423 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
424 | - ? (string) $setup_args['plugin_slug'] |
|
425 | - : '', |
|
426 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
427 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
428 | - ? (string) $setup_args['plugin_action_slug'] |
|
429 | - : '', |
|
430 | - // the "software" version for the addon |
|
431 | - 'version' => isset($setup_args['version']) |
|
432 | - ? (string) $setup_args['version'] |
|
433 | - : '', |
|
434 | - // the minimum version of EE Core that the addon will work with |
|
435 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
436 | - ? (string) $setup_args['min_core_version'] |
|
437 | - : '', |
|
438 | - // the minimum version of WordPress that the addon will work with |
|
439 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
440 | - ? (string) $setup_args['min_wp_version'] |
|
441 | - : EE_MIN_WP_VER_REQUIRED, |
|
442 | - // full server path to main file (file loaded directly by WP) |
|
443 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
444 | - ? (string) $setup_args['main_file_path'] |
|
445 | - : '', |
|
446 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
447 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
448 | - ? $setup_args['domain'] |
|
449 | - : null, |
|
450 | - // Fully Qualified Class Name for the addon's Domain class |
|
451 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
452 | - ? (string) $setup_args['domain_fqcn'] |
|
453 | - : '', |
|
454 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
455 | - 'admin_path' => isset($setup_args['admin_path']) |
|
456 | - ? (string) $setup_args['admin_path'] : '', |
|
457 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
458 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
459 | - ? (string) $setup_args['admin_callback'] |
|
460 | - : '', |
|
461 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
462 | - 'config_section' => isset($setup_args['config_section']) |
|
463 | - ? (string) $setup_args['config_section'] |
|
464 | - : 'addons', |
|
465 | - // the class name for this addon's configuration settings object |
|
466 | - 'config_class' => isset($setup_args['config_class']) |
|
467 | - ? (string) $setup_args['config_class'] : '', |
|
468 | - // the name given to the config for this addons' configuration settings object (optional) |
|
469 | - 'config_name' => isset($setup_args['config_name']) |
|
470 | - ? (string) $setup_args['config_name'] : '', |
|
471 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
472 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
473 | - ? (array) $setup_args['autoloader_paths'] |
|
474 | - : [], |
|
475 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
476 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
477 | - ? (array) $setup_args['autoloader_folders'] |
|
478 | - : [], |
|
479 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
480 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
481 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
482 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
483 | - ? (array) $setup_args['dms_paths'] |
|
484 | - : [], |
|
485 | - // array of full server paths to any EED_Modules used by the addon |
|
486 | - 'module_paths' => isset($setup_args['module_paths']) |
|
487 | - ? (array) $setup_args['module_paths'] |
|
488 | - : [], |
|
489 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
490 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
491 | - ? (array) $setup_args['shortcode_paths'] |
|
492 | - : [], |
|
493 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
494 | - ? (array) $setup_args['shortcode_fqcns'] |
|
495 | - : [], |
|
496 | - // array of full server paths to any WP_Widgets used by the addon |
|
497 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
498 | - ? (array) $setup_args['widget_paths'] |
|
499 | - : [], |
|
500 | - // array of PUE options used by the addon |
|
501 | - 'pue_options' => isset($setup_args['pue_options']) |
|
502 | - ? (array) $setup_args['pue_options'] |
|
503 | - : [], |
|
504 | - 'message_types' => isset($setup_args['message_types']) |
|
505 | - ? (array) $setup_args['message_types'] |
|
506 | - : [], |
|
507 | - 'capabilities' => isset($setup_args['capabilities']) |
|
508 | - ? (array) $setup_args['capabilities'] |
|
509 | - : [], |
|
510 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
511 | - ? (array) $setup_args['capability_maps'] |
|
512 | - : [], |
|
513 | - 'model_paths' => isset($setup_args['model_paths']) |
|
514 | - ? (array) $setup_args['model_paths'] |
|
515 | - : [], |
|
516 | - 'class_paths' => isset($setup_args['class_paths']) |
|
517 | - ? (array) $setup_args['class_paths'] |
|
518 | - : [], |
|
519 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
520 | - ? (array) $setup_args['model_extension_paths'] |
|
521 | - : [], |
|
522 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
523 | - ? (array) $setup_args['class_extension_paths'] |
|
524 | - : [], |
|
525 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
526 | - ? (array) $setup_args['custom_post_types'] |
|
527 | - : [], |
|
528 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
529 | - ? (array) $setup_args['custom_taxonomies'] |
|
530 | - : [], |
|
531 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
532 | - ? (array) $setup_args['payment_method_paths'] |
|
533 | - : [], |
|
534 | - 'default_terms' => isset($setup_args['default_terms']) |
|
535 | - ? (array) $setup_args['default_terms'] |
|
536 | - : [], |
|
537 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
538 | - // that can be used for adding upgrading/marketing info |
|
539 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
540 | - ? (array) $setup_args['plugins_page_row'] |
|
541 | - : [], |
|
542 | - 'namespace' => isset( |
|
543 | - $setup_args['namespace']['FQNS'], |
|
544 | - $setup_args['namespace']['DIR'] |
|
545 | - ) |
|
546 | - ? (array) $setup_args['namespace'] |
|
547 | - : [], |
|
548 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
549 | - ? (array) $setup_args['privacy_policies'] |
|
550 | - : '', |
|
551 | - ]; |
|
552 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
553 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
554 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
555 | - && ! empty($addon_settings['admin_path']) |
|
556 | - ? $addon_settings['plugin_slug'] |
|
557 | - : $addon_settings['plugin_action_slug']; |
|
558 | - // full server path to main file (file loaded directly by WP) |
|
559 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
560 | - return $addon_settings; |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * @param string $addon_name |
|
566 | - * @param array $addon_settings |
|
567 | - * @return boolean |
|
568 | - */ |
|
569 | - private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
570 | - { |
|
571 | - global $wp_version; |
|
572 | - $incompatibility_message = ''; |
|
573 | - // check whether this addon version is compatible with EE core |
|
574 | - if ( |
|
575 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
576 | - && ! self::_meets_min_core_version_requirement( |
|
577 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
578 | - $addon_settings['version'] |
|
579 | - ) |
|
580 | - ) { |
|
581 | - $incompatibility_message = sprintf( |
|
582 | - esc_html__( |
|
583 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
584 | - 'event_espresso' |
|
585 | - ), |
|
586 | - $addon_name, |
|
587 | - '<br />', |
|
588 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
589 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
590 | - '</span><br />' |
|
591 | - ); |
|
592 | - } elseif ( |
|
593 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
594 | - ) { |
|
595 | - $incompatibility_message = sprintf( |
|
596 | - esc_html__( |
|
597 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
598 | - 'event_espresso' |
|
599 | - ), |
|
600 | - $addon_name, |
|
601 | - self::_effective_version($addon_settings['min_core_version']), |
|
602 | - self::_effective_version(espresso_version()), |
|
603 | - '<br />', |
|
604 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
605 | - '</span><br />' |
|
606 | - ); |
|
607 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
608 | - $incompatibility_message = sprintf( |
|
609 | - esc_html__( |
|
610 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
611 | - 'event_espresso' |
|
612 | - ), |
|
613 | - $addon_name, |
|
614 | - $addon_settings['min_wp_version'], |
|
615 | - '<br />', |
|
616 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
617 | - '</span><br />' |
|
618 | - ); |
|
619 | - } |
|
620 | - if (! empty($incompatibility_message)) { |
|
621 | - // remove 'activate' from the REQUEST |
|
622 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
623 | - /** @var RequestInterface $request */ |
|
624 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
625 | - $request->unSetRequestParam('activate', true); |
|
626 | - if (current_user_can('activate_plugins')) { |
|
627 | - // show an error message indicating the plugin didn't activate properly |
|
628 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
629 | - } |
|
630 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
631 | - return false; |
|
632 | - } |
|
633 | - // addon IS compatible |
|
634 | - return true; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * if plugin update engine is being used for auto-updates, |
|
640 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
641 | - * (not needed if PUE is not being used) |
|
642 | - * |
|
643 | - * @param string $addon_name |
|
644 | - * @param string $class_name |
|
645 | - * @param array $setup_args |
|
646 | - * @return void |
|
647 | - */ |
|
648 | - private static function _parse_pue_options(string $addon_name, string $class_name, array $setup_args) |
|
649 | - { |
|
650 | - if (! empty($setup_args['pue_options'])) { |
|
651 | - self::$_settings[ $addon_name ]['pue_options'] = [ |
|
652 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
653 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
654 | - : 'espresso_' . strtolower($class_name), |
|
655 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
656 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
657 | - : plugin_basename($setup_args['main_file_path']), |
|
658 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
659 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
660 | - : '24', |
|
661 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
662 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
663 | - : false, |
|
664 | - ]; |
|
665 | - add_action( |
|
666 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
667 | - ['EE_Register_Addon', 'load_pue_update'] |
|
668 | - ); |
|
669 | - } |
|
670 | - } |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
675 | - * |
|
676 | - * @param array $addon_settings |
|
677 | - * @return void |
|
678 | - */ |
|
679 | - private static function _setup_namespaces(array $addon_settings) |
|
680 | - { |
|
681 | - // |
|
682 | - if ( |
|
683 | - isset( |
|
684 | - $addon_settings['namespace']['FQNS'], |
|
685 | - $addon_settings['namespace']['DIR'] |
|
686 | - ) |
|
687 | - ) { |
|
688 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
689 | - $addon_settings['namespace']['FQNS'], |
|
690 | - $addon_settings['namespace']['DIR'] |
|
691 | - ); |
|
692 | - } |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * @param string $addon_name |
|
698 | - * @param array $addon_settings |
|
699 | - * @return bool |
|
700 | - * @throws InvalidArgumentException |
|
701 | - * @throws InvalidDataTypeException |
|
702 | - * @throws InvalidInterfaceException |
|
703 | - */ |
|
704 | - private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
705 | - { |
|
706 | - // this is an activation request |
|
707 | - if (did_action('activate_plugin')) { |
|
708 | - // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
709 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
710 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
711 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
712 | - if ( |
|
713 | - ! isset(self::$_settings[ $addon_name ]) |
|
714 | - || (isset(self::$_settings[ $addon_name ]) |
|
715 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
716 | - ) |
|
717 | - ) { |
|
718 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
719 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
720 | - $addon->set_activation_indicator_option(); |
|
721 | - // dont bother setting up the rest of the addon. |
|
722 | - // we know it was just activated and the request will end soon |
|
723 | - } |
|
724 | - return true; |
|
725 | - } |
|
726 | - // make sure addon settings are set correctly without overwriting anything existing |
|
727 | - if (isset(self::$_settings[ $addon_name ])) { |
|
728 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
729 | - } else { |
|
730 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
731 | - } |
|
732 | - return false; |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * @param string $addon_name |
|
738 | - * @return void |
|
739 | - * @throws EE_Error |
|
740 | - */ |
|
741 | - private static function _setup_autoloaders(string $addon_name) |
|
742 | - { |
|
743 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
744 | - // setup autoloader for single file |
|
745 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
746 | - } |
|
747 | - // setup autoloaders for folders |
|
748 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
749 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
750 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
751 | - } |
|
752 | - } |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * register new models and extensions |
|
758 | - * |
|
759 | - * @param string $addon_name |
|
760 | - * @return void |
|
761 | - * @throws EE_Error |
|
762 | - */ |
|
763 | - private static function _register_models_and_extensions(string $addon_name) |
|
764 | - { |
|
765 | - // register new models |
|
766 | - if ( |
|
767 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
768 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
769 | - ) { |
|
770 | - EE_Register_Model::register( |
|
771 | - $addon_name, |
|
772 | - [ |
|
773 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
774 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
775 | - ] |
|
776 | - ); |
|
777 | - } |
|
778 | - // register model extensions |
|
779 | - if ( |
|
780 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
781 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
782 | - ) { |
|
783 | - EE_Register_Model_Extensions::register( |
|
784 | - $addon_name, |
|
785 | - [ |
|
786 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
787 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
788 | - ] |
|
789 | - ); |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * @param string $addon_name |
|
796 | - * @return void |
|
797 | - * @throws EE_Error |
|
798 | - */ |
|
799 | - private static function _register_data_migration_scripts(string $addon_name) |
|
800 | - { |
|
801 | - // setup DMS |
|
802 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
803 | - EE_Register_Data_Migration_Scripts::register( |
|
804 | - $addon_name, |
|
805 | - ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
806 | - ); |
|
807 | - } |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - /** |
|
812 | - * @param string $addon_name |
|
813 | - * @return void |
|
814 | - * @throws EE_Error |
|
815 | - */ |
|
816 | - private static function _register_config(string $addon_name) |
|
817 | - { |
|
818 | - // if config_class is present let's register config. |
|
819 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
820 | - EE_Register_Config::register( |
|
821 | - self::$_settings[ $addon_name ]['config_class'], |
|
822 | - [ |
|
823 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
824 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
825 | - ] |
|
826 | - ); |
|
827 | - } |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
832 | - * @param string $addon_name |
|
833 | - * @return void |
|
834 | - * @throws EE_Error |
|
835 | - */ |
|
836 | - private static function _register_admin_pages(string $addon_name) |
|
837 | - { |
|
838 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
839 | - EE_Register_Admin_Page::register( |
|
840 | - $addon_name, |
|
841 | - ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
842 | - ); |
|
843 | - } |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - /** |
|
848 | - * @param string $addon_name |
|
849 | - * @return void |
|
850 | - * @throws EE_Error |
|
851 | - */ |
|
852 | - private static function _register_modules(string $addon_name) |
|
853 | - { |
|
854 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
855 | - EE_Register_Module::register( |
|
856 | - $addon_name, |
|
857 | - ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
858 | - ); |
|
859 | - } |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * @param string $addon_name |
|
865 | - * @return void |
|
866 | - * @throws EE_Error |
|
867 | - */ |
|
868 | - private static function _register_shortcodes(string $addon_name) |
|
869 | - { |
|
870 | - if ( |
|
871 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
872 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
873 | - ) { |
|
874 | - EE_Register_Shortcode::register( |
|
875 | - $addon_name, |
|
876 | - [ |
|
877 | - 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
878 | - 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
879 | - ] |
|
880 | - ); |
|
881 | - } |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * @param string $addon_name |
|
887 | - * @return void |
|
888 | - * @throws EE_Error |
|
889 | - */ |
|
890 | - private static function _register_widgets(string $addon_name) |
|
891 | - { |
|
892 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
893 | - EE_Register_Widget::register( |
|
894 | - $addon_name, |
|
895 | - ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
896 | - ); |
|
897 | - } |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * @param string $addon_name |
|
903 | - * @return void |
|
904 | - * @throws EE_Error |
|
905 | - */ |
|
906 | - private static function _register_capabilities(string $addon_name) |
|
907 | - { |
|
908 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
909 | - EE_Register_Capabilities::register( |
|
910 | - $addon_name, |
|
911 | - [ |
|
912 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
913 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
914 | - ] |
|
915 | - ); |
|
916 | - } |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * @param string $addon_name |
|
922 | - * @return void |
|
923 | - */ |
|
924 | - private static function _register_message_types(string $addon_name) |
|
925 | - { |
|
926 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
927 | - add_action( |
|
928 | - 'EE_Brewing_Regular___messages_caf', |
|
929 | - ['EE_Register_Addon', 'register_message_types'] |
|
930 | - ); |
|
931 | - } |
|
932 | - } |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * @param string $addon_name |
|
937 | - * @return void |
|
938 | - * @throws EE_Error |
|
939 | - */ |
|
940 | - private static function _register_custom_post_types(string $addon_name) |
|
941 | - { |
|
942 | - if ( |
|
943 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
944 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
945 | - ) { |
|
946 | - EE_Register_CPT::register( |
|
947 | - $addon_name, |
|
948 | - [ |
|
949 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
950 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
951 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
952 | - ] |
|
953 | - ); |
|
954 | - } |
|
955 | - } |
|
956 | - |
|
957 | - |
|
958 | - /** |
|
959 | - * @param string $addon_name |
|
960 | - * @return void |
|
961 | - * @throws InvalidArgumentException |
|
962 | - * @throws InvalidInterfaceException |
|
963 | - * @throws InvalidDataTypeException |
|
964 | - * @throws DomainException |
|
965 | - * @throws EE_Error |
|
966 | - */ |
|
967 | - private static function _register_payment_methods(string $addon_name) |
|
968 | - { |
|
969 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
970 | - EE_Register_Payment_Method::register( |
|
971 | - $addon_name, |
|
972 | - ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
973 | - ); |
|
974 | - } |
|
975 | - } |
|
976 | - |
|
977 | - |
|
978 | - /** |
|
979 | - * @param string $addon_name |
|
980 | - * @return void |
|
981 | - * @throws InvalidArgumentException |
|
982 | - * @throws InvalidInterfaceException |
|
983 | - * @throws InvalidDataTypeException |
|
984 | - * @throws DomainException |
|
985 | - */ |
|
986 | - private static function registerPrivacyPolicies(string $addon_name) |
|
987 | - { |
|
988 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
989 | - EE_Register_Privacy_Policy::register( |
|
990 | - $addon_name, |
|
991 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
992 | - ); |
|
993 | - } |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - /** |
|
998 | - * @param string $addon_name |
|
999 | - * @return void |
|
1000 | - */ |
|
1001 | - private static function registerPersonalDataExporters(string $addon_name) |
|
1002 | - { |
|
1003 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
1004 | - EE_Register_Personal_Data_Eraser::register( |
|
1005 | - $addon_name, |
|
1006 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
1007 | - ); |
|
1008 | - } |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * @param string $addon_name |
|
1014 | - * @return void |
|
1015 | - */ |
|
1016 | - private static function registerPersonalDataErasers(string $addon_name) |
|
1017 | - { |
|
1018 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1019 | - EE_Register_Personal_Data_Eraser::register( |
|
1020 | - $addon_name, |
|
1021 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1022 | - ); |
|
1023 | - } |
|
1024 | - } |
|
1025 | - |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1029 | - * |
|
1030 | - * @param string $addon_name |
|
1031 | - * @return EE_Addon |
|
1032 | - * @throws InvalidArgumentException |
|
1033 | - * @throws InvalidInterfaceException |
|
1034 | - * @throws InvalidDataTypeException |
|
1035 | - */ |
|
1036 | - private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
|
1037 | - { |
|
1038 | - $addon = self::$loader->getShared( |
|
1039 | - self::$_settings[ $addon_name ]['class_name'], |
|
1040 | - ['EE_Registry::create(addon)' => true] |
|
1041 | - ); |
|
1042 | - if (! $addon instanceof EE_Addon) { |
|
1043 | - throw new DomainException( |
|
1044 | - sprintf( |
|
1045 | - esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
1046 | - self::$_settings[ $addon_name ]['class_name'] |
|
1047 | - ) |
|
1048 | - ); |
|
1049 | - } |
|
1050 | - // setter inject dep map if required |
|
1051 | - if ($addon->dependencyMap() === null) { |
|
1052 | - $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
1053 | - } |
|
1054 | - // setter inject domain if required |
|
1055 | - EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1056 | - |
|
1057 | - $addon->set_name($addon_name); |
|
1058 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1059 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1060 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1061 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1062 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1063 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1064 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1065 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1066 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1067 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1068 | - // setup the add-on's pue_slug if we have one. |
|
1069 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1070 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1071 | - } |
|
1072 | - // unfortunately this can't be hooked in upon construction, because we don't have |
|
1073 | - // the plugin mainfile's path upon construction. |
|
1074 | - register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
1075 | - // call any additional admin_callback functions during load_admin_controller hook |
|
1076 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1077 | - add_action( |
|
1078 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1079 | - [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1080 | - ); |
|
1081 | - } |
|
1082 | - return $addon; |
|
1083 | - } |
|
1084 | - |
|
1085 | - |
|
1086 | - /** |
|
1087 | - * @param string $addon_name |
|
1088 | - * @param EE_Addon $addon |
|
1089 | - * @since 4.10.13.p |
|
1090 | - */ |
|
1091 | - private static function injectAddonDomain(string $addon_name, EE_Addon $addon) |
|
1092 | - { |
|
1093 | - if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1094 | - // using supplied Domain object |
|
1095 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1096 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1097 | - : null; |
|
1098 | - // or construct one using Domain FQCN |
|
1099 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1100 | - $domain = self::$loader->getShared( |
|
1101 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1102 | - [ |
|
1103 | - new EventEspresso\core\domain\values\FilePath( |
|
1104 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1105 | - ), |
|
1106 | - EventEspresso\core\domain\values\Version::fromString( |
|
1107 | - self::$_settings[ $addon_name ]['version'] |
|
1108 | - ), |
|
1109 | - ] |
|
1110 | - ); |
|
1111 | - } |
|
1112 | - if ($domain instanceof DomainInterface) { |
|
1113 | - $addon->setDomain($domain); |
|
1114 | - } |
|
1115 | - } |
|
1116 | - } |
|
1117 | - |
|
1118 | - |
|
1119 | - /** |
|
1120 | - * load_pue_update - Update notifications |
|
1121 | - * |
|
1122 | - * @return void |
|
1123 | - * @throws InvalidArgumentException |
|
1124 | - * @throws InvalidDataTypeException |
|
1125 | - * @throws InvalidInterfaceException |
|
1126 | - */ |
|
1127 | - public static function load_pue_update() |
|
1128 | - { |
|
1129 | - // load PUE client |
|
1130 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1131 | - $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1132 | - // cycle thru settings |
|
1133 | - foreach (self::$_settings as $settings) { |
|
1134 | - if (! empty($settings['pue_options'])) { |
|
1135 | - // initiate the class and start the plugin update engine! |
|
1136 | - new PluginUpdateEngine( |
|
1137 | - // host file URL |
|
1138 | - $license_server, |
|
1139 | - // plugin slug(s) |
|
1140 | - [ |
|
1141 | - 'premium' => ['p' => $settings['pue_options']['pue_plugin_slug']], |
|
1142 | - 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'], |
|
1143 | - ], |
|
1144 | - // options |
|
1145 | - [ |
|
1146 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1147 | - 'lang_domain' => 'event_espresso', |
|
1148 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1149 | - 'option_key' => 'ee_site_license_key', |
|
1150 | - 'options_page_slug' => 'event_espresso', |
|
1151 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1152 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1153 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1154 | - ] |
|
1155 | - ); |
|
1156 | - } |
|
1157 | - } |
|
1158 | - } |
|
1159 | - |
|
1160 | - |
|
1161 | - /** |
|
1162 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1163 | - * |
|
1164 | - * @return void |
|
1165 | - * @throws EE_Error |
|
1166 | - * @since 4.4.0 |
|
1167 | - */ |
|
1168 | - public static function register_message_types() |
|
1169 | - { |
|
1170 | - foreach (self::$_settings as $settings) { |
|
1171 | - if (! empty($settings['message_types'])) { |
|
1172 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1173 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1174 | - } |
|
1175 | - } |
|
1176 | - } |
|
1177 | - } |
|
1178 | - |
|
1179 | - |
|
1180 | - /** |
|
1181 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1182 | - * |
|
1183 | - * @param string $addon_name the name for the addon that was previously registered |
|
1184 | - * @throws DomainException |
|
1185 | - * @throws InvalidArgumentException |
|
1186 | - * @throws InvalidDataTypeException |
|
1187 | - * @throws InvalidInterfaceException |
|
1188 | - * @since 4.3.0 |
|
1189 | - */ |
|
1190 | - public static function deregister(string $addon_name = '') |
|
1191 | - { |
|
1192 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1193 | - try { |
|
1194 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1195 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1196 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1197 | - // setup DMS |
|
1198 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1199 | - } |
|
1200 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1201 | - // register admin page |
|
1202 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1203 | - } |
|
1204 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1205 | - // add to list of modules to be registered |
|
1206 | - EE_Register_Module::deregister($addon_name); |
|
1207 | - } |
|
1208 | - if ( |
|
1209 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1210 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1211 | - ) { |
|
1212 | - // add to list of shortcodes to be registered |
|
1213 | - EE_Register_Shortcode::deregister($addon_name); |
|
1214 | - } |
|
1215 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1216 | - // if config_class present let's register config. |
|
1217 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1218 | - } |
|
1219 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1220 | - // add to list of widgets to be registered |
|
1221 | - EE_Register_Widget::deregister($addon_name); |
|
1222 | - } |
|
1223 | - if ( |
|
1224 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1225 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1226 | - ) { |
|
1227 | - // add to list of shortcodes to be registered |
|
1228 | - EE_Register_Model::deregister($addon_name); |
|
1229 | - } |
|
1230 | - if ( |
|
1231 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1232 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1233 | - ) { |
|
1234 | - // add to list of shortcodes to be registered |
|
1235 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1236 | - } |
|
1237 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1238 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1239 | - EE_Register_Message_Type::deregister($message_type); |
|
1240 | - } |
|
1241 | - } |
|
1242 | - // deregister capabilities for addon |
|
1243 | - if ( |
|
1244 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1245 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1246 | - ) { |
|
1247 | - EE_Register_Capabilities::deregister($addon_name); |
|
1248 | - } |
|
1249 | - // deregister custom_post_types for addon |
|
1250 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1251 | - EE_Register_CPT::deregister($addon_name); |
|
1252 | - } |
|
1253 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1254 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1255 | - } |
|
1256 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1257 | - if ($addon instanceof EE_Addon) { |
|
1258 | - remove_action( |
|
1259 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1260 | - [$addon, 'deactivation'] |
|
1261 | - ); |
|
1262 | - remove_action( |
|
1263 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1264 | - [$addon, 'initialize_db_if_no_migrations_required'] |
|
1265 | - ); |
|
1266 | - // remove `after_registration` call |
|
1267 | - remove_action( |
|
1268 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1269 | - [$addon, 'after_registration'], |
|
1270 | - 999 |
|
1271 | - ); |
|
1272 | - } |
|
1273 | - EE_Registry::instance()->removeAddon($class_name); |
|
1274 | - LoaderFactory::getLoader()->remove($class_name); |
|
1275 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1276 | - // the add-on was not yet registered in the registry, |
|
1277 | - // so RegistryContainer::__get() throws this exception. |
|
1278 | - // also no need to worry about this or log it, |
|
1279 | - // it's ok to deregister an add-on before its registered in the registry |
|
1280 | - } catch (Exception $e) { |
|
1281 | - new ExceptionLogger($e); |
|
1282 | - } |
|
1283 | - unset(self::$_settings[ $addon_name ]); |
|
1284 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1285 | - } |
|
1286 | - } |
|
27 | + /** |
|
28 | + * possibly truncated version of the EE core version string |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected static $_core_version = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * Holds values for registered addons |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected static $_settings = []; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
43 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
44 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
45 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
46 | + * EE core with knowledge of ALL the addons out there. |
|
47 | + * If you want NO versions of an addon to run with a certain version of core, |
|
48 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
49 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
50 | + * minimum plugin version. |
|
51 | + * @access protected |
|
52 | + */ |
|
53 | + protected static $_incompatible_addons = [ |
|
54 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
55 | + 'Promotions' => '1.0.0.rc.084', |
|
56 | + ]; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var LoaderInterface |
|
60 | + */ |
|
61 | + protected static $loader; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
66 | + * not just '4.3.0'. |
|
67 | + * So if the addon developer doesn't provide that full version string, |
|
68 | + * fill in the blanks for them |
|
69 | + * |
|
70 | + * @param string $min_core_version |
|
71 | + * @return string always like '4.3.0.rc.000' |
|
72 | + */ |
|
73 | + protected static function _effective_version(string $min_core_version): string |
|
74 | + { |
|
75 | + // versions: 4 . 3 . 1 . p . 123 |
|
76 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
77 | + $version_parts = explode('.', $min_core_version); |
|
78 | + // check they specified the micro version (after 2nd period) |
|
79 | + if (! isset($version_parts[2])) { |
|
80 | + $version_parts[2] = '0'; |
|
81 | + } |
|
82 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
83 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
84 | + if (! isset($version_parts[3])) { |
|
85 | + $version_parts[3] = 'dev'; |
|
86 | + } |
|
87 | + if (! isset($version_parts[4])) { |
|
88 | + $version_parts[4] = '000'; |
|
89 | + } |
|
90 | + return implode('.', $version_parts); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Returns whether or not the min core version requirement of the addon is met |
|
96 | + * |
|
97 | + * @param string $min_core_version the minimum core version required by the addon |
|
98 | + * @param string $actual_core_version the actual core version, optional |
|
99 | + * @return boolean |
|
100 | + */ |
|
101 | + public static function _meets_min_core_version_requirement( |
|
102 | + string $min_core_version, |
|
103 | + string $actual_core_version = EVENT_ESPRESSO_VERSION |
|
104 | + ): bool { |
|
105 | + return version_compare( |
|
106 | + self::_effective_version($actual_core_version), |
|
107 | + self::_effective_version($min_core_version), |
|
108 | + '>=' |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Method for registering new EE_Addons. |
|
115 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
116 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
117 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
118 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
119 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
120 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
121 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
122 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
123 | + * |
|
124 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
125 | + * @param array $setup_args { |
|
126 | + * An array of arguments provided for registering |
|
127 | + * the message type. |
|
128 | + * @type string $class_name the addon's main file name. |
|
129 | + * If left blank, generated from the addon name, |
|
130 | + * changes something like "calendar" to |
|
131 | + * "EE_Calendar" |
|
132 | + * @type string $min_core_version the minimum version of EE Core that the |
|
133 | + * addon will work with. eg "4.8.1.rc.084" |
|
134 | + * @type string $version the "software" version for the addon. eg |
|
135 | + * "1.0.0.p" for a first stable release, or |
|
136 | + * "1.0.0.rc.043" for a version in progress |
|
137 | + * @type string $main_file_path the full server path to the main file |
|
138 | + * loaded directly by WP |
|
139 | + * @type DomainInterface $domain child class of |
|
140 | + * EventEspresso\core\domain\DomainBase |
|
141 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
142 | + * for the addon's Domain class |
|
143 | + * (see EventEspresso\core\domain\Domain) |
|
144 | + * @type string $admin_path full server path to the folder where the |
|
145 | + * addon\'s admin files reside |
|
146 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
147 | + * first invoked, can be used for hooking into |
|
148 | + * any admin page |
|
149 | + * @type string $config_section the section name for this addon's |
|
150 | + * configuration settings section |
|
151 | + * (defaults to "addons") |
|
152 | + * @type string $config_class the class name for this addon's |
|
153 | + * configuration settings object |
|
154 | + * @type string $config_name the class name for this addon's |
|
155 | + * configuration settings object |
|
156 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
157 | + * server paths to those files. |
|
158 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
159 | + * folders containing classes that might be |
|
160 | + * invoked by the addon |
|
161 | + * @type string $dms_paths [Required] an array of full server paths to |
|
162 | + * folders that contain data migration scripts. |
|
163 | + * The key should be the EE_Addon class name that |
|
164 | + * this set of data migration scripts belongs to. |
|
165 | + * If the EE_Addon class is namespaced, then this |
|
166 | + * needs to be the Fully Qualified Class Name |
|
167 | + * @type string $module_paths an array of full server paths to any |
|
168 | + * EED_Modules used by the addon |
|
169 | + * @type string $shortcode_paths an array of full server paths to folders |
|
170 | + * that contain EES_Shortcodes |
|
171 | + * @type string $widget_paths an array of full server paths to folders |
|
172 | + * that contain WP_Widgets |
|
173 | + * @type string $pue_options |
|
174 | + * @type array $capabilities an array indexed by role name |
|
175 | + * (i.e administrator,author ) and the values |
|
176 | + * are an array of caps to add to the role. |
|
177 | + * 'administrator' => array( |
|
178 | + * 'read_addon', |
|
179 | + * 'edit_addon', |
|
180 | + * etc. |
|
181 | + * ). |
|
182 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
183 | + * for any addons that need to register any |
|
184 | + * special meta mapped capabilities. Should |
|
185 | + * be indexed where the key is the |
|
186 | + * EE_Meta_Capability_Map class name and the |
|
187 | + * values are the arguments sent to the class. |
|
188 | + * @type array $model_paths array of folders containing DB models |
|
189 | + * @return boolean |
|
190 | + * @throws DomainException |
|
191 | + * @throws EE_Error |
|
192 | + * @throws InvalidArgumentException |
|
193 | + * @throws InvalidDataTypeException |
|
194 | + * @throws InvalidInterfaceException |
|
195 | + * @since 4.3.0 |
|
196 | + * @see EE_Register_Model |
|
197 | + * @type array $class_paths array of folders containing DB classes |
|
198 | + * @see EE_Register_Model |
|
199 | + * @type array $model_extension_paths array of folders containing DB model |
|
200 | + * extensions |
|
201 | + * @see EE_Register_Model_Extension |
|
202 | + * @type array $class_extension_paths array of folders containing DB class |
|
203 | + * extensions |
|
204 | + * @see EE_Register_Model_Extension |
|
205 | + * @type array message_types { |
|
206 | + * An array of message types with the key as |
|
207 | + * the message type name and the values as |
|
208 | + * below: |
|
209 | + * @type string $mtfilename [Required] The filename of the message type |
|
210 | + * being registered. This will be the main |
|
211 | + * EE_{Message Type Name}_message_type class. |
|
212 | + * for example: |
|
213 | + * EE_Declined_Registration_message_type.class.php |
|
214 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
215 | + * messages autoloader for the new message type. |
|
216 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
217 | + * type should activate with. Each value in |
|
218 | + * the |
|
219 | + * array |
|
220 | + * should match the name property of a |
|
221 | + * EE_messenger. Optional. |
|
222 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
223 | + * type should validate with. Each value in |
|
224 | + * the |
|
225 | + * array |
|
226 | + * should match the name property of an |
|
227 | + * EE_messenger. |
|
228 | + * Optional. |
|
229 | + * } |
|
230 | + * @type array $custom_post_types |
|
231 | + * @type array $custom_taxonomies |
|
232 | + * @type array $payment_method_paths each element is the folder containing the |
|
233 | + * EE_PMT_Base child class |
|
234 | + * (eg, |
|
235 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
236 | + * which contains the files |
|
237 | + * EE_PMT_Payomatic.pm.php) |
|
238 | + * @type array $default_terms |
|
239 | + * @type array $namespace { |
|
240 | + * An array with two items for registering the |
|
241 | + * addon's namespace. (If, for some reason, you |
|
242 | + * require additional namespaces, |
|
243 | + * use |
|
244 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
245 | + * directly) |
|
246 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
247 | + * @type string $FQNS the namespace prefix |
|
248 | + * @type string $DIR a base directory for class files in the |
|
249 | + * namespace. |
|
250 | + * } |
|
251 | + * } |
|
252 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
253 | + * privacy policy classes) or FQCNs (specific |
|
254 | + * classnames of privacy policy classes) |
|
255 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
256 | + * privacy policy classes) or FQCNs (specific |
|
257 | + * classnames of privacy policy classes) |
|
258 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
259 | + * privacy policy classes) or FQCNs (specific |
|
260 | + * classnames of privacy policy classes) |
|
261 | + */ |
|
262 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
263 | + { |
|
264 | + if (! self::$loader instanceof LoaderInterface) { |
|
265 | + self::$loader = LoaderFactory::getLoader(); |
|
266 | + } |
|
267 | + // make sure this was called in the right place! |
|
268 | + if ( |
|
269 | + ! did_action('activate_plugin') |
|
270 | + && ( |
|
271 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
272 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
273 | + ) |
|
274 | + ) { |
|
275 | + EE_Error::doing_it_wrong( |
|
276 | + __METHOD__, |
|
277 | + sprintf( |
|
278 | + esc_html__( |
|
279 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
280 | + 'event_espresso' |
|
281 | + ), |
|
282 | + $addon_name |
|
283 | + ), |
|
284 | + '4.3.0' |
|
285 | + ); |
|
286 | + return false; |
|
287 | + } |
|
288 | + // required fields MUST be present, so let's make sure they are. |
|
289 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
290 | + // get class name for addon |
|
291 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
292 | + // setup $_settings array from incoming values. |
|
293 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
294 | + // setup PUE |
|
295 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
296 | + // does this addon work with this version of core or WordPress ? |
|
297 | + // does this addon work with this version of core or WordPress ? |
|
298 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
299 | + return false; |
|
300 | + } |
|
301 | + // register namespaces |
|
302 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
303 | + // check if this is an activation request |
|
304 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
305 | + // dont bother setting up the rest of the addon atm |
|
306 | + return false; |
|
307 | + } |
|
308 | + // we need cars |
|
309 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
310 | + // register new models and extensions |
|
311 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
312 | + // setup DMS |
|
313 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
314 | + // if config_class is present let's register config. |
|
315 | + EE_Register_Addon::_register_config($addon_name); |
|
316 | + // register admin pages |
|
317 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
318 | + // add to list of modules to be registered |
|
319 | + EE_Register_Addon::_register_modules($addon_name); |
|
320 | + // add to list of shortcodes to be registered |
|
321 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
322 | + // add to list of widgets to be registered |
|
323 | + EE_Register_Addon::_register_widgets($addon_name); |
|
324 | + // register capability related stuff. |
|
325 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
326 | + // any message type to register? |
|
327 | + EE_Register_Addon::_register_message_types($addon_name); |
|
328 | + // any custom post type/ custom capabilities or default terms to register |
|
329 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
330 | + // and any payment methods |
|
331 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
332 | + // and privacy policy generators |
|
333 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
334 | + // and privacy policy generators |
|
335 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
336 | + // and privacy policy generators |
|
337 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
338 | + // load and instantiate main addon class |
|
339 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
340 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
341 | + add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
342 | + return $addon instanceof EE_Addon; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $addon_name |
|
348 | + * @param array $setup_args |
|
349 | + * @return void |
|
350 | + * @throws EE_Error |
|
351 | + */ |
|
352 | + private static function _verify_parameters(string $addon_name, array $setup_args) |
|
353 | + { |
|
354 | + // required fields MUST be present, so let's make sure they are. |
|
355 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
356 | + throw new EE_Error( |
|
357 | + esc_html__( |
|
358 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
359 | + 'event_espresso' |
|
360 | + ) |
|
361 | + ); |
|
362 | + } |
|
363 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
364 | + throw new EE_Error( |
|
365 | + sprintf( |
|
366 | + esc_html__( |
|
367 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
368 | + 'event_espresso' |
|
369 | + ), |
|
370 | + implode(',', array_keys($setup_args)) |
|
371 | + ) |
|
372 | + ); |
|
373 | + } |
|
374 | + // check that addon has not already been registered with that name |
|
375 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
376 | + throw new EE_Error( |
|
377 | + sprintf( |
|
378 | + esc_html__( |
|
379 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
380 | + 'event_espresso' |
|
381 | + ), |
|
382 | + $addon_name |
|
383 | + ) |
|
384 | + ); |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @param string $addon_name |
|
391 | + * @param array $setup_args |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
395 | + { |
|
396 | + if (empty($setup_args['class_name'])) { |
|
397 | + // generate one by first separating name with spaces |
|
398 | + $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
399 | + // capitalize, then replace spaces with underscores |
|
400 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
401 | + } else { |
|
402 | + $class_name = $setup_args['class_name']; |
|
403 | + } |
|
404 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
405 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
406 | + ? $class_name |
|
407 | + : 'EE_' . $class_name; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * @param string $class_name |
|
413 | + * @param array $setup_args |
|
414 | + * @return array |
|
415 | + */ |
|
416 | + private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
417 | + { |
|
418 | + // setup $_settings array from incoming values. |
|
419 | + $addon_settings = [ |
|
420 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
421 | + 'class_name' => $class_name, |
|
422 | + // the addon slug for use in URLs, etc |
|
423 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
424 | + ? (string) $setup_args['plugin_slug'] |
|
425 | + : '', |
|
426 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
427 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
428 | + ? (string) $setup_args['plugin_action_slug'] |
|
429 | + : '', |
|
430 | + // the "software" version for the addon |
|
431 | + 'version' => isset($setup_args['version']) |
|
432 | + ? (string) $setup_args['version'] |
|
433 | + : '', |
|
434 | + // the minimum version of EE Core that the addon will work with |
|
435 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
436 | + ? (string) $setup_args['min_core_version'] |
|
437 | + : '', |
|
438 | + // the minimum version of WordPress that the addon will work with |
|
439 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
440 | + ? (string) $setup_args['min_wp_version'] |
|
441 | + : EE_MIN_WP_VER_REQUIRED, |
|
442 | + // full server path to main file (file loaded directly by WP) |
|
443 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
444 | + ? (string) $setup_args['main_file_path'] |
|
445 | + : '', |
|
446 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
447 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
448 | + ? $setup_args['domain'] |
|
449 | + : null, |
|
450 | + // Fully Qualified Class Name for the addon's Domain class |
|
451 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
452 | + ? (string) $setup_args['domain_fqcn'] |
|
453 | + : '', |
|
454 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
455 | + 'admin_path' => isset($setup_args['admin_path']) |
|
456 | + ? (string) $setup_args['admin_path'] : '', |
|
457 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
458 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
459 | + ? (string) $setup_args['admin_callback'] |
|
460 | + : '', |
|
461 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
462 | + 'config_section' => isset($setup_args['config_section']) |
|
463 | + ? (string) $setup_args['config_section'] |
|
464 | + : 'addons', |
|
465 | + // the class name for this addon's configuration settings object |
|
466 | + 'config_class' => isset($setup_args['config_class']) |
|
467 | + ? (string) $setup_args['config_class'] : '', |
|
468 | + // the name given to the config for this addons' configuration settings object (optional) |
|
469 | + 'config_name' => isset($setup_args['config_name']) |
|
470 | + ? (string) $setup_args['config_name'] : '', |
|
471 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
472 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
473 | + ? (array) $setup_args['autoloader_paths'] |
|
474 | + : [], |
|
475 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
476 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
477 | + ? (array) $setup_args['autoloader_folders'] |
|
478 | + : [], |
|
479 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
480 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
481 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
482 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
483 | + ? (array) $setup_args['dms_paths'] |
|
484 | + : [], |
|
485 | + // array of full server paths to any EED_Modules used by the addon |
|
486 | + 'module_paths' => isset($setup_args['module_paths']) |
|
487 | + ? (array) $setup_args['module_paths'] |
|
488 | + : [], |
|
489 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
490 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
491 | + ? (array) $setup_args['shortcode_paths'] |
|
492 | + : [], |
|
493 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
494 | + ? (array) $setup_args['shortcode_fqcns'] |
|
495 | + : [], |
|
496 | + // array of full server paths to any WP_Widgets used by the addon |
|
497 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
498 | + ? (array) $setup_args['widget_paths'] |
|
499 | + : [], |
|
500 | + // array of PUE options used by the addon |
|
501 | + 'pue_options' => isset($setup_args['pue_options']) |
|
502 | + ? (array) $setup_args['pue_options'] |
|
503 | + : [], |
|
504 | + 'message_types' => isset($setup_args['message_types']) |
|
505 | + ? (array) $setup_args['message_types'] |
|
506 | + : [], |
|
507 | + 'capabilities' => isset($setup_args['capabilities']) |
|
508 | + ? (array) $setup_args['capabilities'] |
|
509 | + : [], |
|
510 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
511 | + ? (array) $setup_args['capability_maps'] |
|
512 | + : [], |
|
513 | + 'model_paths' => isset($setup_args['model_paths']) |
|
514 | + ? (array) $setup_args['model_paths'] |
|
515 | + : [], |
|
516 | + 'class_paths' => isset($setup_args['class_paths']) |
|
517 | + ? (array) $setup_args['class_paths'] |
|
518 | + : [], |
|
519 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
520 | + ? (array) $setup_args['model_extension_paths'] |
|
521 | + : [], |
|
522 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
523 | + ? (array) $setup_args['class_extension_paths'] |
|
524 | + : [], |
|
525 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
526 | + ? (array) $setup_args['custom_post_types'] |
|
527 | + : [], |
|
528 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
529 | + ? (array) $setup_args['custom_taxonomies'] |
|
530 | + : [], |
|
531 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
532 | + ? (array) $setup_args['payment_method_paths'] |
|
533 | + : [], |
|
534 | + 'default_terms' => isset($setup_args['default_terms']) |
|
535 | + ? (array) $setup_args['default_terms'] |
|
536 | + : [], |
|
537 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
538 | + // that can be used for adding upgrading/marketing info |
|
539 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
540 | + ? (array) $setup_args['plugins_page_row'] |
|
541 | + : [], |
|
542 | + 'namespace' => isset( |
|
543 | + $setup_args['namespace']['FQNS'], |
|
544 | + $setup_args['namespace']['DIR'] |
|
545 | + ) |
|
546 | + ? (array) $setup_args['namespace'] |
|
547 | + : [], |
|
548 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
549 | + ? (array) $setup_args['privacy_policies'] |
|
550 | + : '', |
|
551 | + ]; |
|
552 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
553 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
554 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
555 | + && ! empty($addon_settings['admin_path']) |
|
556 | + ? $addon_settings['plugin_slug'] |
|
557 | + : $addon_settings['plugin_action_slug']; |
|
558 | + // full server path to main file (file loaded directly by WP) |
|
559 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
560 | + return $addon_settings; |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * @param string $addon_name |
|
566 | + * @param array $addon_settings |
|
567 | + * @return boolean |
|
568 | + */ |
|
569 | + private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
570 | + { |
|
571 | + global $wp_version; |
|
572 | + $incompatibility_message = ''; |
|
573 | + // check whether this addon version is compatible with EE core |
|
574 | + if ( |
|
575 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
576 | + && ! self::_meets_min_core_version_requirement( |
|
577 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
578 | + $addon_settings['version'] |
|
579 | + ) |
|
580 | + ) { |
|
581 | + $incompatibility_message = sprintf( |
|
582 | + esc_html__( |
|
583 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
584 | + 'event_espresso' |
|
585 | + ), |
|
586 | + $addon_name, |
|
587 | + '<br />', |
|
588 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
589 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
590 | + '</span><br />' |
|
591 | + ); |
|
592 | + } elseif ( |
|
593 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
594 | + ) { |
|
595 | + $incompatibility_message = sprintf( |
|
596 | + esc_html__( |
|
597 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
598 | + 'event_espresso' |
|
599 | + ), |
|
600 | + $addon_name, |
|
601 | + self::_effective_version($addon_settings['min_core_version']), |
|
602 | + self::_effective_version(espresso_version()), |
|
603 | + '<br />', |
|
604 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
605 | + '</span><br />' |
|
606 | + ); |
|
607 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
608 | + $incompatibility_message = sprintf( |
|
609 | + esc_html__( |
|
610 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
611 | + 'event_espresso' |
|
612 | + ), |
|
613 | + $addon_name, |
|
614 | + $addon_settings['min_wp_version'], |
|
615 | + '<br />', |
|
616 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
617 | + '</span><br />' |
|
618 | + ); |
|
619 | + } |
|
620 | + if (! empty($incompatibility_message)) { |
|
621 | + // remove 'activate' from the REQUEST |
|
622 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
623 | + /** @var RequestInterface $request */ |
|
624 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
625 | + $request->unSetRequestParam('activate', true); |
|
626 | + if (current_user_can('activate_plugins')) { |
|
627 | + // show an error message indicating the plugin didn't activate properly |
|
628 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
629 | + } |
|
630 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
631 | + return false; |
|
632 | + } |
|
633 | + // addon IS compatible |
|
634 | + return true; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * if plugin update engine is being used for auto-updates, |
|
640 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
641 | + * (not needed if PUE is not being used) |
|
642 | + * |
|
643 | + * @param string $addon_name |
|
644 | + * @param string $class_name |
|
645 | + * @param array $setup_args |
|
646 | + * @return void |
|
647 | + */ |
|
648 | + private static function _parse_pue_options(string $addon_name, string $class_name, array $setup_args) |
|
649 | + { |
|
650 | + if (! empty($setup_args['pue_options'])) { |
|
651 | + self::$_settings[ $addon_name ]['pue_options'] = [ |
|
652 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
653 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
654 | + : 'espresso_' . strtolower($class_name), |
|
655 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
656 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
657 | + : plugin_basename($setup_args['main_file_path']), |
|
658 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
659 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
660 | + : '24', |
|
661 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
662 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
663 | + : false, |
|
664 | + ]; |
|
665 | + add_action( |
|
666 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
667 | + ['EE_Register_Addon', 'load_pue_update'] |
|
668 | + ); |
|
669 | + } |
|
670 | + } |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
675 | + * |
|
676 | + * @param array $addon_settings |
|
677 | + * @return void |
|
678 | + */ |
|
679 | + private static function _setup_namespaces(array $addon_settings) |
|
680 | + { |
|
681 | + // |
|
682 | + if ( |
|
683 | + isset( |
|
684 | + $addon_settings['namespace']['FQNS'], |
|
685 | + $addon_settings['namespace']['DIR'] |
|
686 | + ) |
|
687 | + ) { |
|
688 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
689 | + $addon_settings['namespace']['FQNS'], |
|
690 | + $addon_settings['namespace']['DIR'] |
|
691 | + ); |
|
692 | + } |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * @param string $addon_name |
|
698 | + * @param array $addon_settings |
|
699 | + * @return bool |
|
700 | + * @throws InvalidArgumentException |
|
701 | + * @throws InvalidDataTypeException |
|
702 | + * @throws InvalidInterfaceException |
|
703 | + */ |
|
704 | + private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
705 | + { |
|
706 | + // this is an activation request |
|
707 | + if (did_action('activate_plugin')) { |
|
708 | + // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
709 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
710 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
711 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
712 | + if ( |
|
713 | + ! isset(self::$_settings[ $addon_name ]) |
|
714 | + || (isset(self::$_settings[ $addon_name ]) |
|
715 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
716 | + ) |
|
717 | + ) { |
|
718 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
719 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
720 | + $addon->set_activation_indicator_option(); |
|
721 | + // dont bother setting up the rest of the addon. |
|
722 | + // we know it was just activated and the request will end soon |
|
723 | + } |
|
724 | + return true; |
|
725 | + } |
|
726 | + // make sure addon settings are set correctly without overwriting anything existing |
|
727 | + if (isset(self::$_settings[ $addon_name ])) { |
|
728 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
729 | + } else { |
|
730 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
731 | + } |
|
732 | + return false; |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * @param string $addon_name |
|
738 | + * @return void |
|
739 | + * @throws EE_Error |
|
740 | + */ |
|
741 | + private static function _setup_autoloaders(string $addon_name) |
|
742 | + { |
|
743 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
744 | + // setup autoloader for single file |
|
745 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
746 | + } |
|
747 | + // setup autoloaders for folders |
|
748 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
749 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
750 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
751 | + } |
|
752 | + } |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * register new models and extensions |
|
758 | + * |
|
759 | + * @param string $addon_name |
|
760 | + * @return void |
|
761 | + * @throws EE_Error |
|
762 | + */ |
|
763 | + private static function _register_models_and_extensions(string $addon_name) |
|
764 | + { |
|
765 | + // register new models |
|
766 | + if ( |
|
767 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
768 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
769 | + ) { |
|
770 | + EE_Register_Model::register( |
|
771 | + $addon_name, |
|
772 | + [ |
|
773 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
774 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
775 | + ] |
|
776 | + ); |
|
777 | + } |
|
778 | + // register model extensions |
|
779 | + if ( |
|
780 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
781 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
782 | + ) { |
|
783 | + EE_Register_Model_Extensions::register( |
|
784 | + $addon_name, |
|
785 | + [ |
|
786 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
787 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
788 | + ] |
|
789 | + ); |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * @param string $addon_name |
|
796 | + * @return void |
|
797 | + * @throws EE_Error |
|
798 | + */ |
|
799 | + private static function _register_data_migration_scripts(string $addon_name) |
|
800 | + { |
|
801 | + // setup DMS |
|
802 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
803 | + EE_Register_Data_Migration_Scripts::register( |
|
804 | + $addon_name, |
|
805 | + ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
806 | + ); |
|
807 | + } |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + /** |
|
812 | + * @param string $addon_name |
|
813 | + * @return void |
|
814 | + * @throws EE_Error |
|
815 | + */ |
|
816 | + private static function _register_config(string $addon_name) |
|
817 | + { |
|
818 | + // if config_class is present let's register config. |
|
819 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
820 | + EE_Register_Config::register( |
|
821 | + self::$_settings[ $addon_name ]['config_class'], |
|
822 | + [ |
|
823 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
824 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
825 | + ] |
|
826 | + ); |
|
827 | + } |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | + * @param string $addon_name |
|
833 | + * @return void |
|
834 | + * @throws EE_Error |
|
835 | + */ |
|
836 | + private static function _register_admin_pages(string $addon_name) |
|
837 | + { |
|
838 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
839 | + EE_Register_Admin_Page::register( |
|
840 | + $addon_name, |
|
841 | + ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
842 | + ); |
|
843 | + } |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + /** |
|
848 | + * @param string $addon_name |
|
849 | + * @return void |
|
850 | + * @throws EE_Error |
|
851 | + */ |
|
852 | + private static function _register_modules(string $addon_name) |
|
853 | + { |
|
854 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
855 | + EE_Register_Module::register( |
|
856 | + $addon_name, |
|
857 | + ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
858 | + ); |
|
859 | + } |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * @param string $addon_name |
|
865 | + * @return void |
|
866 | + * @throws EE_Error |
|
867 | + */ |
|
868 | + private static function _register_shortcodes(string $addon_name) |
|
869 | + { |
|
870 | + if ( |
|
871 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
872 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
873 | + ) { |
|
874 | + EE_Register_Shortcode::register( |
|
875 | + $addon_name, |
|
876 | + [ |
|
877 | + 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
878 | + 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
879 | + ] |
|
880 | + ); |
|
881 | + } |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * @param string $addon_name |
|
887 | + * @return void |
|
888 | + * @throws EE_Error |
|
889 | + */ |
|
890 | + private static function _register_widgets(string $addon_name) |
|
891 | + { |
|
892 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
893 | + EE_Register_Widget::register( |
|
894 | + $addon_name, |
|
895 | + ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
896 | + ); |
|
897 | + } |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * @param string $addon_name |
|
903 | + * @return void |
|
904 | + * @throws EE_Error |
|
905 | + */ |
|
906 | + private static function _register_capabilities(string $addon_name) |
|
907 | + { |
|
908 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
909 | + EE_Register_Capabilities::register( |
|
910 | + $addon_name, |
|
911 | + [ |
|
912 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
913 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
914 | + ] |
|
915 | + ); |
|
916 | + } |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * @param string $addon_name |
|
922 | + * @return void |
|
923 | + */ |
|
924 | + private static function _register_message_types(string $addon_name) |
|
925 | + { |
|
926 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
927 | + add_action( |
|
928 | + 'EE_Brewing_Regular___messages_caf', |
|
929 | + ['EE_Register_Addon', 'register_message_types'] |
|
930 | + ); |
|
931 | + } |
|
932 | + } |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * @param string $addon_name |
|
937 | + * @return void |
|
938 | + * @throws EE_Error |
|
939 | + */ |
|
940 | + private static function _register_custom_post_types(string $addon_name) |
|
941 | + { |
|
942 | + if ( |
|
943 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
944 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
945 | + ) { |
|
946 | + EE_Register_CPT::register( |
|
947 | + $addon_name, |
|
948 | + [ |
|
949 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
950 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
951 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
952 | + ] |
|
953 | + ); |
|
954 | + } |
|
955 | + } |
|
956 | + |
|
957 | + |
|
958 | + /** |
|
959 | + * @param string $addon_name |
|
960 | + * @return void |
|
961 | + * @throws InvalidArgumentException |
|
962 | + * @throws InvalidInterfaceException |
|
963 | + * @throws InvalidDataTypeException |
|
964 | + * @throws DomainException |
|
965 | + * @throws EE_Error |
|
966 | + */ |
|
967 | + private static function _register_payment_methods(string $addon_name) |
|
968 | + { |
|
969 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
970 | + EE_Register_Payment_Method::register( |
|
971 | + $addon_name, |
|
972 | + ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
973 | + ); |
|
974 | + } |
|
975 | + } |
|
976 | + |
|
977 | + |
|
978 | + /** |
|
979 | + * @param string $addon_name |
|
980 | + * @return void |
|
981 | + * @throws InvalidArgumentException |
|
982 | + * @throws InvalidInterfaceException |
|
983 | + * @throws InvalidDataTypeException |
|
984 | + * @throws DomainException |
|
985 | + */ |
|
986 | + private static function registerPrivacyPolicies(string $addon_name) |
|
987 | + { |
|
988 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
989 | + EE_Register_Privacy_Policy::register( |
|
990 | + $addon_name, |
|
991 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
992 | + ); |
|
993 | + } |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + /** |
|
998 | + * @param string $addon_name |
|
999 | + * @return void |
|
1000 | + */ |
|
1001 | + private static function registerPersonalDataExporters(string $addon_name) |
|
1002 | + { |
|
1003 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
1004 | + EE_Register_Personal_Data_Eraser::register( |
|
1005 | + $addon_name, |
|
1006 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
1007 | + ); |
|
1008 | + } |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * @param string $addon_name |
|
1014 | + * @return void |
|
1015 | + */ |
|
1016 | + private static function registerPersonalDataErasers(string $addon_name) |
|
1017 | + { |
|
1018 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1019 | + EE_Register_Personal_Data_Eraser::register( |
|
1020 | + $addon_name, |
|
1021 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1022 | + ); |
|
1023 | + } |
|
1024 | + } |
|
1025 | + |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1029 | + * |
|
1030 | + * @param string $addon_name |
|
1031 | + * @return EE_Addon |
|
1032 | + * @throws InvalidArgumentException |
|
1033 | + * @throws InvalidInterfaceException |
|
1034 | + * @throws InvalidDataTypeException |
|
1035 | + */ |
|
1036 | + private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
|
1037 | + { |
|
1038 | + $addon = self::$loader->getShared( |
|
1039 | + self::$_settings[ $addon_name ]['class_name'], |
|
1040 | + ['EE_Registry::create(addon)' => true] |
|
1041 | + ); |
|
1042 | + if (! $addon instanceof EE_Addon) { |
|
1043 | + throw new DomainException( |
|
1044 | + sprintf( |
|
1045 | + esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
1046 | + self::$_settings[ $addon_name ]['class_name'] |
|
1047 | + ) |
|
1048 | + ); |
|
1049 | + } |
|
1050 | + // setter inject dep map if required |
|
1051 | + if ($addon->dependencyMap() === null) { |
|
1052 | + $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
1053 | + } |
|
1054 | + // setter inject domain if required |
|
1055 | + EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1056 | + |
|
1057 | + $addon->set_name($addon_name); |
|
1058 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1059 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1060 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1061 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1062 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1063 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1064 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1065 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1066 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1067 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1068 | + // setup the add-on's pue_slug if we have one. |
|
1069 | + if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1070 | + $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1071 | + } |
|
1072 | + // unfortunately this can't be hooked in upon construction, because we don't have |
|
1073 | + // the plugin mainfile's path upon construction. |
|
1074 | + register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
1075 | + // call any additional admin_callback functions during load_admin_controller hook |
|
1076 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1077 | + add_action( |
|
1078 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1079 | + [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1080 | + ); |
|
1081 | + } |
|
1082 | + return $addon; |
|
1083 | + } |
|
1084 | + |
|
1085 | + |
|
1086 | + /** |
|
1087 | + * @param string $addon_name |
|
1088 | + * @param EE_Addon $addon |
|
1089 | + * @since 4.10.13.p |
|
1090 | + */ |
|
1091 | + private static function injectAddonDomain(string $addon_name, EE_Addon $addon) |
|
1092 | + { |
|
1093 | + if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1094 | + // using supplied Domain object |
|
1095 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1096 | + ? self::$_settings[ $addon_name ]['domain'] |
|
1097 | + : null; |
|
1098 | + // or construct one using Domain FQCN |
|
1099 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1100 | + $domain = self::$loader->getShared( |
|
1101 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1102 | + [ |
|
1103 | + new EventEspresso\core\domain\values\FilePath( |
|
1104 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
1105 | + ), |
|
1106 | + EventEspresso\core\domain\values\Version::fromString( |
|
1107 | + self::$_settings[ $addon_name ]['version'] |
|
1108 | + ), |
|
1109 | + ] |
|
1110 | + ); |
|
1111 | + } |
|
1112 | + if ($domain instanceof DomainInterface) { |
|
1113 | + $addon->setDomain($domain); |
|
1114 | + } |
|
1115 | + } |
|
1116 | + } |
|
1117 | + |
|
1118 | + |
|
1119 | + /** |
|
1120 | + * load_pue_update - Update notifications |
|
1121 | + * |
|
1122 | + * @return void |
|
1123 | + * @throws InvalidArgumentException |
|
1124 | + * @throws InvalidDataTypeException |
|
1125 | + * @throws InvalidInterfaceException |
|
1126 | + */ |
|
1127 | + public static function load_pue_update() |
|
1128 | + { |
|
1129 | + // load PUE client |
|
1130 | + require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1131 | + $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1132 | + // cycle thru settings |
|
1133 | + foreach (self::$_settings as $settings) { |
|
1134 | + if (! empty($settings['pue_options'])) { |
|
1135 | + // initiate the class and start the plugin update engine! |
|
1136 | + new PluginUpdateEngine( |
|
1137 | + // host file URL |
|
1138 | + $license_server, |
|
1139 | + // plugin slug(s) |
|
1140 | + [ |
|
1141 | + 'premium' => ['p' => $settings['pue_options']['pue_plugin_slug']], |
|
1142 | + 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'], |
|
1143 | + ], |
|
1144 | + // options |
|
1145 | + [ |
|
1146 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1147 | + 'lang_domain' => 'event_espresso', |
|
1148 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1149 | + 'option_key' => 'ee_site_license_key', |
|
1150 | + 'options_page_slug' => 'event_espresso', |
|
1151 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1152 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1153 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1154 | + ] |
|
1155 | + ); |
|
1156 | + } |
|
1157 | + } |
|
1158 | + } |
|
1159 | + |
|
1160 | + |
|
1161 | + /** |
|
1162 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1163 | + * |
|
1164 | + * @return void |
|
1165 | + * @throws EE_Error |
|
1166 | + * @since 4.4.0 |
|
1167 | + */ |
|
1168 | + public static function register_message_types() |
|
1169 | + { |
|
1170 | + foreach (self::$_settings as $settings) { |
|
1171 | + if (! empty($settings['message_types'])) { |
|
1172 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1173 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1174 | + } |
|
1175 | + } |
|
1176 | + } |
|
1177 | + } |
|
1178 | + |
|
1179 | + |
|
1180 | + /** |
|
1181 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1182 | + * |
|
1183 | + * @param string $addon_name the name for the addon that was previously registered |
|
1184 | + * @throws DomainException |
|
1185 | + * @throws InvalidArgumentException |
|
1186 | + * @throws InvalidDataTypeException |
|
1187 | + * @throws InvalidInterfaceException |
|
1188 | + * @since 4.3.0 |
|
1189 | + */ |
|
1190 | + public static function deregister(string $addon_name = '') |
|
1191 | + { |
|
1192 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1193 | + try { |
|
1194 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1195 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1196 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1197 | + // setup DMS |
|
1198 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1199 | + } |
|
1200 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1201 | + // register admin page |
|
1202 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1203 | + } |
|
1204 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1205 | + // add to list of modules to be registered |
|
1206 | + EE_Register_Module::deregister($addon_name); |
|
1207 | + } |
|
1208 | + if ( |
|
1209 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1210 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1211 | + ) { |
|
1212 | + // add to list of shortcodes to be registered |
|
1213 | + EE_Register_Shortcode::deregister($addon_name); |
|
1214 | + } |
|
1215 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1216 | + // if config_class present let's register config. |
|
1217 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1218 | + } |
|
1219 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1220 | + // add to list of widgets to be registered |
|
1221 | + EE_Register_Widget::deregister($addon_name); |
|
1222 | + } |
|
1223 | + if ( |
|
1224 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1225 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1226 | + ) { |
|
1227 | + // add to list of shortcodes to be registered |
|
1228 | + EE_Register_Model::deregister($addon_name); |
|
1229 | + } |
|
1230 | + if ( |
|
1231 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1232 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1233 | + ) { |
|
1234 | + // add to list of shortcodes to be registered |
|
1235 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1236 | + } |
|
1237 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1238 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1239 | + EE_Register_Message_Type::deregister($message_type); |
|
1240 | + } |
|
1241 | + } |
|
1242 | + // deregister capabilities for addon |
|
1243 | + if ( |
|
1244 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1245 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1246 | + ) { |
|
1247 | + EE_Register_Capabilities::deregister($addon_name); |
|
1248 | + } |
|
1249 | + // deregister custom_post_types for addon |
|
1250 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1251 | + EE_Register_CPT::deregister($addon_name); |
|
1252 | + } |
|
1253 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1254 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1255 | + } |
|
1256 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1257 | + if ($addon instanceof EE_Addon) { |
|
1258 | + remove_action( |
|
1259 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1260 | + [$addon, 'deactivation'] |
|
1261 | + ); |
|
1262 | + remove_action( |
|
1263 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1264 | + [$addon, 'initialize_db_if_no_migrations_required'] |
|
1265 | + ); |
|
1266 | + // remove `after_registration` call |
|
1267 | + remove_action( |
|
1268 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1269 | + [$addon, 'after_registration'], |
|
1270 | + 999 |
|
1271 | + ); |
|
1272 | + } |
|
1273 | + EE_Registry::instance()->removeAddon($class_name); |
|
1274 | + LoaderFactory::getLoader()->remove($class_name); |
|
1275 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1276 | + // the add-on was not yet registered in the registry, |
|
1277 | + // so RegistryContainer::__get() throws this exception. |
|
1278 | + // also no need to worry about this or log it, |
|
1279 | + // it's ok to deregister an add-on before its registered in the registry |
|
1280 | + } catch (Exception $e) { |
|
1281 | + new ExceptionLogger($e); |
|
1282 | + } |
|
1283 | + unset(self::$_settings[ $addon_name ]); |
|
1284 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1285 | + } |
|
1286 | + } |
|
1287 | 1287 | } |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | // offsets: 0 . 1 . 2 . 3 . 4 |
77 | 77 | $version_parts = explode('.', $min_core_version); |
78 | 78 | // check they specified the micro version (after 2nd period) |
79 | - if (! isset($version_parts[2])) { |
|
79 | + if ( ! isset($version_parts[2])) { |
|
80 | 80 | $version_parts[2] = '0'; |
81 | 81 | } |
82 | 82 | // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
83 | 83 | // soon we can assume that's 'rc', but this current version is 'alpha' |
84 | - if (! isset($version_parts[3])) { |
|
84 | + if ( ! isset($version_parts[3])) { |
|
85 | 85 | $version_parts[3] = 'dev'; |
86 | 86 | } |
87 | - if (! isset($version_parts[4])) { |
|
87 | + if ( ! isset($version_parts[4])) { |
|
88 | 88 | $version_parts[4] = '000'; |
89 | 89 | } |
90 | 90 | return implode('.', $version_parts); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public static function register(string $addon_name = '', array $setup_args = []): bool |
263 | 263 | { |
264 | - if (! self::$loader instanceof LoaderInterface) { |
|
264 | + if ( ! self::$loader instanceof LoaderInterface) { |
|
265 | 265 | self::$loader = LoaderFactory::getLoader(); |
266 | 266 | } |
267 | 267 | // make sure this was called in the right place! |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
296 | 296 | // does this addon work with this version of core or WordPress ? |
297 | 297 | // does this addon work with this version of core or WordPress ? |
298 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
298 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
299 | 299 | return false; |
300 | 300 | } |
301 | 301 | // register namespaces |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | ) |
361 | 361 | ); |
362 | 362 | } |
363 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
363 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
364 | 364 | throw new EE_Error( |
365 | 365 | sprintf( |
366 | 366 | esc_html__( |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | ); |
373 | 373 | } |
374 | 374 | // check that addon has not already been registered with that name |
375 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
375 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
376 | 376 | throw new EE_Error( |
377 | 377 | sprintf( |
378 | 378 | esc_html__( |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
405 | 405 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
406 | 406 | ? $class_name |
407 | - : 'EE_' . $class_name; |
|
407 | + : 'EE_'.$class_name; |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | |
@@ -572,9 +572,9 @@ discard block |
||
572 | 572 | $incompatibility_message = ''; |
573 | 573 | // check whether this addon version is compatible with EE core |
574 | 574 | if ( |
575 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
575 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
576 | 576 | && ! self::_meets_min_core_version_requirement( |
577 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
577 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
578 | 578 | $addon_settings['version'] |
579 | 579 | ) |
580 | 580 | ) { |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | ), |
586 | 586 | $addon_name, |
587 | 587 | '<br />', |
588 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
588 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
589 | 589 | '<span style="font-weight: bold; color: #D54E21;">', |
590 | 590 | '</span><br />' |
591 | 591 | ); |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | '</span><br />' |
618 | 618 | ); |
619 | 619 | } |
620 | - if (! empty($incompatibility_message)) { |
|
620 | + if ( ! empty($incompatibility_message)) { |
|
621 | 621 | // remove 'activate' from the REQUEST |
622 | 622 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
623 | 623 | /** @var RequestInterface $request */ |
@@ -647,11 +647,11 @@ discard block |
||
647 | 647 | */ |
648 | 648 | private static function _parse_pue_options(string $addon_name, string $class_name, array $setup_args) |
649 | 649 | { |
650 | - if (! empty($setup_args['pue_options'])) { |
|
651 | - self::$_settings[ $addon_name ]['pue_options'] = [ |
|
650 | + if ( ! empty($setup_args['pue_options'])) { |
|
651 | + self::$_settings[$addon_name]['pue_options'] = [ |
|
652 | 652 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
653 | 653 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
654 | - : 'espresso_' . strtolower($class_name), |
|
654 | + : 'espresso_'.strtolower($class_name), |
|
655 | 655 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
656 | 656 | ? (string) $setup_args['pue_options']['plugin_basename'] |
657 | 657 | : plugin_basename($setup_args['main_file_path']), |
@@ -710,12 +710,12 @@ discard block |
||
710 | 710 | // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
711 | 711 | // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
712 | 712 | if ( |
713 | - ! isset(self::$_settings[ $addon_name ]) |
|
714 | - || (isset(self::$_settings[ $addon_name ]) |
|
715 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
713 | + ! isset(self::$_settings[$addon_name]) |
|
714 | + || (isset(self::$_settings[$addon_name]) |
|
715 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
716 | 716 | ) |
717 | 717 | ) { |
718 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
718 | + self::$_settings[$addon_name] = $addon_settings; |
|
719 | 719 | $addon = self::_load_and_init_addon_class($addon_name); |
720 | 720 | $addon->set_activation_indicator_option(); |
721 | 721 | // dont bother setting up the rest of the addon. |
@@ -724,10 +724,10 @@ discard block |
||
724 | 724 | return true; |
725 | 725 | } |
726 | 726 | // make sure addon settings are set correctly without overwriting anything existing |
727 | - if (isset(self::$_settings[ $addon_name ])) { |
|
728 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
727 | + if (isset(self::$_settings[$addon_name])) { |
|
728 | + self::$_settings[$addon_name] += $addon_settings; |
|
729 | 729 | } else { |
730 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
730 | + self::$_settings[$addon_name] = $addon_settings; |
|
731 | 731 | } |
732 | 732 | return false; |
733 | 733 | } |
@@ -740,13 +740,13 @@ discard block |
||
740 | 740 | */ |
741 | 741 | private static function _setup_autoloaders(string $addon_name) |
742 | 742 | { |
743 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
743 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
744 | 744 | // setup autoloader for single file |
745 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
745 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
746 | 746 | } |
747 | 747 | // setup autoloaders for folders |
748 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
749 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
748 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
749 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
750 | 750 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
751 | 751 | } |
752 | 752 | } |
@@ -764,27 +764,27 @@ discard block |
||
764 | 764 | { |
765 | 765 | // register new models |
766 | 766 | if ( |
767 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
768 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
767 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
768 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
769 | 769 | ) { |
770 | 770 | EE_Register_Model::register( |
771 | 771 | $addon_name, |
772 | 772 | [ |
773 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
774 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
773 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
774 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
775 | 775 | ] |
776 | 776 | ); |
777 | 777 | } |
778 | 778 | // register model extensions |
779 | 779 | if ( |
780 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
781 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
780 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
781 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
782 | 782 | ) { |
783 | 783 | EE_Register_Model_Extensions::register( |
784 | 784 | $addon_name, |
785 | 785 | [ |
786 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
787 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
786 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
787 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
788 | 788 | ] |
789 | 789 | ); |
790 | 790 | } |
@@ -799,10 +799,10 @@ discard block |
||
799 | 799 | private static function _register_data_migration_scripts(string $addon_name) |
800 | 800 | { |
801 | 801 | // setup DMS |
802 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
802 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
803 | 803 | EE_Register_Data_Migration_Scripts::register( |
804 | 804 | $addon_name, |
805 | - ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
805 | + ['dms_paths' => self::$_settings[$addon_name]['dms_paths']] |
|
806 | 806 | ); |
807 | 807 | } |
808 | 808 | } |
@@ -816,12 +816,12 @@ discard block |
||
816 | 816 | private static function _register_config(string $addon_name) |
817 | 817 | { |
818 | 818 | // if config_class is present let's register config. |
819 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
819 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
820 | 820 | EE_Register_Config::register( |
821 | - self::$_settings[ $addon_name ]['config_class'], |
|
821 | + self::$_settings[$addon_name]['config_class'], |
|
822 | 822 | [ |
823 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
824 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
823 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
824 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
825 | 825 | ] |
826 | 826 | ); |
827 | 827 | } |
@@ -835,10 +835,10 @@ discard block |
||
835 | 835 | */ |
836 | 836 | private static function _register_admin_pages(string $addon_name) |
837 | 837 | { |
838 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
838 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
839 | 839 | EE_Register_Admin_Page::register( |
840 | 840 | $addon_name, |
841 | - ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
841 | + ['page_path' => self::$_settings[$addon_name]['admin_path']] |
|
842 | 842 | ); |
843 | 843 | } |
844 | 844 | } |
@@ -851,10 +851,10 @@ discard block |
||
851 | 851 | */ |
852 | 852 | private static function _register_modules(string $addon_name) |
853 | 853 | { |
854 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
854 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
855 | 855 | EE_Register_Module::register( |
856 | 856 | $addon_name, |
857 | - ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
857 | + ['module_paths' => self::$_settings[$addon_name]['module_paths']] |
|
858 | 858 | ); |
859 | 859 | } |
860 | 860 | } |
@@ -868,14 +868,14 @@ discard block |
||
868 | 868 | private static function _register_shortcodes(string $addon_name) |
869 | 869 | { |
870 | 870 | if ( |
871 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
872 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
871 | + ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
872 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
873 | 873 | ) { |
874 | 874 | EE_Register_Shortcode::register( |
875 | 875 | $addon_name, |
876 | 876 | [ |
877 | - 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
878 | - 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
877 | + 'shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'] ?? [], |
|
878 | + 'shortcode_fqcns' => self::$_settings[$addon_name]['shortcode_fqcns'] ?? [], |
|
879 | 879 | ] |
880 | 880 | ); |
881 | 881 | } |
@@ -889,10 +889,10 @@ discard block |
||
889 | 889 | */ |
890 | 890 | private static function _register_widgets(string $addon_name) |
891 | 891 | { |
892 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
892 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
893 | 893 | EE_Register_Widget::register( |
894 | 894 | $addon_name, |
895 | - ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
895 | + ['widget_paths' => self::$_settings[$addon_name]['widget_paths']] |
|
896 | 896 | ); |
897 | 897 | } |
898 | 898 | } |
@@ -905,12 +905,12 @@ discard block |
||
905 | 905 | */ |
906 | 906 | private static function _register_capabilities(string $addon_name) |
907 | 907 | { |
908 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
908 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
909 | 909 | EE_Register_Capabilities::register( |
910 | 910 | $addon_name, |
911 | 911 | [ |
912 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
913 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
912 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
913 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
914 | 914 | ] |
915 | 915 | ); |
916 | 916 | } |
@@ -923,7 +923,7 @@ discard block |
||
923 | 923 | */ |
924 | 924 | private static function _register_message_types(string $addon_name) |
925 | 925 | { |
926 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
926 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
927 | 927 | add_action( |
928 | 928 | 'EE_Brewing_Regular___messages_caf', |
929 | 929 | ['EE_Register_Addon', 'register_message_types'] |
@@ -940,15 +940,15 @@ discard block |
||
940 | 940 | private static function _register_custom_post_types(string $addon_name) |
941 | 941 | { |
942 | 942 | if ( |
943 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
944 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
943 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
944 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
945 | 945 | ) { |
946 | 946 | EE_Register_CPT::register( |
947 | 947 | $addon_name, |
948 | 948 | [ |
949 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
950 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
951 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
949 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
950 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
951 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
952 | 952 | ] |
953 | 953 | ); |
954 | 954 | } |
@@ -966,10 +966,10 @@ discard block |
||
966 | 966 | */ |
967 | 967 | private static function _register_payment_methods(string $addon_name) |
968 | 968 | { |
969 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
969 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
970 | 970 | EE_Register_Payment_Method::register( |
971 | 971 | $addon_name, |
972 | - ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
972 | + ['payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']] |
|
973 | 973 | ); |
974 | 974 | } |
975 | 975 | } |
@@ -985,10 +985,10 @@ discard block |
||
985 | 985 | */ |
986 | 986 | private static function registerPrivacyPolicies(string $addon_name) |
987 | 987 | { |
988 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
988 | + if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) { |
|
989 | 989 | EE_Register_Privacy_Policy::register( |
990 | 990 | $addon_name, |
991 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
991 | + self::$_settings[$addon_name]['privacy_policies'] |
|
992 | 992 | ); |
993 | 993 | } |
994 | 994 | } |
@@ -1000,10 +1000,10 @@ discard block |
||
1000 | 1000 | */ |
1001 | 1001 | private static function registerPersonalDataExporters(string $addon_name) |
1002 | 1002 | { |
1003 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
1003 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) { |
|
1004 | 1004 | EE_Register_Personal_Data_Eraser::register( |
1005 | 1005 | $addon_name, |
1006 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
1006 | + self::$_settings[$addon_name]['personal_data_exporters'] |
|
1007 | 1007 | ); |
1008 | 1008 | } |
1009 | 1009 | } |
@@ -1015,10 +1015,10 @@ discard block |
||
1015 | 1015 | */ |
1016 | 1016 | private static function registerPersonalDataErasers(string $addon_name) |
1017 | 1017 | { |
1018 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1018 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) { |
|
1019 | 1019 | EE_Register_Personal_Data_Eraser::register( |
1020 | 1020 | $addon_name, |
1021 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1021 | + self::$_settings[$addon_name]['personal_data_erasers'] |
|
1022 | 1022 | ); |
1023 | 1023 | } |
1024 | 1024 | } |
@@ -1036,14 +1036,14 @@ discard block |
||
1036 | 1036 | private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
1037 | 1037 | { |
1038 | 1038 | $addon = self::$loader->getShared( |
1039 | - self::$_settings[ $addon_name ]['class_name'], |
|
1039 | + self::$_settings[$addon_name]['class_name'], |
|
1040 | 1040 | ['EE_Registry::create(addon)' => true] |
1041 | 1041 | ); |
1042 | - if (! $addon instanceof EE_Addon) { |
|
1042 | + if ( ! $addon instanceof EE_Addon) { |
|
1043 | 1043 | throw new DomainException( |
1044 | 1044 | sprintf( |
1045 | 1045 | esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
1046 | - self::$_settings[ $addon_name ]['class_name'] |
|
1046 | + self::$_settings[$addon_name]['class_name'] |
|
1047 | 1047 | ) |
1048 | 1048 | ); |
1049 | 1049 | } |
@@ -1055,28 +1055,28 @@ discard block |
||
1055 | 1055 | EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
1056 | 1056 | |
1057 | 1057 | $addon->set_name($addon_name); |
1058 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1059 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1060 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1061 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1062 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1063 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1064 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1065 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1066 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1067 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1058 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
1059 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
1060 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
1061 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
1062 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
1063 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
1064 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
1065 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
1066 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
1067 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
1068 | 1068 | // setup the add-on's pue_slug if we have one. |
1069 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1070 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1069 | + if ( ! empty(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug'])) { |
|
1070 | + $addon->setPueSlug(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug']); |
|
1071 | 1071 | } |
1072 | 1072 | // unfortunately this can't be hooked in upon construction, because we don't have |
1073 | 1073 | // the plugin mainfile's path upon construction. |
1074 | 1074 | register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
1075 | 1075 | // call any additional admin_callback functions during load_admin_controller hook |
1076 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1076 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
1077 | 1077 | add_action( |
1078 | 1078 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
1079 | - [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1079 | + [$addon, self::$_settings[$addon_name]['admin_callback']] |
|
1080 | 1080 | ); |
1081 | 1081 | } |
1082 | 1082 | return $addon; |
@@ -1092,19 +1092,19 @@ discard block |
||
1092 | 1092 | { |
1093 | 1093 | if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
1094 | 1094 | // using supplied Domain object |
1095 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1096 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1095 | + $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface |
|
1096 | + ? self::$_settings[$addon_name]['domain'] |
|
1097 | 1097 | : null; |
1098 | 1098 | // or construct one using Domain FQCN |
1099 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1099 | + if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') { |
|
1100 | 1100 | $domain = self::$loader->getShared( |
1101 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1101 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
1102 | 1102 | [ |
1103 | 1103 | new EventEspresso\core\domain\values\FilePath( |
1104 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1104 | + self::$_settings[$addon_name]['main_file_path'] |
|
1105 | 1105 | ), |
1106 | 1106 | EventEspresso\core\domain\values\Version::fromString( |
1107 | - self::$_settings[ $addon_name ]['version'] |
|
1107 | + self::$_settings[$addon_name]['version'] |
|
1108 | 1108 | ), |
1109 | 1109 | ] |
1110 | 1110 | ); |
@@ -1127,11 +1127,11 @@ discard block |
||
1127 | 1127 | public static function load_pue_update() |
1128 | 1128 | { |
1129 | 1129 | // load PUE client |
1130 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1130 | + require_once EE_THIRD_PARTY.'pue/pue-client.php'; |
|
1131 | 1131 | $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
1132 | 1132 | // cycle thru settings |
1133 | 1133 | foreach (self::$_settings as $settings) { |
1134 | - if (! empty($settings['pue_options'])) { |
|
1134 | + if ( ! empty($settings['pue_options'])) { |
|
1135 | 1135 | // initiate the class and start the plugin update engine! |
1136 | 1136 | new PluginUpdateEngine( |
1137 | 1137 | // host file URL |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | // plugin slug(s) |
1140 | 1140 | [ |
1141 | 1141 | 'premium' => ['p' => $settings['pue_options']['pue_plugin_slug']], |
1142 | - 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'], |
|
1142 | + 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'], |
|
1143 | 1143 | ], |
1144 | 1144 | // options |
1145 | 1145 | [ |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | public static function register_message_types() |
1169 | 1169 | { |
1170 | 1170 | foreach (self::$_settings as $settings) { |
1171 | - if (! empty($settings['message_types'])) { |
|
1171 | + if ( ! empty($settings['message_types'])) { |
|
1172 | 1172 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
1173 | 1173 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
1174 | 1174 | } |
@@ -1189,74 +1189,74 @@ discard block |
||
1189 | 1189 | */ |
1190 | 1190 | public static function deregister(string $addon_name = '') |
1191 | 1191 | { |
1192 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1192 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
1193 | 1193 | try { |
1194 | 1194 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
1195 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1196 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1195 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
1196 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1197 | 1197 | // setup DMS |
1198 | 1198 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
1199 | 1199 | } |
1200 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1200 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1201 | 1201 | // register admin page |
1202 | 1202 | EE_Register_Admin_Page::deregister($addon_name); |
1203 | 1203 | } |
1204 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1204 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1205 | 1205 | // add to list of modules to be registered |
1206 | 1206 | EE_Register_Module::deregister($addon_name); |
1207 | 1207 | } |
1208 | 1208 | if ( |
1209 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1210 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1209 | + ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1210 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1211 | 1211 | ) { |
1212 | 1212 | // add to list of shortcodes to be registered |
1213 | 1213 | EE_Register_Shortcode::deregister($addon_name); |
1214 | 1214 | } |
1215 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1215 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1216 | 1216 | // if config_class present let's register config. |
1217 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1217 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1218 | 1218 | } |
1219 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1219 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1220 | 1220 | // add to list of widgets to be registered |
1221 | 1221 | EE_Register_Widget::deregister($addon_name); |
1222 | 1222 | } |
1223 | 1223 | if ( |
1224 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1225 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1224 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1225 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1226 | 1226 | ) { |
1227 | 1227 | // add to list of shortcodes to be registered |
1228 | 1228 | EE_Register_Model::deregister($addon_name); |
1229 | 1229 | } |
1230 | 1230 | if ( |
1231 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1232 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1231 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1232 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1233 | 1233 | ) { |
1234 | 1234 | // add to list of shortcodes to be registered |
1235 | 1235 | EE_Register_Model_Extensions::deregister($addon_name); |
1236 | 1236 | } |
1237 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1238 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1237 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1238 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
1239 | 1239 | EE_Register_Message_Type::deregister($message_type); |
1240 | 1240 | } |
1241 | 1241 | } |
1242 | 1242 | // deregister capabilities for addon |
1243 | 1243 | if ( |
1244 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1245 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1244 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1245 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1246 | 1246 | ) { |
1247 | 1247 | EE_Register_Capabilities::deregister($addon_name); |
1248 | 1248 | } |
1249 | 1249 | // deregister custom_post_types for addon |
1250 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1250 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1251 | 1251 | EE_Register_CPT::deregister($addon_name); |
1252 | 1252 | } |
1253 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1253 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1254 | 1254 | EE_Register_Payment_Method::deregister($addon_name); |
1255 | 1255 | } |
1256 | 1256 | $addon = EE_Registry::instance()->getAddon($class_name); |
1257 | 1257 | if ($addon instanceof EE_Addon) { |
1258 | 1258 | remove_action( |
1259 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1259 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
1260 | 1260 | [$addon, 'deactivation'] |
1261 | 1261 | ); |
1262 | 1262 | remove_action( |
@@ -1280,7 +1280,7 @@ discard block |
||
1280 | 1280 | } catch (Exception $e) { |
1281 | 1281 | new ExceptionLogger($e); |
1282 | 1282 | } |
1283 | - unset(self::$_settings[ $addon_name ]); |
|
1283 | + unset(self::$_settings[$addon_name]); |
|
1284 | 1284 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1285 | 1285 | } |
1286 | 1286 | } |
@@ -21,86 +21,86 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class Stats |
23 | 23 | { |
24 | - const OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS = 'ee_uxip_stats_expiry'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var Config |
|
28 | - */ |
|
29 | - private $config; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @var StatsGatherer |
|
34 | - */ |
|
35 | - private $stats_gatherer; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @var EE_Maintenance_Mode |
|
40 | - */ |
|
41 | - private $maintenance_mode; |
|
42 | - |
|
43 | - public function __construct( |
|
44 | - Config $config, |
|
45 | - EE_Maintenance_Mode $maintenance_mode, |
|
46 | - StatsGatherer $stats_gatherer |
|
47 | - ) { |
|
48 | - $this->config = $config; |
|
49 | - $this->maintenance_mode = $maintenance_mode; |
|
50 | - $this->stats_gatherer = $stats_gatherer; |
|
51 | - $this->setUxipNotices(); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Displays uxip opt-in notice if necessary. |
|
57 | - */ |
|
58 | - private function setUxipNotices() |
|
59 | - { |
|
60 | - if ($this->canDisplayNotices()) { |
|
61 | - add_action('admin_notices', array($this, 'optinNotice')); |
|
62 | - add_action('admin_enqueue_scripts', array($this, 'enqueueScripts')); |
|
63 | - add_action('wp_ajax_espresso_data_optin', array($this, 'ajaxHandler')); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * This returns the callback that PluginUpdateEngine will use for getting any extra stats to send. |
|
70 | - * |
|
71 | - * @return Closure |
|
72 | - */ |
|
73 | - public function statsCallback() |
|
74 | - { |
|
75 | - // returns a callback that can is used to retrieve the stats to send along to the pue server. |
|
76 | - return function () { |
|
77 | - // we only send stats one a week, so let's see if our stat timestamp has expired. |
|
78 | - if (! $this->sendStats()) { |
|
79 | - return array(); |
|
80 | - } |
|
81 | - return $this->stats_gatherer->stats(); |
|
82 | - }; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Return whether notices can be displayed or not |
|
88 | - * |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - private function canDisplayNotices() |
|
92 | - { |
|
93 | - return ! $this->config->hasNotifiedForUxip() |
|
94 | - && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Callback for the admin_notices hook that outputs the UXIP optin-in notice. |
|
100 | - */ |
|
101 | - public function optinNotice() |
|
102 | - { |
|
103 | - ?> |
|
24 | + const OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS = 'ee_uxip_stats_expiry'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var Config |
|
28 | + */ |
|
29 | + private $config; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @var StatsGatherer |
|
34 | + */ |
|
35 | + private $stats_gatherer; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @var EE_Maintenance_Mode |
|
40 | + */ |
|
41 | + private $maintenance_mode; |
|
42 | + |
|
43 | + public function __construct( |
|
44 | + Config $config, |
|
45 | + EE_Maintenance_Mode $maintenance_mode, |
|
46 | + StatsGatherer $stats_gatherer |
|
47 | + ) { |
|
48 | + $this->config = $config; |
|
49 | + $this->maintenance_mode = $maintenance_mode; |
|
50 | + $this->stats_gatherer = $stats_gatherer; |
|
51 | + $this->setUxipNotices(); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Displays uxip opt-in notice if necessary. |
|
57 | + */ |
|
58 | + private function setUxipNotices() |
|
59 | + { |
|
60 | + if ($this->canDisplayNotices()) { |
|
61 | + add_action('admin_notices', array($this, 'optinNotice')); |
|
62 | + add_action('admin_enqueue_scripts', array($this, 'enqueueScripts')); |
|
63 | + add_action('wp_ajax_espresso_data_optin', array($this, 'ajaxHandler')); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * This returns the callback that PluginUpdateEngine will use for getting any extra stats to send. |
|
70 | + * |
|
71 | + * @return Closure |
|
72 | + */ |
|
73 | + public function statsCallback() |
|
74 | + { |
|
75 | + // returns a callback that can is used to retrieve the stats to send along to the pue server. |
|
76 | + return function () { |
|
77 | + // we only send stats one a week, so let's see if our stat timestamp has expired. |
|
78 | + if (! $this->sendStats()) { |
|
79 | + return array(); |
|
80 | + } |
|
81 | + return $this->stats_gatherer->stats(); |
|
82 | + }; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Return whether notices can be displayed or not |
|
88 | + * |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + private function canDisplayNotices() |
|
92 | + { |
|
93 | + return ! $this->config->hasNotifiedForUxip() |
|
94 | + && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Callback for the admin_notices hook that outputs the UXIP optin-in notice. |
|
100 | + */ |
|
101 | + public function optinNotice() |
|
102 | + { |
|
103 | + ?> |
|
104 | 104 | <div class="espresso-notices updated data-collect-optin" id="espresso-data-collect-optin-container"> |
105 | 105 | <div id="data-collect-optin-options-container"> |
106 | 106 | <span class="dashicons dashicons-admin-site"></span> |
@@ -113,128 +113,128 @@ discard block |
||
113 | 113 | </div> |
114 | 114 | </div> |
115 | 115 | <?php |
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Retrieves the optin text (static so it can be used in multiple places as necessary). |
|
121 | - * |
|
122 | - * @param bool $extra |
|
123 | - */ |
|
124 | - public static function optinText($extra = true) |
|
125 | - { |
|
126 | - if (! $extra) { |
|
127 | - echo '<h2 class="ee-admin-settings-hdr" ' |
|
128 | - . (! $extra ? 'id="UXIP_settings"' : '') |
|
129 | - . '>' |
|
130 | - . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
|
131 | - . EEH_Template::get_help_tab_link('organization_logo_info') |
|
132 | - . '</h2>'; |
|
133 | - printf( |
|
134 | - esc_html__( |
|
135 | - '%1$sPlease help us make Event Espresso better and vote for your favorite features.%2$s The %3$sUser eXperience Improvement Program (UXIP)%4$s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary and it is disabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %5$sPlease see our %6$sPrivacy Policy%7$s for more information.', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - '<p><em>', |
|
139 | - '</em></p>', |
|
140 | - '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
141 | - '</a>', |
|
142 | - '<br><br>', |
|
143 | - '<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">', |
|
144 | - '</a>' |
|
145 | - ); |
|
146 | - } else { |
|
147 | - $settings_url = EEH_URL::add_query_args_and_nonce( |
|
148 | - array('action' => 'default'), |
|
149 | - admin_url('admin.php?page=espresso_general_settings') |
|
150 | - ); |
|
151 | - $settings_url .= '#UXIP_settings'; |
|
152 | - printf( |
|
153 | - esc_html__( |
|
154 | - 'The Event Espresso UXIP feature is not yet active on your site. For %1$smore info%2$s and to opt-in %3$sclick here%4$s.', |
|
155 | - 'event_espresso' |
|
156 | - ), |
|
157 | - '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
158 | - '</a>', |
|
159 | - '<a href="' . $settings_url . '" target="_blank">', |
|
160 | - '</a>' |
|
161 | - ); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Callback for admin_enqueue_scripts that sets up the scripts and styles for the uxip notice |
|
168 | - */ |
|
169 | - public function enqueueScripts() |
|
170 | - { |
|
171 | - wp_register_script( |
|
172 | - 'ee-data-optin-js', |
|
173 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
174 | - array('jquery'), |
|
175 | - EVENT_ESPRESSO_VERSION, |
|
176 | - true |
|
177 | - ); |
|
178 | - wp_register_style( |
|
179 | - 'ee-data-optin-css', |
|
180 | - EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
181 | - array(), |
|
182 | - EVENT_ESPRESSO_VERSION |
|
183 | - ); |
|
184 | - |
|
185 | - wp_enqueue_script('ee-data-optin-js'); |
|
186 | - wp_enqueue_style('ee-data-optin-css'); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * Callback for wp_ajax_espresso_data_optin that handles the ajax request |
|
192 | - */ |
|
193 | - public function ajaxHandler() |
|
194 | - { |
|
195 | - /** @var RequestInterface $request */ |
|
196 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
197 | - $nonce = $request->getRequestParam('nonce'); |
|
198 | - // verify nonce |
|
199 | - if (! $nonce || ! wp_verify_nonce($nonce, 'ee-data-optin')) { |
|
200 | - exit(); |
|
201 | - } |
|
202 | - |
|
203 | - // update has notified option |
|
204 | - $this->config->setHasNotifiedAboutUxip(); |
|
205 | - exit(); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Used to determine whether additional stats are sent. |
|
211 | - */ |
|
212 | - private function sendStats() |
|
213 | - { |
|
214 | - return $this->config->isOptedInForUxip() |
|
215 | - && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
216 | - && $this->statSendTimestampExpired(); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * Returns true when the timestamp used to track whether stats get sent (currently a weekly interval) is expired. |
|
222 | - * Returns false otherwise. |
|
223 | - * |
|
224 | - * @return bool |
|
225 | - */ |
|
226 | - private function statSendTimestampExpired() |
|
227 | - { |
|
228 | - $current_expiry = get_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, null); |
|
229 | - if ($current_expiry === null) { |
|
230 | - add_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS, '', 'no'); |
|
231 | - return true; |
|
232 | - } |
|
233 | - |
|
234 | - if (time() > (int) $current_expiry) { |
|
235 | - update_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS); |
|
236 | - return true; |
|
237 | - } |
|
238 | - return false; |
|
239 | - } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Retrieves the optin text (static so it can be used in multiple places as necessary). |
|
121 | + * |
|
122 | + * @param bool $extra |
|
123 | + */ |
|
124 | + public static function optinText($extra = true) |
|
125 | + { |
|
126 | + if (! $extra) { |
|
127 | + echo '<h2 class="ee-admin-settings-hdr" ' |
|
128 | + . (! $extra ? 'id="UXIP_settings"' : '') |
|
129 | + . '>' |
|
130 | + . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
|
131 | + . EEH_Template::get_help_tab_link('organization_logo_info') |
|
132 | + . '</h2>'; |
|
133 | + printf( |
|
134 | + esc_html__( |
|
135 | + '%1$sPlease help us make Event Espresso better and vote for your favorite features.%2$s The %3$sUser eXperience Improvement Program (UXIP)%4$s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary and it is disabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %5$sPlease see our %6$sPrivacy Policy%7$s for more information.', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + '<p><em>', |
|
139 | + '</em></p>', |
|
140 | + '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
141 | + '</a>', |
|
142 | + '<br><br>', |
|
143 | + '<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">', |
|
144 | + '</a>' |
|
145 | + ); |
|
146 | + } else { |
|
147 | + $settings_url = EEH_URL::add_query_args_and_nonce( |
|
148 | + array('action' => 'default'), |
|
149 | + admin_url('admin.php?page=espresso_general_settings') |
|
150 | + ); |
|
151 | + $settings_url .= '#UXIP_settings'; |
|
152 | + printf( |
|
153 | + esc_html__( |
|
154 | + 'The Event Espresso UXIP feature is not yet active on your site. For %1$smore info%2$s and to opt-in %3$sclick here%4$s.', |
|
155 | + 'event_espresso' |
|
156 | + ), |
|
157 | + '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
158 | + '</a>', |
|
159 | + '<a href="' . $settings_url . '" target="_blank">', |
|
160 | + '</a>' |
|
161 | + ); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Callback for admin_enqueue_scripts that sets up the scripts and styles for the uxip notice |
|
168 | + */ |
|
169 | + public function enqueueScripts() |
|
170 | + { |
|
171 | + wp_register_script( |
|
172 | + 'ee-data-optin-js', |
|
173 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
174 | + array('jquery'), |
|
175 | + EVENT_ESPRESSO_VERSION, |
|
176 | + true |
|
177 | + ); |
|
178 | + wp_register_style( |
|
179 | + 'ee-data-optin-css', |
|
180 | + EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
181 | + array(), |
|
182 | + EVENT_ESPRESSO_VERSION |
|
183 | + ); |
|
184 | + |
|
185 | + wp_enqueue_script('ee-data-optin-js'); |
|
186 | + wp_enqueue_style('ee-data-optin-css'); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * Callback for wp_ajax_espresso_data_optin that handles the ajax request |
|
192 | + */ |
|
193 | + public function ajaxHandler() |
|
194 | + { |
|
195 | + /** @var RequestInterface $request */ |
|
196 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
197 | + $nonce = $request->getRequestParam('nonce'); |
|
198 | + // verify nonce |
|
199 | + if (! $nonce || ! wp_verify_nonce($nonce, 'ee-data-optin')) { |
|
200 | + exit(); |
|
201 | + } |
|
202 | + |
|
203 | + // update has notified option |
|
204 | + $this->config->setHasNotifiedAboutUxip(); |
|
205 | + exit(); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Used to determine whether additional stats are sent. |
|
211 | + */ |
|
212 | + private function sendStats() |
|
213 | + { |
|
214 | + return $this->config->isOptedInForUxip() |
|
215 | + && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
216 | + && $this->statSendTimestampExpired(); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * Returns true when the timestamp used to track whether stats get sent (currently a weekly interval) is expired. |
|
222 | + * Returns false otherwise. |
|
223 | + * |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | + private function statSendTimestampExpired() |
|
227 | + { |
|
228 | + $current_expiry = get_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, null); |
|
229 | + if ($current_expiry === null) { |
|
230 | + add_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS, '', 'no'); |
|
231 | + return true; |
|
232 | + } |
|
233 | + |
|
234 | + if (time() > (int) $current_expiry) { |
|
235 | + update_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS); |
|
236 | + return true; |
|
237 | + } |
|
238 | + return false; |
|
239 | + } |
|
240 | 240 | } |
@@ -15,81 +15,81 @@ |
||
15 | 15 | */ |
16 | 16 | class LicenseService |
17 | 17 | { |
18 | - /** |
|
19 | - * @var Config |
|
20 | - */ |
|
21 | - private $config; |
|
18 | + /** |
|
19 | + * @var Config |
|
20 | + */ |
|
21 | + private $config; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @var Stats |
|
26 | - */ |
|
27 | - private $stats_collection; |
|
24 | + /** |
|
25 | + * @var Stats |
|
26 | + */ |
|
27 | + private $stats_collection; |
|
28 | 28 | |
29 | 29 | |
30 | - public function __construct(Stats $stats_collection, Config $config) |
|
31 | - { |
|
32 | - $this->config = $config; |
|
33 | - $this->stats_collection = $stats_collection; |
|
34 | - $this->loadPueClient(); |
|
35 | - } |
|
30 | + public function __construct(Stats $stats_collection, Config $config) |
|
31 | + { |
|
32 | + $this->config = $config; |
|
33 | + $this->stats_collection = $stats_collection; |
|
34 | + $this->loadPueClient(); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - private function loadPueClient() |
|
39 | - { |
|
40 | - // initiate the class and start the plugin update engine! |
|
41 | - new PluginUpdateEngine( |
|
42 | - $this->config->hostServerUrl(), |
|
43 | - $this->config->pluginSlug(), |
|
44 | - // $options needs to be an array with the included keys as listed. |
|
45 | - [ |
|
46 | - // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
47 | - // clients options table. Will be automatically set if left blank. |
|
48 | - 'apikey' => $this->config->siteLicenseKey(), |
|
49 | - // (required), you will need to obtain the apikey that the client gets from your site and |
|
50 | - // then saves in their sites options table (see 'getting an api-key' below) |
|
51 | - 'lang_domain' => $this->config->i18nDomain(), |
|
52 | - // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
53 | - // localized). That way strings in this file will be included in the translation for your plugin. |
|
54 | - 'checkPeriod' => $this->config->checkPeriod(), |
|
55 | - // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
56 | - // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
57 | - // default to 12 hours. |
|
58 | - 'option_key' => $this->config->optionKey(), |
|
59 | - // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
60 | - // updating your information message whenever this option_key is modified. |
|
61 | - 'options_page_slug' => $this->config->optionsPageSlug(), |
|
62 | - 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
63 | - 'use_wp_update' => true, |
|
64 | - // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
65 | - 'extra_stats' => $this->stats_collection->statsCallback(), |
|
66 | - 'turn_on_notices_saved' => true, |
|
67 | - ] |
|
68 | - ); |
|
69 | - } |
|
38 | + private function loadPueClient() |
|
39 | + { |
|
40 | + // initiate the class and start the plugin update engine! |
|
41 | + new PluginUpdateEngine( |
|
42 | + $this->config->hostServerUrl(), |
|
43 | + $this->config->pluginSlug(), |
|
44 | + // $options needs to be an array with the included keys as listed. |
|
45 | + [ |
|
46 | + // 'optionName' => '', //(optional) - used as the reference for saving update information in the |
|
47 | + // clients options table. Will be automatically set if left blank. |
|
48 | + 'apikey' => $this->config->siteLicenseKey(), |
|
49 | + // (required), you will need to obtain the apikey that the client gets from your site and |
|
50 | + // then saves in their sites options table (see 'getting an api-key' below) |
|
51 | + 'lang_domain' => $this->config->i18nDomain(), |
|
52 | + // (optional) - put here whatever reference you are using for the localization of your plugin (if it's |
|
53 | + // localized). That way strings in this file will be included in the translation for your plugin. |
|
54 | + 'checkPeriod' => $this->config->checkPeriod(), |
|
55 | + // (optional) - use this parameter to indicate how often you want the client's install to ping your |
|
56 | + // server for update checks. The integer indicates hours. If you don't include this parameter it will |
|
57 | + // default to 12 hours. |
|
58 | + 'option_key' => $this->config->optionKey(), |
|
59 | + // this is what is used to reference the api_key in your plugin options. PUE uses this to trigger |
|
60 | + // updating your information message whenever this option_key is modified. |
|
61 | + 'options_page_slug' => $this->config->optionsPageSlug(), |
|
62 | + 'plugin_basename' => EE_PLUGIN_BASENAME, |
|
63 | + 'use_wp_update' => true, |
|
64 | + // if TRUE then you want FREE versions of the plugin to be updated from WP |
|
65 | + 'extra_stats' => $this->stats_collection->statsCallback(), |
|
66 | + 'turn_on_notices_saved' => true, |
|
67 | + ] |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
74 | - * |
|
75 | - * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
76 | - * identify plugins. Defaults to core update |
|
77 | - * @return boolean True if update available, false if not. |
|
78 | - */ |
|
79 | - public static function isUpdateAvailable(string $basename = ''): bool |
|
80 | - { |
|
81 | - $update = false; |
|
82 | - $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
83 | - $current = get_site_transient('update_plugins'); |
|
84 | - if (isset($current->response['plugin_file'])) { |
|
85 | - // convert "event-espresso-core/espresso.php" to "/event-espresso-core" and get plugins |
|
86 | - $plugins = get_plugins('/' . dirname($basename)); |
|
87 | - foreach ($plugins as $plugin_file => $plugin_data) { |
|
88 | - // toggle update to true if a match is found |
|
89 | - $update = $current->response['plugin_file'] === $plugin_file ? true : $update; |
|
90 | - } |
|
91 | - } |
|
92 | - // it's also possible that there's an update but an invalid site-license-key is in use |
|
93 | - return get_site_option('pue_json_error_' . $basename) ? true : $update; |
|
94 | - } |
|
72 | + /** |
|
73 | + * This is a handy helper method for retrieving whether there is an update available for the given plugin. |
|
74 | + * |
|
75 | + * @param string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to |
|
76 | + * identify plugins. Defaults to core update |
|
77 | + * @return boolean True if update available, false if not. |
|
78 | + */ |
|
79 | + public static function isUpdateAvailable(string $basename = ''): bool |
|
80 | + { |
|
81 | + $update = false; |
|
82 | + $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
83 | + $current = get_site_transient('update_plugins'); |
|
84 | + if (isset($current->response['plugin_file'])) { |
|
85 | + // convert "event-espresso-core/espresso.php" to "/event-espresso-core" and get plugins |
|
86 | + $plugins = get_plugins('/' . dirname($basename)); |
|
87 | + foreach ($plugins as $plugin_file => $plugin_data) { |
|
88 | + // toggle update to true if a match is found |
|
89 | + $update = $current->response['plugin_file'] === $plugin_file ? true : $update; |
|
90 | + } |
|
91 | + } |
|
92 | + // it's also possible that there's an update but an invalid site-license-key is in use |
|
93 | + return get_site_option('pue_json_error_' . $basename) ? true : $update; |
|
94 | + } |
|
95 | 95 | } |
@@ -83,13 +83,13 @@ |
||
83 | 83 | $current = get_site_transient('update_plugins'); |
84 | 84 | if (isset($current->response['plugin_file'])) { |
85 | 85 | // convert "event-espresso-core/espresso.php" to "/event-espresso-core" and get plugins |
86 | - $plugins = get_plugins('/' . dirname($basename)); |
|
86 | + $plugins = get_plugins('/'.dirname($basename)); |
|
87 | 87 | foreach ($plugins as $plugin_file => $plugin_data) { |
88 | 88 | // toggle update to true if a match is found |
89 | 89 | $update = $current->response['plugin_file'] === $plugin_file ? true : $update; |
90 | 90 | } |
91 | 91 | } |
92 | 92 | // it's also possible that there's an update but an invalid site-license-key is in use |
93 | - return get_site_option('pue_json_error_' . $basename) ? true : $update; |
|
93 | + return get_site_option('pue_json_error_'.$basename) ? true : $update; |
|
94 | 94 | } |
95 | 95 | } |