@@ -24,1239 +24,1239 @@ |
||
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 |
|
50 | - * high value for its minimum plugin version. |
|
51 | - */ |
|
52 | - protected static $_incompatible_addons = [ |
|
53 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
54 | - 'Promotions' => '1.0.0.rc.084', |
|
55 | - ]; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var LoaderInterface |
|
59 | - */ |
|
60 | - protected static $loader; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
65 | - * not just '4.3.0'. |
|
66 | - * So if the addon developer doesn't provide that full version string, |
|
67 | - * fill in the blanks for them |
|
68 | - * |
|
69 | - * @param string $min_core_version |
|
70 | - * @return string always like '4.3.0.rc.000' |
|
71 | - */ |
|
72 | - protected static function _effective_version(string $min_core_version): string |
|
73 | - { |
|
74 | - // versions: 4 . 3 . 1 . p . 123 |
|
75 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
76 | - $version_parts = explode('.', $min_core_version); |
|
77 | - // check they specified the micro version (after 2nd period) |
|
78 | - if (! isset($version_parts[2])) { |
|
79 | - $version_parts[2] = '0'; |
|
80 | - } |
|
81 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
82 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
83 | - if (! isset($version_parts[3])) { |
|
84 | - $version_parts[3] = 'dev'; |
|
85 | - } |
|
86 | - if (! isset($version_parts[4])) { |
|
87 | - $version_parts[4] = '000'; |
|
88 | - } |
|
89 | - return implode('.', $version_parts); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Returns whether or not the min core version requirement of the addon is met |
|
95 | - * |
|
96 | - * @param string $min_core_version the minimum core version required by the addon |
|
97 | - * @param string $actual_core_version the actual core version, optional |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public static function _meets_min_core_version_requirement( |
|
101 | - string $min_core_version, |
|
102 | - string $actual_core_version = EVENT_ESPRESSO_VERSION |
|
103 | - ): bool { |
|
104 | - return version_compare( |
|
105 | - self::_effective_version($actual_core_version), |
|
106 | - self::_effective_version($min_core_version), |
|
107 | - '>=' |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Method for registering new EE_Addons. |
|
114 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
115 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
116 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
117 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
118 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
119 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
120 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
121 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
122 | - * |
|
123 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
124 | - * @param array $setup_args { |
|
125 | - * An array of arguments provided for registering |
|
126 | - * the message type. |
|
127 | - * @type string $class_name the addon's main file name. |
|
128 | - * If left blank, generated from the addon name, |
|
129 | - * changes something like "calendar" to |
|
130 | - * "EE_Calendar" |
|
131 | - * @type string $min_core_version the minimum version of EE Core that the |
|
132 | - * addon will work with. eg "4.8.1.rc.084" |
|
133 | - * @type string $version the "software" version for the addon. eg |
|
134 | - * "1.0.0.p" for a first stable release, or |
|
135 | - * "1.0.0.rc.043" for a version in progress |
|
136 | - * @type string $main_file_path the full server path to the main file |
|
137 | - * loaded directly by WP |
|
138 | - * @type DomainInterface $domain child class of |
|
139 | - * EventEspresso\core\domain\DomainBase |
|
140 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
141 | - * for the addon's Domain class |
|
142 | - * (see EventEspresso\core\domain\Domain) |
|
143 | - * @type string $admin_path full server path to the folder where the |
|
144 | - * addon\'s admin files reside |
|
145 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
146 | - * first invoked, can be used for hooking into |
|
147 | - * any admin page |
|
148 | - * @type string $config_section the section name for this addon's |
|
149 | - * configuration settings section |
|
150 | - * (defaults to "addons") |
|
151 | - * @type string $config_class the class name for this addon's |
|
152 | - * configuration settings object |
|
153 | - * @type string $config_name the class name for this addon's |
|
154 | - * configuration settings object |
|
155 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
156 | - * server paths to those files. |
|
157 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
158 | - * folders containing classes that might be |
|
159 | - * invoked by the addon |
|
160 | - * @type string $dms_paths [Required] an array of full server paths to |
|
161 | - * folders that contain data migration scripts. |
|
162 | - * The key should be the EE_Addon class name that |
|
163 | - * this set of data migration scripts belongs to. |
|
164 | - * If the EE_Addon class is namespaced, then this |
|
165 | - * needs to be the Fully Qualified Class Name |
|
166 | - * @type string $module_paths an array of full server paths to any |
|
167 | - * EED_Modules used by the addon |
|
168 | - * @type string $shortcode_paths an array of full server paths to folders |
|
169 | - * that contain EES_Shortcodes |
|
170 | - * @type string $widget_paths an array of full server paths to folders |
|
171 | - * that contain WP_Widgets |
|
172 | - * @type array $capabilities an array indexed by role name |
|
173 | - * (i.e administrator,author ) and the values |
|
174 | - * are an array of caps to add to the role. |
|
175 | - * 'administrator' => array( |
|
176 | - * 'read_addon', |
|
177 | - * 'edit_addon', |
|
178 | - * etc. |
|
179 | - * ). |
|
180 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
181 | - * for any addons that need to register any |
|
182 | - * special meta mapped capabilities. Should |
|
183 | - * be indexed where the key is the |
|
184 | - * EE_Meta_Capability_Map class name and the |
|
185 | - * values are the arguments sent to the class. |
|
186 | - * @type array $model_paths array of folders containing DB models |
|
187 | - * @return bool |
|
188 | - * @throws DomainException |
|
189 | - * @throws EE_Error |
|
190 | - * @throws InvalidArgumentException |
|
191 | - * @throws InvalidDataTypeException |
|
192 | - * @throws InvalidInterfaceException |
|
193 | - * @since 4.3.0 |
|
194 | - * @see EE_Register_Model |
|
195 | - * @type array $class_paths array of folders containing DB classes |
|
196 | - * @see EE_Register_Model |
|
197 | - * @type array $model_extension_paths array of folders containing DB model |
|
198 | - * extensions |
|
199 | - * @see EE_Register_Model_Extension |
|
200 | - * @type array $class_extension_paths array of folders containing DB class |
|
201 | - * extensions |
|
202 | - * @see EE_Register_Model_Extension |
|
203 | - * @type array message_types { |
|
204 | - * An array of message types with the key as |
|
205 | - * the message type name and the values as |
|
206 | - * below: |
|
207 | - * @type string $mtfilename [Required] The filename of the message type |
|
208 | - * being registered. This will be the main |
|
209 | - * EE_{Message Type Name}_message_type class. |
|
210 | - * for example: |
|
211 | - * EE_Declined_Registration_message_type.class.php |
|
212 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
213 | - * messages autoloader for the new message type. |
|
214 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
215 | - * type should activate with. Each value in |
|
216 | - * the |
|
217 | - * array |
|
218 | - * should match the name property of a |
|
219 | - * EE_messenger. Optional. |
|
220 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
221 | - * type should validate with. Each value in |
|
222 | - * the |
|
223 | - * array |
|
224 | - * should match the name property of an |
|
225 | - * EE_messenger. |
|
226 | - * Optional. |
|
227 | - * } |
|
228 | - * @type array $custom_post_types |
|
229 | - * @type array $custom_taxonomies |
|
230 | - * @type array $payment_method_paths each element is the folder containing the |
|
231 | - * EE_PMT_Base child class |
|
232 | - * (eg, |
|
233 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
234 | - * which contains the files |
|
235 | - * EE_PMT_Payomatic.pm.php) |
|
236 | - * @type array $default_terms |
|
237 | - * @type array $namespace { |
|
238 | - * An array with two items for registering the |
|
239 | - * addon's namespace. (If, for some reason, you |
|
240 | - * require additional namespaces, |
|
241 | - * use |
|
242 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
243 | - * directly) |
|
244 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
245 | - * @type string $FQNS the namespace prefix |
|
246 | - * @type string $DIR a base directory for class files in the |
|
247 | - * namespace. |
|
248 | - * } |
|
249 | - * } |
|
250 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
251 | - * privacy policy classes) or FQCNs (specific |
|
252 | - * classnames of privacy policy classes) |
|
253 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
254 | - * privacy policy classes) or FQCNs (specific |
|
255 | - * classnames of privacy policy classes) |
|
256 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
257 | - * privacy policy classes) or FQCNs (specific |
|
258 | - * classnames of privacy policy classes) |
|
259 | - */ |
|
260 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
261 | - { |
|
262 | - // $addon_name = basename($addon_name); |
|
263 | - if (! self::$loader instanceof LoaderInterface) { |
|
264 | - self::$loader = LoaderFactory::getLoader(); |
|
265 | - } |
|
266 | - // make sure this was called in the right place! |
|
267 | - if ( |
|
268 | - ! did_action('activate_plugin') |
|
269 | - && ( |
|
270 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
271 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
272 | - ) |
|
273 | - ) { |
|
274 | - EE_Error::doing_it_wrong( |
|
275 | - __METHOD__, |
|
276 | - sprintf( |
|
277 | - esc_html__( |
|
278 | - '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.', |
|
279 | - 'event_espresso' |
|
280 | - ), |
|
281 | - $addon_name |
|
282 | - ), |
|
283 | - '4.3.0' |
|
284 | - ); |
|
285 | - return false; |
|
286 | - } |
|
287 | - // required fields MUST be present, so let's make sure they are. |
|
288 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
289 | - // get class name for addon |
|
290 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
291 | - // setup $_settings array from incoming values. |
|
292 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
293 | - // allow early addon setup or modification of addon api settings |
|
294 | - self::$_settings = (array) apply_filters( |
|
295 | - 'FHEE__EE_Register_Addon__register', |
|
296 | - self::$_settings, |
|
297 | - $addon_name, |
|
298 | - $class_name, |
|
299 | - $setup_args |
|
300 | - ); |
|
301 | - // does this addon work with this version of core or WordPress ? |
|
302 | - // does this addon work with this version of core or WordPress ? |
|
303 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
304 | - return false; |
|
305 | - } |
|
306 | - // register namespaces |
|
307 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
308 | - // check if this is an activation request |
|
309 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
310 | - // dont bother setting up the rest of the addon atm |
|
311 | - return false; |
|
312 | - } |
|
313 | - // we need cars |
|
314 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
315 | - // register new models and extensions |
|
316 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
317 | - // setup DMS |
|
318 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
319 | - // if config_class is present let's register config. |
|
320 | - EE_Register_Addon::_register_config($addon_name); |
|
321 | - // register admin pages |
|
322 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
323 | - // add to list of modules to be registered |
|
324 | - EE_Register_Addon::_register_modules($addon_name); |
|
325 | - // add to list of shortcodes to be registered |
|
326 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
327 | - // add to list of widgets to be registered |
|
328 | - EE_Register_Addon::_register_widgets($addon_name); |
|
329 | - // register capability related stuff. |
|
330 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
331 | - // any message type to register? |
|
332 | - EE_Register_Addon::_register_message_types($addon_name); |
|
333 | - // any custom post type/ custom capabilities or default terms to register |
|
334 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
335 | - // and any payment methods |
|
336 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
337 | - // and privacy policy generators |
|
338 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
339 | - // and privacy policy generators |
|
340 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
341 | - // and privacy policy generators |
|
342 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
343 | - // load and instantiate main addon class |
|
344 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
345 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
346 | - add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
347 | - return $addon instanceof EE_Addon; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * @param string $addon_name |
|
353 | - * @param array $setup_args |
|
354 | - * @return void |
|
355 | - * @throws EE_Error |
|
356 | - */ |
|
357 | - private static function _verify_parameters(string $addon_name, array $setup_args) |
|
358 | - { |
|
359 | - // required fields MUST be present, so let's make sure they are. |
|
360 | - if (empty($addon_name) || empty($setup_args)) { |
|
361 | - throw new EE_Error( |
|
362 | - esc_html__( |
|
363 | - '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.', |
|
364 | - 'event_espresso' |
|
365 | - ) |
|
366 | - ); |
|
367 | - } |
|
368 | - if (empty($setup_args['main_file_path'])) { |
|
369 | - throw new EE_Error( |
|
370 | - sprintf( |
|
371 | - esc_html__( |
|
372 | - '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', |
|
373 | - 'event_espresso' |
|
374 | - ), |
|
375 | - implode(',', array_keys($setup_args)) |
|
376 | - ) |
|
377 | - ); |
|
378 | - } |
|
379 | - // check that addon has not already been registered with that name |
|
380 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
381 | - throw new EE_Error( |
|
382 | - sprintf( |
|
383 | - esc_html__( |
|
384 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
385 | - 'event_espresso' |
|
386 | - ), |
|
387 | - $addon_name |
|
388 | - ) |
|
389 | - ); |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @param string $addon_name |
|
396 | - * @param array $setup_args |
|
397 | - * @return string |
|
398 | - */ |
|
399 | - private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
400 | - { |
|
401 | - if (empty($setup_args['class_name'])) { |
|
402 | - // generate one by first separating name with spaces |
|
403 | - $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
404 | - // capitalize, then replace spaces with underscores |
|
405 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
406 | - } else { |
|
407 | - $class_name = $setup_args['class_name']; |
|
408 | - } |
|
409 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
410 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
411 | - ? $class_name |
|
412 | - : 'EE_' . $class_name; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * @param string $class_name |
|
418 | - * @param array $setup_args |
|
419 | - * @return array |
|
420 | - */ |
|
421 | - private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
422 | - { |
|
423 | - // setup $_settings array from incoming values. |
|
424 | - $addon_settings = [ |
|
425 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
426 | - 'class_name' => $class_name, |
|
427 | - // the addon slug for use in URLs, etc |
|
428 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
429 | - ? (string) $setup_args['plugin_slug'] |
|
430 | - : '', |
|
431 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
432 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
433 | - ? (string) $setup_args['plugin_action_slug'] |
|
434 | - : '', |
|
435 | - // the "software" version for the addon |
|
436 | - 'version' => isset($setup_args['version']) |
|
437 | - ? (string) $setup_args['version'] |
|
438 | - : '', |
|
439 | - // the minimum version of EE Core that the addon will work with |
|
440 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
441 | - ? (string) $setup_args['min_core_version'] |
|
442 | - : '', |
|
443 | - // the minimum version of WordPress that the addon will work with |
|
444 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
445 | - ? (string) $setup_args['min_wp_version'] |
|
446 | - : EE_MIN_WP_VER_REQUIRED, |
|
447 | - // full server path to main file (file loaded directly by WP) |
|
448 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
449 | - ? (string) $setup_args['main_file_path'] |
|
450 | - : '', |
|
451 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
452 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
453 | - ? $setup_args['domain'] |
|
454 | - : null, |
|
455 | - // Fully Qualified Class Name for the addon's Domain class |
|
456 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
457 | - ? (string) $setup_args['domain_fqcn'] |
|
458 | - : '', |
|
459 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
460 | - 'admin_path' => isset($setup_args['admin_path']) |
|
461 | - ? (string) $setup_args['admin_path'] |
|
462 | - : '', |
|
463 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
464 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
465 | - ? (string) $setup_args['admin_callback'] |
|
466 | - : '', |
|
467 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
468 | - 'config_section' => isset($setup_args['config_section']) |
|
469 | - ? (string) $setup_args['config_section'] |
|
470 | - : 'addons', |
|
471 | - // the class name for this addon's configuration settings object |
|
472 | - 'config_class' => isset($setup_args['config_class']) |
|
473 | - ? (string) $setup_args['config_class'] |
|
474 | - : '', |
|
475 | - // the name given to the config for this addons' configuration settings object (optional) |
|
476 | - 'config_name' => isset($setup_args['config_name']) |
|
477 | - ? (string) $setup_args['config_name'] |
|
478 | - : '', |
|
479 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
480 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
481 | - ? (array) $setup_args['autoloader_paths'] |
|
482 | - : [], |
|
483 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
484 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
485 | - ? (array) $setup_args['autoloader_folders'] |
|
486 | - : [], |
|
487 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
488 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
489 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
490 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
491 | - ? (array) $setup_args['dms_paths'] |
|
492 | - : [], |
|
493 | - // array of full server paths to any EED_Modules used by the addon |
|
494 | - 'module_paths' => isset($setup_args['module_paths']) |
|
495 | - ? (array) $setup_args['module_paths'] |
|
496 | - : [], |
|
497 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
498 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
499 | - ? (array) $setup_args['shortcode_paths'] |
|
500 | - : [], |
|
501 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
502 | - ? (array) $setup_args['shortcode_fqcns'] |
|
503 | - : [], |
|
504 | - // array of full server paths to any WP_Widgets used by the addon |
|
505 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
506 | - ? (array) $setup_args['widget_paths'] |
|
507 | - : [], |
|
508 | - 'message_types' => isset($setup_args['message_types']) |
|
509 | - ? (array) $setup_args['message_types'] |
|
510 | - : [], |
|
511 | - 'capabilities' => isset($setup_args['capabilities']) |
|
512 | - ? (array) $setup_args['capabilities'] |
|
513 | - : [], |
|
514 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
515 | - ? (array) $setup_args['capability_maps'] |
|
516 | - : [], |
|
517 | - 'model_paths' => isset($setup_args['model_paths']) |
|
518 | - ? (array) $setup_args['model_paths'] |
|
519 | - : [], |
|
520 | - 'class_paths' => isset($setup_args['class_paths']) |
|
521 | - ? (array) $setup_args['class_paths'] |
|
522 | - : [], |
|
523 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
524 | - ? (array) $setup_args['model_extension_paths'] |
|
525 | - : [], |
|
526 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
527 | - ? (array) $setup_args['class_extension_paths'] |
|
528 | - : [], |
|
529 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
530 | - ? (array) $setup_args['custom_post_types'] |
|
531 | - : [], |
|
532 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
533 | - ? (array) $setup_args['custom_taxonomies'] |
|
534 | - : [], |
|
535 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
536 | - ? (array) $setup_args['payment_method_paths'] |
|
537 | - : [], |
|
538 | - 'default_terms' => isset($setup_args['default_terms']) |
|
539 | - ? (array) $setup_args['default_terms'] |
|
540 | - : [], |
|
541 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
542 | - // that can be used for adding upgrading/marketing info |
|
543 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
544 | - ? (array) $setup_args['plugins_page_row'] |
|
545 | - : [], |
|
546 | - 'namespace' => isset( |
|
547 | - $setup_args['namespace']['FQNS'], |
|
548 | - $setup_args['namespace']['DIR'] |
|
549 | - ) |
|
550 | - ? (array) $setup_args['namespace'] |
|
551 | - : [], |
|
552 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
553 | - ? (array) $setup_args['privacy_policies'] |
|
554 | - : '', |
|
555 | - ]; |
|
556 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
557 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
558 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
559 | - && ! empty($addon_settings['admin_path']) |
|
560 | - ? $addon_settings['plugin_slug'] |
|
561 | - : $addon_settings['plugin_action_slug']; |
|
562 | - // full server path to main file (file loaded directly by WP) |
|
563 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
564 | - return $addon_settings; |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * @param string $addon_name |
|
570 | - * @param array $addon_settings |
|
571 | - * @return bool |
|
572 | - */ |
|
573 | - private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
574 | - { |
|
575 | - global $wp_version; |
|
576 | - $incompatibility_message = ''; |
|
577 | - // check whether this addon version is compatible with EE core |
|
578 | - if ( |
|
579 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
580 | - && ! self::_meets_min_core_version_requirement( |
|
581 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
582 | - $addon_settings['version'] |
|
583 | - ) |
|
584 | - ) { |
|
585 | - $incompatibility_message = sprintf( |
|
586 | - esc_html__( |
|
587 | - '%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.', |
|
588 | - 'event_espresso' |
|
589 | - ), |
|
590 | - $addon_name, |
|
591 | - '<br />', |
|
592 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
593 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
594 | - '</span><br />' |
|
595 | - ); |
|
596 | - } elseif ( |
|
597 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
598 | - ) { |
|
599 | - $incompatibility_message = sprintf( |
|
600 | - esc_html__( |
|
601 | - '%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".', |
|
602 | - 'event_espresso' |
|
603 | - ), |
|
604 | - $addon_name, |
|
605 | - self::_effective_version($addon_settings['min_core_version']), |
|
606 | - self::_effective_version(espresso_version()), |
|
607 | - '<br />', |
|
608 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
609 | - '</span><br />' |
|
610 | - ); |
|
611 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
612 | - $incompatibility_message = sprintf( |
|
613 | - esc_html__( |
|
614 | - '%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.', |
|
615 | - 'event_espresso' |
|
616 | - ), |
|
617 | - $addon_name, |
|
618 | - $addon_settings['min_wp_version'], |
|
619 | - '<br />', |
|
620 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
621 | - '</span><br />' |
|
622 | - ); |
|
623 | - } |
|
624 | - if (! empty($incompatibility_message)) { |
|
625 | - // remove 'activate' from the REQUEST |
|
626 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
627 | - /** @var RequestInterface $request */ |
|
628 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
629 | - $request->unSetRequestParam('activate', true); |
|
630 | - if (current_user_can('activate_plugins')) { |
|
631 | - // show an error message indicating the plugin didn't activate properly |
|
632 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
633 | - } |
|
634 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
635 | - if (! function_exists('deactivate_plugins')) { |
|
636 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
637 | - } |
|
638 | - deactivate_plugins(plugin_basename($addon_settings['main_file_path'])); |
|
639 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
640 | - return false; |
|
641 | - } |
|
642 | - // addon IS compatible |
|
643 | - return true; |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
649 | - * |
|
650 | - * @param array $addon_settings |
|
651 | - * @return void |
|
652 | - * @throws EE_Error |
|
653 | - */ |
|
654 | - private static function _setup_namespaces(array $addon_settings) |
|
655 | - { |
|
656 | - // |
|
657 | - if ( |
|
658 | - isset( |
|
659 | - $addon_settings['namespace']['FQNS'], |
|
660 | - $addon_settings['namespace']['DIR'] |
|
661 | - ) |
|
662 | - ) { |
|
663 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
664 | - $addon_settings['namespace']['FQNS'], |
|
665 | - $addon_settings['namespace']['DIR'] |
|
666 | - ); |
|
667 | - } |
|
668 | - } |
|
669 | - |
|
670 | - |
|
671 | - /** |
|
672 | - * @param string $addon_name |
|
673 | - * @param array $addon_settings |
|
674 | - * @return bool |
|
675 | - * @throws InvalidArgumentException |
|
676 | - * @throws InvalidDataTypeException |
|
677 | - * @throws InvalidInterfaceException |
|
678 | - */ |
|
679 | - private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
680 | - { |
|
681 | - // this is an activation request |
|
682 | - if (did_action('activate_plugin')) { |
|
683 | - // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
684 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
685 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
686 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
687 | - if ( |
|
688 | - ! isset(self::$_settings[ $addon_name ]) |
|
689 | - || (isset(self::$_settings[ $addon_name ]) |
|
690 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
691 | - ) |
|
692 | - ) { |
|
693 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
694 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
695 | - $addon->set_activation_indicator_option(); |
|
696 | - // dont bother setting up the rest of the addon. |
|
697 | - // we know it was just activated and the request will end soon |
|
698 | - } |
|
699 | - return true; |
|
700 | - } |
|
701 | - // make sure addon settings are set correctly without overwriting anything existing |
|
702 | - if (isset(self::$_settings[ $addon_name ])) { |
|
703 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
704 | - } else { |
|
705 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
706 | - } |
|
707 | - return false; |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * @param string $addon_name |
|
713 | - * @return void |
|
714 | - * @throws EE_Error |
|
715 | - */ |
|
716 | - private static function _setup_autoloaders(string $addon_name) |
|
717 | - { |
|
718 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
719 | - // setup autoloader for single file |
|
720 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
721 | - } |
|
722 | - // setup autoloaders for folders |
|
723 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
724 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
725 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
726 | - } |
|
727 | - } |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * register new models and extensions |
|
733 | - * |
|
734 | - * @param string $addon_name |
|
735 | - * @return void |
|
736 | - * @throws EE_Error |
|
737 | - */ |
|
738 | - private static function _register_models_and_extensions(string $addon_name) |
|
739 | - { |
|
740 | - // register new models |
|
741 | - if ( |
|
742 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
743 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
744 | - ) { |
|
745 | - EE_Register_Model::register( |
|
746 | - $addon_name, |
|
747 | - [ |
|
748 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
749 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
750 | - ] |
|
751 | - ); |
|
752 | - } |
|
753 | - // register model extensions |
|
754 | - if ( |
|
755 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
756 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
757 | - ) { |
|
758 | - EE_Register_Model_Extensions::register( |
|
759 | - $addon_name, |
|
760 | - [ |
|
761 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
762 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
763 | - ] |
|
764 | - ); |
|
765 | - } |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * @param string $addon_name |
|
771 | - * @return void |
|
772 | - * @throws EE_Error |
|
773 | - */ |
|
774 | - private static function _register_data_migration_scripts(string $addon_name) |
|
775 | - { |
|
776 | - // setup DMS |
|
777 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
778 | - EE_Register_Data_Migration_Scripts::register( |
|
779 | - $addon_name, |
|
780 | - ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
781 | - ); |
|
782 | - } |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * @param string $addon_name |
|
788 | - * @return void |
|
789 | - * @throws EE_Error |
|
790 | - */ |
|
791 | - private static function _register_config(string $addon_name) |
|
792 | - { |
|
793 | - // if config_class is present let's register config. |
|
794 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
795 | - EE_Register_Config::register( |
|
796 | - self::$_settings[ $addon_name ]['config_class'], |
|
797 | - [ |
|
798 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
799 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
800 | - ] |
|
801 | - ); |
|
802 | - } |
|
803 | - } |
|
804 | - |
|
805 | - |
|
806 | - /** |
|
807 | - * @param string $addon_name |
|
808 | - * @return void |
|
809 | - * @throws EE_Error |
|
810 | - */ |
|
811 | - private static function _register_admin_pages(string $addon_name) |
|
812 | - { |
|
813 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
814 | - EE_Register_Admin_Page::register( |
|
815 | - $addon_name, |
|
816 | - ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
817 | - ); |
|
818 | - } |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * @param string $addon_name |
|
824 | - * @return void |
|
825 | - * @throws EE_Error |
|
826 | - */ |
|
827 | - private static function _register_modules(string $addon_name) |
|
828 | - { |
|
829 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
830 | - EE_Register_Module::register( |
|
831 | - $addon_name, |
|
832 | - ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
833 | - ); |
|
834 | - } |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - /** |
|
839 | - * @param string $addon_name |
|
840 | - * @return void |
|
841 | - * @throws EE_Error |
|
842 | - */ |
|
843 | - private static function _register_shortcodes(string $addon_name) |
|
844 | - { |
|
845 | - if ( |
|
846 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
847 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
848 | - ) { |
|
849 | - EE_Register_Shortcode::register( |
|
850 | - $addon_name, |
|
851 | - [ |
|
852 | - 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
853 | - 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
854 | - ] |
|
855 | - ); |
|
856 | - } |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - /** |
|
861 | - * @param string $addon_name |
|
862 | - * @return void |
|
863 | - * @throws EE_Error |
|
864 | - */ |
|
865 | - private static function _register_widgets(string $addon_name) |
|
866 | - { |
|
867 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
868 | - EE_Register_Widget::register( |
|
869 | - $addon_name, |
|
870 | - ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
871 | - ); |
|
872 | - } |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - /** |
|
877 | - * @param string $addon_name |
|
878 | - * @return void |
|
879 | - * @throws EE_Error |
|
880 | - */ |
|
881 | - private static function _register_capabilities(string $addon_name) |
|
882 | - { |
|
883 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
884 | - EE_Register_Capabilities::register( |
|
885 | - $addon_name, |
|
886 | - [ |
|
887 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
888 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
889 | - ] |
|
890 | - ); |
|
891 | - } |
|
892 | - } |
|
893 | - |
|
894 | - |
|
895 | - /** |
|
896 | - * @param string $addon_name |
|
897 | - * @return void |
|
898 | - */ |
|
899 | - private static function _register_message_types(string $addon_name) |
|
900 | - { |
|
901 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
902 | - add_action( |
|
903 | - 'EE_Brewing_Regular___messages_caf', |
|
904 | - ['EE_Register_Addon', 'register_message_types'] |
|
905 | - ); |
|
906 | - } |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * @param string $addon_name |
|
912 | - * @return void |
|
913 | - * @throws EE_Error |
|
914 | - */ |
|
915 | - private static function _register_custom_post_types(string $addon_name) |
|
916 | - { |
|
917 | - if ( |
|
918 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
919 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
920 | - ) { |
|
921 | - EE_Register_CPT::register( |
|
922 | - $addon_name, |
|
923 | - [ |
|
924 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
925 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
926 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
927 | - ] |
|
928 | - ); |
|
929 | - } |
|
930 | - } |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * @param string $addon_name |
|
935 | - * @return void |
|
936 | - * @throws InvalidArgumentException |
|
937 | - * @throws InvalidInterfaceException |
|
938 | - * @throws InvalidDataTypeException |
|
939 | - * @throws DomainException |
|
940 | - * @throws EE_Error |
|
941 | - */ |
|
942 | - private static function _register_payment_methods(string $addon_name) |
|
943 | - { |
|
944 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
945 | - EE_Register_Payment_Method::register( |
|
946 | - $addon_name, |
|
947 | - ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
948 | - ); |
|
949 | - } |
|
950 | - } |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * @param string $addon_name |
|
955 | - * @return void |
|
956 | - * @throws InvalidArgumentException |
|
957 | - * @throws InvalidInterfaceException |
|
958 | - * @throws InvalidDataTypeException |
|
959 | - * @throws DomainException |
|
960 | - */ |
|
961 | - private static function registerPrivacyPolicies(string $addon_name) |
|
962 | - { |
|
963 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
964 | - EE_Register_Privacy_Policy::register( |
|
965 | - $addon_name, |
|
966 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
967 | - ); |
|
968 | - } |
|
969 | - } |
|
970 | - |
|
971 | - |
|
972 | - /** |
|
973 | - * @param string $addon_name |
|
974 | - * @return void |
|
975 | - */ |
|
976 | - private static function registerPersonalDataExporters(string $addon_name) |
|
977 | - { |
|
978 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
979 | - EE_Register_Personal_Data_Eraser::register( |
|
980 | - $addon_name, |
|
981 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
982 | - ); |
|
983 | - } |
|
984 | - } |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * @param string $addon_name |
|
989 | - * @return void |
|
990 | - */ |
|
991 | - private static function registerPersonalDataErasers(string $addon_name) |
|
992 | - { |
|
993 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
994 | - EE_Register_Personal_Data_Eraser::register( |
|
995 | - $addon_name, |
|
996 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
997 | - ); |
|
998 | - } |
|
999 | - } |
|
1000 | - |
|
1001 | - |
|
1002 | - /** |
|
1003 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1004 | - * |
|
1005 | - * @param string $addon_name |
|
1006 | - * @return EE_Addon |
|
1007 | - * @throws InvalidArgumentException |
|
1008 | - * @throws InvalidInterfaceException |
|
1009 | - * @throws InvalidDataTypeException |
|
1010 | - */ |
|
1011 | - private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
|
1012 | - { |
|
1013 | - $addon = self::$loader->getShared( |
|
1014 | - self::$_settings[ $addon_name ]['class_name'], |
|
1015 | - ['EE_Registry::create(addon)' => true] |
|
1016 | - ); |
|
1017 | - if (! $addon instanceof EE_Addon) { |
|
1018 | - throw new DomainException( |
|
1019 | - sprintf( |
|
1020 | - esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
1021 | - self::$_settings[ $addon_name ]['class_name'] |
|
1022 | - ) |
|
1023 | - ); |
|
1024 | - } |
|
1025 | - // setter inject dep map if required |
|
1026 | - if ($addon->dependencyMap() === null) { |
|
1027 | - $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
1028 | - } |
|
1029 | - // setter inject domain if required |
|
1030 | - EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1031 | - |
|
1032 | - $addon->set_name($addon_name); |
|
1033 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1034 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1035 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1036 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1037 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1038 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1039 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1040 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1041 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1042 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1043 | - do_action( |
|
1044 | - 'AHEE__EE_Register_Addon___load_and_init_addon_class', |
|
1045 | - $addon, |
|
1046 | - $addon_name, |
|
1047 | - self::$_settings |
|
1048 | - ); |
|
1049 | - // unfortunately this can't be hooked in upon construction, |
|
1050 | - // because we don't have the plugin's mainfile path upon construction. |
|
1051 | - register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
1052 | - // call any additional admin_callback functions during load_admin_controller hook |
|
1053 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1054 | - add_action( |
|
1055 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1056 | - [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1057 | - ); |
|
1058 | - } |
|
1059 | - return $addon; |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * @param string $addon_name |
|
1065 | - * @param EE_Addon $addon |
|
1066 | - * @since 4.10.13.p |
|
1067 | - */ |
|
1068 | - private static function injectAddonDomain(string $addon_name, EE_Addon $addon) |
|
1069 | - { |
|
1070 | - if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1071 | - // using supplied Domain object |
|
1072 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1073 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1074 | - : null; |
|
1075 | - // or construct one using Domain FQCN |
|
1076 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1077 | - $domain = self::$loader->getShared( |
|
1078 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1079 | - [ |
|
1080 | - new EventEspresso\core\domain\values\FilePath( |
|
1081 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1082 | - ), |
|
1083 | - EventEspresso\core\domain\values\Version::fromString( |
|
1084 | - self::$_settings[ $addon_name ]['version'] |
|
1085 | - ), |
|
1086 | - ] |
|
1087 | - ); |
|
1088 | - } |
|
1089 | - if ($domain instanceof DomainInterface) { |
|
1090 | - $addon->setDomain($domain); |
|
1091 | - } |
|
1092 | - } |
|
1093 | - } |
|
1094 | - |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * @return void |
|
1098 | - * @deprecated 5.0.0.p |
|
1099 | - */ |
|
1100 | - public static function load_pue_update() |
|
1101 | - { |
|
1102 | - RegisterAddonPUE::loadPueUpdate(); |
|
1103 | - } |
|
1104 | - |
|
1105 | - |
|
1106 | - /** |
|
1107 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1108 | - * |
|
1109 | - * @return void |
|
1110 | - * @throws EE_Error |
|
1111 | - * @since 4.4.0 |
|
1112 | - */ |
|
1113 | - public static function register_message_types() |
|
1114 | - { |
|
1115 | - foreach (self::$_settings as $settings) { |
|
1116 | - if (! empty($settings['message_types'])) { |
|
1117 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1118 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1119 | - } |
|
1120 | - } |
|
1121 | - } |
|
1122 | - } |
|
1123 | - |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1127 | - * |
|
1128 | - * @param string $addon_name the name for the addon that was previously registered |
|
1129 | - * @throws DomainException |
|
1130 | - * @throws InvalidArgumentException |
|
1131 | - * @throws InvalidDataTypeException |
|
1132 | - * @throws InvalidInterfaceException |
|
1133 | - * @since 4.3.0 |
|
1134 | - */ |
|
1135 | - public static function deregister(string $addon_name = '') |
|
1136 | - { |
|
1137 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1138 | - try { |
|
1139 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1140 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1141 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1142 | - // setup DMS |
|
1143 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1144 | - } |
|
1145 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1146 | - // register admin page |
|
1147 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1148 | - } |
|
1149 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1150 | - // add to list of modules to be registered |
|
1151 | - EE_Register_Module::deregister($addon_name); |
|
1152 | - } |
|
1153 | - if ( |
|
1154 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1155 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1156 | - ) { |
|
1157 | - // add to list of shortcodes to be registered |
|
1158 | - EE_Register_Shortcode::deregister($addon_name); |
|
1159 | - } |
|
1160 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1161 | - // if config_class present let's register config. |
|
1162 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1163 | - } |
|
1164 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1165 | - // add to list of widgets to be registered |
|
1166 | - EE_Register_Widget::deregister($addon_name); |
|
1167 | - } |
|
1168 | - if ( |
|
1169 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1170 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1171 | - ) { |
|
1172 | - // add to list of shortcodes to be registered |
|
1173 | - EE_Register_Model::deregister($addon_name); |
|
1174 | - } |
|
1175 | - if ( |
|
1176 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1177 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1178 | - ) { |
|
1179 | - // add to list of shortcodes to be registered |
|
1180 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1181 | - } |
|
1182 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1183 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1184 | - EE_Register_Message_Type::deregister($message_type); |
|
1185 | - } |
|
1186 | - } |
|
1187 | - // deregister capabilities for addon |
|
1188 | - if ( |
|
1189 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1190 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1191 | - ) { |
|
1192 | - EE_Register_Capabilities::deregister($addon_name); |
|
1193 | - } |
|
1194 | - // deregister custom_post_types for addon |
|
1195 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1196 | - EE_Register_CPT::deregister($addon_name); |
|
1197 | - } |
|
1198 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1199 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1200 | - } |
|
1201 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1202 | - if ($addon instanceof EE_Addon) { |
|
1203 | - remove_action( |
|
1204 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1205 | - [$addon, 'deactivation'] |
|
1206 | - ); |
|
1207 | - remove_action( |
|
1208 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1209 | - [$addon, 'initialize_db_if_no_migrations_required'] |
|
1210 | - ); |
|
1211 | - // remove `after_registration` call |
|
1212 | - remove_action( |
|
1213 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1214 | - [$addon, 'after_registration'], |
|
1215 | - 999 |
|
1216 | - ); |
|
1217 | - } |
|
1218 | - EE_Registry::instance()->removeAddon($class_name); |
|
1219 | - LoaderFactory::getLoader()->remove($class_name); |
|
1220 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1221 | - // the add-on was not yet registered in the registry, |
|
1222 | - // so RegistryContainer::__get() throws this exception. |
|
1223 | - // also no need to worry about this or log it, |
|
1224 | - // it's ok to deregister an add-on before its registered in the registry |
|
1225 | - } catch (Exception $e) { |
|
1226 | - new ExceptionLogger($e); |
|
1227 | - } |
|
1228 | - unset(self::$_settings[ $addon_name ]); |
|
1229 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1230 | - } |
|
1231 | - } |
|
1232 | - |
|
1233 | - |
|
1234 | - public static function reset(): void |
|
1235 | - { |
|
1236 | - EE_Register_Addon::$_settings = []; |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - public static function resetAll(): void |
|
1241 | - { |
|
1242 | - // EE_Register_Addon::reset(); |
|
1243 | - EE_Register_Admin_Page::reset(); |
|
1244 | - EE_Register_Capabilities::reset(); |
|
1245 | - EE_Register_Config::reset(); |
|
1246 | - EE_Register_CPT::reset(); |
|
1247 | - EE_Register_Data_Migration_Scripts::reset(); |
|
1248 | - EE_Register_Message_Type::reset(); |
|
1249 | - EE_Register_Messages_Shortcode_Library::reset(); |
|
1250 | - EE_Register_Messages_Template_Pack::reset(); |
|
1251 | - EE_Register_Messages_Template_Variations::reset(); |
|
1252 | - EE_Register_Model::reset(); |
|
1253 | - EE_Register_Model_Extensions::reset(); |
|
1254 | - EE_Register_Module::reset(); |
|
1255 | - EE_Register_Payment_Method::reset(); |
|
1256 | - EE_Register_Personal_Data_Eraser::reset(); |
|
1257 | - EE_Register_Personal_Data_Exporter::reset(); |
|
1258 | - EE_Register_Privacy_Policy::reset(); |
|
1259 | - EE_Register_Shortcode::reset(); |
|
1260 | - EE_Register_Widget::reset(); |
|
1261 | - } |
|
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 |
|
50 | + * high value for its minimum plugin version. |
|
51 | + */ |
|
52 | + protected static $_incompatible_addons = [ |
|
53 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
54 | + 'Promotions' => '1.0.0.rc.084', |
|
55 | + ]; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var LoaderInterface |
|
59 | + */ |
|
60 | + protected static $loader; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
65 | + * not just '4.3.0'. |
|
66 | + * So if the addon developer doesn't provide that full version string, |
|
67 | + * fill in the blanks for them |
|
68 | + * |
|
69 | + * @param string $min_core_version |
|
70 | + * @return string always like '4.3.0.rc.000' |
|
71 | + */ |
|
72 | + protected static function _effective_version(string $min_core_version): string |
|
73 | + { |
|
74 | + // versions: 4 . 3 . 1 . p . 123 |
|
75 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
76 | + $version_parts = explode('.', $min_core_version); |
|
77 | + // check they specified the micro version (after 2nd period) |
|
78 | + if (! isset($version_parts[2])) { |
|
79 | + $version_parts[2] = '0'; |
|
80 | + } |
|
81 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
82 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
83 | + if (! isset($version_parts[3])) { |
|
84 | + $version_parts[3] = 'dev'; |
|
85 | + } |
|
86 | + if (! isset($version_parts[4])) { |
|
87 | + $version_parts[4] = '000'; |
|
88 | + } |
|
89 | + return implode('.', $version_parts); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Returns whether or not the min core version requirement of the addon is met |
|
95 | + * |
|
96 | + * @param string $min_core_version the minimum core version required by the addon |
|
97 | + * @param string $actual_core_version the actual core version, optional |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public static function _meets_min_core_version_requirement( |
|
101 | + string $min_core_version, |
|
102 | + string $actual_core_version = EVENT_ESPRESSO_VERSION |
|
103 | + ): bool { |
|
104 | + return version_compare( |
|
105 | + self::_effective_version($actual_core_version), |
|
106 | + self::_effective_version($min_core_version), |
|
107 | + '>=' |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Method for registering new EE_Addons. |
|
114 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
115 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
116 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
117 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
118 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
119 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
120 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
121 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
122 | + * |
|
123 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
124 | + * @param array $setup_args { |
|
125 | + * An array of arguments provided for registering |
|
126 | + * the message type. |
|
127 | + * @type string $class_name the addon's main file name. |
|
128 | + * If left blank, generated from the addon name, |
|
129 | + * changes something like "calendar" to |
|
130 | + * "EE_Calendar" |
|
131 | + * @type string $min_core_version the minimum version of EE Core that the |
|
132 | + * addon will work with. eg "4.8.1.rc.084" |
|
133 | + * @type string $version the "software" version for the addon. eg |
|
134 | + * "1.0.0.p" for a first stable release, or |
|
135 | + * "1.0.0.rc.043" for a version in progress |
|
136 | + * @type string $main_file_path the full server path to the main file |
|
137 | + * loaded directly by WP |
|
138 | + * @type DomainInterface $domain child class of |
|
139 | + * EventEspresso\core\domain\DomainBase |
|
140 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
141 | + * for the addon's Domain class |
|
142 | + * (see EventEspresso\core\domain\Domain) |
|
143 | + * @type string $admin_path full server path to the folder where the |
|
144 | + * addon\'s admin files reside |
|
145 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
146 | + * first invoked, can be used for hooking into |
|
147 | + * any admin page |
|
148 | + * @type string $config_section the section name for this addon's |
|
149 | + * configuration settings section |
|
150 | + * (defaults to "addons") |
|
151 | + * @type string $config_class the class name for this addon's |
|
152 | + * configuration settings object |
|
153 | + * @type string $config_name the class name for this addon's |
|
154 | + * configuration settings object |
|
155 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
156 | + * server paths to those files. |
|
157 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
158 | + * folders containing classes that might be |
|
159 | + * invoked by the addon |
|
160 | + * @type string $dms_paths [Required] an array of full server paths to |
|
161 | + * folders that contain data migration scripts. |
|
162 | + * The key should be the EE_Addon class name that |
|
163 | + * this set of data migration scripts belongs to. |
|
164 | + * If the EE_Addon class is namespaced, then this |
|
165 | + * needs to be the Fully Qualified Class Name |
|
166 | + * @type string $module_paths an array of full server paths to any |
|
167 | + * EED_Modules used by the addon |
|
168 | + * @type string $shortcode_paths an array of full server paths to folders |
|
169 | + * that contain EES_Shortcodes |
|
170 | + * @type string $widget_paths an array of full server paths to folders |
|
171 | + * that contain WP_Widgets |
|
172 | + * @type array $capabilities an array indexed by role name |
|
173 | + * (i.e administrator,author ) and the values |
|
174 | + * are an array of caps to add to the role. |
|
175 | + * 'administrator' => array( |
|
176 | + * 'read_addon', |
|
177 | + * 'edit_addon', |
|
178 | + * etc. |
|
179 | + * ). |
|
180 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
181 | + * for any addons that need to register any |
|
182 | + * special meta mapped capabilities. Should |
|
183 | + * be indexed where the key is the |
|
184 | + * EE_Meta_Capability_Map class name and the |
|
185 | + * values are the arguments sent to the class. |
|
186 | + * @type array $model_paths array of folders containing DB models |
|
187 | + * @return bool |
|
188 | + * @throws DomainException |
|
189 | + * @throws EE_Error |
|
190 | + * @throws InvalidArgumentException |
|
191 | + * @throws InvalidDataTypeException |
|
192 | + * @throws InvalidInterfaceException |
|
193 | + * @since 4.3.0 |
|
194 | + * @see EE_Register_Model |
|
195 | + * @type array $class_paths array of folders containing DB classes |
|
196 | + * @see EE_Register_Model |
|
197 | + * @type array $model_extension_paths array of folders containing DB model |
|
198 | + * extensions |
|
199 | + * @see EE_Register_Model_Extension |
|
200 | + * @type array $class_extension_paths array of folders containing DB class |
|
201 | + * extensions |
|
202 | + * @see EE_Register_Model_Extension |
|
203 | + * @type array message_types { |
|
204 | + * An array of message types with the key as |
|
205 | + * the message type name and the values as |
|
206 | + * below: |
|
207 | + * @type string $mtfilename [Required] The filename of the message type |
|
208 | + * being registered. This will be the main |
|
209 | + * EE_{Message Type Name}_message_type class. |
|
210 | + * for example: |
|
211 | + * EE_Declined_Registration_message_type.class.php |
|
212 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
213 | + * messages autoloader for the new message type. |
|
214 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
215 | + * type should activate with. Each value in |
|
216 | + * the |
|
217 | + * array |
|
218 | + * should match the name property of a |
|
219 | + * EE_messenger. Optional. |
|
220 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
221 | + * type should validate with. Each value in |
|
222 | + * the |
|
223 | + * array |
|
224 | + * should match the name property of an |
|
225 | + * EE_messenger. |
|
226 | + * Optional. |
|
227 | + * } |
|
228 | + * @type array $custom_post_types |
|
229 | + * @type array $custom_taxonomies |
|
230 | + * @type array $payment_method_paths each element is the folder containing the |
|
231 | + * EE_PMT_Base child class |
|
232 | + * (eg, |
|
233 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
234 | + * which contains the files |
|
235 | + * EE_PMT_Payomatic.pm.php) |
|
236 | + * @type array $default_terms |
|
237 | + * @type array $namespace { |
|
238 | + * An array with two items for registering the |
|
239 | + * addon's namespace. (If, for some reason, you |
|
240 | + * require additional namespaces, |
|
241 | + * use |
|
242 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
243 | + * directly) |
|
244 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
245 | + * @type string $FQNS the namespace prefix |
|
246 | + * @type string $DIR a base directory for class files in the |
|
247 | + * namespace. |
|
248 | + * } |
|
249 | + * } |
|
250 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
251 | + * privacy policy classes) or FQCNs (specific |
|
252 | + * classnames of privacy policy classes) |
|
253 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
254 | + * privacy policy classes) or FQCNs (specific |
|
255 | + * classnames of privacy policy classes) |
|
256 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
257 | + * privacy policy classes) or FQCNs (specific |
|
258 | + * classnames of privacy policy classes) |
|
259 | + */ |
|
260 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
261 | + { |
|
262 | + // $addon_name = basename($addon_name); |
|
263 | + if (! self::$loader instanceof LoaderInterface) { |
|
264 | + self::$loader = LoaderFactory::getLoader(); |
|
265 | + } |
|
266 | + // make sure this was called in the right place! |
|
267 | + if ( |
|
268 | + ! did_action('activate_plugin') |
|
269 | + && ( |
|
270 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
271 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
272 | + ) |
|
273 | + ) { |
|
274 | + EE_Error::doing_it_wrong( |
|
275 | + __METHOD__, |
|
276 | + sprintf( |
|
277 | + esc_html__( |
|
278 | + '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.', |
|
279 | + 'event_espresso' |
|
280 | + ), |
|
281 | + $addon_name |
|
282 | + ), |
|
283 | + '4.3.0' |
|
284 | + ); |
|
285 | + return false; |
|
286 | + } |
|
287 | + // required fields MUST be present, so let's make sure they are. |
|
288 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
289 | + // get class name for addon |
|
290 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
291 | + // setup $_settings array from incoming values. |
|
292 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
293 | + // allow early addon setup or modification of addon api settings |
|
294 | + self::$_settings = (array) apply_filters( |
|
295 | + 'FHEE__EE_Register_Addon__register', |
|
296 | + self::$_settings, |
|
297 | + $addon_name, |
|
298 | + $class_name, |
|
299 | + $setup_args |
|
300 | + ); |
|
301 | + // does this addon work with this version of core or WordPress ? |
|
302 | + // does this addon work with this version of core or WordPress ? |
|
303 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
304 | + return false; |
|
305 | + } |
|
306 | + // register namespaces |
|
307 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
308 | + // check if this is an activation request |
|
309 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
310 | + // dont bother setting up the rest of the addon atm |
|
311 | + return false; |
|
312 | + } |
|
313 | + // we need cars |
|
314 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
315 | + // register new models and extensions |
|
316 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
317 | + // setup DMS |
|
318 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
319 | + // if config_class is present let's register config. |
|
320 | + EE_Register_Addon::_register_config($addon_name); |
|
321 | + // register admin pages |
|
322 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
323 | + // add to list of modules to be registered |
|
324 | + EE_Register_Addon::_register_modules($addon_name); |
|
325 | + // add to list of shortcodes to be registered |
|
326 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
327 | + // add to list of widgets to be registered |
|
328 | + EE_Register_Addon::_register_widgets($addon_name); |
|
329 | + // register capability related stuff. |
|
330 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
331 | + // any message type to register? |
|
332 | + EE_Register_Addon::_register_message_types($addon_name); |
|
333 | + // any custom post type/ custom capabilities or default terms to register |
|
334 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
335 | + // and any payment methods |
|
336 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
337 | + // and privacy policy generators |
|
338 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
339 | + // and privacy policy generators |
|
340 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
341 | + // and privacy policy generators |
|
342 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
343 | + // load and instantiate main addon class |
|
344 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
345 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
346 | + add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
347 | + return $addon instanceof EE_Addon; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * @param string $addon_name |
|
353 | + * @param array $setup_args |
|
354 | + * @return void |
|
355 | + * @throws EE_Error |
|
356 | + */ |
|
357 | + private static function _verify_parameters(string $addon_name, array $setup_args) |
|
358 | + { |
|
359 | + // required fields MUST be present, so let's make sure they are. |
|
360 | + if (empty($addon_name) || empty($setup_args)) { |
|
361 | + throw new EE_Error( |
|
362 | + esc_html__( |
|
363 | + '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.', |
|
364 | + 'event_espresso' |
|
365 | + ) |
|
366 | + ); |
|
367 | + } |
|
368 | + if (empty($setup_args['main_file_path'])) { |
|
369 | + throw new EE_Error( |
|
370 | + sprintf( |
|
371 | + esc_html__( |
|
372 | + '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', |
|
373 | + 'event_espresso' |
|
374 | + ), |
|
375 | + implode(',', array_keys($setup_args)) |
|
376 | + ) |
|
377 | + ); |
|
378 | + } |
|
379 | + // check that addon has not already been registered with that name |
|
380 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
381 | + throw new EE_Error( |
|
382 | + sprintf( |
|
383 | + esc_html__( |
|
384 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
385 | + 'event_espresso' |
|
386 | + ), |
|
387 | + $addon_name |
|
388 | + ) |
|
389 | + ); |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @param string $addon_name |
|
396 | + * @param array $setup_args |
|
397 | + * @return string |
|
398 | + */ |
|
399 | + private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
400 | + { |
|
401 | + if (empty($setup_args['class_name'])) { |
|
402 | + // generate one by first separating name with spaces |
|
403 | + $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
404 | + // capitalize, then replace spaces with underscores |
|
405 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
406 | + } else { |
|
407 | + $class_name = $setup_args['class_name']; |
|
408 | + } |
|
409 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
410 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
411 | + ? $class_name |
|
412 | + : 'EE_' . $class_name; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * @param string $class_name |
|
418 | + * @param array $setup_args |
|
419 | + * @return array |
|
420 | + */ |
|
421 | + private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
422 | + { |
|
423 | + // setup $_settings array from incoming values. |
|
424 | + $addon_settings = [ |
|
425 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
426 | + 'class_name' => $class_name, |
|
427 | + // the addon slug for use in URLs, etc |
|
428 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
429 | + ? (string) $setup_args['plugin_slug'] |
|
430 | + : '', |
|
431 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
432 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
433 | + ? (string) $setup_args['plugin_action_slug'] |
|
434 | + : '', |
|
435 | + // the "software" version for the addon |
|
436 | + 'version' => isset($setup_args['version']) |
|
437 | + ? (string) $setup_args['version'] |
|
438 | + : '', |
|
439 | + // the minimum version of EE Core that the addon will work with |
|
440 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
441 | + ? (string) $setup_args['min_core_version'] |
|
442 | + : '', |
|
443 | + // the minimum version of WordPress that the addon will work with |
|
444 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
445 | + ? (string) $setup_args['min_wp_version'] |
|
446 | + : EE_MIN_WP_VER_REQUIRED, |
|
447 | + // full server path to main file (file loaded directly by WP) |
|
448 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
449 | + ? (string) $setup_args['main_file_path'] |
|
450 | + : '', |
|
451 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
452 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
453 | + ? $setup_args['domain'] |
|
454 | + : null, |
|
455 | + // Fully Qualified Class Name for the addon's Domain class |
|
456 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
457 | + ? (string) $setup_args['domain_fqcn'] |
|
458 | + : '', |
|
459 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
460 | + 'admin_path' => isset($setup_args['admin_path']) |
|
461 | + ? (string) $setup_args['admin_path'] |
|
462 | + : '', |
|
463 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
464 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
465 | + ? (string) $setup_args['admin_callback'] |
|
466 | + : '', |
|
467 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
468 | + 'config_section' => isset($setup_args['config_section']) |
|
469 | + ? (string) $setup_args['config_section'] |
|
470 | + : 'addons', |
|
471 | + // the class name for this addon's configuration settings object |
|
472 | + 'config_class' => isset($setup_args['config_class']) |
|
473 | + ? (string) $setup_args['config_class'] |
|
474 | + : '', |
|
475 | + // the name given to the config for this addons' configuration settings object (optional) |
|
476 | + 'config_name' => isset($setup_args['config_name']) |
|
477 | + ? (string) $setup_args['config_name'] |
|
478 | + : '', |
|
479 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
480 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
481 | + ? (array) $setup_args['autoloader_paths'] |
|
482 | + : [], |
|
483 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
484 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
485 | + ? (array) $setup_args['autoloader_folders'] |
|
486 | + : [], |
|
487 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
488 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
489 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
490 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
491 | + ? (array) $setup_args['dms_paths'] |
|
492 | + : [], |
|
493 | + // array of full server paths to any EED_Modules used by the addon |
|
494 | + 'module_paths' => isset($setup_args['module_paths']) |
|
495 | + ? (array) $setup_args['module_paths'] |
|
496 | + : [], |
|
497 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
498 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
499 | + ? (array) $setup_args['shortcode_paths'] |
|
500 | + : [], |
|
501 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
502 | + ? (array) $setup_args['shortcode_fqcns'] |
|
503 | + : [], |
|
504 | + // array of full server paths to any WP_Widgets used by the addon |
|
505 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
506 | + ? (array) $setup_args['widget_paths'] |
|
507 | + : [], |
|
508 | + 'message_types' => isset($setup_args['message_types']) |
|
509 | + ? (array) $setup_args['message_types'] |
|
510 | + : [], |
|
511 | + 'capabilities' => isset($setup_args['capabilities']) |
|
512 | + ? (array) $setup_args['capabilities'] |
|
513 | + : [], |
|
514 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
515 | + ? (array) $setup_args['capability_maps'] |
|
516 | + : [], |
|
517 | + 'model_paths' => isset($setup_args['model_paths']) |
|
518 | + ? (array) $setup_args['model_paths'] |
|
519 | + : [], |
|
520 | + 'class_paths' => isset($setup_args['class_paths']) |
|
521 | + ? (array) $setup_args['class_paths'] |
|
522 | + : [], |
|
523 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
524 | + ? (array) $setup_args['model_extension_paths'] |
|
525 | + : [], |
|
526 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
527 | + ? (array) $setup_args['class_extension_paths'] |
|
528 | + : [], |
|
529 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
530 | + ? (array) $setup_args['custom_post_types'] |
|
531 | + : [], |
|
532 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
533 | + ? (array) $setup_args['custom_taxonomies'] |
|
534 | + : [], |
|
535 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
536 | + ? (array) $setup_args['payment_method_paths'] |
|
537 | + : [], |
|
538 | + 'default_terms' => isset($setup_args['default_terms']) |
|
539 | + ? (array) $setup_args['default_terms'] |
|
540 | + : [], |
|
541 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
542 | + // that can be used for adding upgrading/marketing info |
|
543 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
544 | + ? (array) $setup_args['plugins_page_row'] |
|
545 | + : [], |
|
546 | + 'namespace' => isset( |
|
547 | + $setup_args['namespace']['FQNS'], |
|
548 | + $setup_args['namespace']['DIR'] |
|
549 | + ) |
|
550 | + ? (array) $setup_args['namespace'] |
|
551 | + : [], |
|
552 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
553 | + ? (array) $setup_args['privacy_policies'] |
|
554 | + : '', |
|
555 | + ]; |
|
556 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
557 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
558 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
559 | + && ! empty($addon_settings['admin_path']) |
|
560 | + ? $addon_settings['plugin_slug'] |
|
561 | + : $addon_settings['plugin_action_slug']; |
|
562 | + // full server path to main file (file loaded directly by WP) |
|
563 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
564 | + return $addon_settings; |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * @param string $addon_name |
|
570 | + * @param array $addon_settings |
|
571 | + * @return bool |
|
572 | + */ |
|
573 | + private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
574 | + { |
|
575 | + global $wp_version; |
|
576 | + $incompatibility_message = ''; |
|
577 | + // check whether this addon version is compatible with EE core |
|
578 | + if ( |
|
579 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
580 | + && ! self::_meets_min_core_version_requirement( |
|
581 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
582 | + $addon_settings['version'] |
|
583 | + ) |
|
584 | + ) { |
|
585 | + $incompatibility_message = sprintf( |
|
586 | + esc_html__( |
|
587 | + '%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.', |
|
588 | + 'event_espresso' |
|
589 | + ), |
|
590 | + $addon_name, |
|
591 | + '<br />', |
|
592 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
593 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
594 | + '</span><br />' |
|
595 | + ); |
|
596 | + } elseif ( |
|
597 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
598 | + ) { |
|
599 | + $incompatibility_message = sprintf( |
|
600 | + esc_html__( |
|
601 | + '%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".', |
|
602 | + 'event_espresso' |
|
603 | + ), |
|
604 | + $addon_name, |
|
605 | + self::_effective_version($addon_settings['min_core_version']), |
|
606 | + self::_effective_version(espresso_version()), |
|
607 | + '<br />', |
|
608 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
609 | + '</span><br />' |
|
610 | + ); |
|
611 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
612 | + $incompatibility_message = sprintf( |
|
613 | + esc_html__( |
|
614 | + '%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.', |
|
615 | + 'event_espresso' |
|
616 | + ), |
|
617 | + $addon_name, |
|
618 | + $addon_settings['min_wp_version'], |
|
619 | + '<br />', |
|
620 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
621 | + '</span><br />' |
|
622 | + ); |
|
623 | + } |
|
624 | + if (! empty($incompatibility_message)) { |
|
625 | + // remove 'activate' from the REQUEST |
|
626 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
627 | + /** @var RequestInterface $request */ |
|
628 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
629 | + $request->unSetRequestParam('activate', true); |
|
630 | + if (current_user_can('activate_plugins')) { |
|
631 | + // show an error message indicating the plugin didn't activate properly |
|
632 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
633 | + } |
|
634 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
635 | + if (! function_exists('deactivate_plugins')) { |
|
636 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
637 | + } |
|
638 | + deactivate_plugins(plugin_basename($addon_settings['main_file_path'])); |
|
639 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
640 | + return false; |
|
641 | + } |
|
642 | + // addon IS compatible |
|
643 | + return true; |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
649 | + * |
|
650 | + * @param array $addon_settings |
|
651 | + * @return void |
|
652 | + * @throws EE_Error |
|
653 | + */ |
|
654 | + private static function _setup_namespaces(array $addon_settings) |
|
655 | + { |
|
656 | + // |
|
657 | + if ( |
|
658 | + isset( |
|
659 | + $addon_settings['namespace']['FQNS'], |
|
660 | + $addon_settings['namespace']['DIR'] |
|
661 | + ) |
|
662 | + ) { |
|
663 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
664 | + $addon_settings['namespace']['FQNS'], |
|
665 | + $addon_settings['namespace']['DIR'] |
|
666 | + ); |
|
667 | + } |
|
668 | + } |
|
669 | + |
|
670 | + |
|
671 | + /** |
|
672 | + * @param string $addon_name |
|
673 | + * @param array $addon_settings |
|
674 | + * @return bool |
|
675 | + * @throws InvalidArgumentException |
|
676 | + * @throws InvalidDataTypeException |
|
677 | + * @throws InvalidInterfaceException |
|
678 | + */ |
|
679 | + private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
680 | + { |
|
681 | + // this is an activation request |
|
682 | + if (did_action('activate_plugin')) { |
|
683 | + // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
684 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
685 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
686 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
687 | + if ( |
|
688 | + ! isset(self::$_settings[ $addon_name ]) |
|
689 | + || (isset(self::$_settings[ $addon_name ]) |
|
690 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
691 | + ) |
|
692 | + ) { |
|
693 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
694 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
695 | + $addon->set_activation_indicator_option(); |
|
696 | + // dont bother setting up the rest of the addon. |
|
697 | + // we know it was just activated and the request will end soon |
|
698 | + } |
|
699 | + return true; |
|
700 | + } |
|
701 | + // make sure addon settings are set correctly without overwriting anything existing |
|
702 | + if (isset(self::$_settings[ $addon_name ])) { |
|
703 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
704 | + } else { |
|
705 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
706 | + } |
|
707 | + return false; |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * @param string $addon_name |
|
713 | + * @return void |
|
714 | + * @throws EE_Error |
|
715 | + */ |
|
716 | + private static function _setup_autoloaders(string $addon_name) |
|
717 | + { |
|
718 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
719 | + // setup autoloader for single file |
|
720 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
721 | + } |
|
722 | + // setup autoloaders for folders |
|
723 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
724 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
725 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
726 | + } |
|
727 | + } |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * register new models and extensions |
|
733 | + * |
|
734 | + * @param string $addon_name |
|
735 | + * @return void |
|
736 | + * @throws EE_Error |
|
737 | + */ |
|
738 | + private static function _register_models_and_extensions(string $addon_name) |
|
739 | + { |
|
740 | + // register new models |
|
741 | + if ( |
|
742 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
743 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
744 | + ) { |
|
745 | + EE_Register_Model::register( |
|
746 | + $addon_name, |
|
747 | + [ |
|
748 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
749 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
750 | + ] |
|
751 | + ); |
|
752 | + } |
|
753 | + // register model extensions |
|
754 | + if ( |
|
755 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
756 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
757 | + ) { |
|
758 | + EE_Register_Model_Extensions::register( |
|
759 | + $addon_name, |
|
760 | + [ |
|
761 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
762 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
763 | + ] |
|
764 | + ); |
|
765 | + } |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * @param string $addon_name |
|
771 | + * @return void |
|
772 | + * @throws EE_Error |
|
773 | + */ |
|
774 | + private static function _register_data_migration_scripts(string $addon_name) |
|
775 | + { |
|
776 | + // setup DMS |
|
777 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
778 | + EE_Register_Data_Migration_Scripts::register( |
|
779 | + $addon_name, |
|
780 | + ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
781 | + ); |
|
782 | + } |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * @param string $addon_name |
|
788 | + * @return void |
|
789 | + * @throws EE_Error |
|
790 | + */ |
|
791 | + private static function _register_config(string $addon_name) |
|
792 | + { |
|
793 | + // if config_class is present let's register config. |
|
794 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
795 | + EE_Register_Config::register( |
|
796 | + self::$_settings[ $addon_name ]['config_class'], |
|
797 | + [ |
|
798 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
799 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
800 | + ] |
|
801 | + ); |
|
802 | + } |
|
803 | + } |
|
804 | + |
|
805 | + |
|
806 | + /** |
|
807 | + * @param string $addon_name |
|
808 | + * @return void |
|
809 | + * @throws EE_Error |
|
810 | + */ |
|
811 | + private static function _register_admin_pages(string $addon_name) |
|
812 | + { |
|
813 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
814 | + EE_Register_Admin_Page::register( |
|
815 | + $addon_name, |
|
816 | + ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
817 | + ); |
|
818 | + } |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * @param string $addon_name |
|
824 | + * @return void |
|
825 | + * @throws EE_Error |
|
826 | + */ |
|
827 | + private static function _register_modules(string $addon_name) |
|
828 | + { |
|
829 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
830 | + EE_Register_Module::register( |
|
831 | + $addon_name, |
|
832 | + ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
833 | + ); |
|
834 | + } |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + /** |
|
839 | + * @param string $addon_name |
|
840 | + * @return void |
|
841 | + * @throws EE_Error |
|
842 | + */ |
|
843 | + private static function _register_shortcodes(string $addon_name) |
|
844 | + { |
|
845 | + if ( |
|
846 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
847 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
848 | + ) { |
|
849 | + EE_Register_Shortcode::register( |
|
850 | + $addon_name, |
|
851 | + [ |
|
852 | + 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
853 | + 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
854 | + ] |
|
855 | + ); |
|
856 | + } |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + /** |
|
861 | + * @param string $addon_name |
|
862 | + * @return void |
|
863 | + * @throws EE_Error |
|
864 | + */ |
|
865 | + private static function _register_widgets(string $addon_name) |
|
866 | + { |
|
867 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
868 | + EE_Register_Widget::register( |
|
869 | + $addon_name, |
|
870 | + ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
871 | + ); |
|
872 | + } |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + /** |
|
877 | + * @param string $addon_name |
|
878 | + * @return void |
|
879 | + * @throws EE_Error |
|
880 | + */ |
|
881 | + private static function _register_capabilities(string $addon_name) |
|
882 | + { |
|
883 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
884 | + EE_Register_Capabilities::register( |
|
885 | + $addon_name, |
|
886 | + [ |
|
887 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
888 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
889 | + ] |
|
890 | + ); |
|
891 | + } |
|
892 | + } |
|
893 | + |
|
894 | + |
|
895 | + /** |
|
896 | + * @param string $addon_name |
|
897 | + * @return void |
|
898 | + */ |
|
899 | + private static function _register_message_types(string $addon_name) |
|
900 | + { |
|
901 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
902 | + add_action( |
|
903 | + 'EE_Brewing_Regular___messages_caf', |
|
904 | + ['EE_Register_Addon', 'register_message_types'] |
|
905 | + ); |
|
906 | + } |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * @param string $addon_name |
|
912 | + * @return void |
|
913 | + * @throws EE_Error |
|
914 | + */ |
|
915 | + private static function _register_custom_post_types(string $addon_name) |
|
916 | + { |
|
917 | + if ( |
|
918 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
919 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
920 | + ) { |
|
921 | + EE_Register_CPT::register( |
|
922 | + $addon_name, |
|
923 | + [ |
|
924 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
925 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
926 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
927 | + ] |
|
928 | + ); |
|
929 | + } |
|
930 | + } |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * @param string $addon_name |
|
935 | + * @return void |
|
936 | + * @throws InvalidArgumentException |
|
937 | + * @throws InvalidInterfaceException |
|
938 | + * @throws InvalidDataTypeException |
|
939 | + * @throws DomainException |
|
940 | + * @throws EE_Error |
|
941 | + */ |
|
942 | + private static function _register_payment_methods(string $addon_name) |
|
943 | + { |
|
944 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
945 | + EE_Register_Payment_Method::register( |
|
946 | + $addon_name, |
|
947 | + ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
948 | + ); |
|
949 | + } |
|
950 | + } |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * @param string $addon_name |
|
955 | + * @return void |
|
956 | + * @throws InvalidArgumentException |
|
957 | + * @throws InvalidInterfaceException |
|
958 | + * @throws InvalidDataTypeException |
|
959 | + * @throws DomainException |
|
960 | + */ |
|
961 | + private static function registerPrivacyPolicies(string $addon_name) |
|
962 | + { |
|
963 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
964 | + EE_Register_Privacy_Policy::register( |
|
965 | + $addon_name, |
|
966 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
967 | + ); |
|
968 | + } |
|
969 | + } |
|
970 | + |
|
971 | + |
|
972 | + /** |
|
973 | + * @param string $addon_name |
|
974 | + * @return void |
|
975 | + */ |
|
976 | + private static function registerPersonalDataExporters(string $addon_name) |
|
977 | + { |
|
978 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
979 | + EE_Register_Personal_Data_Eraser::register( |
|
980 | + $addon_name, |
|
981 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
982 | + ); |
|
983 | + } |
|
984 | + } |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * @param string $addon_name |
|
989 | + * @return void |
|
990 | + */ |
|
991 | + private static function registerPersonalDataErasers(string $addon_name) |
|
992 | + { |
|
993 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
994 | + EE_Register_Personal_Data_Eraser::register( |
|
995 | + $addon_name, |
|
996 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
997 | + ); |
|
998 | + } |
|
999 | + } |
|
1000 | + |
|
1001 | + |
|
1002 | + /** |
|
1003 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1004 | + * |
|
1005 | + * @param string $addon_name |
|
1006 | + * @return EE_Addon |
|
1007 | + * @throws InvalidArgumentException |
|
1008 | + * @throws InvalidInterfaceException |
|
1009 | + * @throws InvalidDataTypeException |
|
1010 | + */ |
|
1011 | + private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
|
1012 | + { |
|
1013 | + $addon = self::$loader->getShared( |
|
1014 | + self::$_settings[ $addon_name ]['class_name'], |
|
1015 | + ['EE_Registry::create(addon)' => true] |
|
1016 | + ); |
|
1017 | + if (! $addon instanceof EE_Addon) { |
|
1018 | + throw new DomainException( |
|
1019 | + sprintf( |
|
1020 | + esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
1021 | + self::$_settings[ $addon_name ]['class_name'] |
|
1022 | + ) |
|
1023 | + ); |
|
1024 | + } |
|
1025 | + // setter inject dep map if required |
|
1026 | + if ($addon->dependencyMap() === null) { |
|
1027 | + $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
1028 | + } |
|
1029 | + // setter inject domain if required |
|
1030 | + EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1031 | + |
|
1032 | + $addon->set_name($addon_name); |
|
1033 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1034 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1035 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1036 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1037 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1038 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1039 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1040 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1041 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1042 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1043 | + do_action( |
|
1044 | + 'AHEE__EE_Register_Addon___load_and_init_addon_class', |
|
1045 | + $addon, |
|
1046 | + $addon_name, |
|
1047 | + self::$_settings |
|
1048 | + ); |
|
1049 | + // unfortunately this can't be hooked in upon construction, |
|
1050 | + // because we don't have the plugin's mainfile path upon construction. |
|
1051 | + register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
1052 | + // call any additional admin_callback functions during load_admin_controller hook |
|
1053 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1054 | + add_action( |
|
1055 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1056 | + [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1057 | + ); |
|
1058 | + } |
|
1059 | + return $addon; |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * @param string $addon_name |
|
1065 | + * @param EE_Addon $addon |
|
1066 | + * @since 4.10.13.p |
|
1067 | + */ |
|
1068 | + private static function injectAddonDomain(string $addon_name, EE_Addon $addon) |
|
1069 | + { |
|
1070 | + if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1071 | + // using supplied Domain object |
|
1072 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1073 | + ? self::$_settings[ $addon_name ]['domain'] |
|
1074 | + : null; |
|
1075 | + // or construct one using Domain FQCN |
|
1076 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1077 | + $domain = self::$loader->getShared( |
|
1078 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1079 | + [ |
|
1080 | + new EventEspresso\core\domain\values\FilePath( |
|
1081 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
1082 | + ), |
|
1083 | + EventEspresso\core\domain\values\Version::fromString( |
|
1084 | + self::$_settings[ $addon_name ]['version'] |
|
1085 | + ), |
|
1086 | + ] |
|
1087 | + ); |
|
1088 | + } |
|
1089 | + if ($domain instanceof DomainInterface) { |
|
1090 | + $addon->setDomain($domain); |
|
1091 | + } |
|
1092 | + } |
|
1093 | + } |
|
1094 | + |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * @return void |
|
1098 | + * @deprecated 5.0.0.p |
|
1099 | + */ |
|
1100 | + public static function load_pue_update() |
|
1101 | + { |
|
1102 | + RegisterAddonPUE::loadPueUpdate(); |
|
1103 | + } |
|
1104 | + |
|
1105 | + |
|
1106 | + /** |
|
1107 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1108 | + * |
|
1109 | + * @return void |
|
1110 | + * @throws EE_Error |
|
1111 | + * @since 4.4.0 |
|
1112 | + */ |
|
1113 | + public static function register_message_types() |
|
1114 | + { |
|
1115 | + foreach (self::$_settings as $settings) { |
|
1116 | + if (! empty($settings['message_types'])) { |
|
1117 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1118 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1119 | + } |
|
1120 | + } |
|
1121 | + } |
|
1122 | + } |
|
1123 | + |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1127 | + * |
|
1128 | + * @param string $addon_name the name for the addon that was previously registered |
|
1129 | + * @throws DomainException |
|
1130 | + * @throws InvalidArgumentException |
|
1131 | + * @throws InvalidDataTypeException |
|
1132 | + * @throws InvalidInterfaceException |
|
1133 | + * @since 4.3.0 |
|
1134 | + */ |
|
1135 | + public static function deregister(string $addon_name = '') |
|
1136 | + { |
|
1137 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1138 | + try { |
|
1139 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1140 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1141 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1142 | + // setup DMS |
|
1143 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1144 | + } |
|
1145 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1146 | + // register admin page |
|
1147 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1148 | + } |
|
1149 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1150 | + // add to list of modules to be registered |
|
1151 | + EE_Register_Module::deregister($addon_name); |
|
1152 | + } |
|
1153 | + if ( |
|
1154 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1155 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1156 | + ) { |
|
1157 | + // add to list of shortcodes to be registered |
|
1158 | + EE_Register_Shortcode::deregister($addon_name); |
|
1159 | + } |
|
1160 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1161 | + // if config_class present let's register config. |
|
1162 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1163 | + } |
|
1164 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1165 | + // add to list of widgets to be registered |
|
1166 | + EE_Register_Widget::deregister($addon_name); |
|
1167 | + } |
|
1168 | + if ( |
|
1169 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1170 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1171 | + ) { |
|
1172 | + // add to list of shortcodes to be registered |
|
1173 | + EE_Register_Model::deregister($addon_name); |
|
1174 | + } |
|
1175 | + if ( |
|
1176 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1177 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1178 | + ) { |
|
1179 | + // add to list of shortcodes to be registered |
|
1180 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1181 | + } |
|
1182 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1183 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1184 | + EE_Register_Message_Type::deregister($message_type); |
|
1185 | + } |
|
1186 | + } |
|
1187 | + // deregister capabilities for addon |
|
1188 | + if ( |
|
1189 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1190 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1191 | + ) { |
|
1192 | + EE_Register_Capabilities::deregister($addon_name); |
|
1193 | + } |
|
1194 | + // deregister custom_post_types for addon |
|
1195 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1196 | + EE_Register_CPT::deregister($addon_name); |
|
1197 | + } |
|
1198 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1199 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1200 | + } |
|
1201 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1202 | + if ($addon instanceof EE_Addon) { |
|
1203 | + remove_action( |
|
1204 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1205 | + [$addon, 'deactivation'] |
|
1206 | + ); |
|
1207 | + remove_action( |
|
1208 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1209 | + [$addon, 'initialize_db_if_no_migrations_required'] |
|
1210 | + ); |
|
1211 | + // remove `after_registration` call |
|
1212 | + remove_action( |
|
1213 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1214 | + [$addon, 'after_registration'], |
|
1215 | + 999 |
|
1216 | + ); |
|
1217 | + } |
|
1218 | + EE_Registry::instance()->removeAddon($class_name); |
|
1219 | + LoaderFactory::getLoader()->remove($class_name); |
|
1220 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1221 | + // the add-on was not yet registered in the registry, |
|
1222 | + // so RegistryContainer::__get() throws this exception. |
|
1223 | + // also no need to worry about this or log it, |
|
1224 | + // it's ok to deregister an add-on before its registered in the registry |
|
1225 | + } catch (Exception $e) { |
|
1226 | + new ExceptionLogger($e); |
|
1227 | + } |
|
1228 | + unset(self::$_settings[ $addon_name ]); |
|
1229 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1230 | + } |
|
1231 | + } |
|
1232 | + |
|
1233 | + |
|
1234 | + public static function reset(): void |
|
1235 | + { |
|
1236 | + EE_Register_Addon::$_settings = []; |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + public static function resetAll(): void |
|
1241 | + { |
|
1242 | + // EE_Register_Addon::reset(); |
|
1243 | + EE_Register_Admin_Page::reset(); |
|
1244 | + EE_Register_Capabilities::reset(); |
|
1245 | + EE_Register_Config::reset(); |
|
1246 | + EE_Register_CPT::reset(); |
|
1247 | + EE_Register_Data_Migration_Scripts::reset(); |
|
1248 | + EE_Register_Message_Type::reset(); |
|
1249 | + EE_Register_Messages_Shortcode_Library::reset(); |
|
1250 | + EE_Register_Messages_Template_Pack::reset(); |
|
1251 | + EE_Register_Messages_Template_Variations::reset(); |
|
1252 | + EE_Register_Model::reset(); |
|
1253 | + EE_Register_Model_Extensions::reset(); |
|
1254 | + EE_Register_Module::reset(); |
|
1255 | + EE_Register_Payment_Method::reset(); |
|
1256 | + EE_Register_Personal_Data_Eraser::reset(); |
|
1257 | + EE_Register_Personal_Data_Exporter::reset(); |
|
1258 | + EE_Register_Privacy_Policy::reset(); |
|
1259 | + EE_Register_Shortcode::reset(); |
|
1260 | + EE_Register_Widget::reset(); |
|
1261 | + } |
|
1262 | 1262 | } |
@@ -12,31 +12,31 @@ |
||
12 | 12 | */ |
13 | 13 | class EventShortlinkButton extends PermalinkHtmlHook |
14 | 14 | { |
15 | - public static function getShortlink(int $id): string |
|
16 | - { |
|
17 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
18 | - $post = get_post($id); |
|
19 | - if (isset($post->post_type) && $post->post_type === 'espresso_events') { |
|
20 | - return home_url('?p=' . $post->ID); |
|
21 | - } |
|
22 | - } |
|
23 | - return ''; |
|
24 | - } |
|
15 | + public static function getShortlink(int $id): string |
|
16 | + { |
|
17 | + if (! empty($id) && get_option('permalink_structure') !== '') { |
|
18 | + $post = get_post($id); |
|
19 | + if (isset($post->post_type) && $post->post_type === 'espresso_events') { |
|
20 | + return home_url('?p=' . $post->ID); |
|
21 | + } |
|
22 | + } |
|
23 | + return ''; |
|
24 | + } |
|
25 | 25 | |
26 | 26 | |
27 | - public static function addButton(string $html, int $post_id): string |
|
28 | - { |
|
29 | - $permalink = get_permalink($post_id); |
|
30 | - $shortlink = esc_attr(EventShortlinkButton::getShortlink($post_id)); |
|
31 | - if (! empty($shortlink) && $shortlink !== $permalink && home_url('?page_id=' . $post_id) !== $permalink) { |
|
32 | - $onclick = 'prompt("URL:", jQuery("#espresso-event-shortlink").val()); return false;'; |
|
33 | - $html .= " |
|
27 | + public static function addButton(string $html, int $post_id): string |
|
28 | + { |
|
29 | + $permalink = get_permalink($post_id); |
|
30 | + $shortlink = esc_attr(EventShortlinkButton::getShortlink($post_id)); |
|
31 | + if (! empty($shortlink) && $shortlink !== $permalink && home_url('?page_id=' . $post_id) !== $permalink) { |
|
32 | + $onclick = 'prompt("URL:", jQuery("#espresso-event-shortlink").val()); return false;'; |
|
33 | + $html .= " |
|
34 | 34 | <input id='espresso-event-shortlink' type='hidden' value='$shortlink' /> |
35 | 35 | <button type='button' class='button button--tiny button--secondary' onclick='$onclick'> |
36 | 36 | <span class='dashicons dashicons-admin-links'></span> |
37 | 37 | " . esc_html__('Shortlink') . " |
38 | 38 | </button>"; |
39 | - } |
|
40 | - return $html; |
|
41 | - } |
|
39 | + } |
|
40 | + return $html; |
|
41 | + } |
|
42 | 42 | } |
@@ -14,10 +14,10 @@ discard block |
||
14 | 14 | { |
15 | 15 | public static function getShortlink(int $id): string |
16 | 16 | { |
17 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
17 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
18 | 18 | $post = get_post($id); |
19 | 19 | if (isset($post->post_type) && $post->post_type === 'espresso_events') { |
20 | - return home_url('?p=' . $post->ID); |
|
20 | + return home_url('?p='.$post->ID); |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | return ''; |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | { |
29 | 29 | $permalink = get_permalink($post_id); |
30 | 30 | $shortlink = esc_attr(EventShortlinkButton::getShortlink($post_id)); |
31 | - if (! empty($shortlink) && $shortlink !== $permalink && home_url('?page_id=' . $post_id) !== $permalink) { |
|
31 | + if ( ! empty($shortlink) && $shortlink !== $permalink && home_url('?page_id='.$post_id) !== $permalink) { |
|
32 | 32 | $onclick = 'prompt("URL:", jQuery("#espresso-event-shortlink").val()); return false;'; |
33 | - $html .= " |
|
33 | + $html .= " |
|
34 | 34 | <input id='espresso-event-shortlink' type='hidden' value='$shortlink' /> |
35 | 35 | <button type='button' class='button button--tiny button--secondary' onclick='$onclick'> |
36 | 36 | <span class='dashicons dashicons-admin-links'></span> |
37 | - " . esc_html__('Shortlink') . " |
|
37 | + ".esc_html__('Shortlink')." |
|
38 | 38 | </button>"; |
39 | 39 | } |
40 | 40 | return $html; |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class PreviewButton extends PermalinkHtmlHook |
14 | 14 | { |
15 | - public static function addButton(string $html, int $post_id): string |
|
16 | - { |
|
17 | - $post = get_post($post_id); |
|
18 | - if ('publish' !== get_post_status($post)) { |
|
19 | - $title = esc_html__('Preview', 'event_espresso'); |
|
20 | - $href = get_preview_post_link($post_id); |
|
21 | - $html .= " |
|
15 | + public static function addButton(string $html, int $post_id): string |
|
16 | + { |
|
17 | + $post = get_post($post_id); |
|
18 | + if ('publish' !== get_post_status($post)) { |
|
19 | + $title = esc_html__('Preview', 'event_espresso'); |
|
20 | + $href = get_preview_post_link($post_id); |
|
21 | + $html .= " |
|
22 | 22 | <span id='view-post-btn'> |
23 | 23 | <a target='_blank' |
24 | 24 | href='$href' |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $title |
29 | 29 | </a> |
30 | 30 | </span>"; |
31 | - } |
|
32 | - return $html; |
|
33 | - } |
|
31 | + } |
|
32 | + return $html; |
|
33 | + } |
|
34 | 34 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | if ('publish' !== get_post_status($post)) { |
19 | 19 | $title = esc_html__('Preview', 'event_espresso'); |
20 | 20 | $href = get_preview_post_link($post_id); |
21 | - $html .= " |
|
21 | + $html .= " |
|
22 | 22 | <span id='view-post-btn'> |
23 | 23 | <a target='_blank' |
24 | 24 | href='$href' |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | abstract class PermalinkHtmlHook |
6 | 6 | { |
7 | - public static function addEventEditorPermalinkButton(int $priority = 10, int $accepted_args = 2) |
|
8 | - { |
|
9 | - add_filter('get_sample_permalink_html', [get_called_class(), 'addButton'], $priority, $accepted_args); |
|
10 | - } |
|
7 | + public static function addEventEditorPermalinkButton(int $priority = 10, int $accepted_args = 2) |
|
8 | + { |
|
9 | + add_filter('get_sample_permalink_html', [get_called_class(), 'addButton'], $priority, $accepted_args); |
|
10 | + } |
|
11 | 11 | |
12 | 12 | |
13 | - abstract public static function addButton( string $html, int $post_id ): string; |
|
13 | + abstract public static function addButton( string $html, int $post_id ): string; |
|
14 | 14 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | } |
11 | 11 | |
12 | 12 | |
13 | - abstract public static function addButton( string $html, int $post_id ): string; |
|
13 | + abstract public static function addButton(string $html, int $post_id): string; |
|
14 | 14 | } |
@@ -12,22 +12,22 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class TicketSelectorShortcodeButton extends PermalinkHtmlHook |
14 | 14 | { |
15 | - public static function addButton(string $html, int $post_id): string |
|
16 | - { |
|
17 | - // make sure this is only when editing |
|
18 | - if (empty($post_id)) { |
|
19 | - return $html; |
|
20 | - } |
|
21 | - $post = get_post($post_id); |
|
22 | - // make sure this is EE event |
|
23 | - if (! $post || $post->post_type !== 'espresso_events') { |
|
24 | - return $html; |
|
25 | - } |
|
26 | - $onclick = |
|
27 | - 'prompt("Ticket Selector Shortcode:", jQuery("#espresso-ticket-selector-shortlink").val()); return false;'; |
|
28 | - $shortcode = esc_attr("[ESPRESSO_TICKET_SELECTOR event_id='$post_id']"); |
|
29 | - $title = esc_html__('Ticket Selector Shortcode', 'event_espresso'); |
|
30 | - $html .= " |
|
15 | + public static function addButton(string $html, int $post_id): string |
|
16 | + { |
|
17 | + // make sure this is only when editing |
|
18 | + if (empty($post_id)) { |
|
19 | + return $html; |
|
20 | + } |
|
21 | + $post = get_post($post_id); |
|
22 | + // make sure this is EE event |
|
23 | + if (! $post || $post->post_type !== 'espresso_events') { |
|
24 | + return $html; |
|
25 | + } |
|
26 | + $onclick = |
|
27 | + 'prompt("Ticket Selector Shortcode:", jQuery("#espresso-ticket-selector-shortlink").val()); return false;'; |
|
28 | + $shortcode = esc_attr("[ESPRESSO_TICKET_SELECTOR event_id='$post_id']"); |
|
29 | + $title = esc_html__('Ticket Selector Shortcode', 'event_espresso'); |
|
30 | + $html .= " |
|
31 | 31 | <a class='button button--tiny button--secondary' |
32 | 32 | onclick='$onclick' |
33 | 33 | href='#' |
@@ -37,6 +37,6 @@ discard block |
||
37 | 37 | $title |
38 | 38 | </a> |
39 | 39 | <input id='espresso-ticket-selector-shortlink' type='hidden' value='$shortcode'>"; |
40 | - return $html; |
|
41 | - } |
|
40 | + return $html; |
|
41 | + } |
|
42 | 42 | } |
@@ -20,14 +20,14 @@ |
||
20 | 20 | } |
21 | 21 | $post = get_post($post_id); |
22 | 22 | // make sure this is EE event |
23 | - if (! $post || $post->post_type !== 'espresso_events') { |
|
23 | + if ( ! $post || $post->post_type !== 'espresso_events') { |
|
24 | 24 | return $html; |
25 | 25 | } |
26 | 26 | $onclick = |
27 | 27 | 'prompt("Ticket Selector Shortcode:", jQuery("#espresso-ticket-selector-shortlink").val()); return false;'; |
28 | 28 | $shortcode = esc_attr("[ESPRESSO_TICKET_SELECTOR event_id='$post_id']"); |
29 | 29 | $title = esc_html__('Ticket Selector Shortcode', 'event_espresso'); |
30 | - $html .= " |
|
30 | + $html .= " |
|
31 | 31 | <a class='button button--tiny button--secondary' |
32 | 32 | onclick='$onclick' |
33 | 33 | href='#' |
@@ -14,23 +14,23 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class DuplicateEventButton extends PermalinkHtmlHook |
16 | 16 | { |
17 | - public static function addButton(string $html, int $post_id): string |
|
18 | - { |
|
19 | - // make sure this is only when editing |
|
20 | - if (empty($post_id)) { |
|
21 | - return $html; |
|
22 | - } |
|
23 | - $post = get_post($post_id); |
|
24 | - // make sure this is EE event |
|
25 | - if (! $post || $post->post_type !== 'espresso_events') { |
|
26 | - return $html; |
|
27 | - } |
|
28 | - $href = EEH_URL::add_query_args_and_nonce( |
|
29 | - ['action' => 'duplicate_event', 'EVT_ID' => $post_id], |
|
30 | - admin_url('admin.php?page=espresso_events') |
|
31 | - ); |
|
32 | - $title = esc_attr__('Duplicate', 'event_espresso'); |
|
33 | - $html .= " |
|
17 | + public static function addButton(string $html, int $post_id): string |
|
18 | + { |
|
19 | + // make sure this is only when editing |
|
20 | + if (empty($post_id)) { |
|
21 | + return $html; |
|
22 | + } |
|
23 | + $post = get_post($post_id); |
|
24 | + // make sure this is EE event |
|
25 | + if (! $post || $post->post_type !== 'espresso_events') { |
|
26 | + return $html; |
|
27 | + } |
|
28 | + $href = EEH_URL::add_query_args_and_nonce( |
|
29 | + ['action' => 'duplicate_event', 'EVT_ID' => $post_id], |
|
30 | + admin_url('admin.php?page=espresso_events') |
|
31 | + ); |
|
32 | + $title = esc_attr__('Duplicate', 'event_espresso'); |
|
33 | + $html .= " |
|
34 | 34 | <a aria-label='$title' |
35 | 35 | class='button button--tiny button--secondary' |
36 | 36 | href='$href' |
@@ -40,6 +40,6 @@ discard block |
||
40 | 40 | <span class='dashicons dashicons-admin-page'></span> |
41 | 41 | $title |
42 | 42 | </a>"; |
43 | - return $html; |
|
44 | - } |
|
43 | + return $html; |
|
44 | + } |
|
45 | 45 | } |
@@ -22,15 +22,15 @@ |
||
22 | 22 | } |
23 | 23 | $post = get_post($post_id); |
24 | 24 | // make sure this is EE event |
25 | - if (! $post || $post->post_type !== 'espresso_events') { |
|
25 | + if ( ! $post || $post->post_type !== 'espresso_events') { |
|
26 | 26 | return $html; |
27 | 27 | } |
28 | - $href = EEH_URL::add_query_args_and_nonce( |
|
28 | + $href = EEH_URL::add_query_args_and_nonce( |
|
29 | 29 | ['action' => 'duplicate_event', 'EVT_ID' => $post_id], |
30 | 30 | admin_url('admin.php?page=espresso_events') |
31 | 31 | ); |
32 | 32 | $title = esc_attr__('Duplicate', 'event_espresso'); |
33 | - $html .= " |
|
33 | + $html .= " |
|
34 | 34 | <a aria-label='$title' |
35 | 35 | class='button button--tiny button--secondary' |
36 | 36 | href='$href' |
@@ -13,81 +13,81 @@ |
||
13 | 13 | */ |
14 | 14 | class RegistrationsCsvReportParams |
15 | 15 | { |
16 | - /** |
|
17 | - * @param string $return_url |
|
18 | - * @param array $request_params |
|
19 | - * @param int $EVT_ID |
|
20 | - * @param int $DTT_ID |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public static function getRequestParams( |
|
24 | - string $return_url, |
|
25 | - array $request_params = [], |
|
26 | - int $EVT_ID = 0, |
|
27 | - int $DTT_ID = 0 |
|
28 | - ): array { |
|
29 | - if ( |
|
30 | - ! EE_Capabilities::instance()->current_user_can( |
|
31 | - 'ee_read_registrations', |
|
32 | - 'espresso_registrations_registrations_reports', |
|
33 | - $EVT_ID |
|
34 | - ) |
|
35 | - ) { |
|
36 | - return []; |
|
37 | - } |
|
38 | - unset($request_params['_wp_http_referer']); |
|
39 | - add_action( |
|
40 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
41 | - [RegistrationsCsvReportParams::class, 'csvReportNotice'] |
|
42 | - ); |
|
16 | + /** |
|
17 | + * @param string $return_url |
|
18 | + * @param array $request_params |
|
19 | + * @param int $EVT_ID |
|
20 | + * @param int $DTT_ID |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public static function getRequestParams( |
|
24 | + string $return_url, |
|
25 | + array $request_params = [], |
|
26 | + int $EVT_ID = 0, |
|
27 | + int $DTT_ID = 0 |
|
28 | + ): array { |
|
29 | + if ( |
|
30 | + ! EE_Capabilities::instance()->current_user_can( |
|
31 | + 'ee_read_registrations', |
|
32 | + 'espresso_registrations_registrations_reports', |
|
33 | + $EVT_ID |
|
34 | + ) |
|
35 | + ) { |
|
36 | + return []; |
|
37 | + } |
|
38 | + unset($request_params['_wp_http_referer']); |
|
39 | + add_action( |
|
40 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
41 | + [RegistrationsCsvReportParams::class, 'csvReportNotice'] |
|
42 | + ); |
|
43 | 43 | |
44 | - $route_details = [ |
|
45 | - 'route' => 'registrations_report', |
|
46 | - 'extra_request' => [ 'return_url' => $return_url ], |
|
47 | - 'btn_class' => 'button button--primary', |
|
48 | - ]; |
|
49 | - if (! empty($EVT_ID)) { |
|
50 | - $route_details['extra_request']['EVT_ID'] = $EVT_ID; |
|
51 | - } |
|
52 | - if ($DTT_ID) { |
|
53 | - $route_details['extra_request']['DTT_ID'] = $DTT_ID; |
|
54 | - } |
|
55 | - // detect views (status) or searches (s) and set "use_filters" to true |
|
56 | - if ( |
|
57 | - isset($request_params['status']) |
|
58 | - || isset($request_params['s']) |
|
59 | - || isset($request_params['ticket_id']) |
|
60 | - || isset($request_params['datetime_id']) |
|
61 | - || isset($request_params['_reg_status']) |
|
62 | - ) { |
|
63 | - $request_params['use_filters'] = true; |
|
64 | - $route_details['extra_request']['use_filters'] = true; |
|
65 | - } |
|
66 | - if ( |
|
67 | - isset($request_params['use_filters']) |
|
68 | - && filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN) |
|
69 | - ) { |
|
70 | - $route_details['extra_request']['filters'] = array_diff_key( |
|
71 | - $request_params, |
|
72 | - [ |
|
73 | - 'page' => '', |
|
74 | - 'action' => '', |
|
75 | - 'default_nonce' => '', |
|
76 | - ] |
|
77 | - ); |
|
78 | - } |
|
79 | - return $route_details; |
|
80 | - } |
|
44 | + $route_details = [ |
|
45 | + 'route' => 'registrations_report', |
|
46 | + 'extra_request' => [ 'return_url' => $return_url ], |
|
47 | + 'btn_class' => 'button button--primary', |
|
48 | + ]; |
|
49 | + if (! empty($EVT_ID)) { |
|
50 | + $route_details['extra_request']['EVT_ID'] = $EVT_ID; |
|
51 | + } |
|
52 | + if ($DTT_ID) { |
|
53 | + $route_details['extra_request']['DTT_ID'] = $DTT_ID; |
|
54 | + } |
|
55 | + // detect views (status) or searches (s) and set "use_filters" to true |
|
56 | + if ( |
|
57 | + isset($request_params['status']) |
|
58 | + || isset($request_params['s']) |
|
59 | + || isset($request_params['ticket_id']) |
|
60 | + || isset($request_params['datetime_id']) |
|
61 | + || isset($request_params['_reg_status']) |
|
62 | + ) { |
|
63 | + $request_params['use_filters'] = true; |
|
64 | + $route_details['extra_request']['use_filters'] = true; |
|
65 | + } |
|
66 | + if ( |
|
67 | + isset($request_params['use_filters']) |
|
68 | + && filter_var($request_params['use_filters'], FILTER_VALIDATE_BOOLEAN) |
|
69 | + ) { |
|
70 | + $route_details['extra_request']['filters'] = array_diff_key( |
|
71 | + $request_params, |
|
72 | + [ |
|
73 | + 'page' => '', |
|
74 | + 'action' => '', |
|
75 | + 'default_nonce' => '', |
|
76 | + ] |
|
77 | + ); |
|
78 | + } |
|
79 | + return $route_details; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - public static function csvReportNotice() |
|
84 | - { |
|
85 | - echo ' |
|
83 | + public static function csvReportNotice() |
|
84 | + { |
|
85 | + echo ' |
|
86 | 86 | <span class="csv-report-notice__wrapper"> |
87 | 87 | <span class="dashicons dashicons-info"></span> |
88 | 88 | <span class="csv-report-notice__text"> |
89 | 89 | ' . esc_html('All Registration CSV Reports are now triggered by the preceding button') . ' |
90 | 90 | </span> |
91 | 91 | </span>'; |
92 | - } |
|
92 | + } |
|
93 | 93 | } |
@@ -22,64 +22,64 @@ |
||
22 | 22 | */ |
23 | 23 | class TicketFilterHeader extends AdminPageHeaderDecorator |
24 | 24 | { |
25 | - /** |
|
26 | - * @var EEM_Ticket $ticket_model |
|
27 | - */ |
|
28 | - private $ticket_model; |
|
25 | + /** |
|
26 | + * @var EEM_Ticket $ticket_model |
|
27 | + */ |
|
28 | + private $ticket_model; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * TicketFilterHeader constructor. |
|
33 | - * |
|
34 | - * @param RequestInterface $request |
|
35 | - * @param EEM_Ticket $ticket_model |
|
36 | - */ |
|
37 | - public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
38 | - { |
|
39 | - parent::__construct($request); |
|
40 | - $this->ticket_model = $ticket_model; |
|
41 | - } |
|
31 | + /** |
|
32 | + * TicketFilterHeader constructor. |
|
33 | + * |
|
34 | + * @param RequestInterface $request |
|
35 | + * @param EEM_Ticket $ticket_model |
|
36 | + */ |
|
37 | + public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
38 | + { |
|
39 | + parent::__construct($request); |
|
40 | + $this->ticket_model = $ticket_model; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param string $text |
|
46 | - * @return string |
|
47 | - * @throws EE_Error |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws ReflectionException |
|
52 | - * @since 4.10.2.p |
|
53 | - */ |
|
54 | - public function getHeaderText($text = '') |
|
55 | - { |
|
56 | - $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
57 | - $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int'); |
|
58 | - if ($TKT_ID) { |
|
59 | - $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
60 | - if ($ticket instanceof EE_Ticket) { |
|
61 | - $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | - $ticket_details .= ! $ticket->is_free() |
|
63 | - ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | - : '<span class="reg-overview-free-event-spn">' |
|
65 | - . esc_html__('free', 'event_espresso') |
|
66 | - . '</span>'; |
|
67 | - // remove the closing h3 heading tag if it exists |
|
68 | - $text = str_replace( |
|
69 | - '</h3>', |
|
70 | - '', |
|
71 | - $text |
|
72 | - ); |
|
73 | - if (empty($text)) { |
|
74 | - $text = '<h3 class="ee-filter-header__text">'; |
|
75 | - $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
76 | - } |
|
77 | - $text .= ' '; |
|
78 | - $text .= '<span class="ee-filter-header__details">'; |
|
79 | - $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
80 | - $text .= $ticket_details . '</span></h3>'; |
|
81 | - } |
|
82 | - } |
|
83 | - return $text; |
|
84 | - } |
|
44 | + /** |
|
45 | + * @param string $text |
|
46 | + * @return string |
|
47 | + * @throws EE_Error |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws ReflectionException |
|
52 | + * @since 4.10.2.p |
|
53 | + */ |
|
54 | + public function getHeaderText($text = '') |
|
55 | + { |
|
56 | + $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
57 | + $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int'); |
|
58 | + if ($TKT_ID) { |
|
59 | + $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
60 | + if ($ticket instanceof EE_Ticket) { |
|
61 | + $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
62 | + $ticket_details .= ! $ticket->is_free() |
|
63 | + ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
64 | + : '<span class="reg-overview-free-event-spn">' |
|
65 | + . esc_html__('free', 'event_espresso') |
|
66 | + . '</span>'; |
|
67 | + // remove the closing h3 heading tag if it exists |
|
68 | + $text = str_replace( |
|
69 | + '</h3>', |
|
70 | + '', |
|
71 | + $text |
|
72 | + ); |
|
73 | + if (empty($text)) { |
|
74 | + $text = '<h3 class="ee-filter-header__text">'; |
|
75 | + $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
76 | + } |
|
77 | + $text .= ' '; |
|
78 | + $text .= '<span class="ee-filter-header__details">'; |
|
79 | + $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
80 | + $text .= $ticket_details . '</span></h3>'; |
|
81 | + } |
|
82 | + } |
|
83 | + return $text; |
|
84 | + } |
|
85 | 85 | } |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | if ($TKT_ID) { |
59 | 59 | $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
60 | 60 | if ($ticket instanceof EE_Ticket) { |
61 | - $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
61 | + $ticket_details = '<span class="ee-ticket-name">'.$ticket->name().'</span> '; |
|
62 | 62 | $ticket_details .= ! $ticket->is_free() |
63 | - ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
63 | + ? '<span class="ee-ticket-price">'.$ticket->pretty_price().'</span>' |
|
64 | 64 | : '<span class="reg-overview-free-event-spn">' |
65 | 65 | . esc_html__('free', 'event_espresso') |
66 | 66 | . '</span>'; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $text .= ' '; |
78 | 78 | $text .= '<span class="ee-filter-header__details">'; |
79 | 79 | $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
80 | - $text .= $ticket_details . '</span></h3>'; |
|
80 | + $text .= $ticket_details.'</span></h3>'; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | return $text; |
@@ -22,57 +22,57 @@ |
||
22 | 22 | */ |
23 | 23 | class DateFilterHeader extends AdminPageHeaderDecorator |
24 | 24 | { |
25 | - /** |
|
26 | - * @var EEM_Datetime $datetime_model |
|
27 | - */ |
|
28 | - private $datetime_model; |
|
25 | + /** |
|
26 | + * @var EEM_Datetime $datetime_model |
|
27 | + */ |
|
28 | + private $datetime_model; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * DateFilterHeader constructor. |
|
33 | - * |
|
34 | - * @param RequestInterface $request |
|
35 | - * @param EEM_Datetime $datetime_model |
|
36 | - */ |
|
37 | - public function __construct(RequestInterface $request, EEM_Datetime $datetime_model) |
|
38 | - { |
|
39 | - parent::__construct($request); |
|
40 | - $this->datetime_model = $datetime_model; |
|
41 | - } |
|
31 | + /** |
|
32 | + * DateFilterHeader constructor. |
|
33 | + * |
|
34 | + * @param RequestInterface $request |
|
35 | + * @param EEM_Datetime $datetime_model |
|
36 | + */ |
|
37 | + public function __construct(RequestInterface $request, EEM_Datetime $datetime_model) |
|
38 | + { |
|
39 | + parent::__construct($request); |
|
40 | + $this->datetime_model = $datetime_model; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param string $text |
|
46 | - * @return string |
|
47 | - * @throws EE_Error |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws ReflectionException |
|
52 | - * @since 4.10.2.p |
|
53 | - */ |
|
54 | - public function getHeaderText($text = '') |
|
55 | - { |
|
56 | - $DTT_ID = $this->request->getRequestParam('DTT_ID'); |
|
57 | - $DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID, 'int'); |
|
58 | - if ($DTT_ID) { |
|
59 | - $datetime = $this->datetime_model->get_one_by_ID($DTT_ID); |
|
60 | - if ($datetime instanceof EE_Datetime && $text !== '') { |
|
61 | - // remove the closing h3 heading tag if it exists |
|
62 | - $text = str_replace( |
|
63 | - '</h3>', |
|
64 | - '', |
|
65 | - $text |
|
66 | - ); |
|
67 | - $text .= ' '; |
|
68 | - $text .= '<span class="ee-filter-header__details">'; |
|
69 | - $text .= '<span class="dashicons dashicons-calendar"></span>'; |
|
70 | - $text .= $datetime->name(); |
|
71 | - $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
72 | - $text .= '</span></h3>'; |
|
73 | - } |
|
74 | - } |
|
44 | + /** |
|
45 | + * @param string $text |
|
46 | + * @return string |
|
47 | + * @throws EE_Error |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws ReflectionException |
|
52 | + * @since 4.10.2.p |
|
53 | + */ |
|
54 | + public function getHeaderText($text = '') |
|
55 | + { |
|
56 | + $DTT_ID = $this->request->getRequestParam('DTT_ID'); |
|
57 | + $DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID, 'int'); |
|
58 | + if ($DTT_ID) { |
|
59 | + $datetime = $this->datetime_model->get_one_by_ID($DTT_ID); |
|
60 | + if ($datetime instanceof EE_Datetime && $text !== '') { |
|
61 | + // remove the closing h3 heading tag if it exists |
|
62 | + $text = str_replace( |
|
63 | + '</h3>', |
|
64 | + '', |
|
65 | + $text |
|
66 | + ); |
|
67 | + $text .= ' '; |
|
68 | + $text .= '<span class="ee-filter-header__details">'; |
|
69 | + $text .= '<span class="dashicons dashicons-calendar"></span>'; |
|
70 | + $text .= $datetime->name(); |
|
71 | + $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
72 | + $text .= '</span></h3>'; |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - return $text; |
|
77 | - } |
|
76 | + return $text; |
|
77 | + } |
|
78 | 78 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | $text .= '<span class="ee-filter-header__details">'; |
69 | 69 | $text .= '<span class="dashicons dashicons-calendar"></span>'; |
70 | 70 | $text .= $datetime->name(); |
71 | - $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
71 | + $text .= ' ( '.$datetime->start_date().' )'; |
|
72 | 72 | $text .= '</span></h3>'; |
73 | 73 | } |
74 | 74 | } |