@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __construct() |
53 | 53 | { |
54 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
54 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | $this->_load_class_tools(); |
106 | 106 | // load interfaces |
107 | 107 | espresso_load_required('EEI_Payment_Method_Interfaces', |
108 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
108 | + EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); |
|
109 | 109 | // deprecated functions |
110 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
110 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
111 | 111 | // WP cron jobs |
112 | 112 | $loader->getShared('EE_Cron_Tasks'); |
113 | 113 | $loader->getShared('EE_Request_Handler'); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function dependency_map() |
145 | 145 | { |
146 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
146 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
147 | 147 | throw new EE_Error( |
148 | 148 | sprintf( |
149 | 149 | __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function registry() |
164 | 164 | { |
165 | - if (! $this->registry instanceof EE_Registry) { |
|
165 | + if ( ! $this->registry instanceof EE_Registry) { |
|
166 | 166 | throw new EE_Error( |
167 | 167 | sprintf( |
168 | 168 | __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | */ |
181 | 181 | private function _load_dependency_map() |
182 | 182 | { |
183 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
183 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
184 | 184 | EE_Error::add_error( |
185 | 185 | __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
186 | 186 | __FILE__, __FUNCTION__, __LINE__ |
187 | 187 | ); |
188 | 188 | wp_die(EE_Error::get_notices()); |
189 | 189 | } |
190 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
190 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
191 | 191 | return EE_Dependency_Map::instance($this->request, $this->response); |
192 | 192 | } |
193 | 193 | |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | */ |
199 | 199 | private function _load_registry() |
200 | 200 | { |
201 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
201 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
202 | 202 | EE_Error::add_error( |
203 | 203 | __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
204 | 204 | __FILE__, __FUNCTION__, __LINE__ |
205 | 205 | ); |
206 | 206 | wp_die(EE_Error::get_notices()); |
207 | 207 | } |
208 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
208 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
209 | 209 | return EE_Registry::instance($this->dependency_map); |
210 | 210 | } |
211 | 211 | |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function _load_class_tools() |
218 | 218 | { |
219 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
219 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
220 | 220 | EE_Error::add_error( |
221 | 221 | __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
222 | 222 | __FILE__, __FUNCTION__, __LINE__ |
223 | 223 | ); |
224 | 224 | } |
225 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
225 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -24,208 +24,208 @@ discard block |
||
24 | 24 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EE_Request $request |
|
29 | - */ |
|
30 | - protected $request; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Response $response |
|
34 | - */ |
|
35 | - protected $response; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Dependency_Map $dependency_map |
|
39 | - */ |
|
40 | - protected $dependency_map; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Registry $registry |
|
44 | - */ |
|
45 | - protected $registry; |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * EE_Load_Espresso_Core constructor |
|
51 | - */ |
|
52 | - public function __construct() |
|
53 | - { |
|
54 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * handle |
|
61 | - * sets hooks for running rest of system |
|
62 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
63 | - * starting EE Addons from any other point may lead to problems |
|
64 | - * |
|
65 | - * @param EE_Request $request |
|
66 | - * @param EE_Response $response |
|
67 | - * @return EE_Response |
|
68 | - * @throws EE_Error |
|
69 | - * @throws InvalidDataTypeException |
|
70 | - * @throws InvalidInterfaceException |
|
71 | - * @throws InvalidArgumentException |
|
72 | - */ |
|
73 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
74 | - { |
|
75 | - $this->request = $request; |
|
76 | - $this->response = $response; |
|
77 | - // info about how to load classes required by other classes |
|
78 | - $this->dependency_map = $this->_load_dependency_map(); |
|
79 | - // central repository for classes |
|
80 | - $this->registry = $this->_load_registry(); |
|
81 | - // PSR4 Autoloaders |
|
82 | - $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
83 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
84 | - $loader = LoaderFactory::getLoader($this->registry); |
|
85 | - $this->dependency_map->setLoader($loader); |
|
86 | - // build DI container |
|
87 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
88 | - // $OpenCoffeeShop->addRecipes(); |
|
89 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
90 | - // workarounds for PHP < 5.3 |
|
91 | - $this->_load_class_tools(); |
|
92 | - // load interfaces |
|
93 | - espresso_load_required('EEI_Payment_Method_Interfaces', |
|
94 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
95 | - // deprecated functions |
|
96 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
97 | - // WP cron jobs |
|
98 | - $loader->getShared('EE_Cron_Tasks'); |
|
99 | - $loader->getShared('EE_Request_Handler'); |
|
100 | - $loader->getShared('EE_System'); |
|
101 | - return $this->response; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return EE_Request |
|
108 | - */ |
|
109 | - public function request() |
|
110 | - { |
|
111 | - return $this->request; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return EE_Response |
|
118 | - */ |
|
119 | - public function response() |
|
120 | - { |
|
121 | - return $this->response; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return EE_Dependency_Map |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function dependency_map() |
|
131 | - { |
|
132 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
133 | - throw new EE_Error( |
|
134 | - sprintf( |
|
135 | - __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
136 | - print_r($this->dependency_map, true) |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
140 | - return $this->dependency_map; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return EE_Registry |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - public function registry() |
|
150 | - { |
|
151 | - if (! $this->registry instanceof EE_Registry) { |
|
152 | - throw new EE_Error( |
|
153 | - sprintf( |
|
154 | - __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
155 | - print_r($this->registry, true) |
|
156 | - ) |
|
157 | - ); |
|
158 | - } |
|
159 | - return $this->registry; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @return EE_Dependency_Map |
|
166 | - */ |
|
167 | - private function _load_dependency_map() |
|
168 | - { |
|
169 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
170 | - EE_Error::add_error( |
|
171 | - __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
172 | - __FILE__, __FUNCTION__, __LINE__ |
|
173 | - ); |
|
174 | - wp_die(EE_Error::get_notices()); |
|
175 | - } |
|
176 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
177 | - return EE_Dependency_Map::instance($this->request, $this->response); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @return EE_Registry |
|
184 | - */ |
|
185 | - private function _load_registry() |
|
186 | - { |
|
187 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
188 | - EE_Error::add_error( |
|
189 | - __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
190 | - __FILE__, __FUNCTION__, __LINE__ |
|
191 | - ); |
|
192 | - wp_die(EE_Error::get_notices()); |
|
193 | - } |
|
194 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
195 | - return EE_Registry::instance($this->dependency_map); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - private function _load_class_tools() |
|
204 | - { |
|
205 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
206 | - EE_Error::add_error( |
|
207 | - __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
208 | - __FILE__, __FUNCTION__, __LINE__ |
|
209 | - ); |
|
210 | - } |
|
211 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * called after the request stack has been fully processed |
|
218 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
219 | - * |
|
220 | - * @param EE_Request $request |
|
221 | - * @param EE_Response $response |
|
222 | - */ |
|
223 | - public function handle_response(EE_Request $request, EE_Response $response) |
|
224 | - { |
|
225 | - if ($response->plugin_deactivated()) { |
|
226 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
227 | - } |
|
228 | - } |
|
27 | + /** |
|
28 | + * @var EE_Request $request |
|
29 | + */ |
|
30 | + protected $request; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Response $response |
|
34 | + */ |
|
35 | + protected $response; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Dependency_Map $dependency_map |
|
39 | + */ |
|
40 | + protected $dependency_map; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Registry $registry |
|
44 | + */ |
|
45 | + protected $registry; |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * EE_Load_Espresso_Core constructor |
|
51 | + */ |
|
52 | + public function __construct() |
|
53 | + { |
|
54 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * handle |
|
61 | + * sets hooks for running rest of system |
|
62 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
63 | + * starting EE Addons from any other point may lead to problems |
|
64 | + * |
|
65 | + * @param EE_Request $request |
|
66 | + * @param EE_Response $response |
|
67 | + * @return EE_Response |
|
68 | + * @throws EE_Error |
|
69 | + * @throws InvalidDataTypeException |
|
70 | + * @throws InvalidInterfaceException |
|
71 | + * @throws InvalidArgumentException |
|
72 | + */ |
|
73 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
74 | + { |
|
75 | + $this->request = $request; |
|
76 | + $this->response = $response; |
|
77 | + // info about how to load classes required by other classes |
|
78 | + $this->dependency_map = $this->_load_dependency_map(); |
|
79 | + // central repository for classes |
|
80 | + $this->registry = $this->_load_registry(); |
|
81 | + // PSR4 Autoloaders |
|
82 | + $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
83 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
84 | + $loader = LoaderFactory::getLoader($this->registry); |
|
85 | + $this->dependency_map->setLoader($loader); |
|
86 | + // build DI container |
|
87 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
88 | + // $OpenCoffeeShop->addRecipes(); |
|
89 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
90 | + // workarounds for PHP < 5.3 |
|
91 | + $this->_load_class_tools(); |
|
92 | + // load interfaces |
|
93 | + espresso_load_required('EEI_Payment_Method_Interfaces', |
|
94 | + EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
95 | + // deprecated functions |
|
96 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
97 | + // WP cron jobs |
|
98 | + $loader->getShared('EE_Cron_Tasks'); |
|
99 | + $loader->getShared('EE_Request_Handler'); |
|
100 | + $loader->getShared('EE_System'); |
|
101 | + return $this->response; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return EE_Request |
|
108 | + */ |
|
109 | + public function request() |
|
110 | + { |
|
111 | + return $this->request; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return EE_Response |
|
118 | + */ |
|
119 | + public function response() |
|
120 | + { |
|
121 | + return $this->response; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return EE_Dependency_Map |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function dependency_map() |
|
131 | + { |
|
132 | + if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
133 | + throw new EE_Error( |
|
134 | + sprintf( |
|
135 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
136 | + print_r($this->dependency_map, true) |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | + return $this->dependency_map; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return EE_Registry |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + public function registry() |
|
150 | + { |
|
151 | + if (! $this->registry instanceof EE_Registry) { |
|
152 | + throw new EE_Error( |
|
153 | + sprintf( |
|
154 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
155 | + print_r($this->registry, true) |
|
156 | + ) |
|
157 | + ); |
|
158 | + } |
|
159 | + return $this->registry; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @return EE_Dependency_Map |
|
166 | + */ |
|
167 | + private function _load_dependency_map() |
|
168 | + { |
|
169 | + if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
170 | + EE_Error::add_error( |
|
171 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
172 | + __FILE__, __FUNCTION__, __LINE__ |
|
173 | + ); |
|
174 | + wp_die(EE_Error::get_notices()); |
|
175 | + } |
|
176 | + require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
177 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @return EE_Registry |
|
184 | + */ |
|
185 | + private function _load_registry() |
|
186 | + { |
|
187 | + if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
188 | + EE_Error::add_error( |
|
189 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
190 | + __FILE__, __FUNCTION__, __LINE__ |
|
191 | + ); |
|
192 | + wp_die(EE_Error::get_notices()); |
|
193 | + } |
|
194 | + require_once(EE_CORE . 'EE_Registry.core.php'); |
|
195 | + return EE_Registry::instance($this->dependency_map); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + private function _load_class_tools() |
|
204 | + { |
|
205 | + if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
206 | + EE_Error::add_error( |
|
207 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
208 | + __FILE__, __FUNCTION__, __LINE__ |
|
209 | + ); |
|
210 | + } |
|
211 | + require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * called after the request stack has been fully processed |
|
218 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
219 | + * |
|
220 | + * @param EE_Request $request |
|
221 | + * @param EE_Response $response |
|
222 | + */ |
|
223 | + public function handle_response(EE_Request $request, EE_Response $response) |
|
224 | + { |
|
225 | + if ($response->plugin_deactivated()) { |
|
226 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | 231 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
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 | require_once(EE_MODELS . 'EEM_Base.model.php'); |
7 | 7 | |
@@ -17,193 +17,193 @@ discard block |
||
17 | 17 | class EEM_Transaction extends EEM_Base |
18 | 18 | { |
19 | 19 | |
20 | - // private instance of the Transaction object |
|
21 | - protected static $_instance; |
|
22 | - |
|
23 | - /** |
|
24 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | - * but payment is pending. This is the state for transactions where payment is promised |
|
26 | - * from an offline gateway. |
|
27 | - */ |
|
28 | - // const open_status_code = 'TPN'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | - * either due to a technical reason (server or computer crash during registration), |
|
33 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | - */ |
|
35 | - const failed_status_code = 'TFL'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | - * either due to a technical reason (server or computer crash during registration), |
|
40 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | - * HOWEVER... |
|
42 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | - * registrant |
|
44 | - */ |
|
45 | - const abandoned_status_code = 'TAB'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | - */ |
|
51 | - const incomplete_status_code = 'TIN'; |
|
52 | - |
|
53 | - /** |
|
54 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | - */ |
|
57 | - const complete_status_code = 'TCM'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | - */ |
|
63 | - const overpaid_status_code = 'TOP'; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * private constructor to prevent direct creation |
|
68 | - * |
|
69 | - * @Constructor |
|
70 | - * @access protected |
|
71 | - * |
|
72 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
73 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
74 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
75 | - * timezone in the 'timezone_string' wp option) |
|
76 | - * |
|
77 | - * @return EEM_Transaction |
|
78 | - * @throws \EE_Error |
|
79 | - */ |
|
80 | - protected function __construct($timezone) |
|
81 | - { |
|
82 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
83 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
84 | - |
|
85 | - $this->_tables = array( |
|
86 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
87 | - ); |
|
88 | - $this->_fields = array( |
|
89 | - 'TransactionTable' => array( |
|
90 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
91 | - 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
92 | - __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
93 | - $timezone), |
|
94 | - 'TXN_total' => new EE_Money_Field('TXN_total', |
|
95 | - __('Total value of Transaction', 'event_espresso'), false, 0), |
|
96 | - 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
97 | - __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
98 | - 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
99 | - false, EEM_Transaction::failed_status_code, 'Status'), |
|
100 | - 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
101 | - __('Serialized session data', 'event_espresso'), true, ''), |
|
102 | - 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
103 | - __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
104 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
105 | - __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
106 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
107 | - __('Registration Steps', 'event_espresso'), false, array()), |
|
108 | - ) |
|
109 | - ); |
|
110 | - $this->_model_relations = array( |
|
111 | - 'Registration' => new EE_Has_Many_Relation(), |
|
112 | - 'Payment' => new EE_Has_Many_Relation(), |
|
113 | - 'Status' => new EE_Belongs_To_Relation(), |
|
114 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
115 | - //you can delete a transaction without needing to delete its line items |
|
116 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
117 | - 'Message' => new EE_Has_Many_Relation() |
|
118 | - ); |
|
119 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
120 | - parent::__construct($timezone); |
|
121 | - |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * txn_status_array |
|
127 | - * get list of transaction statuses |
|
128 | - * |
|
129 | - * @access public |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public static function txn_status_array() |
|
133 | - { |
|
134 | - return apply_filters( |
|
135 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
136 | - array( |
|
137 | - EEM_Transaction::overpaid_status_code, |
|
138 | - EEM_Transaction::complete_status_code, |
|
139 | - EEM_Transaction::incomplete_status_code, |
|
140 | - EEM_Transaction::abandoned_status_code, |
|
141 | - EEM_Transaction::failed_status_code, |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
148 | - * |
|
149 | - * @access public |
|
150 | - * |
|
151 | - * @param string $period |
|
152 | - * |
|
153 | - * @return \stdClass[] |
|
154 | - */ |
|
155 | - public function get_revenue_per_day_report($period = '-1 month') |
|
156 | - { |
|
157 | - $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
158 | - 'Y-m-d H:i:s', 'UTC'); |
|
159 | - |
|
160 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
161 | - |
|
162 | - return $this->_get_all_wpdb_results( |
|
163 | - array( |
|
164 | - array( |
|
165 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
166 | - ), |
|
167 | - 'group_by' => 'txnDate', |
|
168 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
169 | - ), |
|
170 | - OBJECT, |
|
171 | - array( |
|
172 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
173 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
181 | - * |
|
182 | - * @access public |
|
183 | - * |
|
184 | - * @param string $period |
|
185 | - * |
|
186 | - * @throws \EE_Error |
|
187 | - * @return mixed |
|
188 | - */ |
|
189 | - public function get_revenue_per_event_report($period = '-1 month') |
|
190 | - { |
|
191 | - global $wpdb; |
|
192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
195 | - $event_table = $wpdb->posts; |
|
196 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
197 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
198 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
199 | - $extra_event_on_join = ''; |
|
200 | - //exclude events not authored by user if permissions in effect |
|
201 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
203 | - } |
|
204 | - |
|
205 | - return $wpdb->get_results( |
|
206 | - "SELECT |
|
20 | + // private instance of the Transaction object |
|
21 | + protected static $_instance; |
|
22 | + |
|
23 | + /** |
|
24 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | + * but payment is pending. This is the state for transactions where payment is promised |
|
26 | + * from an offline gateway. |
|
27 | + */ |
|
28 | + // const open_status_code = 'TPN'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | + * either due to a technical reason (server or computer crash during registration), |
|
33 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | + */ |
|
35 | + const failed_status_code = 'TFL'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | + * either due to a technical reason (server or computer crash during registration), |
|
40 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | + * HOWEVER... |
|
42 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | + * registrant |
|
44 | + */ |
|
45 | + const abandoned_status_code = 'TAB'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | + */ |
|
51 | + const incomplete_status_code = 'TIN'; |
|
52 | + |
|
53 | + /** |
|
54 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | + */ |
|
57 | + const complete_status_code = 'TCM'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | + */ |
|
63 | + const overpaid_status_code = 'TOP'; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * private constructor to prevent direct creation |
|
68 | + * |
|
69 | + * @Constructor |
|
70 | + * @access protected |
|
71 | + * |
|
72 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
73 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
74 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
75 | + * timezone in the 'timezone_string' wp option) |
|
76 | + * |
|
77 | + * @return EEM_Transaction |
|
78 | + * @throws \EE_Error |
|
79 | + */ |
|
80 | + protected function __construct($timezone) |
|
81 | + { |
|
82 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
83 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
84 | + |
|
85 | + $this->_tables = array( |
|
86 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
87 | + ); |
|
88 | + $this->_fields = array( |
|
89 | + 'TransactionTable' => array( |
|
90 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
91 | + 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
92 | + __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
93 | + $timezone), |
|
94 | + 'TXN_total' => new EE_Money_Field('TXN_total', |
|
95 | + __('Total value of Transaction', 'event_espresso'), false, 0), |
|
96 | + 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
97 | + __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
98 | + 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
99 | + false, EEM_Transaction::failed_status_code, 'Status'), |
|
100 | + 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
101 | + __('Serialized session data', 'event_espresso'), true, ''), |
|
102 | + 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
103 | + __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
104 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
105 | + __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
106 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
107 | + __('Registration Steps', 'event_espresso'), false, array()), |
|
108 | + ) |
|
109 | + ); |
|
110 | + $this->_model_relations = array( |
|
111 | + 'Registration' => new EE_Has_Many_Relation(), |
|
112 | + 'Payment' => new EE_Has_Many_Relation(), |
|
113 | + 'Status' => new EE_Belongs_To_Relation(), |
|
114 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
115 | + //you can delete a transaction without needing to delete its line items |
|
116 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
117 | + 'Message' => new EE_Has_Many_Relation() |
|
118 | + ); |
|
119 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
120 | + parent::__construct($timezone); |
|
121 | + |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * txn_status_array |
|
127 | + * get list of transaction statuses |
|
128 | + * |
|
129 | + * @access public |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public static function txn_status_array() |
|
133 | + { |
|
134 | + return apply_filters( |
|
135 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
136 | + array( |
|
137 | + EEM_Transaction::overpaid_status_code, |
|
138 | + EEM_Transaction::complete_status_code, |
|
139 | + EEM_Transaction::incomplete_status_code, |
|
140 | + EEM_Transaction::abandoned_status_code, |
|
141 | + EEM_Transaction::failed_status_code, |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
148 | + * |
|
149 | + * @access public |
|
150 | + * |
|
151 | + * @param string $period |
|
152 | + * |
|
153 | + * @return \stdClass[] |
|
154 | + */ |
|
155 | + public function get_revenue_per_day_report($period = '-1 month') |
|
156 | + { |
|
157 | + $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
158 | + 'Y-m-d H:i:s', 'UTC'); |
|
159 | + |
|
160 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
161 | + |
|
162 | + return $this->_get_all_wpdb_results( |
|
163 | + array( |
|
164 | + array( |
|
165 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
166 | + ), |
|
167 | + 'group_by' => 'txnDate', |
|
168 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
169 | + ), |
|
170 | + OBJECT, |
|
171 | + array( |
|
172 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
173 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
181 | + * |
|
182 | + * @access public |
|
183 | + * |
|
184 | + * @param string $period |
|
185 | + * |
|
186 | + * @throws \EE_Error |
|
187 | + * @return mixed |
|
188 | + */ |
|
189 | + public function get_revenue_per_event_report($period = '-1 month') |
|
190 | + { |
|
191 | + global $wpdb; |
|
192 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
195 | + $event_table = $wpdb->posts; |
|
196 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
197 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
198 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
199 | + $extra_event_on_join = ''; |
|
200 | + //exclude events not authored by user if permissions in effect |
|
201 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
202 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
203 | + } |
|
204 | + |
|
205 | + return $wpdb->get_results( |
|
206 | + "SELECT |
|
207 | 207 | Transaction_Event.event_name AS event_name, |
208 | 208 | SUM(Transaction_Event.paid) AS revenue |
209 | 209 | FROM |
@@ -230,185 +230,185 @@ discard block |
||
230 | 230 | $extra_event_on_join |
231 | 231 | ) AS Transaction_Event |
232 | 232 | GROUP BY event_name", |
233 | - OBJECT |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
240 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
241 | - * the registration pointed to by reg_url_link), if not returns null |
|
242 | - * |
|
243 | - * @param string $reg_url_link |
|
244 | - * |
|
245 | - * @return EE_Transaction |
|
246 | - */ |
|
247 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
248 | - { |
|
249 | - return $this->get_one(array( |
|
250 | - array( |
|
251 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
252 | - '') |
|
253 | - ) |
|
254 | - )); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Updates the provided EE_Transaction with all the applicable payments |
|
260 | - * (or fetch the EE_Transaction from its ID) |
|
261 | - * |
|
262 | - * @deprecated |
|
263 | - * |
|
264 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
265 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
266 | - * |
|
267 | - * @return boolean |
|
268 | - * @throws \EE_Error |
|
269 | - */ |
|
270 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
271 | - { |
|
272 | - EE_Error::doing_it_wrong( |
|
273 | - __CLASS__ . '::' . __FUNCTION__, |
|
274 | - sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
275 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
276 | - '4.6.0' |
|
277 | - ); |
|
278 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
279 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
280 | - |
|
281 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
282 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
283 | - ); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
288 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
289 | - * and so we only use wpdb directly and only do minimal joins. |
|
290 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
291 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
292 | - * it, it's probably not junk (regardless of what status it has). |
|
293 | - * The downside to this approach is that is addons are listening for object deletions |
|
294 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
295 | - * to catch these types of deletions. |
|
296 | - * |
|
297 | - * @global WPDB $wpdb |
|
298 | - * @return mixed |
|
299 | - */ |
|
300 | - public function delete_junk_transactions() |
|
301 | - { |
|
302 | - /** @type WPDB $wpdb */ |
|
303 | - global $wpdb; |
|
304 | - $deleted = false; |
|
305 | - $time_to_leave_alone = apply_filters( |
|
306 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
307 | - , WEEK_IN_SECONDS |
|
308 | - ); |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
313 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
314 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
315 | - */ |
|
316 | - $ids_query = apply_filters( |
|
317 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
318 | - array( |
|
319 | - 0 => array( |
|
320 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
322 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
323 | - ) |
|
324 | - ), |
|
325 | - $time_to_leave_alone |
|
326 | - ); |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
331 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
332 | - */ |
|
333 | - $txn_ids = apply_filters( |
|
334 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
335 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
336 | - $time_to_leave_alone |
|
337 | - ); |
|
338 | - //now that we have the ids to delete |
|
339 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
341 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
342 | - // let's get deletin'... |
|
343 | - // Why no wpdb->prepare? Because the data is trusted. |
|
344 | - // We got the ids from the original query to get them FROM |
|
345 | - // the db (which is sanitized) so no need to prepare them again. |
|
346 | - $query = ' |
|
233 | + OBJECT |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
240 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
241 | + * the registration pointed to by reg_url_link), if not returns null |
|
242 | + * |
|
243 | + * @param string $reg_url_link |
|
244 | + * |
|
245 | + * @return EE_Transaction |
|
246 | + */ |
|
247 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
248 | + { |
|
249 | + return $this->get_one(array( |
|
250 | + array( |
|
251 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
252 | + '') |
|
253 | + ) |
|
254 | + )); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Updates the provided EE_Transaction with all the applicable payments |
|
260 | + * (or fetch the EE_Transaction from its ID) |
|
261 | + * |
|
262 | + * @deprecated |
|
263 | + * |
|
264 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
265 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
266 | + * |
|
267 | + * @return boolean |
|
268 | + * @throws \EE_Error |
|
269 | + */ |
|
270 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
271 | + { |
|
272 | + EE_Error::doing_it_wrong( |
|
273 | + __CLASS__ . '::' . __FUNCTION__, |
|
274 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
275 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
276 | + '4.6.0' |
|
277 | + ); |
|
278 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
279 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
280 | + |
|
281 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
282 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
283 | + ); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
288 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
289 | + * and so we only use wpdb directly and only do minimal joins. |
|
290 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
291 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
292 | + * it, it's probably not junk (regardless of what status it has). |
|
293 | + * The downside to this approach is that is addons are listening for object deletions |
|
294 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
295 | + * to catch these types of deletions. |
|
296 | + * |
|
297 | + * @global WPDB $wpdb |
|
298 | + * @return mixed |
|
299 | + */ |
|
300 | + public function delete_junk_transactions() |
|
301 | + { |
|
302 | + /** @type WPDB $wpdb */ |
|
303 | + global $wpdb; |
|
304 | + $deleted = false; |
|
305 | + $time_to_leave_alone = apply_filters( |
|
306 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
307 | + , WEEK_IN_SECONDS |
|
308 | + ); |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
313 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
314 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
315 | + */ |
|
316 | + $ids_query = apply_filters( |
|
317 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
318 | + array( |
|
319 | + 0 => array( |
|
320 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
321 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
322 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
323 | + ) |
|
324 | + ), |
|
325 | + $time_to_leave_alone |
|
326 | + ); |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
331 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
332 | + */ |
|
333 | + $txn_ids = apply_filters( |
|
334 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
335 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
336 | + $time_to_leave_alone |
|
337 | + ); |
|
338 | + //now that we have the ids to delete |
|
339 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
341 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
342 | + // let's get deletin'... |
|
343 | + // Why no wpdb->prepare? Because the data is trusted. |
|
344 | + // We got the ids from the original query to get them FROM |
|
345 | + // the db (which is sanitized) so no need to prepare them again. |
|
346 | + $query = ' |
|
347 | 347 | DELETE |
348 | 348 | FROM ' . $this->table() . ' |
349 | 349 | WHERE |
350 | 350 | TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
351 | - $deleted = $wpdb->query($query); |
|
352 | - } |
|
353 | - if ($deleted) { |
|
354 | - /** |
|
355 | - * Allows code to do something after the transactions have been deleted. |
|
356 | - */ |
|
357 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
358 | - } |
|
359 | - |
|
360 | - return $deleted; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param array $transaction_IDs |
|
366 | - * |
|
367 | - * @return bool |
|
368 | - */ |
|
369 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
370 | - { |
|
371 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
372 | - $update = false; |
|
373 | - foreach ($transaction_IDs as $TXN_ID) { |
|
374 | - if (isset($locked_transactions[$TXN_ID])) { |
|
375 | - unset($locked_transactions[$TXN_ID]); |
|
376 | - $update = true; |
|
377 | - } |
|
378 | - } |
|
379 | - if ($update) { |
|
380 | - update_option('ee_locked_transactions', $locked_transactions); |
|
381 | - } |
|
382 | - |
|
383 | - return $update; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
390 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
391 | - * |
|
392 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
393 | - * @throws \EE_Error |
|
394 | - */ |
|
395 | - public function get_transactions_in_progress() |
|
396 | - { |
|
397 | - return $this->get_all( |
|
398 | - array( |
|
399 | - array( |
|
400 | - 'TXN_timestamp' => array( |
|
401 | - '>', |
|
402 | - time() - EE_Registry::instance()->SSN->lifespan() |
|
403 | - ), |
|
404 | - 'STS_ID' => array( |
|
405 | - '!=', |
|
406 | - EEM_Transaction::complete_status_code |
|
407 | - ), |
|
408 | - ) |
|
409 | - ) |
|
410 | - ); |
|
411 | - } |
|
351 | + $deleted = $wpdb->query($query); |
|
352 | + } |
|
353 | + if ($deleted) { |
|
354 | + /** |
|
355 | + * Allows code to do something after the transactions have been deleted. |
|
356 | + */ |
|
357 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
358 | + } |
|
359 | + |
|
360 | + return $deleted; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param array $transaction_IDs |
|
366 | + * |
|
367 | + * @return bool |
|
368 | + */ |
|
369 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
370 | + { |
|
371 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
372 | + $update = false; |
|
373 | + foreach ($transaction_IDs as $TXN_ID) { |
|
374 | + if (isset($locked_transactions[$TXN_ID])) { |
|
375 | + unset($locked_transactions[$TXN_ID]); |
|
376 | + $update = true; |
|
377 | + } |
|
378 | + } |
|
379 | + if ($update) { |
|
380 | + update_option('ee_locked_transactions', $locked_transactions); |
|
381 | + } |
|
382 | + |
|
383 | + return $update; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
390 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
391 | + * |
|
392 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
393 | + * @throws \EE_Error |
|
394 | + */ |
|
395 | + public function get_transactions_in_progress() |
|
396 | + { |
|
397 | + return $this->get_all( |
|
398 | + array( |
|
399 | + array( |
|
400 | + 'TXN_timestamp' => array( |
|
401 | + '>', |
|
402 | + time() - EE_Registry::instance()->SSN->lifespan() |
|
403 | + ), |
|
404 | + 'STS_ID' => array( |
|
405 | + '!=', |
|
406 | + EEM_Transaction::complete_status_code |
|
407 | + ), |
|
408 | + ) |
|
409 | + ) |
|
410 | + ); |
|
411 | + } |
|
412 | 412 | |
413 | 413 | |
414 | 414 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | -require_once(EE_MODELS . 'EEM_Base.model.php'); |
|
6 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | __('Registration Steps', 'event_espresso'), false, array()), |
108 | 108 | ) |
109 | 109 | ); |
110 | - $this->_model_relations = array( |
|
110 | + $this->_model_relations = array( |
|
111 | 111 | 'Registration' => new EE_Has_Many_Relation(), |
112 | 112 | 'Payment' => new EE_Has_Many_Relation(), |
113 | 113 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ), |
170 | 170 | OBJECT, |
171 | 171 | array( |
172 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
172 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
173 | 173 | 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
174 | 174 | ) |
175 | 175 | ); |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | public function get_revenue_per_event_report($period = '-1 month') |
190 | 190 | { |
191 | 191 | global $wpdb; |
192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
192 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
193 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
194 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
195 | 195 | $event_table = $wpdb->posts; |
196 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
196 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
197 | 197 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
198 | 198 | $approved_payment_status = EEM_Payment::status_id_approved; |
199 | 199 | $extra_event_on_join = ''; |
200 | 200 | //exclude events not authored by user if permissions in effect |
201 | 201 | if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
202 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $wpdb->get_results( |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
271 | 271 | { |
272 | 272 | EE_Error::doing_it_wrong( |
273 | - __CLASS__ . '::' . __FUNCTION__, |
|
273 | + __CLASS__.'::'.__FUNCTION__, |
|
274 | 274 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
275 | 275 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
276 | 276 | '4.6.0' |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | array( |
319 | 319 | 0 => array( |
320 | 320 | 'STS_ID' => EEM_Transaction::failed_status_code, |
321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
321 | + 'Payment.PAY_ID' => array('IS NULL'), |
|
322 | 322 | 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
323 | 323 | ) |
324 | 324 | ), |
@@ -336,18 +336,18 @@ discard block |
||
336 | 336 | $time_to_leave_alone |
337 | 337 | ); |
338 | 338 | //now that we have the ids to delete |
339 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
339 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | 340 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
341 | 341 | EEM_Transaction::unset_locked_transactions($txn_ids); |
342 | 342 | // let's get deletin'... |
343 | 343 | // Why no wpdb->prepare? Because the data is trusted. |
344 | 344 | // We got the ids from the original query to get them FROM |
345 | 345 | // the db (which is sanitized) so no need to prepare them again. |
346 | - $query = ' |
|
346 | + $query = ' |
|
347 | 347 | DELETE |
348 | - FROM ' . $this->table() . ' |
|
348 | + FROM ' . $this->table().' |
|
349 | 349 | WHERE |
350 | - TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
|
350 | + TXN_ID IN ( ' . implode(",", $txn_ids).')'; |
|
351 | 351 | $deleted = $wpdb->query($query); |
352 | 352 | } |
353 | 353 | if ($deleted) { |
@@ -125,14 +125,14 @@ |
||
125 | 125 | public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ |
126 | 126 | $field_name = NULL; |
127 | 127 | $value = NULL; |
128 | - //backward compat: we still want to find the question's ID |
|
129 | - if( is_numeric( $question_system_id ) ) { |
|
130 | - //find this question's QST_system value |
|
131 | - $question_id = $question_system_id; |
|
132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
133 | - } else { |
|
134 | - $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); |
|
135 | - } |
|
128 | + //backward compat: we still want to find the question's ID |
|
129 | + if( is_numeric( $question_system_id ) ) { |
|
130 | + //find this question's QST_system value |
|
131 | + $question_id = $question_system_id; |
|
132 | + $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
133 | + } else { |
|
134 | + $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); |
|
135 | + } |
|
136 | 136 | //only bother checking if the registration has an attendee |
137 | 137 | if( $registration->attendee() instanceof EE_Attendee ) { |
138 | 138 | $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * constructor |
53 | 53 | */ |
54 | - protected function __construct( $timezone = NULL ){ |
|
55 | - $this->singular_item = __('Answer','event_espresso'); |
|
56 | - $this->plural_item = __('Answers','event_espresso'); |
|
54 | + protected function __construct($timezone = NULL) { |
|
55 | + $this->singular_item = __('Answer', 'event_espresso'); |
|
56 | + $this->plural_item = __('Answers', 'event_espresso'); |
|
57 | 57 | $this->_tables = array( |
58 | 58 | 'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID') |
59 | 59 | ); |
60 | 60 | $this->_fields = array( |
61 | 61 | 'Answer'=>array( |
62 | - 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID','event_espresso')), |
|
63 | - 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID','event_espresso'), false, 0, 'Registration'), |
|
64 | - 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID','event_espresso'), false, 0, 'Question'), |
|
65 | - 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value','event_espresso'), false, '') |
|
62 | + 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), |
|
63 | + 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
64 | + 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
65 | + 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') |
|
66 | 66 | )); |
67 | 67 | $this->_model_relations = array( |
68 | 68 | 'Registration'=>new EE_Belongs_To_Relation(), |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ); |
71 | 71 | $this->_model_chain_to_wp_user = 'Registration.Event'; |
72 | 72 | $this->_caps_slug = 'registrations'; |
73 | - parent::__construct( $timezone ); |
|
73 | + parent::__construct($timezone); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
@@ -83,19 +83,19 @@ discard block |
||
83 | 83 | * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - public function get_answer_value_to_question( EE_Registration $registration, $question_id = NULL,$pretty_answer = FALSE ){ |
|
87 | - $value = $this->get_attendee_property_answer_value( $registration, $question_id, $pretty_answer ); |
|
88 | - if ( $value === NULL ){ |
|
89 | - $answer_obj = $this->get_registration_question_answer_object( $registration, $question_id); |
|
90 | - if( $answer_obj instanceof EE_Answer ){ |
|
91 | - if($pretty_answer){ |
|
86 | + public function get_answer_value_to_question(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) { |
|
87 | + $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
88 | + if ($value === NULL) { |
|
89 | + $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
90 | + if ($answer_obj instanceof EE_Answer) { |
|
91 | + if ($pretty_answer) { |
|
92 | 92 | $value = $answer_obj->pretty_value(); |
93 | - }else{ |
|
93 | + } else { |
|
94 | 94 | $value = $answer_obj->value(); |
95 | 95 | } |
96 | 96 | } |
97 | 97 | } |
98 | - return apply_filters( 'FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id ); |
|
98 | + return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param int $question_id |
107 | 107 | * @return EE_Answer |
108 | 108 | */ |
109 | - public function get_registration_question_answer_object( EE_Registration $registration, $question_id = NULL){ |
|
110 | - $answer_obj = $this->get_one( array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() ))); |
|
111 | - return apply_filters( 'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id ); |
|
109 | + public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL) { |
|
110 | + $answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID()))); |
|
111 | + return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
@@ -122,39 +122,39 @@ discard block |
||
122 | 122 | * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for |
123 | 123 | * a question corresponding to an attendee field, returns null) |
124 | 124 | */ |
125 | - public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ |
|
125 | + public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE) { |
|
126 | 126 | $field_name = NULL; |
127 | 127 | $value = NULL; |
128 | 128 | //backward compat: we still want to find the question's ID |
129 | - if( is_numeric( $question_system_id ) ) { |
|
129 | + if (is_numeric($question_system_id)) { |
|
130 | 130 | //find this question's QST_system value |
131 | 131 | $question_id = $question_system_id; |
132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); |
|
132 | + $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system'); |
|
133 | 133 | } else { |
134 | - $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); |
|
134 | + $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID'); |
|
135 | 135 | } |
136 | 136 | //only bother checking if the registration has an attendee |
137 | - if( $registration->attendee() instanceof EE_Attendee ) { |
|
138 | - $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); |
|
139 | - if( $field_name ) { |
|
140 | - if( $pretty_answer ) { |
|
141 | - if( $field_name === 'STA_ID' ) { |
|
137 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
138 | + $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
139 | + if ($field_name) { |
|
140 | + if ($pretty_answer) { |
|
141 | + if ($field_name === 'STA_ID') { |
|
142 | 142 | $state = $registration->attendee()->state_obj(); |
143 | - $value = $state instanceof EE_State ? $state->name() : sprintf( __('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID() ); |
|
144 | - } else if($field_name === 'CNT_ISO') { |
|
143 | + $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
144 | + } else if ($field_name === 'CNT_ISO') { |
|
145 | 145 | $country = $registration->attendee()->country_obj(); |
146 | - $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID()); |
|
146 | + $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
147 | 147 | } else { |
148 | - $value = $registration->attendee()->get_pretty( $field_name ); |
|
148 | + $value = $registration->attendee()->get_pretty($field_name); |
|
149 | 149 | } |
150 | 150 | //if field name is blank, leave the value as null too |
151 | - }else{ |
|
152 | - $value = $registration->attendee()->get( $field_name ); |
|
151 | + } else { |
|
152 | + $value = $registration->attendee()->get($field_name); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | //if no field was found, leave value blank |
156 | 156 | } |
157 | - return apply_filters( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id ); |
|
157 | + return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | public function previous(); |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns the index of a given object, or false if not found |
|
117 | - * |
|
118 | - * @see http://stackoverflow.com/a/8736013 |
|
119 | - * @param $object |
|
120 | - * @return boolean|int|string |
|
121 | - */ |
|
116 | + * Returns the index of a given object, or false if not found |
|
117 | + * |
|
118 | + * @see http://stackoverflow.com/a/8736013 |
|
119 | + * @param $object |
|
120 | + * @return boolean|int|string |
|
121 | + */ |
|
122 | 122 | public function indexOf( $object ); |
123 | 123 | |
124 | 124 | |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | |
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * detaches ALL objects from the Collection |
|
165 | - */ |
|
166 | - public function detachAll(); |
|
163 | + /** |
|
164 | + * detaches ALL objects from the Collection |
|
165 | + */ |
|
166 | + public function detachAll(); |
|
167 | 167 | |
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * unsets and detaches ALL objects from the Collection |
|
172 | - */ |
|
173 | - public function trashAndDetachAll(); |
|
170 | + /** |
|
171 | + * unsets and detaches ALL objects from the Collection |
|
172 | + */ |
|
173 | + public function trashAndDetachAll(); |
|
174 | 174 | |
175 | 175 | } |
176 | 176 | // End of file CollectionInterface.php |
@@ -83,7 +83,6 @@ discard block |
||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * setIdentifier |
86 | - |
|
87 | 86 | * Sets the data associated with an object in the Collection |
88 | 87 | * if no $identifier is supplied, then the spl_object_hash() is used |
89 | 88 | * |
@@ -352,34 +351,34 @@ discard block |
||
352 | 351 | |
353 | 352 | |
354 | 353 | |
355 | - /** |
|
356 | - * detaches ALL objects from the Collection |
|
357 | - */ |
|
358 | - public function detachAll() |
|
359 | - { |
|
360 | - $this->rewind(); |
|
361 | - while ($this->valid()) { |
|
362 | - $object = $this->current(); |
|
363 | - $this->next(); |
|
364 | - $this->detach($object); |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * unsets and detaches ALL objects from the Collection |
|
372 | - */ |
|
373 | - public function trashAndDetachAll() |
|
374 | - { |
|
375 | - $this->rewind(); |
|
376 | - while ($this->valid()) { |
|
377 | - $object = $this->current(); |
|
378 | - $this->next(); |
|
379 | - $this->detach($object); |
|
380 | - unset($object); |
|
381 | - } |
|
382 | - } |
|
354 | + /** |
|
355 | + * detaches ALL objects from the Collection |
|
356 | + */ |
|
357 | + public function detachAll() |
|
358 | + { |
|
359 | + $this->rewind(); |
|
360 | + while ($this->valid()) { |
|
361 | + $object = $this->current(); |
|
362 | + $this->next(); |
|
363 | + $this->detach($object); |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * unsets and detaches ALL objects from the Collection |
|
371 | + */ |
|
372 | + public function trashAndDetachAll() |
|
373 | + { |
|
374 | + $this->rewind(); |
|
375 | + while ($this->valid()) { |
|
376 | + $object = $this->current(); |
|
377 | + $this->next(); |
|
378 | + $this->detach($object); |
|
379 | + unset($object); |
|
380 | + } |
|
381 | + } |
|
383 | 382 | |
384 | 383 | |
385 | 384 |
@@ -79,37 +79,37 @@ |
||
79 | 79 | class LoaderFactory |
80 | 80 | { |
81 | 81 | |
82 | - /** |
|
83 | - * @var LoaderInterface $loader ; |
|
84 | - */ |
|
85 | - private static $loader; |
|
82 | + /** |
|
83 | + * @var LoaderInterface $loader ; |
|
84 | + */ |
|
85 | + private static $loader; |
|
86 | 86 | |
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param mixed $generator provided during very first instantiation in |
|
91 | - * EE_Load_Espresso_Core::handle_request() |
|
92 | - * otherwise can be left null |
|
93 | - * @return LoaderInterface |
|
94 | - * @throws InvalidArgumentException |
|
95 | - * @throws InvalidInterfaceException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - */ |
|
98 | - public static function getLoader($generator = null) |
|
99 | - { |
|
100 | - if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | - $generator = $generator !== null ? $generator : EE_Registry::instance(); |
|
102 | - $core_loader = new CoreLoader($generator); |
|
103 | - LoaderFactory::$loader = new Loader( |
|
104 | - $core_loader, |
|
105 | - new CachingLoader( |
|
106 | - $core_loader, |
|
107 | - new LooseCollection('') |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - return LoaderFactory::$loader; |
|
112 | - } |
|
89 | + /** |
|
90 | + * @param mixed $generator provided during very first instantiation in |
|
91 | + * EE_Load_Espresso_Core::handle_request() |
|
92 | + * otherwise can be left null |
|
93 | + * @return LoaderInterface |
|
94 | + * @throws InvalidArgumentException |
|
95 | + * @throws InvalidInterfaceException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + */ |
|
98 | + public static function getLoader($generator = null) |
|
99 | + { |
|
100 | + if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | + $generator = $generator !== null ? $generator : EE_Registry::instance(); |
|
102 | + $core_loader = new CoreLoader($generator); |
|
103 | + LoaderFactory::$loader = new Loader( |
|
104 | + $core_loader, |
|
105 | + new CachingLoader( |
|
106 | + $core_loader, |
|
107 | + new LooseCollection('') |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + return LoaderFactory::$loader; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 | } |
@@ -97,7 +97,7 @@ |
||
97 | 97 | */ |
98 | 98 | public static function getLoader($generator = null) |
99 | 99 | { |
100 | - if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
100 | + if ( ! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | 101 | $generator = $generator !== null ? $generator : EE_Registry::instance(); |
102 | 102 | $core_loader = new CoreLoader($generator); |
103 | 103 | LoaderFactory::$loader = new Loader( |
@@ -15,760 +15,760 @@ |
||
15 | 15 | class EE_Datetime_Field extends EE_Model_Field_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | - * |
|
22 | - * @type string unix_timestamp_regex |
|
23 | - */ |
|
24 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type string mysql_timestamp_format |
|
28 | - */ |
|
29 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @type string mysql_date_format |
|
33 | - */ |
|
34 | - const mysql_date_format = 'Y-m-d'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @type string mysql_time_format |
|
38 | - */ |
|
39 | - const mysql_time_format = 'H:i:s'; |
|
40 | - |
|
41 | - /** |
|
42 | - * Const for using in the default value. If the field's default is set to this, |
|
43 | - * then we will return the time of calling `get_default_value()`, not |
|
44 | - * just the current time at construction |
|
45 | - */ |
|
46 | - const now = 'now'; |
|
47 | - |
|
48 | - /** |
|
49 | - * The following properties hold the default formats for date and time. |
|
50 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | - * However they can also be overridden later by the set_format() method |
|
52 | - * (and corresponding set_date_format, set_time_format methods); |
|
53 | - */ |
|
54 | - /** |
|
55 | - * @type string $_date_format |
|
56 | - */ |
|
57 | - protected $_date_format = ''; |
|
58 | - |
|
59 | - /** |
|
60 | - * @type string $_time_format |
|
61 | - */ |
|
62 | - protected $_time_format = ''; |
|
63 | - |
|
64 | - /** |
|
65 | - * @type string $_pretty_date_format |
|
66 | - */ |
|
67 | - protected $_pretty_date_format = ''; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type string $_pretty_time_format |
|
71 | - */ |
|
72 | - protected $_pretty_time_format = ''; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type DateTimeZone $_DateTimeZone |
|
76 | - */ |
|
77 | - protected $_DateTimeZone; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | - */ |
|
82 | - protected $_UTC_DateTimeZone; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type DateTimeZone $_blog_DateTimeZone |
|
86 | - */ |
|
87 | - protected $_blog_DateTimeZone; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | - * and time returned via getters. |
|
94 | - * |
|
95 | - * @var mixed (null|string) |
|
96 | - */ |
|
97 | - protected $_date_time_output; |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * timezone string |
|
102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - protected $_timezone_string; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | - * offsets for comparison purposes). |
|
114 | - * |
|
115 | - * @var int |
|
116 | - */ |
|
117 | - protected $_blog_offset; |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $table_column |
|
123 | - * @param string $nice_name |
|
124 | - * @param bool $nullable |
|
125 | - * @param string $default_value |
|
126 | - * @param string $timezone_string |
|
127 | - * @param string $date_format |
|
128 | - * @param string $time_format |
|
129 | - * @param string $pretty_date_format |
|
130 | - * @param string $pretty_time_format |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - */ |
|
134 | - public function __construct( |
|
135 | - $table_column, |
|
136 | - $nice_name, |
|
137 | - $nullable, |
|
138 | - $default_value, |
|
139 | - $timezone_string = '', |
|
140 | - $date_format = '', |
|
141 | - $time_format = '', |
|
142 | - $pretty_date_format = '', |
|
143 | - $pretty_time_format = '' |
|
144 | - ) { |
|
145 | - |
|
146 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | - |
|
151 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | - $this->set_timezone($timezone_string); |
|
153 | - $this->setSchemaFormat('date-time'); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return DateTimeZone |
|
159 | - * @throws \EE_Error |
|
160 | - */ |
|
161 | - public function get_UTC_DateTimeZone() |
|
162 | - { |
|
163 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | - ? $this->_UTC_DateTimeZone |
|
165 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return DateTimeZone |
|
171 | - * @throws \EE_Error |
|
172 | - */ |
|
173 | - public function get_blog_DateTimeZone() |
|
174 | - { |
|
175 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | - ? $this->_blog_DateTimeZone |
|
177 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | - * |
|
184 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | - * timestamp |
|
186 | - * @return DateTime |
|
187 | - */ |
|
188 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | - { |
|
190 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | - * |
|
198 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | - * @return string The final assembled format string. |
|
200 | - */ |
|
201 | - protected function _get_date_time_output($pretty = false) |
|
202 | - { |
|
203 | - |
|
204 | - switch ($this->_date_time_output) { |
|
205 | - case 'time' : |
|
206 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | - break; |
|
208 | - |
|
209 | - case 'date' : |
|
210 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | - break; |
|
212 | - |
|
213 | - default : |
|
214 | - return $pretty |
|
215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | - * returned (using the format properties) |
|
224 | - * |
|
225 | - * @param string $what acceptable values are 'time' or 'date'. |
|
226 | - * Any other value will be set but will always result |
|
227 | - * in both 'date' and 'time' being returned. |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - public function set_date_time_output($what = null) |
|
231 | - { |
|
232 | - $this->_date_time_output = $what; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | - * We also set some other properties in this method. |
|
241 | - * |
|
242 | - * @param string $timezone_string A valid timezone string as described by @link |
|
243 | - * http://www.php.net/manual/en/timezones.php |
|
244 | - * @return void |
|
245 | - * @throws \EE_Error |
|
246 | - */ |
|
247 | - public function set_timezone($timezone_string) |
|
248 | - { |
|
249 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
250 | - // leave the timezone AS-IS if we already have one and |
|
251 | - // the function arg didn't provide one |
|
252 | - return; |
|
253 | - } |
|
254 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
255 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
256 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * _create_timezone_object_from_timezone_name |
|
262 | - * |
|
263 | - * @access protected |
|
264 | - * @param string $timezone_string |
|
265 | - * @return \DateTimeZone |
|
266 | - * @throws \EE_Error |
|
267 | - */ |
|
268 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
269 | - { |
|
270 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * This just returns whatever is set for the current timezone. |
|
276 | - * |
|
277 | - * @access public |
|
278 | - * @return string timezone string |
|
279 | - */ |
|
280 | - public function get_timezone() |
|
281 | - { |
|
282 | - return $this->_timezone_string; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * set the $_date_format property |
|
288 | - * |
|
289 | - * @access public |
|
290 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
291 | - * @param bool $pretty Whether to set pretty format or not. |
|
292 | - * @return void |
|
293 | - */ |
|
294 | - public function set_date_format($format, $pretty = false) |
|
295 | - { |
|
296 | - if ($pretty) { |
|
297 | - $this->_pretty_date_format = $format; |
|
298 | - } else { |
|
299 | - $this->_date_format = $format; |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * return the $_date_format property value. |
|
306 | - * |
|
307 | - * @param bool $pretty Whether to get pretty format or not. |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function get_date_format($pretty = false) |
|
311 | - { |
|
312 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * set the $_time_format property |
|
318 | - * |
|
319 | - * @access public |
|
320 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
321 | - * @param bool $pretty Whether to set pretty format or not. |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - public function set_time_format($format, $pretty = false) |
|
325 | - { |
|
326 | - if ($pretty) { |
|
327 | - $this->_pretty_time_format = $format; |
|
328 | - } else { |
|
329 | - $this->_time_format = $format; |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * return the $_time_format property value. |
|
336 | - * |
|
337 | - * @param bool $pretty Whether to get pretty format or not. |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - public function get_time_format($pretty = false) |
|
341 | - { |
|
342 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * set the $_pretty_date_format property |
|
348 | - * |
|
349 | - * @access public |
|
350 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
351 | - * @return void |
|
352 | - */ |
|
353 | - public function set_pretty_date_format($format) |
|
354 | - { |
|
355 | - $this->_pretty_date_format = $format; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * set the $_pretty_time_format property |
|
361 | - * |
|
362 | - * @access public |
|
363 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
364 | - * @return void |
|
365 | - */ |
|
366 | - public function set_pretty_time_format($format) |
|
367 | - { |
|
368 | - $this->_pretty_time_format = $format; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Only sets the time portion of the datetime. |
|
374 | - * |
|
375 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
376 | - * @param DateTime $current current DateTime object for the datetime field |
|
377 | - * @return DateTime |
|
378 | - */ |
|
379 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
380 | - { |
|
381 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
382 | - // Otherwise parse the string. |
|
383 | - if ($time_to_set_string instanceof DateTime) { |
|
384 | - $parsed = array( |
|
385 | - 'hour' => $time_to_set_string->format('H'), |
|
386 | - 'minute' => $time_to_set_string->format('i'), |
|
387 | - 'second' => $time_to_set_string->format('s'), |
|
388 | - ); |
|
389 | - } else { |
|
390 | - //parse incoming string |
|
391 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
392 | - } |
|
393 | - |
|
394 | - //make sure $current is in the correct timezone. |
|
395 | - $current->setTimezone($this->_DateTimeZone); |
|
396 | - |
|
397 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * Only sets the date portion of the datetime. |
|
403 | - * |
|
404 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
405 | - * @param DateTime $current current DateTime object for the datetime field |
|
406 | - * @return DateTime |
|
407 | - */ |
|
408 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
409 | - { |
|
410 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
411 | - // Otherwise parse the string. |
|
412 | - if ($date_to_set_string instanceof DateTime) { |
|
413 | - $parsed = array( |
|
414 | - 'year' => $date_to_set_string->format('Y'), |
|
415 | - 'month' => $date_to_set_string->format('m'), |
|
416 | - 'day' => $date_to_set_string->format('d'), |
|
417 | - ); |
|
418 | - } else { |
|
419 | - //parse incoming string |
|
420 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
421 | - } |
|
422 | - |
|
423 | - //make sure $current is in the correct timezone |
|
424 | - $current->setTimezone($this->_DateTimeZone); |
|
425 | - |
|
426 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
432 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
433 | - * |
|
434 | - * @param DateTime $DateTime |
|
435 | - * @return string formatted date time for given timezone |
|
436 | - * @throws \EE_Error |
|
437 | - */ |
|
438 | - public function prepare_for_get($DateTime) |
|
439 | - { |
|
440 | - return $this->_prepare_for_display($DateTime); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
446 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
447 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
448 | - * abbreviation to the date_string. |
|
449 | - * |
|
450 | - * @param mixed $DateTime |
|
451 | - * @param null $schema |
|
452 | - * @return string |
|
453 | - * @throws \EE_Error |
|
454 | - */ |
|
455 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
456 | - { |
|
457 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
463 | - * timezone). |
|
464 | - * |
|
465 | - * @param DateTime $DateTime |
|
466 | - * @param bool|string $schema |
|
467 | - * @return string |
|
468 | - * @throws \EE_Error |
|
469 | - */ |
|
470 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
471 | - { |
|
472 | - if (! $DateTime instanceof DateTime) { |
|
473 | - if ($this->_nullable) { |
|
474 | - return ''; |
|
475 | - } else { |
|
476 | - if (WP_DEBUG) { |
|
477 | - throw new EE_Error( |
|
478 | - sprintf( |
|
479 | - __( |
|
480 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
481 | - 'event_espresso' |
|
482 | - ), |
|
483 | - $this->_nicename |
|
484 | - ) |
|
485 | - ); |
|
486 | - } else { |
|
487 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
488 | - EE_Error::add_error( |
|
489 | - sprintf( |
|
490 | - __( |
|
491 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
492 | - 'event_espresso' |
|
493 | - ), |
|
494 | - $this->_nicename |
|
495 | - ) |
|
496 | - ); |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - $format_string = $this->_get_date_time_output($schema); |
|
501 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
502 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
503 | - if ($schema) { |
|
504 | - if ($this->_display_timezone()) { |
|
505 | - //must be explicit because schema could equal true. |
|
506 | - if ($schema === 'no_html') { |
|
507 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
508 | - } else { |
|
509 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
510 | - } |
|
511 | - } else { |
|
512 | - $timezone_string = ''; |
|
513 | - } |
|
514 | - |
|
515 | - return $DateTime->format($format_string) . $timezone_string; |
|
516 | - } else { |
|
517 | - return $DateTime->format($format_string); |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
524 | - * timezone). |
|
525 | - * |
|
526 | - * @param mixed $datetime_value u |
|
527 | - * @return string mysql timestamp in UTC |
|
528 | - * @throws \EE_Error |
|
529 | - */ |
|
530 | - public function prepare_for_use_in_db($datetime_value) |
|
531 | - { |
|
532 | - //we allow an empty value or DateTime object, but nothing else. |
|
533 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
534 | - throw new EE_Error( |
|
535 | - sprintf( |
|
536 | - __( |
|
537 | - 'The incoming value being prepared for setting in the database must either be empty or a php |
|
18 | + /** |
|
19 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | + * |
|
22 | + * @type string unix_timestamp_regex |
|
23 | + */ |
|
24 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type string mysql_timestamp_format |
|
28 | + */ |
|
29 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @type string mysql_date_format |
|
33 | + */ |
|
34 | + const mysql_date_format = 'Y-m-d'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @type string mysql_time_format |
|
38 | + */ |
|
39 | + const mysql_time_format = 'H:i:s'; |
|
40 | + |
|
41 | + /** |
|
42 | + * Const for using in the default value. If the field's default is set to this, |
|
43 | + * then we will return the time of calling `get_default_value()`, not |
|
44 | + * just the current time at construction |
|
45 | + */ |
|
46 | + const now = 'now'; |
|
47 | + |
|
48 | + /** |
|
49 | + * The following properties hold the default formats for date and time. |
|
50 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | + * However they can also be overridden later by the set_format() method |
|
52 | + * (and corresponding set_date_format, set_time_format methods); |
|
53 | + */ |
|
54 | + /** |
|
55 | + * @type string $_date_format |
|
56 | + */ |
|
57 | + protected $_date_format = ''; |
|
58 | + |
|
59 | + /** |
|
60 | + * @type string $_time_format |
|
61 | + */ |
|
62 | + protected $_time_format = ''; |
|
63 | + |
|
64 | + /** |
|
65 | + * @type string $_pretty_date_format |
|
66 | + */ |
|
67 | + protected $_pretty_date_format = ''; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type string $_pretty_time_format |
|
71 | + */ |
|
72 | + protected $_pretty_time_format = ''; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type DateTimeZone $_DateTimeZone |
|
76 | + */ |
|
77 | + protected $_DateTimeZone; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | + */ |
|
82 | + protected $_UTC_DateTimeZone; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type DateTimeZone $_blog_DateTimeZone |
|
86 | + */ |
|
87 | + protected $_blog_DateTimeZone; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | + * and time returned via getters. |
|
94 | + * |
|
95 | + * @var mixed (null|string) |
|
96 | + */ |
|
97 | + protected $_date_time_output; |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * timezone string |
|
102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + protected $_timezone_string; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | + * offsets for comparison purposes). |
|
114 | + * |
|
115 | + * @var int |
|
116 | + */ |
|
117 | + protected $_blog_offset; |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $table_column |
|
123 | + * @param string $nice_name |
|
124 | + * @param bool $nullable |
|
125 | + * @param string $default_value |
|
126 | + * @param string $timezone_string |
|
127 | + * @param string $date_format |
|
128 | + * @param string $time_format |
|
129 | + * @param string $pretty_date_format |
|
130 | + * @param string $pretty_time_format |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + */ |
|
134 | + public function __construct( |
|
135 | + $table_column, |
|
136 | + $nice_name, |
|
137 | + $nullable, |
|
138 | + $default_value, |
|
139 | + $timezone_string = '', |
|
140 | + $date_format = '', |
|
141 | + $time_format = '', |
|
142 | + $pretty_date_format = '', |
|
143 | + $pretty_time_format = '' |
|
144 | + ) { |
|
145 | + |
|
146 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | + |
|
151 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | + $this->set_timezone($timezone_string); |
|
153 | + $this->setSchemaFormat('date-time'); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return DateTimeZone |
|
159 | + * @throws \EE_Error |
|
160 | + */ |
|
161 | + public function get_UTC_DateTimeZone() |
|
162 | + { |
|
163 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | + ? $this->_UTC_DateTimeZone |
|
165 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return DateTimeZone |
|
171 | + * @throws \EE_Error |
|
172 | + */ |
|
173 | + public function get_blog_DateTimeZone() |
|
174 | + { |
|
175 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | + ? $this->_blog_DateTimeZone |
|
177 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | + * |
|
184 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | + * timestamp |
|
186 | + * @return DateTime |
|
187 | + */ |
|
188 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | + { |
|
190 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | + * |
|
198 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | + * @return string The final assembled format string. |
|
200 | + */ |
|
201 | + protected function _get_date_time_output($pretty = false) |
|
202 | + { |
|
203 | + |
|
204 | + switch ($this->_date_time_output) { |
|
205 | + case 'time' : |
|
206 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | + break; |
|
208 | + |
|
209 | + case 'date' : |
|
210 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | + break; |
|
212 | + |
|
213 | + default : |
|
214 | + return $pretty |
|
215 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | + : $this->_date_format . ' ' . $this->_time_format; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | + * returned (using the format properties) |
|
224 | + * |
|
225 | + * @param string $what acceptable values are 'time' or 'date'. |
|
226 | + * Any other value will be set but will always result |
|
227 | + * in both 'date' and 'time' being returned. |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + public function set_date_time_output($what = null) |
|
231 | + { |
|
232 | + $this->_date_time_output = $what; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | + * We also set some other properties in this method. |
|
241 | + * |
|
242 | + * @param string $timezone_string A valid timezone string as described by @link |
|
243 | + * http://www.php.net/manual/en/timezones.php |
|
244 | + * @return void |
|
245 | + * @throws \EE_Error |
|
246 | + */ |
|
247 | + public function set_timezone($timezone_string) |
|
248 | + { |
|
249 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
250 | + // leave the timezone AS-IS if we already have one and |
|
251 | + // the function arg didn't provide one |
|
252 | + return; |
|
253 | + } |
|
254 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
255 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
256 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * _create_timezone_object_from_timezone_name |
|
262 | + * |
|
263 | + * @access protected |
|
264 | + * @param string $timezone_string |
|
265 | + * @return \DateTimeZone |
|
266 | + * @throws \EE_Error |
|
267 | + */ |
|
268 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
269 | + { |
|
270 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * This just returns whatever is set for the current timezone. |
|
276 | + * |
|
277 | + * @access public |
|
278 | + * @return string timezone string |
|
279 | + */ |
|
280 | + public function get_timezone() |
|
281 | + { |
|
282 | + return $this->_timezone_string; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * set the $_date_format property |
|
288 | + * |
|
289 | + * @access public |
|
290 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
291 | + * @param bool $pretty Whether to set pretty format or not. |
|
292 | + * @return void |
|
293 | + */ |
|
294 | + public function set_date_format($format, $pretty = false) |
|
295 | + { |
|
296 | + if ($pretty) { |
|
297 | + $this->_pretty_date_format = $format; |
|
298 | + } else { |
|
299 | + $this->_date_format = $format; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * return the $_date_format property value. |
|
306 | + * |
|
307 | + * @param bool $pretty Whether to get pretty format or not. |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function get_date_format($pretty = false) |
|
311 | + { |
|
312 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * set the $_time_format property |
|
318 | + * |
|
319 | + * @access public |
|
320 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
321 | + * @param bool $pretty Whether to set pretty format or not. |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + public function set_time_format($format, $pretty = false) |
|
325 | + { |
|
326 | + if ($pretty) { |
|
327 | + $this->_pretty_time_format = $format; |
|
328 | + } else { |
|
329 | + $this->_time_format = $format; |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * return the $_time_format property value. |
|
336 | + * |
|
337 | + * @param bool $pretty Whether to get pretty format or not. |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + public function get_time_format($pretty = false) |
|
341 | + { |
|
342 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * set the $_pretty_date_format property |
|
348 | + * |
|
349 | + * @access public |
|
350 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
351 | + * @return void |
|
352 | + */ |
|
353 | + public function set_pretty_date_format($format) |
|
354 | + { |
|
355 | + $this->_pretty_date_format = $format; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * set the $_pretty_time_format property |
|
361 | + * |
|
362 | + * @access public |
|
363 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
364 | + * @return void |
|
365 | + */ |
|
366 | + public function set_pretty_time_format($format) |
|
367 | + { |
|
368 | + $this->_pretty_time_format = $format; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Only sets the time portion of the datetime. |
|
374 | + * |
|
375 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
376 | + * @param DateTime $current current DateTime object for the datetime field |
|
377 | + * @return DateTime |
|
378 | + */ |
|
379 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
380 | + { |
|
381 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
382 | + // Otherwise parse the string. |
|
383 | + if ($time_to_set_string instanceof DateTime) { |
|
384 | + $parsed = array( |
|
385 | + 'hour' => $time_to_set_string->format('H'), |
|
386 | + 'minute' => $time_to_set_string->format('i'), |
|
387 | + 'second' => $time_to_set_string->format('s'), |
|
388 | + ); |
|
389 | + } else { |
|
390 | + //parse incoming string |
|
391 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
392 | + } |
|
393 | + |
|
394 | + //make sure $current is in the correct timezone. |
|
395 | + $current->setTimezone($this->_DateTimeZone); |
|
396 | + |
|
397 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * Only sets the date portion of the datetime. |
|
403 | + * |
|
404 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
405 | + * @param DateTime $current current DateTime object for the datetime field |
|
406 | + * @return DateTime |
|
407 | + */ |
|
408 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
409 | + { |
|
410 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
411 | + // Otherwise parse the string. |
|
412 | + if ($date_to_set_string instanceof DateTime) { |
|
413 | + $parsed = array( |
|
414 | + 'year' => $date_to_set_string->format('Y'), |
|
415 | + 'month' => $date_to_set_string->format('m'), |
|
416 | + 'day' => $date_to_set_string->format('d'), |
|
417 | + ); |
|
418 | + } else { |
|
419 | + //parse incoming string |
|
420 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
421 | + } |
|
422 | + |
|
423 | + //make sure $current is in the correct timezone |
|
424 | + $current->setTimezone($this->_DateTimeZone); |
|
425 | + |
|
426 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
432 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
433 | + * |
|
434 | + * @param DateTime $DateTime |
|
435 | + * @return string formatted date time for given timezone |
|
436 | + * @throws \EE_Error |
|
437 | + */ |
|
438 | + public function prepare_for_get($DateTime) |
|
439 | + { |
|
440 | + return $this->_prepare_for_display($DateTime); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
446 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
447 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
448 | + * abbreviation to the date_string. |
|
449 | + * |
|
450 | + * @param mixed $DateTime |
|
451 | + * @param null $schema |
|
452 | + * @return string |
|
453 | + * @throws \EE_Error |
|
454 | + */ |
|
455 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
456 | + { |
|
457 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
463 | + * timezone). |
|
464 | + * |
|
465 | + * @param DateTime $DateTime |
|
466 | + * @param bool|string $schema |
|
467 | + * @return string |
|
468 | + * @throws \EE_Error |
|
469 | + */ |
|
470 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
471 | + { |
|
472 | + if (! $DateTime instanceof DateTime) { |
|
473 | + if ($this->_nullable) { |
|
474 | + return ''; |
|
475 | + } else { |
|
476 | + if (WP_DEBUG) { |
|
477 | + throw new EE_Error( |
|
478 | + sprintf( |
|
479 | + __( |
|
480 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
481 | + 'event_espresso' |
|
482 | + ), |
|
483 | + $this->_nicename |
|
484 | + ) |
|
485 | + ); |
|
486 | + } else { |
|
487 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
488 | + EE_Error::add_error( |
|
489 | + sprintf( |
|
490 | + __( |
|
491 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
492 | + 'event_espresso' |
|
493 | + ), |
|
494 | + $this->_nicename |
|
495 | + ) |
|
496 | + ); |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + $format_string = $this->_get_date_time_output($schema); |
|
501 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
502 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
503 | + if ($schema) { |
|
504 | + if ($this->_display_timezone()) { |
|
505 | + //must be explicit because schema could equal true. |
|
506 | + if ($schema === 'no_html') { |
|
507 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
508 | + } else { |
|
509 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
510 | + } |
|
511 | + } else { |
|
512 | + $timezone_string = ''; |
|
513 | + } |
|
514 | + |
|
515 | + return $DateTime->format($format_string) . $timezone_string; |
|
516 | + } else { |
|
517 | + return $DateTime->format($format_string); |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
524 | + * timezone). |
|
525 | + * |
|
526 | + * @param mixed $datetime_value u |
|
527 | + * @return string mysql timestamp in UTC |
|
528 | + * @throws \EE_Error |
|
529 | + */ |
|
530 | + public function prepare_for_use_in_db($datetime_value) |
|
531 | + { |
|
532 | + //we allow an empty value or DateTime object, but nothing else. |
|
533 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
534 | + throw new EE_Error( |
|
535 | + sprintf( |
|
536 | + __( |
|
537 | + 'The incoming value being prepared for setting in the database must either be empty or a php |
|
538 | 538 | DateTime object, instead of: %1$s %2$s', |
539 | - 'event_espresso' |
|
540 | - ), |
|
541 | - '<br />', |
|
542 | - print_r($datetime_value, true) |
|
543 | - ) |
|
544 | - ); |
|
545 | - } |
|
546 | - |
|
547 | - if ($datetime_value instanceof DateTime) { |
|
548 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
549 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
550 | - } |
|
551 | - |
|
552 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
553 | - EE_Datetime_Field::mysql_timestamp_format |
|
554 | - ); |
|
555 | - } |
|
556 | - |
|
557 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
558 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
564 | - * allowed) |
|
565 | - * |
|
566 | - * @param string $datetime_string mysql timestamp in UTC |
|
567 | - * @return mixed null | DateTime |
|
568 | - * @throws \EE_Error |
|
569 | - */ |
|
570 | - public function prepare_for_set_from_db($datetime_string) |
|
571 | - { |
|
572 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
573 | - if (empty($datetime_string) && $this->_nullable) { |
|
574 | - return null; |
|
575 | - } |
|
576 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
577 | - if (empty($datetime_string)) { |
|
578 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
579 | - } else { |
|
580 | - $DateTime = DateTime::createFromFormat( |
|
581 | - EE_Datetime_Field::mysql_timestamp_format, |
|
582 | - $datetime_string, |
|
583 | - $this->get_UTC_DateTimeZone() |
|
584 | - ); |
|
585 | - if ($DateTime instanceof \DateTime) { |
|
586 | - $DateTime = new DbSafeDateTime( |
|
587 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
588 | - $this->get_UTC_DateTimeZone() |
|
589 | - ); |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
594 | - // if still no datetime object, then let's just use now |
|
595 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
596 | - } |
|
597 | - // THEN apply the field's set DateTimeZone |
|
598 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
599 | - |
|
600 | - return $DateTime; |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
606 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
607 | - * If so, then true. |
|
608 | - * |
|
609 | - * @return bool true for yes false for no |
|
610 | - * @throws \EE_Error |
|
611 | - */ |
|
612 | - protected function _display_timezone() |
|
613 | - { |
|
614 | - |
|
615 | - // first let's do a comparison of timezone strings. |
|
616 | - // If they match then we can get out without any further calculations |
|
617 | - $blog_string = get_option('timezone_string'); |
|
618 | - if ($blog_string === $this->_timezone_string) { |
|
619 | - return false; |
|
620 | - } |
|
621 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
622 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
623 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
624 | - // now compare |
|
625 | - return $blog_offset !== $this_offset; |
|
626 | - } |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
631 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
632 | - * with. |
|
633 | - * |
|
634 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
635 | - * in the format that is set on the date_field (or DateTime |
|
636 | - * object)! |
|
637 | - * @return DateTime |
|
638 | - */ |
|
639 | - protected function _get_date_object($date_string) |
|
640 | - { |
|
641 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
642 | - if ($this->_nullable && empty($date_string)) { |
|
643 | - return null; |
|
644 | - } |
|
645 | - |
|
646 | - // if incoming date |
|
647 | - if ($date_string instanceof DateTime) { |
|
648 | - $date_string->setTimezone($this->_DateTimeZone); |
|
649 | - |
|
650 | - return $date_string; |
|
651 | - } |
|
652 | - // if empty date_string and made it here. |
|
653 | - // Return a datetime object for now in the given timezone. |
|
654 | - if (empty($date_string)) { |
|
655 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
656 | - } |
|
657 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
658 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
659 | - try { |
|
660 | - // This is operating under the assumption that the incoming Unix timestamp |
|
661 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
662 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
663 | - $DateTime->setTimestamp($date_string); |
|
664 | - |
|
665 | - return $DateTime; |
|
666 | - } catch (Exception $e) { |
|
667 | - // should be rare, but if things got fooled then let's just continue |
|
668 | - } |
|
669 | - } |
|
670 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
671 | - //create the DateTime object. |
|
672 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
673 | - try { |
|
674 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
675 | - if ($DateTime instanceof DateTime) { |
|
676 | - $DateTime = new DbSafeDateTime( |
|
677 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
678 | - $this->_DateTimeZone |
|
679 | - ); |
|
680 | - } |
|
681 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
682 | - throw new EE_Error( |
|
683 | - sprintf( |
|
684 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
685 | - $date_string, |
|
686 | - $format |
|
687 | - ) |
|
688 | - ); |
|
689 | - } |
|
690 | - } catch (Exception $e) { |
|
691 | - // if we made it here then likely then something went really wrong. |
|
692 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
693 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
694 | - } |
|
695 | - |
|
696 | - return $DateTime; |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * get_timezone_transitions |
|
703 | - * |
|
704 | - * @param \DateTimeZone $DateTimeZone |
|
705 | - * @param int $time |
|
706 | - * @param bool $first_only |
|
707 | - * @return mixed |
|
708 | - */ |
|
709 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
710 | - { |
|
711 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
712 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
713 | - $transitions = $DateTimeZone->getTransitions($time); |
|
714 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * get_timezone_offset |
|
721 | - * |
|
722 | - * @param \DateTimeZone $DateTimeZone |
|
723 | - * @param int $time |
|
724 | - * @return mixed |
|
725 | - * @throws \DomainException |
|
726 | - */ |
|
727 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
728 | - { |
|
729 | - $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
730 | - if ( ! isset($transitions['offset'])) { |
|
731 | - throw new DomainException(); |
|
732 | - } |
|
733 | - return $transitions['offset']; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
739 | - * |
|
740 | - * @param string $timezone_string |
|
741 | - * @return string abbreviation |
|
742 | - * @throws \EE_Error |
|
743 | - */ |
|
744 | - public function get_timezone_abbrev($timezone_string) |
|
745 | - { |
|
746 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
747 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
748 | - |
|
749 | - return $dateTime->format('T'); |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * Overrides the parent to allow for having a dynamic "now" value |
|
754 | - * |
|
755 | - * @return mixed |
|
756 | - */ |
|
757 | - public function get_default_value() |
|
758 | - { |
|
759 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
760 | - return time(); |
|
761 | - } else { |
|
762 | - return parent::get_default_value(); |
|
763 | - } |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - public function getSchemaDescription() |
|
768 | - { |
|
769 | - return sprintf( |
|
770 | - esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
771 | - $this->get_nicename() |
|
772 | - ); |
|
773 | - } |
|
539 | + 'event_espresso' |
|
540 | + ), |
|
541 | + '<br />', |
|
542 | + print_r($datetime_value, true) |
|
543 | + ) |
|
544 | + ); |
|
545 | + } |
|
546 | + |
|
547 | + if ($datetime_value instanceof DateTime) { |
|
548 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
549 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
550 | + } |
|
551 | + |
|
552 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
553 | + EE_Datetime_Field::mysql_timestamp_format |
|
554 | + ); |
|
555 | + } |
|
556 | + |
|
557 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
558 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
564 | + * allowed) |
|
565 | + * |
|
566 | + * @param string $datetime_string mysql timestamp in UTC |
|
567 | + * @return mixed null | DateTime |
|
568 | + * @throws \EE_Error |
|
569 | + */ |
|
570 | + public function prepare_for_set_from_db($datetime_string) |
|
571 | + { |
|
572 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
573 | + if (empty($datetime_string) && $this->_nullable) { |
|
574 | + return null; |
|
575 | + } |
|
576 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
577 | + if (empty($datetime_string)) { |
|
578 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
579 | + } else { |
|
580 | + $DateTime = DateTime::createFromFormat( |
|
581 | + EE_Datetime_Field::mysql_timestamp_format, |
|
582 | + $datetime_string, |
|
583 | + $this->get_UTC_DateTimeZone() |
|
584 | + ); |
|
585 | + if ($DateTime instanceof \DateTime) { |
|
586 | + $DateTime = new DbSafeDateTime( |
|
587 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
588 | + $this->get_UTC_DateTimeZone() |
|
589 | + ); |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
594 | + // if still no datetime object, then let's just use now |
|
595 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
596 | + } |
|
597 | + // THEN apply the field's set DateTimeZone |
|
598 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
599 | + |
|
600 | + return $DateTime; |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
606 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
607 | + * If so, then true. |
|
608 | + * |
|
609 | + * @return bool true for yes false for no |
|
610 | + * @throws \EE_Error |
|
611 | + */ |
|
612 | + protected function _display_timezone() |
|
613 | + { |
|
614 | + |
|
615 | + // first let's do a comparison of timezone strings. |
|
616 | + // If they match then we can get out without any further calculations |
|
617 | + $blog_string = get_option('timezone_string'); |
|
618 | + if ($blog_string === $this->_timezone_string) { |
|
619 | + return false; |
|
620 | + } |
|
621 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
622 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
623 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
624 | + // now compare |
|
625 | + return $blog_offset !== $this_offset; |
|
626 | + } |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
631 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
632 | + * with. |
|
633 | + * |
|
634 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
635 | + * in the format that is set on the date_field (or DateTime |
|
636 | + * object)! |
|
637 | + * @return DateTime |
|
638 | + */ |
|
639 | + protected function _get_date_object($date_string) |
|
640 | + { |
|
641 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
642 | + if ($this->_nullable && empty($date_string)) { |
|
643 | + return null; |
|
644 | + } |
|
645 | + |
|
646 | + // if incoming date |
|
647 | + if ($date_string instanceof DateTime) { |
|
648 | + $date_string->setTimezone($this->_DateTimeZone); |
|
649 | + |
|
650 | + return $date_string; |
|
651 | + } |
|
652 | + // if empty date_string and made it here. |
|
653 | + // Return a datetime object for now in the given timezone. |
|
654 | + if (empty($date_string)) { |
|
655 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
656 | + } |
|
657 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
658 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
659 | + try { |
|
660 | + // This is operating under the assumption that the incoming Unix timestamp |
|
661 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
662 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
663 | + $DateTime->setTimestamp($date_string); |
|
664 | + |
|
665 | + return $DateTime; |
|
666 | + } catch (Exception $e) { |
|
667 | + // should be rare, but if things got fooled then let's just continue |
|
668 | + } |
|
669 | + } |
|
670 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
671 | + //create the DateTime object. |
|
672 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
673 | + try { |
|
674 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
675 | + if ($DateTime instanceof DateTime) { |
|
676 | + $DateTime = new DbSafeDateTime( |
|
677 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
678 | + $this->_DateTimeZone |
|
679 | + ); |
|
680 | + } |
|
681 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
682 | + throw new EE_Error( |
|
683 | + sprintf( |
|
684 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
685 | + $date_string, |
|
686 | + $format |
|
687 | + ) |
|
688 | + ); |
|
689 | + } |
|
690 | + } catch (Exception $e) { |
|
691 | + // if we made it here then likely then something went really wrong. |
|
692 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
693 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
694 | + } |
|
695 | + |
|
696 | + return $DateTime; |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * get_timezone_transitions |
|
703 | + * |
|
704 | + * @param \DateTimeZone $DateTimeZone |
|
705 | + * @param int $time |
|
706 | + * @param bool $first_only |
|
707 | + * @return mixed |
|
708 | + */ |
|
709 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
710 | + { |
|
711 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
712 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
713 | + $transitions = $DateTimeZone->getTransitions($time); |
|
714 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * get_timezone_offset |
|
721 | + * |
|
722 | + * @param \DateTimeZone $DateTimeZone |
|
723 | + * @param int $time |
|
724 | + * @return mixed |
|
725 | + * @throws \DomainException |
|
726 | + */ |
|
727 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
728 | + { |
|
729 | + $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
730 | + if ( ! isset($transitions['offset'])) { |
|
731 | + throw new DomainException(); |
|
732 | + } |
|
733 | + return $transitions['offset']; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
739 | + * |
|
740 | + * @param string $timezone_string |
|
741 | + * @return string abbreviation |
|
742 | + * @throws \EE_Error |
|
743 | + */ |
|
744 | + public function get_timezone_abbrev($timezone_string) |
|
745 | + { |
|
746 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
747 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
748 | + |
|
749 | + return $dateTime->format('T'); |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * Overrides the parent to allow for having a dynamic "now" value |
|
754 | + * |
|
755 | + * @return mixed |
|
756 | + */ |
|
757 | + public function get_default_value() |
|
758 | + { |
|
759 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
760 | + return time(); |
|
761 | + } else { |
|
762 | + return parent::get_default_value(); |
|
763 | + } |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + public function getSchemaDescription() |
|
768 | + { |
|
769 | + return sprintf( |
|
770 | + esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
771 | + $this->get_nicename() |
|
772 | + ); |
|
773 | + } |
|
774 | 774 | } |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | ); |
1048 | 1048 | do_action( |
1049 | 1049 | 'AHEE__EE_Capabilities__init_role_caps__complete', |
1050 | - $capabilities_map |
|
1050 | + $capabilities_map |
|
1051 | 1051 | ); |
1052 | 1052 | } |
1053 | 1053 | ); |
@@ -1067,9 +1067,9 @@ discard block |
||
1067 | 1067 | 'filter' |
1068 | 1068 | ); |
1069 | 1069 | return apply_filters( |
1070 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1071 | - $existing_attendee, $registration, $attendee_data |
|
1072 | - ); |
|
1070 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1071 | + $existing_attendee, $registration, $attendee_data |
|
1072 | + ); |
|
1073 | 1073 | }, |
1074 | 1074 | 10,3 |
1075 | 1075 | ); |
@@ -1082,88 +1082,88 @@ discard block |
||
1082 | 1082 | class EE_Event_List_Query extends WP_Query |
1083 | 1083 | { |
1084 | 1084 | |
1085 | - private $title; |
|
1086 | - |
|
1087 | - private $css_class; |
|
1088 | - |
|
1089 | - private $category_slug; |
|
1090 | - |
|
1091 | - /** |
|
1092 | - * EE_Event_List_Query constructor. |
|
1093 | - * |
|
1094 | - * @param array $args |
|
1095 | - */ |
|
1096 | - public function __construct($args = array()) |
|
1097 | - { |
|
1098 | - \EE_Error::doing_it_wrong( |
|
1099 | - __METHOD__, |
|
1100 | - __( |
|
1101 | - 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1102 | - 'event_espresso' |
|
1103 | - ), |
|
1104 | - '4.9.27', |
|
1105 | - '5.0.0' |
|
1106 | - ); |
|
1107 | - $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1108 | - $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1109 | - $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1110 | - $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1111 | - // the current "page" we are viewing |
|
1112 | - $paged = max(1, get_query_var('paged')); |
|
1113 | - // Force these args |
|
1114 | - $args = array_merge( |
|
1115 | - $args, array( |
|
1116 | - 'post_type' => 'espresso_events', |
|
1117 | - 'posts_per_page' => $limit, |
|
1118 | - 'update_post_term_cache' => false, |
|
1119 | - 'update_post_meta_cache' => false, |
|
1120 | - 'paged' => $paged, |
|
1121 | - 'offset' => ($paged - 1) * $limit |
|
1122 | - ) |
|
1123 | - ); |
|
1124 | - // run the query |
|
1125 | - parent::__construct($args); |
|
1126 | - } |
|
1127 | - |
|
1128 | - |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * event_list_title |
|
1132 | - * |
|
1133 | - * @param string $event_list_title |
|
1134 | - * @return string |
|
1135 | - */ |
|
1136 | - public function event_list_title($event_list_title = '') |
|
1137 | - { |
|
1138 | - if (! empty($this->title)) { |
|
1139 | - return $this->title; |
|
1140 | - } |
|
1141 | - return $event_list_title; |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * event_list_css |
|
1148 | - * |
|
1149 | - * @param string $event_list_css |
|
1150 | - * @return string |
|
1151 | - */ |
|
1152 | - public function event_list_css($event_list_css = '') |
|
1153 | - { |
|
1154 | - $event_list_css .= ! empty($event_list_css) |
|
1155 | - ? ' ' |
|
1156 | - : ''; |
|
1157 | - $event_list_css .= ! empty($this->css_class) |
|
1158 | - ? $this->css_class |
|
1159 | - : ''; |
|
1160 | - $event_list_css .= ! empty($event_list_css) |
|
1161 | - ? ' ' |
|
1162 | - : ''; |
|
1163 | - $event_list_css .= ! empty($this->category_slug) |
|
1164 | - ? $this->category_slug |
|
1165 | - : ''; |
|
1166 | - return $event_list_css; |
|
1167 | - } |
|
1085 | + private $title; |
|
1086 | + |
|
1087 | + private $css_class; |
|
1088 | + |
|
1089 | + private $category_slug; |
|
1090 | + |
|
1091 | + /** |
|
1092 | + * EE_Event_List_Query constructor. |
|
1093 | + * |
|
1094 | + * @param array $args |
|
1095 | + */ |
|
1096 | + public function __construct($args = array()) |
|
1097 | + { |
|
1098 | + \EE_Error::doing_it_wrong( |
|
1099 | + __METHOD__, |
|
1100 | + __( |
|
1101 | + 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1102 | + 'event_espresso' |
|
1103 | + ), |
|
1104 | + '4.9.27', |
|
1105 | + '5.0.0' |
|
1106 | + ); |
|
1107 | + $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1108 | + $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1109 | + $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1110 | + $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1111 | + // the current "page" we are viewing |
|
1112 | + $paged = max(1, get_query_var('paged')); |
|
1113 | + // Force these args |
|
1114 | + $args = array_merge( |
|
1115 | + $args, array( |
|
1116 | + 'post_type' => 'espresso_events', |
|
1117 | + 'posts_per_page' => $limit, |
|
1118 | + 'update_post_term_cache' => false, |
|
1119 | + 'update_post_meta_cache' => false, |
|
1120 | + 'paged' => $paged, |
|
1121 | + 'offset' => ($paged - 1) * $limit |
|
1122 | + ) |
|
1123 | + ); |
|
1124 | + // run the query |
|
1125 | + parent::__construct($args); |
|
1126 | + } |
|
1127 | + |
|
1128 | + |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * event_list_title |
|
1132 | + * |
|
1133 | + * @param string $event_list_title |
|
1134 | + * @return string |
|
1135 | + */ |
|
1136 | + public function event_list_title($event_list_title = '') |
|
1137 | + { |
|
1138 | + if (! empty($this->title)) { |
|
1139 | + return $this->title; |
|
1140 | + } |
|
1141 | + return $event_list_title; |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * event_list_css |
|
1148 | + * |
|
1149 | + * @param string $event_list_css |
|
1150 | + * @return string |
|
1151 | + */ |
|
1152 | + public function event_list_css($event_list_css = '') |
|
1153 | + { |
|
1154 | + $event_list_css .= ! empty($event_list_css) |
|
1155 | + ? ' ' |
|
1156 | + : ''; |
|
1157 | + $event_list_css .= ! empty($this->css_class) |
|
1158 | + ? $this->css_class |
|
1159 | + : ''; |
|
1160 | + $event_list_css .= ! empty($event_list_css) |
|
1161 | + ? ' ' |
|
1162 | + : ''; |
|
1163 | + $event_list_css .= ! empty($this->category_slug) |
|
1164 | + ? $this->category_slug |
|
1165 | + : ''; |
|
1166 | + return $event_list_css; |
|
1167 | + } |
|
1168 | 1168 | |
1169 | 1169 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | /** |
6 | 6 | * ************************************************************************ |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | $action_or_filter = 'action' |
44 | 44 | ) { |
45 | 45 | $action_or_filter = $action_or_filter === 'action' |
46 | - ? esc_html__( 'action', 'event_espresso' ) |
|
47 | - : esc_html__( 'filter', 'event_espresso' ); |
|
46 | + ? esc_html__('action', 'event_espresso') |
|
47 | + : esc_html__('filter', 'event_espresso'); |
|
48 | 48 | EE_Error::doing_it_wrong( |
49 | 49 | $deprecated_filter, |
50 | 50 | sprintf( |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param \EE_Checkout $checkout |
69 | 69 | * @return string |
70 | 70 | */ |
71 | -function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) { |
|
71 | +function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) { |
|
72 | 72 | // list of old filters |
73 | 73 | $deprecated_filters = array( |
74 | 74 | 'update_registration_details' => true, |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | 'proceed_to' => true, |
79 | 79 | ); |
80 | 80 | // loop thru and call doing_it_wrong() or remove any that aren't being used |
81 | - foreach ( $deprecated_filters as $deprecated_filter => $on ) { |
|
81 | + foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
82 | 82 | // was this filter called ? |
83 | - if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) { |
|
83 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) { |
|
84 | 84 | // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
85 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) { |
|
85 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) { |
|
86 | 86 | EE_Error::doing_it_wrong( |
87 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
87 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
88 | 88 | sprintf( |
89 | - __( 'The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ), |
|
90 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
89 | + __('The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'), |
|
90 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
91 | 91 | '<br />', |
92 | 92 | 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
93 | 93 | '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | ); |
97 | 97 | } |
98 | 98 | } else { |
99 | - unset( $deprecated_filters[ $deprecated_filter ] ); |
|
99 | + unset($deprecated_filters[$deprecated_filter]); |
|
100 | 100 | } |
101 | 101 | } |
102 | - if ( ! empty( $deprecated_filters )) { |
|
103 | - |
|
104 | - if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) { |
|
105 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text ); |
|
106 | - } else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) { |
|
107 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text ); |
|
108 | - } else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) { |
|
109 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text ); |
|
102 | + if ( ! empty($deprecated_filters)) { |
|
103 | + |
|
104 | + if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
105 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text); |
|
106 | + } else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
107 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text); |
|
108 | + } else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
109 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text); |
|
110 | 110 | } |
111 | - if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) { |
|
112 | - if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) { |
|
113 | - $submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text ); |
|
111 | + if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
112 | + if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
113 | + $submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text); |
|
114 | 114 | } |
115 | - if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) { |
|
116 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name(); |
|
115 | + if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
116 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name(); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return $submit_button_text; |
122 | 122 | |
123 | 123 | } |
124 | -add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 ); |
|
124 | +add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2); |
|
125 | 125 | |
126 | 126 | |
127 | 127 | |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | * @param \EE_Checkout $checkout |
133 | 133 | * @param boolean $status_updates |
134 | 134 | */ |
135 | -function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) { |
|
135 | +function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) { |
|
136 | 136 | $action_ref = NULL; |
137 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
138 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
139 | - if ( $action_ref ) { |
|
137 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
138 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
139 | + if ($action_ref) { |
|
140 | 140 | |
141 | 141 | EE_Error::doing_it_wrong( |
142 | 142 | $action_ref, |
143 | 143 | sprintf( |
144 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ), |
|
144 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'), |
|
145 | 145 | '<br />', |
146 | 146 | '/core/business/EE_Transaction_Processor.class.php', |
147 | 147 | 'AHEE__EE_Transaction_Processor__finalize', |
@@ -151,39 +151,39 @@ discard block |
||
151 | 151 | ), |
152 | 152 | '4.6.0' |
153 | 153 | ); |
154 | - switch ( $action_ref ) { |
|
154 | + switch ($action_ref) { |
|
155 | 155 | case 'AHEE__EE_Transaction__finalize__new_transaction' : |
156 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request ); |
|
156 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request); |
|
157 | 157 | break; |
158 | 158 | case 'AHEE__EE_Transaction__finalize__all_transaction' : |
159 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request ); |
|
159 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request); |
|
160 | 160 | break; |
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | -add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 ); |
|
164 | +add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2); |
|
165 | 165 | /** |
166 | 166 | * ee_deprecated_finalize_registration |
167 | 167 | * |
168 | 168 | * @param EE_Registration $registration |
169 | 169 | */ |
170 | -function ee_deprecated_finalize_registration( EE_Registration $registration ) { |
|
171 | - $action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
172 | - if ( $action_ref ) { |
|
170 | +function ee_deprecated_finalize_registration(EE_Registration $registration) { |
|
171 | + $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
172 | + if ($action_ref) { |
|
173 | 173 | EE_Error::doing_it_wrong( |
174 | 174 | $action_ref, |
175 | 175 | sprintf( |
176 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ), |
|
176 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'), |
|
177 | 177 | '<br />', |
178 | 178 | '/core/business/EE_Registration_Processor.class.php', |
179 | 179 | 'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook' |
180 | 180 | ), |
181 | 181 | '4.6.0' |
182 | 182 | ); |
183 | - do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ))); |
|
183 | + do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))); |
|
184 | 184 | } |
185 | 185 | } |
186 | -add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 ); |
|
186 | +add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1); |
|
187 | 187 | |
188 | 188 | |
189 | 189 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called. |
192 | 192 | * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately. |
193 | 193 | */ |
194 | -function ee_deprecated_hooks(){ |
|
194 | +function ee_deprecated_hooks() { |
|
195 | 195 | /** |
196 | 196 | * @var $hooks array where keys are hook names, and their values are array{ |
197 | 197 | * @type string $version when deprecated |
@@ -202,25 +202,25 @@ discard block |
||
202 | 202 | $hooks = array( |
203 | 203 | 'AHEE__EE_System___do_setup_validations' => array( |
204 | 204 | 'version' => '4.6.0', |
205 | - 'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ), |
|
205 | + 'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'), |
|
206 | 206 | 'still_works' => FALSE |
207 | 207 | ) |
208 | 208 | ); |
209 | - foreach( $hooks as $name => $deprecation_info ){ |
|
210 | - if( has_action( $name ) ){ |
|
209 | + foreach ($hooks as $name => $deprecation_info) { |
|
210 | + if (has_action($name)) { |
|
211 | 211 | EE_Error::doing_it_wrong( |
212 | 212 | $name, |
213 | 213 | sprintf( |
214 | - __('This filter is deprecated. %1$s%2$s','event_espresso'), |
|
215 | - $deprecation_info[ 'still_works' ] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ), |
|
216 | - isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' ) |
|
214 | + __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
215 | + $deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'), |
|
216 | + isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso') |
|
217 | 217 | ), |
218 | - isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' ) |
|
218 | + isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
219 | 219 | ); |
220 | 220 | } |
221 | 221 | } |
222 | 222 | } |
223 | -add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' ); |
|
223 | +add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks'); |
|
224 | 224 | |
225 | 225 | |
226 | 226 | |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @return boolean |
232 | 232 | */ |
233 | 233 | function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() { |
234 | - $in_use = has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' ) |
|
235 | - || has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' ); |
|
236 | - if( $in_use ) { |
|
234 | + $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
235 | + || has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'); |
|
236 | + if ($in_use) { |
|
237 | 237 | $msg = __( |
238 | 238 | 'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.' |
239 | 239 | . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,' |
@@ -242,18 +242,18 @@ discard block |
||
242 | 242 | 'event_espresso' ) |
243 | 243 | ; |
244 | 244 | EE_Error::doing_it_wrong( |
245 | - __CLASS__ . '::' . __FUNCTION__, |
|
245 | + __CLASS__.'::'.__FUNCTION__, |
|
246 | 246 | $msg, |
247 | 247 | '4.8.32.rc.000' |
248 | 248 | ); |
249 | 249 | //it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
250 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
251 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
250 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
251 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | return $in_use; |
255 | 255 | } |
256 | -add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' ); |
|
256 | +add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'); |
|
257 | 257 | |
258 | 258 | /** |
259 | 259 | * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165 |
@@ -262,34 +262,34 @@ discard block |
||
262 | 262 | * @param EE_Admin_Page $admin_page |
263 | 263 | * @return void |
264 | 264 | */ |
265 | -function ee_deprecated_update_attendee_registration_form_old( $admin_page ) { |
|
265 | +function ee_deprecated_update_attendee_registration_form_old($admin_page) { |
|
266 | 266 | //check if the old hooks are in use. If not, do the default |
267 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
268 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
267 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
268 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | $req_data = $admin_page->get_request_data(); |
272 | - $qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE; |
|
273 | - $REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE; |
|
274 | - $qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns ); |
|
275 | - if ( ! $REG_ID || ! $qstns ) { |
|
276 | - EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
272 | + $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE; |
|
273 | + $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE; |
|
274 | + $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
275 | + if ( ! $REG_ID || ! $qstns) { |
|
276 | + EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
277 | 277 | } |
278 | 278 | $success = TRUE; |
279 | 279 | |
280 | 280 | // allow others to get in on this awesome fun :D |
281 | - do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns ); |
|
281 | + do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns); |
|
282 | 282 | // loop thru questions... FINALLY!!! |
283 | 283 | |
284 | - foreach ( $qstns as $QST_ID => $qstn ) { |
|
284 | + foreach ($qstns as $QST_ID => $qstn) { |
|
285 | 285 | //if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
286 | - if ( !is_array($qstn) ) { |
|
287 | - $success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn); |
|
286 | + if ( ! is_array($qstn)) { |
|
287 | + $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
288 | 288 | continue; |
289 | 289 | } |
290 | 290 | |
291 | 291 | |
292 | - foreach ( $qstn as $ANS_ID => $ANS_value ) { |
|
292 | + foreach ($qstn as $ANS_ID => $ANS_value) { |
|
293 | 293 | //get answer |
294 | 294 | $query_params = array( |
295 | 295 | 0 => array( |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | ); |
301 | 301 | $answer = EEM_Answer::instance()->get_one($query_params); |
302 | 302 | //this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
303 | - if ( ! $answer instanceof EE_Answer ) { |
|
303 | + if ( ! $answer instanceof EE_Answer) { |
|
304 | 304 | $set_values = array( |
305 | 305 | 'QST_ID' => $QST_ID, |
306 | 306 | 'REG_ID' => $REG_ID, |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | } |
316 | 316 | } |
317 | 317 | $what = __('Registration Form', 'event_espresso'); |
318 | - $route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' ); |
|
319 | - $admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route ); |
|
318 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
319 | + $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
320 | 320 | exit; |
321 | 321 | } |
322 | -add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 ); |
|
322 | +add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1); |
|
323 | 323 | /** |
324 | 324 | * Render the registration admin page's custom questions area in the old fashion |
325 | 325 | * and firing the old hooks. When this method is removed, we can probably also |
@@ -332,31 +332,31 @@ discard block |
||
332 | 332 | * @return bool |
333 | 333 | * @throws \EE_Error |
334 | 334 | */ |
335 | -function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) { |
|
335 | +function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) { |
|
336 | 336 | //check if the old hooks are in use. If not, do the default |
337 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
338 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
337 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
338 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
339 | 339 | return $do_default_action; |
340 | 340 | } |
341 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 ); |
|
342 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 ); |
|
343 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 ); |
|
344 | - add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 ); |
|
341 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1); |
|
342 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1); |
|
343 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
344 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
345 | 345 | |
346 | - $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') ); |
|
346 | + $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID')); |
|
347 | 347 | |
348 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
348 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
349 | 349 | $template_args = array( |
350 | - 'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ), |
|
350 | + 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
351 | 351 | 'reg_questions_form_action' => 'edit_registration', |
352 | 352 | 'REG_ID' => $registration->ID() |
353 | 353 | ); |
354 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
355 | - echo EEH_Template::display_template( $template_path, $template_args, TRUE ); |
|
354 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
355 | + echo EEH_Template::display_template($template_path, $template_args, TRUE); |
|
356 | 356 | //indicate that we should not do the default admin page code |
357 | 357 | return false; |
358 | 358 | } |
359 | -add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 ); |
|
359 | +add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3); |
|
360 | 360 | |
361 | 361 | |
362 | 362 | |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | '4.9.0' |
398 | 398 | ); |
399 | 399 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
400 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
401 | - $messenger = $message_resource_manager->get_messenger( $messenger_name ); |
|
402 | - $message_type = $message_resource_manager->get_message_type( $message_type_name ); |
|
400 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
401 | + $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
402 | + $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
403 | 403 | return EE_Registry::instance()->load_lib( |
404 | 404 | 'Messages_Template_Defaults', |
405 | 405 | array( |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | /** |
465 | 465 | * @param string $method |
466 | 466 | */ |
467 | - public function _class_is_deprecated( $method ) { |
|
467 | + public function _class_is_deprecated($method) { |
|
468 | 468 | EE_Error::doing_it_wrong( |
469 | - 'EE_messages::' . $method, |
|
470 | - __( 'EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.' ), |
|
469 | + 'EE_messages::'.$method, |
|
470 | + __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
471 | 471 | '4.9.0', |
472 | 472 | '4.10.0.p' |
473 | 473 | ); |
474 | 474 | // Please use EE_Message_Resource_Manager instead |
475 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
475 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | |
@@ -482,10 +482,10 @@ discard block |
||
482 | 482 | * @param string $messenger_name |
483 | 483 | * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
484 | 484 | */ |
485 | - public function ensure_messenger_is_active( $messenger_name ) { |
|
485 | + public function ensure_messenger_is_active($messenger_name) { |
|
486 | 486 | // EE_messages has been deprecated |
487 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
488 | - return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name ); |
|
487 | + $this->_class_is_deprecated(__FUNCTION__); |
|
488 | + return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | |
@@ -497,10 +497,10 @@ discard block |
||
497 | 497 | * @return bool true if it got activated (or was active) and false if not. |
498 | 498 | * @throws \EE_Error |
499 | 499 | */ |
500 | - public function ensure_message_type_is_active( $message_type, $messenger ) { |
|
500 | + public function ensure_message_type_is_active($message_type, $messenger) { |
|
501 | 501 | // EE_messages has been deprecated |
502 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
503 | - return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger ); |
|
502 | + $this->_class_is_deprecated(__FUNCTION__); |
|
503 | + return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | |
@@ -513,10 +513,10 @@ discard block |
||
513 | 513 | * they are already setup.) |
514 | 514 | * @return boolean an array of generated templates or false if nothing generated/activated. |
515 | 515 | */ |
516 | - public function activate_messenger( $messenger_name, $mts_to_activate = array() ) { |
|
516 | + public function activate_messenger($messenger_name, $mts_to_activate = array()) { |
|
517 | 517 | // EE_messages has been deprecated |
518 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
519 | - return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate ); |
|
518 | + $this->_class_is_deprecated(__FUNCTION__); |
|
519 | + return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | |
@@ -528,10 +528,10 @@ discard block |
||
528 | 528 | * |
529 | 529 | * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
530 | 530 | */ |
531 | - public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) { |
|
531 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) { |
|
532 | 532 | // EE_messages has been deprecated |
533 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
534 | - return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type ); |
|
533 | + $this->_class_is_deprecated(__FUNCTION__); |
|
534 | + return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | |
@@ -541,10 +541,10 @@ discard block |
||
541 | 541 | * @param string $messenger |
542 | 542 | * @return EE_messenger | null |
543 | 543 | */ |
544 | - public function get_messenger_if_active( $messenger ) { |
|
544 | + public function get_messenger_if_active($messenger) { |
|
545 | 545 | // EE_messages has been deprecated |
546 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
547 | - return $this->_message_resource_manager->get_active_messenger( $messenger ); |
|
546 | + $this->_class_is_deprecated(__FUNCTION__); |
|
547 | + return $this->_message_resource_manager->get_active_messenger($messenger); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | * 'message_type' => null |
566 | 566 | * ) |
567 | 567 | */ |
568 | - public function validate_for_use( EE_Message $message ) { |
|
568 | + public function validate_for_use(EE_Message $message) { |
|
569 | 569 | // EE_messages has been deprecated |
570 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
570 | + $this->_class_is_deprecated(__FUNCTION__); |
|
571 | 571 | return array( |
572 | 572 | 'messenger' => $message->messenger_object(), |
573 | 573 | 'message_type' => $message->message_type_object(), |
@@ -595,41 +595,41 @@ discard block |
||
595 | 595 | $send = true |
596 | 596 | ) { |
597 | 597 | // EE_messages has been deprecated |
598 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
598 | + $this->_class_is_deprecated(__FUNCTION__); |
|
599 | 599 | /** @type EE_Messages_Processor $processor */ |
600 | - $processor = EE_Registry::instance()->load_lib( 'Messages_Processor' ); |
|
600 | + $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
601 | 601 | $error = false; |
602 | 602 | //try to intelligently determine what method we'll call based on the incoming data. |
603 | 603 | //if generating and sending are different then generate and send immediately. |
604 | - if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) { |
|
604 | + if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
605 | 605 | //in the legacy system, when generating and sending were different, that means all the |
606 | 606 | //vars are already in the request object. So let's just use that. |
607 | 607 | try { |
608 | 608 | /** @type EE_Message_To_Generate_From_Request $mtg */ |
609 | - $mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' ); |
|
610 | - $processor->generate_and_send_now( $mtg ); |
|
611 | - } catch ( EE_Error $e ) { |
|
609 | + $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
610 | + $processor->generate_and_send_now($mtg); |
|
611 | + } catch (EE_Error $e) { |
|
612 | 612 | $error_msg = __( |
613 | 613 | 'Please note that a system message failed to send due to a technical issue.', |
614 | 614 | 'event_espresso' |
615 | 615 | ); |
616 | 616 | // add specific message for developers if WP_DEBUG in on |
617 | - $error_msg .= '||' . $e->getMessage(); |
|
618 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
617 | + $error_msg .= '||'.$e->getMessage(); |
|
618 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
619 | 619 | $error = true; |
620 | 620 | } |
621 | 621 | } else { |
622 | - $processor->generate_for_all_active_messengers( $type, $vars, $send ); |
|
622 | + $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
623 | 623 | //let's find out if there were any errors and how many successfully were queued. |
624 | 624 | $count_errors = $processor->get_queue()->count_STS_in_queue( |
625 | - array( EEM_Message::status_failed, EEM_Message::status_debug_only ) |
|
625 | + array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
626 | 626 | ); |
627 | - $count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete ); |
|
628 | - $count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry ); |
|
627 | + $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
628 | + $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
629 | 629 | $count_errors = $count_errors + $count_retry; |
630 | - if ( $count_errors > 0 ) { |
|
630 | + if ($count_errors > 0) { |
|
631 | 631 | $error = true; |
632 | - if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) { |
|
632 | + if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
633 | 633 | $message = sprintf( |
634 | 634 | __( |
635 | 635 | 'There were %d errors and %d messages successfully queued for generation and sending', |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | $count_errors, |
639 | 639 | $count_queued |
640 | 640 | ); |
641 | - } elseif ( $count_errors > 1 && $count_queued === 1 ) { |
|
641 | + } elseif ($count_errors > 1 && $count_queued === 1) { |
|
642 | 642 | $message = sprintf( |
643 | 643 | __( |
644 | 644 | 'There were %d errors and %d message successfully queued for generation.', |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | $count_errors, |
648 | 648 | $count_queued |
649 | 649 | ); |
650 | - } elseif ( $count_errors === 1 && $count_queued > 1 ) { |
|
650 | + } elseif ($count_errors === 1 && $count_queued > 1) { |
|
651 | 651 | $message = sprintf( |
652 | 652 | __( |
653 | 653 | 'There was %d error and %d messages successfully queued for generation.', |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | $count_errors |
666 | 666 | ); |
667 | 667 | } |
668 | - EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ ); |
|
668 | + EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
669 | 669 | } else { |
670 | - if ( $count_queued === 1 ) { |
|
670 | + if ($count_queued === 1) { |
|
671 | 671 | $message = sprintf( |
672 | 672 | __( |
673 | 673 | '%d message successfully queued for generation.', |
@@ -684,18 +684,18 @@ discard block |
||
684 | 684 | $count_queued |
685 | 685 | ); |
686 | 686 | } |
687 | - EE_Error::add_success( $message ); |
|
687 | + EE_Error::add_success($message); |
|
688 | 688 | } |
689 | 689 | } |
690 | 690 | //if no error then return the generated message(s). |
691 | - if ( ! $error && ! $send ) { |
|
692 | - $generated_queue = $processor->generate_queue( false ); |
|
691 | + if ( ! $error && ! $send) { |
|
692 | + $generated_queue = $processor->generate_queue(false); |
|
693 | 693 | //get message and return. |
694 | 694 | $generated_queue->get_message_repository()->rewind(); |
695 | 695 | $messages = array(); |
696 | - while ( $generated_queue->get_message_repository()->valid() ) { |
|
696 | + while ($generated_queue->get_message_repository()->valid()) { |
|
697 | 697 | $message = $generated_queue->get_message_repository()->current(); |
698 | - if ( $message instanceof EE_Message ) { |
|
698 | + if ($message instanceof EE_Message) { |
|
699 | 699 | //set properties that might be expected by add-ons (backward compat) |
700 | 700 | $message->content = $message->content(); |
701 | 701 | $message->template_pack = $message->get_template_pack(); |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular preview |
721 | 721 | * @return string The body of the message. |
722 | 722 | */ |
723 | - public function preview_message( $type, $context, $messenger, $send = false ) { |
|
723 | + public function preview_message($type, $context, $messenger, $send = false) { |
|
724 | 724 | // EE_messages has been deprecated |
725 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
726 | - return EED_Messages::preview_message( $type, $context, $messenger, $send ); |
|
725 | + $this->_class_is_deprecated(__FUNCTION__); |
|
726 | + return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | |
@@ -737,14 +737,14 @@ discard block |
||
737 | 737 | * |
738 | 738 | * @return bool success or fail. |
739 | 739 | */ |
740 | - public function send_message_with_messenger_only( $messenger, $message_type, $message ) { |
|
740 | + public function send_message_with_messenger_only($messenger, $message_type, $message) { |
|
741 | 741 | // EE_messages has been deprecated |
742 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
742 | + $this->_class_is_deprecated(__FUNCTION__); |
|
743 | 743 | //setup for sending to new method. |
744 | 744 | /** @type EE_Messages_Queue $queue */ |
745 | - $queue = EE_Registry::instance()->load_lib( 'Messages_Queue' ); |
|
745 | + $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
746 | 746 | //make sure we have a proper message object |
747 | - if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) { |
|
747 | + if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
748 | 748 | $msg = EE_Message_Factory::create( |
749 | 749 | array( |
750 | 750 | 'MSG_messenger' => $messenger, |
@@ -756,15 +756,15 @@ discard block |
||
756 | 756 | } else { |
757 | 757 | $msg = $message; |
758 | 758 | } |
759 | - if ( ! $msg instanceof EE_Message ) { |
|
759 | + if ( ! $msg instanceof EE_Message) { |
|
760 | 760 | return false; |
761 | 761 | } |
762 | 762 | //make sure any content in a content property (if not empty) is set on the MSG_content. |
763 | - if ( ! empty( $msg->content ) ) { |
|
764 | - $msg->set( 'MSG_content', $msg->content ); |
|
763 | + if ( ! empty($msg->content)) { |
|
764 | + $msg->set('MSG_content', $msg->content); |
|
765 | 765 | } |
766 | - $queue->add( $msg ); |
|
767 | - return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue ); |
|
766 | + $queue->add($msg); |
|
767 | + return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
@@ -778,11 +778,11 @@ discard block |
||
778 | 778 | * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned. |
779 | 779 | * @throws \EE_Error |
780 | 780 | */ |
781 | - public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) { |
|
781 | + public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) { |
|
782 | 782 | // EE_messages has been deprecated |
783 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
784 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
785 | - return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global ); |
|
783 | + $this->_class_is_deprecated(__FUNCTION__); |
|
784 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
785 | + return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | |
@@ -793,11 +793,11 @@ discard block |
||
793 | 793 | * @param string $message_type_name name of EE_message_type |
794 | 794 | * @return array |
795 | 795 | */ |
796 | - public function get_fields( $messenger_name, $message_type_name ) { |
|
796 | + public function get_fields($messenger_name, $message_type_name) { |
|
797 | 797 | // EE_messages has been deprecated |
798 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
799 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
800 | - return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name ); |
|
798 | + $this->_class_is_deprecated(__FUNCTION__); |
|
799 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
800 | + return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -811,13 +811,13 @@ discard block |
||
811 | 811 | * @return array multidimensional array of messenger and message_type objects |
812 | 812 | * (messengers index, and message_type index); |
813 | 813 | */ |
814 | - public function get_installed( $type = 'all', $skip_cache = false ) { |
|
814 | + public function get_installed($type = 'all', $skip_cache = false) { |
|
815 | 815 | // EE_messages has been deprecated |
816 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
817 | - if ( $skip_cache ) { |
|
816 | + $this->_class_is_deprecated(__FUNCTION__); |
|
817 | + if ($skip_cache) { |
|
818 | 818 | $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
819 | 819 | } |
820 | - switch ( $type ) { |
|
820 | + switch ($type) { |
|
821 | 821 | case 'messengers' : |
822 | 822 | return array( |
823 | 823 | 'messenger' => $this->_message_resource_manager->installed_messengers(), |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | */ |
847 | 847 | public function get_active_messengers() { |
848 | 848 | // EE_messages has been deprecated |
849 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
849 | + $this->_class_is_deprecated(__FUNCTION__); |
|
850 | 850 | return $this->_message_resource_manager->active_messengers(); |
851 | 851 | } |
852 | 852 | |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function get_active_message_types() { |
860 | 860 | // EE_messages has been deprecated |
861 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
861 | + $this->_class_is_deprecated(__FUNCTION__); |
|
862 | 862 | return $this->_message_resource_manager->list_of_active_message_types(); |
863 | 863 | } |
864 | 864 | |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | */ |
871 | 871 | public function get_active_message_type_objects() { |
872 | 872 | // EE_messages has been deprecated |
873 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
873 | + $this->_class_is_deprecated(__FUNCTION__); |
|
874 | 874 | return $this->_message_resource_manager->get_active_message_type_objects(); |
875 | 875 | } |
876 | 876 | |
@@ -882,10 +882,10 @@ discard block |
||
882 | 882 | * @param string $messenger The messenger being checked |
883 | 883 | * @return EE_message_type[] (or empty array if none present) |
884 | 884 | */ |
885 | - public function get_active_message_types_per_messenger( $messenger ) { |
|
885 | + public function get_active_message_types_per_messenger($messenger) { |
|
886 | 886 | // EE_messages has been deprecated |
887 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
888 | - return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger ); |
|
887 | + $this->_class_is_deprecated(__FUNCTION__); |
|
888 | + return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | |
@@ -896,10 +896,10 @@ discard block |
||
896 | 896 | * @param string $message_type The string should correspond to a message type. |
897 | 897 | * @return EE_message_type|null |
898 | 898 | */ |
899 | - public function get_active_message_type( $messenger, $message_type ) { |
|
899 | + public function get_active_message_type($messenger, $message_type) { |
|
900 | 900 | // EE_messages has been deprecated |
901 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
902 | - return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type ); |
|
901 | + $this->_class_is_deprecated(__FUNCTION__); |
|
902 | + return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | */ |
911 | 911 | public function get_installed_message_types() { |
912 | 912 | // EE_messages has been deprecated |
913 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
913 | + $this->_class_is_deprecated(__FUNCTION__); |
|
914 | 914 | return $this->_message_resource_manager->installed_message_types(); |
915 | 915 | } |
916 | 916 | |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | */ |
923 | 923 | public function get_installed_messengers() { |
924 | 924 | // EE_messages has been deprecated |
925 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
925 | + $this->_class_is_deprecated(__FUNCTION__); |
|
926 | 926 | return $this->_message_resource_manager->installed_messengers(); |
927 | 927 | } |
928 | 928 | |
@@ -933,10 +933,10 @@ discard block |
||
933 | 933 | * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type. |
934 | 934 | * @return array |
935 | 935 | */ |
936 | - public function get_all_contexts( $slugs_only = true ) { |
|
936 | + public function get_all_contexts($slugs_only = true) { |
|
937 | 937 | // EE_messages has been deprecated |
938 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
939 | - return $this->_message_resource_manager->get_all_contexts( $slugs_only ); |
|
938 | + $this->_class_is_deprecated(__FUNCTION__); |
|
939 | + return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | add_filter( |
996 | 996 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
997 | 997 | function($event_list_iframe_css) { |
998 | - if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) { |
|
998 | + if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
999 | 999 | return $event_list_iframe_css; |
1000 | 1000 | } |
1001 | 1001 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | add_filter( |
1016 | 1016 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
1017 | 1017 | function($event_list_iframe_js) { |
1018 | - if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) { |
|
1018 | + if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1019 | 1019 | return $event_list_iframe_js; |
1020 | 1020 | } |
1021 | 1021 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | add_action( |
1036 | 1036 | 'AHEE__EE_Capabilities__addCaps__complete', |
1037 | 1037 | function($capabilities_map) { |
1038 | - if ( ! has_action( 'AHEE__EE_Capabilities__init_role_caps__complete' )) { |
|
1038 | + if ( ! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1039 | 1039 | return; |
1040 | 1040 | } |
1041 | 1041 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | add_filter( |
1056 | 1056 | 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
1057 | 1057 | function($existing_attendee, $registration, $attendee_data) { |
1058 | - if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) { |
|
1058 | + if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1059 | 1059 | return $existing_attendee; |
1060 | 1060 | } |
1061 | 1061 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1071,7 +1071,7 @@ discard block |
||
1071 | 1071 | $existing_attendee, $registration, $attendee_data |
1072 | 1072 | ); |
1073 | 1073 | }, |
1074 | - 10,3 |
|
1074 | + 10, 3 |
|
1075 | 1075 | ); |
1076 | 1076 | |
1077 | 1077 | /** |
@@ -1135,7 +1135,7 @@ discard block |
||
1135 | 1135 | */ |
1136 | 1136 | public function event_list_title($event_list_title = '') |
1137 | 1137 | { |
1138 | - if (! empty($this->title)) { |
|
1138 | + if ( ! empty($this->title)) { |
|
1139 | 1139 | return $this->title; |
1140 | 1140 | } |
1141 | 1141 | return $event_list_title; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | { |
262 | 262 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
263 | 263 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
264 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
264 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
296 | 296 | ) |
297 | 297 | ) { |
298 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
298 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
299 | 299 | } |
300 | 300 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
301 | 301 | } |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | private function _parse_model_names() |
782 | 782 | { |
783 | 783 | //get all the files in the EE_MODELS folder that end in .model.php |
784 | - $models = glob(EE_MODELS . '*.model.php'); |
|
784 | + $models = glob(EE_MODELS.'*.model.php'); |
|
785 | 785 | $model_names = array(); |
786 | 786 | $non_abstract_db_models = array(); |
787 | 787 | foreach ($models as $model) { |
@@ -809,8 +809,8 @@ discard block |
||
809 | 809 | */ |
810 | 810 | private function _maybe_brew_regular() |
811 | 811 | { |
812 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
813 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
812 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
813 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
814 | 814 | } |
815 | 815 | } |
816 | 816 | |
@@ -860,8 +860,8 @@ discard block |
||
860 | 860 | 'event_espresso'); |
861 | 861 | $msg .= '<ul>'; |
862 | 862 | foreach ($class_names as $class_name) { |
863 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
864 | - $class_name) . '</b></li>'; |
|
863 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
864 | + $class_name).'</b></li>'; |
|
865 | 865 | } |
866 | 866 | $msg .= '</ul>'; |
867 | 867 | $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
@@ -1016,8 +1016,8 @@ discard block |
||
1016 | 1016 | $this->registry->load_core('Session'); |
1017 | 1017 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
1018 | 1018 | // load_espresso_template_tags |
1019 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
1020 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
1019 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
1020 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
1021 | 1021 | } |
1022 | 1022 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
1023 | 1023 | $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true); |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | 'href' => $events_admin_url, |
1164 | 1164 | 'meta' => array( |
1165 | 1165 | 'title' => __('Event Espresso', 'event_espresso'), |
1166 | - 'class' => $menu_class . 'first', |
|
1166 | + 'class' => $menu_class.'first', |
|
1167 | 1167 | ), |
1168 | 1168 | )); |
1169 | 1169 | //Events |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
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 | |
@@ -24,1506 +24,1506 @@ discard block |
||
24 | 24 | { |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
29 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
30 | - */ |
|
31 | - const req_type_normal = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * Indicates this is a brand new installation of EE so we should install |
|
35 | - * tables and default data etc |
|
36 | - */ |
|
37 | - const req_type_new_activation = 1; |
|
38 | - |
|
39 | - /** |
|
40 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
41 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
42 | - * and that default data is setup too |
|
43 | - */ |
|
44 | - const req_type_reactivation = 2; |
|
45 | - |
|
46 | - /** |
|
47 | - * indicates that EE has been upgraded since its previous request. |
|
48 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
49 | - */ |
|
50 | - const req_type_upgrade = 3; |
|
51 | - |
|
52 | - /** |
|
53 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
54 | - */ |
|
55 | - const req_type_downgrade = 4; |
|
56 | - |
|
57 | - /** |
|
58 | - * @deprecated since version 4.6.0.dev.006 |
|
59 | - * Now whenever a new_activation is detected the request type is still just |
|
60 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
61 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
62 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
63 | - * (Specifically, when the migration manager indicates migrations are finished |
|
64 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
65 | - */ |
|
66 | - const req_type_activation_but_not_installed = 5; |
|
67 | - |
|
68 | - /** |
|
69 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
70 | - */ |
|
71 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @var EE_System $_instance |
|
76 | - */ |
|
77 | - private static $_instance; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var EE_Registry $registry |
|
81 | - */ |
|
82 | - protected $registry; |
|
83 | - |
|
84 | - /** |
|
85 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
86 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
87 | - * |
|
88 | - * @var int $_req_type |
|
89 | - */ |
|
90 | - private $_req_type; |
|
91 | - |
|
92 | - /** |
|
93 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
94 | - * |
|
95 | - * @var boolean $_major_version_change |
|
96 | - */ |
|
97 | - private $_major_version_change = false; |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @singleton method used to instantiate class object |
|
103 | - * @access public |
|
104 | - * @param EE_Registry $Registry |
|
105 | - * @return EE_System |
|
106 | - */ |
|
107 | - public static function instance(EE_Registry $Registry = null) |
|
108 | - { |
|
109 | - // check if class object is instantiated |
|
110 | - if ( ! self::$_instance instanceof EE_System) { |
|
111 | - self::$_instance = new self($Registry); |
|
112 | - } |
|
113 | - return self::$_instance; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * resets the instance and returns it |
|
120 | - * |
|
121 | - * @return EE_System |
|
122 | - */ |
|
123 | - public static function reset() |
|
124 | - { |
|
125 | - self::$_instance->_req_type = null; |
|
126 | - //make sure none of the old hooks are left hanging around |
|
127 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
128 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
129 | - EE_Data_Migration_Manager::reset(); |
|
130 | - self::instance()->detect_activations_or_upgrades(); |
|
131 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
132 | - return self::instance(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * sets hooks for running rest of system |
|
139 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
140 | - * starting EE Addons from any other point may lead to problems |
|
141 | - * |
|
142 | - * @access private |
|
143 | - * @param EE_Registry $Registry |
|
144 | - */ |
|
145 | - private function __construct(EE_Registry $Registry) |
|
146 | - { |
|
147 | - $this->registry = $Registry; |
|
148 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
149 | - add_action( |
|
150 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
151 | - array($this, 'loadCapabilities'), |
|
152 | - 5 |
|
153 | - ); |
|
154 | - add_action( |
|
155 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
156 | - array($this, 'loadCommandBus'), |
|
157 | - 7 |
|
158 | - ); |
|
159 | - add_action( |
|
160 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
161 | - array($this, 'loadPluginApi'), |
|
162 | - 9 |
|
163 | - ); |
|
164 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
165 | - add_action( |
|
166 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
167 | - array($this, 'load_espresso_addons') |
|
168 | - ); |
|
169 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
170 | - // because the newly-activated addon didn't get a chance to run at all |
|
171 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
172 | - // detect whether install or upgrade |
|
173 | - add_action( |
|
174 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
175 | - array($this, 'detect_activations_or_upgrades'), |
|
176 | - 3 |
|
177 | - ); |
|
178 | - // load EE_Config, EE_Textdomain, etc |
|
179 | - add_action( |
|
180 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
181 | - array($this, 'load_core_configuration'), |
|
182 | - 5 |
|
183 | - ); |
|
184 | - // load EE_Config, EE_Textdomain, etc |
|
185 | - add_action( |
|
186 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
187 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
188 | - 7 |
|
189 | - ); |
|
190 | - // you wanna get going? I wanna get going... let's get going! |
|
191 | - add_action( |
|
192 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
193 | - array($this, 'brew_espresso'), |
|
194 | - 9 |
|
195 | - ); |
|
196 | - //other housekeeping |
|
197 | - //exclude EE critical pages from wp_list_pages |
|
198 | - add_filter( |
|
199 | - 'wp_list_pages_excludes', |
|
200 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
201 | - 10 |
|
202 | - ); |
|
203 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
204 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
205 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * load and setup EE_Capabilities |
|
212 | - * |
|
213 | - * @return void |
|
214 | - * @throws EE_Error |
|
215 | - */ |
|
216 | - public function loadCapabilities() |
|
217 | - { |
|
218 | - $this->registry->load_core('EE_Capabilities'); |
|
219 | - add_action( |
|
220 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
221 | - function() { |
|
222 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
223 | - } |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * create and cache the CommandBus, and also add middleware |
|
231 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
232 | - * which is why we need to load the CommandBus after Caps are set up |
|
233 | - * |
|
234 | - * @return void |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - public function loadCommandBus() |
|
238 | - { |
|
239 | - $this->registry->create( |
|
240 | - 'CommandBusInterface', |
|
241 | - array( |
|
242 | - null, |
|
243 | - apply_filters( |
|
244 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
245 | - array( |
|
246 | - $this->registry->create('CapChecker'), |
|
247 | - $this->registry->create('AddActionHook'), |
|
248 | - ) |
|
249 | - ), |
|
250 | - ), |
|
251 | - true |
|
252 | - ); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @return void |
|
259 | - * @throws EE_Error |
|
260 | - */ |
|
261 | - public function loadPluginApi() |
|
262 | - { |
|
263 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
264 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
265 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * load_espresso_addons |
|
272 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
273 | - * this is hooked into both: |
|
274 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
275 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
276 | - * and the WP 'activate_plugin' hook point |
|
277 | - * |
|
278 | - * @access public |
|
279 | - * @return void |
|
280 | - * @throws EE_Error |
|
281 | - */ |
|
282 | - public function load_espresso_addons() |
|
283 | - { |
|
284 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
285 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
286 | - //We want it for mobile apps. Just include the entire plugin |
|
287 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
288 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
289 | - //and causes a fatal error |
|
290 | - if ( |
|
291 | - ! (isset($_GET['activate']) && $_GET['activate'] === 'true') |
|
292 | - && ! function_exists('json_basic_auth_handler') |
|
293 | - && ! function_exists('json_basic_auth_error') |
|
294 | - && ! ( |
|
295 | - isset($_GET['action']) |
|
296 | - && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
297 | - ) |
|
298 | - ) { |
|
299 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
300 | - } |
|
301 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * detect_activations_or_upgrades |
|
308 | - * Checks for activation or upgrade of core first; |
|
309 | - * then also checks if any registered addons have been activated or upgraded |
|
310 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
311 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
312 | - * |
|
313 | - * @access public |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function detect_activations_or_upgrades() |
|
317 | - { |
|
318 | - //first off: let's make sure to handle core |
|
319 | - $this->detect_if_activation_or_upgrade(); |
|
320 | - foreach ($this->registry->addons as $addon) { |
|
321 | - //detect teh request type for that addon |
|
322 | - $addon->detect_activation_or_upgrade(); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * detect_if_activation_or_upgrade |
|
330 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
331 | - * and either setting up the DB or setting up maintenance mode etc. |
|
332 | - * |
|
333 | - * @access public |
|
334 | - * @return void |
|
335 | - */ |
|
336 | - public function detect_if_activation_or_upgrade() |
|
337 | - { |
|
338 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
339 | - // load M-Mode class |
|
340 | - $this->registry->load_core('Maintenance_Mode'); |
|
341 | - // check if db has been updated, or if its a brand-new installation |
|
342 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
343 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
344 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
345 | - switch ($request_type) { |
|
346 | - case EE_System::req_type_new_activation: |
|
347 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
348 | - $this->_handle_core_version_change($espresso_db_update); |
|
349 | - break; |
|
350 | - case EE_System::req_type_reactivation: |
|
351 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
352 | - $this->_handle_core_version_change($espresso_db_update); |
|
353 | - break; |
|
354 | - case EE_System::req_type_upgrade: |
|
355 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
356 | - //migrations may be required now that we've upgraded |
|
357 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
358 | - $this->_handle_core_version_change($espresso_db_update); |
|
359 | - // echo "done upgrade";die; |
|
360 | - break; |
|
361 | - case EE_System::req_type_downgrade: |
|
362 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
363 | - //its possible migrations are no longer required |
|
364 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
365 | - $this->_handle_core_version_change($espresso_db_update); |
|
366 | - break; |
|
367 | - case EE_System::req_type_normal: |
|
368 | - default: |
|
369 | - // $this->_maybe_redirect_to_ee_about(); |
|
370 | - break; |
|
371 | - } |
|
372 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Updates the list of installed versions and sets hooks for |
|
379 | - * initializing the database later during the request |
|
380 | - * |
|
381 | - * @param array $espresso_db_update |
|
382 | - */ |
|
383 | - protected function _handle_core_version_change($espresso_db_update) |
|
384 | - { |
|
385 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
386 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
387 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
388 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
395 | - * information about what versions of EE have been installed and activated, |
|
396 | - * NOT necessarily the state of the database |
|
397 | - * |
|
398 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
399 | - * If not supplied, fetches it from the options table |
|
400 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
401 | - */ |
|
402 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
403 | - { |
|
404 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
405 | - if ( ! $espresso_db_update) { |
|
406 | - $espresso_db_update = get_option('espresso_db_update'); |
|
407 | - } |
|
408 | - // check that option is an array |
|
409 | - if ( ! is_array($espresso_db_update)) { |
|
410 | - // if option is FALSE, then it never existed |
|
411 | - if ($espresso_db_update === false) { |
|
412 | - // make $espresso_db_update an array and save option with autoload OFF |
|
413 | - $espresso_db_update = array(); |
|
414 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
415 | - } else { |
|
416 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
417 | - $espresso_db_update = array($espresso_db_update => array()); |
|
418 | - update_option('espresso_db_update', $espresso_db_update); |
|
419 | - } |
|
420 | - } else { |
|
421 | - $corrected_db_update = array(); |
|
422 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
423 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
424 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
425 | - //the key is an int, and the value IS NOT an array |
|
426 | - //so it must be numerically-indexed, where values are versions installed... |
|
427 | - //fix it! |
|
428 | - $version_string = $should_be_array; |
|
429 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
430 | - } else { |
|
431 | - //ok it checks out |
|
432 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
433 | - } |
|
434 | - } |
|
435 | - $espresso_db_update = $corrected_db_update; |
|
436 | - update_option('espresso_db_update', $espresso_db_update); |
|
437 | - } |
|
438 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
439 | - return $espresso_db_update; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
446 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
447 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
448 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
449 | - * so that it will be done when migrations are finished |
|
450 | - * |
|
451 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
452 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
453 | - * This is a resource-intensive job |
|
454 | - * so we prefer to only do it when necessary |
|
455 | - * @return void |
|
456 | - * @throws EE_Error |
|
457 | - */ |
|
458 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
459 | - { |
|
460 | - $request_type = $this->detect_req_type(); |
|
461 | - //only initialize system if we're not in maintenance mode. |
|
462 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
463 | - update_option('ee_flush_rewrite_rules', true); |
|
464 | - if ($verify_schema) { |
|
465 | - EEH_Activation::initialize_db_and_folders(); |
|
466 | - } |
|
467 | - EEH_Activation::initialize_db_content(); |
|
468 | - EEH_Activation::system_initialization(); |
|
469 | - if ($initialize_addons_too) { |
|
470 | - $this->initialize_addons(); |
|
471 | - } |
|
472 | - } else { |
|
473 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
474 | - } |
|
475 | - if ($request_type === EE_System::req_type_new_activation |
|
476 | - || $request_type === EE_System::req_type_reactivation |
|
477 | - || ( |
|
478 | - $request_type === EE_System::req_type_upgrade |
|
479 | - && $this->is_major_version_change() |
|
480 | - ) |
|
481 | - ) { |
|
482 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
483 | - } |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * Initializes the db for all registered addons |
|
490 | - * |
|
491 | - * @throws EE_Error |
|
492 | - */ |
|
493 | - public function initialize_addons() |
|
494 | - { |
|
495 | - //foreach registered addon, make sure its db is up-to-date too |
|
496 | - foreach ($this->registry->addons as $addon) { |
|
497 | - $addon->initialize_db_if_no_migrations_required(); |
|
498 | - } |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
505 | - * |
|
506 | - * @param array $version_history |
|
507 | - * @param string $current_version_to_add version to be added to the version history |
|
508 | - * @return boolean success as to whether or not this option was changed |
|
509 | - */ |
|
510 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
511 | - { |
|
512 | - if ( ! $version_history) { |
|
513 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
514 | - } |
|
515 | - if ($current_version_to_add === null) { |
|
516 | - $current_version_to_add = espresso_version(); |
|
517 | - } |
|
518 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
519 | - // re-save |
|
520 | - return update_option('espresso_db_update', $version_history); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * Detects if the current version indicated in the has existed in the list of |
|
527 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
528 | - * |
|
529 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
530 | - * If not supplied, fetches it from the options table. |
|
531 | - * Also, caches its result so later parts of the code can also know whether |
|
532 | - * there's been an update or not. This way we can add the current version to |
|
533 | - * espresso_db_update, but still know if this is a new install or not |
|
534 | - * @return int one of the constants on EE_System::req_type_ |
|
535 | - */ |
|
536 | - public function detect_req_type($espresso_db_update = null) |
|
537 | - { |
|
538 | - if ($this->_req_type === null) { |
|
539 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
540 | - : $this->fix_espresso_db_upgrade_option(); |
|
541 | - $this->_req_type = EE_System::detect_req_type_given_activation_history($espresso_db_update, |
|
542 | - 'ee_espresso_activation', espresso_version()); |
|
543 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
544 | - } |
|
545 | - return $this->_req_type; |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
552 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
553 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
554 | - * |
|
555 | - * @param $activation_history |
|
556 | - * @return bool |
|
557 | - */ |
|
558 | - protected function _detect_major_version_change($activation_history) |
|
559 | - { |
|
560 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
561 | - $previous_version_parts = explode('.', $previous_version); |
|
562 | - $current_version_parts = explode('.', espresso_version()); |
|
563 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
564 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
565 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
566 | - ); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Returns true if either the major or minor version of EE changed during this request. |
|
573 | - * 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 |
|
574 | - * |
|
575 | - * @return bool |
|
576 | - */ |
|
577 | - public function is_major_version_change() |
|
578 | - { |
|
579 | - return $this->_major_version_change; |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
586 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
587 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
588 | - * just activated to (for core that will always be espresso_version()) |
|
589 | - * |
|
590 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
591 | - * ee plugin. for core that's 'espresso_db_update' |
|
592 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
593 | - * indicate that this plugin was just activated |
|
594 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
595 | - * espresso_version()) |
|
596 | - * @return int one of the constants on EE_System::req_type_* |
|
597 | - */ |
|
598 | - public static function detect_req_type_given_activation_history( |
|
599 | - $activation_history_for_addon, |
|
600 | - $activation_indicator_option_name, |
|
601 | - $version_to_upgrade_to |
|
602 | - ) { |
|
603 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
604 | - if ($activation_history_for_addon) { |
|
605 | - //it exists, so this isn't a completely new install |
|
606 | - //check if this version already in that list of previously installed versions |
|
607 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
608 | - //it a version we haven't seen before |
|
609 | - if ($version_is_higher === 1) { |
|
610 | - $req_type = EE_System::req_type_upgrade; |
|
611 | - } else { |
|
612 | - $req_type = EE_System::req_type_downgrade; |
|
613 | - } |
|
614 | - delete_option($activation_indicator_option_name); |
|
615 | - } else { |
|
616 | - // its not an update. maybe a reactivation? |
|
617 | - if (get_option($activation_indicator_option_name, false)) { |
|
618 | - if ($version_is_higher === -1) { |
|
619 | - $req_type = EE_System::req_type_downgrade; |
|
620 | - } elseif ($version_is_higher === 0) { |
|
621 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
622 | - $req_type = EE_System::req_type_reactivation; |
|
623 | - } else {//$version_is_higher === 1 |
|
624 | - $req_type = EE_System::req_type_upgrade; |
|
625 | - } |
|
626 | - delete_option($activation_indicator_option_name); |
|
627 | - } else { |
|
628 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
629 | - if ($version_is_higher === -1) { |
|
630 | - $req_type = EE_System::req_type_downgrade; |
|
631 | - } elseif ($version_is_higher === 0) { |
|
632 | - //we've seen this version before and it's not an activation. its normal request |
|
633 | - $req_type = EE_System::req_type_normal; |
|
634 | - } else {//$version_is_higher === 1 |
|
635 | - $req_type = EE_System::req_type_upgrade; |
|
636 | - } |
|
637 | - } |
|
638 | - } |
|
639 | - } else { |
|
640 | - //brand new install |
|
641 | - $req_type = EE_System::req_type_new_activation; |
|
642 | - delete_option($activation_indicator_option_name); |
|
643 | - } |
|
644 | - return $req_type; |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
651 | - * the $activation_history_for_addon |
|
652 | - * |
|
653 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
654 | - * sometimes containing 'unknown-date' |
|
655 | - * @param string $version_to_upgrade_to (current version) |
|
656 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
657 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
658 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
659 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
660 | - */ |
|
661 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
662 | - { |
|
663 | - //find the most recently-activated version |
|
664 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
665 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * Gets the most recently active version listed in the activation history, |
|
672 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
673 | - * |
|
674 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
675 | - * sometimes containing 'unknown-date' |
|
676 | - * @return string |
|
677 | - */ |
|
678 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
679 | - { |
|
680 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
681 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
682 | - if (is_array($activation_history)) { |
|
683 | - foreach ($activation_history as $version => $times_activated) { |
|
684 | - //check there is a record of when this version was activated. Otherwise, |
|
685 | - //mark it as unknown |
|
686 | - if ( ! $times_activated) { |
|
687 | - $times_activated = array('unknown-date'); |
|
688 | - } |
|
689 | - if (is_string($times_activated)) { |
|
690 | - $times_activated = array($times_activated); |
|
691 | - } |
|
692 | - foreach ($times_activated as $an_activation) { |
|
693 | - if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
694 | - $most_recently_active_version = $version; |
|
695 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
696 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
697 | - } |
|
698 | - } |
|
699 | - } |
|
700 | - } |
|
701 | - return $most_recently_active_version; |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * This redirects to the about EE page after activation |
|
708 | - * |
|
709 | - * @return void |
|
710 | - */ |
|
711 | - public function redirect_to_about_ee() |
|
712 | - { |
|
713 | - $notices = EE_Error::get_notices(false); |
|
714 | - //if current user is an admin and it's not an ajax or rest request |
|
715 | - if ( |
|
716 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
717 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
718 | - && ! isset($notices['errors']) |
|
719 | - && apply_filters( |
|
720 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
721 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
722 | - ) |
|
723 | - ) { |
|
724 | - $query_params = array('page' => 'espresso_about'); |
|
725 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
726 | - $query_params['new_activation'] = true; |
|
727 | - } |
|
728 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
729 | - $query_params['reactivation'] = true; |
|
730 | - } |
|
731 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
732 | - wp_safe_redirect($url); |
|
733 | - exit(); |
|
734 | - } |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * load_core_configuration |
|
741 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
742 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
743 | - * |
|
744 | - * @return void |
|
745 | - * @throws \ReflectionException |
|
746 | - */ |
|
747 | - public function load_core_configuration() |
|
748 | - { |
|
749 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
750 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
751 | - //load textdomain |
|
752 | - EE_Load_Textdomain::load_textdomain(); |
|
753 | - // load and setup EE_Config and EE_Network_Config |
|
754 | - $this->registry->load_core('Config'); |
|
755 | - $this->registry->load_core('Network_Config'); |
|
756 | - // setup autoloaders |
|
757 | - // enable logging? |
|
758 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
759 | - $this->registry->load_core('Log'); |
|
760 | - } |
|
761 | - // check for activation errors |
|
762 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
763 | - if ($activation_errors) { |
|
764 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
765 | - update_option('ee_plugin_activation_errors', false); |
|
766 | - } |
|
767 | - // get model names |
|
768 | - $this->_parse_model_names(); |
|
769 | - //load caf stuff a chance to play during the activation process too. |
|
770 | - $this->_maybe_brew_regular(); |
|
771 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - |
|
776 | - /** |
|
777 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
778 | - * |
|
779 | - * @return void |
|
780 | - * @throws ReflectionException |
|
781 | - */ |
|
782 | - private function _parse_model_names() |
|
783 | - { |
|
784 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
785 | - $models = glob(EE_MODELS . '*.model.php'); |
|
786 | - $model_names = array(); |
|
787 | - $non_abstract_db_models = array(); |
|
788 | - foreach ($models as $model) { |
|
789 | - // get model classname |
|
790 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
791 | - $short_name = str_replace('EEM_', '', $classname); |
|
792 | - $reflectionClass = new ReflectionClass($classname); |
|
793 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
794 | - $non_abstract_db_models[$short_name] = $classname; |
|
795 | - } |
|
796 | - $model_names[$short_name] = $classname; |
|
797 | - } |
|
798 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
799 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
800 | - $non_abstract_db_models); |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
807 | - * that need to be setup before our EE_System launches. |
|
808 | - * |
|
809 | - * @return void |
|
810 | - */ |
|
811 | - private function _maybe_brew_regular() |
|
812 | - { |
|
813 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
814 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
815 | - } |
|
816 | - } |
|
817 | - |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * register_shortcodes_modules_and_widgets |
|
822 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
823 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
824 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
825 | - * |
|
826 | - * @access public |
|
827 | - * @return void |
|
828 | - */ |
|
829 | - public function register_shortcodes_modules_and_widgets() |
|
830 | - { |
|
831 | - try { |
|
832 | - // load, register, and add shortcodes the new way |
|
833 | - LoaderFactory::getLoader()->getShared( |
|
834 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
835 | - array( |
|
836 | - // and the old way, but we'll put it under control of the new system |
|
837 | - EE_Config::getLegacyShortcodesManager() |
|
838 | - ) |
|
839 | - ); |
|
840 | - } catch (Exception $exception) { |
|
841 | - new ExceptionStackTraceDisplay($exception); |
|
842 | - } |
|
843 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
844 | - // check for addons using old hook point |
|
845 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
846 | - $this->_incompatible_addon_error(); |
|
847 | - } |
|
848 | - } |
|
849 | - |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * _incompatible_addon_error |
|
854 | - * |
|
855 | - * @access public |
|
856 | - * @return void |
|
857 | - */ |
|
858 | - private function _incompatible_addon_error() |
|
859 | - { |
|
860 | - // get array of classes hooking into here |
|
861 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
862 | - if ( ! empty($class_names)) { |
|
863 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
864 | - 'event_espresso'); |
|
865 | - $msg .= '<ul>'; |
|
866 | - foreach ($class_names as $class_name) { |
|
867 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
868 | - $class_name) . '</b></li>'; |
|
869 | - } |
|
870 | - $msg .= '</ul>'; |
|
871 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
872 | - 'event_espresso'); |
|
873 | - // save list of incompatible addons to wp-options for later use |
|
874 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
875 | - if (is_admin()) { |
|
876 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
877 | - } |
|
878 | - } |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - |
|
883 | - /** |
|
884 | - * brew_espresso |
|
885 | - * begins the process of setting hooks for initializing EE in the correct order |
|
886 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
887 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
888 | - * |
|
889 | - * @return void |
|
890 | - */ |
|
891 | - public function brew_espresso() |
|
892 | - { |
|
893 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
894 | - // load some final core systems |
|
895 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
896 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
897 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
898 | - add_action('init', array($this, 'load_controllers'), 7); |
|
899 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
900 | - add_action('init', array($this, 'initialize'), 10); |
|
901 | - add_action('init', array($this, 'initialize_last'), 100); |
|
902 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
903 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
904 | - // pew pew pew |
|
905 | - $this->registry->load_core('PUE'); |
|
906 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
907 | - } |
|
908 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - |
|
913 | - /** |
|
914 | - * set_hooks_for_core |
|
915 | - * |
|
916 | - * @access public |
|
917 | - * @return void |
|
918 | - * @throws EE_Error |
|
919 | - */ |
|
920 | - public function set_hooks_for_core() |
|
921 | - { |
|
922 | - $this->_deactivate_incompatible_addons(); |
|
923 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
924 | - //caps need to be initialized on every request so that capability maps are set. |
|
925 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
926 | - $this->registry->CAP->init_caps(); |
|
927 | - } |
|
928 | - |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
933 | - * deactivates any addons considered incompatible with the current version of EE |
|
934 | - */ |
|
935 | - private function _deactivate_incompatible_addons() |
|
936 | - { |
|
937 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
938 | - if ( ! empty($incompatible_addons)) { |
|
939 | - $active_plugins = get_option('active_plugins', array()); |
|
940 | - foreach ($active_plugins as $active_plugin) { |
|
941 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
942 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
943 | - unset($_GET['activate']); |
|
944 | - espresso_deactivate_plugin($active_plugin); |
|
945 | - } |
|
946 | - } |
|
947 | - } |
|
948 | - } |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * perform_activations_upgrades_and_migrations |
|
955 | - * |
|
956 | - * @access public |
|
957 | - * @return void |
|
958 | - */ |
|
959 | - public function perform_activations_upgrades_and_migrations() |
|
960 | - { |
|
961 | - //first check if we had previously attempted to setup EE's directories but failed |
|
962 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
963 | - EEH_Activation::create_upload_directories(); |
|
964 | - } |
|
965 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * load_CPTs_and_session |
|
972 | - * |
|
973 | - * @access public |
|
974 | - * @return void |
|
975 | - */ |
|
976 | - public function load_CPTs_and_session() |
|
977 | - { |
|
978 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
979 | - // register Custom Post Types |
|
980 | - $this->registry->load_core('Register_CPTs'); |
|
981 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - |
|
986 | - /** |
|
987 | - * load_controllers |
|
988 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
989 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
990 | - * time |
|
991 | - * |
|
992 | - * @access public |
|
993 | - * @return void |
|
994 | - */ |
|
995 | - public function load_controllers() |
|
996 | - { |
|
997 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
998 | - // let's get it started |
|
999 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
1000 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1001 | - $this->registry->load_core('Front_Controller'); |
|
1002 | - } else if ( ! EE_FRONT_AJAX) { |
|
1003 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1004 | - EE_Registry::instance()->load_core('Admin'); |
|
1005 | - } |
|
1006 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * core_loaded_and_ready |
|
1013 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1014 | - * |
|
1015 | - * @access public |
|
1016 | - * @return void |
|
1017 | - */ |
|
1018 | - public function core_loaded_and_ready() |
|
1019 | - { |
|
1020 | - $this->registry->load_core('Session'); |
|
1021 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1022 | - // load_espresso_template_tags |
|
1023 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
1024 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
1025 | - } |
|
1026 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1027 | - $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true); |
|
1028 | - } |
|
1029 | - |
|
1030 | - |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * initialize |
|
1034 | - * this is the best place to begin initializing client code |
|
1035 | - * |
|
1036 | - * @access public |
|
1037 | - * @return void |
|
1038 | - */ |
|
1039 | - public function initialize() |
|
1040 | - { |
|
1041 | - do_action('AHEE__EE_System__initialize'); |
|
1042 | - } |
|
1043 | - |
|
1044 | - |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * initialize_last |
|
1048 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1049 | - * initialize has done so |
|
1050 | - * |
|
1051 | - * @access public |
|
1052 | - * @return void |
|
1053 | - */ |
|
1054 | - public function initialize_last() |
|
1055 | - { |
|
1056 | - do_action('AHEE__EE_System__initialize_last'); |
|
1057 | - } |
|
1058 | - |
|
1059 | - |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * set_hooks_for_shortcodes_modules_and_addons |
|
1063 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
1064 | - * this happens at the very beginning of the wp_loaded hook point |
|
1065 | - * |
|
1066 | - * @access public |
|
1067 | - * @return void |
|
1068 | - */ |
|
1069 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
1070 | - { |
|
1071 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
1072 | - } |
|
1073 | - |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * do_not_cache |
|
1078 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1079 | - * |
|
1080 | - * @access public |
|
1081 | - * @return void |
|
1082 | - */ |
|
1083 | - public static function do_not_cache() |
|
1084 | - { |
|
1085 | - // set no cache constants |
|
1086 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
1087 | - define('DONOTCACHEPAGE', true); |
|
1088 | - } |
|
1089 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1090 | - define('DONOTCACHCEOBJECT', true); |
|
1091 | - } |
|
1092 | - if ( ! defined('DONOTCACHEDB')) { |
|
1093 | - define('DONOTCACHEDB', true); |
|
1094 | - } |
|
1095 | - // add no cache headers |
|
1096 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1097 | - // plus a little extra for nginx and Google Chrome |
|
1098 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1099 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1100 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1101 | - } |
|
1102 | - |
|
1103 | - |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * extra_nocache_headers |
|
1107 | - * |
|
1108 | - * @access public |
|
1109 | - * @param $headers |
|
1110 | - * @return array |
|
1111 | - */ |
|
1112 | - public static function extra_nocache_headers($headers) |
|
1113 | - { |
|
1114 | - // for NGINX |
|
1115 | - $headers['X-Accel-Expires'] = 0; |
|
1116 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1117 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1118 | - return $headers; |
|
1119 | - } |
|
1120 | - |
|
1121 | - |
|
1122 | - |
|
1123 | - /** |
|
1124 | - * nocache_headers |
|
1125 | - * |
|
1126 | - * @access public |
|
1127 | - * @return void |
|
1128 | - */ |
|
1129 | - public static function nocache_headers() |
|
1130 | - { |
|
1131 | - nocache_headers(); |
|
1132 | - } |
|
1133 | - |
|
1134 | - |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * espresso_toolbar_items |
|
1138 | - * |
|
1139 | - * @access public |
|
1140 | - * @param WP_Admin_Bar $admin_bar |
|
1141 | - * @return void |
|
1142 | - */ |
|
1143 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1144 | - { |
|
1145 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1146 | - if ( |
|
1147 | - defined('DOING_AJAX') |
|
1148 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1149 | - || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
1150 | - ) { |
|
1151 | - return; |
|
1152 | - } |
|
1153 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1154 | - $menu_class = 'espresso_menu_item_class'; |
|
1155 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1156 | - //because they're only defined in each of their respective constructors |
|
1157 | - //and this might be a frontend request, in which case they aren't available |
|
1158 | - $events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
1159 | - $reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
1160 | - $extensions_admin_url = admin_url('admin.php?page=espresso_packages'); |
|
1161 | - //Top Level |
|
1162 | - $admin_bar->add_menu(array( |
|
1163 | - 'id' => 'espresso-toolbar', |
|
1164 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1165 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1166 | - . '</span>', |
|
1167 | - 'href' => $events_admin_url, |
|
1168 | - 'meta' => array( |
|
1169 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1170 | - 'class' => $menu_class . 'first', |
|
1171 | - ), |
|
1172 | - )); |
|
1173 | - //Events |
|
1174 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1175 | - $admin_bar->add_menu(array( |
|
1176 | - 'id' => 'espresso-toolbar-events', |
|
1177 | - 'parent' => 'espresso-toolbar', |
|
1178 | - 'title' => __('Events', 'event_espresso'), |
|
1179 | - 'href' => $events_admin_url, |
|
1180 | - 'meta' => array( |
|
1181 | - 'title' => __('Events', 'event_espresso'), |
|
1182 | - 'target' => '', |
|
1183 | - 'class' => $menu_class, |
|
1184 | - ), |
|
1185 | - )); |
|
1186 | - } |
|
1187 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1188 | - //Events Add New |
|
1189 | - $admin_bar->add_menu(array( |
|
1190 | - 'id' => 'espresso-toolbar-events-new', |
|
1191 | - 'parent' => 'espresso-toolbar-events', |
|
1192 | - 'title' => __('Add New', 'event_espresso'), |
|
1193 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1194 | - 'meta' => array( |
|
1195 | - 'title' => __('Add New', 'event_espresso'), |
|
1196 | - 'target' => '', |
|
1197 | - 'class' => $menu_class, |
|
1198 | - ), |
|
1199 | - )); |
|
1200 | - } |
|
1201 | - if (is_single() && (get_post_type() === 'espresso_events')) { |
|
1202 | - //Current post |
|
1203 | - global $post; |
|
1204 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1205 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1206 | - ) { |
|
1207 | - //Events Edit Current Event |
|
1208 | - $admin_bar->add_menu(array( |
|
1209 | - 'id' => 'espresso-toolbar-events-edit', |
|
1210 | - 'parent' => 'espresso-toolbar-events', |
|
1211 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1212 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1213 | - $events_admin_url), |
|
1214 | - 'meta' => array( |
|
1215 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1216 | - 'target' => '', |
|
1217 | - 'class' => $menu_class, |
|
1218 | - ), |
|
1219 | - )); |
|
1220 | - } |
|
1221 | - } |
|
1222 | - //Events View |
|
1223 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1224 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1225 | - ) { |
|
1226 | - $admin_bar->add_menu(array( |
|
1227 | - 'id' => 'espresso-toolbar-events-view', |
|
1228 | - 'parent' => 'espresso-toolbar-events', |
|
1229 | - 'title' => __('View', 'event_espresso'), |
|
1230 | - 'href' => $events_admin_url, |
|
1231 | - 'meta' => array( |
|
1232 | - 'title' => __('View', 'event_espresso'), |
|
1233 | - 'target' => '', |
|
1234 | - 'class' => $menu_class, |
|
1235 | - ), |
|
1236 | - )); |
|
1237 | - } |
|
1238 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1239 | - //Events View All |
|
1240 | - $admin_bar->add_menu(array( |
|
1241 | - 'id' => 'espresso-toolbar-events-all', |
|
1242 | - 'parent' => 'espresso-toolbar-events-view', |
|
1243 | - 'title' => __('All', 'event_espresso'), |
|
1244 | - 'href' => $events_admin_url, |
|
1245 | - 'meta' => array( |
|
1246 | - 'title' => __('All', 'event_espresso'), |
|
1247 | - 'target' => '', |
|
1248 | - 'class' => $menu_class, |
|
1249 | - ), |
|
1250 | - )); |
|
1251 | - } |
|
1252 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1253 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1254 | - ) { |
|
1255 | - //Events View Today |
|
1256 | - $admin_bar->add_menu(array( |
|
1257 | - 'id' => 'espresso-toolbar-events-today', |
|
1258 | - 'parent' => 'espresso-toolbar-events-view', |
|
1259 | - 'title' => __('Today', 'event_espresso'), |
|
1260 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1261 | - $events_admin_url), |
|
1262 | - 'meta' => array( |
|
1263 | - 'title' => __('Today', 'event_espresso'), |
|
1264 | - 'target' => '', |
|
1265 | - 'class' => $menu_class, |
|
1266 | - ), |
|
1267 | - )); |
|
1268 | - } |
|
1269 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1270 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1271 | - ) { |
|
1272 | - //Events View This Month |
|
1273 | - $admin_bar->add_menu(array( |
|
1274 | - 'id' => 'espresso-toolbar-events-month', |
|
1275 | - 'parent' => 'espresso-toolbar-events-view', |
|
1276 | - 'title' => __('This Month', 'event_espresso'), |
|
1277 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1278 | - $events_admin_url), |
|
1279 | - 'meta' => array( |
|
1280 | - 'title' => __('This Month', 'event_espresso'), |
|
1281 | - 'target' => '', |
|
1282 | - 'class' => $menu_class, |
|
1283 | - ), |
|
1284 | - )); |
|
1285 | - } |
|
1286 | - //Registration Overview |
|
1287 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1288 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1289 | - ) { |
|
1290 | - $admin_bar->add_menu(array( |
|
1291 | - 'id' => 'espresso-toolbar-registrations', |
|
1292 | - 'parent' => 'espresso-toolbar', |
|
1293 | - 'title' => __('Registrations', 'event_espresso'), |
|
1294 | - 'href' => $reg_admin_url, |
|
1295 | - 'meta' => array( |
|
1296 | - 'title' => __('Registrations', 'event_espresso'), |
|
1297 | - 'target' => '', |
|
1298 | - 'class' => $menu_class, |
|
1299 | - ), |
|
1300 | - )); |
|
1301 | - } |
|
1302 | - //Registration Overview Today |
|
1303 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1304 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1305 | - ) { |
|
1306 | - $admin_bar->add_menu(array( |
|
1307 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1308 | - 'parent' => 'espresso-toolbar-registrations', |
|
1309 | - 'title' => __('Today', 'event_espresso'), |
|
1310 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1311 | - $reg_admin_url), |
|
1312 | - 'meta' => array( |
|
1313 | - 'title' => __('Today', 'event_espresso'), |
|
1314 | - 'target' => '', |
|
1315 | - 'class' => $menu_class, |
|
1316 | - ), |
|
1317 | - )); |
|
1318 | - } |
|
1319 | - //Registration Overview Today Completed |
|
1320 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1321 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1322 | - ) { |
|
1323 | - $admin_bar->add_menu(array( |
|
1324 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1325 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1326 | - 'title' => __('Approved', 'event_espresso'), |
|
1327 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1328 | - 'action' => 'default', |
|
1329 | - 'status' => 'today', |
|
1330 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1331 | - ), $reg_admin_url), |
|
1332 | - 'meta' => array( |
|
1333 | - 'title' => __('Approved', 'event_espresso'), |
|
1334 | - 'target' => '', |
|
1335 | - 'class' => $menu_class, |
|
1336 | - ), |
|
1337 | - )); |
|
1338 | - } |
|
1339 | - //Registration Overview Today Pending\ |
|
1340 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1341 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1342 | - ) { |
|
1343 | - $admin_bar->add_menu(array( |
|
1344 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1345 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1346 | - 'title' => __('Pending', 'event_espresso'), |
|
1347 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1348 | - 'action' => 'default', |
|
1349 | - 'status' => 'today', |
|
1350 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1351 | - ), $reg_admin_url), |
|
1352 | - 'meta' => array( |
|
1353 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1354 | - 'target' => '', |
|
1355 | - 'class' => $menu_class, |
|
1356 | - ), |
|
1357 | - )); |
|
1358 | - } |
|
1359 | - //Registration Overview Today Incomplete |
|
1360 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1361 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1362 | - ) { |
|
1363 | - $admin_bar->add_menu(array( |
|
1364 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1365 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1366 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1367 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1368 | - 'action' => 'default', |
|
1369 | - 'status' => 'today', |
|
1370 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1371 | - ), $reg_admin_url), |
|
1372 | - 'meta' => array( |
|
1373 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1374 | - 'target' => '', |
|
1375 | - 'class' => $menu_class, |
|
1376 | - ), |
|
1377 | - )); |
|
1378 | - } |
|
1379 | - //Registration Overview Today Incomplete |
|
1380 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1381 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1382 | - ) { |
|
1383 | - $admin_bar->add_menu(array( |
|
1384 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1385 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1386 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1387 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1388 | - 'action' => 'default', |
|
1389 | - 'status' => 'today', |
|
1390 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1391 | - ), $reg_admin_url), |
|
1392 | - 'meta' => array( |
|
1393 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1394 | - 'target' => '', |
|
1395 | - 'class' => $menu_class, |
|
1396 | - ), |
|
1397 | - )); |
|
1398 | - } |
|
1399 | - //Registration Overview This Month |
|
1400 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1401 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1402 | - ) { |
|
1403 | - $admin_bar->add_menu(array( |
|
1404 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1405 | - 'parent' => 'espresso-toolbar-registrations', |
|
1406 | - 'title' => __('This Month', 'event_espresso'), |
|
1407 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1408 | - $reg_admin_url), |
|
1409 | - 'meta' => array( |
|
1410 | - 'title' => __('This Month', 'event_espresso'), |
|
1411 | - 'target' => '', |
|
1412 | - 'class' => $menu_class, |
|
1413 | - ), |
|
1414 | - )); |
|
1415 | - } |
|
1416 | - //Registration Overview This Month Approved |
|
1417 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1418 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1419 | - ) { |
|
1420 | - $admin_bar->add_menu(array( |
|
1421 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1422 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1423 | - 'title' => __('Approved', 'event_espresso'), |
|
1424 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1425 | - 'action' => 'default', |
|
1426 | - 'status' => 'month', |
|
1427 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1428 | - ), $reg_admin_url), |
|
1429 | - 'meta' => array( |
|
1430 | - 'title' => __('Approved', 'event_espresso'), |
|
1431 | - 'target' => '', |
|
1432 | - 'class' => $menu_class, |
|
1433 | - ), |
|
1434 | - )); |
|
1435 | - } |
|
1436 | - //Registration Overview This Month Pending |
|
1437 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1438 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1439 | - ) { |
|
1440 | - $admin_bar->add_menu(array( |
|
1441 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1442 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1443 | - 'title' => __('Pending', 'event_espresso'), |
|
1444 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1445 | - 'action' => 'default', |
|
1446 | - 'status' => 'month', |
|
1447 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1448 | - ), $reg_admin_url), |
|
1449 | - 'meta' => array( |
|
1450 | - 'title' => __('Pending', 'event_espresso'), |
|
1451 | - 'target' => '', |
|
1452 | - 'class' => $menu_class, |
|
1453 | - ), |
|
1454 | - )); |
|
1455 | - } |
|
1456 | - //Registration Overview This Month Not Approved |
|
1457 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1458 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1459 | - ) { |
|
1460 | - $admin_bar->add_menu(array( |
|
1461 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1462 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1463 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1464 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1465 | - 'action' => 'default', |
|
1466 | - 'status' => 'month', |
|
1467 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1468 | - ), $reg_admin_url), |
|
1469 | - 'meta' => array( |
|
1470 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1471 | - 'target' => '', |
|
1472 | - 'class' => $menu_class, |
|
1473 | - ), |
|
1474 | - )); |
|
1475 | - } |
|
1476 | - //Registration Overview This Month Cancelled |
|
1477 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1478 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1479 | - ) { |
|
1480 | - $admin_bar->add_menu(array( |
|
1481 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1482 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1483 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1484 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1485 | - 'action' => 'default', |
|
1486 | - 'status' => 'month', |
|
1487 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1488 | - ), $reg_admin_url), |
|
1489 | - 'meta' => array( |
|
1490 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1491 | - 'target' => '', |
|
1492 | - 'class' => $menu_class, |
|
1493 | - ), |
|
1494 | - )); |
|
1495 | - } |
|
1496 | - //Extensions & Services |
|
1497 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1498 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1499 | - ) { |
|
1500 | - $admin_bar->add_menu(array( |
|
1501 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1502 | - 'parent' => 'espresso-toolbar', |
|
1503 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1504 | - 'href' => $extensions_admin_url, |
|
1505 | - 'meta' => array( |
|
1506 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1507 | - 'target' => '', |
|
1508 | - 'class' => $menu_class, |
|
1509 | - ), |
|
1510 | - )); |
|
1511 | - } |
|
1512 | - } |
|
1513 | - |
|
1514 | - |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1518 | - * never returned with the function. |
|
1519 | - * |
|
1520 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1521 | - * @return array |
|
1522 | - */ |
|
1523 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1524 | - { |
|
1525 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1526 | - } |
|
27 | + /** |
|
28 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
29 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
30 | + */ |
|
31 | + const req_type_normal = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * Indicates this is a brand new installation of EE so we should install |
|
35 | + * tables and default data etc |
|
36 | + */ |
|
37 | + const req_type_new_activation = 1; |
|
38 | + |
|
39 | + /** |
|
40 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
41 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
42 | + * and that default data is setup too |
|
43 | + */ |
|
44 | + const req_type_reactivation = 2; |
|
45 | + |
|
46 | + /** |
|
47 | + * indicates that EE has been upgraded since its previous request. |
|
48 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
49 | + */ |
|
50 | + const req_type_upgrade = 3; |
|
51 | + |
|
52 | + /** |
|
53 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
54 | + */ |
|
55 | + const req_type_downgrade = 4; |
|
56 | + |
|
57 | + /** |
|
58 | + * @deprecated since version 4.6.0.dev.006 |
|
59 | + * Now whenever a new_activation is detected the request type is still just |
|
60 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
61 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
62 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
63 | + * (Specifically, when the migration manager indicates migrations are finished |
|
64 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
65 | + */ |
|
66 | + const req_type_activation_but_not_installed = 5; |
|
67 | + |
|
68 | + /** |
|
69 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
70 | + */ |
|
71 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @var EE_System $_instance |
|
76 | + */ |
|
77 | + private static $_instance; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var EE_Registry $registry |
|
81 | + */ |
|
82 | + protected $registry; |
|
83 | + |
|
84 | + /** |
|
85 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
86 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
87 | + * |
|
88 | + * @var int $_req_type |
|
89 | + */ |
|
90 | + private $_req_type; |
|
91 | + |
|
92 | + /** |
|
93 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
94 | + * |
|
95 | + * @var boolean $_major_version_change |
|
96 | + */ |
|
97 | + private $_major_version_change = false; |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @singleton method used to instantiate class object |
|
103 | + * @access public |
|
104 | + * @param EE_Registry $Registry |
|
105 | + * @return EE_System |
|
106 | + */ |
|
107 | + public static function instance(EE_Registry $Registry = null) |
|
108 | + { |
|
109 | + // check if class object is instantiated |
|
110 | + if ( ! self::$_instance instanceof EE_System) { |
|
111 | + self::$_instance = new self($Registry); |
|
112 | + } |
|
113 | + return self::$_instance; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * resets the instance and returns it |
|
120 | + * |
|
121 | + * @return EE_System |
|
122 | + */ |
|
123 | + public static function reset() |
|
124 | + { |
|
125 | + self::$_instance->_req_type = null; |
|
126 | + //make sure none of the old hooks are left hanging around |
|
127 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
128 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
129 | + EE_Data_Migration_Manager::reset(); |
|
130 | + self::instance()->detect_activations_or_upgrades(); |
|
131 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
132 | + return self::instance(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * sets hooks for running rest of system |
|
139 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
140 | + * starting EE Addons from any other point may lead to problems |
|
141 | + * |
|
142 | + * @access private |
|
143 | + * @param EE_Registry $Registry |
|
144 | + */ |
|
145 | + private function __construct(EE_Registry $Registry) |
|
146 | + { |
|
147 | + $this->registry = $Registry; |
|
148 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
149 | + add_action( |
|
150 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
151 | + array($this, 'loadCapabilities'), |
|
152 | + 5 |
|
153 | + ); |
|
154 | + add_action( |
|
155 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
156 | + array($this, 'loadCommandBus'), |
|
157 | + 7 |
|
158 | + ); |
|
159 | + add_action( |
|
160 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
161 | + array($this, 'loadPluginApi'), |
|
162 | + 9 |
|
163 | + ); |
|
164 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
165 | + add_action( |
|
166 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
167 | + array($this, 'load_espresso_addons') |
|
168 | + ); |
|
169 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
170 | + // because the newly-activated addon didn't get a chance to run at all |
|
171 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
172 | + // detect whether install or upgrade |
|
173 | + add_action( |
|
174 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
175 | + array($this, 'detect_activations_or_upgrades'), |
|
176 | + 3 |
|
177 | + ); |
|
178 | + // load EE_Config, EE_Textdomain, etc |
|
179 | + add_action( |
|
180 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
181 | + array($this, 'load_core_configuration'), |
|
182 | + 5 |
|
183 | + ); |
|
184 | + // load EE_Config, EE_Textdomain, etc |
|
185 | + add_action( |
|
186 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
187 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
188 | + 7 |
|
189 | + ); |
|
190 | + // you wanna get going? I wanna get going... let's get going! |
|
191 | + add_action( |
|
192 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
193 | + array($this, 'brew_espresso'), |
|
194 | + 9 |
|
195 | + ); |
|
196 | + //other housekeeping |
|
197 | + //exclude EE critical pages from wp_list_pages |
|
198 | + add_filter( |
|
199 | + 'wp_list_pages_excludes', |
|
200 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
201 | + 10 |
|
202 | + ); |
|
203 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
204 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
205 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * load and setup EE_Capabilities |
|
212 | + * |
|
213 | + * @return void |
|
214 | + * @throws EE_Error |
|
215 | + */ |
|
216 | + public function loadCapabilities() |
|
217 | + { |
|
218 | + $this->registry->load_core('EE_Capabilities'); |
|
219 | + add_action( |
|
220 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
221 | + function() { |
|
222 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
223 | + } |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * create and cache the CommandBus, and also add middleware |
|
231 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
232 | + * which is why we need to load the CommandBus after Caps are set up |
|
233 | + * |
|
234 | + * @return void |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + public function loadCommandBus() |
|
238 | + { |
|
239 | + $this->registry->create( |
|
240 | + 'CommandBusInterface', |
|
241 | + array( |
|
242 | + null, |
|
243 | + apply_filters( |
|
244 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
245 | + array( |
|
246 | + $this->registry->create('CapChecker'), |
|
247 | + $this->registry->create('AddActionHook'), |
|
248 | + ) |
|
249 | + ), |
|
250 | + ), |
|
251 | + true |
|
252 | + ); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @return void |
|
259 | + * @throws EE_Error |
|
260 | + */ |
|
261 | + public function loadPluginApi() |
|
262 | + { |
|
263 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
264 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
265 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * load_espresso_addons |
|
272 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
273 | + * this is hooked into both: |
|
274 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
275 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
276 | + * and the WP 'activate_plugin' hook point |
|
277 | + * |
|
278 | + * @access public |
|
279 | + * @return void |
|
280 | + * @throws EE_Error |
|
281 | + */ |
|
282 | + public function load_espresso_addons() |
|
283 | + { |
|
284 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
285 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
286 | + //We want it for mobile apps. Just include the entire plugin |
|
287 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
288 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
289 | + //and causes a fatal error |
|
290 | + if ( |
|
291 | + ! (isset($_GET['activate']) && $_GET['activate'] === 'true') |
|
292 | + && ! function_exists('json_basic_auth_handler') |
|
293 | + && ! function_exists('json_basic_auth_error') |
|
294 | + && ! ( |
|
295 | + isset($_GET['action']) |
|
296 | + && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
297 | + ) |
|
298 | + ) { |
|
299 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
300 | + } |
|
301 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * detect_activations_or_upgrades |
|
308 | + * Checks for activation or upgrade of core first; |
|
309 | + * then also checks if any registered addons have been activated or upgraded |
|
310 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
311 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
312 | + * |
|
313 | + * @access public |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function detect_activations_or_upgrades() |
|
317 | + { |
|
318 | + //first off: let's make sure to handle core |
|
319 | + $this->detect_if_activation_or_upgrade(); |
|
320 | + foreach ($this->registry->addons as $addon) { |
|
321 | + //detect teh request type for that addon |
|
322 | + $addon->detect_activation_or_upgrade(); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * detect_if_activation_or_upgrade |
|
330 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
331 | + * and either setting up the DB or setting up maintenance mode etc. |
|
332 | + * |
|
333 | + * @access public |
|
334 | + * @return void |
|
335 | + */ |
|
336 | + public function detect_if_activation_or_upgrade() |
|
337 | + { |
|
338 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
339 | + // load M-Mode class |
|
340 | + $this->registry->load_core('Maintenance_Mode'); |
|
341 | + // check if db has been updated, or if its a brand-new installation |
|
342 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
343 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
344 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
345 | + switch ($request_type) { |
|
346 | + case EE_System::req_type_new_activation: |
|
347 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
348 | + $this->_handle_core_version_change($espresso_db_update); |
|
349 | + break; |
|
350 | + case EE_System::req_type_reactivation: |
|
351 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
352 | + $this->_handle_core_version_change($espresso_db_update); |
|
353 | + break; |
|
354 | + case EE_System::req_type_upgrade: |
|
355 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
356 | + //migrations may be required now that we've upgraded |
|
357 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
358 | + $this->_handle_core_version_change($espresso_db_update); |
|
359 | + // echo "done upgrade";die; |
|
360 | + break; |
|
361 | + case EE_System::req_type_downgrade: |
|
362 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
363 | + //its possible migrations are no longer required |
|
364 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
365 | + $this->_handle_core_version_change($espresso_db_update); |
|
366 | + break; |
|
367 | + case EE_System::req_type_normal: |
|
368 | + default: |
|
369 | + // $this->_maybe_redirect_to_ee_about(); |
|
370 | + break; |
|
371 | + } |
|
372 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Updates the list of installed versions and sets hooks for |
|
379 | + * initializing the database later during the request |
|
380 | + * |
|
381 | + * @param array $espresso_db_update |
|
382 | + */ |
|
383 | + protected function _handle_core_version_change($espresso_db_update) |
|
384 | + { |
|
385 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
386 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
387 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
388 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
395 | + * information about what versions of EE have been installed and activated, |
|
396 | + * NOT necessarily the state of the database |
|
397 | + * |
|
398 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
399 | + * If not supplied, fetches it from the options table |
|
400 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
401 | + */ |
|
402 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
403 | + { |
|
404 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
405 | + if ( ! $espresso_db_update) { |
|
406 | + $espresso_db_update = get_option('espresso_db_update'); |
|
407 | + } |
|
408 | + // check that option is an array |
|
409 | + if ( ! is_array($espresso_db_update)) { |
|
410 | + // if option is FALSE, then it never existed |
|
411 | + if ($espresso_db_update === false) { |
|
412 | + // make $espresso_db_update an array and save option with autoload OFF |
|
413 | + $espresso_db_update = array(); |
|
414 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
415 | + } else { |
|
416 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
417 | + $espresso_db_update = array($espresso_db_update => array()); |
|
418 | + update_option('espresso_db_update', $espresso_db_update); |
|
419 | + } |
|
420 | + } else { |
|
421 | + $corrected_db_update = array(); |
|
422 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
423 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
424 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
425 | + //the key is an int, and the value IS NOT an array |
|
426 | + //so it must be numerically-indexed, where values are versions installed... |
|
427 | + //fix it! |
|
428 | + $version_string = $should_be_array; |
|
429 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
430 | + } else { |
|
431 | + //ok it checks out |
|
432 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
433 | + } |
|
434 | + } |
|
435 | + $espresso_db_update = $corrected_db_update; |
|
436 | + update_option('espresso_db_update', $espresso_db_update); |
|
437 | + } |
|
438 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
439 | + return $espresso_db_update; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
446 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
447 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
448 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
449 | + * so that it will be done when migrations are finished |
|
450 | + * |
|
451 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
452 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
453 | + * This is a resource-intensive job |
|
454 | + * so we prefer to only do it when necessary |
|
455 | + * @return void |
|
456 | + * @throws EE_Error |
|
457 | + */ |
|
458 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
459 | + { |
|
460 | + $request_type = $this->detect_req_type(); |
|
461 | + //only initialize system if we're not in maintenance mode. |
|
462 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
463 | + update_option('ee_flush_rewrite_rules', true); |
|
464 | + if ($verify_schema) { |
|
465 | + EEH_Activation::initialize_db_and_folders(); |
|
466 | + } |
|
467 | + EEH_Activation::initialize_db_content(); |
|
468 | + EEH_Activation::system_initialization(); |
|
469 | + if ($initialize_addons_too) { |
|
470 | + $this->initialize_addons(); |
|
471 | + } |
|
472 | + } else { |
|
473 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
474 | + } |
|
475 | + if ($request_type === EE_System::req_type_new_activation |
|
476 | + || $request_type === EE_System::req_type_reactivation |
|
477 | + || ( |
|
478 | + $request_type === EE_System::req_type_upgrade |
|
479 | + && $this->is_major_version_change() |
|
480 | + ) |
|
481 | + ) { |
|
482 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
483 | + } |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * Initializes the db for all registered addons |
|
490 | + * |
|
491 | + * @throws EE_Error |
|
492 | + */ |
|
493 | + public function initialize_addons() |
|
494 | + { |
|
495 | + //foreach registered addon, make sure its db is up-to-date too |
|
496 | + foreach ($this->registry->addons as $addon) { |
|
497 | + $addon->initialize_db_if_no_migrations_required(); |
|
498 | + } |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
505 | + * |
|
506 | + * @param array $version_history |
|
507 | + * @param string $current_version_to_add version to be added to the version history |
|
508 | + * @return boolean success as to whether or not this option was changed |
|
509 | + */ |
|
510 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
511 | + { |
|
512 | + if ( ! $version_history) { |
|
513 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
514 | + } |
|
515 | + if ($current_version_to_add === null) { |
|
516 | + $current_version_to_add = espresso_version(); |
|
517 | + } |
|
518 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
519 | + // re-save |
|
520 | + return update_option('espresso_db_update', $version_history); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * Detects if the current version indicated in the has existed in the list of |
|
527 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
528 | + * |
|
529 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
530 | + * If not supplied, fetches it from the options table. |
|
531 | + * Also, caches its result so later parts of the code can also know whether |
|
532 | + * there's been an update or not. This way we can add the current version to |
|
533 | + * espresso_db_update, but still know if this is a new install or not |
|
534 | + * @return int one of the constants on EE_System::req_type_ |
|
535 | + */ |
|
536 | + public function detect_req_type($espresso_db_update = null) |
|
537 | + { |
|
538 | + if ($this->_req_type === null) { |
|
539 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
540 | + : $this->fix_espresso_db_upgrade_option(); |
|
541 | + $this->_req_type = EE_System::detect_req_type_given_activation_history($espresso_db_update, |
|
542 | + 'ee_espresso_activation', espresso_version()); |
|
543 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
544 | + } |
|
545 | + return $this->_req_type; |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
552 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
553 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
554 | + * |
|
555 | + * @param $activation_history |
|
556 | + * @return bool |
|
557 | + */ |
|
558 | + protected function _detect_major_version_change($activation_history) |
|
559 | + { |
|
560 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
561 | + $previous_version_parts = explode('.', $previous_version); |
|
562 | + $current_version_parts = explode('.', espresso_version()); |
|
563 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
564 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
565 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
566 | + ); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Returns true if either the major or minor version of EE changed during this request. |
|
573 | + * 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 |
|
574 | + * |
|
575 | + * @return bool |
|
576 | + */ |
|
577 | + public function is_major_version_change() |
|
578 | + { |
|
579 | + return $this->_major_version_change; |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
586 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
587 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
588 | + * just activated to (for core that will always be espresso_version()) |
|
589 | + * |
|
590 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
591 | + * ee plugin. for core that's 'espresso_db_update' |
|
592 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
593 | + * indicate that this plugin was just activated |
|
594 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
595 | + * espresso_version()) |
|
596 | + * @return int one of the constants on EE_System::req_type_* |
|
597 | + */ |
|
598 | + public static function detect_req_type_given_activation_history( |
|
599 | + $activation_history_for_addon, |
|
600 | + $activation_indicator_option_name, |
|
601 | + $version_to_upgrade_to |
|
602 | + ) { |
|
603 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
604 | + if ($activation_history_for_addon) { |
|
605 | + //it exists, so this isn't a completely new install |
|
606 | + //check if this version already in that list of previously installed versions |
|
607 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
608 | + //it a version we haven't seen before |
|
609 | + if ($version_is_higher === 1) { |
|
610 | + $req_type = EE_System::req_type_upgrade; |
|
611 | + } else { |
|
612 | + $req_type = EE_System::req_type_downgrade; |
|
613 | + } |
|
614 | + delete_option($activation_indicator_option_name); |
|
615 | + } else { |
|
616 | + // its not an update. maybe a reactivation? |
|
617 | + if (get_option($activation_indicator_option_name, false)) { |
|
618 | + if ($version_is_higher === -1) { |
|
619 | + $req_type = EE_System::req_type_downgrade; |
|
620 | + } elseif ($version_is_higher === 0) { |
|
621 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
622 | + $req_type = EE_System::req_type_reactivation; |
|
623 | + } else {//$version_is_higher === 1 |
|
624 | + $req_type = EE_System::req_type_upgrade; |
|
625 | + } |
|
626 | + delete_option($activation_indicator_option_name); |
|
627 | + } else { |
|
628 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
629 | + if ($version_is_higher === -1) { |
|
630 | + $req_type = EE_System::req_type_downgrade; |
|
631 | + } elseif ($version_is_higher === 0) { |
|
632 | + //we've seen this version before and it's not an activation. its normal request |
|
633 | + $req_type = EE_System::req_type_normal; |
|
634 | + } else {//$version_is_higher === 1 |
|
635 | + $req_type = EE_System::req_type_upgrade; |
|
636 | + } |
|
637 | + } |
|
638 | + } |
|
639 | + } else { |
|
640 | + //brand new install |
|
641 | + $req_type = EE_System::req_type_new_activation; |
|
642 | + delete_option($activation_indicator_option_name); |
|
643 | + } |
|
644 | + return $req_type; |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
651 | + * the $activation_history_for_addon |
|
652 | + * |
|
653 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
654 | + * sometimes containing 'unknown-date' |
|
655 | + * @param string $version_to_upgrade_to (current version) |
|
656 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
657 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
658 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
659 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
660 | + */ |
|
661 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
662 | + { |
|
663 | + //find the most recently-activated version |
|
664 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
665 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * Gets the most recently active version listed in the activation history, |
|
672 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
673 | + * |
|
674 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
675 | + * sometimes containing 'unknown-date' |
|
676 | + * @return string |
|
677 | + */ |
|
678 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
679 | + { |
|
680 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
681 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
682 | + if (is_array($activation_history)) { |
|
683 | + foreach ($activation_history as $version => $times_activated) { |
|
684 | + //check there is a record of when this version was activated. Otherwise, |
|
685 | + //mark it as unknown |
|
686 | + if ( ! $times_activated) { |
|
687 | + $times_activated = array('unknown-date'); |
|
688 | + } |
|
689 | + if (is_string($times_activated)) { |
|
690 | + $times_activated = array($times_activated); |
|
691 | + } |
|
692 | + foreach ($times_activated as $an_activation) { |
|
693 | + if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
694 | + $most_recently_active_version = $version; |
|
695 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
696 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
697 | + } |
|
698 | + } |
|
699 | + } |
|
700 | + } |
|
701 | + return $most_recently_active_version; |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * This redirects to the about EE page after activation |
|
708 | + * |
|
709 | + * @return void |
|
710 | + */ |
|
711 | + public function redirect_to_about_ee() |
|
712 | + { |
|
713 | + $notices = EE_Error::get_notices(false); |
|
714 | + //if current user is an admin and it's not an ajax or rest request |
|
715 | + if ( |
|
716 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
717 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
718 | + && ! isset($notices['errors']) |
|
719 | + && apply_filters( |
|
720 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
721 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
722 | + ) |
|
723 | + ) { |
|
724 | + $query_params = array('page' => 'espresso_about'); |
|
725 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
726 | + $query_params['new_activation'] = true; |
|
727 | + } |
|
728 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
729 | + $query_params['reactivation'] = true; |
|
730 | + } |
|
731 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
732 | + wp_safe_redirect($url); |
|
733 | + exit(); |
|
734 | + } |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * load_core_configuration |
|
741 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
742 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
743 | + * |
|
744 | + * @return void |
|
745 | + * @throws \ReflectionException |
|
746 | + */ |
|
747 | + public function load_core_configuration() |
|
748 | + { |
|
749 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
750 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
751 | + //load textdomain |
|
752 | + EE_Load_Textdomain::load_textdomain(); |
|
753 | + // load and setup EE_Config and EE_Network_Config |
|
754 | + $this->registry->load_core('Config'); |
|
755 | + $this->registry->load_core('Network_Config'); |
|
756 | + // setup autoloaders |
|
757 | + // enable logging? |
|
758 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
759 | + $this->registry->load_core('Log'); |
|
760 | + } |
|
761 | + // check for activation errors |
|
762 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
763 | + if ($activation_errors) { |
|
764 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
765 | + update_option('ee_plugin_activation_errors', false); |
|
766 | + } |
|
767 | + // get model names |
|
768 | + $this->_parse_model_names(); |
|
769 | + //load caf stuff a chance to play during the activation process too. |
|
770 | + $this->_maybe_brew_regular(); |
|
771 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + |
|
776 | + /** |
|
777 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
778 | + * |
|
779 | + * @return void |
|
780 | + * @throws ReflectionException |
|
781 | + */ |
|
782 | + private function _parse_model_names() |
|
783 | + { |
|
784 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
785 | + $models = glob(EE_MODELS . '*.model.php'); |
|
786 | + $model_names = array(); |
|
787 | + $non_abstract_db_models = array(); |
|
788 | + foreach ($models as $model) { |
|
789 | + // get model classname |
|
790 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
791 | + $short_name = str_replace('EEM_', '', $classname); |
|
792 | + $reflectionClass = new ReflectionClass($classname); |
|
793 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
794 | + $non_abstract_db_models[$short_name] = $classname; |
|
795 | + } |
|
796 | + $model_names[$short_name] = $classname; |
|
797 | + } |
|
798 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
799 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
800 | + $non_abstract_db_models); |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
807 | + * that need to be setup before our EE_System launches. |
|
808 | + * |
|
809 | + * @return void |
|
810 | + */ |
|
811 | + private function _maybe_brew_regular() |
|
812 | + { |
|
813 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
814 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
815 | + } |
|
816 | + } |
|
817 | + |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * register_shortcodes_modules_and_widgets |
|
822 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
823 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
824 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
825 | + * |
|
826 | + * @access public |
|
827 | + * @return void |
|
828 | + */ |
|
829 | + public function register_shortcodes_modules_and_widgets() |
|
830 | + { |
|
831 | + try { |
|
832 | + // load, register, and add shortcodes the new way |
|
833 | + LoaderFactory::getLoader()->getShared( |
|
834 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
835 | + array( |
|
836 | + // and the old way, but we'll put it under control of the new system |
|
837 | + EE_Config::getLegacyShortcodesManager() |
|
838 | + ) |
|
839 | + ); |
|
840 | + } catch (Exception $exception) { |
|
841 | + new ExceptionStackTraceDisplay($exception); |
|
842 | + } |
|
843 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
844 | + // check for addons using old hook point |
|
845 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
846 | + $this->_incompatible_addon_error(); |
|
847 | + } |
|
848 | + } |
|
849 | + |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * _incompatible_addon_error |
|
854 | + * |
|
855 | + * @access public |
|
856 | + * @return void |
|
857 | + */ |
|
858 | + private function _incompatible_addon_error() |
|
859 | + { |
|
860 | + // get array of classes hooking into here |
|
861 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
862 | + if ( ! empty($class_names)) { |
|
863 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
864 | + 'event_espresso'); |
|
865 | + $msg .= '<ul>'; |
|
866 | + foreach ($class_names as $class_name) { |
|
867 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
868 | + $class_name) . '</b></li>'; |
|
869 | + } |
|
870 | + $msg .= '</ul>'; |
|
871 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
872 | + 'event_espresso'); |
|
873 | + // save list of incompatible addons to wp-options for later use |
|
874 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
875 | + if (is_admin()) { |
|
876 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
877 | + } |
|
878 | + } |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + |
|
883 | + /** |
|
884 | + * brew_espresso |
|
885 | + * begins the process of setting hooks for initializing EE in the correct order |
|
886 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
887 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
888 | + * |
|
889 | + * @return void |
|
890 | + */ |
|
891 | + public function brew_espresso() |
|
892 | + { |
|
893 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
894 | + // load some final core systems |
|
895 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
896 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
897 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
898 | + add_action('init', array($this, 'load_controllers'), 7); |
|
899 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
900 | + add_action('init', array($this, 'initialize'), 10); |
|
901 | + add_action('init', array($this, 'initialize_last'), 100); |
|
902 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
903 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
904 | + // pew pew pew |
|
905 | + $this->registry->load_core('PUE'); |
|
906 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
907 | + } |
|
908 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + |
|
913 | + /** |
|
914 | + * set_hooks_for_core |
|
915 | + * |
|
916 | + * @access public |
|
917 | + * @return void |
|
918 | + * @throws EE_Error |
|
919 | + */ |
|
920 | + public function set_hooks_for_core() |
|
921 | + { |
|
922 | + $this->_deactivate_incompatible_addons(); |
|
923 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
924 | + //caps need to be initialized on every request so that capability maps are set. |
|
925 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
926 | + $this->registry->CAP->init_caps(); |
|
927 | + } |
|
928 | + |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
933 | + * deactivates any addons considered incompatible with the current version of EE |
|
934 | + */ |
|
935 | + private function _deactivate_incompatible_addons() |
|
936 | + { |
|
937 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
938 | + if ( ! empty($incompatible_addons)) { |
|
939 | + $active_plugins = get_option('active_plugins', array()); |
|
940 | + foreach ($active_plugins as $active_plugin) { |
|
941 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
942 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
943 | + unset($_GET['activate']); |
|
944 | + espresso_deactivate_plugin($active_plugin); |
|
945 | + } |
|
946 | + } |
|
947 | + } |
|
948 | + } |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * perform_activations_upgrades_and_migrations |
|
955 | + * |
|
956 | + * @access public |
|
957 | + * @return void |
|
958 | + */ |
|
959 | + public function perform_activations_upgrades_and_migrations() |
|
960 | + { |
|
961 | + //first check if we had previously attempted to setup EE's directories but failed |
|
962 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
963 | + EEH_Activation::create_upload_directories(); |
|
964 | + } |
|
965 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * load_CPTs_and_session |
|
972 | + * |
|
973 | + * @access public |
|
974 | + * @return void |
|
975 | + */ |
|
976 | + public function load_CPTs_and_session() |
|
977 | + { |
|
978 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
979 | + // register Custom Post Types |
|
980 | + $this->registry->load_core('Register_CPTs'); |
|
981 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + |
|
986 | + /** |
|
987 | + * load_controllers |
|
988 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
989 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
990 | + * time |
|
991 | + * |
|
992 | + * @access public |
|
993 | + * @return void |
|
994 | + */ |
|
995 | + public function load_controllers() |
|
996 | + { |
|
997 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
998 | + // let's get it started |
|
999 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
1000 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1001 | + $this->registry->load_core('Front_Controller'); |
|
1002 | + } else if ( ! EE_FRONT_AJAX) { |
|
1003 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1004 | + EE_Registry::instance()->load_core('Admin'); |
|
1005 | + } |
|
1006 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * core_loaded_and_ready |
|
1013 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1014 | + * |
|
1015 | + * @access public |
|
1016 | + * @return void |
|
1017 | + */ |
|
1018 | + public function core_loaded_and_ready() |
|
1019 | + { |
|
1020 | + $this->registry->load_core('Session'); |
|
1021 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1022 | + // load_espresso_template_tags |
|
1023 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
1024 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
1025 | + } |
|
1026 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1027 | + $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true); |
|
1028 | + } |
|
1029 | + |
|
1030 | + |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * initialize |
|
1034 | + * this is the best place to begin initializing client code |
|
1035 | + * |
|
1036 | + * @access public |
|
1037 | + * @return void |
|
1038 | + */ |
|
1039 | + public function initialize() |
|
1040 | + { |
|
1041 | + do_action('AHEE__EE_System__initialize'); |
|
1042 | + } |
|
1043 | + |
|
1044 | + |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * initialize_last |
|
1048 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1049 | + * initialize has done so |
|
1050 | + * |
|
1051 | + * @access public |
|
1052 | + * @return void |
|
1053 | + */ |
|
1054 | + public function initialize_last() |
|
1055 | + { |
|
1056 | + do_action('AHEE__EE_System__initialize_last'); |
|
1057 | + } |
|
1058 | + |
|
1059 | + |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * set_hooks_for_shortcodes_modules_and_addons |
|
1063 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
1064 | + * this happens at the very beginning of the wp_loaded hook point |
|
1065 | + * |
|
1066 | + * @access public |
|
1067 | + * @return void |
|
1068 | + */ |
|
1069 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
1070 | + { |
|
1071 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
1072 | + } |
|
1073 | + |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * do_not_cache |
|
1078 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1079 | + * |
|
1080 | + * @access public |
|
1081 | + * @return void |
|
1082 | + */ |
|
1083 | + public static function do_not_cache() |
|
1084 | + { |
|
1085 | + // set no cache constants |
|
1086 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1087 | + define('DONOTCACHEPAGE', true); |
|
1088 | + } |
|
1089 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1090 | + define('DONOTCACHCEOBJECT', true); |
|
1091 | + } |
|
1092 | + if ( ! defined('DONOTCACHEDB')) { |
|
1093 | + define('DONOTCACHEDB', true); |
|
1094 | + } |
|
1095 | + // add no cache headers |
|
1096 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1097 | + // plus a little extra for nginx and Google Chrome |
|
1098 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1099 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1100 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1101 | + } |
|
1102 | + |
|
1103 | + |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * extra_nocache_headers |
|
1107 | + * |
|
1108 | + * @access public |
|
1109 | + * @param $headers |
|
1110 | + * @return array |
|
1111 | + */ |
|
1112 | + public static function extra_nocache_headers($headers) |
|
1113 | + { |
|
1114 | + // for NGINX |
|
1115 | + $headers['X-Accel-Expires'] = 0; |
|
1116 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1117 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1118 | + return $headers; |
|
1119 | + } |
|
1120 | + |
|
1121 | + |
|
1122 | + |
|
1123 | + /** |
|
1124 | + * nocache_headers |
|
1125 | + * |
|
1126 | + * @access public |
|
1127 | + * @return void |
|
1128 | + */ |
|
1129 | + public static function nocache_headers() |
|
1130 | + { |
|
1131 | + nocache_headers(); |
|
1132 | + } |
|
1133 | + |
|
1134 | + |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * espresso_toolbar_items |
|
1138 | + * |
|
1139 | + * @access public |
|
1140 | + * @param WP_Admin_Bar $admin_bar |
|
1141 | + * @return void |
|
1142 | + */ |
|
1143 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1144 | + { |
|
1145 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1146 | + if ( |
|
1147 | + defined('DOING_AJAX') |
|
1148 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1149 | + || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
1150 | + ) { |
|
1151 | + return; |
|
1152 | + } |
|
1153 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1154 | + $menu_class = 'espresso_menu_item_class'; |
|
1155 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1156 | + //because they're only defined in each of their respective constructors |
|
1157 | + //and this might be a frontend request, in which case they aren't available |
|
1158 | + $events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
1159 | + $reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
1160 | + $extensions_admin_url = admin_url('admin.php?page=espresso_packages'); |
|
1161 | + //Top Level |
|
1162 | + $admin_bar->add_menu(array( |
|
1163 | + 'id' => 'espresso-toolbar', |
|
1164 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1165 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1166 | + . '</span>', |
|
1167 | + 'href' => $events_admin_url, |
|
1168 | + 'meta' => array( |
|
1169 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1170 | + 'class' => $menu_class . 'first', |
|
1171 | + ), |
|
1172 | + )); |
|
1173 | + //Events |
|
1174 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1175 | + $admin_bar->add_menu(array( |
|
1176 | + 'id' => 'espresso-toolbar-events', |
|
1177 | + 'parent' => 'espresso-toolbar', |
|
1178 | + 'title' => __('Events', 'event_espresso'), |
|
1179 | + 'href' => $events_admin_url, |
|
1180 | + 'meta' => array( |
|
1181 | + 'title' => __('Events', 'event_espresso'), |
|
1182 | + 'target' => '', |
|
1183 | + 'class' => $menu_class, |
|
1184 | + ), |
|
1185 | + )); |
|
1186 | + } |
|
1187 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1188 | + //Events Add New |
|
1189 | + $admin_bar->add_menu(array( |
|
1190 | + 'id' => 'espresso-toolbar-events-new', |
|
1191 | + 'parent' => 'espresso-toolbar-events', |
|
1192 | + 'title' => __('Add New', 'event_espresso'), |
|
1193 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1194 | + 'meta' => array( |
|
1195 | + 'title' => __('Add New', 'event_espresso'), |
|
1196 | + 'target' => '', |
|
1197 | + 'class' => $menu_class, |
|
1198 | + ), |
|
1199 | + )); |
|
1200 | + } |
|
1201 | + if (is_single() && (get_post_type() === 'espresso_events')) { |
|
1202 | + //Current post |
|
1203 | + global $post; |
|
1204 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1205 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1206 | + ) { |
|
1207 | + //Events Edit Current Event |
|
1208 | + $admin_bar->add_menu(array( |
|
1209 | + 'id' => 'espresso-toolbar-events-edit', |
|
1210 | + 'parent' => 'espresso-toolbar-events', |
|
1211 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1212 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1213 | + $events_admin_url), |
|
1214 | + 'meta' => array( |
|
1215 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1216 | + 'target' => '', |
|
1217 | + 'class' => $menu_class, |
|
1218 | + ), |
|
1219 | + )); |
|
1220 | + } |
|
1221 | + } |
|
1222 | + //Events View |
|
1223 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1224 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1225 | + ) { |
|
1226 | + $admin_bar->add_menu(array( |
|
1227 | + 'id' => 'espresso-toolbar-events-view', |
|
1228 | + 'parent' => 'espresso-toolbar-events', |
|
1229 | + 'title' => __('View', 'event_espresso'), |
|
1230 | + 'href' => $events_admin_url, |
|
1231 | + 'meta' => array( |
|
1232 | + 'title' => __('View', 'event_espresso'), |
|
1233 | + 'target' => '', |
|
1234 | + 'class' => $menu_class, |
|
1235 | + ), |
|
1236 | + )); |
|
1237 | + } |
|
1238 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1239 | + //Events View All |
|
1240 | + $admin_bar->add_menu(array( |
|
1241 | + 'id' => 'espresso-toolbar-events-all', |
|
1242 | + 'parent' => 'espresso-toolbar-events-view', |
|
1243 | + 'title' => __('All', 'event_espresso'), |
|
1244 | + 'href' => $events_admin_url, |
|
1245 | + 'meta' => array( |
|
1246 | + 'title' => __('All', 'event_espresso'), |
|
1247 | + 'target' => '', |
|
1248 | + 'class' => $menu_class, |
|
1249 | + ), |
|
1250 | + )); |
|
1251 | + } |
|
1252 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1253 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1254 | + ) { |
|
1255 | + //Events View Today |
|
1256 | + $admin_bar->add_menu(array( |
|
1257 | + 'id' => 'espresso-toolbar-events-today', |
|
1258 | + 'parent' => 'espresso-toolbar-events-view', |
|
1259 | + 'title' => __('Today', 'event_espresso'), |
|
1260 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1261 | + $events_admin_url), |
|
1262 | + 'meta' => array( |
|
1263 | + 'title' => __('Today', 'event_espresso'), |
|
1264 | + 'target' => '', |
|
1265 | + 'class' => $menu_class, |
|
1266 | + ), |
|
1267 | + )); |
|
1268 | + } |
|
1269 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1270 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1271 | + ) { |
|
1272 | + //Events View This Month |
|
1273 | + $admin_bar->add_menu(array( |
|
1274 | + 'id' => 'espresso-toolbar-events-month', |
|
1275 | + 'parent' => 'espresso-toolbar-events-view', |
|
1276 | + 'title' => __('This Month', 'event_espresso'), |
|
1277 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1278 | + $events_admin_url), |
|
1279 | + 'meta' => array( |
|
1280 | + 'title' => __('This Month', 'event_espresso'), |
|
1281 | + 'target' => '', |
|
1282 | + 'class' => $menu_class, |
|
1283 | + ), |
|
1284 | + )); |
|
1285 | + } |
|
1286 | + //Registration Overview |
|
1287 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1288 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1289 | + ) { |
|
1290 | + $admin_bar->add_menu(array( |
|
1291 | + 'id' => 'espresso-toolbar-registrations', |
|
1292 | + 'parent' => 'espresso-toolbar', |
|
1293 | + 'title' => __('Registrations', 'event_espresso'), |
|
1294 | + 'href' => $reg_admin_url, |
|
1295 | + 'meta' => array( |
|
1296 | + 'title' => __('Registrations', 'event_espresso'), |
|
1297 | + 'target' => '', |
|
1298 | + 'class' => $menu_class, |
|
1299 | + ), |
|
1300 | + )); |
|
1301 | + } |
|
1302 | + //Registration Overview Today |
|
1303 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1304 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1305 | + ) { |
|
1306 | + $admin_bar->add_menu(array( |
|
1307 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1308 | + 'parent' => 'espresso-toolbar-registrations', |
|
1309 | + 'title' => __('Today', 'event_espresso'), |
|
1310 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1311 | + $reg_admin_url), |
|
1312 | + 'meta' => array( |
|
1313 | + 'title' => __('Today', 'event_espresso'), |
|
1314 | + 'target' => '', |
|
1315 | + 'class' => $menu_class, |
|
1316 | + ), |
|
1317 | + )); |
|
1318 | + } |
|
1319 | + //Registration Overview Today Completed |
|
1320 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1321 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1322 | + ) { |
|
1323 | + $admin_bar->add_menu(array( |
|
1324 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1325 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1326 | + 'title' => __('Approved', 'event_espresso'), |
|
1327 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1328 | + 'action' => 'default', |
|
1329 | + 'status' => 'today', |
|
1330 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1331 | + ), $reg_admin_url), |
|
1332 | + 'meta' => array( |
|
1333 | + 'title' => __('Approved', 'event_espresso'), |
|
1334 | + 'target' => '', |
|
1335 | + 'class' => $menu_class, |
|
1336 | + ), |
|
1337 | + )); |
|
1338 | + } |
|
1339 | + //Registration Overview Today Pending\ |
|
1340 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1341 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1342 | + ) { |
|
1343 | + $admin_bar->add_menu(array( |
|
1344 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1345 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1346 | + 'title' => __('Pending', 'event_espresso'), |
|
1347 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1348 | + 'action' => 'default', |
|
1349 | + 'status' => 'today', |
|
1350 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1351 | + ), $reg_admin_url), |
|
1352 | + 'meta' => array( |
|
1353 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1354 | + 'target' => '', |
|
1355 | + 'class' => $menu_class, |
|
1356 | + ), |
|
1357 | + )); |
|
1358 | + } |
|
1359 | + //Registration Overview Today Incomplete |
|
1360 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1361 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1362 | + ) { |
|
1363 | + $admin_bar->add_menu(array( |
|
1364 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1365 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1366 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1367 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1368 | + 'action' => 'default', |
|
1369 | + 'status' => 'today', |
|
1370 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1371 | + ), $reg_admin_url), |
|
1372 | + 'meta' => array( |
|
1373 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1374 | + 'target' => '', |
|
1375 | + 'class' => $menu_class, |
|
1376 | + ), |
|
1377 | + )); |
|
1378 | + } |
|
1379 | + //Registration Overview Today Incomplete |
|
1380 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1381 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1382 | + ) { |
|
1383 | + $admin_bar->add_menu(array( |
|
1384 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1385 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1386 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1387 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1388 | + 'action' => 'default', |
|
1389 | + 'status' => 'today', |
|
1390 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1391 | + ), $reg_admin_url), |
|
1392 | + 'meta' => array( |
|
1393 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1394 | + 'target' => '', |
|
1395 | + 'class' => $menu_class, |
|
1396 | + ), |
|
1397 | + )); |
|
1398 | + } |
|
1399 | + //Registration Overview This Month |
|
1400 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1401 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1402 | + ) { |
|
1403 | + $admin_bar->add_menu(array( |
|
1404 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1405 | + 'parent' => 'espresso-toolbar-registrations', |
|
1406 | + 'title' => __('This Month', 'event_espresso'), |
|
1407 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1408 | + $reg_admin_url), |
|
1409 | + 'meta' => array( |
|
1410 | + 'title' => __('This Month', 'event_espresso'), |
|
1411 | + 'target' => '', |
|
1412 | + 'class' => $menu_class, |
|
1413 | + ), |
|
1414 | + )); |
|
1415 | + } |
|
1416 | + //Registration Overview This Month Approved |
|
1417 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1418 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1419 | + ) { |
|
1420 | + $admin_bar->add_menu(array( |
|
1421 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1422 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1423 | + 'title' => __('Approved', 'event_espresso'), |
|
1424 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1425 | + 'action' => 'default', |
|
1426 | + 'status' => 'month', |
|
1427 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1428 | + ), $reg_admin_url), |
|
1429 | + 'meta' => array( |
|
1430 | + 'title' => __('Approved', 'event_espresso'), |
|
1431 | + 'target' => '', |
|
1432 | + 'class' => $menu_class, |
|
1433 | + ), |
|
1434 | + )); |
|
1435 | + } |
|
1436 | + //Registration Overview This Month Pending |
|
1437 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1438 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1439 | + ) { |
|
1440 | + $admin_bar->add_menu(array( |
|
1441 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1442 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1443 | + 'title' => __('Pending', 'event_espresso'), |
|
1444 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1445 | + 'action' => 'default', |
|
1446 | + 'status' => 'month', |
|
1447 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1448 | + ), $reg_admin_url), |
|
1449 | + 'meta' => array( |
|
1450 | + 'title' => __('Pending', 'event_espresso'), |
|
1451 | + 'target' => '', |
|
1452 | + 'class' => $menu_class, |
|
1453 | + ), |
|
1454 | + )); |
|
1455 | + } |
|
1456 | + //Registration Overview This Month Not Approved |
|
1457 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1458 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1459 | + ) { |
|
1460 | + $admin_bar->add_menu(array( |
|
1461 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1462 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1463 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1464 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1465 | + 'action' => 'default', |
|
1466 | + 'status' => 'month', |
|
1467 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1468 | + ), $reg_admin_url), |
|
1469 | + 'meta' => array( |
|
1470 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1471 | + 'target' => '', |
|
1472 | + 'class' => $menu_class, |
|
1473 | + ), |
|
1474 | + )); |
|
1475 | + } |
|
1476 | + //Registration Overview This Month Cancelled |
|
1477 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1478 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1479 | + ) { |
|
1480 | + $admin_bar->add_menu(array( |
|
1481 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1482 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1483 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1484 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1485 | + 'action' => 'default', |
|
1486 | + 'status' => 'month', |
|
1487 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1488 | + ), $reg_admin_url), |
|
1489 | + 'meta' => array( |
|
1490 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1491 | + 'target' => '', |
|
1492 | + 'class' => $menu_class, |
|
1493 | + ), |
|
1494 | + )); |
|
1495 | + } |
|
1496 | + //Extensions & Services |
|
1497 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1498 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1499 | + ) { |
|
1500 | + $admin_bar->add_menu(array( |
|
1501 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1502 | + 'parent' => 'espresso-toolbar', |
|
1503 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1504 | + 'href' => $extensions_admin_url, |
|
1505 | + 'meta' => array( |
|
1506 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1507 | + 'target' => '', |
|
1508 | + 'class' => $menu_class, |
|
1509 | + ), |
|
1510 | + )); |
|
1511 | + } |
|
1512 | + } |
|
1513 | + |
|
1514 | + |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1518 | + * never returned with the function. |
|
1519 | + * |
|
1520 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1521 | + * @return array |
|
1522 | + */ |
|
1523 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1524 | + { |
|
1525 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1526 | + } |
|
1527 | 1527 | |
1528 | 1528 | |
1529 | 1529 |