@@ -27,830 +27,830 @@ |
||
27 | 27 | */ |
28 | 28 | class EE_Registration_Processor extends EE_Processor_Base |
29 | 29 | { |
30 | - /** |
|
31 | - * @var EE_Registration_Processor $_instance |
|
32 | - * @access private |
|
33 | - */ |
|
34 | - private static $_instance; |
|
35 | - |
|
36 | - /** |
|
37 | - * initial reg status at the beginning of this request. |
|
38 | - * indexed by registration ID |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected $_old_reg_status = []; |
|
43 | - |
|
44 | - /** |
|
45 | - * reg status at the end of the request after all processing. |
|
46 | - * indexed by registration ID |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $_new_reg_status = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * amounts paid at the end of the request after all processing. |
|
54 | - * indexed by registration ID |
|
55 | - * |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected static $_amount_paid = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * Cache of the reg final price for registrations corresponding to a ticket line item |
|
62 | - * |
|
63 | - * @deprecated |
|
64 | - * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
65 | - */ |
|
66 | - protected $_reg_final_price_per_tkt_line_item; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var RequestInterface $request |
|
70 | - */ |
|
71 | - protected $request; |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @singleton method used to instantiate class object |
|
76 | - * @param RequestInterface|null $request |
|
77 | - * @return EE_Registration_Processor instance |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - */ |
|
82 | - public static function instance(RequestInterface $request = null) |
|
83 | - { |
|
84 | - // check if class object is instantiated |
|
85 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
86 | - if (! $request instanceof RequestInterface) { |
|
87 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
88 | - } |
|
89 | - self::$_instance = new self($request); |
|
90 | - } |
|
91 | - return self::$_instance; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * EE_Registration_Processor constructor. |
|
97 | - * |
|
98 | - * @param RequestInterface $request |
|
99 | - */ |
|
100 | - public function __construct(RequestInterface $request) |
|
101 | - { |
|
102 | - $this->request = $request; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @param int $REG_ID |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function old_reg_status($REG_ID) |
|
111 | - { |
|
112 | - return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @param int $REG_ID |
|
118 | - * @param string $old_reg_status |
|
119 | - */ |
|
120 | - public function set_old_reg_status($REG_ID, $old_reg_status) |
|
121 | - { |
|
122 | - // only set the first time |
|
123 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
124 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @param int $REG_ID |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function new_reg_status($REG_ID) |
|
134 | - { |
|
135 | - return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param int $REG_ID |
|
141 | - * @param string $new_reg_status |
|
142 | - */ |
|
143 | - public function set_new_reg_status($REG_ID, $new_reg_status) |
|
144 | - { |
|
145 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * reg_status_updated |
|
151 | - * |
|
152 | - * @param int $REG_ID |
|
153 | - * @return bool |
|
154 | - */ |
|
155 | - public function reg_status_updated($REG_ID) |
|
156 | - { |
|
157 | - return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param EE_Registration $registration |
|
163 | - * @throws EE_Error |
|
164 | - * @throws EntityNotFoundException |
|
165 | - * @throws InvalidArgumentException |
|
166 | - * @throws InvalidDataTypeException |
|
167 | - * @throws InvalidInterfaceException |
|
168 | - * @throws ReflectionException |
|
169 | - * @throws RuntimeException |
|
170 | - */ |
|
171 | - public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
172 | - { |
|
173 | - $this->toggle_incomplete_registration_status_to_default( |
|
174 | - $registration, |
|
175 | - false, |
|
176 | - new Context( |
|
177 | - __METHOD__, |
|
178 | - esc_html__( |
|
179 | - 'Executed when the registration status is updated during the registration process just prior to triggering notifications.', |
|
180 | - 'event_espresso' |
|
181 | - ) |
|
182 | - ) |
|
183 | - ); |
|
184 | - $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
185 | - $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
186 | - $registration->save(); |
|
187 | - // trigger notifications |
|
188 | - $this->trigger_registration_update_notifications($registration); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * manually_update_registration_status |
|
194 | - * |
|
195 | - * @access public |
|
196 | - * @param EE_Registration $registration |
|
197 | - * @param string $new_reg_status |
|
198 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
199 | - * to client code |
|
200 | - * @return bool |
|
201 | - * @throws EE_Error |
|
202 | - * @throws EntityNotFoundException |
|
203 | - * @throws InvalidArgumentException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - * @throws ReflectionException |
|
207 | - * @throws RuntimeException |
|
208 | - */ |
|
209 | - public function manually_update_registration_status( |
|
210 | - EE_Registration $registration, |
|
211 | - $new_reg_status = '', |
|
212 | - $save = true |
|
213 | - ) { |
|
214 | - // set initial REG_Status |
|
215 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
216 | - // set incoming REG_Status |
|
217 | - $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
218 | - // toggle reg status but only if it has changed and the user can do so |
|
219 | - if ( |
|
220 | - $this->reg_status_updated($registration->ID()) |
|
221 | - && ( |
|
222 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
223 | - || EE_Registry::instance()->CAP->current_user_can( |
|
224 | - 'ee_edit_registration', |
|
225 | - 'toggle_registration_status', |
|
226 | - $registration->ID() |
|
227 | - ) |
|
228 | - ) |
|
229 | - ) { |
|
230 | - // change status to new value |
|
231 | - $updated = $registration->set_status( |
|
232 | - $this->new_reg_status($registration->ID()), |
|
233 | - false, |
|
234 | - new Context( |
|
235 | - __METHOD__, |
|
236 | - esc_html__( |
|
237 | - 'Executed when the registration status is manually updated during the reg process.', |
|
238 | - 'event_espresso' |
|
239 | - ) |
|
240 | - ) |
|
241 | - ); |
|
242 | - if ($updated && $save) { |
|
243 | - $registration->save(); |
|
244 | - } |
|
245 | - return true; |
|
246 | - } |
|
247 | - return false; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * toggle_incomplete_registration_status_to_default |
|
253 | - * changes any incomplete registrations to either the event or global default registration status |
|
254 | - * |
|
255 | - * @access public |
|
256 | - * @param EE_Registration $registration |
|
257 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave |
|
258 | - * that up to client code |
|
259 | - * @param ContextInterface|null $context |
|
260 | - * @return void |
|
261 | - * @throws EE_Error |
|
262 | - * @throws InvalidArgumentException |
|
263 | - * @throws ReflectionException |
|
264 | - * @throws RuntimeException |
|
265 | - * @throws EntityNotFoundException |
|
266 | - * @throws InvalidDataTypeException |
|
267 | - * @throws InvalidInterfaceException |
|
268 | - */ |
|
269 | - public function toggle_incomplete_registration_status_to_default( |
|
270 | - EE_Registration $registration, |
|
271 | - $save = true, |
|
272 | - ?ContextInterface $context = null |
|
273 | - ) { |
|
274 | - $existing_reg_status = $registration->status_ID(); |
|
275 | - // set initial REG_Status |
|
276 | - $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
277 | - // is the registration currently incomplete ? |
|
278 | - if ($registration->status_ID() === RegStatus::INCOMPLETE) { |
|
279 | - // grab default reg status for the event, if set |
|
280 | - $event_default_registration_status = $registration->defaultRegistrationStatus(); |
|
281 | - // if no default reg status is set for the event, then use the global value |
|
282 | - $STS_ID = ! empty($event_default_registration_status) |
|
283 | - ? $event_default_registration_status |
|
284 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
285 | - // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
286 | - $STS_ID = $STS_ID === RegStatus::APPROVED |
|
287 | - ? RegStatus::PENDING_PAYMENT |
|
288 | - : $STS_ID; |
|
289 | - // set incoming REG_Status |
|
290 | - $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
291 | - $context = $context instanceof ContextInterface |
|
292 | - ? $context |
|
293 | - : new Context( |
|
294 | - __METHOD__, |
|
295 | - esc_html__( |
|
296 | - 'Executed when the registration status is updated to the default reg status during the registration process.', |
|
297 | - 'event_espresso' |
|
298 | - ) |
|
299 | - ); |
|
300 | - $registration->set_status($STS_ID, false, $context); |
|
301 | - if ($save) { |
|
302 | - $registration->save(); |
|
303 | - } |
|
304 | - // don't trigger notifications during IPNs because they will get triggered by |
|
305 | - // EventEspresso\core\services\payments\PostPaymentProcessor |
|
306 | - if (! EE_Processor_Base::$IPN) { |
|
307 | - // otherwise, send out notifications |
|
308 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
309 | - } |
|
310 | - // DEBUG LOG |
|
311 | - // $this->log( |
|
312 | - // __CLASS__, |
|
313 | - // __FUNCTION__, |
|
314 | - // __LINE__, |
|
315 | - // $registration->transaction(), |
|
316 | - // array( |
|
317 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
318 | - // 'deliver_notifications' => has_filter( |
|
319 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
320 | - // ), |
|
321 | - // ) |
|
322 | - // ); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * toggle_registration_status_for_default_approved_events |
|
329 | - * |
|
330 | - * @access public |
|
331 | - * @param EE_Registration $registration |
|
332 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
333 | - * to client code |
|
334 | - * @return bool |
|
335 | - * @throws EE_Error |
|
336 | - * @throws EntityNotFoundException |
|
337 | - * @throws InvalidArgumentException |
|
338 | - * @throws InvalidDataTypeException |
|
339 | - * @throws InvalidInterfaceException |
|
340 | - * @throws ReflectionException |
|
341 | - * @throws RuntimeException |
|
342 | - */ |
|
343 | - public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
344 | - { |
|
345 | - $reg_status = $registration->status_ID(); |
|
346 | - // set initial REG_Status |
|
347 | - $this->set_old_reg_status($registration->ID(), $reg_status); |
|
348 | - // if not already, toggle reg status to approved IF the event default reg status is approved |
|
349 | - // ( as long as the registration wasn't cancelled or declined at some point ) |
|
350 | - if ( |
|
351 | - $reg_status !== RegStatus::CANCELLED |
|
352 | - && $reg_status !== RegStatus::DECLINED |
|
353 | - && $reg_status !== RegStatus::APPROVED |
|
354 | - && $registration->defaultRegistrationStatus() === RegStatus::APPROVED |
|
355 | - ) { |
|
356 | - // set incoming REG_Status |
|
357 | - $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
358 | - // toggle status to approved |
|
359 | - $registration->set_status( |
|
360 | - RegStatus::APPROVED, |
|
361 | - false, |
|
362 | - new Context( |
|
363 | - __METHOD__, |
|
364 | - esc_html__( |
|
365 | - 'Executed when the registration status is updated for events with a default reg status of RegStatus::APPROVED.', |
|
366 | - 'event_espresso' |
|
367 | - ) |
|
368 | - ) |
|
369 | - ); |
|
370 | - if ($save) { |
|
371 | - $registration->save(); |
|
372 | - } |
|
373 | - // don't trigger notifications during IPNs because they will get triggered by |
|
374 | - // EventEspresso\core\services\payments\PostPaymentProcessor |
|
375 | - if (! EE_Processor_Base::$IPN) { |
|
376 | - // otherwise, send out notifications |
|
377 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
378 | - } |
|
379 | - // DEBUG LOG |
|
380 | - // $this->log( |
|
381 | - // __CLASS__, |
|
382 | - // __FUNCTION__, |
|
383 | - // __LINE__, |
|
384 | - // $registration->transaction(), |
|
385 | - // array( |
|
386 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
387 | - // 'deliver_notifications' => has_filter( |
|
388 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
389 | - // ), |
|
390 | - // ) |
|
391 | - // ); |
|
392 | - return true; |
|
393 | - } |
|
394 | - return false; |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * toggle_registration_statuses_if_no_monies_owing |
|
400 | - * |
|
401 | - * @access public |
|
402 | - * @param EE_Registration $registration |
|
403 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
404 | - * to client code |
|
405 | - * @param array $additional_details |
|
406 | - * @return bool |
|
407 | - * @throws EE_Error |
|
408 | - * @throws EntityNotFoundException |
|
409 | - * @throws InvalidArgumentException |
|
410 | - * @throws InvalidDataTypeException |
|
411 | - * @throws InvalidInterfaceException |
|
412 | - * @throws ReflectionException |
|
413 | - * @throws RuntimeException |
|
414 | - */ |
|
415 | - public function toggle_registration_status_if_no_monies_owing( |
|
416 | - EE_Registration $registration, |
|
417 | - $save = true, |
|
418 | - array $additional_details = [] |
|
419 | - ) { |
|
420 | - // set initial REG_Status |
|
421 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
422 | - // was a payment just made ? |
|
423 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
424 | - && $additional_details['payment_updates'] |
|
425 | - && $additional_details['last_payment'] instanceof EE_Payment |
|
426 | - ? $additional_details['last_payment'] |
|
427 | - : null; |
|
428 | - $total_paid = array_sum(self::$_amount_paid); |
|
429 | - // toggle reg status to approved IF |
|
430 | - if ( |
|
30 | + /** |
|
31 | + * @var EE_Registration_Processor $_instance |
|
32 | + * @access private |
|
33 | + */ |
|
34 | + private static $_instance; |
|
35 | + |
|
36 | + /** |
|
37 | + * initial reg status at the beginning of this request. |
|
38 | + * indexed by registration ID |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected $_old_reg_status = []; |
|
43 | + |
|
44 | + /** |
|
45 | + * reg status at the end of the request after all processing. |
|
46 | + * indexed by registration ID |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $_new_reg_status = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * amounts paid at the end of the request after all processing. |
|
54 | + * indexed by registration ID |
|
55 | + * |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected static $_amount_paid = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * Cache of the reg final price for registrations corresponding to a ticket line item |
|
62 | + * |
|
63 | + * @deprecated |
|
64 | + * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
65 | + */ |
|
66 | + protected $_reg_final_price_per_tkt_line_item; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var RequestInterface $request |
|
70 | + */ |
|
71 | + protected $request; |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @singleton method used to instantiate class object |
|
76 | + * @param RequestInterface|null $request |
|
77 | + * @return EE_Registration_Processor instance |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + */ |
|
82 | + public static function instance(RequestInterface $request = null) |
|
83 | + { |
|
84 | + // check if class object is instantiated |
|
85 | + if (! self::$_instance instanceof EE_Registration_Processor) { |
|
86 | + if (! $request instanceof RequestInterface) { |
|
87 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
88 | + } |
|
89 | + self::$_instance = new self($request); |
|
90 | + } |
|
91 | + return self::$_instance; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * EE_Registration_Processor constructor. |
|
97 | + * |
|
98 | + * @param RequestInterface $request |
|
99 | + */ |
|
100 | + public function __construct(RequestInterface $request) |
|
101 | + { |
|
102 | + $this->request = $request; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @param int $REG_ID |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function old_reg_status($REG_ID) |
|
111 | + { |
|
112 | + return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @param int $REG_ID |
|
118 | + * @param string $old_reg_status |
|
119 | + */ |
|
120 | + public function set_old_reg_status($REG_ID, $old_reg_status) |
|
121 | + { |
|
122 | + // only set the first time |
|
123 | + if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
124 | + $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @param int $REG_ID |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function new_reg_status($REG_ID) |
|
134 | + { |
|
135 | + return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param int $REG_ID |
|
141 | + * @param string $new_reg_status |
|
142 | + */ |
|
143 | + public function set_new_reg_status($REG_ID, $new_reg_status) |
|
144 | + { |
|
145 | + $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * reg_status_updated |
|
151 | + * |
|
152 | + * @param int $REG_ID |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | + public function reg_status_updated($REG_ID) |
|
156 | + { |
|
157 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param EE_Registration $registration |
|
163 | + * @throws EE_Error |
|
164 | + * @throws EntityNotFoundException |
|
165 | + * @throws InvalidArgumentException |
|
166 | + * @throws InvalidDataTypeException |
|
167 | + * @throws InvalidInterfaceException |
|
168 | + * @throws ReflectionException |
|
169 | + * @throws RuntimeException |
|
170 | + */ |
|
171 | + public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
172 | + { |
|
173 | + $this->toggle_incomplete_registration_status_to_default( |
|
174 | + $registration, |
|
175 | + false, |
|
176 | + new Context( |
|
177 | + __METHOD__, |
|
178 | + esc_html__( |
|
179 | + 'Executed when the registration status is updated during the registration process just prior to triggering notifications.', |
|
180 | + 'event_espresso' |
|
181 | + ) |
|
182 | + ) |
|
183 | + ); |
|
184 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
185 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
186 | + $registration->save(); |
|
187 | + // trigger notifications |
|
188 | + $this->trigger_registration_update_notifications($registration); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * manually_update_registration_status |
|
194 | + * |
|
195 | + * @access public |
|
196 | + * @param EE_Registration $registration |
|
197 | + * @param string $new_reg_status |
|
198 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
199 | + * to client code |
|
200 | + * @return bool |
|
201 | + * @throws EE_Error |
|
202 | + * @throws EntityNotFoundException |
|
203 | + * @throws InvalidArgumentException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + * @throws ReflectionException |
|
207 | + * @throws RuntimeException |
|
208 | + */ |
|
209 | + public function manually_update_registration_status( |
|
210 | + EE_Registration $registration, |
|
211 | + $new_reg_status = '', |
|
212 | + $save = true |
|
213 | + ) { |
|
214 | + // set initial REG_Status |
|
215 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
216 | + // set incoming REG_Status |
|
217 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
218 | + // toggle reg status but only if it has changed and the user can do so |
|
219 | + if ( |
|
220 | + $this->reg_status_updated($registration->ID()) |
|
221 | + && ( |
|
222 | + (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
223 | + || EE_Registry::instance()->CAP->current_user_can( |
|
224 | + 'ee_edit_registration', |
|
225 | + 'toggle_registration_status', |
|
226 | + $registration->ID() |
|
227 | + ) |
|
228 | + ) |
|
229 | + ) { |
|
230 | + // change status to new value |
|
231 | + $updated = $registration->set_status( |
|
232 | + $this->new_reg_status($registration->ID()), |
|
233 | + false, |
|
234 | + new Context( |
|
235 | + __METHOD__, |
|
236 | + esc_html__( |
|
237 | + 'Executed when the registration status is manually updated during the reg process.', |
|
238 | + 'event_espresso' |
|
239 | + ) |
|
240 | + ) |
|
241 | + ); |
|
242 | + if ($updated && $save) { |
|
243 | + $registration->save(); |
|
244 | + } |
|
245 | + return true; |
|
246 | + } |
|
247 | + return false; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * toggle_incomplete_registration_status_to_default |
|
253 | + * changes any incomplete registrations to either the event or global default registration status |
|
254 | + * |
|
255 | + * @access public |
|
256 | + * @param EE_Registration $registration |
|
257 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave |
|
258 | + * that up to client code |
|
259 | + * @param ContextInterface|null $context |
|
260 | + * @return void |
|
261 | + * @throws EE_Error |
|
262 | + * @throws InvalidArgumentException |
|
263 | + * @throws ReflectionException |
|
264 | + * @throws RuntimeException |
|
265 | + * @throws EntityNotFoundException |
|
266 | + * @throws InvalidDataTypeException |
|
267 | + * @throws InvalidInterfaceException |
|
268 | + */ |
|
269 | + public function toggle_incomplete_registration_status_to_default( |
|
270 | + EE_Registration $registration, |
|
271 | + $save = true, |
|
272 | + ?ContextInterface $context = null |
|
273 | + ) { |
|
274 | + $existing_reg_status = $registration->status_ID(); |
|
275 | + // set initial REG_Status |
|
276 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
277 | + // is the registration currently incomplete ? |
|
278 | + if ($registration->status_ID() === RegStatus::INCOMPLETE) { |
|
279 | + // grab default reg status for the event, if set |
|
280 | + $event_default_registration_status = $registration->defaultRegistrationStatus(); |
|
281 | + // if no default reg status is set for the event, then use the global value |
|
282 | + $STS_ID = ! empty($event_default_registration_status) |
|
283 | + ? $event_default_registration_status |
|
284 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
285 | + // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
286 | + $STS_ID = $STS_ID === RegStatus::APPROVED |
|
287 | + ? RegStatus::PENDING_PAYMENT |
|
288 | + : $STS_ID; |
|
289 | + // set incoming REG_Status |
|
290 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
291 | + $context = $context instanceof ContextInterface |
|
292 | + ? $context |
|
293 | + : new Context( |
|
294 | + __METHOD__, |
|
295 | + esc_html__( |
|
296 | + 'Executed when the registration status is updated to the default reg status during the registration process.', |
|
297 | + 'event_espresso' |
|
298 | + ) |
|
299 | + ); |
|
300 | + $registration->set_status($STS_ID, false, $context); |
|
301 | + if ($save) { |
|
302 | + $registration->save(); |
|
303 | + } |
|
304 | + // don't trigger notifications during IPNs because they will get triggered by |
|
305 | + // EventEspresso\core\services\payments\PostPaymentProcessor |
|
306 | + if (! EE_Processor_Base::$IPN) { |
|
307 | + // otherwise, send out notifications |
|
308 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
309 | + } |
|
310 | + // DEBUG LOG |
|
311 | + // $this->log( |
|
312 | + // __CLASS__, |
|
313 | + // __FUNCTION__, |
|
314 | + // __LINE__, |
|
315 | + // $registration->transaction(), |
|
316 | + // array( |
|
317 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
318 | + // 'deliver_notifications' => has_filter( |
|
319 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
320 | + // ), |
|
321 | + // ) |
|
322 | + // ); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * toggle_registration_status_for_default_approved_events |
|
329 | + * |
|
330 | + * @access public |
|
331 | + * @param EE_Registration $registration |
|
332 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
333 | + * to client code |
|
334 | + * @return bool |
|
335 | + * @throws EE_Error |
|
336 | + * @throws EntityNotFoundException |
|
337 | + * @throws InvalidArgumentException |
|
338 | + * @throws InvalidDataTypeException |
|
339 | + * @throws InvalidInterfaceException |
|
340 | + * @throws ReflectionException |
|
341 | + * @throws RuntimeException |
|
342 | + */ |
|
343 | + public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
344 | + { |
|
345 | + $reg_status = $registration->status_ID(); |
|
346 | + // set initial REG_Status |
|
347 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
348 | + // if not already, toggle reg status to approved IF the event default reg status is approved |
|
349 | + // ( as long as the registration wasn't cancelled or declined at some point ) |
|
350 | + if ( |
|
351 | + $reg_status !== RegStatus::CANCELLED |
|
352 | + && $reg_status !== RegStatus::DECLINED |
|
353 | + && $reg_status !== RegStatus::APPROVED |
|
354 | + && $registration->defaultRegistrationStatus() === RegStatus::APPROVED |
|
355 | + ) { |
|
356 | + // set incoming REG_Status |
|
357 | + $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
358 | + // toggle status to approved |
|
359 | + $registration->set_status( |
|
360 | + RegStatus::APPROVED, |
|
361 | + false, |
|
362 | + new Context( |
|
363 | + __METHOD__, |
|
364 | + esc_html__( |
|
365 | + 'Executed when the registration status is updated for events with a default reg status of RegStatus::APPROVED.', |
|
366 | + 'event_espresso' |
|
367 | + ) |
|
368 | + ) |
|
369 | + ); |
|
370 | + if ($save) { |
|
371 | + $registration->save(); |
|
372 | + } |
|
373 | + // don't trigger notifications during IPNs because they will get triggered by |
|
374 | + // EventEspresso\core\services\payments\PostPaymentProcessor |
|
375 | + if (! EE_Processor_Base::$IPN) { |
|
376 | + // otherwise, send out notifications |
|
377 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
378 | + } |
|
379 | + // DEBUG LOG |
|
380 | + // $this->log( |
|
381 | + // __CLASS__, |
|
382 | + // __FUNCTION__, |
|
383 | + // __LINE__, |
|
384 | + // $registration->transaction(), |
|
385 | + // array( |
|
386 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
387 | + // 'deliver_notifications' => has_filter( |
|
388 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
389 | + // ), |
|
390 | + // ) |
|
391 | + // ); |
|
392 | + return true; |
|
393 | + } |
|
394 | + return false; |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * toggle_registration_statuses_if_no_monies_owing |
|
400 | + * |
|
401 | + * @access public |
|
402 | + * @param EE_Registration $registration |
|
403 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
404 | + * to client code |
|
405 | + * @param array $additional_details |
|
406 | + * @return bool |
|
407 | + * @throws EE_Error |
|
408 | + * @throws EntityNotFoundException |
|
409 | + * @throws InvalidArgumentException |
|
410 | + * @throws InvalidDataTypeException |
|
411 | + * @throws InvalidInterfaceException |
|
412 | + * @throws ReflectionException |
|
413 | + * @throws RuntimeException |
|
414 | + */ |
|
415 | + public function toggle_registration_status_if_no_monies_owing( |
|
416 | + EE_Registration $registration, |
|
417 | + $save = true, |
|
418 | + array $additional_details = [] |
|
419 | + ) { |
|
420 | + // set initial REG_Status |
|
421 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
422 | + // was a payment just made ? |
|
423 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
424 | + && $additional_details['payment_updates'] |
|
425 | + && $additional_details['last_payment'] instanceof EE_Payment |
|
426 | + ? $additional_details['last_payment'] |
|
427 | + : null; |
|
428 | + $total_paid = array_sum(self::$_amount_paid); |
|
429 | + // toggle reg status to approved IF |
|
430 | + if ( |
|
431 | 431 | // REG status is pending payment |
432 | - $registration->status_ID() === RegStatus::PENDING_PAYMENT |
|
433 | - // AND no monies are owing |
|
434 | - && ( |
|
435 | - ( |
|
436 | - $registration->transaction()->is_completed() |
|
437 | - || $registration->transaction()->is_overpaid() |
|
438 | - || $registration->transaction()->is_free() |
|
439 | - || apply_filters( |
|
440 | - 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
441 | - false, |
|
442 | - $registration |
|
443 | - ) |
|
444 | - ) |
|
445 | - || ( |
|
446 | - $payment instanceof EE_Payment && $payment->is_approved() |
|
447 | - && // this specific registration has not yet been paid for |
|
448 | - ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
449 | - && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
450 | - $payment->amount() - $total_paid >= $registration->final_price() |
|
451 | - ) |
|
452 | - ) |
|
453 | - ) { |
|
454 | - // mark as paid |
|
455 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
456 | - // track new REG_Status |
|
457 | - $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
458 | - // toggle status to approved |
|
459 | - $registration->set_status( |
|
460 | - RegStatus::APPROVED, |
|
461 | - false, |
|
462 | - new Context( |
|
463 | - __METHOD__, |
|
464 | - esc_html__( |
|
465 | - 'Executed when the registration status is updated to RegStatus::APPROVED when no monies are owing.', |
|
466 | - 'event_espresso' |
|
467 | - ) |
|
468 | - ) |
|
469 | - ); |
|
470 | - if ($save) { |
|
471 | - $registration->save(); |
|
472 | - } |
|
473 | - // don't trigger notifications during IPNs because they will get triggered by |
|
474 | - // EventEspresso\core\services\payments\PostPaymentProcessor |
|
475 | - if (! EE_Processor_Base::$IPN) { |
|
476 | - // otherwise, send out notifications |
|
477 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
478 | - } |
|
479 | - // DEBUG LOG |
|
480 | - // $this->log( |
|
481 | - // __CLASS__, |
|
482 | - // __FUNCTION__, |
|
483 | - // __LINE__, |
|
484 | - // $registration->transaction(), |
|
485 | - // array( |
|
486 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
487 | - // 'deliver_notifications' => has_filter( |
|
488 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
489 | - // ), |
|
490 | - // ) |
|
491 | - // ); |
|
492 | - return true; |
|
493 | - } |
|
494 | - return false; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * registration_status_changed |
|
500 | - * |
|
501 | - * @access public |
|
502 | - * @param EE_Registration $registration |
|
503 | - * @param array $additional_details |
|
504 | - * @return void |
|
505 | - */ |
|
506 | - public function trigger_registration_update_notifications($registration, array $additional_details = []) |
|
507 | - { |
|
508 | - try { |
|
509 | - if (! $registration instanceof EE_Registration) { |
|
510 | - throw new EE_Error( |
|
511 | - esc_html__('An invalid registration was received.', 'event_espresso') |
|
512 | - ); |
|
513 | - } |
|
514 | - // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
515 | - // EEH_Debug_Tools::log( |
|
516 | - // __CLASS__, |
|
517 | - // __FUNCTION__, |
|
518 | - // __LINE__, |
|
519 | - // array($registration->transaction(), $additional_details), |
|
520 | - // false, |
|
521 | - // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
522 | - // ); |
|
523 | - if ( |
|
524 | - ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int') |
|
525 | - && ! $registration->is_primary_registrant() |
|
526 | - ) { |
|
527 | - return; |
|
528 | - } |
|
529 | - do_action( |
|
530 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
531 | - $registration, |
|
532 | - $additional_details |
|
533 | - ); |
|
534 | - } catch (Exception $e) { |
|
535 | - EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
536 | - } |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
542 | - * |
|
543 | - * @param EE_Registration $registration |
|
544 | - * @param array $additional_details |
|
545 | - * @return bool |
|
546 | - * @throws EE_Error |
|
547 | - * @throws EntityNotFoundException |
|
548 | - * @throws InvalidArgumentException |
|
549 | - * @throws InvalidDataTypeException |
|
550 | - * @throws InvalidInterfaceException |
|
551 | - * @throws ReflectionException |
|
552 | - * @throws RuntimeException |
|
553 | - */ |
|
554 | - public function update_registration_after_checkout_or_payment( |
|
555 | - EE_Registration $registration, |
|
556 | - array $additional_details = [] |
|
557 | - ) { |
|
558 | - // set initial REG_Status |
|
559 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
560 | - // if the registration status gets updated, then save the registration |
|
561 | - if ( |
|
562 | - $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
563 | - || $this->toggle_registration_status_if_no_monies_owing( |
|
564 | - $registration, |
|
565 | - false, |
|
566 | - $additional_details |
|
567 | - ) |
|
568 | - ) { |
|
569 | - $registration->save(); |
|
570 | - } |
|
571 | - // set new REG_Status |
|
572 | - $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
573 | - return $this->reg_status_updated($registration->ID()) |
|
574 | - && $this->new_reg_status($registration->ID()) === RegStatus::APPROVED; |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Updates the registration' final prices based on the current line item tree (taking into account |
|
580 | - * discounts, taxes, and other line items unrelated to tickets.) |
|
581 | - * |
|
582 | - * @param EE_Transaction $transaction |
|
583 | - * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
584 | - * @return void |
|
585 | - * @throws EE_Error |
|
586 | - * @throws InvalidArgumentException |
|
587 | - * @throws InvalidDataTypeException |
|
588 | - * @throws InvalidInterfaceException |
|
589 | - * @throws RuntimeException |
|
590 | - * @throws ReflectionException |
|
591 | - */ |
|
592 | - public function update_registration_final_prices($transaction, $save_regs = true) |
|
593 | - { |
|
594 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
595 | - $transaction->total_line_item() |
|
596 | - ); |
|
597 | - foreach ($transaction->registrations() as $registration) { |
|
598 | - /** @var EE_Line_Item $line_item */ |
|
599 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
600 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
601 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
602 | - if ($save_regs) { |
|
603 | - $registration->save(); |
|
604 | - } |
|
605 | - } |
|
606 | - } |
|
607 | - // and make sure there's no rounding problem |
|
608 | - $this->fix_reg_final_price_rounding_issue($transaction); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * Makes sure there is no rounding errors for the REG_final_prices. |
|
614 | - * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
615 | - * they will each be for $0.99333333, which gets rounded to $1 again. |
|
616 | - * So the transaction total will be $2.99, but each registration will be for $1, |
|
617 | - * so if each registrant paid individually they will have overpaid by $0.01. |
|
618 | - * So in order to overcome this, we check for any difference, and if there is a difference |
|
619 | - * we just grab one registrant at random and make them responsible for it. |
|
620 | - * This should be used after setting REG_final_prices (it's done automatically as part of |
|
621 | - * EE_Registration_Processor::update_registration_final_prices()) |
|
622 | - * |
|
623 | - * @param EE_Transaction $transaction |
|
624 | - * @return bool success verifying that there is NO difference after this method is done |
|
625 | - * @throws EE_Error |
|
626 | - * @throws InvalidArgumentException |
|
627 | - * @throws InvalidDataTypeException |
|
628 | - * @throws InvalidInterfaceException |
|
629 | - * @throws ReflectionException |
|
630 | - */ |
|
631 | - public function fix_reg_final_price_rounding_issue($transaction) |
|
632 | - { |
|
633 | - $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
634 | - [ |
|
635 | - [ |
|
636 | - 'TXN_ID' => $transaction->ID(), |
|
637 | - ], |
|
638 | - ], |
|
639 | - 'REG_final_price' |
|
640 | - ); |
|
641 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
642 | - // ok then, just grab one of the registrations |
|
643 | - if ($diff !== 0.0) { |
|
644 | - $a_reg = EEM_Registration::instance()->get_one( |
|
645 | - [ |
|
646 | - [ |
|
647 | - 'TXN_ID' => $transaction->ID(), |
|
648 | - ], |
|
649 | - ] |
|
650 | - ); |
|
651 | - return $a_reg instanceof EE_Registration |
|
652 | - && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
653 | - } |
|
654 | - return true; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * update_registration_after_being_canceled_or_declined |
|
660 | - * |
|
661 | - * @param EE_Registration $registration |
|
662 | - * @param array $closed_reg_statuses |
|
663 | - * @param bool $update_reg |
|
664 | - * @return bool |
|
665 | - * @throws EE_Error |
|
666 | - * @throws RuntimeException |
|
667 | - * @throws ReflectionException |
|
668 | - */ |
|
669 | - public function update_registration_after_being_canceled_or_declined( |
|
670 | - EE_Registration $registration, |
|
671 | - array $closed_reg_statuses = [], |
|
672 | - $update_reg = true |
|
673 | - ) { |
|
674 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
675 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
676 | - ? $closed_reg_statuses |
|
677 | - : EEM_Registration::closed_reg_statuses(); |
|
678 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
679 | - return false; |
|
680 | - } |
|
681 | - // release a reserved ticket by decrementing ticket and datetime reserved values |
|
682 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
683 | - $registration->set_final_price(0); |
|
684 | - if ($update_reg) { |
|
685 | - $registration->save(); |
|
686 | - } |
|
687 | - return true; |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * update_canceled_or_declined_registration_after_being_reinstated |
|
693 | - * |
|
694 | - * @param EE_Registration $registration |
|
695 | - * @param array $closed_reg_statuses |
|
696 | - * @param bool $update_reg |
|
697 | - * @return bool |
|
698 | - * @throws EE_Error |
|
699 | - * @throws RuntimeException |
|
700 | - * @throws ReflectionException |
|
701 | - */ |
|
702 | - public function update_canceled_or_declined_registration_after_being_reinstated( |
|
703 | - EE_Registration $registration, |
|
704 | - array $closed_reg_statuses = [], |
|
705 | - $update_reg = true |
|
706 | - ) { |
|
707 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
708 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
709 | - : EEM_Registration::closed_reg_statuses(); |
|
710 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
711 | - return false; |
|
712 | - } |
|
713 | - $ticket = $registration->ticket(); |
|
714 | - if (! $ticket instanceof EE_Ticket) { |
|
715 | - throw new EE_Error( |
|
716 | - sprintf( |
|
717 | - esc_html__( |
|
718 | - 'The Ticket for Registration %1$d was not found or is invalid.', |
|
719 | - 'event_espresso' |
|
720 | - ), |
|
721 | - $registration->ticket_ID() |
|
722 | - ) |
|
723 | - ); |
|
724 | - } |
|
725 | - $registration->set_final_price($ticket->price()); |
|
726 | - if ($update_reg) { |
|
727 | - $registration->save(); |
|
728 | - } |
|
729 | - return true; |
|
730 | - } |
|
731 | - |
|
732 | - |
|
733 | - /** |
|
734 | - * generate_ONE_registration_from_line_item |
|
735 | - * Although a ticket line item may have a quantity greater than 1, |
|
736 | - * this method will ONLY CREATE ONE REGISTRATION !!! |
|
737 | - * Regardless of the ticket line item quantity. |
|
738 | - * This means that any code calling this method is responsible for ensuring |
|
739 | - * that the final registration count matches the ticket line item quantity. |
|
740 | - * This was done to make it easier to match the number of registrations |
|
741 | - * to the number of tickets in the cart, when the cart has been edited |
|
742 | - * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
743 | - * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
744 | - * |
|
745 | - * @param EE_Line_Item $line_item |
|
746 | - * @param EE_Transaction $transaction |
|
747 | - * @param int $att_nmbr |
|
748 | - * @param int $total_ticket_count |
|
749 | - * @return EE_Registration | null |
|
750 | - * @throws OutOfRangeException |
|
751 | - * @throws UnexpectedEntityException |
|
752 | - * @throws EE_Error |
|
753 | - * @throws ReflectionException |
|
754 | - * @deprecated |
|
755 | - * @since 4.9.1 |
|
756 | - */ |
|
757 | - public function generate_ONE_registration_from_line_item( |
|
758 | - EE_Line_Item $line_item, |
|
759 | - EE_Transaction $transaction, |
|
760 | - $att_nmbr = 1, |
|
761 | - $total_ticket_count = 1 |
|
762 | - ) { |
|
763 | - EE_Error::doing_it_wrong( |
|
764 | - __CLASS__ . '::' . __FUNCTION__, |
|
765 | - sprintf( |
|
766 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
767 | - '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
768 | - ), |
|
769 | - '4.9.1', |
|
770 | - '5.0.0' |
|
771 | - ); |
|
772 | - // grab the related ticket object for this line_item |
|
773 | - $ticket = $line_item->ticket(); |
|
774 | - if (! $ticket instanceof EE_Ticket) { |
|
775 | - EE_Error::add_error( |
|
776 | - sprintf( |
|
777 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
778 | - $line_item->ID() |
|
779 | - ), |
|
780 | - __FILE__, |
|
781 | - __FUNCTION__, |
|
782 | - __LINE__ |
|
783 | - ); |
|
784 | - return null; |
|
785 | - } |
|
786 | - $registration_service = new CreateRegistrationService(); |
|
787 | - // then generate a new registration from that |
|
788 | - return $registration_service->create( |
|
789 | - $ticket->get_related_event(), |
|
790 | - $transaction, |
|
791 | - $ticket, |
|
792 | - $line_item, |
|
793 | - $att_nmbr, |
|
794 | - $total_ticket_count |
|
795 | - ); |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * generates reg_url_link |
|
801 | - * |
|
802 | - * @param int $att_nmbr |
|
803 | - * @param EE_Line_Item | string $item |
|
804 | - * @return RegUrlLink |
|
805 | - * @throws InvalidArgumentException |
|
806 | - * @deprecated |
|
807 | - * @since 4.9.1 |
|
808 | - */ |
|
809 | - public function generate_reg_url_link($att_nmbr, $item) |
|
810 | - { |
|
811 | - EE_Error::doing_it_wrong( |
|
812 | - __CLASS__ . '::' . __FUNCTION__, |
|
813 | - sprintf( |
|
814 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
815 | - 'EventEspresso\core\domain\entities\RegUrlLink' |
|
816 | - ), |
|
817 | - '4.9.1', |
|
818 | - '5.0.0' |
|
819 | - ); |
|
820 | - return new RegUrlLink($att_nmbr, $item); |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * generates reg code |
|
826 | - * |
|
827 | - * @param EE_Registration $registration |
|
828 | - * @return RegCode |
|
829 | - * @throws EE_Error |
|
830 | - * @throws EntityNotFoundException |
|
831 | - * @throws InvalidArgumentException |
|
832 | - * @since 4.9.1 |
|
833 | - * @deprecated |
|
834 | - */ |
|
835 | - public function generate_reg_code(EE_Registration $registration) |
|
836 | - { |
|
837 | - EE_Error::doing_it_wrong( |
|
838 | - __CLASS__ . '::' . __FUNCTION__, |
|
839 | - sprintf( |
|
840 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
841 | - 'EventEspresso\core\domain\entities\RegCode' |
|
842 | - ), |
|
843 | - '4.9.1', |
|
844 | - '5.0.0' |
|
845 | - ); |
|
846 | - return apply_filters( |
|
847 | - 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
848 | - new RegCode( |
|
849 | - RegUrlLink::fromRegistration($registration), |
|
850 | - $registration->transaction(), |
|
851 | - $registration->ticket() |
|
852 | - ), |
|
853 | - $registration |
|
854 | - ); |
|
855 | - } |
|
432 | + $registration->status_ID() === RegStatus::PENDING_PAYMENT |
|
433 | + // AND no monies are owing |
|
434 | + && ( |
|
435 | + ( |
|
436 | + $registration->transaction()->is_completed() |
|
437 | + || $registration->transaction()->is_overpaid() |
|
438 | + || $registration->transaction()->is_free() |
|
439 | + || apply_filters( |
|
440 | + 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
441 | + false, |
|
442 | + $registration |
|
443 | + ) |
|
444 | + ) |
|
445 | + || ( |
|
446 | + $payment instanceof EE_Payment && $payment->is_approved() |
|
447 | + && // this specific registration has not yet been paid for |
|
448 | + ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
449 | + && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
450 | + $payment->amount() - $total_paid >= $registration->final_price() |
|
451 | + ) |
|
452 | + ) |
|
453 | + ) { |
|
454 | + // mark as paid |
|
455 | + self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
456 | + // track new REG_Status |
|
457 | + $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
458 | + // toggle status to approved |
|
459 | + $registration->set_status( |
|
460 | + RegStatus::APPROVED, |
|
461 | + false, |
|
462 | + new Context( |
|
463 | + __METHOD__, |
|
464 | + esc_html__( |
|
465 | + 'Executed when the registration status is updated to RegStatus::APPROVED when no monies are owing.', |
|
466 | + 'event_espresso' |
|
467 | + ) |
|
468 | + ) |
|
469 | + ); |
|
470 | + if ($save) { |
|
471 | + $registration->save(); |
|
472 | + } |
|
473 | + // don't trigger notifications during IPNs because they will get triggered by |
|
474 | + // EventEspresso\core\services\payments\PostPaymentProcessor |
|
475 | + if (! EE_Processor_Base::$IPN) { |
|
476 | + // otherwise, send out notifications |
|
477 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
478 | + } |
|
479 | + // DEBUG LOG |
|
480 | + // $this->log( |
|
481 | + // __CLASS__, |
|
482 | + // __FUNCTION__, |
|
483 | + // __LINE__, |
|
484 | + // $registration->transaction(), |
|
485 | + // array( |
|
486 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
487 | + // 'deliver_notifications' => has_filter( |
|
488 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
489 | + // ), |
|
490 | + // ) |
|
491 | + // ); |
|
492 | + return true; |
|
493 | + } |
|
494 | + return false; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * registration_status_changed |
|
500 | + * |
|
501 | + * @access public |
|
502 | + * @param EE_Registration $registration |
|
503 | + * @param array $additional_details |
|
504 | + * @return void |
|
505 | + */ |
|
506 | + public function trigger_registration_update_notifications($registration, array $additional_details = []) |
|
507 | + { |
|
508 | + try { |
|
509 | + if (! $registration instanceof EE_Registration) { |
|
510 | + throw new EE_Error( |
|
511 | + esc_html__('An invalid registration was received.', 'event_espresso') |
|
512 | + ); |
|
513 | + } |
|
514 | + // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
515 | + // EEH_Debug_Tools::log( |
|
516 | + // __CLASS__, |
|
517 | + // __FUNCTION__, |
|
518 | + // __LINE__, |
|
519 | + // array($registration->transaction(), $additional_details), |
|
520 | + // false, |
|
521 | + // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
522 | + // ); |
|
523 | + if ( |
|
524 | + ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int') |
|
525 | + && ! $registration->is_primary_registrant() |
|
526 | + ) { |
|
527 | + return; |
|
528 | + } |
|
529 | + do_action( |
|
530 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
531 | + $registration, |
|
532 | + $additional_details |
|
533 | + ); |
|
534 | + } catch (Exception $e) { |
|
535 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
536 | + } |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
542 | + * |
|
543 | + * @param EE_Registration $registration |
|
544 | + * @param array $additional_details |
|
545 | + * @return bool |
|
546 | + * @throws EE_Error |
|
547 | + * @throws EntityNotFoundException |
|
548 | + * @throws InvalidArgumentException |
|
549 | + * @throws InvalidDataTypeException |
|
550 | + * @throws InvalidInterfaceException |
|
551 | + * @throws ReflectionException |
|
552 | + * @throws RuntimeException |
|
553 | + */ |
|
554 | + public function update_registration_after_checkout_or_payment( |
|
555 | + EE_Registration $registration, |
|
556 | + array $additional_details = [] |
|
557 | + ) { |
|
558 | + // set initial REG_Status |
|
559 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
560 | + // if the registration status gets updated, then save the registration |
|
561 | + if ( |
|
562 | + $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
563 | + || $this->toggle_registration_status_if_no_monies_owing( |
|
564 | + $registration, |
|
565 | + false, |
|
566 | + $additional_details |
|
567 | + ) |
|
568 | + ) { |
|
569 | + $registration->save(); |
|
570 | + } |
|
571 | + // set new REG_Status |
|
572 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
573 | + return $this->reg_status_updated($registration->ID()) |
|
574 | + && $this->new_reg_status($registration->ID()) === RegStatus::APPROVED; |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Updates the registration' final prices based on the current line item tree (taking into account |
|
580 | + * discounts, taxes, and other line items unrelated to tickets.) |
|
581 | + * |
|
582 | + * @param EE_Transaction $transaction |
|
583 | + * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
584 | + * @return void |
|
585 | + * @throws EE_Error |
|
586 | + * @throws InvalidArgumentException |
|
587 | + * @throws InvalidDataTypeException |
|
588 | + * @throws InvalidInterfaceException |
|
589 | + * @throws RuntimeException |
|
590 | + * @throws ReflectionException |
|
591 | + */ |
|
592 | + public function update_registration_final_prices($transaction, $save_regs = true) |
|
593 | + { |
|
594 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
595 | + $transaction->total_line_item() |
|
596 | + ); |
|
597 | + foreach ($transaction->registrations() as $registration) { |
|
598 | + /** @var EE_Line_Item $line_item */ |
|
599 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
600 | + if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
601 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
602 | + if ($save_regs) { |
|
603 | + $registration->save(); |
|
604 | + } |
|
605 | + } |
|
606 | + } |
|
607 | + // and make sure there's no rounding problem |
|
608 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * Makes sure there is no rounding errors for the REG_final_prices. |
|
614 | + * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
615 | + * they will each be for $0.99333333, which gets rounded to $1 again. |
|
616 | + * So the transaction total will be $2.99, but each registration will be for $1, |
|
617 | + * so if each registrant paid individually they will have overpaid by $0.01. |
|
618 | + * So in order to overcome this, we check for any difference, and if there is a difference |
|
619 | + * we just grab one registrant at random and make them responsible for it. |
|
620 | + * This should be used after setting REG_final_prices (it's done automatically as part of |
|
621 | + * EE_Registration_Processor::update_registration_final_prices()) |
|
622 | + * |
|
623 | + * @param EE_Transaction $transaction |
|
624 | + * @return bool success verifying that there is NO difference after this method is done |
|
625 | + * @throws EE_Error |
|
626 | + * @throws InvalidArgumentException |
|
627 | + * @throws InvalidDataTypeException |
|
628 | + * @throws InvalidInterfaceException |
|
629 | + * @throws ReflectionException |
|
630 | + */ |
|
631 | + public function fix_reg_final_price_rounding_issue($transaction) |
|
632 | + { |
|
633 | + $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
634 | + [ |
|
635 | + [ |
|
636 | + 'TXN_ID' => $transaction->ID(), |
|
637 | + ], |
|
638 | + ], |
|
639 | + 'REG_final_price' |
|
640 | + ); |
|
641 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
642 | + // ok then, just grab one of the registrations |
|
643 | + if ($diff !== 0.0) { |
|
644 | + $a_reg = EEM_Registration::instance()->get_one( |
|
645 | + [ |
|
646 | + [ |
|
647 | + 'TXN_ID' => $transaction->ID(), |
|
648 | + ], |
|
649 | + ] |
|
650 | + ); |
|
651 | + return $a_reg instanceof EE_Registration |
|
652 | + && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
653 | + } |
|
654 | + return true; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * update_registration_after_being_canceled_or_declined |
|
660 | + * |
|
661 | + * @param EE_Registration $registration |
|
662 | + * @param array $closed_reg_statuses |
|
663 | + * @param bool $update_reg |
|
664 | + * @return bool |
|
665 | + * @throws EE_Error |
|
666 | + * @throws RuntimeException |
|
667 | + * @throws ReflectionException |
|
668 | + */ |
|
669 | + public function update_registration_after_being_canceled_or_declined( |
|
670 | + EE_Registration $registration, |
|
671 | + array $closed_reg_statuses = [], |
|
672 | + $update_reg = true |
|
673 | + ) { |
|
674 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
675 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
676 | + ? $closed_reg_statuses |
|
677 | + : EEM_Registration::closed_reg_statuses(); |
|
678 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
679 | + return false; |
|
680 | + } |
|
681 | + // release a reserved ticket by decrementing ticket and datetime reserved values |
|
682 | + $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
683 | + $registration->set_final_price(0); |
|
684 | + if ($update_reg) { |
|
685 | + $registration->save(); |
|
686 | + } |
|
687 | + return true; |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * update_canceled_or_declined_registration_after_being_reinstated |
|
693 | + * |
|
694 | + * @param EE_Registration $registration |
|
695 | + * @param array $closed_reg_statuses |
|
696 | + * @param bool $update_reg |
|
697 | + * @return bool |
|
698 | + * @throws EE_Error |
|
699 | + * @throws RuntimeException |
|
700 | + * @throws ReflectionException |
|
701 | + */ |
|
702 | + public function update_canceled_or_declined_registration_after_being_reinstated( |
|
703 | + EE_Registration $registration, |
|
704 | + array $closed_reg_statuses = [], |
|
705 | + $update_reg = true |
|
706 | + ) { |
|
707 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
708 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
709 | + : EEM_Registration::closed_reg_statuses(); |
|
710 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
711 | + return false; |
|
712 | + } |
|
713 | + $ticket = $registration->ticket(); |
|
714 | + if (! $ticket instanceof EE_Ticket) { |
|
715 | + throw new EE_Error( |
|
716 | + sprintf( |
|
717 | + esc_html__( |
|
718 | + 'The Ticket for Registration %1$d was not found or is invalid.', |
|
719 | + 'event_espresso' |
|
720 | + ), |
|
721 | + $registration->ticket_ID() |
|
722 | + ) |
|
723 | + ); |
|
724 | + } |
|
725 | + $registration->set_final_price($ticket->price()); |
|
726 | + if ($update_reg) { |
|
727 | + $registration->save(); |
|
728 | + } |
|
729 | + return true; |
|
730 | + } |
|
731 | + |
|
732 | + |
|
733 | + /** |
|
734 | + * generate_ONE_registration_from_line_item |
|
735 | + * Although a ticket line item may have a quantity greater than 1, |
|
736 | + * this method will ONLY CREATE ONE REGISTRATION !!! |
|
737 | + * Regardless of the ticket line item quantity. |
|
738 | + * This means that any code calling this method is responsible for ensuring |
|
739 | + * that the final registration count matches the ticket line item quantity. |
|
740 | + * This was done to make it easier to match the number of registrations |
|
741 | + * to the number of tickets in the cart, when the cart has been edited |
|
742 | + * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
743 | + * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
744 | + * |
|
745 | + * @param EE_Line_Item $line_item |
|
746 | + * @param EE_Transaction $transaction |
|
747 | + * @param int $att_nmbr |
|
748 | + * @param int $total_ticket_count |
|
749 | + * @return EE_Registration | null |
|
750 | + * @throws OutOfRangeException |
|
751 | + * @throws UnexpectedEntityException |
|
752 | + * @throws EE_Error |
|
753 | + * @throws ReflectionException |
|
754 | + * @deprecated |
|
755 | + * @since 4.9.1 |
|
756 | + */ |
|
757 | + public function generate_ONE_registration_from_line_item( |
|
758 | + EE_Line_Item $line_item, |
|
759 | + EE_Transaction $transaction, |
|
760 | + $att_nmbr = 1, |
|
761 | + $total_ticket_count = 1 |
|
762 | + ) { |
|
763 | + EE_Error::doing_it_wrong( |
|
764 | + __CLASS__ . '::' . __FUNCTION__, |
|
765 | + sprintf( |
|
766 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
767 | + '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
768 | + ), |
|
769 | + '4.9.1', |
|
770 | + '5.0.0' |
|
771 | + ); |
|
772 | + // grab the related ticket object for this line_item |
|
773 | + $ticket = $line_item->ticket(); |
|
774 | + if (! $ticket instanceof EE_Ticket) { |
|
775 | + EE_Error::add_error( |
|
776 | + sprintf( |
|
777 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
778 | + $line_item->ID() |
|
779 | + ), |
|
780 | + __FILE__, |
|
781 | + __FUNCTION__, |
|
782 | + __LINE__ |
|
783 | + ); |
|
784 | + return null; |
|
785 | + } |
|
786 | + $registration_service = new CreateRegistrationService(); |
|
787 | + // then generate a new registration from that |
|
788 | + return $registration_service->create( |
|
789 | + $ticket->get_related_event(), |
|
790 | + $transaction, |
|
791 | + $ticket, |
|
792 | + $line_item, |
|
793 | + $att_nmbr, |
|
794 | + $total_ticket_count |
|
795 | + ); |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * generates reg_url_link |
|
801 | + * |
|
802 | + * @param int $att_nmbr |
|
803 | + * @param EE_Line_Item | string $item |
|
804 | + * @return RegUrlLink |
|
805 | + * @throws InvalidArgumentException |
|
806 | + * @deprecated |
|
807 | + * @since 4.9.1 |
|
808 | + */ |
|
809 | + public function generate_reg_url_link($att_nmbr, $item) |
|
810 | + { |
|
811 | + EE_Error::doing_it_wrong( |
|
812 | + __CLASS__ . '::' . __FUNCTION__, |
|
813 | + sprintf( |
|
814 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
815 | + 'EventEspresso\core\domain\entities\RegUrlLink' |
|
816 | + ), |
|
817 | + '4.9.1', |
|
818 | + '5.0.0' |
|
819 | + ); |
|
820 | + return new RegUrlLink($att_nmbr, $item); |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * generates reg code |
|
826 | + * |
|
827 | + * @param EE_Registration $registration |
|
828 | + * @return RegCode |
|
829 | + * @throws EE_Error |
|
830 | + * @throws EntityNotFoundException |
|
831 | + * @throws InvalidArgumentException |
|
832 | + * @since 4.9.1 |
|
833 | + * @deprecated |
|
834 | + */ |
|
835 | + public function generate_reg_code(EE_Registration $registration) |
|
836 | + { |
|
837 | + EE_Error::doing_it_wrong( |
|
838 | + __CLASS__ . '::' . __FUNCTION__, |
|
839 | + sprintf( |
|
840 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
841 | + 'EventEspresso\core\domain\entities\RegCode' |
|
842 | + ), |
|
843 | + '4.9.1', |
|
844 | + '5.0.0' |
|
845 | + ); |
|
846 | + return apply_filters( |
|
847 | + 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
848 | + new RegCode( |
|
849 | + RegUrlLink::fromRegistration($registration), |
|
850 | + $registration->transaction(), |
|
851 | + $registration->ticket() |
|
852 | + ), |
|
853 | + $registration |
|
854 | + ); |
|
855 | + } |
|
856 | 856 | } |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | public static function instance(RequestInterface $request = null) |
83 | 83 | { |
84 | 84 | // check if class object is instantiated |
85 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
86 | - if (! $request instanceof RequestInterface) { |
|
85 | + if ( ! self::$_instance instanceof EE_Registration_Processor) { |
|
86 | + if ( ! $request instanceof RequestInterface) { |
|
87 | 87 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
88 | 88 | } |
89 | 89 | self::$_instance = new self($request); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function old_reg_status($REG_ID) |
111 | 111 | { |
112 | - return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
112 | + return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | public function set_old_reg_status($REG_ID, $old_reg_status) |
121 | 121 | { |
122 | 122 | // only set the first time |
123 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
124 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
123 | + if ( ! isset($this->_old_reg_status[$REG_ID])) { |
|
124 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function new_reg_status($REG_ID) |
134 | 134 | { |
135 | - return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
135 | + return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function set_new_reg_status($REG_ID, $new_reg_status) |
144 | 144 | { |
145 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
145 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | if ( |
220 | 220 | $this->reg_status_updated($registration->ID()) |
221 | 221 | && ( |
222 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
222 | + ( ! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
223 | 223 | || EE_Registry::instance()->CAP->current_user_can( |
224 | 224 | 'ee_edit_registration', |
225 | 225 | 'toggle_registration_status', |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | } |
304 | 304 | // don't trigger notifications during IPNs because they will get triggered by |
305 | 305 | // EventEspresso\core\services\payments\PostPaymentProcessor |
306 | - if (! EE_Processor_Base::$IPN) { |
|
306 | + if ( ! EE_Processor_Base::$IPN) { |
|
307 | 307 | // otherwise, send out notifications |
308 | 308 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
309 | 309 | } |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | } |
373 | 373 | // don't trigger notifications during IPNs because they will get triggered by |
374 | 374 | // EventEspresso\core\services\payments\PostPaymentProcessor |
375 | - if (! EE_Processor_Base::$IPN) { |
|
375 | + if ( ! EE_Processor_Base::$IPN) { |
|
376 | 376 | // otherwise, send out notifications |
377 | 377 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
378 | 378 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | // set initial REG_Status |
421 | 421 | $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
422 | 422 | // was a payment just made ? |
423 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
423 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
424 | 424 | && $additional_details['payment_updates'] |
425 | 425 | && $additional_details['last_payment'] instanceof EE_Payment |
426 | 426 | ? $additional_details['last_payment'] |
@@ -445,14 +445,14 @@ discard block |
||
445 | 445 | || ( |
446 | 446 | $payment instanceof EE_Payment && $payment->is_approved() |
447 | 447 | && // this specific registration has not yet been paid for |
448 | - ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
448 | + ! isset(self::$_amount_paid[$registration->ID()]) |
|
449 | 449 | && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
450 | 450 | $payment->amount() - $total_paid >= $registration->final_price() |
451 | 451 | ) |
452 | 452 | ) |
453 | 453 | ) { |
454 | 454 | // mark as paid |
455 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
455 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
456 | 456 | // track new REG_Status |
457 | 457 | $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
458 | 458 | // toggle status to approved |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | } |
473 | 473 | // don't trigger notifications during IPNs because they will get triggered by |
474 | 474 | // EventEspresso\core\services\payments\PostPaymentProcessor |
475 | - if (! EE_Processor_Base::$IPN) { |
|
475 | + if ( ! EE_Processor_Base::$IPN) { |
|
476 | 476 | // otherwise, send out notifications |
477 | 477 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
478 | 478 | } |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | public function trigger_registration_update_notifications($registration, array $additional_details = []) |
507 | 507 | { |
508 | 508 | try { |
509 | - if (! $registration instanceof EE_Registration) { |
|
509 | + if ( ! $registration instanceof EE_Registration) { |
|
510 | 510 | throw new EE_Error( |
511 | 511 | esc_html__('An invalid registration was received.', 'event_espresso') |
512 | 512 | ); |
@@ -597,8 +597,8 @@ discard block |
||
597 | 597 | foreach ($transaction->registrations() as $registration) { |
598 | 598 | /** @var EE_Line_Item $line_item */ |
599 | 599 | $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
600 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
601 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
600 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
601 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
602 | 602 | if ($save_regs) { |
603 | 603 | $registration->save(); |
604 | 604 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | ], |
639 | 639 | 'REG_final_price' |
640 | 640 | ); |
641 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
641 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
642 | 642 | // ok then, just grab one of the registrations |
643 | 643 | if ($diff !== 0.0) { |
644 | 644 | $a_reg = EEM_Registration::instance()->get_one( |
@@ -675,11 +675,11 @@ discard block |
||
675 | 675 | $closed_reg_statuses = ! empty($closed_reg_statuses) |
676 | 676 | ? $closed_reg_statuses |
677 | 677 | : EEM_Registration::closed_reg_statuses(); |
678 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
678 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
679 | 679 | return false; |
680 | 680 | } |
681 | 681 | // release a reserved ticket by decrementing ticket and datetime reserved values |
682 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
682 | + $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__); |
|
683 | 683 | $registration->set_final_price(0); |
684 | 684 | if ($update_reg) { |
685 | 685 | $registration->save(); |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | return false; |
712 | 712 | } |
713 | 713 | $ticket = $registration->ticket(); |
714 | - if (! $ticket instanceof EE_Ticket) { |
|
714 | + if ( ! $ticket instanceof EE_Ticket) { |
|
715 | 715 | throw new EE_Error( |
716 | 716 | sprintf( |
717 | 717 | esc_html__( |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | $total_ticket_count = 1 |
762 | 762 | ) { |
763 | 763 | EE_Error::doing_it_wrong( |
764 | - __CLASS__ . '::' . __FUNCTION__, |
|
764 | + __CLASS__.'::'.__FUNCTION__, |
|
765 | 765 | sprintf( |
766 | 766 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
767 | 767 | '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | ); |
772 | 772 | // grab the related ticket object for this line_item |
773 | 773 | $ticket = $line_item->ticket(); |
774 | - if (! $ticket instanceof EE_Ticket) { |
|
774 | + if ( ! $ticket instanceof EE_Ticket) { |
|
775 | 775 | EE_Error::add_error( |
776 | 776 | sprintf( |
777 | 777 | esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | public function generate_reg_url_link($att_nmbr, $item) |
810 | 810 | { |
811 | 811 | EE_Error::doing_it_wrong( |
812 | - __CLASS__ . '::' . __FUNCTION__, |
|
812 | + __CLASS__.'::'.__FUNCTION__, |
|
813 | 813 | sprintf( |
814 | 814 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
815 | 815 | 'EventEspresso\core\domain\entities\RegUrlLink' |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | public function generate_reg_code(EE_Registration $registration) |
836 | 836 | { |
837 | 837 | EE_Error::doing_it_wrong( |
838 | - __CLASS__ . '::' . __FUNCTION__, |
|
838 | + __CLASS__.'::'.__FUNCTION__, |
|
839 | 839 | sprintf( |
840 | 840 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
841 | 841 | 'EventEspresso\core\domain\entities\RegCode' |
@@ -23,162 +23,162 @@ |
||
23 | 23 | */ |
24 | 24 | class GracePeriod extends WordPressOption |
25 | 25 | { |
26 | - private const OPTION_NAME = 'ee_gateway_grace_period'; |
|
27 | - |
|
28 | - private const EXPIRY_DATE_FORMAT = 'Y-m-d H:i:s'; |
|
29 | - |
|
30 | - public const LICENSE_ACTIVE = 'active'; |
|
31 | - |
|
32 | - public const LICENSE_DECAF = 'decaf'; |
|
33 | - |
|
34 | - public const LICENSE_EXPIRED = 'expired'; |
|
35 | - |
|
36 | - |
|
37 | - protected DateTimeImmutable $current_date; |
|
38 | - |
|
39 | - protected DateTimeImmutable $grace_period_start_date; |
|
40 | - |
|
41 | - protected DateTimeZone $UTC_TZ; |
|
42 | - |
|
43 | - protected array $grace_periods = [ |
|
44 | - GracePeriod::LICENSE_ACTIVE => 14, |
|
45 | - GracePeriod::LICENSE_EXPIRED => 14, |
|
46 | - GracePeriod::LICENSE_DECAF => 28, |
|
47 | - ]; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @throws Exception |
|
52 | - */ |
|
53 | - public function __construct() |
|
54 | - { |
|
55 | - parent::__construct(GracePeriod::OPTION_NAME, 0); |
|
56 | - $this->UTC_TZ = new DateTimeZone('UTC'); |
|
57 | - $this->current_date = new DateTimeImmutable('now', $this->UTC_TZ); |
|
58 | - $this->grace_period_start_date = $this->gracePeriodStartDate(); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param string $license_status |
|
64 | - * @param string $license_expires |
|
65 | - * @return bool |
|
66 | - * @throws Exception |
|
67 | - */ |
|
68 | - public function withinGracePeriod(string $license_status, string $license_expires): bool |
|
69 | - { |
|
70 | - if ($license_status === GracePeriod::LICENSE_ACTIVE) { |
|
71 | - return true; |
|
72 | - } |
|
73 | - $license_expires_datetime = $this->licenseExpiresDateTime($license_expires); |
|
74 | - if ($license_expires_datetime instanceof DateTimeImmutable) { |
|
75 | - $this->resetGracePeriodIfLicenseExpired($this->licenseExpiresDateTime($license_expires)); |
|
76 | - } |
|
77 | - return $this->daysLeft() <= $this->gracePeriodForLicense($license_status); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return DateTimeImmutable |
|
83 | - * @throws Exception |
|
84 | - */ |
|
85 | - protected function gracePeriodStartDate(): DateTimeImmutable |
|
86 | - { |
|
87 | - $grace_period_start_timestamp = $this->loadOption(); |
|
88 | - if (! $grace_period_start_timestamp) { |
|
89 | - $grace_period_start_timestamp = time(); |
|
90 | - $this->updateOption($grace_period_start_timestamp, true); |
|
91 | - } |
|
92 | - return new DateTimeImmutable("@$grace_period_start_timestamp", $this->UTC_TZ); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * will reset the grace period start date if the license is expired |
|
98 | - * |
|
99 | - * @param DateTimeImmutable $license_expiry_date |
|
100 | - * @throws Exception |
|
101 | - */ |
|
102 | - protected function resetGracePeriodIfLicenseExpired(DateTimeImmutable $license_expiry_date) |
|
103 | - { |
|
104 | - // return if license has not expired |
|
105 | - if ($license_expiry_date >= $this->current_date) { |
|
106 | - return; |
|
107 | - } |
|
108 | - // return if grace period start date is already set to the date the license expired |
|
109 | - if ($license_expiry_date == $this->grace_period_start_date) { |
|
110 | - return; |
|
111 | - } |
|
112 | - // reset grace period start date to the date the license expired |
|
113 | - $grace_period_timestamp = $license_expiry_date->getTimestamp(); |
|
114 | - $this->updateOption($grace_period_timestamp, true); |
|
115 | - $this->grace_period_start_date = new DateTimeImmutable("@$grace_period_timestamp", $this->UTC_TZ); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * returns the number of days between the grace period start date and the current date |
|
121 | - * |
|
122 | - * @return DateInterval |
|
123 | - * @throws Exception |
|
124 | - */ |
|
125 | - protected function gracePeriodDateInterval(): DateInterval |
|
126 | - { |
|
127 | - return $this->grace_period_start_date->diff($this->current_date, true); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * returns the number of days left in the grace period |
|
133 | - * |
|
134 | - * @return int |
|
135 | - * @throws Exception |
|
136 | - */ |
|
137 | - protected function daysLeft(): int |
|
138 | - { |
|
139 | - return max((int) $this->gracePeriodDateInterval()->format('%a'), 0); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $license_status |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - protected function gracePeriodForLicense(string $license_status): int |
|
148 | - { |
|
149 | - return $this->grace_periods[ $license_status ] ?? 0; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param string $license_expires |
|
155 | - * @return DateTimeImmutable|null |
|
156 | - */ |
|
157 | - protected function licenseExpiresDateTime(string $license_expires): ?DateTimeImmutable |
|
158 | - { |
|
159 | - if (empty($license_expires)) { |
|
160 | - return null; |
|
161 | - } |
|
162 | - $dateTime = DateTime::createFromFormat(GracePeriod::EXPIRY_DATE_FORMAT, $license_expires); |
|
163 | - $errors = DateTime::getLastErrors(); |
|
164 | - // return null if date could not be created or there were errors |
|
165 | - if ( |
|
166 | - $dateTime === false |
|
167 | - || (is_array($errors) && ($errors['warning_count'] > 0 || $errors['error_count'] > 0)) |
|
168 | - ) { |
|
169 | - return null; |
|
170 | - } |
|
171 | - return DateTimeImmutable::createFromMutable($dateTime); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * override parent method to prevent deletion |
|
177 | - * |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function deleteOption(): bool |
|
181 | - { |
|
182 | - return false; |
|
183 | - } |
|
26 | + private const OPTION_NAME = 'ee_gateway_grace_period'; |
|
27 | + |
|
28 | + private const EXPIRY_DATE_FORMAT = 'Y-m-d H:i:s'; |
|
29 | + |
|
30 | + public const LICENSE_ACTIVE = 'active'; |
|
31 | + |
|
32 | + public const LICENSE_DECAF = 'decaf'; |
|
33 | + |
|
34 | + public const LICENSE_EXPIRED = 'expired'; |
|
35 | + |
|
36 | + |
|
37 | + protected DateTimeImmutable $current_date; |
|
38 | + |
|
39 | + protected DateTimeImmutable $grace_period_start_date; |
|
40 | + |
|
41 | + protected DateTimeZone $UTC_TZ; |
|
42 | + |
|
43 | + protected array $grace_periods = [ |
|
44 | + GracePeriod::LICENSE_ACTIVE => 14, |
|
45 | + GracePeriod::LICENSE_EXPIRED => 14, |
|
46 | + GracePeriod::LICENSE_DECAF => 28, |
|
47 | + ]; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @throws Exception |
|
52 | + */ |
|
53 | + public function __construct() |
|
54 | + { |
|
55 | + parent::__construct(GracePeriod::OPTION_NAME, 0); |
|
56 | + $this->UTC_TZ = new DateTimeZone('UTC'); |
|
57 | + $this->current_date = new DateTimeImmutable('now', $this->UTC_TZ); |
|
58 | + $this->grace_period_start_date = $this->gracePeriodStartDate(); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param string $license_status |
|
64 | + * @param string $license_expires |
|
65 | + * @return bool |
|
66 | + * @throws Exception |
|
67 | + */ |
|
68 | + public function withinGracePeriod(string $license_status, string $license_expires): bool |
|
69 | + { |
|
70 | + if ($license_status === GracePeriod::LICENSE_ACTIVE) { |
|
71 | + return true; |
|
72 | + } |
|
73 | + $license_expires_datetime = $this->licenseExpiresDateTime($license_expires); |
|
74 | + if ($license_expires_datetime instanceof DateTimeImmutable) { |
|
75 | + $this->resetGracePeriodIfLicenseExpired($this->licenseExpiresDateTime($license_expires)); |
|
76 | + } |
|
77 | + return $this->daysLeft() <= $this->gracePeriodForLicense($license_status); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return DateTimeImmutable |
|
83 | + * @throws Exception |
|
84 | + */ |
|
85 | + protected function gracePeriodStartDate(): DateTimeImmutable |
|
86 | + { |
|
87 | + $grace_period_start_timestamp = $this->loadOption(); |
|
88 | + if (! $grace_period_start_timestamp) { |
|
89 | + $grace_period_start_timestamp = time(); |
|
90 | + $this->updateOption($grace_period_start_timestamp, true); |
|
91 | + } |
|
92 | + return new DateTimeImmutable("@$grace_period_start_timestamp", $this->UTC_TZ); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * will reset the grace period start date if the license is expired |
|
98 | + * |
|
99 | + * @param DateTimeImmutable $license_expiry_date |
|
100 | + * @throws Exception |
|
101 | + */ |
|
102 | + protected function resetGracePeriodIfLicenseExpired(DateTimeImmutable $license_expiry_date) |
|
103 | + { |
|
104 | + // return if license has not expired |
|
105 | + if ($license_expiry_date >= $this->current_date) { |
|
106 | + return; |
|
107 | + } |
|
108 | + // return if grace period start date is already set to the date the license expired |
|
109 | + if ($license_expiry_date == $this->grace_period_start_date) { |
|
110 | + return; |
|
111 | + } |
|
112 | + // reset grace period start date to the date the license expired |
|
113 | + $grace_period_timestamp = $license_expiry_date->getTimestamp(); |
|
114 | + $this->updateOption($grace_period_timestamp, true); |
|
115 | + $this->grace_period_start_date = new DateTimeImmutable("@$grace_period_timestamp", $this->UTC_TZ); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * returns the number of days between the grace period start date and the current date |
|
121 | + * |
|
122 | + * @return DateInterval |
|
123 | + * @throws Exception |
|
124 | + */ |
|
125 | + protected function gracePeriodDateInterval(): DateInterval |
|
126 | + { |
|
127 | + return $this->grace_period_start_date->diff($this->current_date, true); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * returns the number of days left in the grace period |
|
133 | + * |
|
134 | + * @return int |
|
135 | + * @throws Exception |
|
136 | + */ |
|
137 | + protected function daysLeft(): int |
|
138 | + { |
|
139 | + return max((int) $this->gracePeriodDateInterval()->format('%a'), 0); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $license_status |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + protected function gracePeriodForLicense(string $license_status): int |
|
148 | + { |
|
149 | + return $this->grace_periods[ $license_status ] ?? 0; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param string $license_expires |
|
155 | + * @return DateTimeImmutable|null |
|
156 | + */ |
|
157 | + protected function licenseExpiresDateTime(string $license_expires): ?DateTimeImmutable |
|
158 | + { |
|
159 | + if (empty($license_expires)) { |
|
160 | + return null; |
|
161 | + } |
|
162 | + $dateTime = DateTime::createFromFormat(GracePeriod::EXPIRY_DATE_FORMAT, $license_expires); |
|
163 | + $errors = DateTime::getLastErrors(); |
|
164 | + // return null if date could not be created or there were errors |
|
165 | + if ( |
|
166 | + $dateTime === false |
|
167 | + || (is_array($errors) && ($errors['warning_count'] > 0 || $errors['error_count'] > 0)) |
|
168 | + ) { |
|
169 | + return null; |
|
170 | + } |
|
171 | + return DateTimeImmutable::createFromMutable($dateTime); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * override parent method to prevent deletion |
|
177 | + * |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function deleteOption(): bool |
|
181 | + { |
|
182 | + return false; |
|
183 | + } |
|
184 | 184 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | protected function gracePeriodStartDate(): DateTimeImmutable |
86 | 86 | { |
87 | 87 | $grace_period_start_timestamp = $this->loadOption(); |
88 | - if (! $grace_period_start_timestamp) { |
|
88 | + if ( ! $grace_period_start_timestamp) { |
|
89 | 89 | $grace_period_start_timestamp = time(); |
90 | 90 | $this->updateOption($grace_period_start_timestamp, true); |
91 | 91 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | protected function gracePeriodForLicense(string $license_status): int |
148 | 148 | { |
149 | - return $this->grace_periods[ $license_status ] ?? 0; |
|
149 | + return $this->grace_periods[$license_status] ?? 0; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 |
@@ -18,284 +18,284 @@ |
||
18 | 18 | */ |
19 | 19 | class RequestTypeContextDetector |
20 | 20 | { |
21 | - private GraphQLEndpoint $gql_endpoint; |
|
22 | - |
|
23 | - private RequestTypeContextFactoryInterface $factory; |
|
24 | - |
|
25 | - private RequestInterface $request; |
|
26 | - |
|
27 | - private array $globalRouteConditions; |
|
28 | - |
|
29 | - private string $permalink_prefix; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * RequestTypeContextDetector constructor. |
|
34 | - * |
|
35 | - * @param GraphQLEndpoint $gql_endpoint |
|
36 | - * @param RequestInterface $request |
|
37 | - * @param RequestTypeContextFactoryInterface $factory |
|
38 | - * @param array $globalRouteConditions an array for injecting values that would |
|
39 | - * otherwise be defined as global constants |
|
40 | - * or other global variables for the current |
|
41 | - * request route such as DOING_AJAX |
|
42 | - */ |
|
43 | - public function __construct( |
|
44 | - GraphQLEndpoint $gql_endpoint, |
|
45 | - RequestInterface $request, |
|
46 | - RequestTypeContextFactoryInterface $factory, |
|
47 | - array $globalRouteConditions = [] |
|
48 | - ) { |
|
49 | - $this->gql_endpoint = $gql_endpoint; |
|
50 | - $this->request = $request; |
|
51 | - $this->factory = $factory; |
|
52 | - $this->globalRouteConditions = $globalRouteConditions; |
|
53 | - $permalink_structure = ltrim((string) get_option( 'permalink_structure' ), '/'); |
|
54 | - $this->permalink_prefix = strpos($permalink_structure, 'index.php') === 0 ? '/index.php/' : ''; |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param string $globalRouteCondition |
|
60 | - * @param mixed $default |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - private function getGlobalRouteCondition(string $globalRouteCondition, $default = false) |
|
64 | - { |
|
65 | - return $this->globalRouteConditions[ $globalRouteCondition ] ?? $default; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return RequestTypeContext |
|
71 | - * @throws InvalidArgumentException |
|
72 | - */ |
|
73 | - public function detectRequestTypeContext(): RequestTypeContext |
|
74 | - { |
|
75 | - // Detect error scrapes |
|
76 | - if ($this->isWordPressErrorScrape()) { |
|
77 | - return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
78 | - } |
|
79 | - // Detect activations |
|
80 | - if ($this->isWordPressActivationRequest()) { |
|
81 | - return $this->factory->create(RequestTypeContext::ACTIVATION); |
|
82 | - } |
|
83 | - // Detect EE REST API |
|
84 | - if ($this->isEspressoRestApiRequest()) { |
|
85 | - return $this->factory->create(RequestTypeContext::API); |
|
86 | - } |
|
87 | - // Detect WP REST API |
|
88 | - if ($this->isWordPressRestApiRequest()) { |
|
89 | - return $this->factory->create(RequestTypeContext::WP_API); |
|
90 | - } |
|
91 | - // Detect EE GraphQL |
|
92 | - if ($this->isEspressoGraphQLRequest()) { |
|
93 | - return $this->factory->create(RequestTypeContext::GQL); |
|
94 | - } |
|
95 | - // Detect AJAX |
|
96 | - if ($this->getGlobalRouteCondition('DOING_AJAX')) { |
|
97 | - return $this->isAjaxRequest(); |
|
98 | - } |
|
99 | - // Detect WP_Cron |
|
100 | - if ($this->isCronRequest()) { |
|
101 | - return $this->factory->create(RequestTypeContext::CRON); |
|
102 | - } |
|
103 | - // Detect command line requests |
|
104 | - if ($this->getGlobalRouteCondition('WP_CLI')) { |
|
105 | - return $this->factory->create(RequestTypeContext::CLI); |
|
106 | - } |
|
107 | - // detect WordPress admin (ie: "Dashboard") |
|
108 | - if ($this->getGlobalRouteCondition('is_admin')) { |
|
109 | - return $this->factory->create(RequestTypeContext::ADMIN); |
|
110 | - } |
|
111 | - // Detect iFrames |
|
112 | - if ($this->isIframeRoute()) { |
|
113 | - return $this->factory->create(RequestTypeContext::IFRAME); |
|
114 | - } |
|
115 | - // Detect Feeds |
|
116 | - if ($this->isFeedRequest()) { |
|
117 | - return $this->factory->create(RequestTypeContext::FEED); |
|
118 | - } |
|
119 | - // and by process of elimination... |
|
120 | - return $this->factory->create(RequestTypeContext::FRONTEND); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return RequestTypeContext |
|
126 | - */ |
|
127 | - private function isAjaxRequest(): RequestTypeContext |
|
128 | - { |
|
129 | - if ( |
|
130 | - $this->request->getRequestParam('ee_front_ajax', false, 'bool') |
|
131 | - || $this->request->getRequestParam('data[ee_front_ajax]', false, 'bool') |
|
132 | - ) { |
|
133 | - if (! defined('EE_FRONT_AJAX')) { |
|
134 | - define('EE_FRONT_AJAX', true); |
|
135 | - } |
|
136 | - if (! defined('EE_ADMIN_AJAX')) { |
|
137 | - define('EE_ADMIN_AJAX', false); |
|
138 | - } |
|
139 | - return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
140 | - } |
|
141 | - if ( |
|
142 | - $this->request->getRequestParam('ee_admin_ajax', false, 'bool') |
|
143 | - || $this->request->getRequestParam('data[ee_admin_ajax]', false, 'bool') |
|
144 | - ) { |
|
145 | - if (! defined('EE_ADMIN_AJAX')) { |
|
146 | - define('EE_ADMIN_AJAX', true); |
|
147 | - } |
|
148 | - if (! defined('EE_FRONT_AJAX')) { |
|
149 | - define('EE_FRONT_AJAX', false); |
|
150 | - } |
|
151 | - return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
152 | - } |
|
153 | - if ($this->request->getRequestParam('action') === 'heartbeat') { |
|
154 | - return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT); |
|
155 | - } |
|
156 | - return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - private function isWordPressErrorScrape(): bool |
|
164 | - { |
|
165 | - return ( |
|
166 | - $this->request->getRequestParam('wp_scrape_key') !== '' |
|
167 | - && $this->request->getRequestParam('wp_scrape_nonce') !== '' |
|
168 | - ) || ( |
|
169 | - $this->request->getRequestParam('action') === 'error_scrape' |
|
170 | - && $this->request->getRequestParam('_wpnonce') !== '' |
|
171 | - ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - private function isWordPressActivationRequest(): bool |
|
179 | - { |
|
180 | - $action = $this->request->getRequestParam('action'); |
|
181 | - $plugins_page_actions = [ |
|
182 | - 'true', |
|
183 | - 'activate', |
|
184 | - 'activate-multi', |
|
185 | - 'activate-selected', |
|
186 | - 'deactivate', |
|
187 | - 'deactivate-multi', |
|
188 | - 'deactivate-selected', |
|
189 | - 'delete-selected', |
|
190 | - 'disable-auto-update-selected', |
|
191 | - 'enable-auto-update-selected', |
|
192 | - 'update-selected', |
|
193 | - ]; |
|
194 | - return ($this->uriPathMatches('wp-admin/update.php') && $action === 'upload-plugin') |
|
195 | - || ($this->uriPathMatches('wp-admin/plugins.php') && in_array($action, $plugins_page_actions, true)); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $extra_path |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - private function isRestApiRequest(string $extra_path = ''): bool |
|
204 | - { |
|
205 | - $rest_route = $this->request->getRequestParam('rest_route'); |
|
206 | - return ( |
|
207 | - $this->request->getRequestParam('rest_route') !== '' |
|
208 | - && ( $extra_path === '' || strpos($rest_route, $extra_path) !== 0 ) |
|
209 | - ) |
|
210 | - || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . $extra_path); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @return bool |
|
216 | - */ |
|
217 | - private function isEspressoRestApiRequest(): bool |
|
218 | - { |
|
219 | - $api_namespace = '/' . ltrim(Domain::API_NAMESPACE, '/'); |
|
220 | - // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/... |
|
221 | - return $this->isRestApiRequest($api_namespace); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Checks for URLs like https://mysite.com/graphql |
|
227 | - * |
|
228 | - * @return bool |
|
229 | - */ |
|
230 | - private function isEspressoGraphQLRequest(): bool |
|
231 | - { |
|
232 | - if ($this->gql_endpoint->isGraphqlRequest()) { |
|
233 | - return true; |
|
234 | - } |
|
235 | - $gql_endpoint = $this->gql_endpoint->getEndpoint(); |
|
236 | - return $this->uriPathMatches($gql_endpoint) || $this->request->requestParamIsSet($gql_endpoint); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @return bool |
|
242 | - */ |
|
243 | - private function isWordPressRestApiRequest(): bool |
|
244 | - { |
|
245 | - // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/... |
|
246 | - return $this->isRestApiRequest(); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @return bool |
|
252 | - */ |
|
253 | - private function isCronRequest(): bool |
|
254 | - { |
|
255 | - return $this->uriPathMatches('wp-cron.php'); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - private function isFeedRequest(): bool |
|
263 | - { |
|
264 | - return $this->uriPathMatches('feed'); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * returns true if the current request URI starts with the supplied $component string |
|
270 | - * |
|
271 | - * @param string $component |
|
272 | - * @return bool |
|
273 | - */ |
|
274 | - private function uriPathMatches(string $component): bool |
|
275 | - { |
|
276 | - $request_uri = $this->request->requestUri(true); |
|
277 | - // remove permalink /index.php/ prefix if present |
|
278 | - if (substr($request_uri, 0, strlen($this->permalink_prefix)) === $this->permalink_prefix) { |
|
279 | - $request_uri = substr($request_uri, strlen($this->permalink_prefix)); |
|
280 | - } |
|
281 | - $parts = explode('?', $request_uri); |
|
282 | - $path = trim(reset($parts), '/'); |
|
283 | - return strpos($path, $component) === 0; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @return bool |
|
289 | - */ |
|
290 | - private function isIframeRoute(): bool |
|
291 | - { |
|
292 | - $is_iframe_route = apply_filters( |
|
293 | - 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
294 | - $this->request->getRequestParam('event_list', '') === 'iframe' |
|
295 | - || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
296 | - || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
297 | - $this |
|
298 | - ); |
|
299 | - return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
300 | - } |
|
21 | + private GraphQLEndpoint $gql_endpoint; |
|
22 | + |
|
23 | + private RequestTypeContextFactoryInterface $factory; |
|
24 | + |
|
25 | + private RequestInterface $request; |
|
26 | + |
|
27 | + private array $globalRouteConditions; |
|
28 | + |
|
29 | + private string $permalink_prefix; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * RequestTypeContextDetector constructor. |
|
34 | + * |
|
35 | + * @param GraphQLEndpoint $gql_endpoint |
|
36 | + * @param RequestInterface $request |
|
37 | + * @param RequestTypeContextFactoryInterface $factory |
|
38 | + * @param array $globalRouteConditions an array for injecting values that would |
|
39 | + * otherwise be defined as global constants |
|
40 | + * or other global variables for the current |
|
41 | + * request route such as DOING_AJAX |
|
42 | + */ |
|
43 | + public function __construct( |
|
44 | + GraphQLEndpoint $gql_endpoint, |
|
45 | + RequestInterface $request, |
|
46 | + RequestTypeContextFactoryInterface $factory, |
|
47 | + array $globalRouteConditions = [] |
|
48 | + ) { |
|
49 | + $this->gql_endpoint = $gql_endpoint; |
|
50 | + $this->request = $request; |
|
51 | + $this->factory = $factory; |
|
52 | + $this->globalRouteConditions = $globalRouteConditions; |
|
53 | + $permalink_structure = ltrim((string) get_option( 'permalink_structure' ), '/'); |
|
54 | + $this->permalink_prefix = strpos($permalink_structure, 'index.php') === 0 ? '/index.php/' : ''; |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param string $globalRouteCondition |
|
60 | + * @param mixed $default |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + private function getGlobalRouteCondition(string $globalRouteCondition, $default = false) |
|
64 | + { |
|
65 | + return $this->globalRouteConditions[ $globalRouteCondition ] ?? $default; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return RequestTypeContext |
|
71 | + * @throws InvalidArgumentException |
|
72 | + */ |
|
73 | + public function detectRequestTypeContext(): RequestTypeContext |
|
74 | + { |
|
75 | + // Detect error scrapes |
|
76 | + if ($this->isWordPressErrorScrape()) { |
|
77 | + return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
78 | + } |
|
79 | + // Detect activations |
|
80 | + if ($this->isWordPressActivationRequest()) { |
|
81 | + return $this->factory->create(RequestTypeContext::ACTIVATION); |
|
82 | + } |
|
83 | + // Detect EE REST API |
|
84 | + if ($this->isEspressoRestApiRequest()) { |
|
85 | + return $this->factory->create(RequestTypeContext::API); |
|
86 | + } |
|
87 | + // Detect WP REST API |
|
88 | + if ($this->isWordPressRestApiRequest()) { |
|
89 | + return $this->factory->create(RequestTypeContext::WP_API); |
|
90 | + } |
|
91 | + // Detect EE GraphQL |
|
92 | + if ($this->isEspressoGraphQLRequest()) { |
|
93 | + return $this->factory->create(RequestTypeContext::GQL); |
|
94 | + } |
|
95 | + // Detect AJAX |
|
96 | + if ($this->getGlobalRouteCondition('DOING_AJAX')) { |
|
97 | + return $this->isAjaxRequest(); |
|
98 | + } |
|
99 | + // Detect WP_Cron |
|
100 | + if ($this->isCronRequest()) { |
|
101 | + return $this->factory->create(RequestTypeContext::CRON); |
|
102 | + } |
|
103 | + // Detect command line requests |
|
104 | + if ($this->getGlobalRouteCondition('WP_CLI')) { |
|
105 | + return $this->factory->create(RequestTypeContext::CLI); |
|
106 | + } |
|
107 | + // detect WordPress admin (ie: "Dashboard") |
|
108 | + if ($this->getGlobalRouteCondition('is_admin')) { |
|
109 | + return $this->factory->create(RequestTypeContext::ADMIN); |
|
110 | + } |
|
111 | + // Detect iFrames |
|
112 | + if ($this->isIframeRoute()) { |
|
113 | + return $this->factory->create(RequestTypeContext::IFRAME); |
|
114 | + } |
|
115 | + // Detect Feeds |
|
116 | + if ($this->isFeedRequest()) { |
|
117 | + return $this->factory->create(RequestTypeContext::FEED); |
|
118 | + } |
|
119 | + // and by process of elimination... |
|
120 | + return $this->factory->create(RequestTypeContext::FRONTEND); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return RequestTypeContext |
|
126 | + */ |
|
127 | + private function isAjaxRequest(): RequestTypeContext |
|
128 | + { |
|
129 | + if ( |
|
130 | + $this->request->getRequestParam('ee_front_ajax', false, 'bool') |
|
131 | + || $this->request->getRequestParam('data[ee_front_ajax]', false, 'bool') |
|
132 | + ) { |
|
133 | + if (! defined('EE_FRONT_AJAX')) { |
|
134 | + define('EE_FRONT_AJAX', true); |
|
135 | + } |
|
136 | + if (! defined('EE_ADMIN_AJAX')) { |
|
137 | + define('EE_ADMIN_AJAX', false); |
|
138 | + } |
|
139 | + return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
140 | + } |
|
141 | + if ( |
|
142 | + $this->request->getRequestParam('ee_admin_ajax', false, 'bool') |
|
143 | + || $this->request->getRequestParam('data[ee_admin_ajax]', false, 'bool') |
|
144 | + ) { |
|
145 | + if (! defined('EE_ADMIN_AJAX')) { |
|
146 | + define('EE_ADMIN_AJAX', true); |
|
147 | + } |
|
148 | + if (! defined('EE_FRONT_AJAX')) { |
|
149 | + define('EE_FRONT_AJAX', false); |
|
150 | + } |
|
151 | + return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
152 | + } |
|
153 | + if ($this->request->getRequestParam('action') === 'heartbeat') { |
|
154 | + return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT); |
|
155 | + } |
|
156 | + return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + private function isWordPressErrorScrape(): bool |
|
164 | + { |
|
165 | + return ( |
|
166 | + $this->request->getRequestParam('wp_scrape_key') !== '' |
|
167 | + && $this->request->getRequestParam('wp_scrape_nonce') !== '' |
|
168 | + ) || ( |
|
169 | + $this->request->getRequestParam('action') === 'error_scrape' |
|
170 | + && $this->request->getRequestParam('_wpnonce') !== '' |
|
171 | + ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + private function isWordPressActivationRequest(): bool |
|
179 | + { |
|
180 | + $action = $this->request->getRequestParam('action'); |
|
181 | + $plugins_page_actions = [ |
|
182 | + 'true', |
|
183 | + 'activate', |
|
184 | + 'activate-multi', |
|
185 | + 'activate-selected', |
|
186 | + 'deactivate', |
|
187 | + 'deactivate-multi', |
|
188 | + 'deactivate-selected', |
|
189 | + 'delete-selected', |
|
190 | + 'disable-auto-update-selected', |
|
191 | + 'enable-auto-update-selected', |
|
192 | + 'update-selected', |
|
193 | + ]; |
|
194 | + return ($this->uriPathMatches('wp-admin/update.php') && $action === 'upload-plugin') |
|
195 | + || ($this->uriPathMatches('wp-admin/plugins.php') && in_array($action, $plugins_page_actions, true)); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $extra_path |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + private function isRestApiRequest(string $extra_path = ''): bool |
|
204 | + { |
|
205 | + $rest_route = $this->request->getRequestParam('rest_route'); |
|
206 | + return ( |
|
207 | + $this->request->getRequestParam('rest_route') !== '' |
|
208 | + && ( $extra_path === '' || strpos($rest_route, $extra_path) !== 0 ) |
|
209 | + ) |
|
210 | + || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . $extra_path); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @return bool |
|
216 | + */ |
|
217 | + private function isEspressoRestApiRequest(): bool |
|
218 | + { |
|
219 | + $api_namespace = '/' . ltrim(Domain::API_NAMESPACE, '/'); |
|
220 | + // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/... |
|
221 | + return $this->isRestApiRequest($api_namespace); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Checks for URLs like https://mysite.com/graphql |
|
227 | + * |
|
228 | + * @return bool |
|
229 | + */ |
|
230 | + private function isEspressoGraphQLRequest(): bool |
|
231 | + { |
|
232 | + if ($this->gql_endpoint->isGraphqlRequest()) { |
|
233 | + return true; |
|
234 | + } |
|
235 | + $gql_endpoint = $this->gql_endpoint->getEndpoint(); |
|
236 | + return $this->uriPathMatches($gql_endpoint) || $this->request->requestParamIsSet($gql_endpoint); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @return bool |
|
242 | + */ |
|
243 | + private function isWordPressRestApiRequest(): bool |
|
244 | + { |
|
245 | + // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/... |
|
246 | + return $this->isRestApiRequest(); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | + private function isCronRequest(): bool |
|
254 | + { |
|
255 | + return $this->uriPathMatches('wp-cron.php'); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + private function isFeedRequest(): bool |
|
263 | + { |
|
264 | + return $this->uriPathMatches('feed'); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * returns true if the current request URI starts with the supplied $component string |
|
270 | + * |
|
271 | + * @param string $component |
|
272 | + * @return bool |
|
273 | + */ |
|
274 | + private function uriPathMatches(string $component): bool |
|
275 | + { |
|
276 | + $request_uri = $this->request->requestUri(true); |
|
277 | + // remove permalink /index.php/ prefix if present |
|
278 | + if (substr($request_uri, 0, strlen($this->permalink_prefix)) === $this->permalink_prefix) { |
|
279 | + $request_uri = substr($request_uri, strlen($this->permalink_prefix)); |
|
280 | + } |
|
281 | + $parts = explode('?', $request_uri); |
|
282 | + $path = trim(reset($parts), '/'); |
|
283 | + return strpos($path, $component) === 0; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @return bool |
|
289 | + */ |
|
290 | + private function isIframeRoute(): bool |
|
291 | + { |
|
292 | + $is_iframe_route = apply_filters( |
|
293 | + 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
294 | + $this->request->getRequestParam('event_list', '') === 'iframe' |
|
295 | + || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
296 | + || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
297 | + $this |
|
298 | + ); |
|
299 | + return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
300 | + } |
|
301 | 301 | } |
@@ -11,211 +11,211 @@ |
||
11 | 11 | class FeatureFlag |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Whether to use the New Event Editor (EDTR) or continue using the legacy Event Editor |
|
16 | - * deafult: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
17 | - */ |
|
18 | - public const USE_ADVANCED_EVENT_EDITOR = 'ee_advanced_event_editor'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR) |
|
22 | - * default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
23 | - */ |
|
24 | - public const USE_EVENT_EDITOR_BULK_EDIT = 'ee_event_editor_bulk_edit'; |
|
25 | - |
|
26 | - /** |
|
27 | - * Whether to enable the new Default Ticket Manager in the EDTR |
|
28 | - * default: Enabled |
|
29 | - */ |
|
30 | - public const USE_DEFAULT_TICKET_MANAGER = 'use_default_ticket_manager'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce |
|
34 | - * default: Disabled |
|
35 | - */ |
|
36 | - public const USE_EVENT_DESCRIPTION_RTE = 'use_event_description_rte'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Whether to enable the Rich Text Editor for all other RTE fields in the EDTR |
|
40 | - * default: Disabled |
|
41 | - */ |
|
42 | - public const USE_EXPERIMENTAL_RTE = 'use_experimental_rte'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Whether to enable the new Registration Form Builder in the EDTR |
|
46 | - * or continue using the legacy Question Groups and Registration Form admin pages |
|
47 | - * default: Disabled |
|
48 | - */ |
|
49 | - public const USE_REG_FORM_BUILDER = 'use_reg_form_builder'; |
|
50 | - |
|
51 | - /** |
|
52 | - * Whether to enable the new Registration Options meta box in the EDTR |
|
53 | - * or continue using the legacy Event Registration Options |
|
54 | - * default: Disabled |
|
55 | - */ |
|
56 | - public const USE_REG_OPTIONS_META_BOX = 'use_reg_options_meta_box'; |
|
57 | - |
|
58 | - /** |
|
59 | - * Whether to enable the new Single Page Checkout form refactor changes |
|
60 | - * default: Disabled |
|
61 | - * |
|
62 | - * @since 5.0.18.p |
|
63 | - */ |
|
64 | - public const USE_SPCO_FORM_REFACTOR = 'use_spco_form_refactor'; |
|
65 | - |
|
66 | - /** |
|
67 | - * Whether to enable the new Reg Form Ticket Questions functionality |
|
68 | - * default: Disabled |
|
69 | - */ |
|
70 | - public const USE_REG_FORM_TICKET_QUESTIONS = 'use_reg_form_ticket_questions'; |
|
71 | - |
|
72 | - /** |
|
73 | - * Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins |
|
74 | - * default: Disabled |
|
75 | - */ |
|
76 | - public const USE_EDD_PLUGIN_LICENSING = 'use_edd_plugin_licensing'; |
|
77 | - |
|
78 | - /** |
|
79 | - * Whether to use the new Datetime Status Controls in the EDTR |
|
80 | - * default: Disabled |
|
81 | - */ |
|
82 | - public const USE_DATETIME_STATUS_CONTROLS = 'use_datetime_status_controls'; |
|
83 | - |
|
84 | - /** |
|
85 | - * Whether to apply Gateway Partner fees to transactions |
|
86 | - * default: Disabled |
|
87 | - */ |
|
88 | - public const USE_PAYMENT_PROCESSOR_FEES = 'use_payment_processor_fees'; |
|
89 | - |
|
90 | - |
|
91 | - public static function getFormOptions(): array |
|
92 | - { |
|
93 | - return [ |
|
94 | - FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT => [ |
|
95 | - 'name' => esc_html__('Event Editor Bulk Edit', 'event_espresso'), |
|
96 | - 'html_label_text' => esc_html__('Use Event Editor Bulk Edit', 'event_espresso'), |
|
97 | - 'help_text' => sprintf( |
|
98 | - esc_html__( |
|
99 | - 'Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR).%1$s%2$sPLEASE NOTE: Bulk Editing is ALWAYS enabled if the Recurring Events Manager add-on is active.%3$s%1$s default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - '<br/>', |
|
103 | - '<strong>', |
|
104 | - '</strong>' |
|
105 | - ), |
|
106 | - 'overridden' => false, |
|
107 | - 'overridden_by' => '', |
|
108 | - ], |
|
109 | - FeatureFlag::USE_DEFAULT_TICKET_MANAGER => [ |
|
110 | - 'name' => esc_html__('Default Ticket Manager', 'event_espresso'), |
|
111 | - 'html_label_text' => esc_html__('Use Default Ticket Manager', 'event_espresso'), |
|
112 | - 'help_text' => esc_html__( |
|
113 | - 'Whether to enable the new Default Ticket Manager in the EDTR. default: Enabled', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - 'overridden' => false, |
|
117 | - 'overridden_by' => '', |
|
118 | - ], |
|
119 | - FeatureFlag::USE_EVENT_DESCRIPTION_RTE => [ |
|
120 | - 'name' => esc_html__('Event Description RTE', 'event_espresso'), |
|
121 | - 'html_label_text' => esc_html__('Use Rich Text Editor for Event Description', 'event_espresso'), |
|
122 | - 'help_text' => esc_html__( |
|
123 | - 'Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce. default: Disabled', |
|
124 | - 'event_espresso' |
|
125 | - ), |
|
126 | - 'overridden' => false, |
|
127 | - 'overridden_by' => '', |
|
128 | - ], |
|
129 | - FeatureFlag::USE_EXPERIMENTAL_RTE => [ |
|
130 | - 'name' => esc_html__('Rich Text Editor', 'event_espresso'), |
|
131 | - 'html_label_text' => esc_html__('Use Rich Text Editor for other RTE fields', 'event_espresso'), |
|
132 | - 'help_text' => esc_html__( |
|
133 | - 'Whether to enable the Rich Text Editor for all other RTE fields in the EDTR. default: Disabled', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - 'overridden' => false, |
|
137 | - 'overridden_by' => '', |
|
138 | - ], |
|
139 | - FeatureFlag::USE_REG_FORM_BUILDER => [ |
|
140 | - 'name' => esc_html__('Registration Form Builder', 'event_espresso'), |
|
141 | - 'html_label_text' => esc_html__('Use Registration Form Builder', 'event_espresso'), |
|
142 | - 'help_text' => esc_html__( |
|
143 | - 'Whether to enable the new Registration Form Builder in the EDTR or continue using the legacy Question Groups and Registration Form admin pages. default: Disabled', |
|
144 | - 'event_espresso' |
|
145 | - ), |
|
146 | - 'overridden' => false, |
|
147 | - 'overridden_by' => '', |
|
148 | - ], |
|
149 | - FeatureFlag::USE_REG_OPTIONS_META_BOX => [ |
|
150 | - 'name' => esc_html__('Registration Options', 'event_espresso'), |
|
151 | - 'html_label_text' => esc_html__('Use Registration Options', 'event_espresso'), |
|
152 | - 'help_text' => esc_html__( |
|
153 | - 'Whether to enable the new Registration Options meta box in the EDTR or continue using the legacy Event Registration Options. default: Disabled', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - 'overridden' => false, |
|
157 | - 'overridden_by' => '', |
|
158 | - ], |
|
159 | - FeatureFlag::USE_SPCO_FORM_REFACTOR => [ |
|
160 | - 'name' => esc_html__('SPCO Form Refactor', 'event_espresso'), |
|
161 | - 'html_label_text' => esc_html__('Use SPCO Form Refactor', 'event_espresso'), |
|
162 | - 'help_text' => esc_html__( |
|
163 | - 'Whether to enable the new Single Page Checkout form refactor changes or continue using the legacy Single Page Checkout form. default: Disabled', |
|
164 | - 'event_espresso' |
|
165 | - ), |
|
166 | - 'overridden' => false, |
|
167 | - 'overridden_by' => '', |
|
168 | - ], |
|
169 | - FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => [ |
|
170 | - 'name' => esc_html__('Reg Form Ticket Questions', 'event_espresso'), |
|
171 | - 'html_label_text' => esc_html__('Use Reg Form Ticket Questions', 'event_espresso'), |
|
172 | - 'help_text' => esc_html__( |
|
173 | - 'Whether to enable the new Reg Form Ticket Questions functionality. default: Disabled', |
|
174 | - 'event_espresso' |
|
175 | - ), |
|
176 | - 'overridden' => false, |
|
177 | - 'overridden_by' => '', |
|
178 | - ], |
|
179 | - FeatureFlag::USE_EDD_PLUGIN_LICENSING => [ |
|
180 | - 'name' => esc_html__('EDD Plugin Licensing', 'event_espresso'), |
|
181 | - 'html_label_text' => esc_html__('Use EDD Plugin Licensing', 'event_espresso'), |
|
182 | - 'help_text' => esc_html__( |
|
183 | - 'Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins. default: Disabled', |
|
184 | - 'event_espresso' |
|
185 | - ), |
|
186 | - 'overridden' => defined('EE_USE_EDD_PLUGIN_LICENSING'), |
|
187 | - 'overridden_by' => defined('EE_USE_EDD_PLUGIN_LICENSING') |
|
188 | - ? sprintf( |
|
189 | - esc_html__( |
|
190 | - '%1$sCurrently overriden by the %2$s constant in wp-config.php%3$s', |
|
191 | - 'event_espresso' |
|
192 | - ), |
|
193 | - '<br><span class="ee-status--warning">', |
|
194 | - 'EE_USE_EDD_PLUGIN_LICENSING', |
|
195 | - '</span>' |
|
196 | - ) |
|
197 | - : '', |
|
198 | - ], |
|
199 | - FeatureFlag::USE_DATETIME_STATUS_CONTROLS => [ |
|
200 | - 'name' => esc_html__('Datetime Status Controls', 'event_espresso'), |
|
201 | - 'html_label_text' => esc_html__('Use Datetime Status Controls', 'event_espresso'), |
|
202 | - 'help_text' => esc_html__( |
|
203 | - 'Whether to use the new Datetime Status Controls in the EDTR. default: Disabled', |
|
204 | - 'event_espresso' |
|
205 | - ), |
|
206 | - 'overridden' => false, |
|
207 | - 'overridden_by' => '', |
|
208 | - ], |
|
209 | - FeatureFlag::USE_PAYMENT_PROCESSOR_FEES => [ |
|
210 | - 'name' => esc_html__('Gateway Partner Fees', 'event_espresso'), |
|
211 | - 'html_label_text' => esc_html__('Apply Payment Processor Fees', 'event_espresso'), |
|
212 | - 'help_text' => esc_html__( |
|
213 | - 'Whether to apply Gateway Partner fees to transactions. default: Disabled', |
|
214 | - 'event_espresso' |
|
215 | - ), |
|
216 | - 'overridden' => false, |
|
217 | - 'overridden_by' => '', |
|
218 | - ], |
|
219 | - ]; |
|
220 | - } |
|
14 | + /** |
|
15 | + * Whether to use the New Event Editor (EDTR) or continue using the legacy Event Editor |
|
16 | + * deafult: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
17 | + */ |
|
18 | + public const USE_ADVANCED_EVENT_EDITOR = 'ee_advanced_event_editor'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR) |
|
22 | + * default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs |
|
23 | + */ |
|
24 | + public const USE_EVENT_EDITOR_BULK_EDIT = 'ee_event_editor_bulk_edit'; |
|
25 | + |
|
26 | + /** |
|
27 | + * Whether to enable the new Default Ticket Manager in the EDTR |
|
28 | + * default: Enabled |
|
29 | + */ |
|
30 | + public const USE_DEFAULT_TICKET_MANAGER = 'use_default_ticket_manager'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce |
|
34 | + * default: Disabled |
|
35 | + */ |
|
36 | + public const USE_EVENT_DESCRIPTION_RTE = 'use_event_description_rte'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Whether to enable the Rich Text Editor for all other RTE fields in the EDTR |
|
40 | + * default: Disabled |
|
41 | + */ |
|
42 | + public const USE_EXPERIMENTAL_RTE = 'use_experimental_rte'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Whether to enable the new Registration Form Builder in the EDTR |
|
46 | + * or continue using the legacy Question Groups and Registration Form admin pages |
|
47 | + * default: Disabled |
|
48 | + */ |
|
49 | + public const USE_REG_FORM_BUILDER = 'use_reg_form_builder'; |
|
50 | + |
|
51 | + /** |
|
52 | + * Whether to enable the new Registration Options meta box in the EDTR |
|
53 | + * or continue using the legacy Event Registration Options |
|
54 | + * default: Disabled |
|
55 | + */ |
|
56 | + public const USE_REG_OPTIONS_META_BOX = 'use_reg_options_meta_box'; |
|
57 | + |
|
58 | + /** |
|
59 | + * Whether to enable the new Single Page Checkout form refactor changes |
|
60 | + * default: Disabled |
|
61 | + * |
|
62 | + * @since 5.0.18.p |
|
63 | + */ |
|
64 | + public const USE_SPCO_FORM_REFACTOR = 'use_spco_form_refactor'; |
|
65 | + |
|
66 | + /** |
|
67 | + * Whether to enable the new Reg Form Ticket Questions functionality |
|
68 | + * default: Disabled |
|
69 | + */ |
|
70 | + public const USE_REG_FORM_TICKET_QUESTIONS = 'use_reg_form_ticket_questions'; |
|
71 | + |
|
72 | + /** |
|
73 | + * Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins |
|
74 | + * default: Disabled |
|
75 | + */ |
|
76 | + public const USE_EDD_PLUGIN_LICENSING = 'use_edd_plugin_licensing'; |
|
77 | + |
|
78 | + /** |
|
79 | + * Whether to use the new Datetime Status Controls in the EDTR |
|
80 | + * default: Disabled |
|
81 | + */ |
|
82 | + public const USE_DATETIME_STATUS_CONTROLS = 'use_datetime_status_controls'; |
|
83 | + |
|
84 | + /** |
|
85 | + * Whether to apply Gateway Partner fees to transactions |
|
86 | + * default: Disabled |
|
87 | + */ |
|
88 | + public const USE_PAYMENT_PROCESSOR_FEES = 'use_payment_processor_fees'; |
|
89 | + |
|
90 | + |
|
91 | + public static function getFormOptions(): array |
|
92 | + { |
|
93 | + return [ |
|
94 | + FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT => [ |
|
95 | + 'name' => esc_html__('Event Editor Bulk Edit', 'event_espresso'), |
|
96 | + 'html_label_text' => esc_html__('Use Event Editor Bulk Edit', 'event_espresso'), |
|
97 | + 'help_text' => sprintf( |
|
98 | + esc_html__( |
|
99 | + 'Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR).%1$s%2$sPLEASE NOTE: Bulk Editing is ALWAYS enabled if the Recurring Events Manager add-on is active.%3$s%1$s default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + '<br/>', |
|
103 | + '<strong>', |
|
104 | + '</strong>' |
|
105 | + ), |
|
106 | + 'overridden' => false, |
|
107 | + 'overridden_by' => '', |
|
108 | + ], |
|
109 | + FeatureFlag::USE_DEFAULT_TICKET_MANAGER => [ |
|
110 | + 'name' => esc_html__('Default Ticket Manager', 'event_espresso'), |
|
111 | + 'html_label_text' => esc_html__('Use Default Ticket Manager', 'event_espresso'), |
|
112 | + 'help_text' => esc_html__( |
|
113 | + 'Whether to enable the new Default Ticket Manager in the EDTR. default: Enabled', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + 'overridden' => false, |
|
117 | + 'overridden_by' => '', |
|
118 | + ], |
|
119 | + FeatureFlag::USE_EVENT_DESCRIPTION_RTE => [ |
|
120 | + 'name' => esc_html__('Event Description RTE', 'event_espresso'), |
|
121 | + 'html_label_text' => esc_html__('Use Rich Text Editor for Event Description', 'event_espresso'), |
|
122 | + 'help_text' => esc_html__( |
|
123 | + 'Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce. default: Disabled', |
|
124 | + 'event_espresso' |
|
125 | + ), |
|
126 | + 'overridden' => false, |
|
127 | + 'overridden_by' => '', |
|
128 | + ], |
|
129 | + FeatureFlag::USE_EXPERIMENTAL_RTE => [ |
|
130 | + 'name' => esc_html__('Rich Text Editor', 'event_espresso'), |
|
131 | + 'html_label_text' => esc_html__('Use Rich Text Editor for other RTE fields', 'event_espresso'), |
|
132 | + 'help_text' => esc_html__( |
|
133 | + 'Whether to enable the Rich Text Editor for all other RTE fields in the EDTR. default: Disabled', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + 'overridden' => false, |
|
137 | + 'overridden_by' => '', |
|
138 | + ], |
|
139 | + FeatureFlag::USE_REG_FORM_BUILDER => [ |
|
140 | + 'name' => esc_html__('Registration Form Builder', 'event_espresso'), |
|
141 | + 'html_label_text' => esc_html__('Use Registration Form Builder', 'event_espresso'), |
|
142 | + 'help_text' => esc_html__( |
|
143 | + 'Whether to enable the new Registration Form Builder in the EDTR or continue using the legacy Question Groups and Registration Form admin pages. default: Disabled', |
|
144 | + 'event_espresso' |
|
145 | + ), |
|
146 | + 'overridden' => false, |
|
147 | + 'overridden_by' => '', |
|
148 | + ], |
|
149 | + FeatureFlag::USE_REG_OPTIONS_META_BOX => [ |
|
150 | + 'name' => esc_html__('Registration Options', 'event_espresso'), |
|
151 | + 'html_label_text' => esc_html__('Use Registration Options', 'event_espresso'), |
|
152 | + 'help_text' => esc_html__( |
|
153 | + 'Whether to enable the new Registration Options meta box in the EDTR or continue using the legacy Event Registration Options. default: Disabled', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + 'overridden' => false, |
|
157 | + 'overridden_by' => '', |
|
158 | + ], |
|
159 | + FeatureFlag::USE_SPCO_FORM_REFACTOR => [ |
|
160 | + 'name' => esc_html__('SPCO Form Refactor', 'event_espresso'), |
|
161 | + 'html_label_text' => esc_html__('Use SPCO Form Refactor', 'event_espresso'), |
|
162 | + 'help_text' => esc_html__( |
|
163 | + 'Whether to enable the new Single Page Checkout form refactor changes or continue using the legacy Single Page Checkout form. default: Disabled', |
|
164 | + 'event_espresso' |
|
165 | + ), |
|
166 | + 'overridden' => false, |
|
167 | + 'overridden_by' => '', |
|
168 | + ], |
|
169 | + FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => [ |
|
170 | + 'name' => esc_html__('Reg Form Ticket Questions', 'event_espresso'), |
|
171 | + 'html_label_text' => esc_html__('Use Reg Form Ticket Questions', 'event_espresso'), |
|
172 | + 'help_text' => esc_html__( |
|
173 | + 'Whether to enable the new Reg Form Ticket Questions functionality. default: Disabled', |
|
174 | + 'event_espresso' |
|
175 | + ), |
|
176 | + 'overridden' => false, |
|
177 | + 'overridden_by' => '', |
|
178 | + ], |
|
179 | + FeatureFlag::USE_EDD_PLUGIN_LICENSING => [ |
|
180 | + 'name' => esc_html__('EDD Plugin Licensing', 'event_espresso'), |
|
181 | + 'html_label_text' => esc_html__('Use EDD Plugin Licensing', 'event_espresso'), |
|
182 | + 'help_text' => esc_html__( |
|
183 | + 'Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins. default: Disabled', |
|
184 | + 'event_espresso' |
|
185 | + ), |
|
186 | + 'overridden' => defined('EE_USE_EDD_PLUGIN_LICENSING'), |
|
187 | + 'overridden_by' => defined('EE_USE_EDD_PLUGIN_LICENSING') |
|
188 | + ? sprintf( |
|
189 | + esc_html__( |
|
190 | + '%1$sCurrently overriden by the %2$s constant in wp-config.php%3$s', |
|
191 | + 'event_espresso' |
|
192 | + ), |
|
193 | + '<br><span class="ee-status--warning">', |
|
194 | + 'EE_USE_EDD_PLUGIN_LICENSING', |
|
195 | + '</span>' |
|
196 | + ) |
|
197 | + : '', |
|
198 | + ], |
|
199 | + FeatureFlag::USE_DATETIME_STATUS_CONTROLS => [ |
|
200 | + 'name' => esc_html__('Datetime Status Controls', 'event_espresso'), |
|
201 | + 'html_label_text' => esc_html__('Use Datetime Status Controls', 'event_espresso'), |
|
202 | + 'help_text' => esc_html__( |
|
203 | + 'Whether to use the new Datetime Status Controls in the EDTR. default: Disabled', |
|
204 | + 'event_espresso' |
|
205 | + ), |
|
206 | + 'overridden' => false, |
|
207 | + 'overridden_by' => '', |
|
208 | + ], |
|
209 | + FeatureFlag::USE_PAYMENT_PROCESSOR_FEES => [ |
|
210 | + 'name' => esc_html__('Gateway Partner Fees', 'event_espresso'), |
|
211 | + 'html_label_text' => esc_html__('Apply Payment Processor Fees', 'event_espresso'), |
|
212 | + 'help_text' => esc_html__( |
|
213 | + 'Whether to apply Gateway Partner fees to transactions. default: Disabled', |
|
214 | + 'event_espresso' |
|
215 | + ), |
|
216 | + 'overridden' => false, |
|
217 | + 'overridden_by' => '', |
|
218 | + ], |
|
219 | + ]; |
|
220 | + } |
|
221 | 221 | } |
@@ -17,170 +17,170 @@ |
||
17 | 17 | */ |
18 | 18 | class FeatureFlagsConfig extends JsonDataWordpressOption |
19 | 19 | { |
20 | - /** |
|
21 | - * WP option name for saving the Feature Flags configuration |
|
22 | - */ |
|
23 | - private const OPTION_NAME = 'ee_feature_flags'; |
|
24 | - |
|
25 | - /** |
|
26 | - * use FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT instead |
|
27 | - * this hasn't been deleted because it's used in the REM add-on |
|
28 | - * |
|
29 | - * @deprecated 5.0.18.p |
|
30 | - */ |
|
31 | - public const USE_EVENT_EDITOR_BULK_EDIT = FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT; |
|
32 | - |
|
33 | - private static array $removed = [ |
|
34 | - FeatureFlag::USE_ADVANCED_EVENT_EDITOR, |
|
35 | - ]; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - protected Domain $domain; |
|
40 | - |
|
41 | - private ?stdClass $feature_flags = null; |
|
42 | - |
|
43 | - |
|
44 | - public function __construct(Domain $domain, JsonDataHandler $json_data_handler) |
|
45 | - { |
|
46 | - $this->domain = $domain; |
|
47 | - parent::__construct($json_data_handler, FeatureFlagsConfig::OPTION_NAME, $this->getDefaultFeatureFlagOptions()); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * see the FeatureFlag::USE_* constants for descriptions of each feature flag and their default values |
|
53 | - * |
|
54 | - * @return stdClass |
|
55 | - */ |
|
56 | - public function getDefaultFeatureFlagOptions(): stdClass |
|
57 | - { |
|
58 | - return (object) [ |
|
59 | - FeatureFlag::USE_DATETIME_STATUS_CONTROLS => false, |
|
60 | - FeatureFlag::USE_DEFAULT_TICKET_MANAGER => true, |
|
61 | - FeatureFlag::USE_EDD_PLUGIN_LICENSING => defined('EE_USE_EDD_PLUGIN_LICENSING') |
|
62 | - && EE_USE_EDD_PLUGIN_LICENSING, |
|
63 | - FeatureFlag::USE_EVENT_DESCRIPTION_RTE => false, |
|
64 | - FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT => $this->domain->isCaffeinated() |
|
65 | - && ! $this->domain->isMultiSite(), |
|
66 | - FeatureFlag::USE_EXPERIMENTAL_RTE => false, |
|
67 | - FeatureFlag::USE_REG_FORM_BUILDER => false, |
|
68 | - FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => false, |
|
69 | - FeatureFlag::USE_REG_OPTIONS_META_BOX => false, |
|
70 | - FeatureFlag::USE_SPCO_FORM_REFACTOR => false, |
|
71 | - FeatureFlag::USE_PAYMENT_PROCESSOR_FEES => true, |
|
72 | - ]; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * feature flags that absolutely must be enabled/disabled based on hard-coded conditions |
|
78 | - * |
|
79 | - * @return stdClass |
|
80 | - * @since 5.0.20.p |
|
81 | - */ |
|
82 | - public function getOverrides(): stdClass |
|
83 | - { |
|
84 | - $overrides = []; |
|
85 | - if (defined('EE_USE_EDD_PLUGIN_LICENSING')) { |
|
86 | - $overrides[ FeatureFlag::USE_EDD_PLUGIN_LICENSING ] = EE_USE_EDD_PLUGIN_LICENSING; |
|
87 | - } |
|
88 | - return (object) $overrides; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return stdClass |
|
94 | - */ |
|
95 | - public function getFeatureFlags(): stdClass |
|
96 | - { |
|
97 | - if ($this->feature_flags) { |
|
98 | - return $this->feature_flags; |
|
99 | - } |
|
100 | - $default_options = $this->getDefaultFeatureFlagOptions(); |
|
101 | - $this->feature_flags = $this->getAll(); |
|
102 | - $overrides = $this->getOverrides(); |
|
103 | - // ensure that all feature flags are set |
|
104 | - foreach ($default_options as $key => $value) { |
|
105 | - // if the feature flag is not set, use the default value |
|
106 | - if (! isset($this->feature_flags->$key)) { |
|
107 | - $this->feature_flags->$key = $value; |
|
108 | - } |
|
109 | - // ensure that all overrides are set |
|
110 | - if (isset($overrides->$key)) { |
|
111 | - $this->feature_flags->$key = $overrides->$key; |
|
112 | - } |
|
113 | - } |
|
114 | - return $this->feature_flags; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - public function saveFeatureFlagsConfig(?stdClass $feature_flags = null): int |
|
119 | - { |
|
120 | - $feature_flags = $feature_flags ?? $this->feature_flags; |
|
121 | - foreach (FeatureFlagsConfig::$removed as $feature_flag) { |
|
122 | - unset($feature_flags->{$feature_flag}); |
|
123 | - } |
|
124 | - return $this->updateOption($feature_flags); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * enables a feature flag, ex: |
|
130 | - * $this->enableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR); |
|
131 | - * |
|
132 | - * @param string $feature_flag the feature flag to enable. One of the FeatureFlag::USE_* constants |
|
133 | - * @param bool $add_if_missing |
|
134 | - * @param bool $save |
|
135 | - * @return int |
|
136 | - */ |
|
137 | - public function enableFeatureFlag(string $feature_flag, bool $add_if_missing = false, bool $save = true): int |
|
138 | - { |
|
139 | - if (! $this->feature_flags) { |
|
140 | - $this->getFeatureFlags(); |
|
141 | - } |
|
142 | - if (! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) { |
|
143 | - return WordPressOption::UPDATE_ERROR; |
|
144 | - } |
|
145 | - $this->feature_flags->{$feature_flag} = true; |
|
146 | - // if feature flag is the advanced event editor bulk edit options |
|
147 | - // then only enabled if the site is Caffeinated and not MultiSite |
|
148 | - if ( $feature_flag === FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT ) { |
|
149 | - $this->feature_flags->{$feature_flag} = $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(); |
|
150 | - } |
|
151 | - if ($save) { |
|
152 | - return $this->saveFeatureFlagsConfig($this->feature_flags); |
|
153 | - } |
|
154 | - return WordPressOption::UPDATE_NONE; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * disables a feature flag, ex: |
|
160 | - * $this->disableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR); |
|
161 | - * |
|
162 | - * @param string $feature_flag the feature flag to disable. One of the FeatureFlag::USE_* constants |
|
163 | - * @param bool $save |
|
164 | - * @return int |
|
165 | - */ |
|
166 | - public function disableFeatureFlag(string $feature_flag, bool $save = true): int |
|
167 | - { |
|
168 | - if (! $this->feature_flags) { |
|
169 | - $this->getFeatureFlags(); |
|
170 | - } |
|
171 | - if (! property_exists($this->feature_flags, $feature_flag)) { |
|
172 | - return WordPressOption::UPDATE_ERROR; |
|
173 | - } |
|
174 | - $this->feature_flags->{$feature_flag} = false; |
|
175 | - if ($save) { |
|
176 | - return $this->saveFeatureFlagsConfig($this->feature_flags); |
|
177 | - } |
|
178 | - return WordPressOption::UPDATE_NONE; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - public function getFeatureFlagsFormOptions(): ?array |
|
183 | - { |
|
184 | - return FeatureFlag::getFormOptions(); |
|
185 | - } |
|
20 | + /** |
|
21 | + * WP option name for saving the Feature Flags configuration |
|
22 | + */ |
|
23 | + private const OPTION_NAME = 'ee_feature_flags'; |
|
24 | + |
|
25 | + /** |
|
26 | + * use FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT instead |
|
27 | + * this hasn't been deleted because it's used in the REM add-on |
|
28 | + * |
|
29 | + * @deprecated 5.0.18.p |
|
30 | + */ |
|
31 | + public const USE_EVENT_EDITOR_BULK_EDIT = FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT; |
|
32 | + |
|
33 | + private static array $removed = [ |
|
34 | + FeatureFlag::USE_ADVANCED_EVENT_EDITOR, |
|
35 | + ]; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + protected Domain $domain; |
|
40 | + |
|
41 | + private ?stdClass $feature_flags = null; |
|
42 | + |
|
43 | + |
|
44 | + public function __construct(Domain $domain, JsonDataHandler $json_data_handler) |
|
45 | + { |
|
46 | + $this->domain = $domain; |
|
47 | + parent::__construct($json_data_handler, FeatureFlagsConfig::OPTION_NAME, $this->getDefaultFeatureFlagOptions()); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * see the FeatureFlag::USE_* constants for descriptions of each feature flag and their default values |
|
53 | + * |
|
54 | + * @return stdClass |
|
55 | + */ |
|
56 | + public function getDefaultFeatureFlagOptions(): stdClass |
|
57 | + { |
|
58 | + return (object) [ |
|
59 | + FeatureFlag::USE_DATETIME_STATUS_CONTROLS => false, |
|
60 | + FeatureFlag::USE_DEFAULT_TICKET_MANAGER => true, |
|
61 | + FeatureFlag::USE_EDD_PLUGIN_LICENSING => defined('EE_USE_EDD_PLUGIN_LICENSING') |
|
62 | + && EE_USE_EDD_PLUGIN_LICENSING, |
|
63 | + FeatureFlag::USE_EVENT_DESCRIPTION_RTE => false, |
|
64 | + FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT => $this->domain->isCaffeinated() |
|
65 | + && ! $this->domain->isMultiSite(), |
|
66 | + FeatureFlag::USE_EXPERIMENTAL_RTE => false, |
|
67 | + FeatureFlag::USE_REG_FORM_BUILDER => false, |
|
68 | + FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => false, |
|
69 | + FeatureFlag::USE_REG_OPTIONS_META_BOX => false, |
|
70 | + FeatureFlag::USE_SPCO_FORM_REFACTOR => false, |
|
71 | + FeatureFlag::USE_PAYMENT_PROCESSOR_FEES => true, |
|
72 | + ]; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * feature flags that absolutely must be enabled/disabled based on hard-coded conditions |
|
78 | + * |
|
79 | + * @return stdClass |
|
80 | + * @since 5.0.20.p |
|
81 | + */ |
|
82 | + public function getOverrides(): stdClass |
|
83 | + { |
|
84 | + $overrides = []; |
|
85 | + if (defined('EE_USE_EDD_PLUGIN_LICENSING')) { |
|
86 | + $overrides[ FeatureFlag::USE_EDD_PLUGIN_LICENSING ] = EE_USE_EDD_PLUGIN_LICENSING; |
|
87 | + } |
|
88 | + return (object) $overrides; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return stdClass |
|
94 | + */ |
|
95 | + public function getFeatureFlags(): stdClass |
|
96 | + { |
|
97 | + if ($this->feature_flags) { |
|
98 | + return $this->feature_flags; |
|
99 | + } |
|
100 | + $default_options = $this->getDefaultFeatureFlagOptions(); |
|
101 | + $this->feature_flags = $this->getAll(); |
|
102 | + $overrides = $this->getOverrides(); |
|
103 | + // ensure that all feature flags are set |
|
104 | + foreach ($default_options as $key => $value) { |
|
105 | + // if the feature flag is not set, use the default value |
|
106 | + if (! isset($this->feature_flags->$key)) { |
|
107 | + $this->feature_flags->$key = $value; |
|
108 | + } |
|
109 | + // ensure that all overrides are set |
|
110 | + if (isset($overrides->$key)) { |
|
111 | + $this->feature_flags->$key = $overrides->$key; |
|
112 | + } |
|
113 | + } |
|
114 | + return $this->feature_flags; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + public function saveFeatureFlagsConfig(?stdClass $feature_flags = null): int |
|
119 | + { |
|
120 | + $feature_flags = $feature_flags ?? $this->feature_flags; |
|
121 | + foreach (FeatureFlagsConfig::$removed as $feature_flag) { |
|
122 | + unset($feature_flags->{$feature_flag}); |
|
123 | + } |
|
124 | + return $this->updateOption($feature_flags); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * enables a feature flag, ex: |
|
130 | + * $this->enableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR); |
|
131 | + * |
|
132 | + * @param string $feature_flag the feature flag to enable. One of the FeatureFlag::USE_* constants |
|
133 | + * @param bool $add_if_missing |
|
134 | + * @param bool $save |
|
135 | + * @return int |
|
136 | + */ |
|
137 | + public function enableFeatureFlag(string $feature_flag, bool $add_if_missing = false, bool $save = true): int |
|
138 | + { |
|
139 | + if (! $this->feature_flags) { |
|
140 | + $this->getFeatureFlags(); |
|
141 | + } |
|
142 | + if (! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) { |
|
143 | + return WordPressOption::UPDATE_ERROR; |
|
144 | + } |
|
145 | + $this->feature_flags->{$feature_flag} = true; |
|
146 | + // if feature flag is the advanced event editor bulk edit options |
|
147 | + // then only enabled if the site is Caffeinated and not MultiSite |
|
148 | + if ( $feature_flag === FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT ) { |
|
149 | + $this->feature_flags->{$feature_flag} = $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(); |
|
150 | + } |
|
151 | + if ($save) { |
|
152 | + return $this->saveFeatureFlagsConfig($this->feature_flags); |
|
153 | + } |
|
154 | + return WordPressOption::UPDATE_NONE; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * disables a feature flag, ex: |
|
160 | + * $this->disableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR); |
|
161 | + * |
|
162 | + * @param string $feature_flag the feature flag to disable. One of the FeatureFlag::USE_* constants |
|
163 | + * @param bool $save |
|
164 | + * @return int |
|
165 | + */ |
|
166 | + public function disableFeatureFlag(string $feature_flag, bool $save = true): int |
|
167 | + { |
|
168 | + if (! $this->feature_flags) { |
|
169 | + $this->getFeatureFlags(); |
|
170 | + } |
|
171 | + if (! property_exists($this->feature_flags, $feature_flag)) { |
|
172 | + return WordPressOption::UPDATE_ERROR; |
|
173 | + } |
|
174 | + $this->feature_flags->{$feature_flag} = false; |
|
175 | + if ($save) { |
|
176 | + return $this->saveFeatureFlagsConfig($this->feature_flags); |
|
177 | + } |
|
178 | + return WordPressOption::UPDATE_NONE; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + public function getFeatureFlagsFormOptions(): ?array |
|
183 | + { |
|
184 | + return FeatureFlag::getFormOptions(); |
|
185 | + } |
|
186 | 186 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | { |
84 | 84 | $overrides = []; |
85 | 85 | if (defined('EE_USE_EDD_PLUGIN_LICENSING')) { |
86 | - $overrides[ FeatureFlag::USE_EDD_PLUGIN_LICENSING ] = EE_USE_EDD_PLUGIN_LICENSING; |
|
86 | + $overrides[FeatureFlag::USE_EDD_PLUGIN_LICENSING] = EE_USE_EDD_PLUGIN_LICENSING; |
|
87 | 87 | } |
88 | 88 | return (object) $overrides; |
89 | 89 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | // ensure that all feature flags are set |
104 | 104 | foreach ($default_options as $key => $value) { |
105 | 105 | // if the feature flag is not set, use the default value |
106 | - if (! isset($this->feature_flags->$key)) { |
|
106 | + if ( ! isset($this->feature_flags->$key)) { |
|
107 | 107 | $this->feature_flags->$key = $value; |
108 | 108 | } |
109 | 109 | // ensure that all overrides are set |
@@ -136,16 +136,16 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function enableFeatureFlag(string $feature_flag, bool $add_if_missing = false, bool $save = true): int |
138 | 138 | { |
139 | - if (! $this->feature_flags) { |
|
139 | + if ( ! $this->feature_flags) { |
|
140 | 140 | $this->getFeatureFlags(); |
141 | 141 | } |
142 | - if (! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) { |
|
142 | + if ( ! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) { |
|
143 | 143 | return WordPressOption::UPDATE_ERROR; |
144 | 144 | } |
145 | 145 | $this->feature_flags->{$feature_flag} = true; |
146 | 146 | // if feature flag is the advanced event editor bulk edit options |
147 | 147 | // then only enabled if the site is Caffeinated and not MultiSite |
148 | - if ( $feature_flag === FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT ) { |
|
148 | + if ($feature_flag === FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT) { |
|
149 | 149 | $this->feature_flags->{$feature_flag} = $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(); |
150 | 150 | } |
151 | 151 | if ($save) { |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function disableFeatureFlag(string $feature_flag, bool $save = true): int |
167 | 167 | { |
168 | - if (! $this->feature_flags) { |
|
168 | + if ( ! $this->feature_flags) { |
|
169 | 169 | $this->getFeatureFlags(); |
170 | 170 | } |
171 | - if (! property_exists($this->feature_flags, $feature_flag)) { |
|
171 | + if ( ! property_exists($this->feature_flags, $feature_flag)) { |
|
172 | 172 | return WordPressOption::UPDATE_ERROR; |
173 | 173 | } |
174 | 174 | $this->feature_flags->{$feature_flag} = false; |
@@ -29,164 +29,164 @@ |
||
29 | 29 | class CoreAssetManager extends AssetManager |
30 | 30 | { |
31 | 31 | |
32 | - // WordPress core / Third party JS asset handles |
|
33 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
34 | - |
|
35 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
36 | - |
|
37 | - const JS_HANDLE_I18N = 'eei18n'; |
|
38 | - |
|
39 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
40 | - |
|
41 | - const JS_HANDLE_RAMDA = 'ramda'; |
|
42 | - |
|
43 | - const RAMDA_VERSION = '0.27.1'; |
|
44 | - |
|
45 | - // EE CSS assets handles |
|
46 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
47 | - |
|
48 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var EE_Currency_Config $currency_config |
|
52 | - */ |
|
53 | - protected $currency_config; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var EE_Template_Config $template_config |
|
57 | - */ |
|
58 | - protected $template_config; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * CoreAssetRegister constructor. |
|
63 | - * |
|
64 | - * @param AssetCollection $assets |
|
65 | - * @param EE_Currency_Config $currency_config |
|
66 | - * @param EE_Template_Config $template_config |
|
67 | - * @param DomainInterface $domain |
|
68 | - * @param Registry $registry |
|
69 | - */ |
|
70 | - public function __construct( |
|
71 | - AssetCollection $assets, |
|
72 | - EE_Currency_Config $currency_config, |
|
73 | - EE_Template_Config $template_config, |
|
74 | - DomainInterface $domain, |
|
75 | - Registry $registry |
|
76 | - ) { |
|
77 | - $this->currency_config = $currency_config; |
|
78 | - $this->template_config = $template_config; |
|
79 | - parent::__construct($domain, $assets, $registry); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @throws DomainException |
|
85 | - * @throws DuplicateCollectionIdentifierException |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * @throws InvalidDataTypeException |
|
88 | - * @throws InvalidEntityException |
|
89 | - * @throws InvalidInterfaceException |
|
90 | - * @since 4.9.62.p |
|
91 | - */ |
|
92 | - public function addAssets() |
|
93 | - { |
|
94 | - $this->addJavascriptFiles(); |
|
95 | - $this->addStylesheetFiles(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @throws DomainException |
|
101 | - * @throws DuplicateCollectionIdentifierException |
|
102 | - * @throws InvalidArgumentException |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - * @throws InvalidEntityException |
|
105 | - * @throws InvalidInterfaceException |
|
106 | - * @since 4.9.62.p |
|
107 | - */ |
|
108 | - public function addJavascriptFiles() |
|
109 | - { |
|
110 | - $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
111 | - $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
112 | - $this->addJavascript( |
|
113 | - CoreAssetManager::JS_HANDLE_CORE, |
|
114 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
115 | - [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
116 | - )->setInlineDataCallback( |
|
117 | - function () { |
|
118 | - wp_localize_script( |
|
119 | - CoreAssetManager::JS_HANDLE_CORE, |
|
120 | - CoreAssetManager::JS_HANDLE_I18N, |
|
121 | - EE_Registry::sanitize_i18n_js_strings() |
|
122 | - ); |
|
123 | - } |
|
124 | - ); |
|
125 | - $this->loadQtipJs(); |
|
126 | - $this->addVendorJavascript( |
|
127 | - CoreAssetManager::JS_HANDLE_RAMDA, |
|
128 | - [], |
|
129 | - true, |
|
130 | - CoreAssetManager::RAMDA_VERSION |
|
131 | - ); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @throws DuplicateCollectionIdentifierException |
|
137 | - * @throws InvalidDataTypeException |
|
138 | - * @throws InvalidEntityException |
|
139 | - * @throws DomainException |
|
140 | - * @since 4.9.62.p |
|
141 | - */ |
|
142 | - public function addStylesheetFiles() |
|
143 | - { |
|
144 | - if (! is_admin()) { |
|
145 | - $this->addStylesheet( |
|
146 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
147 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
148 | - ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
149 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
150 | - ['dashicons'] |
|
151 | - ); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Returns configuration data for the js Currency VO. |
|
158 | - * |
|
159 | - * @return array |
|
160 | - * @since 4.9.71.p |
|
161 | - */ |
|
162 | - private function getCurrencySettings() |
|
163 | - { |
|
164 | - return [ |
|
165 | - 'code' => $this->currency_config->code, |
|
166 | - 'singularLabel' => $this->currency_config->name, |
|
167 | - 'pluralLabel' => $this->currency_config->plural, |
|
168 | - 'sign' => $this->currency_config->sign, |
|
169 | - 'signB4' => $this->currency_config->sign_b4, |
|
170 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
171 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
172 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
173 | - ]; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * replacement: |
|
179 | - * EventEspresso\core\domain\services\assets\EspressoLegacyAdminAssetManager::loadQtipJs() |
|
180 | - * |
|
181 | - * @param JavascriptAsset $script |
|
182 | - * @deprecated 5.0.0.p |
|
183 | - */ |
|
184 | - public function loadQtipJs(JavascriptAsset $script = null) |
|
185 | - { |
|
186 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
187 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
188 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
189 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
190 | - } |
|
191 | - } |
|
32 | + // WordPress core / Third party JS asset handles |
|
33 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
34 | + |
|
35 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
36 | + |
|
37 | + const JS_HANDLE_I18N = 'eei18n'; |
|
38 | + |
|
39 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
40 | + |
|
41 | + const JS_HANDLE_RAMDA = 'ramda'; |
|
42 | + |
|
43 | + const RAMDA_VERSION = '0.27.1'; |
|
44 | + |
|
45 | + // EE CSS assets handles |
|
46 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
47 | + |
|
48 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var EE_Currency_Config $currency_config |
|
52 | + */ |
|
53 | + protected $currency_config; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var EE_Template_Config $template_config |
|
57 | + */ |
|
58 | + protected $template_config; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * CoreAssetRegister constructor. |
|
63 | + * |
|
64 | + * @param AssetCollection $assets |
|
65 | + * @param EE_Currency_Config $currency_config |
|
66 | + * @param EE_Template_Config $template_config |
|
67 | + * @param DomainInterface $domain |
|
68 | + * @param Registry $registry |
|
69 | + */ |
|
70 | + public function __construct( |
|
71 | + AssetCollection $assets, |
|
72 | + EE_Currency_Config $currency_config, |
|
73 | + EE_Template_Config $template_config, |
|
74 | + DomainInterface $domain, |
|
75 | + Registry $registry |
|
76 | + ) { |
|
77 | + $this->currency_config = $currency_config; |
|
78 | + $this->template_config = $template_config; |
|
79 | + parent::__construct($domain, $assets, $registry); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @throws DomainException |
|
85 | + * @throws DuplicateCollectionIdentifierException |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * @throws InvalidDataTypeException |
|
88 | + * @throws InvalidEntityException |
|
89 | + * @throws InvalidInterfaceException |
|
90 | + * @since 4.9.62.p |
|
91 | + */ |
|
92 | + public function addAssets() |
|
93 | + { |
|
94 | + $this->addJavascriptFiles(); |
|
95 | + $this->addStylesheetFiles(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @throws DomainException |
|
101 | + * @throws DuplicateCollectionIdentifierException |
|
102 | + * @throws InvalidArgumentException |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + * @throws InvalidEntityException |
|
105 | + * @throws InvalidInterfaceException |
|
106 | + * @since 4.9.62.p |
|
107 | + */ |
|
108 | + public function addJavascriptFiles() |
|
109 | + { |
|
110 | + $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
111 | + $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
112 | + $this->addJavascript( |
|
113 | + CoreAssetManager::JS_HANDLE_CORE, |
|
114 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
115 | + [JqueryAssetManager::JS_HANDLE_JQUERY] |
|
116 | + )->setInlineDataCallback( |
|
117 | + function () { |
|
118 | + wp_localize_script( |
|
119 | + CoreAssetManager::JS_HANDLE_CORE, |
|
120 | + CoreAssetManager::JS_HANDLE_I18N, |
|
121 | + EE_Registry::sanitize_i18n_js_strings() |
|
122 | + ); |
|
123 | + } |
|
124 | + ); |
|
125 | + $this->loadQtipJs(); |
|
126 | + $this->addVendorJavascript( |
|
127 | + CoreAssetManager::JS_HANDLE_RAMDA, |
|
128 | + [], |
|
129 | + true, |
|
130 | + CoreAssetManager::RAMDA_VERSION |
|
131 | + ); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @throws DuplicateCollectionIdentifierException |
|
137 | + * @throws InvalidDataTypeException |
|
138 | + * @throws InvalidEntityException |
|
139 | + * @throws DomainException |
|
140 | + * @since 4.9.62.p |
|
141 | + */ |
|
142 | + public function addStylesheetFiles() |
|
143 | + { |
|
144 | + if (! is_admin()) { |
|
145 | + $this->addStylesheet( |
|
146 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
147 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
148 | + ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
149 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
150 | + ['dashicons'] |
|
151 | + ); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Returns configuration data for the js Currency VO. |
|
158 | + * |
|
159 | + * @return array |
|
160 | + * @since 4.9.71.p |
|
161 | + */ |
|
162 | + private function getCurrencySettings() |
|
163 | + { |
|
164 | + return [ |
|
165 | + 'code' => $this->currency_config->code, |
|
166 | + 'singularLabel' => $this->currency_config->name, |
|
167 | + 'pluralLabel' => $this->currency_config->plural, |
|
168 | + 'sign' => $this->currency_config->sign, |
|
169 | + 'signB4' => $this->currency_config->sign_b4, |
|
170 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
171 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
172 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
173 | + ]; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * replacement: |
|
179 | + * EventEspresso\core\domain\services\assets\EspressoLegacyAdminAssetManager::loadQtipJs() |
|
180 | + * |
|
181 | + * @param JavascriptAsset $script |
|
182 | + * @deprecated 5.0.0.p |
|
183 | + */ |
|
184 | + public function loadQtipJs(JavascriptAsset $script = null) |
|
185 | + { |
|
186 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
187 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
188 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
189 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
190 | + } |
|
191 | + } |
|
192 | 192 | } |
@@ -10,55 +10,55 @@ |
||
10 | 10 | class LicenseData |
11 | 11 | { |
12 | 12 | |
13 | - public const LICENSE_ACTIVE = 'active'; |
|
13 | + public const LICENSE_ACTIVE = 'active'; |
|
14 | 14 | |
15 | - public const LICENSE_DECAF = 'decaf'; |
|
15 | + public const LICENSE_DECAF = 'decaf'; |
|
16 | 16 | |
17 | - public const LICENSE_EXPIRED = 'expired'; |
|
17 | + public const LICENSE_EXPIRED = 'expired'; |
|
18 | 18 | |
19 | - public const LICENSE_VALID = 'valid'; |
|
19 | + public const LICENSE_VALID = 'valid'; |
|
20 | 20 | |
21 | 21 | |
22 | - private Domain $domain; |
|
22 | + private Domain $domain; |
|
23 | 23 | |
24 | - private FeatureFlags $feature; |
|
25 | - private LicenseDataStrategy $license_data; |
|
24 | + private FeatureFlags $feature; |
|
25 | + private LicenseDataStrategy $license_data; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @param Domain $domain |
|
30 | - * @param FeatureFlags $feature |
|
31 | - */ |
|
32 | - public function __construct(Domain $domain, FeatureFlags $feature) |
|
33 | - { |
|
34 | - $this->domain = $domain; |
|
35 | - $this->feature = $feature; |
|
36 | - $this->license_data = $this->feature->allowed(FeatureFlag::USE_EDD_PLUGIN_LICENSING) |
|
37 | - ? LoaderFactory::getShared(LicenseDataEDD::class) |
|
38 | - : LoaderFactory::getShared(LicenseDataPue::class); |
|
39 | - $this->license_data->loadLicenseData(); |
|
40 | - } |
|
28 | + /** |
|
29 | + * @param Domain $domain |
|
30 | + * @param FeatureFlags $feature |
|
31 | + */ |
|
32 | + public function __construct(Domain $domain, FeatureFlags $feature) |
|
33 | + { |
|
34 | + $this->domain = $domain; |
|
35 | + $this->feature = $feature; |
|
36 | + $this->license_data = $this->feature->allowed(FeatureFlag::USE_EDD_PLUGIN_LICENSING) |
|
37 | + ? LoaderFactory::getShared(LicenseDataEDD::class) |
|
38 | + : LoaderFactory::getShared(LicenseDataPue::class); |
|
39 | + $this->license_data->loadLicenseData(); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @return bool |
|
46 | - * @since 5.0.22.p |
|
47 | - */ |
|
48 | - protected function isDecaf(): bool |
|
49 | - { |
|
50 | - return ! $this->domain->isDecaf(); |
|
51 | - } |
|
44 | + /** |
|
45 | + * @return bool |
|
46 | + * @since 5.0.22.p |
|
47 | + */ |
|
48 | + protected function isDecaf(): bool |
|
49 | + { |
|
50 | + return ! $this->domain->isDecaf(); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - public function licenseStatus(): string |
|
55 | - { |
|
56 | - return ! $this->domain->isDecaf() ? $this->license_data->getLicenseStatus() : LicenseData::LICENSE_DECAF; |
|
57 | - } |
|
54 | + public function licenseStatus(): string |
|
55 | + { |
|
56 | + return ! $this->domain->isDecaf() ? $this->license_data->getLicenseStatus() : LicenseData::LICENSE_DECAF; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - public function licenseExpiry(): string |
|
61 | - { |
|
62 | - return ! $this->isDecaf() ? $this->license_data->getLicenseExpiry() : ''; |
|
63 | - } |
|
60 | + public function licenseExpiry(): string |
|
61 | + { |
|
62 | + return ! $this->isDecaf() ? $this->license_data->getLicenseExpiry() : ''; |
|
63 | + } |
|
64 | 64 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | |
54 | 54 | public function licenseStatus(): string |
55 | 55 | { |
56 | - return ! $this->domain->isDecaf() ? $this->license_data->getLicenseStatus() : LicenseData::LICENSE_DECAF; |
|
56 | + return ! $this->domain->isDecaf() ? $this->license_data->getLicenseStatus() : LicenseData::LICENSE_DECAF; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 |
@@ -16,45 +16,45 @@ |
||
16 | 16 | class LicenseDataEDD implements LicenseDataStrategy |
17 | 17 | { |
18 | 18 | |
19 | - private LicenseKeyData $license_key_data; |
|
19 | + private LicenseKeyData $license_key_data; |
|
20 | 20 | |
21 | - private string $status; |
|
21 | + private string $status; |
|
22 | 22 | |
23 | - private string $expiry; |
|
23 | + private string $expiry; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @param LicenseKeyData $license_key_data |
|
28 | - */ |
|
29 | - public function __construct(LicenseKeyData $license_key_data) |
|
30 | - { |
|
31 | - $this->license_key_data = $license_key_data; |
|
32 | - } |
|
26 | + /** |
|
27 | + * @param LicenseKeyData $license_key_data |
|
28 | + */ |
|
29 | + public function __construct(LicenseKeyData $license_key_data) |
|
30 | + { |
|
31 | + $this->license_key_data = $license_key_data; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - public function loadLicenseData() |
|
36 | - { |
|
37 | - $license_data = $this->license_key_data->getLicenseDataForPlugin(Domain::pluginSlug()); |
|
38 | - if (! isset($license_data->license)) { |
|
39 | - $this->status = LicenseData::LICENSE_EXPIRED; |
|
40 | - $this->expiry = ''; |
|
41 | - return; |
|
42 | - } |
|
43 | - $this->status = $license_data->license_key && $license_data->license === LicenseData::LICENSE_VALID |
|
44 | - ? LicenseData::LICENSE_ACTIVE |
|
45 | - : LicenseData::LICENSE_EXPIRED; |
|
46 | - $this->expiry = $license_data->expires ?? ''; |
|
47 | - } |
|
35 | + public function loadLicenseData() |
|
36 | + { |
|
37 | + $license_data = $this->license_key_data->getLicenseDataForPlugin(Domain::pluginSlug()); |
|
38 | + if (! isset($license_data->license)) { |
|
39 | + $this->status = LicenseData::LICENSE_EXPIRED; |
|
40 | + $this->expiry = ''; |
|
41 | + return; |
|
42 | + } |
|
43 | + $this->status = $license_data->license_key && $license_data->license === LicenseData::LICENSE_VALID |
|
44 | + ? LicenseData::LICENSE_ACTIVE |
|
45 | + : LicenseData::LICENSE_EXPIRED; |
|
46 | + $this->expiry = $license_data->expires ?? ''; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - public function getLicenseStatus(): string |
|
51 | - { |
|
52 | - return $this->status; |
|
53 | - } |
|
50 | + public function getLicenseStatus(): string |
|
51 | + { |
|
52 | + return $this->status; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - public function getLicenseExpiry(): string |
|
57 | - { |
|
58 | - return $this->expiry; |
|
59 | - } |
|
56 | + public function getLicenseExpiry(): string |
|
57 | + { |
|
58 | + return $this->expiry; |
|
59 | + } |
|
60 | 60 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | public function loadLicenseData() |
36 | 36 | { |
37 | 37 | $license_data = $this->license_key_data->getLicenseDataForPlugin(Domain::pluginSlug()); |
38 | - if (! isset($license_data->license)) { |
|
38 | + if ( ! isset($license_data->license)) { |
|
39 | 39 | $this->status = LicenseData::LICENSE_EXPIRED; |
40 | 40 | $this->expiry = ''; |
41 | 41 | return; |
@@ -14,39 +14,39 @@ |
||
14 | 14 | */ |
15 | 15 | class LicenseDataPue implements LicenseDataStrategy |
16 | 16 | { |
17 | - private string $status; |
|
17 | + private string $status; |
|
18 | 18 | |
19 | - protected EE_Network_Core_Config $network_core_config; |
|
19 | + protected EE_Network_Core_Config $network_core_config; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param EE_Network_Core_Config $network_core_config |
|
24 | - */ |
|
25 | - public function __construct(EE_Network_Core_Config $network_core_config) |
|
26 | - { |
|
27 | - $this->network_core_config = $network_core_config; |
|
28 | - } |
|
22 | + /** |
|
23 | + * @param EE_Network_Core_Config $network_core_config |
|
24 | + */ |
|
25 | + public function __construct(EE_Network_Core_Config $network_core_config) |
|
26 | + { |
|
27 | + $this->network_core_config = $network_core_config; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - public function loadLicenseData(): void |
|
32 | - { |
|
33 | - if (empty($this->network_core_config->site_license_key)) { |
|
34 | - $this->status = LicenseData::LICENSE_EXPIRED; |
|
35 | - return; |
|
36 | - } |
|
37 | - $verify_fail = get_option('puvererr_' . basename(EE_PLUGIN_BASENAME), false); |
|
38 | - $this->status = $verify_fail ? LicenseData::LICENSE_EXPIRED : LicenseData::LICENSE_ACTIVE; |
|
39 | - } |
|
31 | + public function loadLicenseData(): void |
|
32 | + { |
|
33 | + if (empty($this->network_core_config->site_license_key)) { |
|
34 | + $this->status = LicenseData::LICENSE_EXPIRED; |
|
35 | + return; |
|
36 | + } |
|
37 | + $verify_fail = get_option('puvererr_' . basename(EE_PLUGIN_BASENAME), false); |
|
38 | + $this->status = $verify_fail ? LicenseData::LICENSE_EXPIRED : LicenseData::LICENSE_ACTIVE; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - public function getLicenseStatus(): string |
|
43 | - { |
|
44 | - return $this->status; |
|
45 | - } |
|
42 | + public function getLicenseStatus(): string |
|
43 | + { |
|
44 | + return $this->status; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - public function getLicenseExpiry(): string |
|
49 | - { |
|
50 | - return ''; |
|
51 | - } |
|
48 | + public function getLicenseExpiry(): string |
|
49 | + { |
|
50 | + return ''; |
|
51 | + } |
|
52 | 52 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | $this->status = LicenseData::LICENSE_EXPIRED; |
35 | 35 | return; |
36 | 36 | } |
37 | - $verify_fail = get_option('puvererr_' . basename(EE_PLUGIN_BASENAME), false); |
|
37 | + $verify_fail = get_option('puvererr_'.basename(EE_PLUGIN_BASENAME), false); |
|
38 | 38 | $this->status = $verify_fail ? LicenseData::LICENSE_EXPIRED : LicenseData::LICENSE_ACTIVE; |
39 | 39 | } |
40 | 40 |