@@ -19,54 +19,54 @@ |
||
19 | 19 | class Domain extends DomainBase implements CaffeinatedInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * URL path component used to denote an API request |
|
24 | - */ |
|
25 | - const API_NAMESPACE = 'ee/v'; |
|
22 | + /** |
|
23 | + * URL path component used to denote an API request |
|
24 | + */ |
|
25 | + const API_NAMESPACE = 'ee/v'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
29 | - * Page ui. |
|
30 | - */ |
|
31 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN |
|
32 | - = 'manual_registration_status_change_from_registration_admin'; |
|
27 | + /** |
|
28 | + * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin |
|
29 | + * Page ui. |
|
30 | + */ |
|
31 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN |
|
32 | + = 'manual_registration_status_change_from_registration_admin'; |
|
33 | 33 | |
34 | - const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
35 | - = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
34 | + const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
35 | + = 'manual_registration_status_change_from_registration_admin_and_notify'; |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * Whether or not EE core is the full premium version. |
|
40 | - * @since $VID:$ |
|
41 | - * @var bool |
|
42 | - */ |
|
43 | - private $caffeinated; |
|
38 | + /** |
|
39 | + * Whether or not EE core is the full premium version. |
|
40 | + * @since $VID:$ |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | + private $caffeinated; |
|
44 | 44 | |
45 | 45 | |
46 | - public function __construct(FilePath $plugin_file, Version $version) |
|
47 | - { |
|
48 | - parent::__construct($plugin_file, $version); |
|
49 | - $this->setCaffeinated(); |
|
50 | - } |
|
46 | + public function __construct(FilePath $plugin_file, Version $version) |
|
47 | + { |
|
48 | + parent::__construct($plugin_file, $version); |
|
49 | + $this->setCaffeinated(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Whether or not EE core is the full premium version. |
|
54 | - * @since $VID:$ |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function isCaffeinated() |
|
58 | - { |
|
59 | - return $this->caffeinated; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Whether or not EE core is the full premium version. |
|
54 | + * @since $VID:$ |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function isCaffeinated() |
|
58 | + { |
|
59 | + return $this->caffeinated; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * Setter for $is_caffeinated property. |
|
65 | - * @since $VID:$ |
|
66 | - */ |
|
67 | - private function setCaffeinated() |
|
68 | - { |
|
69 | - $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | - && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
71 | - } |
|
63 | + /** |
|
64 | + * Setter for $is_caffeinated property. |
|
65 | + * @since $VID:$ |
|
66 | + */ |
|
67 | + private function setCaffeinated() |
|
68 | + { |
|
69 | + $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | + && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
71 | + } |
|
72 | 72 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | */ |
67 | 67 | private function setCaffeinated() |
68 | 68 | { |
69 | - $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | - && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php'); |
|
69 | + $this->caffeinated = ( ! defined('EE_DECAF') || EE_DECAF !== true) |
|
70 | + && is_readable($this->pluginPath().'caffeinated/brewing_regular.php'); |
|
71 | 71 | } |
72 | 72 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | EE_Maintenance_Mode $maintenance_mode = null |
149 | 149 | ) { |
150 | 150 | // check if class object is instantiated |
151 | - if (! self::$_instance instanceof EE_System) { |
|
151 | + if ( ! self::$_instance instanceof EE_System) { |
|
152 | 152 | self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
153 | 153 | } |
154 | 154 | return self::$_instance; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
268 | 268 | add_action( |
269 | 269 | 'AHEE__EE_Capabilities__init_caps__before_initialization', |
270 | - function () |
|
270 | + function() |
|
271 | 271 | { |
272 | 272 | LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
273 | 273 | } |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | { |
312 | 312 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
313 | 313 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
314 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
314 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
315 | 315 | $this->loader->getShared('EE_Request_Handler'); |
316 | 316 | } |
317 | 317 | |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | $load_callback, |
332 | 332 | $plugin_file_constant |
333 | 333 | ) { |
334 | - if (! defined($version_constant)) { |
|
334 | + if ( ! defined($version_constant)) { |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | $addon_version = constant($version_constant); |
338 | 338 | if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
339 | 339 | remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
340 | - if (! function_exists('deactivate_plugins')) { |
|
341 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
340 | + if ( ! function_exists('deactivate_plugins')) { |
|
341 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
342 | 342 | } |
343 | 343 | deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
344 | 344 | unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $addon_name, |
352 | 352 | $min_version_required |
353 | 353 | ), |
354 | - __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__ |
|
354 | + __FILE__, __FUNCTION__."({$addon_name})", __LINE__ |
|
355 | 355 | ); |
356 | 356 | EE_Error::get_notices(false, true); |
357 | 357 | } |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | true |
402 | 402 | ) |
403 | 403 | ) { |
404 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
404 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
405 | 405 | } |
406 | 406 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
407 | 407 | } |
@@ -508,11 +508,11 @@ discard block |
||
508 | 508 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
509 | 509 | { |
510 | 510 | do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
511 | - if (! $espresso_db_update) { |
|
511 | + if ( ! $espresso_db_update) { |
|
512 | 512 | $espresso_db_update = get_option('espresso_db_update'); |
513 | 513 | } |
514 | 514 | // check that option is an array |
515 | - if (! is_array($espresso_db_update)) { |
|
515 | + if ( ! is_array($espresso_db_update)) { |
|
516 | 516 | // if option is FALSE, then it never existed |
517 | 517 | if ($espresso_db_update === false) { |
518 | 518 | // make $espresso_db_update an array and save option with autoload OFF |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | //so it must be numerically-indexed, where values are versions installed... |
533 | 533 | //fix it! |
534 | 534 | $version_string = $should_be_array; |
535 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
535 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
536 | 536 | } else { |
537 | 537 | //ok it checks out |
538 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
538 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
539 | 539 | } |
540 | 540 | } |
541 | 541 | $espresso_db_update = $corrected_db_update; |
@@ -617,13 +617,13 @@ discard block |
||
617 | 617 | */ |
618 | 618 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
619 | 619 | { |
620 | - if (! $version_history) { |
|
620 | + if ( ! $version_history) { |
|
621 | 621 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
622 | 622 | } |
623 | 623 | if ($current_version_to_add === null) { |
624 | 624 | $current_version_to_add = espresso_version(); |
625 | 625 | } |
626 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
626 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
627 | 627 | // re-save |
628 | 628 | return update_option('espresso_db_update', $version_history); |
629 | 629 | } |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | if ($activation_history_for_addon) { |
717 | 717 | //it exists, so this isn't a completely new install |
718 | 718 | //check if this version already in that list of previously installed versions |
719 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
719 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
720 | 720 | //it a version we haven't seen before |
721 | 721 | if ($version_is_higher === 1) { |
722 | 722 | $req_type = EE_System::req_type_upgrade; |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | foreach ($activation_history as $version => $times_activated) { |
797 | 797 | //check there is a record of when this version was activated. Otherwise, |
798 | 798 | //mark it as unknown |
799 | - if (! $times_activated) { |
|
799 | + if ( ! $times_activated) { |
|
800 | 800 | $times_activated = array('unknown-date'); |
801 | 801 | } |
802 | 802 | if (is_string($times_activated)) { |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | private function _parse_model_names() |
898 | 898 | { |
899 | 899 | //get all the files in the EE_MODELS folder that end in .model.php |
900 | - $models = glob(EE_MODELS . '*.model.php'); |
|
900 | + $models = glob(EE_MODELS.'*.model.php'); |
|
901 | 901 | $model_names = array(); |
902 | 902 | $non_abstract_db_models = array(); |
903 | 903 | foreach ($models as $model) { |
@@ -906,9 +906,9 @@ discard block |
||
906 | 906 | $short_name = str_replace('EEM_', '', $classname); |
907 | 907 | $reflectionClass = new ReflectionClass($classname); |
908 | 908 | if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
909 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
909 | + $non_abstract_db_models[$short_name] = $classname; |
|
910 | 910 | } |
911 | - $model_names[ $short_name ] = $classname; |
|
911 | + $model_names[$short_name] = $classname; |
|
912 | 912 | } |
913 | 913 | $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
914 | 914 | $this->registry->non_abstract_db_models = apply_filters( |
@@ -943,7 +943,7 @@ discard block |
||
943 | 943 | ) |
944 | 944 | ); |
945 | 945 | if ($domain->isCaffeinated()) { |
946 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
946 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
947 | 947 | } |
948 | 948 | } |
949 | 949 | |
@@ -996,17 +996,17 @@ discard block |
||
996 | 996 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
997 | 997 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
998 | 998 | ); |
999 | - if (! empty($class_names)) { |
|
999 | + if ( ! empty($class_names)) { |
|
1000 | 1000 | $msg = __( |
1001 | 1001 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
1002 | 1002 | 'event_espresso' |
1003 | 1003 | ); |
1004 | 1004 | $msg .= '<ul>'; |
1005 | 1005 | foreach ($class_names as $class_name) { |
1006 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
1006 | + $msg .= '<li><b>Event Espresso - '.str_replace( |
|
1007 | 1007 | array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
1008 | 1008 | $class_name |
1009 | - ) . '</b></li>'; |
|
1009 | + ).'</b></li>'; |
|
1010 | 1010 | } |
1011 | 1011 | $msg .= '</ul>'; |
1012 | 1012 | $msg .= __( |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | private function _deactivate_incompatible_addons() |
1078 | 1078 | { |
1079 | 1079 | $incompatible_addons = get_option('ee_incompatible_addons', array()); |
1080 | - if (! empty($incompatible_addons)) { |
|
1080 | + if ( ! empty($incompatible_addons)) { |
|
1081 | 1081 | $active_plugins = get_option('active_plugins', array()); |
1082 | 1082 | foreach ($active_plugins as $active_plugin) { |
1083 | 1083 | foreach ($incompatible_addons as $incompatible_addon) { |
@@ -1172,10 +1172,10 @@ discard block |
||
1172 | 1172 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
1173 | 1173 | // load_espresso_template_tags |
1174 | 1174 | if ( |
1175 | - is_readable(EE_PUBLIC . 'template_tags.php') |
|
1175 | + is_readable(EE_PUBLIC.'template_tags.php') |
|
1176 | 1176 | && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed()) |
1177 | 1177 | ) { |
1178 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
1178 | + require_once EE_PUBLIC.'template_tags.php'; |
|
1179 | 1179 | } |
1180 | 1180 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
1181 | 1181 | if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) { |
@@ -1239,13 +1239,13 @@ discard block |
||
1239 | 1239 | public static function do_not_cache() |
1240 | 1240 | { |
1241 | 1241 | // set no cache constants |
1242 | - if (! defined('DONOTCACHEPAGE')) { |
|
1242 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1243 | 1243 | define('DONOTCACHEPAGE', true); |
1244 | 1244 | } |
1245 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1245 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1246 | 1246 | define('DONOTCACHCEOBJECT', true); |
1247 | 1247 | } |
1248 | - if (! defined('DONOTCACHEDB')) { |
|
1248 | + if ( ! defined('DONOTCACHEDB')) { |
|
1249 | 1249 | define('DONOTCACHEDB', true); |
1250 | 1250 | } |
1251 | 1251 | // add no cache headers |
@@ -32,1271 +32,1271 @@ |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
37 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
38 | - */ |
|
39 | - const req_type_normal = 0; |
|
40 | - |
|
41 | - /** |
|
42 | - * Indicates this is a brand new installation of EE so we should install |
|
43 | - * tables and default data etc |
|
44 | - */ |
|
45 | - const req_type_new_activation = 1; |
|
46 | - |
|
47 | - /** |
|
48 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
49 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
50 | - * and that default data is setup too |
|
51 | - */ |
|
52 | - const req_type_reactivation = 2; |
|
53 | - |
|
54 | - /** |
|
55 | - * indicates that EE has been upgraded since its previous request. |
|
56 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
57 | - */ |
|
58 | - const req_type_upgrade = 3; |
|
59 | - |
|
60 | - /** |
|
61 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
62 | - */ |
|
63 | - const req_type_downgrade = 4; |
|
64 | - |
|
65 | - /** |
|
66 | - * @deprecated since version 4.6.0.dev.006 |
|
67 | - * Now whenever a new_activation is detected the request type is still just |
|
68 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
69 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
70 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
71 | - * (Specifically, when the migration manager indicates migrations are finished |
|
72 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
73 | - */ |
|
74 | - const req_type_activation_but_not_installed = 5; |
|
75 | - |
|
76 | - /** |
|
77 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
78 | - */ |
|
79 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @var EE_System $_instance |
|
84 | - */ |
|
85 | - private static $_instance; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var EE_Registry $registry |
|
89 | - */ |
|
90 | - private $registry; |
|
91 | - |
|
92 | - /** |
|
93 | - * @var LoaderInterface $loader |
|
94 | - */ |
|
95 | - private $loader; |
|
96 | - |
|
97 | - /** |
|
98 | - * @var EE_Capabilities $capabilities |
|
99 | - */ |
|
100 | - private $capabilities; |
|
101 | - |
|
102 | - /** |
|
103 | - * @var RequestInterface $request |
|
104 | - */ |
|
105 | - private $request; |
|
106 | - |
|
107 | - /** |
|
108 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
109 | - */ |
|
110 | - private $maintenance_mode; |
|
111 | - |
|
112 | - /** |
|
113 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
114 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
115 | - * |
|
116 | - * @var int $_req_type |
|
117 | - */ |
|
118 | - private $_req_type; |
|
119 | - |
|
120 | - /** |
|
121 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
122 | - * |
|
123 | - * @var boolean $_major_version_change |
|
124 | - */ |
|
125 | - private $_major_version_change = false; |
|
126 | - |
|
127 | - /** |
|
128 | - * A Context DTO dedicated solely to identifying the current request type. |
|
129 | - * |
|
130 | - * @var RequestTypeContextCheckerInterface $request_type |
|
131 | - */ |
|
132 | - private $request_type; |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @singleton method used to instantiate class object |
|
138 | - * @param EE_Registry|null $registry |
|
139 | - * @param LoaderInterface|null $loader |
|
140 | - * @param RequestInterface|null $request |
|
141 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
142 | - * @return EE_System |
|
143 | - */ |
|
144 | - public static function instance( |
|
145 | - EE_Registry $registry = null, |
|
146 | - LoaderInterface $loader = null, |
|
147 | - RequestInterface $request = null, |
|
148 | - EE_Maintenance_Mode $maintenance_mode = null |
|
149 | - ) { |
|
150 | - // check if class object is instantiated |
|
151 | - if (! self::$_instance instanceof EE_System) { |
|
152 | - self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
153 | - } |
|
154 | - return self::$_instance; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * resets the instance and returns it |
|
161 | - * |
|
162 | - * @return EE_System |
|
163 | - */ |
|
164 | - public static function reset() |
|
165 | - { |
|
166 | - self::$_instance->_req_type = null; |
|
167 | - //make sure none of the old hooks are left hanging around |
|
168 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
169 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
170 | - EE_Data_Migration_Manager::reset(); |
|
171 | - self::instance()->detect_activations_or_upgrades(); |
|
172 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
173 | - return self::instance(); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * sets hooks for running rest of system |
|
180 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
181 | - * starting EE Addons from any other point may lead to problems |
|
182 | - * |
|
183 | - * @param EE_Registry $registry |
|
184 | - * @param LoaderInterface $loader |
|
185 | - * @param RequestInterface $request |
|
186 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
187 | - */ |
|
188 | - private function __construct( |
|
189 | - EE_Registry $registry, |
|
190 | - LoaderInterface $loader, |
|
191 | - RequestInterface $request, |
|
192 | - EE_Maintenance_Mode $maintenance_mode |
|
193 | - ) { |
|
194 | - $this->registry = $registry; |
|
195 | - $this->loader = $loader; |
|
196 | - $this->request = $request; |
|
197 | - $this->maintenance_mode = $maintenance_mode; |
|
198 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
199 | - add_action( |
|
200 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
201 | - array($this, 'loadCapabilities'), |
|
202 | - 5 |
|
203 | - ); |
|
204 | - add_action( |
|
205 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
206 | - array($this, 'loadCommandBus'), |
|
207 | - 7 |
|
208 | - ); |
|
209 | - add_action( |
|
210 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
211 | - array($this, 'loadPluginApi'), |
|
212 | - 9 |
|
213 | - ); |
|
214 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
215 | - add_action( |
|
216 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
217 | - array($this, 'load_espresso_addons') |
|
218 | - ); |
|
219 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
220 | - // because the newly-activated addon didn't get a chance to run at all |
|
221 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
222 | - // detect whether install or upgrade |
|
223 | - add_action( |
|
224 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
225 | - array($this, 'detect_activations_or_upgrades'), |
|
226 | - 3 |
|
227 | - ); |
|
228 | - // load EE_Config, EE_Textdomain, etc |
|
229 | - add_action( |
|
230 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
231 | - array($this, 'load_core_configuration'), |
|
232 | - 5 |
|
233 | - ); |
|
234 | - // load EE_Config, EE_Textdomain, etc |
|
235 | - add_action( |
|
236 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
237 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
238 | - 7 |
|
239 | - ); |
|
240 | - // you wanna get going? I wanna get going... let's get going! |
|
241 | - add_action( |
|
242 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
243 | - array($this, 'brew_espresso'), |
|
244 | - 9 |
|
245 | - ); |
|
246 | - //other housekeeping |
|
247 | - //exclude EE critical pages from wp_list_pages |
|
248 | - add_filter( |
|
249 | - 'wp_list_pages_excludes', |
|
250 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
251 | - 10 |
|
252 | - ); |
|
253 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
254 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
255 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * load and setup EE_Capabilities |
|
261 | - * |
|
262 | - * @return void |
|
263 | - * @throws EE_Error |
|
264 | - */ |
|
265 | - public function loadCapabilities() |
|
266 | - { |
|
267 | - $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
268 | - add_action( |
|
269 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
270 | - function () |
|
271 | - { |
|
272 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
273 | - } |
|
274 | - ); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * create and cache the CommandBus, and also add middleware |
|
281 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
282 | - * which is why we need to load the CommandBus after Caps are set up |
|
283 | - * |
|
284 | - * @return void |
|
285 | - * @throws EE_Error |
|
286 | - */ |
|
287 | - public function loadCommandBus() |
|
288 | - { |
|
289 | - $this->loader->getShared( |
|
290 | - 'CommandBusInterface', |
|
291 | - array( |
|
292 | - null, |
|
293 | - apply_filters( |
|
294 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
295 | - array( |
|
296 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
297 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
298 | - ) |
|
299 | - ), |
|
300 | - ) |
|
301 | - ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * @return void |
|
308 | - * @throws EE_Error |
|
309 | - */ |
|
310 | - public function loadPluginApi() |
|
311 | - { |
|
312 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
313 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
314 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
315 | - $this->loader->getShared('EE_Request_Handler'); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * @param string $addon_name |
|
321 | - * @param string $version_constant |
|
322 | - * @param string $min_version_required |
|
323 | - * @param string $load_callback |
|
324 | - * @param string $plugin_file_constant |
|
325 | - * @return void |
|
326 | - */ |
|
327 | - private function deactivateIncompatibleAddon( |
|
328 | - $addon_name, |
|
329 | - $version_constant, |
|
330 | - $min_version_required, |
|
331 | - $load_callback, |
|
332 | - $plugin_file_constant |
|
333 | - ) { |
|
334 | - if (! defined($version_constant)) { |
|
335 | - return; |
|
336 | - } |
|
337 | - $addon_version = constant($version_constant); |
|
338 | - if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
339 | - remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
340 | - if (! function_exists('deactivate_plugins')) { |
|
341 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
342 | - } |
|
343 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
344 | - unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
345 | - EE_Error::add_error( |
|
346 | - sprintf( |
|
347 | - esc_html__( |
|
348 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
349 | - 'event_espresso' |
|
350 | - ), |
|
351 | - $addon_name, |
|
352 | - $min_version_required |
|
353 | - ), |
|
354 | - __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__ |
|
355 | - ); |
|
356 | - EE_Error::get_notices(false, true); |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * load_espresso_addons |
|
363 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
364 | - * this is hooked into both: |
|
365 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
366 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
367 | - * and the WP 'activate_plugin' hook point |
|
368 | - * |
|
369 | - * @access public |
|
370 | - * @return void |
|
371 | - */ |
|
372 | - public function load_espresso_addons() |
|
373 | - { |
|
374 | - $this->deactivateIncompatibleAddon( |
|
375 | - 'Wait Lists', |
|
376 | - 'EE_WAIT_LISTS_VERSION', |
|
377 | - '1.0.0.beta.074', |
|
378 | - 'load_espresso_wait_lists', |
|
379 | - 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
380 | - ); |
|
381 | - $this->deactivateIncompatibleAddon( |
|
382 | - 'Automated Upcoming Event Notifications', |
|
383 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
384 | - '1.0.0.beta.091', |
|
385 | - 'load_espresso_automated_upcoming_event_notification', |
|
386 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
387 | - ); |
|
388 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
389 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
390 | - //We want it for mobile apps. Just include the entire plugin |
|
391 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
392 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
393 | - //and causes a fatal error |
|
394 | - if ( |
|
395 | - $this->request->getRequestParam('activate') !== 'true' |
|
396 | - && ! function_exists('json_basic_auth_handler') |
|
397 | - && ! function_exists('json_basic_auth_error') |
|
398 | - && ! in_array( |
|
399 | - $this->request->getRequestParam('action'), |
|
400 | - array('activate', 'activate-selected'), |
|
401 | - true |
|
402 | - ) |
|
403 | - ) { |
|
404 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
405 | - } |
|
406 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * detect_activations_or_upgrades |
|
413 | - * Checks for activation or upgrade of core first; |
|
414 | - * then also checks if any registered addons have been activated or upgraded |
|
415 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
416 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
417 | - * |
|
418 | - * @access public |
|
419 | - * @return void |
|
420 | - */ |
|
421 | - public function detect_activations_or_upgrades() |
|
422 | - { |
|
423 | - //first off: let's make sure to handle core |
|
424 | - $this->detect_if_activation_or_upgrade(); |
|
425 | - foreach ($this->registry->addons as $addon) { |
|
426 | - if ($addon instanceof EE_Addon) { |
|
427 | - //detect teh request type for that addon |
|
428 | - $addon->detect_activation_or_upgrade(); |
|
429 | - } |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * detect_if_activation_or_upgrade |
|
437 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
438 | - * and either setting up the DB or setting up maintenance mode etc. |
|
439 | - * |
|
440 | - * @access public |
|
441 | - * @return void |
|
442 | - */ |
|
443 | - public function detect_if_activation_or_upgrade() |
|
444 | - { |
|
445 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
446 | - // check if db has been updated, or if its a brand-new installation |
|
447 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
448 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
449 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
450 | - switch ($request_type) { |
|
451 | - case EE_System::req_type_new_activation: |
|
452 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
453 | - $this->_handle_core_version_change($espresso_db_update); |
|
454 | - break; |
|
455 | - case EE_System::req_type_reactivation: |
|
456 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
457 | - $this->_handle_core_version_change($espresso_db_update); |
|
458 | - break; |
|
459 | - case EE_System::req_type_upgrade: |
|
460 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
461 | - //migrations may be required now that we've upgraded |
|
462 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
463 | - $this->_handle_core_version_change($espresso_db_update); |
|
464 | - // echo "done upgrade";die; |
|
465 | - break; |
|
466 | - case EE_System::req_type_downgrade: |
|
467 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
468 | - //its possible migrations are no longer required |
|
469 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
470 | - $this->_handle_core_version_change($espresso_db_update); |
|
471 | - break; |
|
472 | - case EE_System::req_type_normal: |
|
473 | - default: |
|
474 | - break; |
|
475 | - } |
|
476 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Updates the list of installed versions and sets hooks for |
|
483 | - * initializing the database later during the request |
|
484 | - * |
|
485 | - * @param array $espresso_db_update |
|
486 | - */ |
|
487 | - private function _handle_core_version_change($espresso_db_update) |
|
488 | - { |
|
489 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
490 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
491 | - add_action( |
|
492 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
493 | - array($this, 'initialize_db_if_no_migrations_required') |
|
494 | - ); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
501 | - * information about what versions of EE have been installed and activated, |
|
502 | - * NOT necessarily the state of the database |
|
503 | - * |
|
504 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
505 | - * If not supplied, fetches it from the options table |
|
506 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
507 | - */ |
|
508 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
509 | - { |
|
510 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
511 | - if (! $espresso_db_update) { |
|
512 | - $espresso_db_update = get_option('espresso_db_update'); |
|
513 | - } |
|
514 | - // check that option is an array |
|
515 | - if (! is_array($espresso_db_update)) { |
|
516 | - // if option is FALSE, then it never existed |
|
517 | - if ($espresso_db_update === false) { |
|
518 | - // make $espresso_db_update an array and save option with autoload OFF |
|
519 | - $espresso_db_update = array(); |
|
520 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
521 | - } else { |
|
522 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
523 | - $espresso_db_update = array($espresso_db_update => array()); |
|
524 | - update_option('espresso_db_update', $espresso_db_update); |
|
525 | - } |
|
526 | - } else { |
|
527 | - $corrected_db_update = array(); |
|
528 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
529 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
530 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
531 | - //the key is an int, and the value IS NOT an array |
|
532 | - //so it must be numerically-indexed, where values are versions installed... |
|
533 | - //fix it! |
|
534 | - $version_string = $should_be_array; |
|
535 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
536 | - } else { |
|
537 | - //ok it checks out |
|
538 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
539 | - } |
|
540 | - } |
|
541 | - $espresso_db_update = $corrected_db_update; |
|
542 | - update_option('espresso_db_update', $espresso_db_update); |
|
543 | - } |
|
544 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
545 | - return $espresso_db_update; |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
552 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
553 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
554 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
555 | - * so that it will be done when migrations are finished |
|
556 | - * |
|
557 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
558 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
559 | - * This is a resource-intensive job |
|
560 | - * so we prefer to only do it when necessary |
|
561 | - * @return void |
|
562 | - * @throws EE_Error |
|
563 | - */ |
|
564 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
565 | - { |
|
566 | - $request_type = $this->detect_req_type(); |
|
567 | - //only initialize system if we're not in maintenance mode. |
|
568 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
569 | - update_option('ee_flush_rewrite_rules', true); |
|
570 | - if ($verify_schema) { |
|
571 | - EEH_Activation::initialize_db_and_folders(); |
|
572 | - } |
|
573 | - EEH_Activation::initialize_db_content(); |
|
574 | - EEH_Activation::system_initialization(); |
|
575 | - if ($initialize_addons_too) { |
|
576 | - $this->initialize_addons(); |
|
577 | - } |
|
578 | - } else { |
|
579 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
580 | - } |
|
581 | - if ($request_type === EE_System::req_type_new_activation |
|
582 | - || $request_type === EE_System::req_type_reactivation |
|
583 | - || ( |
|
584 | - $request_type === EE_System::req_type_upgrade |
|
585 | - && $this->is_major_version_change() |
|
586 | - ) |
|
587 | - ) { |
|
588 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Initializes the db for all registered addons |
|
596 | - * |
|
597 | - * @throws EE_Error |
|
598 | - */ |
|
599 | - public function initialize_addons() |
|
600 | - { |
|
601 | - //foreach registered addon, make sure its db is up-to-date too |
|
602 | - foreach ($this->registry->addons as $addon) { |
|
603 | - if ($addon instanceof EE_Addon) { |
|
604 | - $addon->initialize_db_if_no_migrations_required(); |
|
605 | - } |
|
606 | - } |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
613 | - * |
|
614 | - * @param array $version_history |
|
615 | - * @param string $current_version_to_add version to be added to the version history |
|
616 | - * @return boolean success as to whether or not this option was changed |
|
617 | - */ |
|
618 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
619 | - { |
|
620 | - if (! $version_history) { |
|
621 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
622 | - } |
|
623 | - if ($current_version_to_add === null) { |
|
624 | - $current_version_to_add = espresso_version(); |
|
625 | - } |
|
626 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
627 | - // re-save |
|
628 | - return update_option('espresso_db_update', $version_history); |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * Detects if the current version indicated in the has existed in the list of |
|
635 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
636 | - * |
|
637 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
638 | - * If not supplied, fetches it from the options table. |
|
639 | - * Also, caches its result so later parts of the code can also know whether |
|
640 | - * there's been an update or not. This way we can add the current version to |
|
641 | - * espresso_db_update, but still know if this is a new install or not |
|
642 | - * @return int one of the constants on EE_System::req_type_ |
|
643 | - */ |
|
644 | - public function detect_req_type($espresso_db_update = null) |
|
645 | - { |
|
646 | - if ($this->_req_type === null) { |
|
647 | - $espresso_db_update = ! empty($espresso_db_update) |
|
648 | - ? $espresso_db_update |
|
649 | - : $this->fix_espresso_db_upgrade_option(); |
|
650 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
651 | - $espresso_db_update, |
|
652 | - 'ee_espresso_activation', espresso_version() |
|
653 | - ); |
|
654 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
655 | - $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
656 | - } |
|
657 | - return $this->_req_type; |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
664 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
665 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
666 | - * |
|
667 | - * @param $activation_history |
|
668 | - * @return bool |
|
669 | - */ |
|
670 | - private function _detect_major_version_change($activation_history) |
|
671 | - { |
|
672 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
673 | - $previous_version_parts = explode('.', $previous_version); |
|
674 | - $current_version_parts = explode('.', espresso_version()); |
|
675 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
676 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
677 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
678 | - ); |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * Returns true if either the major or minor version of EE changed during this request. |
|
685 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
686 | - * |
|
687 | - * @return bool |
|
688 | - */ |
|
689 | - public function is_major_version_change() |
|
690 | - { |
|
691 | - return $this->_major_version_change; |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
698 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
699 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
700 | - * just activated to (for core that will always be espresso_version()) |
|
701 | - * |
|
702 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
703 | - * ee plugin. for core that's 'espresso_db_update' |
|
704 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
705 | - * indicate that this plugin was just activated |
|
706 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
707 | - * espresso_version()) |
|
708 | - * @return int one of the constants on EE_System::req_type_* |
|
709 | - */ |
|
710 | - public static function detect_req_type_given_activation_history( |
|
711 | - $activation_history_for_addon, |
|
712 | - $activation_indicator_option_name, |
|
713 | - $version_to_upgrade_to |
|
714 | - ) { |
|
715 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
716 | - if ($activation_history_for_addon) { |
|
717 | - //it exists, so this isn't a completely new install |
|
718 | - //check if this version already in that list of previously installed versions |
|
719 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
720 | - //it a version we haven't seen before |
|
721 | - if ($version_is_higher === 1) { |
|
722 | - $req_type = EE_System::req_type_upgrade; |
|
723 | - } else { |
|
724 | - $req_type = EE_System::req_type_downgrade; |
|
725 | - } |
|
726 | - delete_option($activation_indicator_option_name); |
|
727 | - } else { |
|
728 | - // its not an update. maybe a reactivation? |
|
729 | - if (get_option($activation_indicator_option_name, false)) { |
|
730 | - if ($version_is_higher === -1) { |
|
731 | - $req_type = EE_System::req_type_downgrade; |
|
732 | - } elseif ($version_is_higher === 0) { |
|
733 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
734 | - $req_type = EE_System::req_type_reactivation; |
|
735 | - } else {//$version_is_higher === 1 |
|
736 | - $req_type = EE_System::req_type_upgrade; |
|
737 | - } |
|
738 | - delete_option($activation_indicator_option_name); |
|
739 | - } else { |
|
740 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
741 | - if ($version_is_higher === -1) { |
|
742 | - $req_type = EE_System::req_type_downgrade; |
|
743 | - } elseif ($version_is_higher === 0) { |
|
744 | - //we've seen this version before and it's not an activation. its normal request |
|
745 | - $req_type = EE_System::req_type_normal; |
|
746 | - } else {//$version_is_higher === 1 |
|
747 | - $req_type = EE_System::req_type_upgrade; |
|
748 | - } |
|
749 | - } |
|
750 | - } |
|
751 | - } else { |
|
752 | - //brand new install |
|
753 | - $req_type = EE_System::req_type_new_activation; |
|
754 | - delete_option($activation_indicator_option_name); |
|
755 | - } |
|
756 | - return $req_type; |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
763 | - * the $activation_history_for_addon |
|
764 | - * |
|
765 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
766 | - * sometimes containing 'unknown-date' |
|
767 | - * @param string $version_to_upgrade_to (current version) |
|
768 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
769 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
770 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
771 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
772 | - */ |
|
773 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
774 | - { |
|
775 | - //find the most recently-activated version |
|
776 | - $most_recently_active_version = |
|
777 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
778 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * Gets the most recently active version listed in the activation history, |
|
785 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
786 | - * |
|
787 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
788 | - * sometimes containing 'unknown-date' |
|
789 | - * @return string |
|
790 | - */ |
|
791 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
792 | - { |
|
793 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
794 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
795 | - if (is_array($activation_history)) { |
|
796 | - foreach ($activation_history as $version => $times_activated) { |
|
797 | - //check there is a record of when this version was activated. Otherwise, |
|
798 | - //mark it as unknown |
|
799 | - if (! $times_activated) { |
|
800 | - $times_activated = array('unknown-date'); |
|
801 | - } |
|
802 | - if (is_string($times_activated)) { |
|
803 | - $times_activated = array($times_activated); |
|
804 | - } |
|
805 | - foreach ($times_activated as $an_activation) { |
|
806 | - if ($an_activation !== 'unknown-date' |
|
807 | - && $an_activation |
|
808 | - > $most_recently_active_version_activation) { |
|
809 | - $most_recently_active_version = $version; |
|
810 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
811 | - ? '1970-01-01 00:00:00' |
|
812 | - : $an_activation; |
|
813 | - } |
|
814 | - } |
|
815 | - } |
|
816 | - } |
|
817 | - return $most_recently_active_version; |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * This redirects to the about EE page after activation |
|
824 | - * |
|
825 | - * @return void |
|
826 | - */ |
|
827 | - public function redirect_to_about_ee() |
|
828 | - { |
|
829 | - $notices = EE_Error::get_notices(false); |
|
830 | - //if current user is an admin and it's not an ajax or rest request |
|
831 | - if ( |
|
832 | - ! isset($notices['errors']) |
|
833 | - && $this->request->isAdmin() |
|
834 | - && apply_filters( |
|
835 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
836 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
837 | - ) |
|
838 | - ) { |
|
839 | - $query_params = array('page' => 'espresso_about'); |
|
840 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
841 | - $query_params['new_activation'] = true; |
|
842 | - } |
|
843 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
844 | - $query_params['reactivation'] = true; |
|
845 | - } |
|
846 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
847 | - wp_safe_redirect($url); |
|
848 | - exit(); |
|
849 | - } |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * load_core_configuration |
|
856 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
857 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
858 | - * |
|
859 | - * @return void |
|
860 | - * @throws ReflectionException |
|
861 | - */ |
|
862 | - public function load_core_configuration() |
|
863 | - { |
|
864 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
865 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
866 | - //load textdomain |
|
867 | - EE_Load_Textdomain::load_textdomain(); |
|
868 | - // load and setup EE_Config and EE_Network_Config |
|
869 | - $config = $this->loader->getShared('EE_Config'); |
|
870 | - $this->loader->getShared('EE_Network_Config'); |
|
871 | - // setup autoloaders |
|
872 | - // enable logging? |
|
873 | - if ($config->admin->use_full_logging) { |
|
874 | - $this->loader->getShared('EE_Log'); |
|
875 | - } |
|
876 | - // check for activation errors |
|
877 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
878 | - if ($activation_errors) { |
|
879 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
880 | - update_option('ee_plugin_activation_errors', false); |
|
881 | - } |
|
882 | - // get model names |
|
883 | - $this->_parse_model_names(); |
|
884 | - //load caf stuff a chance to play during the activation process too. |
|
885 | - $this->_maybe_brew_regular(); |
|
886 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
887 | - } |
|
888 | - |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
893 | - * |
|
894 | - * @return void |
|
895 | - * @throws ReflectionException |
|
896 | - */ |
|
897 | - private function _parse_model_names() |
|
898 | - { |
|
899 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
900 | - $models = glob(EE_MODELS . '*.model.php'); |
|
901 | - $model_names = array(); |
|
902 | - $non_abstract_db_models = array(); |
|
903 | - foreach ($models as $model) { |
|
904 | - // get model classname |
|
905 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
906 | - $short_name = str_replace('EEM_', '', $classname); |
|
907 | - $reflectionClass = new ReflectionClass($classname); |
|
908 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
909 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
910 | - } |
|
911 | - $model_names[ $short_name ] = $classname; |
|
912 | - } |
|
913 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
914 | - $this->registry->non_abstract_db_models = apply_filters( |
|
915 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
916 | - $non_abstract_db_models |
|
917 | - ); |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
923 | - * that need to be setup before our EE_System launches. |
|
924 | - * |
|
925 | - * @return void |
|
926 | - * @throws DomainException |
|
927 | - * @throws InvalidArgumentException |
|
928 | - * @throws InvalidDataTypeException |
|
929 | - * @throws InvalidInterfaceException |
|
930 | - * @throws InvalidClassException |
|
931 | - * @throws InvalidFilePathException |
|
932 | - */ |
|
933 | - private function _maybe_brew_regular() |
|
934 | - { |
|
935 | - /** @var Domain $domain */ |
|
936 | - $domain = DomainFactory::getShared( |
|
937 | - new FullyQualifiedName( |
|
938 | - 'EventEspresso\core\domain\Domain' |
|
939 | - ), |
|
940 | - array( |
|
941 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
942 | - Version::fromString(espresso_version()) |
|
943 | - ) |
|
944 | - ); |
|
945 | - if ($domain->isCaffeinated()) { |
|
946 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
947 | - } |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - |
|
952 | - /** |
|
953 | - * register_shortcodes_modules_and_widgets |
|
954 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
955 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
956 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
957 | - * |
|
958 | - * @access public |
|
959 | - * @return void |
|
960 | - * @throws Exception |
|
961 | - */ |
|
962 | - public function register_shortcodes_modules_and_widgets() |
|
963 | - { |
|
964 | - if ($this->request->isFrontend() || $this->request->isIframe()) { |
|
965 | - try { |
|
966 | - // load, register, and add shortcodes the new way |
|
967 | - $this->loader->getShared( |
|
968 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
969 | - array( |
|
970 | - // and the old way, but we'll put it under control of the new system |
|
971 | - EE_Config::getLegacyShortcodesManager(), |
|
972 | - ) |
|
973 | - ); |
|
974 | - } catch (Exception $exception) { |
|
975 | - new ExceptionStackTraceDisplay($exception); |
|
976 | - } |
|
977 | - } |
|
978 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
979 | - // check for addons using old hook point |
|
980 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
981 | - $this->_incompatible_addon_error(); |
|
982 | - } |
|
983 | - } |
|
984 | - |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * _incompatible_addon_error |
|
989 | - * |
|
990 | - * @access public |
|
991 | - * @return void |
|
992 | - */ |
|
993 | - private function _incompatible_addon_error() |
|
994 | - { |
|
995 | - // get array of classes hooking into here |
|
996 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
997 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
998 | - ); |
|
999 | - if (! empty($class_names)) { |
|
1000 | - $msg = __( |
|
1001 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1002 | - 'event_espresso' |
|
1003 | - ); |
|
1004 | - $msg .= '<ul>'; |
|
1005 | - foreach ($class_names as $class_name) { |
|
1006 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
1007 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
1008 | - $class_name |
|
1009 | - ) . '</b></li>'; |
|
1010 | - } |
|
1011 | - $msg .= '</ul>'; |
|
1012 | - $msg .= __( |
|
1013 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1014 | - 'event_espresso' |
|
1015 | - ); |
|
1016 | - // save list of incompatible addons to wp-options for later use |
|
1017 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1018 | - if (is_admin()) { |
|
1019 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1020 | - } |
|
1021 | - } |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * brew_espresso |
|
1028 | - * begins the process of setting hooks for initializing EE in the correct order |
|
1029 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1030 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1031 | - * |
|
1032 | - * @return void |
|
1033 | - */ |
|
1034 | - public function brew_espresso() |
|
1035 | - { |
|
1036 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1037 | - // load some final core systems |
|
1038 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1039 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1040 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1041 | - add_action('init', array($this, 'load_controllers'), 7); |
|
1042 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1043 | - add_action('init', array($this, 'initialize'), 10); |
|
1044 | - add_action('init', array($this, 'initialize_last'), 100); |
|
1045 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1046 | - // pew pew pew |
|
1047 | - $this->loader->getShared('EE_PUE'); |
|
1048 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1049 | - } |
|
1050 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1051 | - } |
|
1052 | - |
|
1053 | - |
|
1054 | - |
|
1055 | - /** |
|
1056 | - * set_hooks_for_core |
|
1057 | - * |
|
1058 | - * @access public |
|
1059 | - * @return void |
|
1060 | - * @throws EE_Error |
|
1061 | - */ |
|
1062 | - public function set_hooks_for_core() |
|
1063 | - { |
|
1064 | - $this->_deactivate_incompatible_addons(); |
|
1065 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1066 | - $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1067 | - //caps need to be initialized on every request so that capability maps are set. |
|
1068 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1069 | - $this->registry->CAP->init_caps(); |
|
1070 | - } |
|
1071 | - |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1076 | - * deactivates any addons considered incompatible with the current version of EE |
|
1077 | - */ |
|
1078 | - private function _deactivate_incompatible_addons() |
|
1079 | - { |
|
1080 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1081 | - if (! empty($incompatible_addons)) { |
|
1082 | - $active_plugins = get_option('active_plugins', array()); |
|
1083 | - foreach ($active_plugins as $active_plugin) { |
|
1084 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
1085 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1086 | - unset($_GET['activate']); |
|
1087 | - espresso_deactivate_plugin($active_plugin); |
|
1088 | - } |
|
1089 | - } |
|
1090 | - } |
|
1091 | - } |
|
1092 | - } |
|
1093 | - |
|
1094 | - |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * perform_activations_upgrades_and_migrations |
|
1098 | - * |
|
1099 | - * @access public |
|
1100 | - * @return void |
|
1101 | - */ |
|
1102 | - public function perform_activations_upgrades_and_migrations() |
|
1103 | - { |
|
1104 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1105 | - } |
|
1106 | - |
|
1107 | - |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * load_CPTs_and_session |
|
1111 | - * |
|
1112 | - * @access public |
|
1113 | - * @return void |
|
1114 | - */ |
|
1115 | - public function load_CPTs_and_session() |
|
1116 | - { |
|
1117 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1118 | - // register Custom Post Types |
|
1119 | - $this->loader->getShared('EE_Register_CPTs'); |
|
1120 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1121 | - } |
|
1122 | - |
|
1123 | - |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * load_controllers |
|
1127 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
1128 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1129 | - * time |
|
1130 | - * |
|
1131 | - * @access public |
|
1132 | - * @return void |
|
1133 | - */ |
|
1134 | - public function load_controllers() |
|
1135 | - { |
|
1136 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
1137 | - // let's get it started |
|
1138 | - if ( |
|
1139 | - ! $this->maintenance_mode->level() |
|
1140 | - && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1141 | - ) { |
|
1142 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1143 | - $this->loader->getShared('EE_Front_Controller'); |
|
1144 | - } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1145 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1146 | - $this->loader->getShared('EE_Admin'); |
|
1147 | - } |
|
1148 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
1149 | - } |
|
1150 | - |
|
1151 | - |
|
1152 | - |
|
1153 | - /** |
|
1154 | - * core_loaded_and_ready |
|
1155 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1156 | - * |
|
1157 | - * @access public |
|
1158 | - * @return void |
|
1159 | - */ |
|
1160 | - public function core_loaded_and_ready() |
|
1161 | - { |
|
1162 | - if ( |
|
1163 | - $this->request->isAdmin() |
|
1164 | - || $this->request->isEeAjax() |
|
1165 | - || $this->request->isFrontend() |
|
1166 | - ) { |
|
1167 | - $this->loader->getShared('EE_Session'); |
|
1168 | - } |
|
1169 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1170 | - // load_espresso_template_tags |
|
1171 | - if ( |
|
1172 | - is_readable(EE_PUBLIC . 'template_tags.php') |
|
1173 | - && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed()) |
|
1174 | - ) { |
|
1175 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
1176 | - } |
|
1177 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1178 | - if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) { |
|
1179 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1180 | - } |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - |
|
1185 | - /** |
|
1186 | - * initialize |
|
1187 | - * this is the best place to begin initializing client code |
|
1188 | - * |
|
1189 | - * @access public |
|
1190 | - * @return void |
|
1191 | - */ |
|
1192 | - public function initialize() |
|
1193 | - { |
|
1194 | - do_action('AHEE__EE_System__initialize'); |
|
1195 | - } |
|
1196 | - |
|
1197 | - |
|
1198 | - |
|
1199 | - /** |
|
1200 | - * initialize_last |
|
1201 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1202 | - * initialize has done so |
|
1203 | - * |
|
1204 | - * @access public |
|
1205 | - * @return void |
|
1206 | - */ |
|
1207 | - public function initialize_last() |
|
1208 | - { |
|
1209 | - do_action('AHEE__EE_System__initialize_last'); |
|
1210 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1211 | - } |
|
1212 | - |
|
1213 | - |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * @return void |
|
1217 | - * @throws EE_Error |
|
1218 | - */ |
|
1219 | - public function addEspressoToolbar() |
|
1220 | - { |
|
1221 | - $this->loader->getShared( |
|
1222 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1223 | - array($this->registry->CAP) |
|
1224 | - ); |
|
1225 | - } |
|
1226 | - |
|
1227 | - |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * do_not_cache |
|
1231 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1232 | - * |
|
1233 | - * @access public |
|
1234 | - * @return void |
|
1235 | - */ |
|
1236 | - public static function do_not_cache() |
|
1237 | - { |
|
1238 | - // set no cache constants |
|
1239 | - if (! defined('DONOTCACHEPAGE')) { |
|
1240 | - define('DONOTCACHEPAGE', true); |
|
1241 | - } |
|
1242 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1243 | - define('DONOTCACHCEOBJECT', true); |
|
1244 | - } |
|
1245 | - if (! defined('DONOTCACHEDB')) { |
|
1246 | - define('DONOTCACHEDB', true); |
|
1247 | - } |
|
1248 | - // add no cache headers |
|
1249 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1250 | - // plus a little extra for nginx and Google Chrome |
|
1251 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1252 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1253 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1254 | - } |
|
1255 | - |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * extra_nocache_headers |
|
1260 | - * |
|
1261 | - * @access public |
|
1262 | - * @param $headers |
|
1263 | - * @return array |
|
1264 | - */ |
|
1265 | - public static function extra_nocache_headers($headers) |
|
1266 | - { |
|
1267 | - // for NGINX |
|
1268 | - $headers['X-Accel-Expires'] = 0; |
|
1269 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1270 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1271 | - return $headers; |
|
1272 | - } |
|
1273 | - |
|
1274 | - |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * nocache_headers |
|
1278 | - * |
|
1279 | - * @access public |
|
1280 | - * @return void |
|
1281 | - */ |
|
1282 | - public static function nocache_headers() |
|
1283 | - { |
|
1284 | - nocache_headers(); |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1291 | - * never returned with the function. |
|
1292 | - * |
|
1293 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1294 | - * @return array |
|
1295 | - */ |
|
1296 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1297 | - { |
|
1298 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1299 | - } |
|
35 | + /** |
|
36 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
37 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
38 | + */ |
|
39 | + const req_type_normal = 0; |
|
40 | + |
|
41 | + /** |
|
42 | + * Indicates this is a brand new installation of EE so we should install |
|
43 | + * tables and default data etc |
|
44 | + */ |
|
45 | + const req_type_new_activation = 1; |
|
46 | + |
|
47 | + /** |
|
48 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
49 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
50 | + * and that default data is setup too |
|
51 | + */ |
|
52 | + const req_type_reactivation = 2; |
|
53 | + |
|
54 | + /** |
|
55 | + * indicates that EE has been upgraded since its previous request. |
|
56 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
57 | + */ |
|
58 | + const req_type_upgrade = 3; |
|
59 | + |
|
60 | + /** |
|
61 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
62 | + */ |
|
63 | + const req_type_downgrade = 4; |
|
64 | + |
|
65 | + /** |
|
66 | + * @deprecated since version 4.6.0.dev.006 |
|
67 | + * Now whenever a new_activation is detected the request type is still just |
|
68 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
69 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
70 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
71 | + * (Specifically, when the migration manager indicates migrations are finished |
|
72 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
73 | + */ |
|
74 | + const req_type_activation_but_not_installed = 5; |
|
75 | + |
|
76 | + /** |
|
77 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
78 | + */ |
|
79 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @var EE_System $_instance |
|
84 | + */ |
|
85 | + private static $_instance; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var EE_Registry $registry |
|
89 | + */ |
|
90 | + private $registry; |
|
91 | + |
|
92 | + /** |
|
93 | + * @var LoaderInterface $loader |
|
94 | + */ |
|
95 | + private $loader; |
|
96 | + |
|
97 | + /** |
|
98 | + * @var EE_Capabilities $capabilities |
|
99 | + */ |
|
100 | + private $capabilities; |
|
101 | + |
|
102 | + /** |
|
103 | + * @var RequestInterface $request |
|
104 | + */ |
|
105 | + private $request; |
|
106 | + |
|
107 | + /** |
|
108 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
109 | + */ |
|
110 | + private $maintenance_mode; |
|
111 | + |
|
112 | + /** |
|
113 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
114 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
115 | + * |
|
116 | + * @var int $_req_type |
|
117 | + */ |
|
118 | + private $_req_type; |
|
119 | + |
|
120 | + /** |
|
121 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
122 | + * |
|
123 | + * @var boolean $_major_version_change |
|
124 | + */ |
|
125 | + private $_major_version_change = false; |
|
126 | + |
|
127 | + /** |
|
128 | + * A Context DTO dedicated solely to identifying the current request type. |
|
129 | + * |
|
130 | + * @var RequestTypeContextCheckerInterface $request_type |
|
131 | + */ |
|
132 | + private $request_type; |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @singleton method used to instantiate class object |
|
138 | + * @param EE_Registry|null $registry |
|
139 | + * @param LoaderInterface|null $loader |
|
140 | + * @param RequestInterface|null $request |
|
141 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
142 | + * @return EE_System |
|
143 | + */ |
|
144 | + public static function instance( |
|
145 | + EE_Registry $registry = null, |
|
146 | + LoaderInterface $loader = null, |
|
147 | + RequestInterface $request = null, |
|
148 | + EE_Maintenance_Mode $maintenance_mode = null |
|
149 | + ) { |
|
150 | + // check if class object is instantiated |
|
151 | + if (! self::$_instance instanceof EE_System) { |
|
152 | + self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
153 | + } |
|
154 | + return self::$_instance; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * resets the instance and returns it |
|
161 | + * |
|
162 | + * @return EE_System |
|
163 | + */ |
|
164 | + public static function reset() |
|
165 | + { |
|
166 | + self::$_instance->_req_type = null; |
|
167 | + //make sure none of the old hooks are left hanging around |
|
168 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
169 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
170 | + EE_Data_Migration_Manager::reset(); |
|
171 | + self::instance()->detect_activations_or_upgrades(); |
|
172 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
173 | + return self::instance(); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * sets hooks for running rest of system |
|
180 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
181 | + * starting EE Addons from any other point may lead to problems |
|
182 | + * |
|
183 | + * @param EE_Registry $registry |
|
184 | + * @param LoaderInterface $loader |
|
185 | + * @param RequestInterface $request |
|
186 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
187 | + */ |
|
188 | + private function __construct( |
|
189 | + EE_Registry $registry, |
|
190 | + LoaderInterface $loader, |
|
191 | + RequestInterface $request, |
|
192 | + EE_Maintenance_Mode $maintenance_mode |
|
193 | + ) { |
|
194 | + $this->registry = $registry; |
|
195 | + $this->loader = $loader; |
|
196 | + $this->request = $request; |
|
197 | + $this->maintenance_mode = $maintenance_mode; |
|
198 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
199 | + add_action( |
|
200 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
201 | + array($this, 'loadCapabilities'), |
|
202 | + 5 |
|
203 | + ); |
|
204 | + add_action( |
|
205 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
206 | + array($this, 'loadCommandBus'), |
|
207 | + 7 |
|
208 | + ); |
|
209 | + add_action( |
|
210 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
211 | + array($this, 'loadPluginApi'), |
|
212 | + 9 |
|
213 | + ); |
|
214 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
215 | + add_action( |
|
216 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
217 | + array($this, 'load_espresso_addons') |
|
218 | + ); |
|
219 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
220 | + // because the newly-activated addon didn't get a chance to run at all |
|
221 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
222 | + // detect whether install or upgrade |
|
223 | + add_action( |
|
224 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
225 | + array($this, 'detect_activations_or_upgrades'), |
|
226 | + 3 |
|
227 | + ); |
|
228 | + // load EE_Config, EE_Textdomain, etc |
|
229 | + add_action( |
|
230 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
231 | + array($this, 'load_core_configuration'), |
|
232 | + 5 |
|
233 | + ); |
|
234 | + // load EE_Config, EE_Textdomain, etc |
|
235 | + add_action( |
|
236 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
237 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
238 | + 7 |
|
239 | + ); |
|
240 | + // you wanna get going? I wanna get going... let's get going! |
|
241 | + add_action( |
|
242 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
243 | + array($this, 'brew_espresso'), |
|
244 | + 9 |
|
245 | + ); |
|
246 | + //other housekeeping |
|
247 | + //exclude EE critical pages from wp_list_pages |
|
248 | + add_filter( |
|
249 | + 'wp_list_pages_excludes', |
|
250 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
251 | + 10 |
|
252 | + ); |
|
253 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
254 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
255 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * load and setup EE_Capabilities |
|
261 | + * |
|
262 | + * @return void |
|
263 | + * @throws EE_Error |
|
264 | + */ |
|
265 | + public function loadCapabilities() |
|
266 | + { |
|
267 | + $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
268 | + add_action( |
|
269 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
270 | + function () |
|
271 | + { |
|
272 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
273 | + } |
|
274 | + ); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * create and cache the CommandBus, and also add middleware |
|
281 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
282 | + * which is why we need to load the CommandBus after Caps are set up |
|
283 | + * |
|
284 | + * @return void |
|
285 | + * @throws EE_Error |
|
286 | + */ |
|
287 | + public function loadCommandBus() |
|
288 | + { |
|
289 | + $this->loader->getShared( |
|
290 | + 'CommandBusInterface', |
|
291 | + array( |
|
292 | + null, |
|
293 | + apply_filters( |
|
294 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
295 | + array( |
|
296 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
297 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
298 | + ) |
|
299 | + ), |
|
300 | + ) |
|
301 | + ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * @return void |
|
308 | + * @throws EE_Error |
|
309 | + */ |
|
310 | + public function loadPluginApi() |
|
311 | + { |
|
312 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
313 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
314 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
315 | + $this->loader->getShared('EE_Request_Handler'); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * @param string $addon_name |
|
321 | + * @param string $version_constant |
|
322 | + * @param string $min_version_required |
|
323 | + * @param string $load_callback |
|
324 | + * @param string $plugin_file_constant |
|
325 | + * @return void |
|
326 | + */ |
|
327 | + private function deactivateIncompatibleAddon( |
|
328 | + $addon_name, |
|
329 | + $version_constant, |
|
330 | + $min_version_required, |
|
331 | + $load_callback, |
|
332 | + $plugin_file_constant |
|
333 | + ) { |
|
334 | + if (! defined($version_constant)) { |
|
335 | + return; |
|
336 | + } |
|
337 | + $addon_version = constant($version_constant); |
|
338 | + if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
339 | + remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
340 | + if (! function_exists('deactivate_plugins')) { |
|
341 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
342 | + } |
|
343 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
344 | + unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
345 | + EE_Error::add_error( |
|
346 | + sprintf( |
|
347 | + esc_html__( |
|
348 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
349 | + 'event_espresso' |
|
350 | + ), |
|
351 | + $addon_name, |
|
352 | + $min_version_required |
|
353 | + ), |
|
354 | + __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__ |
|
355 | + ); |
|
356 | + EE_Error::get_notices(false, true); |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * load_espresso_addons |
|
363 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
364 | + * this is hooked into both: |
|
365 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
366 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
367 | + * and the WP 'activate_plugin' hook point |
|
368 | + * |
|
369 | + * @access public |
|
370 | + * @return void |
|
371 | + */ |
|
372 | + public function load_espresso_addons() |
|
373 | + { |
|
374 | + $this->deactivateIncompatibleAddon( |
|
375 | + 'Wait Lists', |
|
376 | + 'EE_WAIT_LISTS_VERSION', |
|
377 | + '1.0.0.beta.074', |
|
378 | + 'load_espresso_wait_lists', |
|
379 | + 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
380 | + ); |
|
381 | + $this->deactivateIncompatibleAddon( |
|
382 | + 'Automated Upcoming Event Notifications', |
|
383 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
384 | + '1.0.0.beta.091', |
|
385 | + 'load_espresso_automated_upcoming_event_notification', |
|
386 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
387 | + ); |
|
388 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
389 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
390 | + //We want it for mobile apps. Just include the entire plugin |
|
391 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
392 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
393 | + //and causes a fatal error |
|
394 | + if ( |
|
395 | + $this->request->getRequestParam('activate') !== 'true' |
|
396 | + && ! function_exists('json_basic_auth_handler') |
|
397 | + && ! function_exists('json_basic_auth_error') |
|
398 | + && ! in_array( |
|
399 | + $this->request->getRequestParam('action'), |
|
400 | + array('activate', 'activate-selected'), |
|
401 | + true |
|
402 | + ) |
|
403 | + ) { |
|
404 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
405 | + } |
|
406 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * detect_activations_or_upgrades |
|
413 | + * Checks for activation or upgrade of core first; |
|
414 | + * then also checks if any registered addons have been activated or upgraded |
|
415 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
416 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
417 | + * |
|
418 | + * @access public |
|
419 | + * @return void |
|
420 | + */ |
|
421 | + public function detect_activations_or_upgrades() |
|
422 | + { |
|
423 | + //first off: let's make sure to handle core |
|
424 | + $this->detect_if_activation_or_upgrade(); |
|
425 | + foreach ($this->registry->addons as $addon) { |
|
426 | + if ($addon instanceof EE_Addon) { |
|
427 | + //detect teh request type for that addon |
|
428 | + $addon->detect_activation_or_upgrade(); |
|
429 | + } |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * detect_if_activation_or_upgrade |
|
437 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
438 | + * and either setting up the DB or setting up maintenance mode etc. |
|
439 | + * |
|
440 | + * @access public |
|
441 | + * @return void |
|
442 | + */ |
|
443 | + public function detect_if_activation_or_upgrade() |
|
444 | + { |
|
445 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
446 | + // check if db has been updated, or if its a brand-new installation |
|
447 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
448 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
449 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
450 | + switch ($request_type) { |
|
451 | + case EE_System::req_type_new_activation: |
|
452 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
453 | + $this->_handle_core_version_change($espresso_db_update); |
|
454 | + break; |
|
455 | + case EE_System::req_type_reactivation: |
|
456 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
457 | + $this->_handle_core_version_change($espresso_db_update); |
|
458 | + break; |
|
459 | + case EE_System::req_type_upgrade: |
|
460 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
461 | + //migrations may be required now that we've upgraded |
|
462 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
463 | + $this->_handle_core_version_change($espresso_db_update); |
|
464 | + // echo "done upgrade";die; |
|
465 | + break; |
|
466 | + case EE_System::req_type_downgrade: |
|
467 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
468 | + //its possible migrations are no longer required |
|
469 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
470 | + $this->_handle_core_version_change($espresso_db_update); |
|
471 | + break; |
|
472 | + case EE_System::req_type_normal: |
|
473 | + default: |
|
474 | + break; |
|
475 | + } |
|
476 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Updates the list of installed versions and sets hooks for |
|
483 | + * initializing the database later during the request |
|
484 | + * |
|
485 | + * @param array $espresso_db_update |
|
486 | + */ |
|
487 | + private function _handle_core_version_change($espresso_db_update) |
|
488 | + { |
|
489 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
490 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
491 | + add_action( |
|
492 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
493 | + array($this, 'initialize_db_if_no_migrations_required') |
|
494 | + ); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
501 | + * information about what versions of EE have been installed and activated, |
|
502 | + * NOT necessarily the state of the database |
|
503 | + * |
|
504 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
505 | + * If not supplied, fetches it from the options table |
|
506 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
507 | + */ |
|
508 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
509 | + { |
|
510 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
511 | + if (! $espresso_db_update) { |
|
512 | + $espresso_db_update = get_option('espresso_db_update'); |
|
513 | + } |
|
514 | + // check that option is an array |
|
515 | + if (! is_array($espresso_db_update)) { |
|
516 | + // if option is FALSE, then it never existed |
|
517 | + if ($espresso_db_update === false) { |
|
518 | + // make $espresso_db_update an array and save option with autoload OFF |
|
519 | + $espresso_db_update = array(); |
|
520 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
521 | + } else { |
|
522 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
523 | + $espresso_db_update = array($espresso_db_update => array()); |
|
524 | + update_option('espresso_db_update', $espresso_db_update); |
|
525 | + } |
|
526 | + } else { |
|
527 | + $corrected_db_update = array(); |
|
528 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
529 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
530 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
531 | + //the key is an int, and the value IS NOT an array |
|
532 | + //so it must be numerically-indexed, where values are versions installed... |
|
533 | + //fix it! |
|
534 | + $version_string = $should_be_array; |
|
535 | + $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
536 | + } else { |
|
537 | + //ok it checks out |
|
538 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
539 | + } |
|
540 | + } |
|
541 | + $espresso_db_update = $corrected_db_update; |
|
542 | + update_option('espresso_db_update', $espresso_db_update); |
|
543 | + } |
|
544 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
545 | + return $espresso_db_update; |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
552 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
553 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
554 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
555 | + * so that it will be done when migrations are finished |
|
556 | + * |
|
557 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
558 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
559 | + * This is a resource-intensive job |
|
560 | + * so we prefer to only do it when necessary |
|
561 | + * @return void |
|
562 | + * @throws EE_Error |
|
563 | + */ |
|
564 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
565 | + { |
|
566 | + $request_type = $this->detect_req_type(); |
|
567 | + //only initialize system if we're not in maintenance mode. |
|
568 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
569 | + update_option('ee_flush_rewrite_rules', true); |
|
570 | + if ($verify_schema) { |
|
571 | + EEH_Activation::initialize_db_and_folders(); |
|
572 | + } |
|
573 | + EEH_Activation::initialize_db_content(); |
|
574 | + EEH_Activation::system_initialization(); |
|
575 | + if ($initialize_addons_too) { |
|
576 | + $this->initialize_addons(); |
|
577 | + } |
|
578 | + } else { |
|
579 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
580 | + } |
|
581 | + if ($request_type === EE_System::req_type_new_activation |
|
582 | + || $request_type === EE_System::req_type_reactivation |
|
583 | + || ( |
|
584 | + $request_type === EE_System::req_type_upgrade |
|
585 | + && $this->is_major_version_change() |
|
586 | + ) |
|
587 | + ) { |
|
588 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Initializes the db for all registered addons |
|
596 | + * |
|
597 | + * @throws EE_Error |
|
598 | + */ |
|
599 | + public function initialize_addons() |
|
600 | + { |
|
601 | + //foreach registered addon, make sure its db is up-to-date too |
|
602 | + foreach ($this->registry->addons as $addon) { |
|
603 | + if ($addon instanceof EE_Addon) { |
|
604 | + $addon->initialize_db_if_no_migrations_required(); |
|
605 | + } |
|
606 | + } |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
613 | + * |
|
614 | + * @param array $version_history |
|
615 | + * @param string $current_version_to_add version to be added to the version history |
|
616 | + * @return boolean success as to whether or not this option was changed |
|
617 | + */ |
|
618 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
619 | + { |
|
620 | + if (! $version_history) { |
|
621 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
622 | + } |
|
623 | + if ($current_version_to_add === null) { |
|
624 | + $current_version_to_add = espresso_version(); |
|
625 | + } |
|
626 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
627 | + // re-save |
|
628 | + return update_option('espresso_db_update', $version_history); |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * Detects if the current version indicated in the has existed in the list of |
|
635 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
636 | + * |
|
637 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
638 | + * If not supplied, fetches it from the options table. |
|
639 | + * Also, caches its result so later parts of the code can also know whether |
|
640 | + * there's been an update or not. This way we can add the current version to |
|
641 | + * espresso_db_update, but still know if this is a new install or not |
|
642 | + * @return int one of the constants on EE_System::req_type_ |
|
643 | + */ |
|
644 | + public function detect_req_type($espresso_db_update = null) |
|
645 | + { |
|
646 | + if ($this->_req_type === null) { |
|
647 | + $espresso_db_update = ! empty($espresso_db_update) |
|
648 | + ? $espresso_db_update |
|
649 | + : $this->fix_espresso_db_upgrade_option(); |
|
650 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
651 | + $espresso_db_update, |
|
652 | + 'ee_espresso_activation', espresso_version() |
|
653 | + ); |
|
654 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
655 | + $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
656 | + } |
|
657 | + return $this->_req_type; |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
664 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
665 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
666 | + * |
|
667 | + * @param $activation_history |
|
668 | + * @return bool |
|
669 | + */ |
|
670 | + private function _detect_major_version_change($activation_history) |
|
671 | + { |
|
672 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
673 | + $previous_version_parts = explode('.', $previous_version); |
|
674 | + $current_version_parts = explode('.', espresso_version()); |
|
675 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
676 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
677 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
678 | + ); |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * Returns true if either the major or minor version of EE changed during this request. |
|
685 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
686 | + * |
|
687 | + * @return bool |
|
688 | + */ |
|
689 | + public function is_major_version_change() |
|
690 | + { |
|
691 | + return $this->_major_version_change; |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
698 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
699 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
700 | + * just activated to (for core that will always be espresso_version()) |
|
701 | + * |
|
702 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
703 | + * ee plugin. for core that's 'espresso_db_update' |
|
704 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
705 | + * indicate that this plugin was just activated |
|
706 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
707 | + * espresso_version()) |
|
708 | + * @return int one of the constants on EE_System::req_type_* |
|
709 | + */ |
|
710 | + public static function detect_req_type_given_activation_history( |
|
711 | + $activation_history_for_addon, |
|
712 | + $activation_indicator_option_name, |
|
713 | + $version_to_upgrade_to |
|
714 | + ) { |
|
715 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
716 | + if ($activation_history_for_addon) { |
|
717 | + //it exists, so this isn't a completely new install |
|
718 | + //check if this version already in that list of previously installed versions |
|
719 | + if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
720 | + //it a version we haven't seen before |
|
721 | + if ($version_is_higher === 1) { |
|
722 | + $req_type = EE_System::req_type_upgrade; |
|
723 | + } else { |
|
724 | + $req_type = EE_System::req_type_downgrade; |
|
725 | + } |
|
726 | + delete_option($activation_indicator_option_name); |
|
727 | + } else { |
|
728 | + // its not an update. maybe a reactivation? |
|
729 | + if (get_option($activation_indicator_option_name, false)) { |
|
730 | + if ($version_is_higher === -1) { |
|
731 | + $req_type = EE_System::req_type_downgrade; |
|
732 | + } elseif ($version_is_higher === 0) { |
|
733 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
734 | + $req_type = EE_System::req_type_reactivation; |
|
735 | + } else {//$version_is_higher === 1 |
|
736 | + $req_type = EE_System::req_type_upgrade; |
|
737 | + } |
|
738 | + delete_option($activation_indicator_option_name); |
|
739 | + } else { |
|
740 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
741 | + if ($version_is_higher === -1) { |
|
742 | + $req_type = EE_System::req_type_downgrade; |
|
743 | + } elseif ($version_is_higher === 0) { |
|
744 | + //we've seen this version before and it's not an activation. its normal request |
|
745 | + $req_type = EE_System::req_type_normal; |
|
746 | + } else {//$version_is_higher === 1 |
|
747 | + $req_type = EE_System::req_type_upgrade; |
|
748 | + } |
|
749 | + } |
|
750 | + } |
|
751 | + } else { |
|
752 | + //brand new install |
|
753 | + $req_type = EE_System::req_type_new_activation; |
|
754 | + delete_option($activation_indicator_option_name); |
|
755 | + } |
|
756 | + return $req_type; |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
763 | + * the $activation_history_for_addon |
|
764 | + * |
|
765 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
766 | + * sometimes containing 'unknown-date' |
|
767 | + * @param string $version_to_upgrade_to (current version) |
|
768 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
769 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
770 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
771 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
772 | + */ |
|
773 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
774 | + { |
|
775 | + //find the most recently-activated version |
|
776 | + $most_recently_active_version = |
|
777 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
778 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * Gets the most recently active version listed in the activation history, |
|
785 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
786 | + * |
|
787 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
788 | + * sometimes containing 'unknown-date' |
|
789 | + * @return string |
|
790 | + */ |
|
791 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
792 | + { |
|
793 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
794 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
795 | + if (is_array($activation_history)) { |
|
796 | + foreach ($activation_history as $version => $times_activated) { |
|
797 | + //check there is a record of when this version was activated. Otherwise, |
|
798 | + //mark it as unknown |
|
799 | + if (! $times_activated) { |
|
800 | + $times_activated = array('unknown-date'); |
|
801 | + } |
|
802 | + if (is_string($times_activated)) { |
|
803 | + $times_activated = array($times_activated); |
|
804 | + } |
|
805 | + foreach ($times_activated as $an_activation) { |
|
806 | + if ($an_activation !== 'unknown-date' |
|
807 | + && $an_activation |
|
808 | + > $most_recently_active_version_activation) { |
|
809 | + $most_recently_active_version = $version; |
|
810 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
811 | + ? '1970-01-01 00:00:00' |
|
812 | + : $an_activation; |
|
813 | + } |
|
814 | + } |
|
815 | + } |
|
816 | + } |
|
817 | + return $most_recently_active_version; |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * This redirects to the about EE page after activation |
|
824 | + * |
|
825 | + * @return void |
|
826 | + */ |
|
827 | + public function redirect_to_about_ee() |
|
828 | + { |
|
829 | + $notices = EE_Error::get_notices(false); |
|
830 | + //if current user is an admin and it's not an ajax or rest request |
|
831 | + if ( |
|
832 | + ! isset($notices['errors']) |
|
833 | + && $this->request->isAdmin() |
|
834 | + && apply_filters( |
|
835 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
836 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
837 | + ) |
|
838 | + ) { |
|
839 | + $query_params = array('page' => 'espresso_about'); |
|
840 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
841 | + $query_params['new_activation'] = true; |
|
842 | + } |
|
843 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
844 | + $query_params['reactivation'] = true; |
|
845 | + } |
|
846 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
847 | + wp_safe_redirect($url); |
|
848 | + exit(); |
|
849 | + } |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * load_core_configuration |
|
856 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
857 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
858 | + * |
|
859 | + * @return void |
|
860 | + * @throws ReflectionException |
|
861 | + */ |
|
862 | + public function load_core_configuration() |
|
863 | + { |
|
864 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
865 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
866 | + //load textdomain |
|
867 | + EE_Load_Textdomain::load_textdomain(); |
|
868 | + // load and setup EE_Config and EE_Network_Config |
|
869 | + $config = $this->loader->getShared('EE_Config'); |
|
870 | + $this->loader->getShared('EE_Network_Config'); |
|
871 | + // setup autoloaders |
|
872 | + // enable logging? |
|
873 | + if ($config->admin->use_full_logging) { |
|
874 | + $this->loader->getShared('EE_Log'); |
|
875 | + } |
|
876 | + // check for activation errors |
|
877 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
878 | + if ($activation_errors) { |
|
879 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
880 | + update_option('ee_plugin_activation_errors', false); |
|
881 | + } |
|
882 | + // get model names |
|
883 | + $this->_parse_model_names(); |
|
884 | + //load caf stuff a chance to play during the activation process too. |
|
885 | + $this->_maybe_brew_regular(); |
|
886 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
887 | + } |
|
888 | + |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
893 | + * |
|
894 | + * @return void |
|
895 | + * @throws ReflectionException |
|
896 | + */ |
|
897 | + private function _parse_model_names() |
|
898 | + { |
|
899 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
900 | + $models = glob(EE_MODELS . '*.model.php'); |
|
901 | + $model_names = array(); |
|
902 | + $non_abstract_db_models = array(); |
|
903 | + foreach ($models as $model) { |
|
904 | + // get model classname |
|
905 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
906 | + $short_name = str_replace('EEM_', '', $classname); |
|
907 | + $reflectionClass = new ReflectionClass($classname); |
|
908 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
909 | + $non_abstract_db_models[ $short_name ] = $classname; |
|
910 | + } |
|
911 | + $model_names[ $short_name ] = $classname; |
|
912 | + } |
|
913 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
914 | + $this->registry->non_abstract_db_models = apply_filters( |
|
915 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
916 | + $non_abstract_db_models |
|
917 | + ); |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
923 | + * that need to be setup before our EE_System launches. |
|
924 | + * |
|
925 | + * @return void |
|
926 | + * @throws DomainException |
|
927 | + * @throws InvalidArgumentException |
|
928 | + * @throws InvalidDataTypeException |
|
929 | + * @throws InvalidInterfaceException |
|
930 | + * @throws InvalidClassException |
|
931 | + * @throws InvalidFilePathException |
|
932 | + */ |
|
933 | + private function _maybe_brew_regular() |
|
934 | + { |
|
935 | + /** @var Domain $domain */ |
|
936 | + $domain = DomainFactory::getShared( |
|
937 | + new FullyQualifiedName( |
|
938 | + 'EventEspresso\core\domain\Domain' |
|
939 | + ), |
|
940 | + array( |
|
941 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
942 | + Version::fromString(espresso_version()) |
|
943 | + ) |
|
944 | + ); |
|
945 | + if ($domain->isCaffeinated()) { |
|
946 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
947 | + } |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + |
|
952 | + /** |
|
953 | + * register_shortcodes_modules_and_widgets |
|
954 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
955 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
956 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
957 | + * |
|
958 | + * @access public |
|
959 | + * @return void |
|
960 | + * @throws Exception |
|
961 | + */ |
|
962 | + public function register_shortcodes_modules_and_widgets() |
|
963 | + { |
|
964 | + if ($this->request->isFrontend() || $this->request->isIframe()) { |
|
965 | + try { |
|
966 | + // load, register, and add shortcodes the new way |
|
967 | + $this->loader->getShared( |
|
968 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
969 | + array( |
|
970 | + // and the old way, but we'll put it under control of the new system |
|
971 | + EE_Config::getLegacyShortcodesManager(), |
|
972 | + ) |
|
973 | + ); |
|
974 | + } catch (Exception $exception) { |
|
975 | + new ExceptionStackTraceDisplay($exception); |
|
976 | + } |
|
977 | + } |
|
978 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
979 | + // check for addons using old hook point |
|
980 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
981 | + $this->_incompatible_addon_error(); |
|
982 | + } |
|
983 | + } |
|
984 | + |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * _incompatible_addon_error |
|
989 | + * |
|
990 | + * @access public |
|
991 | + * @return void |
|
992 | + */ |
|
993 | + private function _incompatible_addon_error() |
|
994 | + { |
|
995 | + // get array of classes hooking into here |
|
996 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
997 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
998 | + ); |
|
999 | + if (! empty($class_names)) { |
|
1000 | + $msg = __( |
|
1001 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1002 | + 'event_espresso' |
|
1003 | + ); |
|
1004 | + $msg .= '<ul>'; |
|
1005 | + foreach ($class_names as $class_name) { |
|
1006 | + $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
1007 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
1008 | + $class_name |
|
1009 | + ) . '</b></li>'; |
|
1010 | + } |
|
1011 | + $msg .= '</ul>'; |
|
1012 | + $msg .= __( |
|
1013 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1014 | + 'event_espresso' |
|
1015 | + ); |
|
1016 | + // save list of incompatible addons to wp-options for later use |
|
1017 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1018 | + if (is_admin()) { |
|
1019 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1020 | + } |
|
1021 | + } |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * brew_espresso |
|
1028 | + * begins the process of setting hooks for initializing EE in the correct order |
|
1029 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1030 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1031 | + * |
|
1032 | + * @return void |
|
1033 | + */ |
|
1034 | + public function brew_espresso() |
|
1035 | + { |
|
1036 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1037 | + // load some final core systems |
|
1038 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1039 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1040 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1041 | + add_action('init', array($this, 'load_controllers'), 7); |
|
1042 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1043 | + add_action('init', array($this, 'initialize'), 10); |
|
1044 | + add_action('init', array($this, 'initialize_last'), 100); |
|
1045 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1046 | + // pew pew pew |
|
1047 | + $this->loader->getShared('EE_PUE'); |
|
1048 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1049 | + } |
|
1050 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1051 | + } |
|
1052 | + |
|
1053 | + |
|
1054 | + |
|
1055 | + /** |
|
1056 | + * set_hooks_for_core |
|
1057 | + * |
|
1058 | + * @access public |
|
1059 | + * @return void |
|
1060 | + * @throws EE_Error |
|
1061 | + */ |
|
1062 | + public function set_hooks_for_core() |
|
1063 | + { |
|
1064 | + $this->_deactivate_incompatible_addons(); |
|
1065 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1066 | + $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1067 | + //caps need to be initialized on every request so that capability maps are set. |
|
1068 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1069 | + $this->registry->CAP->init_caps(); |
|
1070 | + } |
|
1071 | + |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1076 | + * deactivates any addons considered incompatible with the current version of EE |
|
1077 | + */ |
|
1078 | + private function _deactivate_incompatible_addons() |
|
1079 | + { |
|
1080 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1081 | + if (! empty($incompatible_addons)) { |
|
1082 | + $active_plugins = get_option('active_plugins', array()); |
|
1083 | + foreach ($active_plugins as $active_plugin) { |
|
1084 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
1085 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1086 | + unset($_GET['activate']); |
|
1087 | + espresso_deactivate_plugin($active_plugin); |
|
1088 | + } |
|
1089 | + } |
|
1090 | + } |
|
1091 | + } |
|
1092 | + } |
|
1093 | + |
|
1094 | + |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * perform_activations_upgrades_and_migrations |
|
1098 | + * |
|
1099 | + * @access public |
|
1100 | + * @return void |
|
1101 | + */ |
|
1102 | + public function perform_activations_upgrades_and_migrations() |
|
1103 | + { |
|
1104 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1105 | + } |
|
1106 | + |
|
1107 | + |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * load_CPTs_and_session |
|
1111 | + * |
|
1112 | + * @access public |
|
1113 | + * @return void |
|
1114 | + */ |
|
1115 | + public function load_CPTs_and_session() |
|
1116 | + { |
|
1117 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1118 | + // register Custom Post Types |
|
1119 | + $this->loader->getShared('EE_Register_CPTs'); |
|
1120 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1121 | + } |
|
1122 | + |
|
1123 | + |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * load_controllers |
|
1127 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
1128 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1129 | + * time |
|
1130 | + * |
|
1131 | + * @access public |
|
1132 | + * @return void |
|
1133 | + */ |
|
1134 | + public function load_controllers() |
|
1135 | + { |
|
1136 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
1137 | + // let's get it started |
|
1138 | + if ( |
|
1139 | + ! $this->maintenance_mode->level() |
|
1140 | + && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1141 | + ) { |
|
1142 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1143 | + $this->loader->getShared('EE_Front_Controller'); |
|
1144 | + } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1145 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1146 | + $this->loader->getShared('EE_Admin'); |
|
1147 | + } |
|
1148 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
1149 | + } |
|
1150 | + |
|
1151 | + |
|
1152 | + |
|
1153 | + /** |
|
1154 | + * core_loaded_and_ready |
|
1155 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1156 | + * |
|
1157 | + * @access public |
|
1158 | + * @return void |
|
1159 | + */ |
|
1160 | + public function core_loaded_and_ready() |
|
1161 | + { |
|
1162 | + if ( |
|
1163 | + $this->request->isAdmin() |
|
1164 | + || $this->request->isEeAjax() |
|
1165 | + || $this->request->isFrontend() |
|
1166 | + ) { |
|
1167 | + $this->loader->getShared('EE_Session'); |
|
1168 | + } |
|
1169 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1170 | + // load_espresso_template_tags |
|
1171 | + if ( |
|
1172 | + is_readable(EE_PUBLIC . 'template_tags.php') |
|
1173 | + && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed()) |
|
1174 | + ) { |
|
1175 | + require_once EE_PUBLIC . 'template_tags.php'; |
|
1176 | + } |
|
1177 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1178 | + if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) { |
|
1179 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1180 | + } |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + |
|
1185 | + /** |
|
1186 | + * initialize |
|
1187 | + * this is the best place to begin initializing client code |
|
1188 | + * |
|
1189 | + * @access public |
|
1190 | + * @return void |
|
1191 | + */ |
|
1192 | + public function initialize() |
|
1193 | + { |
|
1194 | + do_action('AHEE__EE_System__initialize'); |
|
1195 | + } |
|
1196 | + |
|
1197 | + |
|
1198 | + |
|
1199 | + /** |
|
1200 | + * initialize_last |
|
1201 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1202 | + * initialize has done so |
|
1203 | + * |
|
1204 | + * @access public |
|
1205 | + * @return void |
|
1206 | + */ |
|
1207 | + public function initialize_last() |
|
1208 | + { |
|
1209 | + do_action('AHEE__EE_System__initialize_last'); |
|
1210 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1211 | + } |
|
1212 | + |
|
1213 | + |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * @return void |
|
1217 | + * @throws EE_Error |
|
1218 | + */ |
|
1219 | + public function addEspressoToolbar() |
|
1220 | + { |
|
1221 | + $this->loader->getShared( |
|
1222 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1223 | + array($this->registry->CAP) |
|
1224 | + ); |
|
1225 | + } |
|
1226 | + |
|
1227 | + |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * do_not_cache |
|
1231 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1232 | + * |
|
1233 | + * @access public |
|
1234 | + * @return void |
|
1235 | + */ |
|
1236 | + public static function do_not_cache() |
|
1237 | + { |
|
1238 | + // set no cache constants |
|
1239 | + if (! defined('DONOTCACHEPAGE')) { |
|
1240 | + define('DONOTCACHEPAGE', true); |
|
1241 | + } |
|
1242 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
1243 | + define('DONOTCACHCEOBJECT', true); |
|
1244 | + } |
|
1245 | + if (! defined('DONOTCACHEDB')) { |
|
1246 | + define('DONOTCACHEDB', true); |
|
1247 | + } |
|
1248 | + // add no cache headers |
|
1249 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1250 | + // plus a little extra for nginx and Google Chrome |
|
1251 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1252 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1253 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1254 | + } |
|
1255 | + |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * extra_nocache_headers |
|
1260 | + * |
|
1261 | + * @access public |
|
1262 | + * @param $headers |
|
1263 | + * @return array |
|
1264 | + */ |
|
1265 | + public static function extra_nocache_headers($headers) |
|
1266 | + { |
|
1267 | + // for NGINX |
|
1268 | + $headers['X-Accel-Expires'] = 0; |
|
1269 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1270 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1271 | + return $headers; |
|
1272 | + } |
|
1273 | + |
|
1274 | + |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * nocache_headers |
|
1278 | + * |
|
1279 | + * @access public |
|
1280 | + * @return void |
|
1281 | + */ |
|
1282 | + public static function nocache_headers() |
|
1283 | + { |
|
1284 | + nocache_headers(); |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + |
|
1289 | + /** |
|
1290 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1291 | + * never returned with the function. |
|
1292 | + * |
|
1293 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1294 | + * @return array |
|
1295 | + */ |
|
1296 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1297 | + { |
|
1298 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1299 | + } |
|
1300 | 1300 | |
1301 | 1301 | |
1302 | 1302 |
@@ -23,458 +23,458 @@ discard block |
||
23 | 23 | final class EE_Admin implements InterminableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Admin $_instance |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
33 | - */ |
|
34 | - private $persistent_admin_notice_manager; |
|
35 | - |
|
36 | - /** |
|
37 | - * @singleton method used to instantiate class object |
|
38 | - * @return EE_Admin |
|
39 | - * @throws EE_Error |
|
40 | - */ |
|
41 | - public static function instance() |
|
42 | - { |
|
43 | - // check if class object is instantiated |
|
44 | - if (! self::$_instance instanceof EE_Admin) { |
|
45 | - self::$_instance = new self(); |
|
46 | - } |
|
47 | - return self::$_instance; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @return EE_Admin |
|
53 | - * @throws EE_Error |
|
54 | - */ |
|
55 | - public static function reset() |
|
56 | - { |
|
57 | - self::$_instance = null; |
|
58 | - return self::instance(); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * class constructor |
|
64 | - * |
|
65 | - * @throws EE_Error |
|
66 | - * @throws InvalidDataTypeException |
|
67 | - * @throws InvalidInterfaceException |
|
68 | - * @throws InvalidArgumentException |
|
69 | - */ |
|
70 | - protected function __construct() |
|
71 | - { |
|
72 | - // define global EE_Admin constants |
|
73 | - $this->_define_all_constants(); |
|
74 | - // set autoloaders for our admin page classes based on included path information |
|
75 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
76 | - // admin hooks |
|
77 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
78 | - // load EE_Request_Handler early |
|
79 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
80 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
81 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
82 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
83 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
84 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
85 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
87 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
88 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
89 | - add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage')); |
|
90 | - //reset Environment config (we only do this on admin page loads); |
|
91 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
92 | - do_action('AHEE__EE_Admin__loaded'); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * _define_all_constants |
|
99 | - * define constants that are set globally for all admin pages |
|
100 | - * |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - private function _define_all_constants() |
|
104 | - { |
|
105 | - if (! defined('EE_ADMIN_URL')) { |
|
106 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
107 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
108 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
109 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
110 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
117 | - * |
|
118 | - * @param array $links |
|
119 | - * @param string $plugin |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function filter_plugin_actions($links, $plugin) |
|
123 | - { |
|
124 | - // set $main_file in stone |
|
125 | - static $main_file; |
|
126 | - // if $main_file is not set yet |
|
127 | - if (! $main_file) { |
|
128 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
129 | - } |
|
130 | - if ($plugin === $main_file) { |
|
131 | - // compare current plugin to this one |
|
132 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
133 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
134 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
135 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
136 | - . '</a>'; |
|
137 | - array_unshift($links, $maintenance_link); |
|
138 | - } else { |
|
139 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
140 | - . esc_html__('Settings', 'event_espresso') |
|
141 | - . '</a>'; |
|
142 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
143 | - . esc_html__('Events', 'event_espresso') |
|
144 | - . '</a>'; |
|
145 | - // add before other links |
|
146 | - array_unshift($links, $org_settings_link, $events_link); |
|
147 | - } |
|
148 | - } |
|
149 | - return $links; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * _get_request |
|
155 | - * |
|
156 | - * @return void |
|
157 | - * @throws EE_Error |
|
158 | - * @throws InvalidArgumentException |
|
159 | - * @throws InvalidDataTypeException |
|
160 | - * @throws InvalidInterfaceException |
|
161 | - * @throws ReflectionException |
|
162 | - */ |
|
163 | - public function get_request() |
|
164 | - { |
|
165 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
166 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * hide_admin_pages_except_maintenance_mode |
|
173 | - * |
|
174 | - * @param array $admin_page_folder_names |
|
175 | - * @return array |
|
176 | - */ |
|
177 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
178 | - { |
|
179 | - return array( |
|
180 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
181 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
182 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
183 | - ); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
190 | - * EE_Front_Controller's init phases have run |
|
191 | - * |
|
192 | - * @return void |
|
193 | - * @throws EE_Error |
|
194 | - * @throws InvalidArgumentException |
|
195 | - * @throws InvalidDataTypeException |
|
196 | - * @throws InvalidInterfaceException |
|
197 | - * @throws ReflectionException |
|
198 | - * @throws ServiceNotFoundException |
|
199 | - */ |
|
200 | - public function init() |
|
201 | - { |
|
202 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
203 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
204 | - //ok so we want to enable the entire admin |
|
205 | - $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
206 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
207 | - ); |
|
208 | - $this->persistent_admin_notice_manager->setReturnUrl( |
|
209 | - EE_Admin_Page::add_query_args_and_nonce( |
|
210 | - array( |
|
211 | - 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
212 | - 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
213 | - ), |
|
214 | - EE_ADMIN_URL |
|
215 | - ) |
|
216 | - ); |
|
217 | - $this->maybeSetDatetimeWarningNotice(); |
|
218 | - //at a glance dashboard widget |
|
219 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
220 | - //filter for get_edit_post_link used on comments for custom post types |
|
221 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
222 | - } |
|
223 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
224 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
225 | - try { |
|
226 | - //this loads the controller for the admin pages which will setup routing etc |
|
227 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
228 | - } catch (EE_Error $e) { |
|
229 | - $e->get_error(); |
|
230 | - } |
|
231 | - } |
|
232 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
233 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
234 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
235 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
236 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
237 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * get_persistent_admin_notices |
|
243 | - * |
|
244 | - * @access public |
|
245 | - * @return void |
|
246 | - * @throws EE_Error |
|
247 | - * @throws InvalidArgumentException |
|
248 | - * @throws InvalidDataTypeException |
|
249 | - * @throws InvalidInterfaceException |
|
250 | - */ |
|
251 | - public function maybeSetDatetimeWarningNotice() |
|
252 | - { |
|
253 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
254 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
255 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
256 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
257 | - if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
258 | - && ! get_option('timezone_string') |
|
259 | - && EEM_Event::instance()->count() > 0 |
|
260 | - ) { |
|
261 | - new PersistentAdminNotice( |
|
262 | - 'datetime_fix_notice', |
|
263 | - sprintf( |
|
264 | - esc_html__( |
|
265 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - '<strong>', |
|
269 | - '</strong>', |
|
270 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
271 | - '</a>', |
|
272 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
273 | - array( |
|
274 | - 'page' => 'espresso_maintenance_settings', |
|
275 | - 'action' => 'datetime_tools' |
|
276 | - ), |
|
277 | - admin_url('admin.php') |
|
278 | - ) . '">' |
|
279 | - ), |
|
280 | - false, |
|
281 | - 'manage_options', |
|
282 | - 'datetime_fix_persistent_notice' |
|
283 | - ); |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
291 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
292 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
293 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
294 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
295 | - * |
|
296 | - * @param WP_Post $post_type WP post type object |
|
297 | - * @return WP_Post |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - */ |
|
302 | - public function remove_pages_from_nav_menu($post_type) |
|
303 | - { |
|
304 | - //if this isn't the "pages" post type let's get out |
|
305 | - if ($post_type->name !== 'page') { |
|
306 | - return $post_type; |
|
307 | - } |
|
308 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
309 | - $post_type->_default_query = array( |
|
310 | - 'post__not_in' => $critical_pages, |
|
311 | - ); |
|
312 | - return $post_type; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
319 | - * metaboxes get shown as well |
|
320 | - * |
|
321 | - * @return void |
|
322 | - */ |
|
323 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
324 | - { |
|
325 | - global $wp_meta_boxes, $pagenow; |
|
326 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
327 | - return; |
|
328 | - } |
|
329 | - $user = wp_get_current_user(); |
|
330 | - //has this been done yet? |
|
331 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
332 | - return; |
|
333 | - } |
|
334 | - |
|
335 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
336 | - $initial_meta_boxes = apply_filters( |
|
337 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
338 | - array( |
|
339 | - 'nav-menu-theme-locations', |
|
340 | - 'add-page', |
|
341 | - 'add-custom-links', |
|
342 | - 'add-category', |
|
343 | - 'add-espresso_events', |
|
344 | - 'add-espresso_venues', |
|
345 | - 'add-espresso_event_categories', |
|
346 | - 'add-espresso_venue_categories', |
|
347 | - 'add-post-type-post', |
|
348 | - 'add-post-type-page', |
|
349 | - ) |
|
350 | - ); |
|
351 | - |
|
352 | - if (is_array($hidden_meta_boxes)) { |
|
353 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
354 | - if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
355 | - unset($hidden_meta_boxes[$key]); |
|
356 | - } |
|
357 | - } |
|
358 | - } |
|
359 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
360 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
367 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
368 | - * |
|
369 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
370 | - * addons etc. |
|
371 | - * @return void |
|
372 | - */ |
|
373 | - public function register_custom_nav_menu_boxes() |
|
374 | - { |
|
375 | - add_meta_box( |
|
376 | - 'add-extra-nav-menu-pages', |
|
377 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
378 | - array($this, 'ee_cpt_archive_pages'), |
|
379 | - 'nav-menus', |
|
380 | - 'side', |
|
381 | - 'core' |
|
382 | - ); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
389 | - * |
|
390 | - * @since 4.3.0 |
|
391 | - * @param string $link the original link generated by wp |
|
392 | - * @param int $id post id |
|
393 | - * @return string the (maybe) modified link |
|
394 | - */ |
|
395 | - public function modify_edit_post_link($link, $id) |
|
396 | - { |
|
397 | - if (! $post = get_post($id)) { |
|
398 | - return $link; |
|
399 | - } |
|
400 | - if ($post->post_type === 'espresso_attendees') { |
|
401 | - $query_args = array( |
|
402 | - 'action' => 'edit_attendee', |
|
403 | - 'post' => $id, |
|
404 | - ); |
|
405 | - return EEH_URL::add_query_args_and_nonce( |
|
406 | - $query_args, |
|
407 | - admin_url('admin.php?page=espresso_registrations') |
|
408 | - ); |
|
409 | - } |
|
410 | - return $link; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - |
|
415 | - public function ee_cpt_archive_pages() |
|
416 | - { |
|
417 | - global $nav_menu_selected_id; |
|
418 | - $db_fields = false; |
|
419 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
420 | - $current_tab = 'event-archives'; |
|
421 | - $removed_args = array( |
|
422 | - 'action', |
|
423 | - 'customlink-tab', |
|
424 | - 'edit-menu-item', |
|
425 | - 'menu-item', |
|
426 | - 'page-tab', |
|
427 | - '_wpnonce', |
|
428 | - ); |
|
429 | - ?> |
|
26 | + /** |
|
27 | + * @var EE_Admin $_instance |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
33 | + */ |
|
34 | + private $persistent_admin_notice_manager; |
|
35 | + |
|
36 | + /** |
|
37 | + * @singleton method used to instantiate class object |
|
38 | + * @return EE_Admin |
|
39 | + * @throws EE_Error |
|
40 | + */ |
|
41 | + public static function instance() |
|
42 | + { |
|
43 | + // check if class object is instantiated |
|
44 | + if (! self::$_instance instanceof EE_Admin) { |
|
45 | + self::$_instance = new self(); |
|
46 | + } |
|
47 | + return self::$_instance; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @return EE_Admin |
|
53 | + * @throws EE_Error |
|
54 | + */ |
|
55 | + public static function reset() |
|
56 | + { |
|
57 | + self::$_instance = null; |
|
58 | + return self::instance(); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * class constructor |
|
64 | + * |
|
65 | + * @throws EE_Error |
|
66 | + * @throws InvalidDataTypeException |
|
67 | + * @throws InvalidInterfaceException |
|
68 | + * @throws InvalidArgumentException |
|
69 | + */ |
|
70 | + protected function __construct() |
|
71 | + { |
|
72 | + // define global EE_Admin constants |
|
73 | + $this->_define_all_constants(); |
|
74 | + // set autoloaders for our admin page classes based on included path information |
|
75 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
76 | + // admin hooks |
|
77 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
78 | + // load EE_Request_Handler early |
|
79 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
80 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
81 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
82 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
83 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
84 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
85 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
87 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
88 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
89 | + add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage')); |
|
90 | + //reset Environment config (we only do this on admin page loads); |
|
91 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
92 | + do_action('AHEE__EE_Admin__loaded'); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * _define_all_constants |
|
99 | + * define constants that are set globally for all admin pages |
|
100 | + * |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + private function _define_all_constants() |
|
104 | + { |
|
105 | + if (! defined('EE_ADMIN_URL')) { |
|
106 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
107 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
108 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
109 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
110 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
117 | + * |
|
118 | + * @param array $links |
|
119 | + * @param string $plugin |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function filter_plugin_actions($links, $plugin) |
|
123 | + { |
|
124 | + // set $main_file in stone |
|
125 | + static $main_file; |
|
126 | + // if $main_file is not set yet |
|
127 | + if (! $main_file) { |
|
128 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
129 | + } |
|
130 | + if ($plugin === $main_file) { |
|
131 | + // compare current plugin to this one |
|
132 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
133 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
134 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
135 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
136 | + . '</a>'; |
|
137 | + array_unshift($links, $maintenance_link); |
|
138 | + } else { |
|
139 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
140 | + . esc_html__('Settings', 'event_espresso') |
|
141 | + . '</a>'; |
|
142 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
143 | + . esc_html__('Events', 'event_espresso') |
|
144 | + . '</a>'; |
|
145 | + // add before other links |
|
146 | + array_unshift($links, $org_settings_link, $events_link); |
|
147 | + } |
|
148 | + } |
|
149 | + return $links; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * _get_request |
|
155 | + * |
|
156 | + * @return void |
|
157 | + * @throws EE_Error |
|
158 | + * @throws InvalidArgumentException |
|
159 | + * @throws InvalidDataTypeException |
|
160 | + * @throws InvalidInterfaceException |
|
161 | + * @throws ReflectionException |
|
162 | + */ |
|
163 | + public function get_request() |
|
164 | + { |
|
165 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
166 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * hide_admin_pages_except_maintenance_mode |
|
173 | + * |
|
174 | + * @param array $admin_page_folder_names |
|
175 | + * @return array |
|
176 | + */ |
|
177 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
178 | + { |
|
179 | + return array( |
|
180 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
181 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
182 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
183 | + ); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
190 | + * EE_Front_Controller's init phases have run |
|
191 | + * |
|
192 | + * @return void |
|
193 | + * @throws EE_Error |
|
194 | + * @throws InvalidArgumentException |
|
195 | + * @throws InvalidDataTypeException |
|
196 | + * @throws InvalidInterfaceException |
|
197 | + * @throws ReflectionException |
|
198 | + * @throws ServiceNotFoundException |
|
199 | + */ |
|
200 | + public function init() |
|
201 | + { |
|
202 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
203 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
204 | + //ok so we want to enable the entire admin |
|
205 | + $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
206 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
207 | + ); |
|
208 | + $this->persistent_admin_notice_manager->setReturnUrl( |
|
209 | + EE_Admin_Page::add_query_args_and_nonce( |
|
210 | + array( |
|
211 | + 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
212 | + 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
213 | + ), |
|
214 | + EE_ADMIN_URL |
|
215 | + ) |
|
216 | + ); |
|
217 | + $this->maybeSetDatetimeWarningNotice(); |
|
218 | + //at a glance dashboard widget |
|
219 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
220 | + //filter for get_edit_post_link used on comments for custom post types |
|
221 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
222 | + } |
|
223 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
224 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
225 | + try { |
|
226 | + //this loads the controller for the admin pages which will setup routing etc |
|
227 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
228 | + } catch (EE_Error $e) { |
|
229 | + $e->get_error(); |
|
230 | + } |
|
231 | + } |
|
232 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
233 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
234 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
235 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
236 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
237 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * get_persistent_admin_notices |
|
243 | + * |
|
244 | + * @access public |
|
245 | + * @return void |
|
246 | + * @throws EE_Error |
|
247 | + * @throws InvalidArgumentException |
|
248 | + * @throws InvalidDataTypeException |
|
249 | + * @throws InvalidInterfaceException |
|
250 | + */ |
|
251 | + public function maybeSetDatetimeWarningNotice() |
|
252 | + { |
|
253 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
254 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
255 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
256 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
257 | + if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
258 | + && ! get_option('timezone_string') |
|
259 | + && EEM_Event::instance()->count() > 0 |
|
260 | + ) { |
|
261 | + new PersistentAdminNotice( |
|
262 | + 'datetime_fix_notice', |
|
263 | + sprintf( |
|
264 | + esc_html__( |
|
265 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + '<strong>', |
|
269 | + '</strong>', |
|
270 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
271 | + '</a>', |
|
272 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
273 | + array( |
|
274 | + 'page' => 'espresso_maintenance_settings', |
|
275 | + 'action' => 'datetime_tools' |
|
276 | + ), |
|
277 | + admin_url('admin.php') |
|
278 | + ) . '">' |
|
279 | + ), |
|
280 | + false, |
|
281 | + 'manage_options', |
|
282 | + 'datetime_fix_persistent_notice' |
|
283 | + ); |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
291 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
292 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
293 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
294 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
295 | + * |
|
296 | + * @param WP_Post $post_type WP post type object |
|
297 | + * @return WP_Post |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + */ |
|
302 | + public function remove_pages_from_nav_menu($post_type) |
|
303 | + { |
|
304 | + //if this isn't the "pages" post type let's get out |
|
305 | + if ($post_type->name !== 'page') { |
|
306 | + return $post_type; |
|
307 | + } |
|
308 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
309 | + $post_type->_default_query = array( |
|
310 | + 'post__not_in' => $critical_pages, |
|
311 | + ); |
|
312 | + return $post_type; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
319 | + * metaboxes get shown as well |
|
320 | + * |
|
321 | + * @return void |
|
322 | + */ |
|
323 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
324 | + { |
|
325 | + global $wp_meta_boxes, $pagenow; |
|
326 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
327 | + return; |
|
328 | + } |
|
329 | + $user = wp_get_current_user(); |
|
330 | + //has this been done yet? |
|
331 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
332 | + return; |
|
333 | + } |
|
334 | + |
|
335 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
336 | + $initial_meta_boxes = apply_filters( |
|
337 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
338 | + array( |
|
339 | + 'nav-menu-theme-locations', |
|
340 | + 'add-page', |
|
341 | + 'add-custom-links', |
|
342 | + 'add-category', |
|
343 | + 'add-espresso_events', |
|
344 | + 'add-espresso_venues', |
|
345 | + 'add-espresso_event_categories', |
|
346 | + 'add-espresso_venue_categories', |
|
347 | + 'add-post-type-post', |
|
348 | + 'add-post-type-page', |
|
349 | + ) |
|
350 | + ); |
|
351 | + |
|
352 | + if (is_array($hidden_meta_boxes)) { |
|
353 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
354 | + if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
355 | + unset($hidden_meta_boxes[$key]); |
|
356 | + } |
|
357 | + } |
|
358 | + } |
|
359 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
360 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
367 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
368 | + * |
|
369 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
370 | + * addons etc. |
|
371 | + * @return void |
|
372 | + */ |
|
373 | + public function register_custom_nav_menu_boxes() |
|
374 | + { |
|
375 | + add_meta_box( |
|
376 | + 'add-extra-nav-menu-pages', |
|
377 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
378 | + array($this, 'ee_cpt_archive_pages'), |
|
379 | + 'nav-menus', |
|
380 | + 'side', |
|
381 | + 'core' |
|
382 | + ); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
389 | + * |
|
390 | + * @since 4.3.0 |
|
391 | + * @param string $link the original link generated by wp |
|
392 | + * @param int $id post id |
|
393 | + * @return string the (maybe) modified link |
|
394 | + */ |
|
395 | + public function modify_edit_post_link($link, $id) |
|
396 | + { |
|
397 | + if (! $post = get_post($id)) { |
|
398 | + return $link; |
|
399 | + } |
|
400 | + if ($post->post_type === 'espresso_attendees') { |
|
401 | + $query_args = array( |
|
402 | + 'action' => 'edit_attendee', |
|
403 | + 'post' => $id, |
|
404 | + ); |
|
405 | + return EEH_URL::add_query_args_and_nonce( |
|
406 | + $query_args, |
|
407 | + admin_url('admin.php?page=espresso_registrations') |
|
408 | + ); |
|
409 | + } |
|
410 | + return $link; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + |
|
415 | + public function ee_cpt_archive_pages() |
|
416 | + { |
|
417 | + global $nav_menu_selected_id; |
|
418 | + $db_fields = false; |
|
419 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
420 | + $current_tab = 'event-archives'; |
|
421 | + $removed_args = array( |
|
422 | + 'action', |
|
423 | + 'customlink-tab', |
|
424 | + 'edit-menu-item', |
|
425 | + 'menu-item', |
|
426 | + 'page-tab', |
|
427 | + '_wpnonce', |
|
428 | + ); |
|
429 | + ?> |
|
430 | 430 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
431 | 431 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
432 | 432 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
433 | 433 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
434 | 434 | href="<?php if ($nav_menu_selected_id) { |
435 | - echo esc_url( |
|
436 | - add_query_arg( |
|
437 | - 'extra-nav-menu-pages-tab', |
|
438 | - 'event-archives', |
|
439 | - remove_query_arg($removed_args) |
|
440 | - ) |
|
441 | - ); |
|
442 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
435 | + echo esc_url( |
|
436 | + add_query_arg( |
|
437 | + 'extra-nav-menu-pages-tab', |
|
438 | + 'event-archives', |
|
439 | + remove_query_arg($removed_args) |
|
440 | + ) |
|
441 | + ); |
|
442 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
443 | 443 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
444 | 444 | </a> |
445 | 445 | </li> |
446 | 446 | </ul><!-- .posttype-tabs --> |
447 | 447 | |
448 | 448 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
449 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
450 | - ?>"> |
|
449 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
450 | + ?>"> |
|
451 | 451 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
452 | 452 | <?php |
453 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
454 | - $args['walker'] = $walker; |
|
455 | - echo walk_nav_menu_tree( |
|
456 | - array_map( |
|
457 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
458 | - $pages |
|
459 | - ), |
|
460 | - 0, |
|
461 | - (object) $args |
|
462 | - ); |
|
463 | - ?> |
|
453 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
454 | + $args['walker'] = $walker; |
|
455 | + echo walk_nav_menu_tree( |
|
456 | + array_map( |
|
457 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
458 | + $pages |
|
459 | + ), |
|
460 | + 0, |
|
461 | + (object) $args |
|
462 | + ); |
|
463 | + ?> |
|
464 | 464 | </ul> |
465 | 465 | </div><!-- /.tabs-panel --> |
466 | 466 | |
467 | 467 | <p class="button-controls"> |
468 | 468 | <span class="list-controls"> |
469 | 469 | <a href="<?php |
470 | - echo esc_url(add_query_arg( |
|
471 | - array( |
|
472 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
473 | - 'selectall' => 1, |
|
474 | - ), |
|
475 | - remove_query_arg($removed_args) |
|
476 | - )); |
|
477 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
470 | + echo esc_url(add_query_arg( |
|
471 | + array( |
|
472 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
473 | + 'selectall' => 1, |
|
474 | + ), |
|
475 | + remove_query_arg($removed_args) |
|
476 | + )); |
|
477 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
478 | 478 | </span> |
479 | 479 | <span class="add-to-menu"> |
480 | 480 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -487,486 +487,486 @@ discard block |
||
487 | 487 | |
488 | 488 | </div><!-- /.posttypediv --> |
489 | 489 | <?php |
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * Returns an array of event archive nav items. |
|
495 | - * |
|
496 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
497 | - * method we use for getting the extra nav menu items |
|
498 | - * @return array |
|
499 | - */ |
|
500 | - private function _get_extra_nav_menu_pages_items() |
|
501 | - { |
|
502 | - $menuitems[] = array( |
|
503 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
504 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
505 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
506 | - ); |
|
507 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
513 | - * the properties and converts it to the menu item object. |
|
514 | - * |
|
515 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
516 | - * @param $menu_item_values |
|
517 | - * @return stdClass |
|
518 | - */ |
|
519 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
520 | - { |
|
521 | - $menu_item = new stdClass(); |
|
522 | - $keys = array( |
|
523 | - 'ID' => 0, |
|
524 | - 'db_id' => 0, |
|
525 | - 'menu_item_parent' => 0, |
|
526 | - 'object_id' => -1, |
|
527 | - 'post_parent' => 0, |
|
528 | - 'type' => 'custom', |
|
529 | - 'object' => '', |
|
530 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
531 | - 'title' => '', |
|
532 | - 'url' => '', |
|
533 | - 'target' => '', |
|
534 | - 'attr_title' => '', |
|
535 | - 'description' => '', |
|
536 | - 'classes' => array(), |
|
537 | - 'xfn' => '', |
|
538 | - ); |
|
539 | - |
|
540 | - foreach ($keys as $key => $value) { |
|
541 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
542 | - } |
|
543 | - return $menu_item; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
549 | - * EE_Admin_Page route is called. |
|
550 | - * |
|
551 | - * @return void |
|
552 | - */ |
|
553 | - public function route_admin_request() |
|
554 | - { |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
560 | - * |
|
561 | - * @return void |
|
562 | - */ |
|
563 | - public function wp_loaded() |
|
564 | - { |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * admin_init |
|
570 | - * |
|
571 | - * @return void |
|
572 | - * @throws EE_Error |
|
573 | - * @throws InvalidArgumentException |
|
574 | - * @throws InvalidDataTypeException |
|
575 | - * @throws InvalidInterfaceException |
|
576 | - * @throws ReflectionException |
|
577 | - */ |
|
578 | - public function admin_init() |
|
579 | - { |
|
580 | - |
|
581 | - /** |
|
582 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
583 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
584 | - * - check if doing post processing. |
|
585 | - * - check if doing post processing of one of EE CPTs |
|
586 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
587 | - */ |
|
588 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
589 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
590 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
596 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
597 | - * Pages" tab in the EE General Settings Admin page. |
|
598 | - * This is for user-proofing. |
|
599 | - */ |
|
600 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
606 | - * |
|
607 | - * @param string $output Current output. |
|
608 | - * @return string |
|
609 | - * @throws InvalidArgumentException |
|
610 | - * @throws InvalidDataTypeException |
|
611 | - * @throws InvalidInterfaceException |
|
612 | - */ |
|
613 | - public function modify_dropdown_pages($output) |
|
614 | - { |
|
615 | - //get critical pages |
|
616 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
617 | - |
|
618 | - //split current output by line break for easier parsing. |
|
619 | - $split_output = explode("\n", $output); |
|
620 | - |
|
621 | - //loop through to remove any critical pages from the array. |
|
622 | - foreach ($critical_pages as $page_id) { |
|
623 | - $needle = 'value="' . $page_id . '"'; |
|
624 | - foreach ($split_output as $key => $haystack) { |
|
625 | - if (strpos($haystack, $needle) !== false) { |
|
626 | - unset($split_output[$key]); |
|
627 | - } |
|
628 | - } |
|
629 | - } |
|
630 | - //replace output with the new contents |
|
631 | - return implode("\n", $split_output); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * enqueue all admin scripts that need loaded for admin pages |
|
637 | - * |
|
638 | - * @return void |
|
639 | - */ |
|
640 | - public function enqueue_admin_scripts() |
|
641 | - { |
|
642 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
643 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
644 | - // calls. |
|
645 | - wp_enqueue_script( |
|
646 | - 'ee-inject-wp', |
|
647 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
648 | - array('jquery'), |
|
649 | - EVENT_ESPRESSO_VERSION, |
|
650 | - true |
|
651 | - ); |
|
652 | - // register cookie script for future dependencies |
|
653 | - wp_register_script( |
|
654 | - 'jquery-cookie', |
|
655 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
656 | - array('jquery'), |
|
657 | - '2.1', |
|
658 | - true |
|
659 | - ); |
|
660 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
661 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
662 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
663 | - //joyride style |
|
664 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
665 | - wp_register_style( |
|
666 | - 'ee-joyride-css', |
|
667 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
668 | - array('joyride-css'), |
|
669 | - EVENT_ESPRESSO_VERSION |
|
670 | - ); |
|
671 | - wp_register_script( |
|
672 | - 'joyride-modernizr', |
|
673 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
674 | - array(), |
|
675 | - '2.1', |
|
676 | - true |
|
677 | - ); |
|
678 | - //joyride JS |
|
679 | - wp_register_script( |
|
680 | - 'jquery-joyride', |
|
681 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
682 | - array('jquery-cookie', 'joyride-modernizr'), |
|
683 | - '2.1', |
|
684 | - true |
|
685 | - ); |
|
686 | - // wanna go for a joyride? |
|
687 | - wp_enqueue_style('ee-joyride-css'); |
|
688 | - wp_enqueue_script('jquery-joyride'); |
|
689 | - } |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * display_admin_notices |
|
695 | - * |
|
696 | - * @return void |
|
697 | - */ |
|
698 | - public function display_admin_notices() |
|
699 | - { |
|
700 | - echo EE_Error::get_notices(); |
|
701 | - } |
|
702 | - |
|
703 | - |
|
704 | - |
|
705 | - /** |
|
706 | - * @param array $elements |
|
707 | - * @return array |
|
708 | - * @throws EE_Error |
|
709 | - * @throws InvalidArgumentException |
|
710 | - * @throws InvalidDataTypeException |
|
711 | - * @throws InvalidInterfaceException |
|
712 | - */ |
|
713 | - public function dashboard_glance_items($elements) |
|
714 | - { |
|
715 | - $elements = is_array($elements) ? $elements : array($elements); |
|
716 | - $events = EEM_Event::instance()->count(); |
|
717 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
718 | - array('page' => 'espresso_events'), |
|
719 | - admin_url('admin.php') |
|
720 | - ); |
|
721 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
722 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
723 | - $registrations = EEM_Registration::instance()->count( |
|
724 | - array( |
|
725 | - array( |
|
726 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
727 | - ), |
|
728 | - ) |
|
729 | - ); |
|
730 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
731 | - array('page' => 'espresso_registrations'), |
|
732 | - admin_url('admin.php') |
|
733 | - ); |
|
734 | - $items['registrations']['text'] = sprintf( |
|
735 | - _n('%s Registration', '%s Registrations', $registrations), |
|
736 | - number_format_i18n($registrations) |
|
737 | - ); |
|
738 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
739 | - |
|
740 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
741 | - |
|
742 | - foreach ($items as $type => $item_properties) { |
|
743 | - $elements[] = sprintf( |
|
744 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
745 | - $item_properties['url'], |
|
746 | - $item_properties['title'], |
|
747 | - $item_properties['text'] |
|
748 | - ); |
|
749 | - } |
|
750 | - return $elements; |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * check_for_invalid_datetime_formats |
|
756 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
757 | - * their selected format can be parsed by PHP |
|
758 | - * |
|
759 | - * @param $value |
|
760 | - * @param $option |
|
761 | - * @throws EE_Error |
|
762 | - * @return string |
|
763 | - */ |
|
764 | - public function check_for_invalid_datetime_formats($value, $option) |
|
765 | - { |
|
766 | - // check for date_format or time_format |
|
767 | - switch ($option) { |
|
768 | - case 'date_format': |
|
769 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
770 | - break; |
|
771 | - case 'time_format': |
|
772 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
773 | - break; |
|
774 | - default: |
|
775 | - $date_time_format = false; |
|
776 | - } |
|
777 | - // do we have a date_time format to check ? |
|
778 | - if ($date_time_format) { |
|
779 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
780 | - |
|
781 | - if (is_array($error_msg)) { |
|
782 | - $msg = '<p>' |
|
783 | - . sprintf( |
|
784 | - esc_html__( |
|
785 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
786 | - 'event_espresso' |
|
787 | - ), |
|
788 | - date($date_time_format), |
|
789 | - $date_time_format |
|
790 | - ) |
|
791 | - . '</p><p><ul>'; |
|
792 | - |
|
793 | - |
|
794 | - foreach ($error_msg as $error) { |
|
795 | - $msg .= '<li>' . $error . '</li>'; |
|
796 | - } |
|
797 | - |
|
798 | - $msg .= '</ul></p><p>' |
|
799 | - . sprintf( |
|
800 | - esc_html__( |
|
801 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
802 | - 'event_espresso' |
|
803 | - ), |
|
804 | - '<span style="color:#D54E21;">', |
|
805 | - '</span>' |
|
806 | - ) |
|
807 | - . '</p>'; |
|
808 | - |
|
809 | - // trigger WP settings error |
|
810 | - add_settings_error( |
|
811 | - 'date_format', |
|
812 | - 'date_format', |
|
813 | - $msg |
|
814 | - ); |
|
815 | - |
|
816 | - // set format to something valid |
|
817 | - switch ($option) { |
|
818 | - case 'date_format': |
|
819 | - $value = 'F j, Y'; |
|
820 | - break; |
|
821 | - case 'time_format': |
|
822 | - $value = 'g:i a'; |
|
823 | - break; |
|
824 | - } |
|
825 | - } |
|
826 | - } |
|
827 | - return $value; |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
832 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
833 | - * |
|
834 | - * @param $content |
|
835 | - * @return string |
|
836 | - */ |
|
837 | - public function its_eSpresso($content) |
|
838 | - { |
|
839 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
840 | - } |
|
841 | - |
|
842 | - |
|
843 | - /** |
|
844 | - * espresso_admin_footer |
|
845 | - * |
|
846 | - * @return string |
|
847 | - */ |
|
848 | - public function espresso_admin_footer() |
|
849 | - { |
|
850 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * static method for registering ee admin page. |
|
856 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
857 | - * |
|
858 | - * @since 4.3.0 |
|
859 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
860 | - * @see EE_Register_Admin_Page::register() |
|
861 | - * @param $page_basename |
|
862 | - * @param $page_path |
|
863 | - * @param array $config |
|
864 | - * @return void |
|
865 | - * @throws EE_Error |
|
866 | - */ |
|
867 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
868 | - { |
|
869 | - EE_Error::doing_it_wrong( |
|
870 | - __METHOD__, |
|
871 | - sprintf( |
|
872 | - esc_html__( |
|
873 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
874 | - 'event_espresso' |
|
875 | - ), |
|
876 | - $page_basename |
|
877 | - ), |
|
878 | - '4.3' |
|
879 | - ); |
|
880 | - if (class_exists('EE_Register_Admin_Page')) { |
|
881 | - $config['page_path'] = $page_path; |
|
882 | - } |
|
883 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
884 | - } |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * @deprecated 4.8.41 |
|
889 | - * @param int $post_ID |
|
890 | - * @param \WP_Post $post |
|
891 | - * @return void |
|
892 | - */ |
|
893 | - public static function parse_post_content_on_save($post_ID, $post) |
|
894 | - { |
|
895 | - EE_Error::doing_it_wrong( |
|
896 | - __METHOD__, |
|
897 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
898 | - '4.8.41' |
|
899 | - ); |
|
900 | - } |
|
901 | - |
|
902 | - |
|
903 | - /** |
|
904 | - * @deprecated 4.8.41 |
|
905 | - * @param $option |
|
906 | - * @param $old_value |
|
907 | - * @param $value |
|
908 | - * @return void |
|
909 | - */ |
|
910 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
911 | - { |
|
912 | - EE_Error::doing_it_wrong( |
|
913 | - __METHOD__, |
|
914 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
915 | - '4.8.41' |
|
916 | - ); |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * @deprecated 4.9.27 |
|
923 | - * @return void |
|
924 | - */ |
|
925 | - public function get_persistent_admin_notices() |
|
926 | - { |
|
927 | - EE_Error::doing_it_wrong( |
|
928 | - __METHOD__, |
|
929 | - sprintf( |
|
930 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
931 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
932 | - ), |
|
933 | - '4.9.27' |
|
934 | - ); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - |
|
939 | - /** |
|
940 | - * @deprecated 4.9.27 |
|
941 | - * @throws InvalidInterfaceException |
|
942 | - * @throws InvalidDataTypeException |
|
943 | - * @throws DomainException |
|
944 | - */ |
|
945 | - public function dismiss_ee_nag_notice_callback() |
|
946 | - { |
|
947 | - EE_Error::doing_it_wrong( |
|
948 | - __METHOD__, |
|
949 | - sprintf( |
|
950 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
951 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
952 | - ), |
|
953 | - '4.9.27' |
|
954 | - ); |
|
955 | - $this->persistent_admin_notice_manager->dismissNotice(); |
|
956 | - } |
|
957 | - |
|
958 | - |
|
959 | - /** |
|
960 | - * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page. |
|
961 | - * @throws InvalidArgumentException |
|
962 | - * @throws InvalidDataTypeException |
|
963 | - * @throws InvalidInterfaceException |
|
964 | - */ |
|
965 | - public function hookIntoWpPluginsPage() |
|
966 | - { |
|
967 | - LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal'); |
|
968 | - LoaderFactory::getLoader() |
|
969 | - ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells') |
|
970 | - ->decafUpsells(); |
|
971 | - } |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * Returns an array of event archive nav items. |
|
495 | + * |
|
496 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
497 | + * method we use for getting the extra nav menu items |
|
498 | + * @return array |
|
499 | + */ |
|
500 | + private function _get_extra_nav_menu_pages_items() |
|
501 | + { |
|
502 | + $menuitems[] = array( |
|
503 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
504 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
505 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
506 | + ); |
|
507 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
513 | + * the properties and converts it to the menu item object. |
|
514 | + * |
|
515 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
516 | + * @param $menu_item_values |
|
517 | + * @return stdClass |
|
518 | + */ |
|
519 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
520 | + { |
|
521 | + $menu_item = new stdClass(); |
|
522 | + $keys = array( |
|
523 | + 'ID' => 0, |
|
524 | + 'db_id' => 0, |
|
525 | + 'menu_item_parent' => 0, |
|
526 | + 'object_id' => -1, |
|
527 | + 'post_parent' => 0, |
|
528 | + 'type' => 'custom', |
|
529 | + 'object' => '', |
|
530 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
531 | + 'title' => '', |
|
532 | + 'url' => '', |
|
533 | + 'target' => '', |
|
534 | + 'attr_title' => '', |
|
535 | + 'description' => '', |
|
536 | + 'classes' => array(), |
|
537 | + 'xfn' => '', |
|
538 | + ); |
|
539 | + |
|
540 | + foreach ($keys as $key => $value) { |
|
541 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
542 | + } |
|
543 | + return $menu_item; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
549 | + * EE_Admin_Page route is called. |
|
550 | + * |
|
551 | + * @return void |
|
552 | + */ |
|
553 | + public function route_admin_request() |
|
554 | + { |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
560 | + * |
|
561 | + * @return void |
|
562 | + */ |
|
563 | + public function wp_loaded() |
|
564 | + { |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * admin_init |
|
570 | + * |
|
571 | + * @return void |
|
572 | + * @throws EE_Error |
|
573 | + * @throws InvalidArgumentException |
|
574 | + * @throws InvalidDataTypeException |
|
575 | + * @throws InvalidInterfaceException |
|
576 | + * @throws ReflectionException |
|
577 | + */ |
|
578 | + public function admin_init() |
|
579 | + { |
|
580 | + |
|
581 | + /** |
|
582 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
583 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
584 | + * - check if doing post processing. |
|
585 | + * - check if doing post processing of one of EE CPTs |
|
586 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
587 | + */ |
|
588 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
589 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
590 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
596 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
597 | + * Pages" tab in the EE General Settings Admin page. |
|
598 | + * This is for user-proofing. |
|
599 | + */ |
|
600 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
606 | + * |
|
607 | + * @param string $output Current output. |
|
608 | + * @return string |
|
609 | + * @throws InvalidArgumentException |
|
610 | + * @throws InvalidDataTypeException |
|
611 | + * @throws InvalidInterfaceException |
|
612 | + */ |
|
613 | + public function modify_dropdown_pages($output) |
|
614 | + { |
|
615 | + //get critical pages |
|
616 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
617 | + |
|
618 | + //split current output by line break for easier parsing. |
|
619 | + $split_output = explode("\n", $output); |
|
620 | + |
|
621 | + //loop through to remove any critical pages from the array. |
|
622 | + foreach ($critical_pages as $page_id) { |
|
623 | + $needle = 'value="' . $page_id . '"'; |
|
624 | + foreach ($split_output as $key => $haystack) { |
|
625 | + if (strpos($haystack, $needle) !== false) { |
|
626 | + unset($split_output[$key]); |
|
627 | + } |
|
628 | + } |
|
629 | + } |
|
630 | + //replace output with the new contents |
|
631 | + return implode("\n", $split_output); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * enqueue all admin scripts that need loaded for admin pages |
|
637 | + * |
|
638 | + * @return void |
|
639 | + */ |
|
640 | + public function enqueue_admin_scripts() |
|
641 | + { |
|
642 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
643 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
644 | + // calls. |
|
645 | + wp_enqueue_script( |
|
646 | + 'ee-inject-wp', |
|
647 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
648 | + array('jquery'), |
|
649 | + EVENT_ESPRESSO_VERSION, |
|
650 | + true |
|
651 | + ); |
|
652 | + // register cookie script for future dependencies |
|
653 | + wp_register_script( |
|
654 | + 'jquery-cookie', |
|
655 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
656 | + array('jquery'), |
|
657 | + '2.1', |
|
658 | + true |
|
659 | + ); |
|
660 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
661 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
662 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
663 | + //joyride style |
|
664 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
665 | + wp_register_style( |
|
666 | + 'ee-joyride-css', |
|
667 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
668 | + array('joyride-css'), |
|
669 | + EVENT_ESPRESSO_VERSION |
|
670 | + ); |
|
671 | + wp_register_script( |
|
672 | + 'joyride-modernizr', |
|
673 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
674 | + array(), |
|
675 | + '2.1', |
|
676 | + true |
|
677 | + ); |
|
678 | + //joyride JS |
|
679 | + wp_register_script( |
|
680 | + 'jquery-joyride', |
|
681 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
682 | + array('jquery-cookie', 'joyride-modernizr'), |
|
683 | + '2.1', |
|
684 | + true |
|
685 | + ); |
|
686 | + // wanna go for a joyride? |
|
687 | + wp_enqueue_style('ee-joyride-css'); |
|
688 | + wp_enqueue_script('jquery-joyride'); |
|
689 | + } |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * display_admin_notices |
|
695 | + * |
|
696 | + * @return void |
|
697 | + */ |
|
698 | + public function display_admin_notices() |
|
699 | + { |
|
700 | + echo EE_Error::get_notices(); |
|
701 | + } |
|
702 | + |
|
703 | + |
|
704 | + |
|
705 | + /** |
|
706 | + * @param array $elements |
|
707 | + * @return array |
|
708 | + * @throws EE_Error |
|
709 | + * @throws InvalidArgumentException |
|
710 | + * @throws InvalidDataTypeException |
|
711 | + * @throws InvalidInterfaceException |
|
712 | + */ |
|
713 | + public function dashboard_glance_items($elements) |
|
714 | + { |
|
715 | + $elements = is_array($elements) ? $elements : array($elements); |
|
716 | + $events = EEM_Event::instance()->count(); |
|
717 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
718 | + array('page' => 'espresso_events'), |
|
719 | + admin_url('admin.php') |
|
720 | + ); |
|
721 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
722 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
723 | + $registrations = EEM_Registration::instance()->count( |
|
724 | + array( |
|
725 | + array( |
|
726 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
727 | + ), |
|
728 | + ) |
|
729 | + ); |
|
730 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
731 | + array('page' => 'espresso_registrations'), |
|
732 | + admin_url('admin.php') |
|
733 | + ); |
|
734 | + $items['registrations']['text'] = sprintf( |
|
735 | + _n('%s Registration', '%s Registrations', $registrations), |
|
736 | + number_format_i18n($registrations) |
|
737 | + ); |
|
738 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
739 | + |
|
740 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
741 | + |
|
742 | + foreach ($items as $type => $item_properties) { |
|
743 | + $elements[] = sprintf( |
|
744 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
745 | + $item_properties['url'], |
|
746 | + $item_properties['title'], |
|
747 | + $item_properties['text'] |
|
748 | + ); |
|
749 | + } |
|
750 | + return $elements; |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * check_for_invalid_datetime_formats |
|
756 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
757 | + * their selected format can be parsed by PHP |
|
758 | + * |
|
759 | + * @param $value |
|
760 | + * @param $option |
|
761 | + * @throws EE_Error |
|
762 | + * @return string |
|
763 | + */ |
|
764 | + public function check_for_invalid_datetime_formats($value, $option) |
|
765 | + { |
|
766 | + // check for date_format or time_format |
|
767 | + switch ($option) { |
|
768 | + case 'date_format': |
|
769 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
770 | + break; |
|
771 | + case 'time_format': |
|
772 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
773 | + break; |
|
774 | + default: |
|
775 | + $date_time_format = false; |
|
776 | + } |
|
777 | + // do we have a date_time format to check ? |
|
778 | + if ($date_time_format) { |
|
779 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
780 | + |
|
781 | + if (is_array($error_msg)) { |
|
782 | + $msg = '<p>' |
|
783 | + . sprintf( |
|
784 | + esc_html__( |
|
785 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
786 | + 'event_espresso' |
|
787 | + ), |
|
788 | + date($date_time_format), |
|
789 | + $date_time_format |
|
790 | + ) |
|
791 | + . '</p><p><ul>'; |
|
792 | + |
|
793 | + |
|
794 | + foreach ($error_msg as $error) { |
|
795 | + $msg .= '<li>' . $error . '</li>'; |
|
796 | + } |
|
797 | + |
|
798 | + $msg .= '</ul></p><p>' |
|
799 | + . sprintf( |
|
800 | + esc_html__( |
|
801 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
802 | + 'event_espresso' |
|
803 | + ), |
|
804 | + '<span style="color:#D54E21;">', |
|
805 | + '</span>' |
|
806 | + ) |
|
807 | + . '</p>'; |
|
808 | + |
|
809 | + // trigger WP settings error |
|
810 | + add_settings_error( |
|
811 | + 'date_format', |
|
812 | + 'date_format', |
|
813 | + $msg |
|
814 | + ); |
|
815 | + |
|
816 | + // set format to something valid |
|
817 | + switch ($option) { |
|
818 | + case 'date_format': |
|
819 | + $value = 'F j, Y'; |
|
820 | + break; |
|
821 | + case 'time_format': |
|
822 | + $value = 'g:i a'; |
|
823 | + break; |
|
824 | + } |
|
825 | + } |
|
826 | + } |
|
827 | + return $value; |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
833 | + * |
|
834 | + * @param $content |
|
835 | + * @return string |
|
836 | + */ |
|
837 | + public function its_eSpresso($content) |
|
838 | + { |
|
839 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
840 | + } |
|
841 | + |
|
842 | + |
|
843 | + /** |
|
844 | + * espresso_admin_footer |
|
845 | + * |
|
846 | + * @return string |
|
847 | + */ |
|
848 | + public function espresso_admin_footer() |
|
849 | + { |
|
850 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * static method for registering ee admin page. |
|
856 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
857 | + * |
|
858 | + * @since 4.3.0 |
|
859 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
860 | + * @see EE_Register_Admin_Page::register() |
|
861 | + * @param $page_basename |
|
862 | + * @param $page_path |
|
863 | + * @param array $config |
|
864 | + * @return void |
|
865 | + * @throws EE_Error |
|
866 | + */ |
|
867 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
868 | + { |
|
869 | + EE_Error::doing_it_wrong( |
|
870 | + __METHOD__, |
|
871 | + sprintf( |
|
872 | + esc_html__( |
|
873 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
874 | + 'event_espresso' |
|
875 | + ), |
|
876 | + $page_basename |
|
877 | + ), |
|
878 | + '4.3' |
|
879 | + ); |
|
880 | + if (class_exists('EE_Register_Admin_Page')) { |
|
881 | + $config['page_path'] = $page_path; |
|
882 | + } |
|
883 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
884 | + } |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * @deprecated 4.8.41 |
|
889 | + * @param int $post_ID |
|
890 | + * @param \WP_Post $post |
|
891 | + * @return void |
|
892 | + */ |
|
893 | + public static function parse_post_content_on_save($post_ID, $post) |
|
894 | + { |
|
895 | + EE_Error::doing_it_wrong( |
|
896 | + __METHOD__, |
|
897 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
898 | + '4.8.41' |
|
899 | + ); |
|
900 | + } |
|
901 | + |
|
902 | + |
|
903 | + /** |
|
904 | + * @deprecated 4.8.41 |
|
905 | + * @param $option |
|
906 | + * @param $old_value |
|
907 | + * @param $value |
|
908 | + * @return void |
|
909 | + */ |
|
910 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
911 | + { |
|
912 | + EE_Error::doing_it_wrong( |
|
913 | + __METHOD__, |
|
914 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
915 | + '4.8.41' |
|
916 | + ); |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * @deprecated 4.9.27 |
|
923 | + * @return void |
|
924 | + */ |
|
925 | + public function get_persistent_admin_notices() |
|
926 | + { |
|
927 | + EE_Error::doing_it_wrong( |
|
928 | + __METHOD__, |
|
929 | + sprintf( |
|
930 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
931 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
932 | + ), |
|
933 | + '4.9.27' |
|
934 | + ); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + |
|
939 | + /** |
|
940 | + * @deprecated 4.9.27 |
|
941 | + * @throws InvalidInterfaceException |
|
942 | + * @throws InvalidDataTypeException |
|
943 | + * @throws DomainException |
|
944 | + */ |
|
945 | + public function dismiss_ee_nag_notice_callback() |
|
946 | + { |
|
947 | + EE_Error::doing_it_wrong( |
|
948 | + __METHOD__, |
|
949 | + sprintf( |
|
950 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
951 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
952 | + ), |
|
953 | + '4.9.27' |
|
954 | + ); |
|
955 | + $this->persistent_admin_notice_manager->dismissNotice(); |
|
956 | + } |
|
957 | + |
|
958 | + |
|
959 | + /** |
|
960 | + * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page. |
|
961 | + * @throws InvalidArgumentException |
|
962 | + * @throws InvalidDataTypeException |
|
963 | + * @throws InvalidInterfaceException |
|
964 | + */ |
|
965 | + public function hookIntoWpPluginsPage() |
|
966 | + { |
|
967 | + LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal'); |
|
968 | + LoaderFactory::getLoader() |
|
969 | + ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells') |
|
970 | + ->decafUpsells(); |
|
971 | + } |
|
972 | 972 | } |
@@ -22,369 +22,369 @@ |
||
22 | 22 | class EE_Request implements LegacyRequestInterface, InterminableInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var RequestInterface $request |
|
27 | - */ |
|
28 | - private $request; |
|
29 | - |
|
30 | - /** |
|
31 | - * whether current request is for the admin but NOT via AJAX |
|
32 | - * |
|
33 | - * @var boolean $admin |
|
34 | - */ |
|
35 | - public $admin = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * whether current request is via AJAX |
|
39 | - * |
|
40 | - * @var boolean $ajax |
|
41 | - */ |
|
42 | - public $ajax = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * whether current request is via AJAX from the frontend of the site |
|
46 | - * |
|
47 | - * @var boolean $front_ajax |
|
48 | - */ |
|
49 | - public $front_ajax = false; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @deprecated 4.9.53 |
|
54 | - * @param array $get |
|
55 | - * @param array $post |
|
56 | - * @param array $cookie |
|
57 | - * @param array $server |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - array $get = array(), |
|
61 | - array $post = array(), |
|
62 | - array $cookie = array(), |
|
63 | - array $server = array() |
|
64 | - ) { |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @return RequestInterface |
|
70 | - * @throws InvalidArgumentException |
|
71 | - * @throws InvalidInterfaceException |
|
72 | - * @throws InvalidDataTypeException |
|
73 | - */ |
|
74 | - private function request() |
|
75 | - { |
|
76 | - if($this->request instanceof RequestInterface){ |
|
77 | - return $this->request; |
|
78 | - } |
|
79 | - $loader = LoaderFactory::getLoader(); |
|
80 | - $this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
81 | - return $this->request; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param RequestInterface $request |
|
87 | - */ |
|
88 | - public function setRequest(RequestInterface $request) |
|
89 | - { |
|
90 | - $this->request = $request; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @deprecated 4.9.53 |
|
97 | - * @return array |
|
98 | - * @throws InvalidArgumentException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws InvalidInterfaceException |
|
101 | - */ |
|
102 | - public function get_params() |
|
103 | - { |
|
104 | - return $this->request()->getParams(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @deprecated 4.9.53 |
|
111 | - * @return array |
|
112 | - * @throws InvalidArgumentException |
|
113 | - * @throws InvalidDataTypeException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - */ |
|
116 | - public function post_params() |
|
117 | - { |
|
118 | - return $this->request()->postParams(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @deprecated 4.9.53 |
|
125 | - * @return array |
|
126 | - * @throws InvalidArgumentException |
|
127 | - * @throws InvalidDataTypeException |
|
128 | - * @throws InvalidInterfaceException |
|
129 | - */ |
|
130 | - public function cookie_params() |
|
131 | - { |
|
132 | - return $this->request()->cookieParams(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @deprecated 4.9.53 |
|
138 | - * @return array |
|
139 | - * @throws InvalidArgumentException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - */ |
|
143 | - public function server_params() |
|
144 | - { |
|
145 | - return $this->request()->serverParams(); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * returns contents of $_REQUEST |
|
152 | - * |
|
153 | - * @deprecated 4.9.53 |
|
154 | - * @return array |
|
155 | - * @throws InvalidArgumentException |
|
156 | - * @throws InvalidDataTypeException |
|
157 | - * @throws InvalidInterfaceException |
|
158 | - */ |
|
159 | - public function params() |
|
160 | - { |
|
161 | - return $this->request()->requestParams(); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @deprecated 4.9.53 |
|
168 | - * @param $key |
|
169 | - * @param $value |
|
170 | - * @param bool $override_ee |
|
171 | - * @return void |
|
172 | - * @throws InvalidArgumentException |
|
173 | - * @throws InvalidDataTypeException |
|
174 | - * @throws InvalidInterfaceException |
|
175 | - */ |
|
176 | - public function set($key, $value, $override_ee = false) |
|
177 | - { |
|
178 | - $this->request()->setRequestParam($key, $value, $override_ee); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * returns the value for a request param if the given key exists |
|
185 | - * |
|
186 | - * @deprecated 4.9.53 |
|
187 | - * @param $key |
|
188 | - * @param null $default |
|
189 | - * @return mixed |
|
190 | - * @throws InvalidArgumentException |
|
191 | - * @throws InvalidDataTypeException |
|
192 | - * @throws InvalidInterfaceException |
|
193 | - */ |
|
194 | - public function get($key, $default = null) |
|
195 | - { |
|
196 | - return $this->request()->getRequestParam($key, $default); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * check if param exists |
|
203 | - * |
|
204 | - * @deprecated 4.9.53 |
|
205 | - * @param $key |
|
206 | - * @return bool |
|
207 | - * @throws InvalidArgumentException |
|
208 | - * @throws InvalidDataTypeException |
|
209 | - * @throws InvalidInterfaceException |
|
210 | - */ |
|
211 | - public function is_set($key) |
|
212 | - { |
|
213 | - return $this->request()->requestParamIsSet($key); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * remove param |
|
219 | - * |
|
220 | - * @deprecated 4.9.53 |
|
221 | - * @param $key |
|
222 | - * @param bool $unset_from_global_too |
|
223 | - * @throws InvalidArgumentException |
|
224 | - * @throws InvalidDataTypeException |
|
225 | - * @throws InvalidInterfaceException |
|
226 | - */ |
|
227 | - public function un_set($key, $unset_from_global_too = false) |
|
228 | - { |
|
229 | - $this->request()->unSetRequestParam($key, $unset_from_global_too); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * @deprecated 4.9.53 |
|
236 | - * @return string |
|
237 | - * @throws InvalidArgumentException |
|
238 | - * @throws InvalidDataTypeException |
|
239 | - * @throws InvalidInterfaceException |
|
240 | - */ |
|
241 | - public function ip_address() |
|
242 | - { |
|
243 | - return $this->request()->ipAddress(); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @deprecated 4.9.53 |
|
249 | - * @return bool |
|
250 | - * @throws InvalidArgumentException |
|
251 | - * @throws InvalidDataTypeException |
|
252 | - * @throws InvalidInterfaceException |
|
253 | - */ |
|
254 | - public function isAdmin() |
|
255 | - { |
|
256 | - return $this->request()->isAdmin(); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * @deprecated 4.9.53 |
|
262 | - * @return mixed |
|
263 | - * @throws InvalidArgumentException |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - * @throws InvalidInterfaceException |
|
266 | - */ |
|
267 | - public function isAjax() |
|
268 | - { |
|
269 | - return $this->request()->isAjax(); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @deprecated 4.9.53 |
|
275 | - * @return mixed |
|
276 | - * @throws InvalidArgumentException |
|
277 | - * @throws InvalidDataTypeException |
|
278 | - * @throws InvalidInterfaceException |
|
279 | - */ |
|
280 | - public function isFrontAjax() |
|
281 | - { |
|
282 | - return $this->request()->isFrontAjax(); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @deprecated 4.9.53 |
|
288 | - * @return mixed|string |
|
289 | - * @throws InvalidArgumentException |
|
290 | - * @throws InvalidDataTypeException |
|
291 | - * @throws InvalidInterfaceException |
|
292 | - */ |
|
293 | - public function requestUri() |
|
294 | - { |
|
295 | - return $this->request()->requestUri(); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @deprecated 4.9.53 |
|
301 | - * @return string |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - */ |
|
306 | - public function userAgent() |
|
307 | - { |
|
308 | - return $this->request()->userAgent(); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @deprecated 4.9.53 |
|
314 | - * @param string $user_agent |
|
315 | - * @throws InvalidArgumentException |
|
316 | - * @throws InvalidDataTypeException |
|
317 | - * @throws InvalidInterfaceException |
|
318 | - */ |
|
319 | - public function setUserAgent($user_agent = '') |
|
320 | - { |
|
321 | - $this->request()->setUserAgent($user_agent); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * @deprecated 4.9.53 |
|
327 | - * @return bool |
|
328 | - * @throws InvalidArgumentException |
|
329 | - * @throws InvalidDataTypeException |
|
330 | - * @throws InvalidInterfaceException |
|
331 | - */ |
|
332 | - public function isBot() |
|
333 | - { |
|
334 | - return $this->request()->isBot(); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @deprecated 4.9.53 |
|
340 | - * @param bool $is_bot |
|
341 | - * @throws InvalidArgumentException |
|
342 | - * @throws InvalidDataTypeException |
|
343 | - * @throws InvalidInterfaceException |
|
344 | - */ |
|
345 | - public function setIsBot($is_bot) |
|
346 | - { |
|
347 | - $this->request()->setIsBot($is_bot); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
353 | - * and return the value for the first match found |
|
354 | - * wildcards can be either of the following: |
|
355 | - * ? to represent a single character of any type |
|
356 | - * * to represent one or more characters of any type |
|
357 | - * |
|
358 | - * @param string $pattern |
|
359 | - * @param null|mixed $default |
|
360 | - * @return false|int |
|
361 | - * @throws InvalidArgumentException |
|
362 | - * @throws InvalidInterfaceException |
|
363 | - * @throws InvalidDataTypeException |
|
364 | - */ |
|
365 | - public function getMatch($pattern, $default = null) |
|
366 | - { |
|
367 | - return $this->request()->getMatch($pattern, $default); |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
373 | - * wildcards can be either of the following: |
|
374 | - * ? to represent a single character of any type |
|
375 | - * * to represent one or more characters of any type |
|
376 | - * returns true if a match is found or false if not |
|
377 | - * |
|
378 | - * @param string $pattern |
|
379 | - * @return false|int |
|
380 | - * @throws InvalidArgumentException |
|
381 | - * @throws InvalidInterfaceException |
|
382 | - * @throws InvalidDataTypeException |
|
383 | - */ |
|
384 | - public function matches($pattern) |
|
385 | - { |
|
386 | - return $this->request()->matches($pattern); |
|
387 | - } |
|
25 | + /** |
|
26 | + * @var RequestInterface $request |
|
27 | + */ |
|
28 | + private $request; |
|
29 | + |
|
30 | + /** |
|
31 | + * whether current request is for the admin but NOT via AJAX |
|
32 | + * |
|
33 | + * @var boolean $admin |
|
34 | + */ |
|
35 | + public $admin = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * whether current request is via AJAX |
|
39 | + * |
|
40 | + * @var boolean $ajax |
|
41 | + */ |
|
42 | + public $ajax = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * whether current request is via AJAX from the frontend of the site |
|
46 | + * |
|
47 | + * @var boolean $front_ajax |
|
48 | + */ |
|
49 | + public $front_ajax = false; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @deprecated 4.9.53 |
|
54 | + * @param array $get |
|
55 | + * @param array $post |
|
56 | + * @param array $cookie |
|
57 | + * @param array $server |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + array $get = array(), |
|
61 | + array $post = array(), |
|
62 | + array $cookie = array(), |
|
63 | + array $server = array() |
|
64 | + ) { |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @return RequestInterface |
|
70 | + * @throws InvalidArgumentException |
|
71 | + * @throws InvalidInterfaceException |
|
72 | + * @throws InvalidDataTypeException |
|
73 | + */ |
|
74 | + private function request() |
|
75 | + { |
|
76 | + if($this->request instanceof RequestInterface){ |
|
77 | + return $this->request; |
|
78 | + } |
|
79 | + $loader = LoaderFactory::getLoader(); |
|
80 | + $this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
81 | + return $this->request; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param RequestInterface $request |
|
87 | + */ |
|
88 | + public function setRequest(RequestInterface $request) |
|
89 | + { |
|
90 | + $this->request = $request; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @deprecated 4.9.53 |
|
97 | + * @return array |
|
98 | + * @throws InvalidArgumentException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws InvalidInterfaceException |
|
101 | + */ |
|
102 | + public function get_params() |
|
103 | + { |
|
104 | + return $this->request()->getParams(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @deprecated 4.9.53 |
|
111 | + * @return array |
|
112 | + * @throws InvalidArgumentException |
|
113 | + * @throws InvalidDataTypeException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + */ |
|
116 | + public function post_params() |
|
117 | + { |
|
118 | + return $this->request()->postParams(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @deprecated 4.9.53 |
|
125 | + * @return array |
|
126 | + * @throws InvalidArgumentException |
|
127 | + * @throws InvalidDataTypeException |
|
128 | + * @throws InvalidInterfaceException |
|
129 | + */ |
|
130 | + public function cookie_params() |
|
131 | + { |
|
132 | + return $this->request()->cookieParams(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @deprecated 4.9.53 |
|
138 | + * @return array |
|
139 | + * @throws InvalidArgumentException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + */ |
|
143 | + public function server_params() |
|
144 | + { |
|
145 | + return $this->request()->serverParams(); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * returns contents of $_REQUEST |
|
152 | + * |
|
153 | + * @deprecated 4.9.53 |
|
154 | + * @return array |
|
155 | + * @throws InvalidArgumentException |
|
156 | + * @throws InvalidDataTypeException |
|
157 | + * @throws InvalidInterfaceException |
|
158 | + */ |
|
159 | + public function params() |
|
160 | + { |
|
161 | + return $this->request()->requestParams(); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @deprecated 4.9.53 |
|
168 | + * @param $key |
|
169 | + * @param $value |
|
170 | + * @param bool $override_ee |
|
171 | + * @return void |
|
172 | + * @throws InvalidArgumentException |
|
173 | + * @throws InvalidDataTypeException |
|
174 | + * @throws InvalidInterfaceException |
|
175 | + */ |
|
176 | + public function set($key, $value, $override_ee = false) |
|
177 | + { |
|
178 | + $this->request()->setRequestParam($key, $value, $override_ee); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * returns the value for a request param if the given key exists |
|
185 | + * |
|
186 | + * @deprecated 4.9.53 |
|
187 | + * @param $key |
|
188 | + * @param null $default |
|
189 | + * @return mixed |
|
190 | + * @throws InvalidArgumentException |
|
191 | + * @throws InvalidDataTypeException |
|
192 | + * @throws InvalidInterfaceException |
|
193 | + */ |
|
194 | + public function get($key, $default = null) |
|
195 | + { |
|
196 | + return $this->request()->getRequestParam($key, $default); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * check if param exists |
|
203 | + * |
|
204 | + * @deprecated 4.9.53 |
|
205 | + * @param $key |
|
206 | + * @return bool |
|
207 | + * @throws InvalidArgumentException |
|
208 | + * @throws InvalidDataTypeException |
|
209 | + * @throws InvalidInterfaceException |
|
210 | + */ |
|
211 | + public function is_set($key) |
|
212 | + { |
|
213 | + return $this->request()->requestParamIsSet($key); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * remove param |
|
219 | + * |
|
220 | + * @deprecated 4.9.53 |
|
221 | + * @param $key |
|
222 | + * @param bool $unset_from_global_too |
|
223 | + * @throws InvalidArgumentException |
|
224 | + * @throws InvalidDataTypeException |
|
225 | + * @throws InvalidInterfaceException |
|
226 | + */ |
|
227 | + public function un_set($key, $unset_from_global_too = false) |
|
228 | + { |
|
229 | + $this->request()->unSetRequestParam($key, $unset_from_global_too); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * @deprecated 4.9.53 |
|
236 | + * @return string |
|
237 | + * @throws InvalidArgumentException |
|
238 | + * @throws InvalidDataTypeException |
|
239 | + * @throws InvalidInterfaceException |
|
240 | + */ |
|
241 | + public function ip_address() |
|
242 | + { |
|
243 | + return $this->request()->ipAddress(); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @deprecated 4.9.53 |
|
249 | + * @return bool |
|
250 | + * @throws InvalidArgumentException |
|
251 | + * @throws InvalidDataTypeException |
|
252 | + * @throws InvalidInterfaceException |
|
253 | + */ |
|
254 | + public function isAdmin() |
|
255 | + { |
|
256 | + return $this->request()->isAdmin(); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * @deprecated 4.9.53 |
|
262 | + * @return mixed |
|
263 | + * @throws InvalidArgumentException |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + * @throws InvalidInterfaceException |
|
266 | + */ |
|
267 | + public function isAjax() |
|
268 | + { |
|
269 | + return $this->request()->isAjax(); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @deprecated 4.9.53 |
|
275 | + * @return mixed |
|
276 | + * @throws InvalidArgumentException |
|
277 | + * @throws InvalidDataTypeException |
|
278 | + * @throws InvalidInterfaceException |
|
279 | + */ |
|
280 | + public function isFrontAjax() |
|
281 | + { |
|
282 | + return $this->request()->isFrontAjax(); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @deprecated 4.9.53 |
|
288 | + * @return mixed|string |
|
289 | + * @throws InvalidArgumentException |
|
290 | + * @throws InvalidDataTypeException |
|
291 | + * @throws InvalidInterfaceException |
|
292 | + */ |
|
293 | + public function requestUri() |
|
294 | + { |
|
295 | + return $this->request()->requestUri(); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @deprecated 4.9.53 |
|
301 | + * @return string |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + */ |
|
306 | + public function userAgent() |
|
307 | + { |
|
308 | + return $this->request()->userAgent(); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @deprecated 4.9.53 |
|
314 | + * @param string $user_agent |
|
315 | + * @throws InvalidArgumentException |
|
316 | + * @throws InvalidDataTypeException |
|
317 | + * @throws InvalidInterfaceException |
|
318 | + */ |
|
319 | + public function setUserAgent($user_agent = '') |
|
320 | + { |
|
321 | + $this->request()->setUserAgent($user_agent); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @deprecated 4.9.53 |
|
327 | + * @return bool |
|
328 | + * @throws InvalidArgumentException |
|
329 | + * @throws InvalidDataTypeException |
|
330 | + * @throws InvalidInterfaceException |
|
331 | + */ |
|
332 | + public function isBot() |
|
333 | + { |
|
334 | + return $this->request()->isBot(); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @deprecated 4.9.53 |
|
340 | + * @param bool $is_bot |
|
341 | + * @throws InvalidArgumentException |
|
342 | + * @throws InvalidDataTypeException |
|
343 | + * @throws InvalidInterfaceException |
|
344 | + */ |
|
345 | + public function setIsBot($is_bot) |
|
346 | + { |
|
347 | + $this->request()->setIsBot($is_bot); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
353 | + * and return the value for the first match found |
|
354 | + * wildcards can be either of the following: |
|
355 | + * ? to represent a single character of any type |
|
356 | + * * to represent one or more characters of any type |
|
357 | + * |
|
358 | + * @param string $pattern |
|
359 | + * @param null|mixed $default |
|
360 | + * @return false|int |
|
361 | + * @throws InvalidArgumentException |
|
362 | + * @throws InvalidInterfaceException |
|
363 | + * @throws InvalidDataTypeException |
|
364 | + */ |
|
365 | + public function getMatch($pattern, $default = null) |
|
366 | + { |
|
367 | + return $this->request()->getMatch($pattern, $default); |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
373 | + * wildcards can be either of the following: |
|
374 | + * ? to represent a single character of any type |
|
375 | + * * to represent one or more characters of any type |
|
376 | + * returns true if a match is found or false if not |
|
377 | + * |
|
378 | + * @param string $pattern |
|
379 | + * @return false|int |
|
380 | + * @throws InvalidArgumentException |
|
381 | + * @throws InvalidInterfaceException |
|
382 | + * @throws InvalidDataTypeException |
|
383 | + */ |
|
384 | + public function matches($pattern) |
|
385 | + { |
|
386 | + return $this->request()->matches($pattern); |
|
387 | + } |
|
388 | 388 | |
389 | 389 | |
390 | 390 | } |
@@ -47,404 +47,404 @@ |
||
47 | 47 | class EEM_Line_Item extends EEM_Base |
48 | 48 | { |
49 | 49 | |
50 | - /** |
|
51 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
52 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
53 | - * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
54 | - */ |
|
55 | - const type_tax_sub_total = 'tax-sub-total'; |
|
56 | - |
|
57 | - /** |
|
58 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
59 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
60 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
61 | - */ |
|
62 | - const type_tax = 'tax'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Indicating individual items purchased, or discounts or surcharges. |
|
66 | - * The sum of all the regular line items plus the tax items should equal |
|
67 | - * the grand total. |
|
68 | - * Possible children are sub-line-items and cancellations. |
|
69 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
70 | - * LIN_totals. Its LIN_percent = 0. |
|
71 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
72 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
73 | - */ |
|
74 | - const type_line_item = 'line-item'; |
|
75 | - |
|
76 | - /** |
|
77 | - * Line item indicating all the factors that make a single line item. |
|
78 | - * Sub-line items should have NO children line items. |
|
79 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
80 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
81 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
82 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
83 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
84 | - */ |
|
85 | - const type_sub_line_item = 'sub-item'; |
|
86 | - |
|
87 | - /** |
|
88 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
89 | - * Direct children should be event subtotals. |
|
90 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
91 | - * |
|
92 | - */ |
|
93 | - const type_sub_total = 'sub-total'; |
|
94 | - |
|
95 | - /** |
|
96 | - * Line item for the grand total of an order. Its direct children |
|
97 | - * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item |
|
98 | - * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of |
|
99 | - * the entire order's mount. |
|
100 | - */ |
|
101 | - const type_total = 'total'; |
|
102 | - |
|
103 | - /** |
|
104 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
105 | - * should be created, indicating the quantity that were cancelled |
|
106 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
107 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
108 | - * cancelled, and only one remains). |
|
109 | - * When items are refunded, a cancellation line item should be made, which points |
|
110 | - * to teh payment model object which actually refunded the payment. |
|
111 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
112 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
113 | - * Their LIN_percent should be 0. |
|
114 | - */ |
|
115 | - const type_cancellation = 'cancellation'; |
|
116 | - |
|
117 | - // private instance of the EEM_Line_Item object |
|
118 | - protected static $_instance = NULL; |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * private constructor to prevent direct creation |
|
123 | - * @Constructor |
|
124 | - * @access protected |
|
125 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
126 | - * @return \EEM_Line_Item |
|
127 | - */ |
|
128 | - protected function __construct($timezone) |
|
129 | - { |
|
130 | - $this->singular_item = __('Line Item', 'event_espresso'); |
|
131 | - $this->plural_item = __('Line Items', 'event_espresso'); |
|
132 | - |
|
133 | - $this->_tables = array( |
|
134 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
135 | - ); |
|
136 | - $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
137 | - $this->_fields = array( |
|
138 | - 'Line_Item' => array( |
|
139 | - 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
140 | - 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
141 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
142 | - 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
143 | - 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
144 | - 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
145 | - 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
146 | - 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
147 | - 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
148 | - 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
149 | - 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
150 | - 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
151 | - 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
152 | - self::type_line_item => __("Line Item", "event_espresso"), |
|
153 | - self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
154 | - self::type_sub_total => __("Subtotal", "event_espresso"), |
|
155 | - self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
156 | - self::type_tax => __("Tax", "event_espresso"), |
|
157 | - self::type_total => __("Total", "event_espresso"), |
|
158 | - self::type_cancellation => __('Cancellation', 'event_espresso') |
|
159 | - ) |
|
160 | - ), |
|
161 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
162 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
163 | - 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
164 | - ) |
|
165 | - ); |
|
166 | - $this->_model_relations = array( |
|
167 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
168 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
169 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
170 | - 'Event' => new EE_Belongs_To_Any_Relation() |
|
171 | - ); |
|
172 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
173 | - $this->_caps_slug = 'transactions'; |
|
174 | - parent::__construct($timezone); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Gets all the line items for this transaction of the given type |
|
180 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
181 | - * @param EE_Transaction|int $transaction |
|
182 | - * @return EE_Line_Item[] |
|
183 | - */ |
|
184 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
185 | - { |
|
186 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
187 | - return $this->get_all(array(array( |
|
188 | - 'LIN_type' => $line_item_type, |
|
189 | - 'TXN_ID' => $transaction |
|
190 | - ))); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Gets all line items unrelated to tickets that are normal line items |
|
196 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
197 | - * @param EE_Transaction|int $transaction |
|
198 | - * @return EE_Line_Item[] |
|
199 | - */ |
|
200 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
201 | - { |
|
202 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
203 | - return $this->get_all(array(array( |
|
204 | - 'LIN_type' => self::type_line_item, |
|
205 | - 'TXN_ID' => $transaction, |
|
206 | - 'OR' => array( |
|
207 | - 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
208 | - 'OBJ_type*null' => array('IS_NULL')) |
|
209 | - ))); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
214 | - * This needs to be very efficient |
|
215 | - * because if there are spam bots afoot there will be LOTS of line items |
|
216 | - * @return int count of how many deleted |
|
217 | - */ |
|
218 | - public function delete_line_items_with_no_transaction() |
|
219 | - { |
|
220 | - /** @type WPDB $wpdb */ |
|
221 | - global $wpdb; |
|
222 | - $time_to_leave_alone = apply_filters( |
|
223 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', WEEK_IN_SECONDS |
|
224 | - ); |
|
225 | - $query = $wpdb->prepare( |
|
226 | - 'DELETE li |
|
50 | + /** |
|
51 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
52 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
53 | + * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
54 | + */ |
|
55 | + const type_tax_sub_total = 'tax-sub-total'; |
|
56 | + |
|
57 | + /** |
|
58 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
59 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
60 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
61 | + */ |
|
62 | + const type_tax = 'tax'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Indicating individual items purchased, or discounts or surcharges. |
|
66 | + * The sum of all the regular line items plus the tax items should equal |
|
67 | + * the grand total. |
|
68 | + * Possible children are sub-line-items and cancellations. |
|
69 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
70 | + * LIN_totals. Its LIN_percent = 0. |
|
71 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
72 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
73 | + */ |
|
74 | + const type_line_item = 'line-item'; |
|
75 | + |
|
76 | + /** |
|
77 | + * Line item indicating all the factors that make a single line item. |
|
78 | + * Sub-line items should have NO children line items. |
|
79 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
80 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
81 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
82 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
83 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
84 | + */ |
|
85 | + const type_sub_line_item = 'sub-item'; |
|
86 | + |
|
87 | + /** |
|
88 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
89 | + * Direct children should be event subtotals. |
|
90 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
91 | + * |
|
92 | + */ |
|
93 | + const type_sub_total = 'sub-total'; |
|
94 | + |
|
95 | + /** |
|
96 | + * Line item for the grand total of an order. Its direct children |
|
97 | + * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item |
|
98 | + * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of |
|
99 | + * the entire order's mount. |
|
100 | + */ |
|
101 | + const type_total = 'total'; |
|
102 | + |
|
103 | + /** |
|
104 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
105 | + * should be created, indicating the quantity that were cancelled |
|
106 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
107 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
108 | + * cancelled, and only one remains). |
|
109 | + * When items are refunded, a cancellation line item should be made, which points |
|
110 | + * to teh payment model object which actually refunded the payment. |
|
111 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
112 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
113 | + * Their LIN_percent should be 0. |
|
114 | + */ |
|
115 | + const type_cancellation = 'cancellation'; |
|
116 | + |
|
117 | + // private instance of the EEM_Line_Item object |
|
118 | + protected static $_instance = NULL; |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * private constructor to prevent direct creation |
|
123 | + * @Constructor |
|
124 | + * @access protected |
|
125 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
126 | + * @return \EEM_Line_Item |
|
127 | + */ |
|
128 | + protected function __construct($timezone) |
|
129 | + { |
|
130 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
131 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
132 | + |
|
133 | + $this->_tables = array( |
|
134 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
135 | + ); |
|
136 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
137 | + $this->_fields = array( |
|
138 | + 'Line_Item' => array( |
|
139 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
140 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
141 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
142 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
143 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
144 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
145 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
146 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
147 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
148 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
149 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
150 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
151 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
152 | + self::type_line_item => __("Line Item", "event_espresso"), |
|
153 | + self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
154 | + self::type_sub_total => __("Subtotal", "event_espresso"), |
|
155 | + self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
156 | + self::type_tax => __("Tax", "event_espresso"), |
|
157 | + self::type_total => __("Total", "event_espresso"), |
|
158 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
159 | + ) |
|
160 | + ), |
|
161 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
162 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
163 | + 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
164 | + ) |
|
165 | + ); |
|
166 | + $this->_model_relations = array( |
|
167 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
168 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
169 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
170 | + 'Event' => new EE_Belongs_To_Any_Relation() |
|
171 | + ); |
|
172 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
173 | + $this->_caps_slug = 'transactions'; |
|
174 | + parent::__construct($timezone); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Gets all the line items for this transaction of the given type |
|
180 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
181 | + * @param EE_Transaction|int $transaction |
|
182 | + * @return EE_Line_Item[] |
|
183 | + */ |
|
184 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
185 | + { |
|
186 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
187 | + return $this->get_all(array(array( |
|
188 | + 'LIN_type' => $line_item_type, |
|
189 | + 'TXN_ID' => $transaction |
|
190 | + ))); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Gets all line items unrelated to tickets that are normal line items |
|
196 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
197 | + * @param EE_Transaction|int $transaction |
|
198 | + * @return EE_Line_Item[] |
|
199 | + */ |
|
200 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
201 | + { |
|
202 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
203 | + return $this->get_all(array(array( |
|
204 | + 'LIN_type' => self::type_line_item, |
|
205 | + 'TXN_ID' => $transaction, |
|
206 | + 'OR' => array( |
|
207 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
208 | + 'OBJ_type*null' => array('IS_NULL')) |
|
209 | + ))); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
214 | + * This needs to be very efficient |
|
215 | + * because if there are spam bots afoot there will be LOTS of line items |
|
216 | + * @return int count of how many deleted |
|
217 | + */ |
|
218 | + public function delete_line_items_with_no_transaction() |
|
219 | + { |
|
220 | + /** @type WPDB $wpdb */ |
|
221 | + global $wpdb; |
|
222 | + $time_to_leave_alone = apply_filters( |
|
223 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', WEEK_IN_SECONDS |
|
224 | + ); |
|
225 | + $query = $wpdb->prepare( |
|
226 | + 'DELETE li |
|
227 | 227 | FROM ' . $this->table() . ' li |
228 | 228 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
229 | 229 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
230 | - // use GMT time because that's what TXN_timestamps are in |
|
231 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
232 | - ); |
|
233 | - return $wpdb->query($query); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * get_line_item_for_transaction_object |
|
239 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
240 | - * |
|
241 | - * @param int $TXN_ID |
|
242 | - * @param \EE_Base_Class $object |
|
243 | - * @return EE_Line_Item[] |
|
244 | - */ |
|
245 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
246 | - { |
|
247 | - return $this->get_all(array(array( |
|
248 | - 'TXN_ID' => $TXN_ID, |
|
249 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
250 | - 'OBJ_ID' => $object->ID() |
|
251 | - ))); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * get_object_line_items_for_transaction |
|
257 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
258 | - * |
|
259 | - * @param int $TXN_ID |
|
260 | - * @param string $OBJ_type |
|
261 | - * @param array $OBJ_IDs |
|
262 | - * @return EE_Line_Item[] |
|
263 | - */ |
|
264 | - public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
265 | - { |
|
266 | - $query_params = array( |
|
267 | - 'OBJ_type' => $OBJ_type, |
|
268 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
269 | - 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
270 | - ); |
|
271 | - if ($TXN_ID) { |
|
272 | - $query_params['TXN_ID'] = $TXN_ID; |
|
273 | - } |
|
274 | - return $this->get_all(array($query_params)); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * get_all_ticket_line_items_for_transaction |
|
280 | - * |
|
281 | - * @param EE_Transaction $transaction |
|
282 | - * @return EE_Line_Item[] |
|
283 | - */ |
|
284 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
285 | - { |
|
286 | - return $this->get_all(array( |
|
287 | - array( |
|
288 | - 'TXN_ID' => $transaction->ID(), |
|
289 | - 'OBJ_type' => 'Ticket', |
|
290 | - ) |
|
291 | - )); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * get_ticket_line_item_for_transaction |
|
297 | - * |
|
298 | - * @param int $TXN_ID |
|
299 | - * @param int $TKT_ID |
|
300 | - * @return \EE_Line_Item |
|
301 | - */ |
|
302 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
303 | - { |
|
304 | - return $this->get_one(array( |
|
305 | - array( |
|
306 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
307 | - 'OBJ_ID' => $TKT_ID, |
|
308 | - 'OBJ_type' => 'Ticket', |
|
309 | - ) |
|
310 | - )); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * get_existing_promotion_line_item |
|
316 | - * searches the cart for existing line items for the specified promotion |
|
317 | - * |
|
318 | - * @since 1.0.0 |
|
319 | - * |
|
320 | - * @param EE_Line_Item $parent_line_item |
|
321 | - * @param EE_Promotion $promotion |
|
322 | - * @return EE_Line_Item |
|
323 | - */ |
|
324 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
325 | - { |
|
326 | - return $this->get_one(array( |
|
327 | - array( |
|
328 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
329 | - 'LIN_parent' => $parent_line_item->ID(), |
|
330 | - 'OBJ_type' => 'Promotion', |
|
331 | - 'OBJ_ID' => $promotion->ID() |
|
332 | - ) |
|
333 | - )); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * get_all_promotion_line_items |
|
339 | - * searches the cart for any and all existing promotion line items |
|
340 | - * |
|
341 | - * @since 1.0.0 |
|
342 | - * |
|
343 | - * @param EE_Line_Item $parent_line_item |
|
344 | - * @return EE_Line_Item[] |
|
345 | - */ |
|
346 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
347 | - { |
|
348 | - return $this->get_all(array( |
|
349 | - array( |
|
350 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
351 | - 'LIN_parent' => $parent_line_item->ID(), |
|
352 | - 'OBJ_type' => 'Promotion' |
|
353 | - ) |
|
354 | - )); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Gets the registration's corresponding line item. |
|
359 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
360 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
361 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
362 | - * @param EE_Registration $registration |
|
363 | - * @return EE_Line_ITem |
|
364 | - */ |
|
365 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
366 | - { |
|
367 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
372 | - * @param EE_Registration $registration |
|
373 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
374 | - * @return array like EEM_Base::get_all()'s $query_params |
|
375 | - */ |
|
376 | - public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
377 | - { |
|
378 | - return array_replace_recursive($original_query_params, array( |
|
379 | - array( |
|
380 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
381 | - 'OBJ_type' => 'Ticket', |
|
382 | - 'TXN_ID' => $registration->transaction_ID() |
|
383 | - ) |
|
384 | - )); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function get_total_line_items_with_no_transaction() |
|
393 | - { |
|
394 | - return $this->get_total_line_items_for_carts(); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
400 | - * @throws EE_Error |
|
401 | - */ |
|
402 | - public function get_total_line_items_for_active_carts() |
|
403 | - { |
|
404 | - return $this->get_total_line_items_for_carts(false); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
410 | - * @throws EE_Error |
|
411 | - */ |
|
412 | - public function get_total_line_items_for_expired_carts() |
|
413 | - { |
|
414 | - return $this->get_total_line_items_for_carts(true); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
420 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
421 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
422 | - * |
|
423 | - * @param bool|null $expired |
|
424 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
425 | - * @throws InvalidInterfaceException |
|
426 | - * @throws InvalidDataTypeException |
|
427 | - * @throws EE_Error |
|
428 | - * @throws InvalidArgumentException |
|
429 | - */ |
|
430 | - private function get_total_line_items_for_carts($expired = null) |
|
431 | - { |
|
432 | - $where_params = array( |
|
433 | - 'TXN_ID' => 0, |
|
434 | - 'LIN_type' => 'total', |
|
435 | - ); |
|
436 | - if ($expired !== null) { |
|
437 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
438 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
439 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
440 | - ); |
|
441 | - $where_params['LIN_timestamp'] = array( |
|
442 | - $expired ? '<=' : '>', |
|
443 | - $session_lifespan->expiration(), |
|
444 | - ); |
|
445 | - } |
|
446 | - return $this->get_all(array($where_params)); |
|
447 | - } |
|
230 | + // use GMT time because that's what TXN_timestamps are in |
|
231 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
232 | + ); |
|
233 | + return $wpdb->query($query); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * get_line_item_for_transaction_object |
|
239 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
240 | + * |
|
241 | + * @param int $TXN_ID |
|
242 | + * @param \EE_Base_Class $object |
|
243 | + * @return EE_Line_Item[] |
|
244 | + */ |
|
245 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
246 | + { |
|
247 | + return $this->get_all(array(array( |
|
248 | + 'TXN_ID' => $TXN_ID, |
|
249 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
250 | + 'OBJ_ID' => $object->ID() |
|
251 | + ))); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * get_object_line_items_for_transaction |
|
257 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
258 | + * |
|
259 | + * @param int $TXN_ID |
|
260 | + * @param string $OBJ_type |
|
261 | + * @param array $OBJ_IDs |
|
262 | + * @return EE_Line_Item[] |
|
263 | + */ |
|
264 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
265 | + { |
|
266 | + $query_params = array( |
|
267 | + 'OBJ_type' => $OBJ_type, |
|
268 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
269 | + 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
270 | + ); |
|
271 | + if ($TXN_ID) { |
|
272 | + $query_params['TXN_ID'] = $TXN_ID; |
|
273 | + } |
|
274 | + return $this->get_all(array($query_params)); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * get_all_ticket_line_items_for_transaction |
|
280 | + * |
|
281 | + * @param EE_Transaction $transaction |
|
282 | + * @return EE_Line_Item[] |
|
283 | + */ |
|
284 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
285 | + { |
|
286 | + return $this->get_all(array( |
|
287 | + array( |
|
288 | + 'TXN_ID' => $transaction->ID(), |
|
289 | + 'OBJ_type' => 'Ticket', |
|
290 | + ) |
|
291 | + )); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * get_ticket_line_item_for_transaction |
|
297 | + * |
|
298 | + * @param int $TXN_ID |
|
299 | + * @param int $TKT_ID |
|
300 | + * @return \EE_Line_Item |
|
301 | + */ |
|
302 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
303 | + { |
|
304 | + return $this->get_one(array( |
|
305 | + array( |
|
306 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
307 | + 'OBJ_ID' => $TKT_ID, |
|
308 | + 'OBJ_type' => 'Ticket', |
|
309 | + ) |
|
310 | + )); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * get_existing_promotion_line_item |
|
316 | + * searches the cart for existing line items for the specified promotion |
|
317 | + * |
|
318 | + * @since 1.0.0 |
|
319 | + * |
|
320 | + * @param EE_Line_Item $parent_line_item |
|
321 | + * @param EE_Promotion $promotion |
|
322 | + * @return EE_Line_Item |
|
323 | + */ |
|
324 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
325 | + { |
|
326 | + return $this->get_one(array( |
|
327 | + array( |
|
328 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
329 | + 'LIN_parent' => $parent_line_item->ID(), |
|
330 | + 'OBJ_type' => 'Promotion', |
|
331 | + 'OBJ_ID' => $promotion->ID() |
|
332 | + ) |
|
333 | + )); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * get_all_promotion_line_items |
|
339 | + * searches the cart for any and all existing promotion line items |
|
340 | + * |
|
341 | + * @since 1.0.0 |
|
342 | + * |
|
343 | + * @param EE_Line_Item $parent_line_item |
|
344 | + * @return EE_Line_Item[] |
|
345 | + */ |
|
346 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
347 | + { |
|
348 | + return $this->get_all(array( |
|
349 | + array( |
|
350 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
351 | + 'LIN_parent' => $parent_line_item->ID(), |
|
352 | + 'OBJ_type' => 'Promotion' |
|
353 | + ) |
|
354 | + )); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Gets the registration's corresponding line item. |
|
359 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
360 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
361 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
362 | + * @param EE_Registration $registration |
|
363 | + * @return EE_Line_ITem |
|
364 | + */ |
|
365 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
366 | + { |
|
367 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
372 | + * @param EE_Registration $registration |
|
373 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
374 | + * @return array like EEM_Base::get_all()'s $query_params |
|
375 | + */ |
|
376 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
377 | + { |
|
378 | + return array_replace_recursive($original_query_params, array( |
|
379 | + array( |
|
380 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
381 | + 'OBJ_type' => 'Ticket', |
|
382 | + 'TXN_ID' => $registration->transaction_ID() |
|
383 | + ) |
|
384 | + )); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function get_total_line_items_with_no_transaction() |
|
393 | + { |
|
394 | + return $this->get_total_line_items_for_carts(); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
400 | + * @throws EE_Error |
|
401 | + */ |
|
402 | + public function get_total_line_items_for_active_carts() |
|
403 | + { |
|
404 | + return $this->get_total_line_items_for_carts(false); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
410 | + * @throws EE_Error |
|
411 | + */ |
|
412 | + public function get_total_line_items_for_expired_carts() |
|
413 | + { |
|
414 | + return $this->get_total_line_items_for_carts(true); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
420 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
421 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
422 | + * |
|
423 | + * @param bool|null $expired |
|
424 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
425 | + * @throws InvalidInterfaceException |
|
426 | + * @throws InvalidDataTypeException |
|
427 | + * @throws EE_Error |
|
428 | + * @throws InvalidArgumentException |
|
429 | + */ |
|
430 | + private function get_total_line_items_for_carts($expired = null) |
|
431 | + { |
|
432 | + $where_params = array( |
|
433 | + 'TXN_ID' => 0, |
|
434 | + 'LIN_type' => 'total', |
|
435 | + ); |
|
436 | + if ($expired !== null) { |
|
437 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
438 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
439 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
440 | + ); |
|
441 | + $where_params['LIN_timestamp'] = array( |
|
442 | + $expired ? '<=' : '>', |
|
443 | + $session_lifespan->expiration(), |
|
444 | + ); |
|
445 | + } |
|
446 | + return $this->get_all(array($where_params)); |
|
447 | + } |
|
448 | 448 | |
449 | 449 | |
450 | 450 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -17,632 +17,632 @@ discard block |
||
17 | 17 | class EEH_Debug_Tools |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EEH_Autoloader object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $_memory_usage_points = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EEH_Debug_Tools |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * private class constructor |
|
53 | - */ |
|
54 | - private function __construct() |
|
55 | - { |
|
56 | - // load Kint PHP debugging library |
|
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | - } |
|
65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | - // } |
|
68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * show_db_name |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public static function show_db_name() |
|
82 | - { |
|
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | - . DB_NAME |
|
86 | - . '</p>'; |
|
87 | - } |
|
88 | - if (EE_DEBUG) { |
|
89 | - Benchmark::displayResults(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public function espresso_session_footer_dump() |
|
101 | - { |
|
102 | - if ( |
|
103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | - && ! defined('DOING_AJAX') |
|
105 | - && class_exists('Kint') |
|
106 | - && function_exists('wp_get_current_user') |
|
107 | - && current_user_can('update_core') |
|
108 | - && class_exists('EE_Registry') |
|
109 | - ) { |
|
110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | - $this->espresso_list_hooked_functions(); |
|
114 | - Benchmark::displayResults(); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * List All Hooked Functions |
|
122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | - * |
|
125 | - * @param string $tag |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - public function espresso_list_hooked_functions($tag = '') |
|
129 | - { |
|
130 | - global $wp_filter; |
|
131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | - if ($tag) { |
|
133 | - $hook[$tag] = $wp_filter[$tag]; |
|
134 | - if (! is_array($hook[$tag])) { |
|
135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | - return; |
|
137 | - } |
|
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | - } else { |
|
140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | - ksort($hook); |
|
142 | - } |
|
143 | - foreach ($hook as $tag_name => $priorities) { |
|
144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | - ksort($priorities); |
|
146 | - foreach ($priorities as $priority => $function) { |
|
147 | - echo $priority; |
|
148 | - foreach ($function as $name => $properties) { |
|
149 | - echo "\t$name<br />"; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * registered_filter_callbacks |
|
159 | - * |
|
160 | - * @param string $hook_name |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function registered_filter_callbacks($hook_name = '') |
|
164 | - { |
|
165 | - $filters = array(); |
|
166 | - global $wp_filter; |
|
167 | - if (isset($wp_filter[$hook_name])) { |
|
168 | - $filters[$hook_name] = array(); |
|
169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | - $filters[$hook_name][$priority] = array(); |
|
171 | - foreach ($callbacks as $callback) { |
|
172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $filters; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * captures plugin activation errors for debugging |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public static function ee_plugin_activation_errors() |
|
188 | - { |
|
189 | - if (WP_DEBUG) { |
|
190 | - $activation_errors = ob_get_contents(); |
|
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | - } |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | - if (class_exists('EEH_File')) { |
|
196 | - try { |
|
197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | - ); |
|
200 | - EEH_File::write_to_file( |
|
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | - $activation_errors |
|
203 | - ); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf( |
|
207 | - __( |
|
208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - $e->getMessage() |
|
212 | - ), |
|
213 | - __FILE__, __FUNCTION__, __LINE__ |
|
214 | - ); |
|
215 | - } |
|
216 | - } else { |
|
217 | - // old school attempt |
|
218 | - file_put_contents( |
|
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | - $activation_errors |
|
221 | - ); |
|
222 | - } |
|
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | - * or we want to make sure they use something the right way. |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param string $function The function that was called |
|
237 | - * @param string $message A message explaining what has been done incorrectly |
|
238 | - * @param string $version The version of Event Espresso where the error was added |
|
239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | - * but not have any notices appear until a later version. This allows developers |
|
242 | - * extra time to update their code before notices appear. |
|
243 | - * @param int $error_type |
|
244 | - * @uses trigger_error() |
|
245 | - */ |
|
246 | - public function doing_it_wrong( |
|
247 | - $function, |
|
248 | - $message, |
|
249 | - $version, |
|
250 | - $applies_when = '', |
|
251 | - $error_type = null |
|
252 | - ) { |
|
253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | - // because we swapped the parameter order around for the last two params, |
|
256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | - if (is_int($applies_when)) { |
|
258 | - $error_type = $applies_when; |
|
259 | - $applies_when = espresso_version(); |
|
260 | - } |
|
261 | - // if not displaying notices yet, then just leave |
|
262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | - return; |
|
264 | - } |
|
265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | - $version = $version === null |
|
267 | - ? '' |
|
268 | - : sprintf( |
|
269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | - $version |
|
271 | - ); |
|
272 | - $error_message = sprintf( |
|
273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | - $function, |
|
275 | - '<strong>', |
|
276 | - '</strong>', |
|
277 | - $message, |
|
278 | - $version |
|
279 | - ); |
|
280 | - // don't trigger error if doing ajax, |
|
281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | - $error_message .= ' ' . esc_html__( |
|
284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | - 'event_espresso' |
|
286 | - ); |
|
287 | - $error_message .= '<ul><li>'; |
|
288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | - $error_message .= '</ul>'; |
|
290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | - //now we set this on the transient so it shows up on the next request. |
|
292 | - EE_Error::get_notices(false, true); |
|
293 | - } else { |
|
294 | - trigger_error($error_message, $error_type); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Logger helpers |
|
303 | - */ |
|
304 | - /** |
|
305 | - * debug |
|
306 | - * |
|
307 | - * @param string $class |
|
308 | - * @param string $func |
|
309 | - * @param string $line |
|
310 | - * @param array $info |
|
311 | - * @param bool $display_request |
|
312 | - * @param string $debug_index |
|
313 | - * @param string $debug_key |
|
314 | - * @throws EE_Error |
|
315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | - */ |
|
317 | - public static function log( |
|
318 | - $class = '', |
|
319 | - $func = '', |
|
320 | - $line = '', |
|
321 | - $info = array(), |
|
322 | - $display_request = false, |
|
323 | - $debug_index = '', |
|
324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
325 | - ) { |
|
326 | - if (WP_DEBUG) { |
|
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | - $debug_data = get_option($debug_key, array()); |
|
329 | - $default_data = array( |
|
330 | - $class => $func . '() : ' . $line, |
|
331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | - ); |
|
333 | - // don't serialize objects |
|
334 | - $info = self::strip_objects($info); |
|
335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | - if (! isset($debug_data[$index])) { |
|
337 | - $debug_data[$index] = array(); |
|
338 | - } |
|
339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | - update_option($debug_key, $debug_data); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * strip_objects |
|
348 | - * |
|
349 | - * @param array $info |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function strip_objects($info = array()) |
|
353 | - { |
|
354 | - foreach ($info as $key => $value) { |
|
355 | - if (is_array($value)) { |
|
356 | - $info[$key] = self::strip_objects($value); |
|
357 | - } else if (is_object($value)) { |
|
358 | - $object_class = get_class($value); |
|
359 | - $info[$object_class] = array(); |
|
360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | - if (method_exists($value, 'ID')) { |
|
362 | - $info[$object_class]['ID'] = $value->ID(); |
|
363 | - } |
|
364 | - if (method_exists($value, 'status')) { |
|
365 | - $info[$object_class]['status'] = $value->status(); |
|
366 | - } else if (method_exists($value, 'status_ID')) { |
|
367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
368 | - } |
|
369 | - unset($info[$key]); |
|
370 | - } |
|
371 | - } |
|
372 | - return (array)$info; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $var |
|
379 | - * @param string $var_name |
|
380 | - * @param string $file |
|
381 | - * @param int|string $line |
|
382 | - * @param int $heading_tag |
|
383 | - * @param bool $die |
|
384 | - * @param string $margin |
|
385 | - */ |
|
386 | - public static function printv( |
|
387 | - $var, |
|
388 | - $var_name = '', |
|
389 | - $file = '', |
|
390 | - $line = '', |
|
391 | - $heading_tag = 5, |
|
392 | - $die = false, |
|
393 | - $margin = '' |
|
394 | - ) { |
|
395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | - $is_method = method_exists($var_name, $var); |
|
398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | - $result = $heading_tag > 3 && defined('EE_TESTS_DIR') |
|
400 | - ? "\n" |
|
401 | - :''; |
|
402 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
403 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
404 | - $result .= $is_method |
|
405 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
406 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
407 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
408 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
409 | - if ($die) { |
|
410 | - die($result); |
|
411 | - } |
|
412 | - echo $result; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * @param string $var_name |
|
419 | - * @param string $heading_tag |
|
420 | - * @param string $margin |
|
421 | - * @return string |
|
422 | - */ |
|
423 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
424 | - { |
|
425 | - if (defined('EE_TESTS_DIR')) { |
|
426 | - return "\n{$var_name}"; |
|
427 | - } |
|
428 | - $margin = "25px 0 0 {$margin}"; |
|
429 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @param string $heading_tag |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - protected static function headingX($heading_tag = 'h5') |
|
439 | - { |
|
440 | - if (defined('EE_TESTS_DIR')) { |
|
441 | - return ''; |
|
442 | - } |
|
443 | - return '</' . $heading_tag . '>'; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * @param string $content |
|
450 | - * @return string |
|
451 | - */ |
|
452 | - protected static function grey_span($content = '') |
|
453 | - { |
|
454 | - if (defined('EE_TESTS_DIR')) { |
|
455 | - return $content; |
|
456 | - } |
|
457 | - return '<span style="color:#999">' . $content . '</span>'; |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @param string $file |
|
464 | - * @param int $line |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - protected static function file_and_line($file, $line) |
|
468 | - { |
|
469 | - if ($file === '' || $line === '' || defined('EE_TESTS_DIR')) { |
|
470 | - return ''; |
|
471 | - } |
|
472 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
473 | - . $file |
|
474 | - . '<br />line no: ' |
|
475 | - . $line |
|
476 | - . '</span>'; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @param string $content |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - protected static function orange_span($content = '') |
|
486 | - { |
|
487 | - if (defined('EE_TESTS_DIR')) { |
|
488 | - return $content; |
|
489 | - } |
|
490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * @param mixed $var |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - protected static function pre_span($var) |
|
500 | - { |
|
501 | - ob_start(); |
|
502 | - var_dump($var); |
|
503 | - $var = ob_get_clean(); |
|
504 | - if (defined('EE_TESTS_DIR')) { |
|
505 | - return "\n" . $var; |
|
506 | - } |
|
507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param mixed $var |
|
514 | - * @param string $var_name |
|
515 | - * @param string $file |
|
516 | - * @param int|string $line |
|
517 | - * @param int $heading_tag |
|
518 | - * @param bool $die |
|
519 | - */ |
|
520 | - public static function printr( |
|
521 | - $var, |
|
522 | - $var_name = '', |
|
523 | - $file = '', |
|
524 | - $line = '', |
|
525 | - $heading_tag = 5, |
|
526 | - $die = false |
|
527 | - ) { |
|
528 | - // return; |
|
529 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
530 | - $margin = is_admin() ? ' 180px' : '0'; |
|
531 | - //$print_r = false; |
|
532 | - if (is_string($var)) { |
|
533 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
534 | - return; |
|
535 | - } |
|
536 | - if (is_object($var)) { |
|
537 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
538 | - //$print_r = true; |
|
539 | - } else if (is_array($var)) { |
|
540 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
541 | - //$print_r = true; |
|
542 | - } else if (is_numeric($var)) { |
|
543 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
544 | - } else if ($var === null) { |
|
545 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
546 | - } |
|
547 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
548 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
549 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
551 | - EEH_Debug_Tools::pre_span($var) |
|
552 | - ); |
|
553 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
554 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
555 | - if ($die) { |
|
556 | - die($result); |
|
557 | - } |
|
558 | - echo $result; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /******************** deprecated ********************/ |
|
564 | - |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * @deprecated 4.9.39.rc.034 |
|
569 | - */ |
|
570 | - public function reset_times() |
|
571 | - { |
|
572 | - Benchmark::resetTimes(); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @deprecated 4.9.39.rc.034 |
|
579 | - * @param null $timer_name |
|
580 | - */ |
|
581 | - public function start_timer($timer_name = null) |
|
582 | - { |
|
583 | - Benchmark::startTimer($timer_name); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * @deprecated 4.9.39.rc.034 |
|
590 | - * @param string $timer_name |
|
591 | - */ |
|
592 | - public function stop_timer($timer_name = '') |
|
593 | - { |
|
594 | - Benchmark::stopTimer($timer_name); |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * @deprecated 4.9.39.rc.034 |
|
601 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
602 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
603 | - * @return void |
|
604 | - */ |
|
605 | - public function measure_memory($label, $output_now = false) |
|
606 | - { |
|
607 | - Benchmark::measureMemory($label, $output_now); |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * @deprecated 4.9.39.rc.034 |
|
614 | - * @param int $size |
|
615 | - * @return string |
|
616 | - */ |
|
617 | - public function convert($size) |
|
618 | - { |
|
619 | - return Benchmark::convert($size); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * @deprecated 4.9.39.rc.034 |
|
626 | - * @param bool $output_now |
|
627 | - * @return string |
|
628 | - */ |
|
629 | - public function show_times($output_now = true) |
|
630 | - { |
|
631 | - return Benchmark::displayResults($output_now); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * @deprecated 4.9.39.rc.034 |
|
638 | - * @param string $timer_name |
|
639 | - * @param float $total_time |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function format_time($timer_name, $total_time) |
|
643 | - { |
|
644 | - return Benchmark::formatTime($timer_name, $total_time); |
|
645 | - } |
|
20 | + /** |
|
21 | + * instance of the EEH_Autoloader object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $_memory_usage_points = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EEH_Debug_Tools |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * private class constructor |
|
53 | + */ |
|
54 | + private function __construct() |
|
55 | + { |
|
56 | + // load Kint PHP debugging library |
|
57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | + } |
|
65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | + // } |
|
68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * show_db_name |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public static function show_db_name() |
|
82 | + { |
|
83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | + . DB_NAME |
|
86 | + . '</p>'; |
|
87 | + } |
|
88 | + if (EE_DEBUG) { |
|
89 | + Benchmark::displayResults(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public function espresso_session_footer_dump() |
|
101 | + { |
|
102 | + if ( |
|
103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | + && ! defined('DOING_AJAX') |
|
105 | + && class_exists('Kint') |
|
106 | + && function_exists('wp_get_current_user') |
|
107 | + && current_user_can('update_core') |
|
108 | + && class_exists('EE_Registry') |
|
109 | + ) { |
|
110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | + $this->espresso_list_hooked_functions(); |
|
114 | + Benchmark::displayResults(); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * List All Hooked Functions |
|
122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | + * |
|
125 | + * @param string $tag |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + public function espresso_list_hooked_functions($tag = '') |
|
129 | + { |
|
130 | + global $wp_filter; |
|
131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | + if ($tag) { |
|
133 | + $hook[$tag] = $wp_filter[$tag]; |
|
134 | + if (! is_array($hook[$tag])) { |
|
135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | + return; |
|
137 | + } |
|
138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | + } else { |
|
140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | + ksort($hook); |
|
142 | + } |
|
143 | + foreach ($hook as $tag_name => $priorities) { |
|
144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | + ksort($priorities); |
|
146 | + foreach ($priorities as $priority => $function) { |
|
147 | + echo $priority; |
|
148 | + foreach ($function as $name => $properties) { |
|
149 | + echo "\t$name<br />"; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * registered_filter_callbacks |
|
159 | + * |
|
160 | + * @param string $hook_name |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function registered_filter_callbacks($hook_name = '') |
|
164 | + { |
|
165 | + $filters = array(); |
|
166 | + global $wp_filter; |
|
167 | + if (isset($wp_filter[$hook_name])) { |
|
168 | + $filters[$hook_name] = array(); |
|
169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | + $filters[$hook_name][$priority] = array(); |
|
171 | + foreach ($callbacks as $callback) { |
|
172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $filters; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * captures plugin activation errors for debugging |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public static function ee_plugin_activation_errors() |
|
188 | + { |
|
189 | + if (WP_DEBUG) { |
|
190 | + $activation_errors = ob_get_contents(); |
|
191 | + if (! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | + } |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | + if (class_exists('EEH_File')) { |
|
196 | + try { |
|
197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | + ); |
|
200 | + EEH_File::write_to_file( |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | + $activation_errors |
|
203 | + ); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf( |
|
207 | + __( |
|
208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + $e->getMessage() |
|
212 | + ), |
|
213 | + __FILE__, __FUNCTION__, __LINE__ |
|
214 | + ); |
|
215 | + } |
|
216 | + } else { |
|
217 | + // old school attempt |
|
218 | + file_put_contents( |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | + $activation_errors |
|
221 | + ); |
|
222 | + } |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | + * or we want to make sure they use something the right way. |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param string $function The function that was called |
|
237 | + * @param string $message A message explaining what has been done incorrectly |
|
238 | + * @param string $version The version of Event Espresso where the error was added |
|
239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | + * but not have any notices appear until a later version. This allows developers |
|
242 | + * extra time to update their code before notices appear. |
|
243 | + * @param int $error_type |
|
244 | + * @uses trigger_error() |
|
245 | + */ |
|
246 | + public function doing_it_wrong( |
|
247 | + $function, |
|
248 | + $message, |
|
249 | + $version, |
|
250 | + $applies_when = '', |
|
251 | + $error_type = null |
|
252 | + ) { |
|
253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | + // because we swapped the parameter order around for the last two params, |
|
256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | + if (is_int($applies_when)) { |
|
258 | + $error_type = $applies_when; |
|
259 | + $applies_when = espresso_version(); |
|
260 | + } |
|
261 | + // if not displaying notices yet, then just leave |
|
262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | + return; |
|
264 | + } |
|
265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | + $version = $version === null |
|
267 | + ? '' |
|
268 | + : sprintf( |
|
269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | + $version |
|
271 | + ); |
|
272 | + $error_message = sprintf( |
|
273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | + $function, |
|
275 | + '<strong>', |
|
276 | + '</strong>', |
|
277 | + $message, |
|
278 | + $version |
|
279 | + ); |
|
280 | + // don't trigger error if doing ajax, |
|
281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | + $error_message .= ' ' . esc_html__( |
|
284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | + 'event_espresso' |
|
286 | + ); |
|
287 | + $error_message .= '<ul><li>'; |
|
288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | + $error_message .= '</ul>'; |
|
290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | + //now we set this on the transient so it shows up on the next request. |
|
292 | + EE_Error::get_notices(false, true); |
|
293 | + } else { |
|
294 | + trigger_error($error_message, $error_type); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Logger helpers |
|
303 | + */ |
|
304 | + /** |
|
305 | + * debug |
|
306 | + * |
|
307 | + * @param string $class |
|
308 | + * @param string $func |
|
309 | + * @param string $line |
|
310 | + * @param array $info |
|
311 | + * @param bool $display_request |
|
312 | + * @param string $debug_index |
|
313 | + * @param string $debug_key |
|
314 | + * @throws EE_Error |
|
315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | + */ |
|
317 | + public static function log( |
|
318 | + $class = '', |
|
319 | + $func = '', |
|
320 | + $line = '', |
|
321 | + $info = array(), |
|
322 | + $display_request = false, |
|
323 | + $debug_index = '', |
|
324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
325 | + ) { |
|
326 | + if (WP_DEBUG) { |
|
327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | + $debug_data = get_option($debug_key, array()); |
|
329 | + $default_data = array( |
|
330 | + $class => $func . '() : ' . $line, |
|
331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | + ); |
|
333 | + // don't serialize objects |
|
334 | + $info = self::strip_objects($info); |
|
335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | + if (! isset($debug_data[$index])) { |
|
337 | + $debug_data[$index] = array(); |
|
338 | + } |
|
339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | + update_option($debug_key, $debug_data); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * strip_objects |
|
348 | + * |
|
349 | + * @param array $info |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function strip_objects($info = array()) |
|
353 | + { |
|
354 | + foreach ($info as $key => $value) { |
|
355 | + if (is_array($value)) { |
|
356 | + $info[$key] = self::strip_objects($value); |
|
357 | + } else if (is_object($value)) { |
|
358 | + $object_class = get_class($value); |
|
359 | + $info[$object_class] = array(); |
|
360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | + if (method_exists($value, 'ID')) { |
|
362 | + $info[$object_class]['ID'] = $value->ID(); |
|
363 | + } |
|
364 | + if (method_exists($value, 'status')) { |
|
365 | + $info[$object_class]['status'] = $value->status(); |
|
366 | + } else if (method_exists($value, 'status_ID')) { |
|
367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
368 | + } |
|
369 | + unset($info[$key]); |
|
370 | + } |
|
371 | + } |
|
372 | + return (array)$info; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $var |
|
379 | + * @param string $var_name |
|
380 | + * @param string $file |
|
381 | + * @param int|string $line |
|
382 | + * @param int $heading_tag |
|
383 | + * @param bool $die |
|
384 | + * @param string $margin |
|
385 | + */ |
|
386 | + public static function printv( |
|
387 | + $var, |
|
388 | + $var_name = '', |
|
389 | + $file = '', |
|
390 | + $line = '', |
|
391 | + $heading_tag = 5, |
|
392 | + $die = false, |
|
393 | + $margin = '' |
|
394 | + ) { |
|
395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | + $is_method = method_exists($var_name, $var); |
|
398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | + $result = $heading_tag > 3 && defined('EE_TESTS_DIR') |
|
400 | + ? "\n" |
|
401 | + :''; |
|
402 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
403 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
404 | + $result .= $is_method |
|
405 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
406 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
407 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
408 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
409 | + if ($die) { |
|
410 | + die($result); |
|
411 | + } |
|
412 | + echo $result; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * @param string $var_name |
|
419 | + * @param string $heading_tag |
|
420 | + * @param string $margin |
|
421 | + * @return string |
|
422 | + */ |
|
423 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
424 | + { |
|
425 | + if (defined('EE_TESTS_DIR')) { |
|
426 | + return "\n{$var_name}"; |
|
427 | + } |
|
428 | + $margin = "25px 0 0 {$margin}"; |
|
429 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @param string $heading_tag |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + protected static function headingX($heading_tag = 'h5') |
|
439 | + { |
|
440 | + if (defined('EE_TESTS_DIR')) { |
|
441 | + return ''; |
|
442 | + } |
|
443 | + return '</' . $heading_tag . '>'; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * @param string $content |
|
450 | + * @return string |
|
451 | + */ |
|
452 | + protected static function grey_span($content = '') |
|
453 | + { |
|
454 | + if (defined('EE_TESTS_DIR')) { |
|
455 | + return $content; |
|
456 | + } |
|
457 | + return '<span style="color:#999">' . $content . '</span>'; |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @param string $file |
|
464 | + * @param int $line |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + protected static function file_and_line($file, $line) |
|
468 | + { |
|
469 | + if ($file === '' || $line === '' || defined('EE_TESTS_DIR')) { |
|
470 | + return ''; |
|
471 | + } |
|
472 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
473 | + . $file |
|
474 | + . '<br />line no: ' |
|
475 | + . $line |
|
476 | + . '</span>'; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @param string $content |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + protected static function orange_span($content = '') |
|
486 | + { |
|
487 | + if (defined('EE_TESTS_DIR')) { |
|
488 | + return $content; |
|
489 | + } |
|
490 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * @param mixed $var |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + protected static function pre_span($var) |
|
500 | + { |
|
501 | + ob_start(); |
|
502 | + var_dump($var); |
|
503 | + $var = ob_get_clean(); |
|
504 | + if (defined('EE_TESTS_DIR')) { |
|
505 | + return "\n" . $var; |
|
506 | + } |
|
507 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param mixed $var |
|
514 | + * @param string $var_name |
|
515 | + * @param string $file |
|
516 | + * @param int|string $line |
|
517 | + * @param int $heading_tag |
|
518 | + * @param bool $die |
|
519 | + */ |
|
520 | + public static function printr( |
|
521 | + $var, |
|
522 | + $var_name = '', |
|
523 | + $file = '', |
|
524 | + $line = '', |
|
525 | + $heading_tag = 5, |
|
526 | + $die = false |
|
527 | + ) { |
|
528 | + // return; |
|
529 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
530 | + $margin = is_admin() ? ' 180px' : '0'; |
|
531 | + //$print_r = false; |
|
532 | + if (is_string($var)) { |
|
533 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
534 | + return; |
|
535 | + } |
|
536 | + if (is_object($var)) { |
|
537 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
538 | + //$print_r = true; |
|
539 | + } else if (is_array($var)) { |
|
540 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
541 | + //$print_r = true; |
|
542 | + } else if (is_numeric($var)) { |
|
543 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
544 | + } else if ($var === null) { |
|
545 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
546 | + } |
|
547 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
548 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
549 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
550 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
551 | + EEH_Debug_Tools::pre_span($var) |
|
552 | + ); |
|
553 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
554 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
555 | + if ($die) { |
|
556 | + die($result); |
|
557 | + } |
|
558 | + echo $result; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /******************** deprecated ********************/ |
|
564 | + |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * @deprecated 4.9.39.rc.034 |
|
569 | + */ |
|
570 | + public function reset_times() |
|
571 | + { |
|
572 | + Benchmark::resetTimes(); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @deprecated 4.9.39.rc.034 |
|
579 | + * @param null $timer_name |
|
580 | + */ |
|
581 | + public function start_timer($timer_name = null) |
|
582 | + { |
|
583 | + Benchmark::startTimer($timer_name); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * @deprecated 4.9.39.rc.034 |
|
590 | + * @param string $timer_name |
|
591 | + */ |
|
592 | + public function stop_timer($timer_name = '') |
|
593 | + { |
|
594 | + Benchmark::stopTimer($timer_name); |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * @deprecated 4.9.39.rc.034 |
|
601 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
602 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
603 | + * @return void |
|
604 | + */ |
|
605 | + public function measure_memory($label, $output_now = false) |
|
606 | + { |
|
607 | + Benchmark::measureMemory($label, $output_now); |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * @deprecated 4.9.39.rc.034 |
|
614 | + * @param int $size |
|
615 | + * @return string |
|
616 | + */ |
|
617 | + public function convert($size) |
|
618 | + { |
|
619 | + return Benchmark::convert($size); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * @deprecated 4.9.39.rc.034 |
|
626 | + * @param bool $output_now |
|
627 | + * @return string |
|
628 | + */ |
|
629 | + public function show_times($output_now = true) |
|
630 | + { |
|
631 | + return Benchmark::displayResults($output_now); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * @deprecated 4.9.39.rc.034 |
|
638 | + * @param string $timer_name |
|
639 | + * @param float $total_time |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function format_time($timer_name, $total_time) |
|
643 | + { |
|
644 | + return Benchmark::formatTime($timer_name, $total_time); |
|
645 | + } |
|
646 | 646 | |
647 | 647 | |
648 | 648 | |
@@ -655,31 +655,31 @@ discard block |
||
655 | 655 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
656 | 656 | */ |
657 | 657 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
658 | - function dump_wp_query() |
|
659 | - { |
|
660 | - global $wp_query; |
|
661 | - d($wp_query); |
|
662 | - } |
|
658 | + function dump_wp_query() |
|
659 | + { |
|
660 | + global $wp_query; |
|
661 | + d($wp_query); |
|
662 | + } |
|
663 | 663 | } |
664 | 664 | /** |
665 | 665 | * borrowed from Kint Debugger |
666 | 666 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
667 | 667 | */ |
668 | 668 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
669 | - function dump_wp() |
|
670 | - { |
|
671 | - global $wp; |
|
672 | - d($wp); |
|
673 | - } |
|
669 | + function dump_wp() |
|
670 | + { |
|
671 | + global $wp; |
|
672 | + d($wp); |
|
673 | + } |
|
674 | 674 | } |
675 | 675 | /** |
676 | 676 | * borrowed from Kint Debugger |
677 | 677 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
678 | 678 | */ |
679 | 679 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
680 | - function dump_post() |
|
681 | - { |
|
682 | - global $post; |
|
683 | - d($post); |
|
684 | - } |
|
680 | + function dump_post() |
|
681 | + { |
|
682 | + global $post; |
|
683 | + d($post); |
|
684 | + } |
|
685 | 685 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function instance() |
41 | 41 | { |
42 | 42 | // check if class object is instantiated, and instantiated properly |
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | private function __construct() |
55 | 55 | { |
56 | 56 | // load Kint PHP debugging library |
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
64 | 64 | } |
65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function show_db_name() |
82 | 82 | { |
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
85 | 85 | . DB_NAME |
86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
132 | 132 | if ($tag) { |
133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
134 | - if (! is_array($hook[$tag])) { |
|
134 | + if ( ! is_array($hook[$tag])) { |
|
135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
136 | 136 | return; |
137 | 137 | } |
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
139 | 139 | } else { |
140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | { |
189 | 189 | if (WP_DEBUG) { |
190 | 190 | $activation_errors = ob_get_contents(); |
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
191 | + if ( ! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
193 | 193 | } |
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
195 | 195 | if (class_exists('EEH_File')) { |
196 | 196 | try { |
197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
199 | 199 | ); |
200 | 200 | EEH_File::write_to_file( |
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
202 | 202 | $activation_errors |
203 | 203 | ); |
204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | } else { |
217 | 217 | // old school attempt |
218 | 218 | file_put_contents( |
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
220 | 220 | $activation_errors |
221 | 221 | ); |
222 | 222 | } |
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
225 | 225 | } |
226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | // don't trigger error if doing ajax, |
281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
283 | - $error_message .= ' ' . esc_html__( |
|
283 | + $error_message .= ' '.esc_html__( |
|
284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
285 | 285 | 'event_espresso' |
286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
325 | 325 | ) { |
326 | 326 | if (WP_DEBUG) { |
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
328 | 328 | $debug_data = get_option($debug_key, array()); |
329 | 329 | $default_data = array( |
330 | - $class => $func . '() : ' . $line, |
|
330 | + $class => $func.'() : '.$line, |
|
331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
332 | 332 | ); |
333 | 333 | // don't serialize objects |
334 | 334 | $info = self::strip_objects($info); |
335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
336 | - if (! isset($debug_data[$index])) { |
|
336 | + if ( ! isset($debug_data[$index])) { |
|
337 | 337 | $debug_data[$index] = array(); |
338 | 338 | } |
339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | unset($info[$key]); |
370 | 370 | } |
371 | 371 | } |
372 | - return (array)$info; |
|
372 | + return (array) $info; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
403 | 403 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
404 | 404 | $result .= $is_method |
405 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
406 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
406 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
407 | 407 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
408 | 408 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
409 | 409 | if ($die) { |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | return "\n{$var_name}"; |
427 | 427 | } |
428 | 428 | $margin = "25px 0 0 {$margin}"; |
429 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
429 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | if (defined('EE_TESTS_DIR')) { |
441 | 441 | return ''; |
442 | 442 | } |
443 | - return '</' . $heading_tag . '>'; |
|
443 | + return '</'.$heading_tag.'>'; |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | if (defined('EE_TESTS_DIR')) { |
455 | 455 | return $content; |
456 | 456 | } |
457 | - return '<span style="color:#999">' . $content . '</span>'; |
|
457 | + return '<span style="color:#999">'.$content.'</span>'; |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | if (defined('EE_TESTS_DIR')) { |
488 | 488 | return $content; |
489 | 489 | } |
490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
490 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | var_dump($var); |
503 | 503 | $var = ob_get_clean(); |
504 | 504 | if (defined('EE_TESTS_DIR')) { |
505 | - return "\n" . $var; |
|
505 | + return "\n".$var; |
|
506 | 506 | } |
507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
507 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
548 | 548 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
549 | 549 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
550 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
551 | 551 | EEH_Debug_Tools::pre_span($var) |
552 | 552 | ); |
553 | 553 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use EEH_Template; |
8 | 8 | |
9 | 9 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
10 | - exit( 'No direct script access allowed' ); |
|
10 | + exit( 'No direct script access allowed' ); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -23,387 +23,387 @@ discard block |
||
23 | 23 | class Iframe |
24 | 24 | { |
25 | 25 | |
26 | - /* |
|
26 | + /* |
|
27 | 27 | * HTML for notices and ajax gif |
28 | 28 | * @var string $title |
29 | 29 | */ |
30 | - protected $title = ''; |
|
30 | + protected $title = ''; |
|
31 | 31 | |
32 | - /* |
|
32 | + /* |
|
33 | 33 | * HTML for the content being displayed |
34 | 34 | * @var string $content |
35 | 35 | */ |
36 | - protected $content = ''; |
|
36 | + protected $content = ''; |
|
37 | 37 | |
38 | - /* |
|
38 | + /* |
|
39 | 39 | * whether or not to call wp_head() and wp_footer() |
40 | 40 | * @var boolean $enqueue_wp_assets |
41 | 41 | */ |
42 | - protected $enqueue_wp_assets = false; |
|
42 | + protected $enqueue_wp_assets = false; |
|
43 | 43 | |
44 | - /* |
|
44 | + /* |
|
45 | 45 | * an array of CSS URLs |
46 | 46 | * @var array $css |
47 | 47 | */ |
48 | - protected $css = array(); |
|
48 | + protected $css = array(); |
|
49 | 49 | |
50 | - /* |
|
50 | + /* |
|
51 | 51 | * an array of JS URLs to be set in the HTML header. |
52 | 52 | * @var array $header_js |
53 | 53 | */ |
54 | - protected $header_js = array(); |
|
54 | + protected $header_js = array(); |
|
55 | 55 | |
56 | - /* |
|
56 | + /* |
|
57 | 57 | * an array of additional attributes to be added to <script> tags for header JS |
58 | 58 | * @var array $footer_js |
59 | 59 | */ |
60 | - protected $header_js_attributes = array(); |
|
60 | + protected $header_js_attributes = array(); |
|
61 | 61 | |
62 | - /* |
|
62 | + /* |
|
63 | 63 | * an array of JS URLs to be displayed before the HTML </body> tag |
64 | 64 | * @var array $footer_js |
65 | 65 | */ |
66 | - protected $footer_js = array(); |
|
66 | + protected $footer_js = array(); |
|
67 | 67 | |
68 | - /* |
|
68 | + /* |
|
69 | 69 | * an array of additional attributes to be added to <script> tags for footer JS |
70 | 70 | * @var array $footer_js_attributes |
71 | 71 | */ |
72 | - protected $footer_js_attributes = array(); |
|
72 | + protected $footer_js_attributes = array(); |
|
73 | 73 | |
74 | - /* |
|
74 | + /* |
|
75 | 75 | * an array of JSON vars to be set in the HTML header. |
76 | 76 | * @var array $localized_vars |
77 | 77 | */ |
78 | - protected $localized_vars = array(); |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Iframe constructor |
|
84 | - * |
|
85 | - * @param string $title |
|
86 | - * @param string $content |
|
87 | - * @throws DomainException |
|
88 | - */ |
|
89 | - public function __construct( $title, $content ) |
|
90 | - { |
|
91 | - global $wp_version; |
|
92 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
93 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
94 | - } |
|
95 | - $this->setContent( $content ); |
|
96 | - $this->setTitle( $title ); |
|
97 | - $this->addStylesheets( |
|
98 | - apply_filters( |
|
99 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
100 | - array( |
|
101 | - 'site_theme' => get_stylesheet_directory_uri() . DS |
|
102 | - . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
103 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
104 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
105 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
106 | - ), |
|
107 | - $this |
|
108 | - ) |
|
109 | - ); |
|
110 | - $this->addScripts( |
|
111 | - apply_filters( |
|
112 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
113 | - array( |
|
114 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
115 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
116 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
117 | - ), |
|
118 | - $this |
|
119 | - ) |
|
120 | - ); |
|
121 | - if ( |
|
122 | - apply_filters( |
|
123 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
124 | - false |
|
125 | - ) |
|
126 | - ) { |
|
127 | - $this->addStylesheets( |
|
128 | - apply_filters( |
|
129 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
130 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
131 | - $this |
|
132 | - ) |
|
133 | - ); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $title |
|
141 | - * @throws DomainException |
|
142 | - */ |
|
143 | - public function setTitle( $title ) |
|
144 | - { |
|
145 | - if ( empty( $title ) ) { |
|
146 | - throw new DomainException( |
|
147 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
148 | - ); |
|
149 | - } |
|
150 | - $this->title = $title; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param string $content |
|
157 | - * @throws DomainException |
|
158 | - */ |
|
159 | - public function setContent( $content ) |
|
160 | - { |
|
161 | - if ( empty( $content ) ) { |
|
162 | - throw new DomainException( |
|
163 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
164 | - ); |
|
165 | - } |
|
166 | - $this->content = $content; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param boolean $enqueue_wp_assets |
|
173 | - */ |
|
174 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
175 | - { |
|
176 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @param array $stylesheets |
|
183 | - * @throws DomainException |
|
184 | - */ |
|
185 | - public function addStylesheets( array $stylesheets ) |
|
186 | - { |
|
187 | - if ( empty( $stylesheets ) ) { |
|
188 | - throw new DomainException( |
|
189 | - esc_html__( |
|
190 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
191 | - 'event_espresso' |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
196 | - $this->css[ $handle ] = $stylesheet; |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param array $scripts |
|
204 | - * @param bool $add_to_header |
|
205 | - * @throws DomainException |
|
206 | - */ |
|
207 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
208 | - { |
|
209 | - if ( empty( $scripts ) ) { |
|
210 | - throw new DomainException( |
|
211 | - esc_html__( |
|
212 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
213 | - 'event_espresso' |
|
214 | - ) |
|
215 | - ); |
|
216 | - } |
|
217 | - foreach ( $scripts as $handle => $script ) { |
|
218 | - if ( $add_to_header ) { |
|
219 | - $this->header_js[ $handle ] = $script; |
|
220 | - } else { |
|
221 | - $this->footer_js[ $handle ] = $script; |
|
222 | - } |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @param array $script_attributes |
|
230 | - * @param bool $add_to_header |
|
231 | - * @throws DomainException |
|
232 | - */ |
|
233 | - public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
234 | - { |
|
235 | - if ( empty($script_attributes ) ) { |
|
236 | - throw new DomainException( |
|
237 | - esc_html__( |
|
238 | - 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
239 | - 'event_espresso' |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
243 | - foreach ($script_attributes as $handle => $script_attribute ) { |
|
244 | - if ( $add_to_header ) { |
|
245 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
246 | - } else { |
|
247 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
248 | - } |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param array $vars |
|
256 | - * @param string $var_name |
|
257 | - * @throws DomainException |
|
258 | - */ |
|
259 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
260 | - { |
|
261 | - if ( empty( $vars ) ) { |
|
262 | - throw new DomainException( |
|
263 | - esc_html__( |
|
264 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
265 | - 'event_espresso' |
|
266 | - ) |
|
267 | - ); |
|
268 | - } |
|
269 | - foreach ( $vars as $handle => $var ) { |
|
270 | - if ( $var_name === 'eei18n' ) { |
|
271 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
272 | - } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
273 | - $this->localized_vars[ $var_name ] = $var; |
|
274 | - } else { |
|
275 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
276 | - $this->localized_vars[ $var_name ] = array(); |
|
277 | - } |
|
278 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @param string $utm_content |
|
287 | - * @throws DomainException |
|
288 | - */ |
|
289 | - public function display($utm_content = '') |
|
290 | - { |
|
291 | - $this->content .= EEH_Template::powered_by_event_espresso( |
|
292 | - '', |
|
293 | - '', |
|
294 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
295 | - ); |
|
296 | - EE_System::do_not_cache(); |
|
297 | - echo $this->getTemplate(); |
|
298 | - exit; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @return string |
|
305 | - * @throws DomainException |
|
306 | - */ |
|
307 | - public function getTemplate() |
|
308 | - { |
|
309 | - return EEH_Template::display_template( |
|
310 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
311 | - array( |
|
312 | - 'title' => apply_filters( |
|
313 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
314 | - $this->title, |
|
315 | - $this |
|
316 | - ), |
|
317 | - 'content' => apply_filters( |
|
318 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
319 | - $this->content, |
|
320 | - $this |
|
321 | - ), |
|
322 | - 'enqueue_wp_assets' => apply_filters( |
|
323 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
324 | - $this->enqueue_wp_assets, |
|
325 | - $this |
|
326 | - ), |
|
327 | - 'css' => (array)apply_filters( |
|
328 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
329 | - $this->css, |
|
330 | - $this |
|
331 | - ), |
|
332 | - 'header_js' => (array)apply_filters( |
|
333 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
334 | - $this->header_js, |
|
335 | - $this |
|
336 | - ), |
|
337 | - 'header_js_attributes' => (array) apply_filters( |
|
338 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
339 | - $this->header_js_attributes, |
|
340 | - $this |
|
341 | - ), |
|
342 | - 'footer_js' => (array)apply_filters( |
|
343 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
344 | - $this->footer_js, |
|
345 | - $this |
|
346 | - ), |
|
347 | - 'footer_js_attributes' => (array)apply_filters( |
|
348 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
349 | - $this->footer_js_attributes, |
|
350 | - $this |
|
351 | - ), |
|
352 | - 'eei18n' => apply_filters( |
|
353 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
354 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
355 | - $this |
|
356 | - ), |
|
357 | - 'notices' => EEH_Template::display_template( |
|
358 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
359 | - array(), |
|
360 | - true |
|
361 | - ), |
|
362 | - ), |
|
363 | - true, |
|
364 | - true |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * localizeJsonVars |
|
372 | - * |
|
373 | - * @return string |
|
374 | - */ |
|
375 | - public function localizeJsonVars() |
|
376 | - { |
|
377 | - $JSON = ''; |
|
378 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
379 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
380 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
381 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
382 | - $JSON .= '; /* ]]> */'; |
|
383 | - } |
|
384 | - return $JSON; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @param bool|int|float|string|array $var |
|
391 | - * @return array |
|
392 | - */ |
|
393 | - public function encodeJsonVars( $var ) |
|
394 | - { |
|
395 | - if ( is_array( $var ) ) { |
|
396 | - $localized_vars = array(); |
|
397 | - foreach ( (array)$var as $key => $value ) { |
|
398 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
399 | - } |
|
400 | - return $localized_vars; |
|
401 | - } |
|
402 | - if ( is_scalar( $var ) ) { |
|
403 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
404 | - } |
|
405 | - return null; |
|
406 | - } |
|
78 | + protected $localized_vars = array(); |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Iframe constructor |
|
84 | + * |
|
85 | + * @param string $title |
|
86 | + * @param string $content |
|
87 | + * @throws DomainException |
|
88 | + */ |
|
89 | + public function __construct( $title, $content ) |
|
90 | + { |
|
91 | + global $wp_version; |
|
92 | + if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
93 | + define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
94 | + } |
|
95 | + $this->setContent( $content ); |
|
96 | + $this->setTitle( $title ); |
|
97 | + $this->addStylesheets( |
|
98 | + apply_filters( |
|
99 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
100 | + array( |
|
101 | + 'site_theme' => get_stylesheet_directory_uri() . DS |
|
102 | + . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
103 | + 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
104 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
105 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
106 | + ), |
|
107 | + $this |
|
108 | + ) |
|
109 | + ); |
|
110 | + $this->addScripts( |
|
111 | + apply_filters( |
|
112 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
113 | + array( |
|
114 | + 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
115 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
116 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
117 | + ), |
|
118 | + $this |
|
119 | + ) |
|
120 | + ); |
|
121 | + if ( |
|
122 | + apply_filters( |
|
123 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
124 | + false |
|
125 | + ) |
|
126 | + ) { |
|
127 | + $this->addStylesheets( |
|
128 | + apply_filters( |
|
129 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
130 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
131 | + $this |
|
132 | + ) |
|
133 | + ); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $title |
|
141 | + * @throws DomainException |
|
142 | + */ |
|
143 | + public function setTitle( $title ) |
|
144 | + { |
|
145 | + if ( empty( $title ) ) { |
|
146 | + throw new DomainException( |
|
147 | + esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
148 | + ); |
|
149 | + } |
|
150 | + $this->title = $title; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param string $content |
|
157 | + * @throws DomainException |
|
158 | + */ |
|
159 | + public function setContent( $content ) |
|
160 | + { |
|
161 | + if ( empty( $content ) ) { |
|
162 | + throw new DomainException( |
|
163 | + esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
164 | + ); |
|
165 | + } |
|
166 | + $this->content = $content; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param boolean $enqueue_wp_assets |
|
173 | + */ |
|
174 | + public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
175 | + { |
|
176 | + $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @param array $stylesheets |
|
183 | + * @throws DomainException |
|
184 | + */ |
|
185 | + public function addStylesheets( array $stylesheets ) |
|
186 | + { |
|
187 | + if ( empty( $stylesheets ) ) { |
|
188 | + throw new DomainException( |
|
189 | + esc_html__( |
|
190 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
191 | + 'event_espresso' |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + foreach ( $stylesheets as $handle => $stylesheet ) { |
|
196 | + $this->css[ $handle ] = $stylesheet; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param array $scripts |
|
204 | + * @param bool $add_to_header |
|
205 | + * @throws DomainException |
|
206 | + */ |
|
207 | + public function addScripts( array $scripts, $add_to_header = false ) |
|
208 | + { |
|
209 | + if ( empty( $scripts ) ) { |
|
210 | + throw new DomainException( |
|
211 | + esc_html__( |
|
212 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
213 | + 'event_espresso' |
|
214 | + ) |
|
215 | + ); |
|
216 | + } |
|
217 | + foreach ( $scripts as $handle => $script ) { |
|
218 | + if ( $add_to_header ) { |
|
219 | + $this->header_js[ $handle ] = $script; |
|
220 | + } else { |
|
221 | + $this->footer_js[ $handle ] = $script; |
|
222 | + } |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @param array $script_attributes |
|
230 | + * @param bool $add_to_header |
|
231 | + * @throws DomainException |
|
232 | + */ |
|
233 | + public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
234 | + { |
|
235 | + if ( empty($script_attributes ) ) { |
|
236 | + throw new DomainException( |
|
237 | + esc_html__( |
|
238 | + 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
239 | + 'event_espresso' |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | + foreach ($script_attributes as $handle => $script_attribute ) { |
|
244 | + if ( $add_to_header ) { |
|
245 | + $this->header_js_attributes[ $handle ] = $script_attribute; |
|
246 | + } else { |
|
247 | + $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
248 | + } |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param array $vars |
|
256 | + * @param string $var_name |
|
257 | + * @throws DomainException |
|
258 | + */ |
|
259 | + public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
260 | + { |
|
261 | + if ( empty( $vars ) ) { |
|
262 | + throw new DomainException( |
|
263 | + esc_html__( |
|
264 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
265 | + 'event_espresso' |
|
266 | + ) |
|
267 | + ); |
|
268 | + } |
|
269 | + foreach ( $vars as $handle => $var ) { |
|
270 | + if ( $var_name === 'eei18n' ) { |
|
271 | + EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
272 | + } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
273 | + $this->localized_vars[ $var_name ] = $var; |
|
274 | + } else { |
|
275 | + if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
276 | + $this->localized_vars[ $var_name ] = array(); |
|
277 | + } |
|
278 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @param string $utm_content |
|
287 | + * @throws DomainException |
|
288 | + */ |
|
289 | + public function display($utm_content = '') |
|
290 | + { |
|
291 | + $this->content .= EEH_Template::powered_by_event_espresso( |
|
292 | + '', |
|
293 | + '', |
|
294 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
295 | + ); |
|
296 | + EE_System::do_not_cache(); |
|
297 | + echo $this->getTemplate(); |
|
298 | + exit; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @return string |
|
305 | + * @throws DomainException |
|
306 | + */ |
|
307 | + public function getTemplate() |
|
308 | + { |
|
309 | + return EEH_Template::display_template( |
|
310 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
311 | + array( |
|
312 | + 'title' => apply_filters( |
|
313 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
314 | + $this->title, |
|
315 | + $this |
|
316 | + ), |
|
317 | + 'content' => apply_filters( |
|
318 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
319 | + $this->content, |
|
320 | + $this |
|
321 | + ), |
|
322 | + 'enqueue_wp_assets' => apply_filters( |
|
323 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
324 | + $this->enqueue_wp_assets, |
|
325 | + $this |
|
326 | + ), |
|
327 | + 'css' => (array)apply_filters( |
|
328 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
329 | + $this->css, |
|
330 | + $this |
|
331 | + ), |
|
332 | + 'header_js' => (array)apply_filters( |
|
333 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
334 | + $this->header_js, |
|
335 | + $this |
|
336 | + ), |
|
337 | + 'header_js_attributes' => (array) apply_filters( |
|
338 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
339 | + $this->header_js_attributes, |
|
340 | + $this |
|
341 | + ), |
|
342 | + 'footer_js' => (array)apply_filters( |
|
343 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
344 | + $this->footer_js, |
|
345 | + $this |
|
346 | + ), |
|
347 | + 'footer_js_attributes' => (array)apply_filters( |
|
348 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
349 | + $this->footer_js_attributes, |
|
350 | + $this |
|
351 | + ), |
|
352 | + 'eei18n' => apply_filters( |
|
353 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
354 | + EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
355 | + $this |
|
356 | + ), |
|
357 | + 'notices' => EEH_Template::display_template( |
|
358 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
359 | + array(), |
|
360 | + true |
|
361 | + ), |
|
362 | + ), |
|
363 | + true, |
|
364 | + true |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * localizeJsonVars |
|
372 | + * |
|
373 | + * @return string |
|
374 | + */ |
|
375 | + public function localizeJsonVars() |
|
376 | + { |
|
377 | + $JSON = ''; |
|
378 | + foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
379 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
380 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
381 | + $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
382 | + $JSON .= '; /* ]]> */'; |
|
383 | + } |
|
384 | + return $JSON; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @param bool|int|float|string|array $var |
|
391 | + * @return array |
|
392 | + */ |
|
393 | + public function encodeJsonVars( $var ) |
|
394 | + { |
|
395 | + if ( is_array( $var ) ) { |
|
396 | + $localized_vars = array(); |
|
397 | + foreach ( (array)$var as $key => $value ) { |
|
398 | + $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
399 | + } |
|
400 | + return $localized_vars; |
|
401 | + } |
|
402 | + if ( is_scalar( $var ) ) { |
|
403 | + return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
404 | + } |
|
405 | + return null; |
|
406 | + } |
|
407 | 407 | |
408 | 408 | |
409 | 409 |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EE_System; |
7 | 7 | use EEH_Template; |
8 | 8 | |
9 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -86,23 +86,23 @@ discard block |
||
86 | 86 | * @param string $content |
87 | 87 | * @throws DomainException |
88 | 88 | */ |
89 | - public function __construct( $title, $content ) |
|
89 | + public function __construct($title, $content) |
|
90 | 90 | { |
91 | 91 | global $wp_version; |
92 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
93 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
92 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
93 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
94 | 94 | } |
95 | - $this->setContent( $content ); |
|
96 | - $this->setTitle( $title ); |
|
95 | + $this->setContent($content); |
|
96 | + $this->setTitle($title); |
|
97 | 97 | $this->addStylesheets( |
98 | 98 | apply_filters( |
99 | 99 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
100 | 100 | array( |
101 | - 'site_theme' => get_stylesheet_directory_uri() . DS |
|
102 | - . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
103 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
101 | + 'site_theme' => get_stylesheet_directory_uri().DS |
|
102 | + . 'style.css?ver='.EVENT_ESPRESSO_VERSION, |
|
103 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
104 | 104 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
105 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
105 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
106 | 106 | ), |
107 | 107 | $this |
108 | 108 | ) |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | apply_filters( |
112 | 112 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
113 | 113 | array( |
114 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
114 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
115 | 115 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
116 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
116 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
117 | 117 | ), |
118 | 118 | $this |
119 | 119 | ) |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | * @param string $title |
141 | 141 | * @throws DomainException |
142 | 142 | */ |
143 | - public function setTitle( $title ) |
|
143 | + public function setTitle($title) |
|
144 | 144 | { |
145 | - if ( empty( $title ) ) { |
|
145 | + if (empty($title)) { |
|
146 | 146 | throw new DomainException( |
147 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
147 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
148 | 148 | ); |
149 | 149 | } |
150 | 150 | $this->title = $title; |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | * @param string $content |
157 | 157 | * @throws DomainException |
158 | 158 | */ |
159 | - public function setContent( $content ) |
|
159 | + public function setContent($content) |
|
160 | 160 | { |
161 | - if ( empty( $content ) ) { |
|
161 | + if (empty($content)) { |
|
162 | 162 | throw new DomainException( |
163 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
163 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
164 | 164 | ); |
165 | 165 | } |
166 | 166 | $this->content = $content; |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | /** |
172 | 172 | * @param boolean $enqueue_wp_assets |
173 | 173 | */ |
174 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
174 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
175 | 175 | { |
176 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
176 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * @param array $stylesheets |
183 | 183 | * @throws DomainException |
184 | 184 | */ |
185 | - public function addStylesheets( array $stylesheets ) |
|
185 | + public function addStylesheets(array $stylesheets) |
|
186 | 186 | { |
187 | - if ( empty( $stylesheets ) ) { |
|
187 | + if (empty($stylesheets)) { |
|
188 | 188 | throw new DomainException( |
189 | 189 | esc_html__( |
190 | 190 | 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | ) |
193 | 193 | ); |
194 | 194 | } |
195 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
196 | - $this->css[ $handle ] = $stylesheet; |
|
195 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
196 | + $this->css[$handle] = $stylesheet; |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * @param bool $add_to_header |
205 | 205 | * @throws DomainException |
206 | 206 | */ |
207 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
207 | + public function addScripts(array $scripts, $add_to_header = false) |
|
208 | 208 | { |
209 | - if ( empty( $scripts ) ) { |
|
209 | + if (empty($scripts)) { |
|
210 | 210 | throw new DomainException( |
211 | 211 | esc_html__( |
212 | 212 | 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | } |
217 | - foreach ( $scripts as $handle => $script ) { |
|
218 | - if ( $add_to_header ) { |
|
219 | - $this->header_js[ $handle ] = $script; |
|
217 | + foreach ($scripts as $handle => $script) { |
|
218 | + if ($add_to_header) { |
|
219 | + $this->header_js[$handle] = $script; |
|
220 | 220 | } else { |
221 | - $this->footer_js[ $handle ] = $script; |
|
221 | + $this->footer_js[$handle] = $script; |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param bool $add_to_header |
231 | 231 | * @throws DomainException |
232 | 232 | */ |
233 | - public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
233 | + public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
234 | 234 | { |
235 | - if ( empty($script_attributes ) ) { |
|
235 | + if (empty($script_attributes)) { |
|
236 | 236 | throw new DomainException( |
237 | 237 | esc_html__( |
238 | 238 | 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
@@ -240,11 +240,11 @@ discard block |
||
240 | 240 | ) |
241 | 241 | ); |
242 | 242 | } |
243 | - foreach ($script_attributes as $handle => $script_attribute ) { |
|
244 | - if ( $add_to_header ) { |
|
245 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
243 | + foreach ($script_attributes as $handle => $script_attribute) { |
|
244 | + if ($add_to_header) { |
|
245 | + $this->header_js_attributes[$handle] = $script_attribute; |
|
246 | 246 | } else { |
247 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
247 | + $this->footer_js_attributes[$handle] = $script_attribute; |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | * @param string $var_name |
257 | 257 | * @throws DomainException |
258 | 258 | */ |
259 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
259 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
260 | 260 | { |
261 | - if ( empty( $vars ) ) { |
|
261 | + if (empty($vars)) { |
|
262 | 262 | throw new DomainException( |
263 | 263 | esc_html__( |
264 | 264 | 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
@@ -266,16 +266,16 @@ discard block |
||
266 | 266 | ) |
267 | 267 | ); |
268 | 268 | } |
269 | - foreach ( $vars as $handle => $var ) { |
|
270 | - if ( $var_name === 'eei18n' ) { |
|
271 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
269 | + foreach ($vars as $handle => $var) { |
|
270 | + if ($var_name === 'eei18n') { |
|
271 | + EE_Registry::$i18n_js_strings[$handle] = $var; |
|
272 | 272 | } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
273 | - $this->localized_vars[ $var_name ] = $var; |
|
273 | + $this->localized_vars[$var_name] = $var; |
|
274 | 274 | } else { |
275 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
276 | - $this->localized_vars[ $var_name ] = array(); |
|
275 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
276 | + $this->localized_vars[$var_name] = array(); |
|
277 | 277 | } |
278 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
278 | + $this->localized_vars[$var_name][$handle] = $var; |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | public function getTemplate() |
308 | 308 | { |
309 | 309 | return EEH_Template::display_template( |
310 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
310 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
311 | 311 | array( |
312 | 312 | 'title' => apply_filters( |
313 | 313 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -324,12 +324,12 @@ discard block |
||
324 | 324 | $this->enqueue_wp_assets, |
325 | 325 | $this |
326 | 326 | ), |
327 | - 'css' => (array)apply_filters( |
|
327 | + 'css' => (array) apply_filters( |
|
328 | 328 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
329 | 329 | $this->css, |
330 | 330 | $this |
331 | 331 | ), |
332 | - 'header_js' => (array)apply_filters( |
|
332 | + 'header_js' => (array) apply_filters( |
|
333 | 333 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
334 | 334 | $this->header_js, |
335 | 335 | $this |
@@ -339,23 +339,23 @@ discard block |
||
339 | 339 | $this->header_js_attributes, |
340 | 340 | $this |
341 | 341 | ), |
342 | - 'footer_js' => (array)apply_filters( |
|
342 | + 'footer_js' => (array) apply_filters( |
|
343 | 343 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
344 | 344 | $this->footer_js, |
345 | 345 | $this |
346 | 346 | ), |
347 | - 'footer_js_attributes' => (array)apply_filters( |
|
347 | + 'footer_js_attributes' => (array) apply_filters( |
|
348 | 348 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
349 | 349 | $this->footer_js_attributes, |
350 | 350 | $this |
351 | 351 | ), |
352 | 352 | 'eei18n' => apply_filters( |
353 | 353 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
354 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
354 | + EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
355 | 355 | $this |
356 | 356 | ), |
357 | 357 | 'notices' => EEH_Template::display_template( |
358 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
358 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
359 | 359 | array(), |
360 | 360 | true |
361 | 361 | ), |
@@ -375,10 +375,10 @@ discard block |
||
375 | 375 | public function localizeJsonVars() |
376 | 376 | { |
377 | 377 | $JSON = ''; |
378 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
379 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
378 | + foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
379 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($vars); |
|
380 | 380 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
381 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
381 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
382 | 382 | $JSON .= '; /* ]]> */'; |
383 | 383 | } |
384 | 384 | return $JSON; |
@@ -390,17 +390,17 @@ discard block |
||
390 | 390 | * @param bool|int|float|string|array $var |
391 | 391 | * @return array |
392 | 392 | */ |
393 | - public function encodeJsonVars( $var ) |
|
393 | + public function encodeJsonVars($var) |
|
394 | 394 | { |
395 | - if ( is_array( $var ) ) { |
|
395 | + if (is_array($var)) { |
|
396 | 396 | $localized_vars = array(); |
397 | - foreach ( (array)$var as $key => $value ) { |
|
398 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
397 | + foreach ((array) $var as $key => $value) { |
|
398 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
399 | 399 | } |
400 | 400 | return $localized_vars; |
401 | 401 | } |
402 | - if ( is_scalar( $var ) ) { |
|
403 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
402 | + if (is_scalar($var)) { |
|
403 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
404 | 404 | } |
405 | 405 | return null; |
406 | 406 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $this->registerManifestFile( |
105 | 105 | self::ASSET_NAMESPACE, |
106 | 106 | $this->domain->distributionAssetsUrl(), |
107 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
107 | + $this->domain->distributionAssetsPath().'build-manifest.json' |
|
108 | 108 | ); |
109 | 109 | add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
110 | 110 | add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | //js.api |
150 | 150 | wp_register_script( |
151 | 151 | 'eejs-api', |
152 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
152 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
153 | 153 | array('underscore', 'eejs-core'), |
154 | 154 | EVENT_ESPRESSO_VERSION, |
155 | 155 | true |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
158 | 158 | $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
159 | 159 | } |
160 | - if (! is_admin()) { |
|
160 | + if ( ! is_admin()) { |
|
161 | 161 | $this->loadCoreCss(); |
162 | 162 | } |
163 | 163 | $this->loadCoreJs(); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function addTemplate($template_reference, $template_content) |
256 | 256 | { |
257 | - if (! isset($this->jsdata['templates'])) { |
|
257 | + if ( ! isset($this->jsdata['templates'])) { |
|
258 | 258 | $this->jsdata['templates'] = array(); |
259 | 259 | } |
260 | 260 | //no overrides allowed. |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | ); |
369 | 369 | } |
370 | 370 | $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
371 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
371 | + if ( ! isset($this->manifest_data[$namespace]['url_base'])) { |
|
372 | 372 | $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
373 | 373 | } |
374 | 374 | } |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | */ |
386 | 386 | private function decodeManifestFile($manifest_file) |
387 | 387 | { |
388 | - if (! file_exists($manifest_file)) { |
|
388 | + if ( ! file_exists($manifest_file)) { |
|
389 | 389 | throw new InvalidFilePathException($manifest_file); |
390 | 390 | } |
391 | 391 | return json_decode(file_get_contents($manifest_file), true); |
@@ -440,9 +440,9 @@ discard block |
||
440 | 440 | private function loadCoreCss() |
441 | 441 | { |
442 | 442 | if ($this->template_config->enable_default_style) { |
443 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
443 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
444 | 444 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
445 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
445 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css'; |
|
446 | 446 | wp_register_style( |
447 | 447 | 'espresso_default', |
448 | 448 | $default_stylesheet_path, |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | if ($this->template_config->custom_style_sheet !== null) { |
454 | 454 | wp_register_style( |
455 | 455 | 'espresso_custom_css', |
456 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
456 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
457 | 457 | array('espresso_default'), |
458 | 458 | EVENT_ESPRESSO_VERSION |
459 | 459 | ); |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | // load core js |
472 | 472 | wp_register_script( |
473 | 473 | 'espresso_core', |
474 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
474 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
475 | 475 | array('jquery'), |
476 | 476 | EVENT_ESPRESSO_VERSION, |
477 | 477 | true |
@@ -488,14 +488,14 @@ discard block |
||
488 | 488 | // register jQuery Validate and additional methods |
489 | 489 | wp_register_script( |
490 | 490 | 'jquery-validate', |
491 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
491 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
492 | 492 | array('jquery'), |
493 | 493 | '1.15.0', |
494 | 494 | true |
495 | 495 | ); |
496 | 496 | wp_register_script( |
497 | 497 | 'jquery-validate-extra-methods', |
498 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
498 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
499 | 499 | array('jquery', 'jquery-validate'), |
500 | 500 | '1.15.0', |
501 | 501 | true |
@@ -513,14 +513,14 @@ discard block |
||
513 | 513 | // @link http://josscrowcroft.github.io/accounting.js/ |
514 | 514 | wp_register_script( |
515 | 515 | 'ee-accounting-core', |
516 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
516 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
517 | 517 | array('underscore'), |
518 | 518 | '0.3.2', |
519 | 519 | true |
520 | 520 | ); |
521 | 521 | wp_register_script( |
522 | 522 | 'ee-accounting', |
523 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
523 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
524 | 524 | array('ee-accounting-core'), |
525 | 525 | EVENT_ESPRESSO_VERSION, |
526 | 526 | true |
@@ -25,616 +25,616 @@ |
||
25 | 25 | class Registry |
26 | 26 | { |
27 | 27 | |
28 | - const ASSET_TYPE_CSS = 'css'; |
|
29 | - const ASSET_TYPE_JS = 'js'; |
|
30 | - const ASSET_NAMESPACE = 'core'; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Template_Config $template_config |
|
34 | - */ |
|
35 | - protected $template_config; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Currency_Config $currency_config |
|
39 | - */ |
|
40 | - protected $currency_config; |
|
41 | - |
|
42 | - /** |
|
43 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $jsdata = array(); |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
52 | - * page source. |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $script_handles_with_data = array(); |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @var DomainInterface |
|
60 | - */ |
|
61 | - protected $domain; |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Holds the manifest data obtained from registered manifest files. |
|
67 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
68 | - * Shape of this array is: |
|
69 | - * |
|
70 | - * array( |
|
71 | - * 'some_namespace_slug' => array( |
|
72 | - * 'some_chunk_name' => array( |
|
73 | - * 'js' => 'filename.js' |
|
74 | - * 'css' => 'filename.js' |
|
75 | - * ), |
|
76 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
77 | - * ) |
|
78 | - * ) |
|
79 | - * |
|
80 | - * @var array |
|
81 | - */ |
|
82 | - private $manifest_data = array(); |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Registry constructor. |
|
87 | - * Hooking into WP actions for script registry. |
|
88 | - * |
|
89 | - * @param EE_Template_Config $template_config |
|
90 | - * @param EE_Currency_Config $currency_config |
|
91 | - * @param DomainInterface $domain |
|
92 | - * @throws InvalidArgumentException |
|
93 | - * @throws InvalidFilePathException |
|
94 | - */ |
|
95 | - public function __construct( |
|
96 | - EE_Template_Config $template_config, |
|
97 | - EE_Currency_Config $currency_config, |
|
98 | - DomainInterface $domain |
|
99 | - ) { |
|
100 | - $this->template_config = $template_config; |
|
101 | - $this->currency_config = $currency_config; |
|
102 | - $this->domain = $domain; |
|
103 | - $this->registerManifestFile( |
|
104 | - self::ASSET_NAMESPACE, |
|
105 | - $this->domain->distributionAssetsUrl(), |
|
106 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
107 | - ); |
|
108 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
109 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
110 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
111 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
112 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
113 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Callback for the WP script actions. |
|
118 | - * Used to register globally accessible core scripts. |
|
119 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
120 | - * |
|
121 | - */ |
|
122 | - public function scripts() |
|
123 | - { |
|
124 | - global $wp_version; |
|
125 | - wp_register_script( |
|
126 | - 'ee-manifest', |
|
127 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'manifest', self::ASSET_TYPE_JS), |
|
128 | - array(), |
|
129 | - null, |
|
130 | - true |
|
131 | - ); |
|
132 | - wp_register_script( |
|
133 | - 'eejs-core', |
|
134 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'eejs', self::ASSET_TYPE_JS), |
|
135 | - array('ee-manifest'), |
|
136 | - null, |
|
137 | - true |
|
138 | - ); |
|
139 | - wp_register_script( |
|
140 | - 'ee-vendor-react', |
|
141 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'reactVendor', self::ASSET_TYPE_JS), |
|
142 | - array('eejs-core'), |
|
143 | - null, |
|
144 | - true |
|
145 | - ); |
|
146 | - //only run this if WordPress 4.4.0 > is in use. |
|
147 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
148 | - //js.api |
|
149 | - wp_register_script( |
|
150 | - 'eejs-api', |
|
151 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
152 | - array('underscore', 'eejs-core'), |
|
153 | - EVENT_ESPRESSO_VERSION, |
|
154 | - true |
|
155 | - ); |
|
156 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
157 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
158 | - } |
|
159 | - if (! is_admin()) { |
|
160 | - $this->loadCoreCss(); |
|
161 | - } |
|
162 | - $this->loadCoreJs(); |
|
163 | - $this->loadJqueryValidate(); |
|
164 | - $this->loadAccountingJs(); |
|
165 | - $this->loadQtipJs(); |
|
166 | - $this->registerAdminAssets(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Call back for the script print in frontend and backend. |
|
173 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
174 | - * |
|
175 | - * @since 4.9.31.rc.015 |
|
176 | - */ |
|
177 | - public function enqueueData() |
|
178 | - { |
|
179 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
180 | - wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
181 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
182 | - $this->localizeAccountingJs(); |
|
183 | - $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
184 | - $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Used to add data to eejs.data object. |
|
191 | - * Note: Overriding existing data is not allowed. |
|
192 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
193 | - * If the data you add is something like this: |
|
194 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
195 | - * It will be exposed in the page source as: |
|
196 | - * eejs.data.my_plugin_data.foo == gar |
|
197 | - * |
|
198 | - * @param string $key Key used to access your data |
|
199 | - * @param string|array $value Value to attach to key |
|
200 | - * @throws InvalidArgumentException |
|
201 | - */ |
|
202 | - public function addData($key, $value) |
|
203 | - { |
|
204 | - if ($this->verifyDataNotExisting($key)) { |
|
205 | - $this->jsdata[$key] = $value; |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
213 | - * elements in an array. |
|
214 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
215 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
216 | - * object like this, eejs.data.test = [ my_data, |
|
217 | - * ] |
|
218 | - * If there has already been a scalar value attached to the data object given key, then |
|
219 | - * this will throw an exception. |
|
220 | - * |
|
221 | - * @param string $key Key to attach data to. |
|
222 | - * @param string|array $value Value being registered. |
|
223 | - * @throws InvalidArgumentException |
|
224 | - */ |
|
225 | - public function pushData($key, $value) |
|
226 | - { |
|
227 | - if (isset($this->jsdata[$key]) |
|
228 | - && ! is_array($this->jsdata[$key]) |
|
229 | - ) { |
|
230 | - throw new invalidArgumentException( |
|
231 | - sprintf( |
|
232 | - __( |
|
233 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
28 | + const ASSET_TYPE_CSS = 'css'; |
|
29 | + const ASSET_TYPE_JS = 'js'; |
|
30 | + const ASSET_NAMESPACE = 'core'; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Template_Config $template_config |
|
34 | + */ |
|
35 | + protected $template_config; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Currency_Config $currency_config |
|
39 | + */ |
|
40 | + protected $currency_config; |
|
41 | + |
|
42 | + /** |
|
43 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $jsdata = array(); |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
52 | + * page source. |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $script_handles_with_data = array(); |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @var DomainInterface |
|
60 | + */ |
|
61 | + protected $domain; |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Holds the manifest data obtained from registered manifest files. |
|
67 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
68 | + * Shape of this array is: |
|
69 | + * |
|
70 | + * array( |
|
71 | + * 'some_namespace_slug' => array( |
|
72 | + * 'some_chunk_name' => array( |
|
73 | + * 'js' => 'filename.js' |
|
74 | + * 'css' => 'filename.js' |
|
75 | + * ), |
|
76 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
77 | + * ) |
|
78 | + * ) |
|
79 | + * |
|
80 | + * @var array |
|
81 | + */ |
|
82 | + private $manifest_data = array(); |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Registry constructor. |
|
87 | + * Hooking into WP actions for script registry. |
|
88 | + * |
|
89 | + * @param EE_Template_Config $template_config |
|
90 | + * @param EE_Currency_Config $currency_config |
|
91 | + * @param DomainInterface $domain |
|
92 | + * @throws InvalidArgumentException |
|
93 | + * @throws InvalidFilePathException |
|
94 | + */ |
|
95 | + public function __construct( |
|
96 | + EE_Template_Config $template_config, |
|
97 | + EE_Currency_Config $currency_config, |
|
98 | + DomainInterface $domain |
|
99 | + ) { |
|
100 | + $this->template_config = $template_config; |
|
101 | + $this->currency_config = $currency_config; |
|
102 | + $this->domain = $domain; |
|
103 | + $this->registerManifestFile( |
|
104 | + self::ASSET_NAMESPACE, |
|
105 | + $this->domain->distributionAssetsUrl(), |
|
106 | + $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
107 | + ); |
|
108 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
109 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
110 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
111 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
112 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
113 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Callback for the WP script actions. |
|
118 | + * Used to register globally accessible core scripts. |
|
119 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
120 | + * |
|
121 | + */ |
|
122 | + public function scripts() |
|
123 | + { |
|
124 | + global $wp_version; |
|
125 | + wp_register_script( |
|
126 | + 'ee-manifest', |
|
127 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'manifest', self::ASSET_TYPE_JS), |
|
128 | + array(), |
|
129 | + null, |
|
130 | + true |
|
131 | + ); |
|
132 | + wp_register_script( |
|
133 | + 'eejs-core', |
|
134 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'eejs', self::ASSET_TYPE_JS), |
|
135 | + array('ee-manifest'), |
|
136 | + null, |
|
137 | + true |
|
138 | + ); |
|
139 | + wp_register_script( |
|
140 | + 'ee-vendor-react', |
|
141 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'reactVendor', self::ASSET_TYPE_JS), |
|
142 | + array('eejs-core'), |
|
143 | + null, |
|
144 | + true |
|
145 | + ); |
|
146 | + //only run this if WordPress 4.4.0 > is in use. |
|
147 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
148 | + //js.api |
|
149 | + wp_register_script( |
|
150 | + 'eejs-api', |
|
151 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
152 | + array('underscore', 'eejs-core'), |
|
153 | + EVENT_ESPRESSO_VERSION, |
|
154 | + true |
|
155 | + ); |
|
156 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
157 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
158 | + } |
|
159 | + if (! is_admin()) { |
|
160 | + $this->loadCoreCss(); |
|
161 | + } |
|
162 | + $this->loadCoreJs(); |
|
163 | + $this->loadJqueryValidate(); |
|
164 | + $this->loadAccountingJs(); |
|
165 | + $this->loadQtipJs(); |
|
166 | + $this->registerAdminAssets(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Call back for the script print in frontend and backend. |
|
173 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
174 | + * |
|
175 | + * @since 4.9.31.rc.015 |
|
176 | + */ |
|
177 | + public function enqueueData() |
|
178 | + { |
|
179 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
180 | + wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
181 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
182 | + $this->localizeAccountingJs(); |
|
183 | + $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
184 | + $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Used to add data to eejs.data object. |
|
191 | + * Note: Overriding existing data is not allowed. |
|
192 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
193 | + * If the data you add is something like this: |
|
194 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
195 | + * It will be exposed in the page source as: |
|
196 | + * eejs.data.my_plugin_data.foo == gar |
|
197 | + * |
|
198 | + * @param string $key Key used to access your data |
|
199 | + * @param string|array $value Value to attach to key |
|
200 | + * @throws InvalidArgumentException |
|
201 | + */ |
|
202 | + public function addData($key, $value) |
|
203 | + { |
|
204 | + if ($this->verifyDataNotExisting($key)) { |
|
205 | + $this->jsdata[$key] = $value; |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
213 | + * elements in an array. |
|
214 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
215 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
216 | + * object like this, eejs.data.test = [ my_data, |
|
217 | + * ] |
|
218 | + * If there has already been a scalar value attached to the data object given key, then |
|
219 | + * this will throw an exception. |
|
220 | + * |
|
221 | + * @param string $key Key to attach data to. |
|
222 | + * @param string|array $value Value being registered. |
|
223 | + * @throws InvalidArgumentException |
|
224 | + */ |
|
225 | + public function pushData($key, $value) |
|
226 | + { |
|
227 | + if (isset($this->jsdata[$key]) |
|
228 | + && ! is_array($this->jsdata[$key]) |
|
229 | + ) { |
|
230 | + throw new invalidArgumentException( |
|
231 | + sprintf( |
|
232 | + __( |
|
233 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
234 | 234 | push values to this data element when it is an array.', |
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - $key, |
|
238 | - __METHOD__ |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - $this->jsdata[$key][] = $value; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Used to set content used by javascript for a template. |
|
249 | - * Note: Overrides of existing registered templates are not allowed. |
|
250 | - * |
|
251 | - * @param string $template_reference |
|
252 | - * @param string $template_content |
|
253 | - * @throws InvalidArgumentException |
|
254 | - */ |
|
255 | - public function addTemplate($template_reference, $template_content) |
|
256 | - { |
|
257 | - if (! isset($this->jsdata['templates'])) { |
|
258 | - $this->jsdata['templates'] = array(); |
|
259 | - } |
|
260 | - //no overrides allowed. |
|
261 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
262 | - throw new invalidArgumentException( |
|
263 | - sprintf( |
|
264 | - __( |
|
265 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $template_reference |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * Retrieve the template content already registered for the given reference. |
|
279 | - * |
|
280 | - * @param string $template_reference |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - public function getTemplate($template_reference) |
|
284 | - { |
|
285 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
286 | - ? $this->jsdata['templates'][$template_reference] |
|
287 | - : ''; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Retrieve registered data. |
|
294 | - * |
|
295 | - * @param string $key Name of key to attach data to. |
|
296 | - * @return mixed If there is no for the given key, then false is returned. |
|
297 | - */ |
|
298 | - public function getData($key) |
|
299 | - { |
|
300 | - return isset($this->jsdata[$key]) |
|
301 | - ? $this->jsdata[$key] |
|
302 | - : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Get the actual asset path for asset manifests. |
|
308 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
309 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
310 | - * asset file location. |
|
311 | - * @param string $chunk_name |
|
312 | - * @param string $asset_type |
|
313 | - * @return string |
|
314 | - * @since $VID:$ |
|
315 | - */ |
|
316 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
317 | - { |
|
318 | - $url = isset( |
|
319 | - $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
320 | - $this->manifest_data[$namespace]['url_base'] |
|
321 | - ) |
|
322 | - ? $this->manifest_data[$namespace]['url_base'] |
|
323 | - . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
324 | - : $chunk_name; |
|
325 | - return apply_filters( |
|
326 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
327 | - $url, |
|
328 | - $namespace, |
|
329 | - $chunk_name, |
|
330 | - $asset_type |
|
331 | - ); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
337 | - * |
|
338 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
339 | - * @param string $url_base The url base for the manifest file location. |
|
340 | - * @param string $manifest_file The absolute path to the manifest file. |
|
341 | - * @throws InvalidArgumentException |
|
342 | - * @throws InvalidFilePathException |
|
343 | - * @since $VID:$ |
|
344 | - */ |
|
345 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
346 | - { |
|
347 | - if (isset($this->manifest_data[$namespace])) { |
|
348 | - throw new InvalidArgumentException( |
|
349 | - sprintf( |
|
350 | - esc_html__( |
|
351 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
352 | - 'event_espresso' |
|
353 | - ), |
|
354 | - $namespace |
|
355 | - ) |
|
356 | - ); |
|
357 | - } |
|
358 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
359 | - throw new InvalidArgumentException( |
|
360 | - sprintf( |
|
361 | - esc_html__( |
|
362 | - 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
363 | - 'event_espresso' |
|
364 | - ), |
|
365 | - '$url_base', |
|
366 | - $url_base |
|
367 | - ) |
|
368 | - ); |
|
369 | - } |
|
370 | - $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
371 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
372 | - $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * Decodes json from the provided manifest file. |
|
380 | - * |
|
381 | - * @since $VID:$ |
|
382 | - * @param string $manifest_file Path to manifest file. |
|
383 | - * @return array |
|
384 | - * @throws InvalidFilePathException |
|
385 | - */ |
|
386 | - private function decodeManifestFile($manifest_file) |
|
387 | - { |
|
388 | - if (! file_exists($manifest_file)) { |
|
389 | - throw new InvalidFilePathException($manifest_file); |
|
390 | - } |
|
391 | - return json_decode(file_get_contents($manifest_file), true); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * Verifies whether the given data exists already on the jsdata array. |
|
398 | - * Overriding data is not allowed. |
|
399 | - * |
|
400 | - * @param string $key Index for data. |
|
401 | - * @return bool If valid then return true. |
|
402 | - * @throws InvalidArgumentException if data already exists. |
|
403 | - */ |
|
404 | - protected function verifyDataNotExisting($key) |
|
405 | - { |
|
406 | - if (isset($this->jsdata[$key])) { |
|
407 | - if (is_array($this->jsdata[$key])) { |
|
408 | - throw new InvalidArgumentException( |
|
409 | - sprintf( |
|
410 | - __( |
|
411 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + $key, |
|
238 | + __METHOD__ |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + $this->jsdata[$key][] = $value; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Used to set content used by javascript for a template. |
|
249 | + * Note: Overrides of existing registered templates are not allowed. |
|
250 | + * |
|
251 | + * @param string $template_reference |
|
252 | + * @param string $template_content |
|
253 | + * @throws InvalidArgumentException |
|
254 | + */ |
|
255 | + public function addTemplate($template_reference, $template_content) |
|
256 | + { |
|
257 | + if (! isset($this->jsdata['templates'])) { |
|
258 | + $this->jsdata['templates'] = array(); |
|
259 | + } |
|
260 | + //no overrides allowed. |
|
261 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
262 | + throw new invalidArgumentException( |
|
263 | + sprintf( |
|
264 | + __( |
|
265 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $template_reference |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * Retrieve the template content already registered for the given reference. |
|
279 | + * |
|
280 | + * @param string $template_reference |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + public function getTemplate($template_reference) |
|
284 | + { |
|
285 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
286 | + ? $this->jsdata['templates'][$template_reference] |
|
287 | + : ''; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Retrieve registered data. |
|
294 | + * |
|
295 | + * @param string $key Name of key to attach data to. |
|
296 | + * @return mixed If there is no for the given key, then false is returned. |
|
297 | + */ |
|
298 | + public function getData($key) |
|
299 | + { |
|
300 | + return isset($this->jsdata[$key]) |
|
301 | + ? $this->jsdata[$key] |
|
302 | + : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Get the actual asset path for asset manifests. |
|
308 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
309 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
310 | + * asset file location. |
|
311 | + * @param string $chunk_name |
|
312 | + * @param string $asset_type |
|
313 | + * @return string |
|
314 | + * @since $VID:$ |
|
315 | + */ |
|
316 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
317 | + { |
|
318 | + $url = isset( |
|
319 | + $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
320 | + $this->manifest_data[$namespace]['url_base'] |
|
321 | + ) |
|
322 | + ? $this->manifest_data[$namespace]['url_base'] |
|
323 | + . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
324 | + : $chunk_name; |
|
325 | + return apply_filters( |
|
326 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
327 | + $url, |
|
328 | + $namespace, |
|
329 | + $chunk_name, |
|
330 | + $asset_type |
|
331 | + ); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
337 | + * |
|
338 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
339 | + * @param string $url_base The url base for the manifest file location. |
|
340 | + * @param string $manifest_file The absolute path to the manifest file. |
|
341 | + * @throws InvalidArgumentException |
|
342 | + * @throws InvalidFilePathException |
|
343 | + * @since $VID:$ |
|
344 | + */ |
|
345 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
346 | + { |
|
347 | + if (isset($this->manifest_data[$namespace])) { |
|
348 | + throw new InvalidArgumentException( |
|
349 | + sprintf( |
|
350 | + esc_html__( |
|
351 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
352 | + 'event_espresso' |
|
353 | + ), |
|
354 | + $namespace |
|
355 | + ) |
|
356 | + ); |
|
357 | + } |
|
358 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
359 | + throw new InvalidArgumentException( |
|
360 | + sprintf( |
|
361 | + esc_html__( |
|
362 | + 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
363 | + 'event_espresso' |
|
364 | + ), |
|
365 | + '$url_base', |
|
366 | + $url_base |
|
367 | + ) |
|
368 | + ); |
|
369 | + } |
|
370 | + $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
371 | + if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
372 | + $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * Decodes json from the provided manifest file. |
|
380 | + * |
|
381 | + * @since $VID:$ |
|
382 | + * @param string $manifest_file Path to manifest file. |
|
383 | + * @return array |
|
384 | + * @throws InvalidFilePathException |
|
385 | + */ |
|
386 | + private function decodeManifestFile($manifest_file) |
|
387 | + { |
|
388 | + if (! file_exists($manifest_file)) { |
|
389 | + throw new InvalidFilePathException($manifest_file); |
|
390 | + } |
|
391 | + return json_decode(file_get_contents($manifest_file), true); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * Verifies whether the given data exists already on the jsdata array. |
|
398 | + * Overriding data is not allowed. |
|
399 | + * |
|
400 | + * @param string $key Index for data. |
|
401 | + * @return bool If valid then return true. |
|
402 | + * @throws InvalidArgumentException if data already exists. |
|
403 | + */ |
|
404 | + protected function verifyDataNotExisting($key) |
|
405 | + { |
|
406 | + if (isset($this->jsdata[$key])) { |
|
407 | + if (is_array($this->jsdata[$key])) { |
|
408 | + throw new InvalidArgumentException( |
|
409 | + sprintf( |
|
410 | + __( |
|
411 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
412 | 412 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
413 | 413 | %2$s method to push your value to the array.', |
414 | - 'event_espresso' |
|
415 | - ), |
|
416 | - $key, |
|
417 | - 'pushData()' |
|
418 | - ) |
|
419 | - ); |
|
420 | - } |
|
421 | - throw new InvalidArgumentException( |
|
422 | - sprintf( |
|
423 | - __( |
|
424 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
414 | + 'event_espresso' |
|
415 | + ), |
|
416 | + $key, |
|
417 | + 'pushData()' |
|
418 | + ) |
|
419 | + ); |
|
420 | + } |
|
421 | + throw new InvalidArgumentException( |
|
422 | + sprintf( |
|
423 | + __( |
|
424 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
425 | 425 | allowed. Consider attaching your value to a different key', |
426 | - 'event_espresso' |
|
427 | - ), |
|
428 | - $key |
|
429 | - ) |
|
430 | - ); |
|
431 | - } |
|
432 | - return true; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * registers core default stylesheets |
|
439 | - */ |
|
440 | - private function loadCoreCss() |
|
441 | - { |
|
442 | - if ($this->template_config->enable_default_style) { |
|
443 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
444 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
445 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
446 | - wp_register_style( |
|
447 | - 'espresso_default', |
|
448 | - $default_stylesheet_path, |
|
449 | - array('dashicons'), |
|
450 | - EVENT_ESPRESSO_VERSION |
|
451 | - ); |
|
452 | - //Load custom style sheet if available |
|
453 | - if ($this->template_config->custom_style_sheet !== null) { |
|
454 | - wp_register_style( |
|
455 | - 'espresso_custom_css', |
|
456 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
457 | - array('espresso_default'), |
|
458 | - EVENT_ESPRESSO_VERSION |
|
459 | - ); |
|
460 | - } |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * registers core default javascript |
|
468 | - */ |
|
469 | - private function loadCoreJs() |
|
470 | - { |
|
471 | - // load core js |
|
472 | - wp_register_script( |
|
473 | - 'espresso_core', |
|
474 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
475 | - array('jquery'), |
|
476 | - EVENT_ESPRESSO_VERSION, |
|
477 | - true |
|
478 | - ); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * registers jQuery Validate for form validation |
|
485 | - */ |
|
486 | - private function loadJqueryValidate() |
|
487 | - { |
|
488 | - // register jQuery Validate and additional methods |
|
489 | - wp_register_script( |
|
490 | - 'jquery-validate', |
|
491 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
492 | - array('jquery'), |
|
493 | - '1.15.0', |
|
494 | - true |
|
495 | - ); |
|
496 | - wp_register_script( |
|
497 | - 'jquery-validate-extra-methods', |
|
498 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
499 | - array('jquery', 'jquery-validate'), |
|
500 | - '1.15.0', |
|
501 | - true |
|
502 | - ); |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * registers accounting.js for performing client-side calculations |
|
509 | - */ |
|
510 | - private function loadAccountingJs() |
|
511 | - { |
|
512 | - //accounting.js library |
|
513 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
514 | - wp_register_script( |
|
515 | - 'ee-accounting-core', |
|
516 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
517 | - array('underscore'), |
|
518 | - '0.3.2', |
|
519 | - true |
|
520 | - ); |
|
521 | - wp_register_script( |
|
522 | - 'ee-accounting', |
|
523 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
524 | - array('ee-accounting-core'), |
|
525 | - EVENT_ESPRESSO_VERSION, |
|
526 | - true |
|
527 | - ); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * registers accounting.js for performing client-side calculations |
|
534 | - */ |
|
535 | - private function localizeAccountingJs() |
|
536 | - { |
|
537 | - wp_localize_script( |
|
538 | - 'ee-accounting', |
|
539 | - 'EE_ACCOUNTING_CFG', |
|
540 | - array( |
|
541 | - 'currency' => array( |
|
542 | - 'symbol' => $this->currency_config->sign, |
|
543 | - 'format' => array( |
|
544 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
545 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
546 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
547 | - ), |
|
548 | - 'decimal' => $this->currency_config->dec_mrk, |
|
549 | - 'thousand' => $this->currency_config->thsnds, |
|
550 | - 'precision' => $this->currency_config->dec_plc, |
|
551 | - ), |
|
552 | - 'number' => array( |
|
553 | - 'precision' => $this->currency_config->dec_plc, |
|
554 | - 'thousand' => $this->currency_config->thsnds, |
|
555 | - 'decimal' => $this->currency_config->dec_mrk, |
|
556 | - ), |
|
557 | - ) |
|
558 | - ); |
|
559 | - $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * registers assets for cleaning your ears |
|
566 | - */ |
|
567 | - private function loadQtipJs() |
|
568 | - { |
|
569 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
570 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
571 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
572 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * This is used to set registered script handles that have data. |
|
579 | - * @param string $script_handle |
|
580 | - */ |
|
581 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
582 | - { |
|
583 | - $this->script_handles_with_data[$script_handle] = $script_handle; |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
589 | - * Dependency stored in WP_Scripts if its set. |
|
590 | - */ |
|
591 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
592 | - { |
|
593 | - if (empty($this->script_handles_with_data)) { |
|
594 | - return; |
|
595 | - } |
|
596 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
597 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
604 | - * @param string $script_handle |
|
605 | - */ |
|
606 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
607 | - { |
|
608 | - if (isset($this->script_handles_with_data[$script_handle])) { |
|
609 | - global $wp_scripts; |
|
610 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
611 | - unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
612 | - unset($this->script_handles_with_data[$script_handle]); |
|
613 | - } |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * Registers assets that are used in the WordPress admin. |
|
620 | - */ |
|
621 | - private function registerAdminAssets() |
|
622 | - { |
|
623 | - wp_register_script( |
|
624 | - 'ee-wp-plugins-page', |
|
625 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_JS), |
|
626 | - array( |
|
627 | - 'jquery', |
|
628 | - 'ee-vendor-react' |
|
629 | - ), |
|
630 | - null, |
|
631 | - true |
|
632 | - ); |
|
633 | - wp_register_style( |
|
634 | - 'ee-wp-plugins-page', |
|
635 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_CSS), |
|
636 | - array(), |
|
637 | - null |
|
638 | - ); |
|
639 | - } |
|
426 | + 'event_espresso' |
|
427 | + ), |
|
428 | + $key |
|
429 | + ) |
|
430 | + ); |
|
431 | + } |
|
432 | + return true; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * registers core default stylesheets |
|
439 | + */ |
|
440 | + private function loadCoreCss() |
|
441 | + { |
|
442 | + if ($this->template_config->enable_default_style) { |
|
443 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
444 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
445 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
446 | + wp_register_style( |
|
447 | + 'espresso_default', |
|
448 | + $default_stylesheet_path, |
|
449 | + array('dashicons'), |
|
450 | + EVENT_ESPRESSO_VERSION |
|
451 | + ); |
|
452 | + //Load custom style sheet if available |
|
453 | + if ($this->template_config->custom_style_sheet !== null) { |
|
454 | + wp_register_style( |
|
455 | + 'espresso_custom_css', |
|
456 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
457 | + array('espresso_default'), |
|
458 | + EVENT_ESPRESSO_VERSION |
|
459 | + ); |
|
460 | + } |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * registers core default javascript |
|
468 | + */ |
|
469 | + private function loadCoreJs() |
|
470 | + { |
|
471 | + // load core js |
|
472 | + wp_register_script( |
|
473 | + 'espresso_core', |
|
474 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
475 | + array('jquery'), |
|
476 | + EVENT_ESPRESSO_VERSION, |
|
477 | + true |
|
478 | + ); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * registers jQuery Validate for form validation |
|
485 | + */ |
|
486 | + private function loadJqueryValidate() |
|
487 | + { |
|
488 | + // register jQuery Validate and additional methods |
|
489 | + wp_register_script( |
|
490 | + 'jquery-validate', |
|
491 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
492 | + array('jquery'), |
|
493 | + '1.15.0', |
|
494 | + true |
|
495 | + ); |
|
496 | + wp_register_script( |
|
497 | + 'jquery-validate-extra-methods', |
|
498 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
499 | + array('jquery', 'jquery-validate'), |
|
500 | + '1.15.0', |
|
501 | + true |
|
502 | + ); |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * registers accounting.js for performing client-side calculations |
|
509 | + */ |
|
510 | + private function loadAccountingJs() |
|
511 | + { |
|
512 | + //accounting.js library |
|
513 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
514 | + wp_register_script( |
|
515 | + 'ee-accounting-core', |
|
516 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
517 | + array('underscore'), |
|
518 | + '0.3.2', |
|
519 | + true |
|
520 | + ); |
|
521 | + wp_register_script( |
|
522 | + 'ee-accounting', |
|
523 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
524 | + array('ee-accounting-core'), |
|
525 | + EVENT_ESPRESSO_VERSION, |
|
526 | + true |
|
527 | + ); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * registers accounting.js for performing client-side calculations |
|
534 | + */ |
|
535 | + private function localizeAccountingJs() |
|
536 | + { |
|
537 | + wp_localize_script( |
|
538 | + 'ee-accounting', |
|
539 | + 'EE_ACCOUNTING_CFG', |
|
540 | + array( |
|
541 | + 'currency' => array( |
|
542 | + 'symbol' => $this->currency_config->sign, |
|
543 | + 'format' => array( |
|
544 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
545 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
546 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
547 | + ), |
|
548 | + 'decimal' => $this->currency_config->dec_mrk, |
|
549 | + 'thousand' => $this->currency_config->thsnds, |
|
550 | + 'precision' => $this->currency_config->dec_plc, |
|
551 | + ), |
|
552 | + 'number' => array( |
|
553 | + 'precision' => $this->currency_config->dec_plc, |
|
554 | + 'thousand' => $this->currency_config->thsnds, |
|
555 | + 'decimal' => $this->currency_config->dec_mrk, |
|
556 | + ), |
|
557 | + ) |
|
558 | + ); |
|
559 | + $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * registers assets for cleaning your ears |
|
566 | + */ |
|
567 | + private function loadQtipJs() |
|
568 | + { |
|
569 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
570 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
571 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
572 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * This is used to set registered script handles that have data. |
|
579 | + * @param string $script_handle |
|
580 | + */ |
|
581 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
582 | + { |
|
583 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
589 | + * Dependency stored in WP_Scripts if its set. |
|
590 | + */ |
|
591 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
592 | + { |
|
593 | + if (empty($this->script_handles_with_data)) { |
|
594 | + return; |
|
595 | + } |
|
596 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
597 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
604 | + * @param string $script_handle |
|
605 | + */ |
|
606 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
607 | + { |
|
608 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
609 | + global $wp_scripts; |
|
610 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
611 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
612 | + unset($this->script_handles_with_data[$script_handle]); |
|
613 | + } |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * Registers assets that are used in the WordPress admin. |
|
620 | + */ |
|
621 | + private function registerAdminAssets() |
|
622 | + { |
|
623 | + wp_register_script( |
|
624 | + 'ee-wp-plugins-page', |
|
625 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_JS), |
|
626 | + array( |
|
627 | + 'jquery', |
|
628 | + 'ee-vendor-react' |
|
629 | + ), |
|
630 | + null, |
|
631 | + true |
|
632 | + ); |
|
633 | + wp_register_style( |
|
634 | + 'ee-wp-plugins-page', |
|
635 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_CSS), |
|
636 | + array(), |
|
637 | + null |
|
638 | + ); |
|
639 | + } |
|
640 | 640 | } |
@@ -19,94 +19,94 @@ |
||
19 | 19 | class ExitModal |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var Registry |
|
24 | - */ |
|
25 | - private $assets_registry; |
|
22 | + /** |
|
23 | + * @var Registry |
|
24 | + */ |
|
25 | + private $assets_registry; |
|
26 | 26 | |
27 | - /** |
|
28 | - * ExitModal constructor. |
|
29 | - * |
|
30 | - * @param Registry $assets_registry |
|
31 | - */ |
|
32 | - public function __construct(Registry $assets_registry) |
|
33 | - { |
|
34 | - $this->assets_registry = $assets_registry; |
|
35 | - add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | - add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | - } |
|
27 | + /** |
|
28 | + * ExitModal constructor. |
|
29 | + * |
|
30 | + * @param Registry $assets_registry |
|
31 | + */ |
|
32 | + public function __construct(Registry $assets_registry) |
|
33 | + { |
|
34 | + $this->assets_registry = $assets_registry; |
|
35 | + add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | + add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | - */ |
|
43 | - public function modalContainer() |
|
44 | - { |
|
45 | - echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | + */ |
|
43 | + public function modalContainer() |
|
44 | + { |
|
45 | + echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | - * |
|
52 | - * @throws InvalidArgumentException |
|
53 | - */ |
|
54 | - public function enqueues() |
|
55 | - { |
|
56 | - $current_user = new WP_User(get_current_user_id()); |
|
57 | - $this->assets_registry->addData( |
|
58 | - 'exitModali18n', |
|
59 | - array( |
|
60 | - 'introText' => htmlspecialchars( |
|
61 | - __( |
|
62 | - 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - ENT_NOQUOTES |
|
66 | - ), |
|
67 | - 'doSurveyButtonText' => htmlspecialchars( |
|
68 | - __( |
|
69 | - 'Sure I\'ll help', |
|
70 | - 'event_espresso' |
|
71 | - ), |
|
72 | - ENT_NOQUOTES |
|
73 | - ), |
|
74 | - 'skipButtonText' => htmlspecialchars( |
|
75 | - __( |
|
76 | - 'Skip', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - ENT_NOQUOTES |
|
80 | - ) |
|
81 | - ) |
|
82 | - ); |
|
83 | - $this->assets_registry->addData( |
|
84 | - 'exitModalInfo', |
|
85 | - array( |
|
86 | - 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | - 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | - 'website' => htmlspecialchars(site_url()), |
|
89 | - 'isModalActive' => $this->isModalActive() |
|
90 | - ) |
|
91 | - ); |
|
49 | + /** |
|
50 | + * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | + * |
|
52 | + * @throws InvalidArgumentException |
|
53 | + */ |
|
54 | + public function enqueues() |
|
55 | + { |
|
56 | + $current_user = new WP_User(get_current_user_id()); |
|
57 | + $this->assets_registry->addData( |
|
58 | + 'exitModali18n', |
|
59 | + array( |
|
60 | + 'introText' => htmlspecialchars( |
|
61 | + __( |
|
62 | + 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + ENT_NOQUOTES |
|
66 | + ), |
|
67 | + 'doSurveyButtonText' => htmlspecialchars( |
|
68 | + __( |
|
69 | + 'Sure I\'ll help', |
|
70 | + 'event_espresso' |
|
71 | + ), |
|
72 | + ENT_NOQUOTES |
|
73 | + ), |
|
74 | + 'skipButtonText' => htmlspecialchars( |
|
75 | + __( |
|
76 | + 'Skip', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + ENT_NOQUOTES |
|
80 | + ) |
|
81 | + ) |
|
82 | + ); |
|
83 | + $this->assets_registry->addData( |
|
84 | + 'exitModalInfo', |
|
85 | + array( |
|
86 | + 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | + 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | + 'website' => htmlspecialchars(site_url()), |
|
89 | + 'isModalActive' => $this->isModalActive() |
|
90 | + ) |
|
91 | + ); |
|
92 | 92 | |
93 | - wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | - wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | - } |
|
93 | + wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | + wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - private function isModalActive() |
|
103 | - { |
|
104 | - return filter_var( |
|
105 | - apply_filters( |
|
106 | - 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | - true |
|
108 | - ), |
|
109 | - FILTER_VALIDATE_BOOLEAN |
|
110 | - ); |
|
111 | - } |
|
98 | + /** |
|
99 | + * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + private function isModalActive() |
|
103 | + { |
|
104 | + return filter_var( |
|
105 | + apply_filters( |
|
106 | + 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | + true |
|
108 | + ), |
|
109 | + FILTER_VALIDATE_BOOLEAN |
|
110 | + ); |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | \ No newline at end of file |