Completed
Branch master (7421d0)
by
unknown
11:25 queued 06:55
created
libraries/messages/data_class/EE_Messages_Preview_incoming_data.class.php 1 patch
Indentation   +599 added lines, -599 removed lines patch added patch discarded remove patch
@@ -21,603 +21,603 @@
 block discarded – undo
21 21
  */
22 22
 class EE_Messages_Preview_incoming_data extends EE_Messages_incoming_data
23 23
 {
24
-    // some specific properties we need for this class
25
-    private $_events        = [];
26
-
27
-    private $_attendees     = [];
28
-
29
-    private $_registrations = [];
30
-
31
-
32
-    /**
33
-     * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
34
-     * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
35
-     * we'll get the first three published events from the users database and use that as a source.
36
-     *
37
-     * @param array $data
38
-     * @throws EE_Error
39
-     * @throws EE_Error
40
-     * @throws ReflectionException
41
-     */
42
-    public function __construct($data = [])
43
-    {
44
-        $this->_data = isset($data['event_ids']) ? $data['event_ids'] : [];
45
-        $this->_setup_attendees_events();
46
-        parent::__construct($data);
47
-    }
48
-
49
-
50
-    /**
51
-     * Returns database safe representation of the data later used to when instantiating this object.
52
-     *
53
-     * @param array $data The incoming data to be prepped.
54
-     *
55
-     * @return array   The prepped data for db
56
-     */
57
-    public static function convert_data_for_persistent_storage($data)
58
-    {
59
-        return $data;
60
-    }
61
-
62
-
63
-    /**
64
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
65
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
66
-     *
67
-     * @param array $data
68
-     *
69
-     * @return array
70
-     */
71
-    public static function convert_data_from_persistent_storage($data)
72
-    {
73
-        return $data;
74
-    }
75
-
76
-
77
-    /**
78
-     * This will just setup the _events property in the expected format.
79
-     *
80
-     * @throws EE_Error
81
-     * @throws ReflectionException
82
-     */
83
-    private function _setup_attendees_events()
84
-    {
85
-
86
-        // setup some attendee objects
87
-        $attendees = $this->_get_some_attendees();
88
-
89
-        // if empty $data we'll do a query to get some events from the server.
90
-        // otherwise we'll retrieve the event data for the given ids.
91
-        $events = $this->_get_some_events($this->_data);
92
-
93
-        $answers_n_questions = $this->_get_some_q_and_as();
94
-
95
-        if (count($events) < 1) {
96
-            throw new EE_Error(
97
-                esc_html__(
98
-                    'We can\'t generate a preview for you because there are no active events in your database',
99
-                    'event_espresso'
100
-                )
101
-            );
102
-        }
103
-
104
-
105
-        // now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
106
-        // we'll actually use the generated line_item identifiers for our loop
107
-        $dtts = $tkts = [];
108
-        foreach ($events as $id => $event) {
109
-            if (! $event instanceof EE_Event) {
110
-                continue;
111
-            }
112
-            $this->_events[ $id ]['ID']       = $id;
113
-            $this->_events[ $id ]['name']     = $event->get('EVT_name');
114
-            $datetime                         = $event->get_first_related('Datetime');
115
-            $tickets                          = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
116
-                'Ticket',
117
-                ['default_where_conditions' => 'none']
118
-            ) : [];
119
-            $this->_events[ $id ]['event']    = $event;
120
-            $this->_events[ $id ]['reg_objs'] = [];
121
-            $this->_events[ $id ]['tkt_objs'] = $tickets;
122
-            $this->_events[ $id ]['dtt_objs'] = [];
123
-
124
-            $tkts     = [];
125
-            foreach ($tickets as $ticket) {
126
-                if (! $ticket instanceof EE_Ticket) {
127
-                    continue;
128
-                }
129
-                $reldatetime                       = $ticket->datetimes();
130
-                $tkts[ $ticket->ID() ]             = [];
131
-                $tkts[ $ticket->ID() ]['ticket']   = $ticket;
132
-                $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
133
-                $tkts[ $ticket->ID() ]['att_objs'] = $attendees;
134
-                $tkts[ $ticket->ID() ]['count']    = count($attendees);
135
-                $tkts[ $ticket->ID() ]['EE_Event'] = $event;
136
-                foreach ($reldatetime as $datetime) {
137
-                    if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
138
-                        $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
139
-                        $dtts[ $datetime->ID() ]['datetime']                 = $datetime;
140
-                        $dtts[ $datetime->ID() ]['tkt_objs'][]               = $ticket;
141
-                        $dtts[ $datetime->ID() ]['evt_objs'][]               = $event;
142
-                    }
143
-                }
144
-            }
145
-
146
-            $this->_events[ $id ]['total_attendees'] = count($attendees);
147
-            $this->_events[ $id ]['att_objs']        = $attendees;
148
-
149
-            // let's also setup the dummy attendees property!
150
-            foreach ($attendees as $att_key => $attendee) {
151
-                if (! $attendee instanceof EE_Attendee) {
152
-                    continue;
153
-                }
154
-                $this->_attendees[ $att_key ]['line_ref'][] =
155
-                    $id;  // so later it can be determined what events this attendee registered for!
156
-                $this->_attendees[ $att_key ]['evt_objs'][] = $event;
157
-                $this->_attendees[ $att_key ]['att_obj']    = $attendee;
158
-                // $this->_attendees[$att_key]['registration_id'] = 0;
159
-                $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
160
-                $this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
161
-                if ($att_key == 999999991) {
162
-                    $this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
163
-                    $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
164
-                    $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
165
-                } elseif ($att_key == 999999992) {
166
-                    $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
167
-                    $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
168
-                    $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
169
-                } elseif ($att_key == 999999993) {
170
-                    $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
171
-                    $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
172
-                    $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
173
-                }
174
-            }
175
-        }
176
-
177
-        $this->tickets            = $tkts;
178
-        $this->datetimes          = $dtts;
179
-        $this->answers            = $answers_n_questions['answers'];
180
-        $this->questions          = $answers_n_questions['questions'];
181
-        $this->total_ticket_count = count($tkts) * count($this->_attendees);
182
-    }
183
-
184
-
185
-    /**
186
-     * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
187
-     *
188
-     * @access private
189
-     * @return array an array of attendee objects
190
-     * @throws EE_Error
191
-     * @throws EE_Error
192
-     */
193
-    private function _get_some_attendees()
194
-    {
195
-        // let's just setup a dummy array of various attendee details
196
-        $dummy_attendees = [
197
-            0 => [
198
-                'Luke',
199
-                'Skywalker',
200
-                '[email protected]',
201
-                '804 Bantha Dr.',
202
-                'Complex 8',
203
-                'Mos Eisley',
204
-                32,
205
-                'US',
206
-                'f0r3e',
207
-                '222-333-4763',
208
-                false,
209
-                '999999991',
210
-            ],
211
-            1 => [
212
-                'Princess',
213
-                'Leia',
214
-                '[email protected]',
215
-                '1456 Valley Way Boulevard',
216
-                'Suite 9',
217
-                'Alderaan',
218
-                15,
219
-                'US',
220
-                'c1h2c',
221
-                '78-123-111-1111',
222
-                false,
223
-                '999999992',
224
-            ],
225
-            2 => [
226
-                'Yoda',
227
-                'I Am',
228
-                '[email protected]',
229
-                '4th Tree',
230
-                '5th Knot',
231
-                'Marsh',
232
-                22,
233
-                'US',
234
-                'l18n',
235
-                '999-999-9999',
236
-                false,
237
-                '999999993',
238
-            ],
239
-        ];
240
-
241
-        // let's generate the attendee objects
242
-        $attendees = [];
243
-        $var_array = [
244
-            'fname',
245
-            'lname',
246
-            'email',
247
-            'address',
248
-            'address2',
249
-            'city',
250
-            'staid',
251
-            'cntry',
252
-            'zip',
253
-            'phone',
254
-            'deleted',
255
-            'attid',
256
-        ];
257
-
258
-        // EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
259
-        foreach ($dummy_attendees as $dummy) {
260
-            $att = array_combine($var_array, $dummy);
261
-            extract($att);
262
-            /** @var $fname string */
263
-            /** @var $lname string */
264
-            /** @var $address string */
265
-            /** @var $address2 string */
266
-            /** @var $city string */
267
-            /** @var $staid string */
268
-            /** @var $cntry string */
269
-            /** @var $zip string */
270
-            /** @var $email string */
271
-            /** @var $phone string */
272
-            /** @var $attid string */
273
-            $attendees[ $attid ] = EE_Attendee::new_instance(
274
-                [
275
-                    'ATT_fname'    => $fname,
276
-                    'ATT_lname'    => $lname,
277
-                    'ATT_address'  => $address,
278
-                    'ATT_address2' => $address2,
279
-                    'ATT_city'     => $city,
280
-                    'STA_ID'       => $staid,
281
-                    'CNT_ISO'      => $cntry,
282
-                    'ATT_zip'      => $zip,
283
-                    'ATT_email'    => $email,
284
-                    'ATT_phone'    => $phone,
285
-                    'ATT_ID'       => $attid,
286
-                ]
287
-            );
288
-        }
289
-
290
-        return $attendees;
291
-    }
292
-
293
-
294
-    /**
295
-     * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
296
-     * This will be used in our dummy data setup
297
-     *
298
-     * @return array
299
-     * @throws EE_Error
300
-     * @throws ReflectionException
301
-     */
302
-    private function _get_some_q_and_as()
303
-    {
304
-        $quests_array = [
305
-            0 => [
306
-                555,
307
-                esc_html__('What is your favorite planet?', 'event_espresso'),
308
-                0,
309
-            ],
310
-            1 => [
311
-                556,
312
-                esc_html__('What is your favorite food?', 'event_espresso'),
313
-                0,
314
-            ],
315
-            2 => [
316
-                557,
317
-                esc_html__('How many lightyears have you travelled', 'event_espresso'),
318
-                0,
319
-            ],
320
-        ];
321
-
322
-        $ans_array = [
323
-            0 => [
324
-                999,
325
-                555,
326
-                'Tattoine',
327
-            ],
328
-            1 => [
329
-                1000,
330
-                555,
331
-                'Alderaan',
332
-            ],
333
-            2 => [
334
-                1001,
335
-                555,
336
-                'Dantooine',
337
-            ],
338
-            3 => [
339
-                1002,
340
-                556,
341
-                'Fish Fingers',
342
-            ],
343
-            4 => [
344
-                1003,
345
-                556,
346
-                'Sushi',
347
-            ],
348
-            5 => [
349
-                1004,
350
-                556,
351
-                'Water',
352
-            ],
353
-            6 => [
354
-                1005,
355
-                557,
356
-                'A lot',
357
-            ],
358
-            7 => [
359
-                1006,
360
-                557,
361
-                "That's none of your business.",
362
-            ],
363
-            8 => [
364
-                1007,
365
-                557,
366
-                "People less travel me then.",
367
-            ],
368
-        ];
369
-
370
-        $qst_columns = ['QST_ID', 'QST_display_text', 'QST_system'];
371
-        $ans_columns = ['ANS_ID', 'QST_ID', 'ANS_value'];
372
-
373
-        // EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
374
-        // EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
375
-
376
-        $qsts = [];
377
-        // first the questions
378
-        foreach ($quests_array as $qst) {
379
-            $qstobj                    = array_combine($qst_columns, $qst);
380
-            $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
381
-        }
382
-
383
-        // now the answers (and we'll setup our arrays)
384
-        $q_n_as = [];
385
-        foreach ($ans_array as $ans) {
386
-            $ansobj                               = array_combine($ans_columns, $ans);
387
-            $ansobj                               = EE_Answer::new_instance($ansobj);
388
-            $q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
389
-            $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
390
-        }
391
-
392
-        return $q_n_as;
393
-    }
394
-
395
-
396
-    /**
397
-     * Return an array of event objects from the database
398
-     *
399
-     * If event ids are not included then we'll just retrieve the first published event from the database.
400
-     *
401
-     * @param array $event_ids if set, this will be an array of event ids to obtain events for.
402
-     *
403
-     * @return array    An array of event objects from the db.
404
-     * @throws EE_Error
405
-     */
406
-    private function _get_some_events(array $event_ids = [])
407
-    {
408
-        /** @var RequestInterface $request */
409
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
410
-        // if we have an evt_id then we want to make sure we use that for the preview
411
-        // (because a specific event template is being viewed);
412
-        $event_ids = $request->getRequestParam('evt_id', $event_ids, 'int', true);
413
-        // clear out any invalid IDs, like 0
414
-        $event_ids = array_filter($event_ids);
415
-        $limit     = ! empty($event_ids)
416
-            ? null
417
-            : apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
418
-
419
-        $where = ! empty($event_ids)
420
-            ? [
421
-                'EVT_ID'                 => ['IN', $event_ids],
422
-                'Datetime.Ticket.TKT_ID' => ['>', 1],
423
-            ]
424
-            : ['Datetime.Ticket.TKT_ID' => ['>', 1]];
425
-
426
-        return EEM_Event::instance()->get_all([$where, 'limit' => $limit]);
427
-    }
428
-
429
-
430
-    /**
431
-     * @throws EE_Error
432
-     * @throws ReflectionException
433
-     */
434
-    protected function _setup_data()
435
-    {
436
-        // need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
437
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
438
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
439
-            $session = EE_Registry::instance()->SSN;
440
-        } else {
441
-            $session = EE_Registry::instance()->load_core('Session');
442
-        }
443
-        $cart = EE_Cart::instance(null, $session);
444
-
445
-        // add tickets to cart
446
-        foreach ($this->tickets as $ticket) {
447
-            $cart->add_ticket_to_cart($ticket['ticket']);
448
-        }
449
-
450
-        // setup txn property
451
-        $this->txn = EE_Transaction::new_instance(
452
-            [
453
-                'TXN_timestamp'    => time(), // unix timestamp
454
-                'TXN_total'        => 0, // txn_total
455
-                'TXN_paid'         => 0, // txn_paid
456
-                'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
457
-                'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
458
-                'TXN_hash_salt'    => null, // hash salt blank as well
459
-                'TXN_ID'           => 999999,
460
-            ]
461
-        );
462
-
463
-
464
-        // setup reg_objects
465
-        // note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
466
-        $this->reg_objs = [];
467
-        $regid          = 9999990;
468
-        foreach ($this->_attendees as $key => $attendee) {
469
-            // note we need to setup reg_objects for each event this attendee belongs to
470
-            $regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
471
-            $regtxn = $this->txn->ID();
472
-            $regcnt = 1;
473
-            foreach ($attendee['line_ref'] as $evtid) {
474
-                foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
475
-                    if (! $ticket instanceof EE_Ticket) {
476
-                        continue;
477
-                    }
478
-                    $reg_array                                            = [
479
-                        'EVT_ID'           => $evtid,
480
-                        'ATT_ID'           => $regatt,
481
-                        'TXN_ID'           => $regtxn,
482
-                        'TKT_ID'           => $ticket->ID(),
483
-                        'STS_ID'           => RegStatus::PENDING_PAYMENT,
484
-                        'REG_date'         => time(),
485
-                        'REG_final_price'  => $ticket->get('TKT_price'),
486
-                        'REG_session'      => 'dummy_session_id',
487
-                        'REG_code'         => $regid . '-dummy-generated-code',
488
-                        'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
489
-                        'REG_count'        => $regcnt,
490
-                        'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
491
-                        'REG_att_is_going' => true,
492
-                        'REG_ID'           => $regid,
493
-                    ];
494
-                    $REG_OBJ                                              = EE_Registration::new_instance($reg_array);
495
-                    $this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
496
-                    $this->_events[ $evtid ]['reg_objs'][]                = $REG_OBJ;
497
-                    $this->reg_objs[]                                     = $REG_OBJ;
498
-                    $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
499
-
500
-                    $regcnt++;
501
-                    $regid++;
502
-                }
503
-            }
504
-        }
505
-
506
-
507
-        // setup line items!
508
-        $line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
509
-
510
-        // add tickets
511
-        foreach ($this->tickets as $item) {
512
-            $qty    = $item['count'];
513
-            $ticket = $item['ticket'];
514
-            EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
515
-        }
516
-
517
-        $shipping_line_item = EE_Line_Item::new_instance(
518
-            [
519
-                'LIN_name'       => esc_html__(
520
-                    'Shipping Surcharge',
521
-                    'event_espresso'
522
-                ),
523
-                'LIN_desc'       => esc_html__(
524
-                    'Sent via Millenium Falcon',
525
-                    'event_espresso'
526
-                ),
527
-                'LIN_unit_price' => 20,
528
-                'LIN_quantity'   => 1,
529
-                'LIN_is_taxable' => true,
530
-                'LIN_total'      => 20,
531
-                'LIN_type'       => EEM_Line_Item::type_line_item,
532
-            ]
533
-        );
534
-        EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
535
-        $this->additional_line_items = [$shipping_line_item];
536
-
537
-        // now let's add taxes
538
-        EEH_Line_Item::apply_taxes($line_item_total);
539
-
540
-        // now we should be able to get the items we need from this object
541
-        $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
542
-        $line_items       = [];
543
-        foreach ($event_line_items as $line_item) {
544
-            if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
545
-                continue;
546
-            }
547
-            $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
548
-            foreach ($ticket_line_items as $ticket_line_item) {
549
-                if (! $ticket_line_item instanceof EE_Line_Item) {
550
-                    continue;
551
-                }
552
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
553
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
554
-                $line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
555
-                $line_items[ $ticket_line_item->ID() ]['EE_Ticket']             =
556
-                    $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
557
-            }
558
-        }
559
-
560
-        $this->line_items_with_children = $line_items;
561
-        $this->tax_line_items           = $line_item_total->tax_descendants();
562
-
563
-        // add proper total to transaction object.
564
-        $grand_total                 = $line_item_total->recalculate_total_including_taxes();
565
-        $this->grand_total_line_item = $line_item_total;
566
-        $this->txn->set_total($grand_total);
567
-
568
-
569
-        // add additional details for each registration
570
-        foreach ($this->reg_objs as $reg) {
571
-            if (! $reg instanceof EE_Registration) {
572
-                continue;
573
-            }
574
-            $this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
575
-            $this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
576
-            $this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
577
-            $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
578
-            $this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
579
-            $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
580
-        }
581
-
582
-
583
-        // events and attendees
584
-        $this->events        = $this->_events;
585
-        $this->attendees     = $this->_attendees;
586
-        $this->registrations = $this->_registrations;
587
-
588
-        $attendees_to_shift = $this->_attendees;
589
-
590
-        // setup primary attendee property
591
-        $this->primary_attendee_data = [
592
-            'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
593
-                ? $this->_attendees[999999991]['att_obj']->fname()
594
-                : '',
595
-
596
-            'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
597
-                ? $this->_attendees[999999991]['att_obj']->lname()
598
-                : '',
599
-
600
-            'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
601
-                ? $this->_attendees[999999991]['att_obj']->email()
602
-                : '',
603
-
604
-            'att_obj' => $this->_attendees[999999991]['att_obj'],
605
-
606
-            'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']),
607
-        ];
608
-
609
-        // reg_info property
610
-        // note this isn't referenced by any shortcode parsers so we'll ignore for now.
611
-        $this->reg_info = [];
612
-
613
-        // let's set a reg_obj for messengers expecting one.
614
-        $this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']);
615
-
616
-        // the below are just dummy items.
617
-        $this->user_id     = 1;
618
-        $this->ip_address  = '192.0.2.1';
619
-        $this->user_agent  = '';
620
-        $this->init_access = time();
621
-        $this->last_access = time();
622
-    }
24
+	// some specific properties we need for this class
25
+	private $_events        = [];
26
+
27
+	private $_attendees     = [];
28
+
29
+	private $_registrations = [];
30
+
31
+
32
+	/**
33
+	 * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
34
+	 * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
35
+	 * we'll get the first three published events from the users database and use that as a source.
36
+	 *
37
+	 * @param array $data
38
+	 * @throws EE_Error
39
+	 * @throws EE_Error
40
+	 * @throws ReflectionException
41
+	 */
42
+	public function __construct($data = [])
43
+	{
44
+		$this->_data = isset($data['event_ids']) ? $data['event_ids'] : [];
45
+		$this->_setup_attendees_events();
46
+		parent::__construct($data);
47
+	}
48
+
49
+
50
+	/**
51
+	 * Returns database safe representation of the data later used to when instantiating this object.
52
+	 *
53
+	 * @param array $data The incoming data to be prepped.
54
+	 *
55
+	 * @return array   The prepped data for db
56
+	 */
57
+	public static function convert_data_for_persistent_storage($data)
58
+	{
59
+		return $data;
60
+	}
61
+
62
+
63
+	/**
64
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
65
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
66
+	 *
67
+	 * @param array $data
68
+	 *
69
+	 * @return array
70
+	 */
71
+	public static function convert_data_from_persistent_storage($data)
72
+	{
73
+		return $data;
74
+	}
75
+
76
+
77
+	/**
78
+	 * This will just setup the _events property in the expected format.
79
+	 *
80
+	 * @throws EE_Error
81
+	 * @throws ReflectionException
82
+	 */
83
+	private function _setup_attendees_events()
84
+	{
85
+
86
+		// setup some attendee objects
87
+		$attendees = $this->_get_some_attendees();
88
+
89
+		// if empty $data we'll do a query to get some events from the server.
90
+		// otherwise we'll retrieve the event data for the given ids.
91
+		$events = $this->_get_some_events($this->_data);
92
+
93
+		$answers_n_questions = $this->_get_some_q_and_as();
94
+
95
+		if (count($events) < 1) {
96
+			throw new EE_Error(
97
+				esc_html__(
98
+					'We can\'t generate a preview for you because there are no active events in your database',
99
+					'event_espresso'
100
+				)
101
+			);
102
+		}
103
+
104
+
105
+		// now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
106
+		// we'll actually use the generated line_item identifiers for our loop
107
+		$dtts = $tkts = [];
108
+		foreach ($events as $id => $event) {
109
+			if (! $event instanceof EE_Event) {
110
+				continue;
111
+			}
112
+			$this->_events[ $id ]['ID']       = $id;
113
+			$this->_events[ $id ]['name']     = $event->get('EVT_name');
114
+			$datetime                         = $event->get_first_related('Datetime');
115
+			$tickets                          = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
116
+				'Ticket',
117
+				['default_where_conditions' => 'none']
118
+			) : [];
119
+			$this->_events[ $id ]['event']    = $event;
120
+			$this->_events[ $id ]['reg_objs'] = [];
121
+			$this->_events[ $id ]['tkt_objs'] = $tickets;
122
+			$this->_events[ $id ]['dtt_objs'] = [];
123
+
124
+			$tkts     = [];
125
+			foreach ($tickets as $ticket) {
126
+				if (! $ticket instanceof EE_Ticket) {
127
+					continue;
128
+				}
129
+				$reldatetime                       = $ticket->datetimes();
130
+				$tkts[ $ticket->ID() ]             = [];
131
+				$tkts[ $ticket->ID() ]['ticket']   = $ticket;
132
+				$tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
133
+				$tkts[ $ticket->ID() ]['att_objs'] = $attendees;
134
+				$tkts[ $ticket->ID() ]['count']    = count($attendees);
135
+				$tkts[ $ticket->ID() ]['EE_Event'] = $event;
136
+				foreach ($reldatetime as $datetime) {
137
+					if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
138
+						$this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
139
+						$dtts[ $datetime->ID() ]['datetime']                 = $datetime;
140
+						$dtts[ $datetime->ID() ]['tkt_objs'][]               = $ticket;
141
+						$dtts[ $datetime->ID() ]['evt_objs'][]               = $event;
142
+					}
143
+				}
144
+			}
145
+
146
+			$this->_events[ $id ]['total_attendees'] = count($attendees);
147
+			$this->_events[ $id ]['att_objs']        = $attendees;
148
+
149
+			// let's also setup the dummy attendees property!
150
+			foreach ($attendees as $att_key => $attendee) {
151
+				if (! $attendee instanceof EE_Attendee) {
152
+					continue;
153
+				}
154
+				$this->_attendees[ $att_key ]['line_ref'][] =
155
+					$id;  // so later it can be determined what events this attendee registered for!
156
+				$this->_attendees[ $att_key ]['evt_objs'][] = $event;
157
+				$this->_attendees[ $att_key ]['att_obj']    = $attendee;
158
+				// $this->_attendees[$att_key]['registration_id'] = 0;
159
+				$this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
160
+				$this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
161
+				if ($att_key == 999999991) {
162
+					$this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
163
+					$this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
164
+					$this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
165
+				} elseif ($att_key == 999999992) {
166
+					$this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
167
+					$this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
168
+					$this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
169
+				} elseif ($att_key == 999999993) {
170
+					$this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
171
+					$this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
172
+					$this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
173
+				}
174
+			}
175
+		}
176
+
177
+		$this->tickets            = $tkts;
178
+		$this->datetimes          = $dtts;
179
+		$this->answers            = $answers_n_questions['answers'];
180
+		$this->questions          = $answers_n_questions['questions'];
181
+		$this->total_ticket_count = count($tkts) * count($this->_attendees);
182
+	}
183
+
184
+
185
+	/**
186
+	 * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
187
+	 *
188
+	 * @access private
189
+	 * @return array an array of attendee objects
190
+	 * @throws EE_Error
191
+	 * @throws EE_Error
192
+	 */
193
+	private function _get_some_attendees()
194
+	{
195
+		// let's just setup a dummy array of various attendee details
196
+		$dummy_attendees = [
197
+			0 => [
198
+				'Luke',
199
+				'Skywalker',
200
+				'[email protected]',
201
+				'804 Bantha Dr.',
202
+				'Complex 8',
203
+				'Mos Eisley',
204
+				32,
205
+				'US',
206
+				'f0r3e',
207
+				'222-333-4763',
208
+				false,
209
+				'999999991',
210
+			],
211
+			1 => [
212
+				'Princess',
213
+				'Leia',
214
+				'[email protected]',
215
+				'1456 Valley Way Boulevard',
216
+				'Suite 9',
217
+				'Alderaan',
218
+				15,
219
+				'US',
220
+				'c1h2c',
221
+				'78-123-111-1111',
222
+				false,
223
+				'999999992',
224
+			],
225
+			2 => [
226
+				'Yoda',
227
+				'I Am',
228
+				'[email protected]',
229
+				'4th Tree',
230
+				'5th Knot',
231
+				'Marsh',
232
+				22,
233
+				'US',
234
+				'l18n',
235
+				'999-999-9999',
236
+				false,
237
+				'999999993',
238
+			],
239
+		];
240
+
241
+		// let's generate the attendee objects
242
+		$attendees = [];
243
+		$var_array = [
244
+			'fname',
245
+			'lname',
246
+			'email',
247
+			'address',
248
+			'address2',
249
+			'city',
250
+			'staid',
251
+			'cntry',
252
+			'zip',
253
+			'phone',
254
+			'deleted',
255
+			'attid',
256
+		];
257
+
258
+		// EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
259
+		foreach ($dummy_attendees as $dummy) {
260
+			$att = array_combine($var_array, $dummy);
261
+			extract($att);
262
+			/** @var $fname string */
263
+			/** @var $lname string */
264
+			/** @var $address string */
265
+			/** @var $address2 string */
266
+			/** @var $city string */
267
+			/** @var $staid string */
268
+			/** @var $cntry string */
269
+			/** @var $zip string */
270
+			/** @var $email string */
271
+			/** @var $phone string */
272
+			/** @var $attid string */
273
+			$attendees[ $attid ] = EE_Attendee::new_instance(
274
+				[
275
+					'ATT_fname'    => $fname,
276
+					'ATT_lname'    => $lname,
277
+					'ATT_address'  => $address,
278
+					'ATT_address2' => $address2,
279
+					'ATT_city'     => $city,
280
+					'STA_ID'       => $staid,
281
+					'CNT_ISO'      => $cntry,
282
+					'ATT_zip'      => $zip,
283
+					'ATT_email'    => $email,
284
+					'ATT_phone'    => $phone,
285
+					'ATT_ID'       => $attid,
286
+				]
287
+			);
288
+		}
289
+
290
+		return $attendees;
291
+	}
292
+
293
+
294
+	/**
295
+	 * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
296
+	 * This will be used in our dummy data setup
297
+	 *
298
+	 * @return array
299
+	 * @throws EE_Error
300
+	 * @throws ReflectionException
301
+	 */
302
+	private function _get_some_q_and_as()
303
+	{
304
+		$quests_array = [
305
+			0 => [
306
+				555,
307
+				esc_html__('What is your favorite planet?', 'event_espresso'),
308
+				0,
309
+			],
310
+			1 => [
311
+				556,
312
+				esc_html__('What is your favorite food?', 'event_espresso'),
313
+				0,
314
+			],
315
+			2 => [
316
+				557,
317
+				esc_html__('How many lightyears have you travelled', 'event_espresso'),
318
+				0,
319
+			],
320
+		];
321
+
322
+		$ans_array = [
323
+			0 => [
324
+				999,
325
+				555,
326
+				'Tattoine',
327
+			],
328
+			1 => [
329
+				1000,
330
+				555,
331
+				'Alderaan',
332
+			],
333
+			2 => [
334
+				1001,
335
+				555,
336
+				'Dantooine',
337
+			],
338
+			3 => [
339
+				1002,
340
+				556,
341
+				'Fish Fingers',
342
+			],
343
+			4 => [
344
+				1003,
345
+				556,
346
+				'Sushi',
347
+			],
348
+			5 => [
349
+				1004,
350
+				556,
351
+				'Water',
352
+			],
353
+			6 => [
354
+				1005,
355
+				557,
356
+				'A lot',
357
+			],
358
+			7 => [
359
+				1006,
360
+				557,
361
+				"That's none of your business.",
362
+			],
363
+			8 => [
364
+				1007,
365
+				557,
366
+				"People less travel me then.",
367
+			],
368
+		];
369
+
370
+		$qst_columns = ['QST_ID', 'QST_display_text', 'QST_system'];
371
+		$ans_columns = ['ANS_ID', 'QST_ID', 'ANS_value'];
372
+
373
+		// EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
374
+		// EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
375
+
376
+		$qsts = [];
377
+		// first the questions
378
+		foreach ($quests_array as $qst) {
379
+			$qstobj                    = array_combine($qst_columns, $qst);
380
+			$qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
381
+		}
382
+
383
+		// now the answers (and we'll setup our arrays)
384
+		$q_n_as = [];
385
+		foreach ($ans_array as $ans) {
386
+			$ansobj                               = array_combine($ans_columns, $ans);
387
+			$ansobj                               = EE_Answer::new_instance($ansobj);
388
+			$q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
389
+			$q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
390
+		}
391
+
392
+		return $q_n_as;
393
+	}
394
+
395
+
396
+	/**
397
+	 * Return an array of event objects from the database
398
+	 *
399
+	 * If event ids are not included then we'll just retrieve the first published event from the database.
400
+	 *
401
+	 * @param array $event_ids if set, this will be an array of event ids to obtain events for.
402
+	 *
403
+	 * @return array    An array of event objects from the db.
404
+	 * @throws EE_Error
405
+	 */
406
+	private function _get_some_events(array $event_ids = [])
407
+	{
408
+		/** @var RequestInterface $request */
409
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
410
+		// if we have an evt_id then we want to make sure we use that for the preview
411
+		// (because a specific event template is being viewed);
412
+		$event_ids = $request->getRequestParam('evt_id', $event_ids, 'int', true);
413
+		// clear out any invalid IDs, like 0
414
+		$event_ids = array_filter($event_ids);
415
+		$limit     = ! empty($event_ids)
416
+			? null
417
+			: apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
418
+
419
+		$where = ! empty($event_ids)
420
+			? [
421
+				'EVT_ID'                 => ['IN', $event_ids],
422
+				'Datetime.Ticket.TKT_ID' => ['>', 1],
423
+			]
424
+			: ['Datetime.Ticket.TKT_ID' => ['>', 1]];
425
+
426
+		return EEM_Event::instance()->get_all([$where, 'limit' => $limit]);
427
+	}
428
+
429
+
430
+	/**
431
+	 * @throws EE_Error
432
+	 * @throws ReflectionException
433
+	 */
434
+	protected function _setup_data()
435
+	{
436
+		// need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
437
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
438
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
439
+			$session = EE_Registry::instance()->SSN;
440
+		} else {
441
+			$session = EE_Registry::instance()->load_core('Session');
442
+		}
443
+		$cart = EE_Cart::instance(null, $session);
444
+
445
+		// add tickets to cart
446
+		foreach ($this->tickets as $ticket) {
447
+			$cart->add_ticket_to_cart($ticket['ticket']);
448
+		}
449
+
450
+		// setup txn property
451
+		$this->txn = EE_Transaction::new_instance(
452
+			[
453
+				'TXN_timestamp'    => time(), // unix timestamp
454
+				'TXN_total'        => 0, // txn_total
455
+				'TXN_paid'         => 0, // txn_paid
456
+				'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
457
+				'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
458
+				'TXN_hash_salt'    => null, // hash salt blank as well
459
+				'TXN_ID'           => 999999,
460
+			]
461
+		);
462
+
463
+
464
+		// setup reg_objects
465
+		// note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
466
+		$this->reg_objs = [];
467
+		$regid          = 9999990;
468
+		foreach ($this->_attendees as $key => $attendee) {
469
+			// note we need to setup reg_objects for each event this attendee belongs to
470
+			$regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
471
+			$regtxn = $this->txn->ID();
472
+			$regcnt = 1;
473
+			foreach ($attendee['line_ref'] as $evtid) {
474
+				foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
475
+					if (! $ticket instanceof EE_Ticket) {
476
+						continue;
477
+					}
478
+					$reg_array                                            = [
479
+						'EVT_ID'           => $evtid,
480
+						'ATT_ID'           => $regatt,
481
+						'TXN_ID'           => $regtxn,
482
+						'TKT_ID'           => $ticket->ID(),
483
+						'STS_ID'           => RegStatus::PENDING_PAYMENT,
484
+						'REG_date'         => time(),
485
+						'REG_final_price'  => $ticket->get('TKT_price'),
486
+						'REG_session'      => 'dummy_session_id',
487
+						'REG_code'         => $regid . '-dummy-generated-code',
488
+						'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
489
+						'REG_count'        => $regcnt,
490
+						'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
491
+						'REG_att_is_going' => true,
492
+						'REG_ID'           => $regid,
493
+					];
494
+					$REG_OBJ                                              = EE_Registration::new_instance($reg_array);
495
+					$this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
496
+					$this->_events[ $evtid ]['reg_objs'][]                = $REG_OBJ;
497
+					$this->reg_objs[]                                     = $REG_OBJ;
498
+					$this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
499
+
500
+					$regcnt++;
501
+					$regid++;
502
+				}
503
+			}
504
+		}
505
+
506
+
507
+		// setup line items!
508
+		$line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
509
+
510
+		// add tickets
511
+		foreach ($this->tickets as $item) {
512
+			$qty    = $item['count'];
513
+			$ticket = $item['ticket'];
514
+			EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
515
+		}
516
+
517
+		$shipping_line_item = EE_Line_Item::new_instance(
518
+			[
519
+				'LIN_name'       => esc_html__(
520
+					'Shipping Surcharge',
521
+					'event_espresso'
522
+				),
523
+				'LIN_desc'       => esc_html__(
524
+					'Sent via Millenium Falcon',
525
+					'event_espresso'
526
+				),
527
+				'LIN_unit_price' => 20,
528
+				'LIN_quantity'   => 1,
529
+				'LIN_is_taxable' => true,
530
+				'LIN_total'      => 20,
531
+				'LIN_type'       => EEM_Line_Item::type_line_item,
532
+			]
533
+		);
534
+		EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
535
+		$this->additional_line_items = [$shipping_line_item];
536
+
537
+		// now let's add taxes
538
+		EEH_Line_Item::apply_taxes($line_item_total);
539
+
540
+		// now we should be able to get the items we need from this object
541
+		$event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
542
+		$line_items       = [];
543
+		foreach ($event_line_items as $line_item) {
544
+			if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
545
+				continue;
546
+			}
547
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
548
+			foreach ($ticket_line_items as $ticket_line_item) {
549
+				if (! $ticket_line_item instanceof EE_Line_Item) {
550
+					continue;
551
+				}
552
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
553
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
554
+				$line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
555
+				$line_items[ $ticket_line_item->ID() ]['EE_Ticket']             =
556
+					$this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
557
+			}
558
+		}
559
+
560
+		$this->line_items_with_children = $line_items;
561
+		$this->tax_line_items           = $line_item_total->tax_descendants();
562
+
563
+		// add proper total to transaction object.
564
+		$grand_total                 = $line_item_total->recalculate_total_including_taxes();
565
+		$this->grand_total_line_item = $line_item_total;
566
+		$this->txn->set_total($grand_total);
567
+
568
+
569
+		// add additional details for each registration
570
+		foreach ($this->reg_objs as $reg) {
571
+			if (! $reg instanceof EE_Registration) {
572
+				continue;
573
+			}
574
+			$this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
575
+			$this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
576
+			$this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
577
+			$this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
578
+			$this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
579
+			$this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
580
+		}
581
+
582
+
583
+		// events and attendees
584
+		$this->events        = $this->_events;
585
+		$this->attendees     = $this->_attendees;
586
+		$this->registrations = $this->_registrations;
587
+
588
+		$attendees_to_shift = $this->_attendees;
589
+
590
+		// setup primary attendee property
591
+		$this->primary_attendee_data = [
592
+			'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
593
+				? $this->_attendees[999999991]['att_obj']->fname()
594
+				: '',
595
+
596
+			'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
597
+				? $this->_attendees[999999991]['att_obj']->lname()
598
+				: '',
599
+
600
+			'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
601
+				? $this->_attendees[999999991]['att_obj']->email()
602
+				: '',
603
+
604
+			'att_obj' => $this->_attendees[999999991]['att_obj'],
605
+
606
+			'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']),
607
+		];
608
+
609
+		// reg_info property
610
+		// note this isn't referenced by any shortcode parsers so we'll ignore for now.
611
+		$this->reg_info = [];
612
+
613
+		// let's set a reg_obj for messengers expecting one.
614
+		$this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']);
615
+
616
+		// the below are just dummy items.
617
+		$this->user_id     = 1;
618
+		$this->ip_address  = '192.0.2.1';
619
+		$this->user_agent  = '';
620
+		$this->init_access = time();
621
+		$this->last_access = time();
622
+	}
623 623
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 1 patch
Indentation   +638 added lines, -638 removed lines patch added patch discarded remove patch
@@ -5,642 +5,642 @@
 block discarded – undo
5 5
  */
6 6
 class EE_Email_messenger extends EE_messenger
7 7
 {
8
-    /**
9
-     * To field for email
10
-     * @var string
11
-     */
12
-    protected $_to = '';
13
-
14
-
15
-    /**
16
-     * CC field for email.
17
-     * @var string
18
-     */
19
-    protected $_cc = '';
20
-
21
-    /**
22
-     * From field for email
23
-     * @var string
24
-     */
25
-    protected $_from = '';
26
-
27
-
28
-    /**
29
-     * Subject field for email
30
-     * @var string
31
-     */
32
-    protected $_subject = '';
33
-
34
-
35
-    /**
36
-     * Content field for email
37
-     * @var string
38
-     */
39
-    protected $_content = '';
40
-
41
-
42
-    /**
43
-     * constructor
44
-     *
45
-     * @access public
46
-     */
47
-    public function __construct()
48
-    {
49
-        // set name and description properties
50
-        $this->name                = 'email';
51
-        $this->description         = sprintf(
52
-            esc_html__(
53
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
54
-                'event_espresso'
55
-            ),
56
-            '<code>wp_mail</code>'
57
-        );
58
-        $this->label               = array(
59
-            'singular' => esc_html__('email', 'event_espresso'),
60
-            'plural'   => esc_html__('emails', 'event_espresso'),
61
-        );
62
-        $this->activate_on_install = true;
63
-
64
-        // we're using defaults so let's call parent constructor that will take care of setting up all the other
65
-        // properties
66
-        parent::__construct();
67
-    }
68
-
69
-
70
-    /**
71
-     * see abstract declaration in parent class for details.
72
-     */
73
-    protected function _set_admin_pages()
74
-    {
75
-        $this->admin_registered_pages = array(
76
-            'events_edit' => true,
77
-        );
78
-    }
79
-
80
-
81
-    /**
82
-     * see abstract declaration in parent class for details
83
-     */
84
-    protected function _set_valid_shortcodes()
85
-    {
86
-        // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
87
-        // message type.
88
-        $this->_valid_shortcodes = array(
89
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
90
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
-        );
93
-    }
94
-
95
-
96
-    /**
97
-     * see abstract declaration in parent class for details
98
-     *
99
-     * @access protected
100
-     * @return void
101
-     */
102
-    protected function _set_validator_config()
103
-    {
104
-        $valid_shortcodes = $this->get_valid_shortcodes();
105
-
106
-        $this->_validator_config = array(
107
-            'to'            => array(
108
-                'shortcodes' => $valid_shortcodes['to'],
109
-                'type'       => 'email',
110
-            ),
111
-            'cc' => array(
112
-                'shortcodes' => $valid_shortcodes['to'],
113
-                'type' => 'email',
114
-            ),
115
-            'from'          => array(
116
-                'shortcodes' => $valid_shortcodes['from'],
117
-                'type'       => 'email',
118
-            ),
119
-            'subject'       => array(
120
-                'shortcodes' => array(
121
-                    'organization',
122
-                    'primary_registration_details',
123
-                    'event_author',
124
-                    'primary_registration_details',
125
-                    'recipient_details',
126
-                ),
127
-            ),
128
-            'content'       => array(
129
-                'shortcodes' => array(
130
-                    'event_list',
131
-                    'attendee_list',
132
-                    'ticket_list',
133
-                    'organization',
134
-                    'primary_registration_details',
135
-                    'primary_registration_list',
136
-                    'event_author',
137
-                    'recipient_details',
138
-                    'recipient_list',
139
-                    'transaction',
140
-                    'messenger',
141
-                ),
142
-            ),
143
-            'attendee_list' => array(
144
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
145
-                'required'   => array('[ATTENDEE_LIST]'),
146
-            ),
147
-            'event_list'    => array(
148
-                'shortcodes' => array(
149
-                    'event',
150
-                    'attendee_list',
151
-                    'ticket_list',
152
-                    'venue',
153
-                    'datetime_list',
154
-                    'attendee',
155
-                    'primary_registration_details',
156
-                    'primary_registration_list',
157
-                    'event_author',
158
-                    'recipient_details',
159
-                    'recipient_list',
160
-                ),
161
-                'required'   => array('[EVENT_LIST]'),
162
-            ),
163
-            'ticket_list'   => array(
164
-                'shortcodes' => array(
165
-                    'event_list',
166
-                    'attendee_list',
167
-                    'ticket',
168
-                    'datetime_list',
169
-                    'primary_registration_details',
170
-                    'recipient_details',
171
-                ),
172
-                'required'   => array('[TICKET_LIST]'),
173
-            ),
174
-            'datetime_list' => array(
175
-                'shortcodes' => array('datetime'),
176
-                'required'   => array('[DATETIME_LIST]'),
177
-            ),
178
-        );
179
-    }
180
-
181
-
182
-    /**
183
-     * @see   parent EE_messenger class for docs
184
-     * @since 4.5.0
185
-     */
186
-    public function do_secondary_messenger_hooks($sending_messenger_name)
187
-    {
188
-        if ($sending_messenger_name === 'html') {
189
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
190
-        }
191
-    }
192
-
193
-
194
-    public function add_email_css(
195
-        $variation_path,
196
-        $messenger,
197
-        $message_type,
198
-        $type,
199
-        $variation,
200
-        $file_extension,
201
-        $url,
202
-        EE_Messages_Template_Pack $template_pack
203
-    ) {
204
-        // prevent recursion on this callback.
205
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
206
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
207
-
208
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
209
-        return $variation;
210
-    }
211
-
212
-
213
-    /**
214
-     * See parent for details
215
-     *
216
-     * @access protected
217
-     * @return void
218
-     */
219
-    protected function _set_test_settings_fields()
220
-    {
221
-        $this->_test_settings_fields = array(
222
-            'to'      => array(
223
-                'input'      => 'text',
224
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
225
-                'type'       => 'email',
226
-                'required'   => false,
227
-                'validation' => true,
228
-                'css_class'  => 'ee-input-width--big',
229
-                'format'     => '%s',
230
-                'default'    => get_bloginfo('admin_email'),
231
-            ),
232
-            'subject' => array(
233
-                'input'      => 'hidden',
234
-                'label'      => '',
235
-                'type'       => 'string',
236
-                'required'   => false,
237
-                'validation' => false,
238
-                'format'     => '%s',
239
-                'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
240
-                'default'    => '',
241
-                'css_class'  => '',
242
-            ),
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * _set_template_fields
249
-     * This sets up the fields that a messenger requires for the message to go out.
250
-     *
251
-     * @access  protected
252
-     * @return void
253
-     */
254
-    protected function _set_template_fields()
255
-    {
256
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
257
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
258
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
259
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
260
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
261
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
262
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
263
-        // will not be displayed/parsed.
264
-        $this->_template_fields = array(
265
-            'to'      => array(
266
-                'input'      => 'text',
267
-                'label'      => esc_html_x(
268
-                    'To',
269
-                    'Label for the "To" field for email addresses',
270
-                    'event_espresso'
271
-                ),
272
-                'type'       => 'string',
273
-                'required'   => false,
274
-                'validation' => true,
275
-                'css_class'  => 'large-text',
276
-                'format'     => '%s',
277
-            ),
278
-            'cc'      => array(
279
-                'input'      => 'text',
280
-                'label'      => esc_html_x(
281
-                    'CC',
282
-                    'Label for the "Carbon Copy" field used for additional email addresses',
283
-                    'event_espresso'
284
-                ),
285
-                'type'       => 'string',
286
-                'required'   => false,
287
-                'validation' => true,
288
-                'css_class'  => 'large-text',
289
-                'format'     => '%s',
290
-            ),
291
-            'from'    => array(
292
-                'input'      => 'text',
293
-                'label'      => esc_html_x(
294
-                    'From',
295
-                    'Label for the "From" field for email addresses.',
296
-                    'event_espresso'
297
-                ),
298
-                'type'       => 'string',
299
-                'required'   => false,
300
-                'validation' => true,
301
-                'css_class'  => 'large-text',
302
-                'format'     => '%s',
303
-            ),
304
-            'subject' => array(
305
-                'input'      => 'text',
306
-                'label'      => esc_html_x(
307
-                    'Subject',
308
-                    'Label for the "Subject" field (short description of contents) for emails.',
309
-                    'event_espresso'
310
-                ),
311
-                'type'       => 'string',
312
-                'required'   => true,
313
-                'validation' => true,
314
-                'css_class'  => 'large-text',
315
-                'format'     => '%s',
316
-            ),
317
-            'content' => '',
318
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
319
-            'extra'   => array(
320
-                'content' => array(
321
-                    'main'          => array(
322
-                        'input'      => 'wp_editor',
323
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
324
-                        'type'       => 'string',
325
-                        'required'   => false,
326
-                        'validation' => true,
327
-                        'format'     => '%s',
328
-                        'rows'       => '15',
329
-                    ),
330
-                    'event_list'    => array(
331
-                        'input'               => 'wp_editor',
332
-                        'label'               => '[EVENT_LIST]',
333
-                        'type'                => 'string',
334
-                        'required'            => false,
335
-                        'validation'          => true,
336
-                        'format'              => '%s',
337
-                        'rows'                => '15',
338
-                        'shortcodes_required' => array('[EVENT_LIST]'),
339
-                    ),
340
-                    'attendee_list' => array(
341
-                        'input'               => 'textarea',
342
-                        'label'               => '[ATTENDEE_LIST]',
343
-                        'type'                => 'string',
344
-                        'required'            => false,
345
-                        'validation'          => true,
346
-                        'format'              => '%s',
347
-                        'css_class'           => 'large-text',
348
-                        'rows'                => '5',
349
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
350
-                    ),
351
-                    'ticket_list'   => array(
352
-                        'input'               => 'textarea',
353
-                        'label'               => '[TICKET_LIST]',
354
-                        'type'                => 'string',
355
-                        'required'            => false,
356
-                        'validation'          => true,
357
-                        'format'              => '%s',
358
-                        'css_class'           => 'large-text',
359
-                        'rows'                => '10',
360
-                        'shortcodes_required' => array('[TICKET_LIST]'),
361
-                    ),
362
-                    'datetime_list' => array(
363
-                        'input'               => 'textarea',
364
-                        'label'               => '[DATETIME_LIST]',
365
-                        'type'                => 'string',
366
-                        'required'            => false,
367
-                        'validation'          => true,
368
-                        'format'              => '%s',
369
-                        'css_class'           => 'large-text',
370
-                        'rows'                => '10',
371
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
372
-                    ),
373
-                ),
374
-            ),
375
-        );
376
-    }
377
-
378
-
379
-    /**
380
-     * See definition of this class in parent
381
-     */
382
-    protected function _set_default_message_types()
383
-    {
384
-        $this->_default_message_types = array(
385
-            'payment',
386
-            'payment_refund',
387
-            'registration',
388
-            'not_approved_registration',
389
-            'pending_approval',
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * @see   definition of this class in parent
396
-     * @since 4.5.0
397
-     */
398
-    protected function _set_valid_message_types()
399
-    {
400
-        $this->_valid_message_types = array(
401
-            'payment',
402
-            'registration',
403
-            'not_approved_registration',
404
-            'declined_registration',
405
-            'cancelled_registration',
406
-            'pending_approval',
407
-            'registration_summary',
408
-            'payment_reminder',
409
-            'payment_declined',
410
-            'payment_refund',
411
-        );
412
-    }
413
-
414
-
415
-    /**
416
-     * setting up admin_settings_fields for messenger.
417
-     */
418
-    protected function _set_admin_settings_fields()
419
-    {
420
-    }
421
-
422
-    /**
423
-     * We just deliver the messages don't kill us!!
424
-     *
425
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
426
-     *              present.
427
-     * @throws EE_Error
428
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
429
-     */
430
-    protected function _send_message()
431
-    {
432
-        $success = wp_mail(
433
-            $this->_to,
434
-            // some old values for subject may be expecting HTML entities to be decoded in the subject
435
-            // and subjects aren't interpreted as HTML, so there should be no HTML in them
436
-            wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
437
-            $this->_body(),
438
-            $this->_headers()
439
-        );
440
-        if (! $success) {
441
-            EE_Error::add_error(
442
-                sprintf(
443
-                    esc_html__(
444
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
445
-                        'event_espresso'
446
-                    ),
447
-                    $this->_to,
448
-                    $this->_from,
449
-                    '<br />'
450
-                ),
451
-                __FILE__,
452
-                __FUNCTION__,
453
-                __LINE__
454
-            );
455
-        }
456
-        return $success;
457
-    }
458
-
459
-
460
-    /**
461
-     * see parent for definition
462
-     *
463
-     * @return string html body of the message content and the related css.
464
-     * @throws EE_Error
465
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
466
-     */
467
-    protected function _preview()
468
-    {
469
-        return $this->_body(true);
470
-    }
471
-
472
-
473
-    /**
474
-     * Setup headers for email
475
-     *
476
-     * @access protected
477
-     * @return string formatted header for email
478
-     */
479
-    protected function _headers()
480
-    {
481
-        $this->_ensure_has_from_email_address();
482
-        $from    = $this->_from;
483
-        $headers = array(
484
-            'From:' . $from,
485
-            'Reply-To:' . $from,
486
-            'Content-Type:text/html; charset=utf-8',
487
-        );
488
-
489
-        /**
490
-         * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
491
-         * cover back compat where there may be users who have saved cc values in their db for the newsletter message
492
-         * type which they are no longer able to change.
493
-         */
494
-        if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
495
-            $headers[] = 'cc: ' . $this->_cc;
496
-        }
497
-
498
-        // but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
499
-        // header.
500
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
501
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
502
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
503
-    }
504
-
505
-
506
-    /**
507
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
508
-     * address for the from address to avoid problems with sending emails.
509
-     */
510
-    protected function _ensure_has_from_email_address()
511
-    {
512
-        if (empty($this->_from)) {
513
-            $this->_from = get_bloginfo('admin_email');
514
-        }
515
-    }
516
-
517
-
518
-    /**
519
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
520
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
521
-     * be empty
522
-     *
523
-     * @since 4.3.1
524
-     * @return array
525
-     */
526
-    private function _parse_from()
527
-    {
528
-        if (strpos($this->_from, '<') !== false) {
529
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
530
-            $from_name = str_replace('"', '', $from_name);
531
-            $from_name = trim($from_name);
532
-
533
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
534
-            $from_email = str_replace('>', '', $from_email);
535
-            $from_email = trim($from_email);
536
-        } elseif (trim($this->_from) !== '') {
537
-            $from_name  = '';
538
-            $from_email = trim($this->_from);
539
-        } else {
540
-            $from_name = $from_email = '';
541
-        }
542
-        return array($from_name, $from_email);
543
-    }
544
-
545
-
546
-    /**
547
-     * Callback for the wp_mail_from filter.
548
-     *
549
-     * @since 4.3.1
550
-     * @param string $from_email What the original from_email is.
551
-     * @return string
552
-     */
553
-    public function set_from_address($from_email)
554
-    {
555
-        $parsed_from = $this->_parse_from();
556
-        // includes fallback if the parsing failed.
557
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
558
-            ? $parsed_from[1]
559
-            : get_bloginfo('admin_email');
560
-        return $from_email;
561
-    }
562
-
563
-
564
-    /**
565
-     * Callback fro the wp_mail_from_name filter.
566
-     *
567
-     * @since 4.3.1
568
-     * @param string $from_name The original from_name.
569
-     * @return string
570
-     */
571
-    public function set_from_name($from_name)
572
-    {
573
-        $parsed_from = $this->_parse_from();
574
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
575
-            $from_name = $parsed_from[0];
576
-        }
577
-
578
-        // if from name is "WordPress" let's sub in the site name instead (more friendly!)
579
-        // but realize the default name is HTML entity-encoded
580
-        $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
581
-
582
-        return $from_name;
583
-    }
584
-
585
-
586
-    /**
587
-     * setup body for email
588
-     *
589
-     * @param bool $preview will determine whether this is preview template or not.
590
-     * @return string formatted body for email.
591
-     * @throws EE_Error
592
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
593
-     */
594
-    protected function _body($preview = false)
595
-    {
596
-        // setup template args!
597
-        $this->_template_args = array(
598
-            'subject'   => $this->_subject,
599
-            'from'      => $this->_from,
600
-            'main_body' => wpautop($this->_content),
601
-        );
602
-        $body                 = $this->_get_main_template($preview);
603
-
604
-        /**
605
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
606
-         *
607
-         * @type    bool $preview Indicates whether a preview is being generated or not.
608
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
609
-         */
610
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
611
-            // now if this isn't a preview, let's setup the body so it has inline styles
612
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
613
-                $style = file_get_contents(
614
-                    $this->get_variation(
615
-                        $this->_tmp_pack,
616
-                        $this->_incoming_message_type->name,
617
-                        false,
618
-                        'main',
619
-                        $this->_variation
620
-                    ),
621
-                    true
622
-                );
623
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles();
624
-                $body  = $CSS->convert($body, $style);
625
-            }
626
-        }
627
-        return $body;
628
-    }
629
-
630
-
631
-    /**
632
-     * This just returns any existing test settings that might be saved in the database
633
-     *
634
-     * @access public
635
-     * @return array
636
-     */
637
-    public function get_existing_test_settings()
638
-    {
639
-        $settings = parent::get_existing_test_settings();
640
-        // override subject if present because we always want it to be fresh.
641
-        if (is_array($settings) && ! empty($settings['subject'])) {
642
-            $settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
643
-        }
644
-        return $settings;
645
-    }
8
+	/**
9
+	 * To field for email
10
+	 * @var string
11
+	 */
12
+	protected $_to = '';
13
+
14
+
15
+	/**
16
+	 * CC field for email.
17
+	 * @var string
18
+	 */
19
+	protected $_cc = '';
20
+
21
+	/**
22
+	 * From field for email
23
+	 * @var string
24
+	 */
25
+	protected $_from = '';
26
+
27
+
28
+	/**
29
+	 * Subject field for email
30
+	 * @var string
31
+	 */
32
+	protected $_subject = '';
33
+
34
+
35
+	/**
36
+	 * Content field for email
37
+	 * @var string
38
+	 */
39
+	protected $_content = '';
40
+
41
+
42
+	/**
43
+	 * constructor
44
+	 *
45
+	 * @access public
46
+	 */
47
+	public function __construct()
48
+	{
49
+		// set name and description properties
50
+		$this->name                = 'email';
51
+		$this->description         = sprintf(
52
+			esc_html__(
53
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
54
+				'event_espresso'
55
+			),
56
+			'<code>wp_mail</code>'
57
+		);
58
+		$this->label               = array(
59
+			'singular' => esc_html__('email', 'event_espresso'),
60
+			'plural'   => esc_html__('emails', 'event_espresso'),
61
+		);
62
+		$this->activate_on_install = true;
63
+
64
+		// we're using defaults so let's call parent constructor that will take care of setting up all the other
65
+		// properties
66
+		parent::__construct();
67
+	}
68
+
69
+
70
+	/**
71
+	 * see abstract declaration in parent class for details.
72
+	 */
73
+	protected function _set_admin_pages()
74
+	{
75
+		$this->admin_registered_pages = array(
76
+			'events_edit' => true,
77
+		);
78
+	}
79
+
80
+
81
+	/**
82
+	 * see abstract declaration in parent class for details
83
+	 */
84
+	protected function _set_valid_shortcodes()
85
+	{
86
+		// remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
87
+		// message type.
88
+		$this->_valid_shortcodes = array(
89
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
90
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
+		);
93
+	}
94
+
95
+
96
+	/**
97
+	 * see abstract declaration in parent class for details
98
+	 *
99
+	 * @access protected
100
+	 * @return void
101
+	 */
102
+	protected function _set_validator_config()
103
+	{
104
+		$valid_shortcodes = $this->get_valid_shortcodes();
105
+
106
+		$this->_validator_config = array(
107
+			'to'            => array(
108
+				'shortcodes' => $valid_shortcodes['to'],
109
+				'type'       => 'email',
110
+			),
111
+			'cc' => array(
112
+				'shortcodes' => $valid_shortcodes['to'],
113
+				'type' => 'email',
114
+			),
115
+			'from'          => array(
116
+				'shortcodes' => $valid_shortcodes['from'],
117
+				'type'       => 'email',
118
+			),
119
+			'subject'       => array(
120
+				'shortcodes' => array(
121
+					'organization',
122
+					'primary_registration_details',
123
+					'event_author',
124
+					'primary_registration_details',
125
+					'recipient_details',
126
+				),
127
+			),
128
+			'content'       => array(
129
+				'shortcodes' => array(
130
+					'event_list',
131
+					'attendee_list',
132
+					'ticket_list',
133
+					'organization',
134
+					'primary_registration_details',
135
+					'primary_registration_list',
136
+					'event_author',
137
+					'recipient_details',
138
+					'recipient_list',
139
+					'transaction',
140
+					'messenger',
141
+				),
142
+			),
143
+			'attendee_list' => array(
144
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
145
+				'required'   => array('[ATTENDEE_LIST]'),
146
+			),
147
+			'event_list'    => array(
148
+				'shortcodes' => array(
149
+					'event',
150
+					'attendee_list',
151
+					'ticket_list',
152
+					'venue',
153
+					'datetime_list',
154
+					'attendee',
155
+					'primary_registration_details',
156
+					'primary_registration_list',
157
+					'event_author',
158
+					'recipient_details',
159
+					'recipient_list',
160
+				),
161
+				'required'   => array('[EVENT_LIST]'),
162
+			),
163
+			'ticket_list'   => array(
164
+				'shortcodes' => array(
165
+					'event_list',
166
+					'attendee_list',
167
+					'ticket',
168
+					'datetime_list',
169
+					'primary_registration_details',
170
+					'recipient_details',
171
+				),
172
+				'required'   => array('[TICKET_LIST]'),
173
+			),
174
+			'datetime_list' => array(
175
+				'shortcodes' => array('datetime'),
176
+				'required'   => array('[DATETIME_LIST]'),
177
+			),
178
+		);
179
+	}
180
+
181
+
182
+	/**
183
+	 * @see   parent EE_messenger class for docs
184
+	 * @since 4.5.0
185
+	 */
186
+	public function do_secondary_messenger_hooks($sending_messenger_name)
187
+	{
188
+		if ($sending_messenger_name === 'html') {
189
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
190
+		}
191
+	}
192
+
193
+
194
+	public function add_email_css(
195
+		$variation_path,
196
+		$messenger,
197
+		$message_type,
198
+		$type,
199
+		$variation,
200
+		$file_extension,
201
+		$url,
202
+		EE_Messages_Template_Pack $template_pack
203
+	) {
204
+		// prevent recursion on this callback.
205
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
206
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
207
+
208
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
209
+		return $variation;
210
+	}
211
+
212
+
213
+	/**
214
+	 * See parent for details
215
+	 *
216
+	 * @access protected
217
+	 * @return void
218
+	 */
219
+	protected function _set_test_settings_fields()
220
+	{
221
+		$this->_test_settings_fields = array(
222
+			'to'      => array(
223
+				'input'      => 'text',
224
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
225
+				'type'       => 'email',
226
+				'required'   => false,
227
+				'validation' => true,
228
+				'css_class'  => 'ee-input-width--big',
229
+				'format'     => '%s',
230
+				'default'    => get_bloginfo('admin_email'),
231
+			),
232
+			'subject' => array(
233
+				'input'      => 'hidden',
234
+				'label'      => '',
235
+				'type'       => 'string',
236
+				'required'   => false,
237
+				'validation' => false,
238
+				'format'     => '%s',
239
+				'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
240
+				'default'    => '',
241
+				'css_class'  => '',
242
+			),
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * _set_template_fields
249
+	 * This sets up the fields that a messenger requires for the message to go out.
250
+	 *
251
+	 * @access  protected
252
+	 * @return void
253
+	 */
254
+	protected function _set_template_fields()
255
+	{
256
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
257
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
258
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
259
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
260
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
261
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
262
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
263
+		// will not be displayed/parsed.
264
+		$this->_template_fields = array(
265
+			'to'      => array(
266
+				'input'      => 'text',
267
+				'label'      => esc_html_x(
268
+					'To',
269
+					'Label for the "To" field for email addresses',
270
+					'event_espresso'
271
+				),
272
+				'type'       => 'string',
273
+				'required'   => false,
274
+				'validation' => true,
275
+				'css_class'  => 'large-text',
276
+				'format'     => '%s',
277
+			),
278
+			'cc'      => array(
279
+				'input'      => 'text',
280
+				'label'      => esc_html_x(
281
+					'CC',
282
+					'Label for the "Carbon Copy" field used for additional email addresses',
283
+					'event_espresso'
284
+				),
285
+				'type'       => 'string',
286
+				'required'   => false,
287
+				'validation' => true,
288
+				'css_class'  => 'large-text',
289
+				'format'     => '%s',
290
+			),
291
+			'from'    => array(
292
+				'input'      => 'text',
293
+				'label'      => esc_html_x(
294
+					'From',
295
+					'Label for the "From" field for email addresses.',
296
+					'event_espresso'
297
+				),
298
+				'type'       => 'string',
299
+				'required'   => false,
300
+				'validation' => true,
301
+				'css_class'  => 'large-text',
302
+				'format'     => '%s',
303
+			),
304
+			'subject' => array(
305
+				'input'      => 'text',
306
+				'label'      => esc_html_x(
307
+					'Subject',
308
+					'Label for the "Subject" field (short description of contents) for emails.',
309
+					'event_espresso'
310
+				),
311
+				'type'       => 'string',
312
+				'required'   => true,
313
+				'validation' => true,
314
+				'css_class'  => 'large-text',
315
+				'format'     => '%s',
316
+			),
317
+			'content' => '',
318
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
319
+			'extra'   => array(
320
+				'content' => array(
321
+					'main'          => array(
322
+						'input'      => 'wp_editor',
323
+						'label'      => esc_html__('Main Content', 'event_espresso'),
324
+						'type'       => 'string',
325
+						'required'   => false,
326
+						'validation' => true,
327
+						'format'     => '%s',
328
+						'rows'       => '15',
329
+					),
330
+					'event_list'    => array(
331
+						'input'               => 'wp_editor',
332
+						'label'               => '[EVENT_LIST]',
333
+						'type'                => 'string',
334
+						'required'            => false,
335
+						'validation'          => true,
336
+						'format'              => '%s',
337
+						'rows'                => '15',
338
+						'shortcodes_required' => array('[EVENT_LIST]'),
339
+					),
340
+					'attendee_list' => array(
341
+						'input'               => 'textarea',
342
+						'label'               => '[ATTENDEE_LIST]',
343
+						'type'                => 'string',
344
+						'required'            => false,
345
+						'validation'          => true,
346
+						'format'              => '%s',
347
+						'css_class'           => 'large-text',
348
+						'rows'                => '5',
349
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
350
+					),
351
+					'ticket_list'   => array(
352
+						'input'               => 'textarea',
353
+						'label'               => '[TICKET_LIST]',
354
+						'type'                => 'string',
355
+						'required'            => false,
356
+						'validation'          => true,
357
+						'format'              => '%s',
358
+						'css_class'           => 'large-text',
359
+						'rows'                => '10',
360
+						'shortcodes_required' => array('[TICKET_LIST]'),
361
+					),
362
+					'datetime_list' => array(
363
+						'input'               => 'textarea',
364
+						'label'               => '[DATETIME_LIST]',
365
+						'type'                => 'string',
366
+						'required'            => false,
367
+						'validation'          => true,
368
+						'format'              => '%s',
369
+						'css_class'           => 'large-text',
370
+						'rows'                => '10',
371
+						'shortcodes_required' => array('[DATETIME_LIST]'),
372
+					),
373
+				),
374
+			),
375
+		);
376
+	}
377
+
378
+
379
+	/**
380
+	 * See definition of this class in parent
381
+	 */
382
+	protected function _set_default_message_types()
383
+	{
384
+		$this->_default_message_types = array(
385
+			'payment',
386
+			'payment_refund',
387
+			'registration',
388
+			'not_approved_registration',
389
+			'pending_approval',
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * @see   definition of this class in parent
396
+	 * @since 4.5.0
397
+	 */
398
+	protected function _set_valid_message_types()
399
+	{
400
+		$this->_valid_message_types = array(
401
+			'payment',
402
+			'registration',
403
+			'not_approved_registration',
404
+			'declined_registration',
405
+			'cancelled_registration',
406
+			'pending_approval',
407
+			'registration_summary',
408
+			'payment_reminder',
409
+			'payment_declined',
410
+			'payment_refund',
411
+		);
412
+	}
413
+
414
+
415
+	/**
416
+	 * setting up admin_settings_fields for messenger.
417
+	 */
418
+	protected function _set_admin_settings_fields()
419
+	{
420
+	}
421
+
422
+	/**
423
+	 * We just deliver the messages don't kill us!!
424
+	 *
425
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
426
+	 *              present.
427
+	 * @throws EE_Error
428
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
429
+	 */
430
+	protected function _send_message()
431
+	{
432
+		$success = wp_mail(
433
+			$this->_to,
434
+			// some old values for subject may be expecting HTML entities to be decoded in the subject
435
+			// and subjects aren't interpreted as HTML, so there should be no HTML in them
436
+			wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
437
+			$this->_body(),
438
+			$this->_headers()
439
+		);
440
+		if (! $success) {
441
+			EE_Error::add_error(
442
+				sprintf(
443
+					esc_html__(
444
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
445
+						'event_espresso'
446
+					),
447
+					$this->_to,
448
+					$this->_from,
449
+					'<br />'
450
+				),
451
+				__FILE__,
452
+				__FUNCTION__,
453
+				__LINE__
454
+			);
455
+		}
456
+		return $success;
457
+	}
458
+
459
+
460
+	/**
461
+	 * see parent for definition
462
+	 *
463
+	 * @return string html body of the message content and the related css.
464
+	 * @throws EE_Error
465
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
466
+	 */
467
+	protected function _preview()
468
+	{
469
+		return $this->_body(true);
470
+	}
471
+
472
+
473
+	/**
474
+	 * Setup headers for email
475
+	 *
476
+	 * @access protected
477
+	 * @return string formatted header for email
478
+	 */
479
+	protected function _headers()
480
+	{
481
+		$this->_ensure_has_from_email_address();
482
+		$from    = $this->_from;
483
+		$headers = array(
484
+			'From:' . $from,
485
+			'Reply-To:' . $from,
486
+			'Content-Type:text/html; charset=utf-8',
487
+		);
488
+
489
+		/**
490
+		 * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
491
+		 * cover back compat where there may be users who have saved cc values in their db for the newsletter message
492
+		 * type which they are no longer able to change.
493
+		 */
494
+		if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
495
+			$headers[] = 'cc: ' . $this->_cc;
496
+		}
497
+
498
+		// but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
499
+		// header.
500
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
501
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
502
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
503
+	}
504
+
505
+
506
+	/**
507
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
508
+	 * address for the from address to avoid problems with sending emails.
509
+	 */
510
+	protected function _ensure_has_from_email_address()
511
+	{
512
+		if (empty($this->_from)) {
513
+			$this->_from = get_bloginfo('admin_email');
514
+		}
515
+	}
516
+
517
+
518
+	/**
519
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
520
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
521
+	 * be empty
522
+	 *
523
+	 * @since 4.3.1
524
+	 * @return array
525
+	 */
526
+	private function _parse_from()
527
+	{
528
+		if (strpos($this->_from, '<') !== false) {
529
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
530
+			$from_name = str_replace('"', '', $from_name);
531
+			$from_name = trim($from_name);
532
+
533
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
534
+			$from_email = str_replace('>', '', $from_email);
535
+			$from_email = trim($from_email);
536
+		} elseif (trim($this->_from) !== '') {
537
+			$from_name  = '';
538
+			$from_email = trim($this->_from);
539
+		} else {
540
+			$from_name = $from_email = '';
541
+		}
542
+		return array($from_name, $from_email);
543
+	}
544
+
545
+
546
+	/**
547
+	 * Callback for the wp_mail_from filter.
548
+	 *
549
+	 * @since 4.3.1
550
+	 * @param string $from_email What the original from_email is.
551
+	 * @return string
552
+	 */
553
+	public function set_from_address($from_email)
554
+	{
555
+		$parsed_from = $this->_parse_from();
556
+		// includes fallback if the parsing failed.
557
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
558
+			? $parsed_from[1]
559
+			: get_bloginfo('admin_email');
560
+		return $from_email;
561
+	}
562
+
563
+
564
+	/**
565
+	 * Callback fro the wp_mail_from_name filter.
566
+	 *
567
+	 * @since 4.3.1
568
+	 * @param string $from_name The original from_name.
569
+	 * @return string
570
+	 */
571
+	public function set_from_name($from_name)
572
+	{
573
+		$parsed_from = $this->_parse_from();
574
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
575
+			$from_name = $parsed_from[0];
576
+		}
577
+
578
+		// if from name is "WordPress" let's sub in the site name instead (more friendly!)
579
+		// but realize the default name is HTML entity-encoded
580
+		$from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
581
+
582
+		return $from_name;
583
+	}
584
+
585
+
586
+	/**
587
+	 * setup body for email
588
+	 *
589
+	 * @param bool $preview will determine whether this is preview template or not.
590
+	 * @return string formatted body for email.
591
+	 * @throws EE_Error
592
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
593
+	 */
594
+	protected function _body($preview = false)
595
+	{
596
+		// setup template args!
597
+		$this->_template_args = array(
598
+			'subject'   => $this->_subject,
599
+			'from'      => $this->_from,
600
+			'main_body' => wpautop($this->_content),
601
+		);
602
+		$body                 = $this->_get_main_template($preview);
603
+
604
+		/**
605
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
606
+		 *
607
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
608
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
609
+		 */
610
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
611
+			// now if this isn't a preview, let's setup the body so it has inline styles
612
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
613
+				$style = file_get_contents(
614
+					$this->get_variation(
615
+						$this->_tmp_pack,
616
+						$this->_incoming_message_type->name,
617
+						false,
618
+						'main',
619
+						$this->_variation
620
+					),
621
+					true
622
+				);
623
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles();
624
+				$body  = $CSS->convert($body, $style);
625
+			}
626
+		}
627
+		return $body;
628
+	}
629
+
630
+
631
+	/**
632
+	 * This just returns any existing test settings that might be saved in the database
633
+	 *
634
+	 * @access public
635
+	 * @return array
636
+	 */
637
+	public function get_existing_test_settings()
638
+	{
639
+		$settings = parent::get_existing_test_settings();
640
+		// override subject if present because we always want it to be fresh.
641
+		if (is_array($settings) && ! empty($settings['subject'])) {
642
+			$settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
643
+		}
644
+		return $settings;
645
+	}
646 646
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Datetime.php 1 patch
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -18,214 +18,214 @@
 block discarded – undo
18 18
 
19 19
 class Datetime extends DatetimeCalculationBase
20 20
 {
21
-    /**
22
-     * @var EEM_Datetime
23
-     */
24
-    protected $datetime_model;
21
+	/**
22
+	 * @var EEM_Datetime
23
+	 */
24
+	protected $datetime_model;
25 25
 
26
-    /**
27
-     * @var EEM_Registration
28
-     */
29
-    protected $registration_model;
30
-    public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
31
-    {
32
-        $this->datetime_model = $datetime_model;
33
-        $this->registration_model = $registration_model;
34
-    }
26
+	/**
27
+	 * @var EEM_Registration
28
+	 */
29
+	protected $registration_model;
30
+	public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
31
+	{
32
+		$this->datetime_model = $datetime_model;
33
+		$this->registration_model = $registration_model;
34
+	}
35 35
 
36
-    /**
37
-     * Calculates the total spaces available on the datetime, taking into account
38
-     * ticket limits too.
39
-     *
40
-     * @see EE_Datetime::spaces_remaining( true )
41
-     * @param array            $wpdb_row
42
-     * @param WP_REST_Request $request
43
-     * @param DatetimeControllerBase  $controller
44
-     * @return int
45
-     * @throws EE_Error
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws InvalidArgumentException
49
-     * @throws ReflectionException
50
-     */
51
-    public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
52
-    {
53
-        if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
54
-            $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
55
-        } else {
56
-            $dtt_obj = null;
57
-        }
58
-        if ($dtt_obj instanceof EE_Datetime) {
59
-            return $dtt_obj->spaces_remaining(true);
60
-        }
61
-        throw new EE_Error(
62
-            sprintf(
63
-                esc_html__(
64
-                // @codingStandardsIgnoreStart
65
-                    'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
66
-                    // @codingStandardsIgnoreEnd
67
-                    'event_espresso'
68
-                ),
69
-                $wpdb_row['Datetime.DTT_ID'],
70
-                print_r($wpdb_row, true)
71
-            )
72
-        );
73
-    }
36
+	/**
37
+	 * Calculates the total spaces available on the datetime, taking into account
38
+	 * ticket limits too.
39
+	 *
40
+	 * @see EE_Datetime::spaces_remaining( true )
41
+	 * @param array            $wpdb_row
42
+	 * @param WP_REST_Request $request
43
+	 * @param DatetimeControllerBase  $controller
44
+	 * @return int
45
+	 * @throws EE_Error
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws InvalidArgumentException
49
+	 * @throws ReflectionException
50
+	 */
51
+	public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
52
+	{
53
+		if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
54
+			$dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
55
+		} else {
56
+			$dtt_obj = null;
57
+		}
58
+		if ($dtt_obj instanceof EE_Datetime) {
59
+			return $dtt_obj->spaces_remaining(true);
60
+		}
61
+		throw new EE_Error(
62
+			sprintf(
63
+				esc_html__(
64
+				// @codingStandardsIgnoreStart
65
+					'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
66
+					// @codingStandardsIgnoreEnd
67
+					'event_espresso'
68
+				),
69
+				$wpdb_row['Datetime.DTT_ID'],
70
+				print_r($wpdb_row, true)
71
+			)
72
+		);
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * Counts registrations who have checked into this datetime
78
-     *
79
-     * @param array           $wpdb_row
80
-     * @param WP_REST_Request $request
81
-     * @param DatetimeControllerBase $controller
82
-     * @return int
83
-     * @throws EE_Error
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidDataTypeException
86
-     * @throws InvalidInterfaceException
87
-     * @throws RestException
88
-     */
89
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
90
-    {
91
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
92
-            throw new EE_Error(
93
-                sprintf(
94
-                    esc_html__(
95
-                    // @codingStandardsIgnoreStart
96
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
97
-                        // @codingStandardsIgnoreEnd
98
-                        'event_espresso'
99
-                    ),
100
-                    print_r($wpdb_row, true)
101
-                )
102
-            );
103
-        }
104
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
105
-        return $this->registration_model
106
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
107
-    }
76
+	/**
77
+	 * Counts registrations who have checked into this datetime
78
+	 *
79
+	 * @param array           $wpdb_row
80
+	 * @param WP_REST_Request $request
81
+	 * @param DatetimeControllerBase $controller
82
+	 * @return int
83
+	 * @throws EE_Error
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidDataTypeException
86
+	 * @throws InvalidInterfaceException
87
+	 * @throws RestException
88
+	 */
89
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
90
+	{
91
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
92
+			throw new EE_Error(
93
+				sprintf(
94
+					esc_html__(
95
+					// @codingStandardsIgnoreStart
96
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
97
+						// @codingStandardsIgnoreEnd
98
+						'event_espresso'
99
+					),
100
+					print_r($wpdb_row, true)
101
+				)
102
+			);
103
+		}
104
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
105
+		return $this->registration_model
106
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
107
+	}
108 108
 
109 109
 
110
-    /**
111
-     * Counts registrations who have checked out of this datetime
112
-     *
113
-     * @param array           $wpdb_row
114
-     * @param WP_REST_Request $request
115
-     * @param DatetimeControllerBase $controller
116
-     * @return int
117
-     * @throws EE_Error
118
-     * @throws InvalidArgumentException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     * @throws RestException
122
-     */
123
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
124
-    {
125
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
126
-            throw new EE_Error(
127
-                sprintf(
128
-                    esc_html__(
129
-                    // @codingStandardsIgnoreStart
130
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
131
-                        // @codingStandardsIgnoreEnd
132
-                        'event_espresso'
133
-                    ),
134
-                    print_r($wpdb_row, true)
135
-                )
136
-            );
137
-        }
138
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
139
-        return $this->registration_model
140
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
141
-    }
110
+	/**
111
+	 * Counts registrations who have checked out of this datetime
112
+	 *
113
+	 * @param array           $wpdb_row
114
+	 * @param WP_REST_Request $request
115
+	 * @param DatetimeControllerBase $controller
116
+	 * @return int
117
+	 * @throws EE_Error
118
+	 * @throws InvalidArgumentException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 * @throws RestException
122
+	 */
123
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
124
+	{
125
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
126
+			throw new EE_Error(
127
+				sprintf(
128
+					esc_html__(
129
+					// @codingStandardsIgnoreStart
130
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
131
+						// @codingStandardsIgnoreEnd
132
+						'event_espresso'
133
+					),
134
+					print_r($wpdb_row, true)
135
+				)
136
+			);
137
+		}
138
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
139
+		return $this->registration_model
140
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
141
+	}
142 142
 
143 143
 
144
-    /**
145
-     * Counts the number of pending-payment registrations for this event (regardless
146
-     * of how many datetimes each registrations' ticket purchase is for)
147
-     *
148
-     * @param array           $wpdb_row
149
-     * @param WP_REST_Request $request
150
-     * @param DatetimeControllerBase $controller
151
-     * @return int
152
-     * @throws EE_Error
153
-     * @throws InvalidArgumentException
154
-     * @throws InvalidDataTypeException
155
-     * @throws InvalidInterfaceException
156
-     * @throws RestException
157
-     */
158
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
159
-    {
160
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
161
-            throw new EE_Error(
162
-                sprintf(
163
-                    esc_html__(
164
-                    // @codingStandardsIgnoreStart
165
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
166
-                        // @codingStandardsIgnoreEnd
167
-                        'event_espresso'
168
-                    ),
169
-                    print_r($wpdb_row, true)
170
-                )
171
-            );
172
-        }
173
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
174
-        return $this->registration_model->count(
175
-            array(
176
-                array(
177
-                    'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
178
-                    'STS_ID'                 => RegStatus::PENDING_PAYMENT,
179
-                ),
180
-            ),
181
-            'REG_ID',
182
-            true
183
-        );
184
-    }
144
+	/**
145
+	 * Counts the number of pending-payment registrations for this event (regardless
146
+	 * of how many datetimes each registrations' ticket purchase is for)
147
+	 *
148
+	 * @param array           $wpdb_row
149
+	 * @param WP_REST_Request $request
150
+	 * @param DatetimeControllerBase $controller
151
+	 * @return int
152
+	 * @throws EE_Error
153
+	 * @throws InvalidArgumentException
154
+	 * @throws InvalidDataTypeException
155
+	 * @throws InvalidInterfaceException
156
+	 * @throws RestException
157
+	 */
158
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
159
+	{
160
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
161
+			throw new EE_Error(
162
+				sprintf(
163
+					esc_html__(
164
+					// @codingStandardsIgnoreStart
165
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
166
+						// @codingStandardsIgnoreEnd
167
+						'event_espresso'
168
+					),
169
+					print_r($wpdb_row, true)
170
+				)
171
+			);
172
+		}
173
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
174
+		return $this->registration_model->count(
175
+			array(
176
+				array(
177
+					'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
178
+					'STS_ID'                 => RegStatus::PENDING_PAYMENT,
179
+				),
180
+			),
181
+			'REG_ID',
182
+			true
183
+		);
184
+	}
185 185
 
186 186
 
187
-    /**
188
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
189
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
190
-     *
191
-     * @since 4.9.68.p
192
-     * @return array
193
-     */
194
-    public function schemaForCalculations()
195
-    {
196
-        return array(
197
-            'spaces_remaining_considering_tickets' => array(
198
-                'description' => esc_html__(
199
-                    'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
200
-                    'event_espresso'
201
-                ),
202
-                'type' => 'number',
203
-                'protected' => true,
204
-            ),
205
-            'registrations_checked_in_count' => array(
206
-                'description' => esc_html__(
207
-                    'Counts registrations who have checked into this datetime.',
208
-                    'event_espresso'
209
-                ),
210
-                'type' => 'number',
211
-                'protected' => true,
212
-            ),
213
-            'registrations_checked_out_count' => array(
214
-                'description' => esc_html__(
215
-                    'Counts registrations who have checked out of this datetime.',
216
-                    'event_espresso'
217
-                ),
218
-                'type' => 'number',
219
-                'protected' => true,
220
-            ),
221
-            'spots_taken_pending_payment' => array(
222
-                'description' => esc_html__(
223
-                    'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
224
-                    'event_espresso'
225
-                ),
226
-                'type' => 'number',
227
-                'protected' => true,
228
-            ),
229
-        );
230
-    }
187
+	/**
188
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
189
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
190
+	 *
191
+	 * @since 4.9.68.p
192
+	 * @return array
193
+	 */
194
+	public function schemaForCalculations()
195
+	{
196
+		return array(
197
+			'spaces_remaining_considering_tickets' => array(
198
+				'description' => esc_html__(
199
+					'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
200
+					'event_espresso'
201
+				),
202
+				'type' => 'number',
203
+				'protected' => true,
204
+			),
205
+			'registrations_checked_in_count' => array(
206
+				'description' => esc_html__(
207
+					'Counts registrations who have checked into this datetime.',
208
+					'event_espresso'
209
+				),
210
+				'type' => 'number',
211
+				'protected' => true,
212
+			),
213
+			'registrations_checked_out_count' => array(
214
+				'description' => esc_html__(
215
+					'Counts registrations who have checked out of this datetime.',
216
+					'event_espresso'
217
+				),
218
+				'type' => 'number',
219
+				'protected' => true,
220
+			),
221
+			'spots_taken_pending_payment' => array(
222
+				'description' => esc_html__(
223
+					'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
224
+					'event_espresso'
225
+				),
226
+				'type' => 'number',
227
+				'protected' => true,
228
+			),
229
+		);
230
+	}
231 231
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Event.php 1 patch
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -27,571 +27,571 @@
 block discarded – undo
27 27
  */
28 28
 class Event extends EventCalculationBase
29 29
 {
30
-    /**
31
-     * @var EEM_Event
32
-     */
33
-    protected $event_model;
34
-
35
-    /**
36
-     * @var EEM_Registration
37
-     */
38
-    protected $registration_model;
39
-    public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
40
-    {
41
-        $this->event_model = $event_model;
42
-        $this->registration_model = $registration_model;
43
-    }
44
-
45
-    /**
46
-     * Calculates the total spaces on the event (not subtracting sales, but taking
47
-     * sales into account; so this is the optimum sales that CAN still be achieved)
48
-     * See EE_Event::total_available_spaces( true );
49
-     *
50
-     * @param array               $wpdb_row
51
-     * @param WP_REST_Request     $request
52
-     * @param EventControllerBase $controller
53
-     * @return int
54
-     * @throws EE_Error
55
-     * @throws DomainException
56
-     * @throws InvalidDataTypeException
57
-     * @throws InvalidInterfaceException
58
-     * @throws UnexpectedEntityException
59
-     * @throws InvalidArgumentException
60
-     */
61
-    public function optimumSalesAtStart($wpdb_row, $request, $controller)
62
-    {
63
-        $event_obj = null;
64
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
65
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
66
-        }
67
-        if ($event_obj instanceof EE_Event) {
68
-            return $event_obj->total_available_spaces();
69
-        }
70
-        throw new EE_Error(
71
-            sprintf(
72
-                esc_html__(
73
-                // @codingStandardsIgnoreStart
74
-                    'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
75
-                    // @codingStandardsIgnoreEnd
76
-                    'event_espresso'
77
-                ),
78
-                $wpdb_row['Event_CPT.ID'],
79
-                print_r($wpdb_row, true)
80
-            )
81
-        );
82
-    }
83
-
84
-
85
-    /**
86
-     * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
87
-     * sales that COULD have been achieved)
88
-     * See EE_Event::total_available_spaces( true );
89
-     *
90
-     * @param array               $wpdb_row
91
-     * @param WP_REST_Request     $request
92
-     * @param EventControllerBase $controller
93
-     * @return int
94
-     * @throws DomainException
95
-     * @throws EE_Error
96
-     * @throws InvalidArgumentException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     * @throws UnexpectedEntityException
100
-     */
101
-    public function optimumSalesNow($wpdb_row, $request, $controller)
102
-    {
103
-        $event_obj = null;
104
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
105
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
106
-        }
107
-        if ($event_obj instanceof EE_Event) {
108
-            return $event_obj->total_available_spaces(true);
109
-        }
110
-        throw new EE_Error(
111
-            sprintf(
112
-                esc_html__(
113
-                // @codingStandardsIgnoreStart
114
-                    'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
115
-                    // @codingStandardsIgnoreEnd
116
-                    'event_espresso'
117
-                ),
118
-                $wpdb_row['Event_CPT.ID'],
119
-                print_r($wpdb_row, true)
120
-            )
121
-        );
122
-    }
123
-
124
-
125
-    /**
126
-     * Like optimum_sales_now, but minus total sales so far.
127
-     * See EE_Event::spaces_remaining_for_sale( true );
128
-     *
129
-     * @param array               $wpdb_row
130
-     * @param WP_REST_Request     $request
131
-     * @param EventControllerBase $controller
132
-     * @return int
133
-     * @throws DomainException
134
-     * @throws EE_Error
135
-     * @throws InvalidArgumentException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidInterfaceException
138
-     * @throws UnexpectedEntityException
139
-     */
140
-    public function spacesRemaining($wpdb_row, $request, $controller)
141
-    {
142
-        $event_obj = null;
143
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
144
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
145
-        }
146
-        if ($event_obj instanceof EE_Event) {
147
-            return $event_obj->spaces_remaining_for_sale();
148
-        }
149
-        throw new EE_Error(
150
-            sprintf(
151
-                esc_html__(
152
-                // @codingStandardsIgnoreStart
153
-                    'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
154
-                    // @codingStandardsIgnoreEnd
155
-                    'event_espresso'
156
-                ),
157
-                $wpdb_row['Event_CPT.ID'],
158
-                print_r($wpdb_row, true)
159
-            )
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * Counts the number of approved registrations for this event (regardless
166
-     * of how many datetimes each registrations' ticket purchase is for)
167
-     *
168
-     * @param array               $wpdb_row
169
-     * @param WP_REST_Request     $request
170
-     * @param EventControllerBase $controller
171
-     * @return int
172
-     * @throws EE_Error
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     */
177
-    public function spotsTaken($wpdb_row, $request, $controller)
178
-    {
179
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
180
-            throw new EE_Error(
181
-                sprintf(
182
-                    esc_html__(
183
-                    // @codingStandardsIgnoreStart
184
-                        'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
185
-                        // @codingStandardsIgnoreEnd
186
-                        'event_espresso'
187
-                    ),
188
-                    print_r($wpdb_row, true)
189
-                )
190
-            );
191
-        }
192
-        return $this->registration_model->count(
193
-            array(
194
-                array(
195
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
196
-                    'STS_ID' => RegStatus::APPROVED,
197
-                ),
198
-            ),
199
-            'REG_ID',
200
-            true
201
-        );
202
-    }
203
-
204
-
205
-    /**
206
-     * Counts the number of pending-payment registrations for this event (regardless
207
-     * of how many datetimes each registrations' ticket purchase is for)
208
-     *
209
-     * @param array               $wpdb_row
210
-     * @param WP_REST_Request     $request
211
-     * @param EventControllerBase $controller
212
-     * @return int
213
-     * @throws EE_Error
214
-     * @throws InvalidArgumentException
215
-     * @throws InvalidDataTypeException
216
-     * @throws InvalidInterfaceException
217
-     * @throws RestException
218
-     */
219
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
220
-    {
221
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
222
-            throw new EE_Error(
223
-                sprintf(
224
-                    esc_html__(
225
-                    // @codingStandardsIgnoreStart
226
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
227
-                        // @codingStandardsIgnoreEnd
228
-                        'event_espresso'
229
-                    ),
230
-                    print_r($wpdb_row, true)
231
-                )
232
-            );
233
-        }
234
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
235
-        return $this->registration_model->count(
236
-            array(
237
-                array(
238
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
239
-                    'STS_ID' => RegStatus::PENDING_PAYMENT,
240
-                ),
241
-            ),
242
-            'REG_ID',
243
-            true
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * Counts all the registrations who have checked into one of this events' datetimes
250
-     * See EE_Event::total_available_spaces( false );
251
-     *
252
-     * @param array               $wpdb_row
253
-     * @param WP_REST_Request     $request
254
-     * @param EventControllerBase $controller
255
-     * @return int|null if permission denied
256
-     * @throws EE_Error
257
-     * @throws InvalidArgumentException
258
-     * @throws InvalidDataTypeException
259
-     * @throws InvalidInterfaceException
260
-     * @throws RestException
261
-     */
262
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
263
-    {
264
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
265
-            throw new EE_Error(
266
-                sprintf(
267
-                    esc_html__(
268
-                    // @codingStandardsIgnoreStart
269
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
270
-                        // @codingStandardsIgnoreEnd
271
-                        'event_espresso'
272
-                    ),
273
-                    print_r($wpdb_row, true)
274
-                )
275
-            );
276
-        }
277
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
278
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
279
-    }
280
-
281
-
282
-    /**
283
-     * Counts all the registrations who have checked out of one of this events' datetimes
284
-     * See EE_Event::total_available_spaces( false );
285
-     *
286
-     * @param array               $wpdb_row
287
-     * @param WP_REST_Request     $request
288
-     * @param EventControllerBase $controller
289
-     * @return int
290
-     * @throws EE_Error
291
-     * @throws InvalidArgumentException
292
-     * @throws InvalidDataTypeException
293
-     * @throws InvalidInterfaceException
294
-     * @throws RestException
295
-     */
296
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
297
-    {
298
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
299
-            throw new EE_Error(
300
-                sprintf(
301
-                    esc_html__(
302
-                    // @codingStandardsIgnoreStart
303
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
304
-                        // @codingStandardsIgnoreEnd
305
-                        'event_espresso'
306
-                    ),
307
-                    print_r($wpdb_row, true)
308
-                )
309
-            );
310
-        }
311
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
312
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
313
-    }
314
-
315
-
316
-    /**
317
-     * Gets the thumbnail image
318
-     *
319
-     * @param array               $wpdb_row
320
-     * @param WP_REST_Request     $request
321
-     * @param EventControllerBase $controller
322
-     * @return array
323
-     * @throws EE_Error
324
-     */
325
-    public function imageThumbnail($wpdb_row, $request, $controller)
326
-    {
327
-        return self::calculateImageData($wpdb_row, 'thumbnail');
328
-    }
329
-
330
-
331
-    /**
332
-     * Gets the medium image
333
-     *
334
-     * @param array               $wpdb_row
335
-     * @param WP_REST_Request     $request
336
-     * @param EventControllerBase $controller
337
-     * @return array
338
-     * @throws EE_Error
339
-     */
340
-    public function imageMedium($wpdb_row, $request, $controller)
341
-    {
342
-        return self::calculateImageData($wpdb_row, 'medium');
343
-    }
344
-
345
-
346
-    /**
347
-     * Gets the medium-large image
348
-     *
349
-     * @param array               $wpdb_row
350
-     * @param WP_REST_Request     $request
351
-     * @param EventControllerBase $controller
352
-     * @return array
353
-     * @throws EE_Error
354
-     */
355
-    public function imageMediumLarge($wpdb_row, $request, $controller)
356
-    {
357
-        return self::calculateImageData($wpdb_row, 'medium_large');
358
-    }
359
-
360
-
361
-    /**
362
-     * Gets the large image
363
-     *
364
-     * @param array               $wpdb_row
365
-     * @param WP_REST_Request     $request
366
-     * @param EventControllerBase $controller
367
-     * @return array
368
-     * @throws EE_Error
369
-     */
370
-    public function imageLarge($wpdb_row, $request, $controller)
371
-    {
372
-        return self::calculateImageData($wpdb_row, 'large');
373
-    }
374
-
375
-
376
-    /**
377
-     * Gets the post-thumbnail image
378
-     *
379
-     * @param array               $wpdb_row
380
-     * @param WP_REST_Request     $request
381
-     * @param EventControllerBase $controller
382
-     * @return array
383
-     * @throws EE_Error
384
-     */
385
-    public function imagePostThumbnail($wpdb_row, $request, $controller)
386
-    {
387
-        return self::calculateImageData($wpdb_row, 'post-thumbnail');
388
-    }
389
-
390
-
391
-    /**
392
-     * Gets the full size image
393
-     *
394
-     * @param array               $wpdb_row
395
-     * @param WP_REST_Request     $request
396
-     * @param EventControllerBase $controller
397
-     * @return array
398
-     * @throws EE_Error
399
-     */
400
-    public function imageFull($wpdb_row, $request, $controller)
401
-    {
402
-        return self::calculateImageData($wpdb_row, 'full');
403
-    }
404
-
405
-
406
-    /**
407
-     * Gets image specs and formats them for the display in the API,
408
-     * according to the image size requested
409
-     *
410
-     * @param array  $wpdb_row
411
-     * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
412
-     * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
413
-     * @throws EE_Error
414
-     */
415
-    protected function calculateImageData($wpdb_row, $image_size)
416
-    {
417
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
418
-            throw new EE_Error(
419
-                sprintf(
420
-                    esc_html__(
421
-                    // @codingStandardsIgnoreStart
422
-                        'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
423
-                        // @codingStandardsIgnoreEnd
424
-                        'event_espresso'
425
-                    ),
426
-                    print_r($wpdb_row, true)
427
-                )
428
-            );
429
-        }
430
-        $EVT_ID = $wpdb_row['Event_CPT.ID'];
431
-        $attachment_id = get_post_thumbnail_id($EVT_ID);
432
-        $data = wp_get_attachment_image_src($attachment_id, $image_size);
433
-        if (! $data) {
434
-            return null;
435
-        }
436
-        $generated = true;
437
-        if (isset($data[3])) {
438
-            $generated = $data[3];
439
-        }
440
-        return array(
441
-            'url'       => $data[0],
442
-            'width'     => $data[1],
443
-            'height'    => $data[2],
444
-            'generated' => $generated,
445
-        );
446
-    }
447
-
448
-
449
-    /**
450
-     * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
451
-     *
452
-     * @param array $wpdb_row
453
-     * @return bool
454
-     */
455
-    protected function wpdbRowHasEventId($wpdb_row)
456
-    {
457
-        return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
458
-    }
459
-
460
-
461
-    /**
462
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
463
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
464
-     *
465
-     * @since 4.9.68.p
466
-     * @return array
467
-     */
468
-    public function schemaForCalculations()
469
-    {
470
-        $image_object_properties = array(
471
-            'url'       => array(
472
-                'type' => 'string',
473
-            ),
474
-            'width'     => array(
475
-                'type' => 'number',
476
-            ),
477
-            'height'    => array(
478
-                'type' => 'number',
479
-            ),
480
-            'generated' => array(
481
-                'type' => 'boolean',
482
-            ),
483
-        );
484
-        return array(
485
-            'optimum_sales_at_start'          => array(
486
-                'description' => esc_html__(
487
-                    'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
488
-                    'event_espresso'
489
-                ),
490
-                'type'        => 'number',
491
-                'protected' => true,
492
-            ),
493
-            'optimum_sales_now'               => array(
494
-                'description' => esc_html__(
495
-                    'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
496
-                    'event_espresso'
497
-                ),
498
-                'type'        => 'number',
499
-                'protected' => true,
500
-            ),
501
-            'spaces_remaining'                => array(
502
-                'description' => esc_html__(
503
-                    'The optimum_sales_number result, minus total sales so far.',
504
-                    'event_espresso'
505
-                ),
506
-                'type'        => 'number',
507
-                'protected' => true,
508
-            ),
509
-            'spots_taken'                     => array(
510
-                'description' => esc_html__(
511
-                    'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
512
-                    'event_espresso'
513
-                ),
514
-                'type'        => 'number',
515
-                'protected' => true,
516
-            ),
517
-            'spots_taken_pending_payment'     => array(
518
-                'description' => esc_html__(
519
-                    'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
520
-                    'event_espresso'
521
-                ),
522
-                'type'        => 'number',
523
-                'protected' => true,
524
-            ),
525
-            'registrations_checked_in_count'  => array(
526
-                'description' => esc_html__(
527
-                    'The count of all the registrations who have checked into one of this event\'s datetimes.',
528
-                    'event_espresso'
529
-                ),
530
-                'type'        => 'number',
531
-                'protected' => true,
532
-            ),
533
-            'registrations_checked_out_count' => array(
534
-                'description' => esc_html__(
535
-                    'The count of all registrations who have checked out of one of this event\'s datetimes.',
536
-                    'event_espresso'
537
-                ),
538
-                'type'        => 'number',
539
-                'protected' => true,
540
-            ),
541
-            'image_thumbnail'                 => array(
542
-                'description'          => esc_html__(
543
-                    'The thumbnail image data.',
544
-                    'event_espresso'
545
-                ),
546
-                'type'                 => 'object',
547
-                'properties'           => $image_object_properties,
548
-                'additionalProperties' => false,
549
-            ),
550
-            'image_medium'                    => array(
551
-                'description'          => esc_html__(
552
-                    'The medium image data.',
553
-                    'event_espresso'
554
-                ),
555
-                'type'                 => 'object',
556
-                'properties'           => $image_object_properties,
557
-                'additionalProperties' => false,
558
-            ),
559
-            'image_medium_large'              => array(
560
-                'description'          => esc_html__(
561
-                    'The medium-large image data.',
562
-                    'event_espresso'
563
-                ),
564
-                'type'                 => 'object',
565
-                'properties'           => $image_object_properties,
566
-                'additionalProperties' => false,
567
-            ),
568
-            'image_large'                     => array(
569
-                'description'          => esc_html__(
570
-                    'The large image data.',
571
-                    'event_espresso'
572
-                ),
573
-                'type'                 => 'object',
574
-                'properties'           => $image_object_properties,
575
-                'additionalProperties' => false,
576
-            ),
577
-            'image_post_thumbnail'            => array(
578
-                'description'          => esc_html__(
579
-                    'The post-thumbnail image data.',
580
-                    'event_espresso'
581
-                ),
582
-                'type'                 => 'object',
583
-                'properties'           => $image_object_properties,
584
-                'additionalProperties' => false,
585
-            ),
586
-            'image_full'                      => array(
587
-                'description'          => esc_html__(
588
-                    'The full size image data',
589
-                    'event_espresso'
590
-                ),
591
-                'type'                 => 'object',
592
-                'properties'           => $image_object_properties,
593
-                'additionalProperties' => false,
594
-            ),
595
-        );
596
-    }
30
+	/**
31
+	 * @var EEM_Event
32
+	 */
33
+	protected $event_model;
34
+
35
+	/**
36
+	 * @var EEM_Registration
37
+	 */
38
+	protected $registration_model;
39
+	public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
40
+	{
41
+		$this->event_model = $event_model;
42
+		$this->registration_model = $registration_model;
43
+	}
44
+
45
+	/**
46
+	 * Calculates the total spaces on the event (not subtracting sales, but taking
47
+	 * sales into account; so this is the optimum sales that CAN still be achieved)
48
+	 * See EE_Event::total_available_spaces( true );
49
+	 *
50
+	 * @param array               $wpdb_row
51
+	 * @param WP_REST_Request     $request
52
+	 * @param EventControllerBase $controller
53
+	 * @return int
54
+	 * @throws EE_Error
55
+	 * @throws DomainException
56
+	 * @throws InvalidDataTypeException
57
+	 * @throws InvalidInterfaceException
58
+	 * @throws UnexpectedEntityException
59
+	 * @throws InvalidArgumentException
60
+	 */
61
+	public function optimumSalesAtStart($wpdb_row, $request, $controller)
62
+	{
63
+		$event_obj = null;
64
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
65
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
66
+		}
67
+		if ($event_obj instanceof EE_Event) {
68
+			return $event_obj->total_available_spaces();
69
+		}
70
+		throw new EE_Error(
71
+			sprintf(
72
+				esc_html__(
73
+				// @codingStandardsIgnoreStart
74
+					'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
75
+					// @codingStandardsIgnoreEnd
76
+					'event_espresso'
77
+				),
78
+				$wpdb_row['Event_CPT.ID'],
79
+				print_r($wpdb_row, true)
80
+			)
81
+		);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
87
+	 * sales that COULD have been achieved)
88
+	 * See EE_Event::total_available_spaces( true );
89
+	 *
90
+	 * @param array               $wpdb_row
91
+	 * @param WP_REST_Request     $request
92
+	 * @param EventControllerBase $controller
93
+	 * @return int
94
+	 * @throws DomainException
95
+	 * @throws EE_Error
96
+	 * @throws InvalidArgumentException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 * @throws UnexpectedEntityException
100
+	 */
101
+	public function optimumSalesNow($wpdb_row, $request, $controller)
102
+	{
103
+		$event_obj = null;
104
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
105
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
106
+		}
107
+		if ($event_obj instanceof EE_Event) {
108
+			return $event_obj->total_available_spaces(true);
109
+		}
110
+		throw new EE_Error(
111
+			sprintf(
112
+				esc_html__(
113
+				// @codingStandardsIgnoreStart
114
+					'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
115
+					// @codingStandardsIgnoreEnd
116
+					'event_espresso'
117
+				),
118
+				$wpdb_row['Event_CPT.ID'],
119
+				print_r($wpdb_row, true)
120
+			)
121
+		);
122
+	}
123
+
124
+
125
+	/**
126
+	 * Like optimum_sales_now, but minus total sales so far.
127
+	 * See EE_Event::spaces_remaining_for_sale( true );
128
+	 *
129
+	 * @param array               $wpdb_row
130
+	 * @param WP_REST_Request     $request
131
+	 * @param EventControllerBase $controller
132
+	 * @return int
133
+	 * @throws DomainException
134
+	 * @throws EE_Error
135
+	 * @throws InvalidArgumentException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidInterfaceException
138
+	 * @throws UnexpectedEntityException
139
+	 */
140
+	public function spacesRemaining($wpdb_row, $request, $controller)
141
+	{
142
+		$event_obj = null;
143
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
144
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
145
+		}
146
+		if ($event_obj instanceof EE_Event) {
147
+			return $event_obj->spaces_remaining_for_sale();
148
+		}
149
+		throw new EE_Error(
150
+			sprintf(
151
+				esc_html__(
152
+				// @codingStandardsIgnoreStart
153
+					'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
154
+					// @codingStandardsIgnoreEnd
155
+					'event_espresso'
156
+				),
157
+				$wpdb_row['Event_CPT.ID'],
158
+				print_r($wpdb_row, true)
159
+			)
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * Counts the number of approved registrations for this event (regardless
166
+	 * of how many datetimes each registrations' ticket purchase is for)
167
+	 *
168
+	 * @param array               $wpdb_row
169
+	 * @param WP_REST_Request     $request
170
+	 * @param EventControllerBase $controller
171
+	 * @return int
172
+	 * @throws EE_Error
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 */
177
+	public function spotsTaken($wpdb_row, $request, $controller)
178
+	{
179
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
180
+			throw new EE_Error(
181
+				sprintf(
182
+					esc_html__(
183
+					// @codingStandardsIgnoreStart
184
+						'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
185
+						// @codingStandardsIgnoreEnd
186
+						'event_espresso'
187
+					),
188
+					print_r($wpdb_row, true)
189
+				)
190
+			);
191
+		}
192
+		return $this->registration_model->count(
193
+			array(
194
+				array(
195
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
196
+					'STS_ID' => RegStatus::APPROVED,
197
+				),
198
+			),
199
+			'REG_ID',
200
+			true
201
+		);
202
+	}
203
+
204
+
205
+	/**
206
+	 * Counts the number of pending-payment registrations for this event (regardless
207
+	 * of how many datetimes each registrations' ticket purchase is for)
208
+	 *
209
+	 * @param array               $wpdb_row
210
+	 * @param WP_REST_Request     $request
211
+	 * @param EventControllerBase $controller
212
+	 * @return int
213
+	 * @throws EE_Error
214
+	 * @throws InvalidArgumentException
215
+	 * @throws InvalidDataTypeException
216
+	 * @throws InvalidInterfaceException
217
+	 * @throws RestException
218
+	 */
219
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
220
+	{
221
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
222
+			throw new EE_Error(
223
+				sprintf(
224
+					esc_html__(
225
+					// @codingStandardsIgnoreStart
226
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
227
+						// @codingStandardsIgnoreEnd
228
+						'event_espresso'
229
+					),
230
+					print_r($wpdb_row, true)
231
+				)
232
+			);
233
+		}
234
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
235
+		return $this->registration_model->count(
236
+			array(
237
+				array(
238
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
239
+					'STS_ID' => RegStatus::PENDING_PAYMENT,
240
+				),
241
+			),
242
+			'REG_ID',
243
+			true
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * Counts all the registrations who have checked into one of this events' datetimes
250
+	 * See EE_Event::total_available_spaces( false );
251
+	 *
252
+	 * @param array               $wpdb_row
253
+	 * @param WP_REST_Request     $request
254
+	 * @param EventControllerBase $controller
255
+	 * @return int|null if permission denied
256
+	 * @throws EE_Error
257
+	 * @throws InvalidArgumentException
258
+	 * @throws InvalidDataTypeException
259
+	 * @throws InvalidInterfaceException
260
+	 * @throws RestException
261
+	 */
262
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
263
+	{
264
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
265
+			throw new EE_Error(
266
+				sprintf(
267
+					esc_html__(
268
+					// @codingStandardsIgnoreStart
269
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
270
+						// @codingStandardsIgnoreEnd
271
+						'event_espresso'
272
+					),
273
+					print_r($wpdb_row, true)
274
+				)
275
+			);
276
+		}
277
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
278
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
279
+	}
280
+
281
+
282
+	/**
283
+	 * Counts all the registrations who have checked out of one of this events' datetimes
284
+	 * See EE_Event::total_available_spaces( false );
285
+	 *
286
+	 * @param array               $wpdb_row
287
+	 * @param WP_REST_Request     $request
288
+	 * @param EventControllerBase $controller
289
+	 * @return int
290
+	 * @throws EE_Error
291
+	 * @throws InvalidArgumentException
292
+	 * @throws InvalidDataTypeException
293
+	 * @throws InvalidInterfaceException
294
+	 * @throws RestException
295
+	 */
296
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
297
+	{
298
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
299
+			throw new EE_Error(
300
+				sprintf(
301
+					esc_html__(
302
+					// @codingStandardsIgnoreStart
303
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
304
+						// @codingStandardsIgnoreEnd
305
+						'event_espresso'
306
+					),
307
+					print_r($wpdb_row, true)
308
+				)
309
+			);
310
+		}
311
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
312
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
313
+	}
314
+
315
+
316
+	/**
317
+	 * Gets the thumbnail image
318
+	 *
319
+	 * @param array               $wpdb_row
320
+	 * @param WP_REST_Request     $request
321
+	 * @param EventControllerBase $controller
322
+	 * @return array
323
+	 * @throws EE_Error
324
+	 */
325
+	public function imageThumbnail($wpdb_row, $request, $controller)
326
+	{
327
+		return self::calculateImageData($wpdb_row, 'thumbnail');
328
+	}
329
+
330
+
331
+	/**
332
+	 * Gets the medium image
333
+	 *
334
+	 * @param array               $wpdb_row
335
+	 * @param WP_REST_Request     $request
336
+	 * @param EventControllerBase $controller
337
+	 * @return array
338
+	 * @throws EE_Error
339
+	 */
340
+	public function imageMedium($wpdb_row, $request, $controller)
341
+	{
342
+		return self::calculateImageData($wpdb_row, 'medium');
343
+	}
344
+
345
+
346
+	/**
347
+	 * Gets the medium-large image
348
+	 *
349
+	 * @param array               $wpdb_row
350
+	 * @param WP_REST_Request     $request
351
+	 * @param EventControllerBase $controller
352
+	 * @return array
353
+	 * @throws EE_Error
354
+	 */
355
+	public function imageMediumLarge($wpdb_row, $request, $controller)
356
+	{
357
+		return self::calculateImageData($wpdb_row, 'medium_large');
358
+	}
359
+
360
+
361
+	/**
362
+	 * Gets the large image
363
+	 *
364
+	 * @param array               $wpdb_row
365
+	 * @param WP_REST_Request     $request
366
+	 * @param EventControllerBase $controller
367
+	 * @return array
368
+	 * @throws EE_Error
369
+	 */
370
+	public function imageLarge($wpdb_row, $request, $controller)
371
+	{
372
+		return self::calculateImageData($wpdb_row, 'large');
373
+	}
374
+
375
+
376
+	/**
377
+	 * Gets the post-thumbnail image
378
+	 *
379
+	 * @param array               $wpdb_row
380
+	 * @param WP_REST_Request     $request
381
+	 * @param EventControllerBase $controller
382
+	 * @return array
383
+	 * @throws EE_Error
384
+	 */
385
+	public function imagePostThumbnail($wpdb_row, $request, $controller)
386
+	{
387
+		return self::calculateImageData($wpdb_row, 'post-thumbnail');
388
+	}
389
+
390
+
391
+	/**
392
+	 * Gets the full size image
393
+	 *
394
+	 * @param array               $wpdb_row
395
+	 * @param WP_REST_Request     $request
396
+	 * @param EventControllerBase $controller
397
+	 * @return array
398
+	 * @throws EE_Error
399
+	 */
400
+	public function imageFull($wpdb_row, $request, $controller)
401
+	{
402
+		return self::calculateImageData($wpdb_row, 'full');
403
+	}
404
+
405
+
406
+	/**
407
+	 * Gets image specs and formats them for the display in the API,
408
+	 * according to the image size requested
409
+	 *
410
+	 * @param array  $wpdb_row
411
+	 * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
412
+	 * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
413
+	 * @throws EE_Error
414
+	 */
415
+	protected function calculateImageData($wpdb_row, $image_size)
416
+	{
417
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
418
+			throw new EE_Error(
419
+				sprintf(
420
+					esc_html__(
421
+					// @codingStandardsIgnoreStart
422
+						'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
423
+						// @codingStandardsIgnoreEnd
424
+						'event_espresso'
425
+					),
426
+					print_r($wpdb_row, true)
427
+				)
428
+			);
429
+		}
430
+		$EVT_ID = $wpdb_row['Event_CPT.ID'];
431
+		$attachment_id = get_post_thumbnail_id($EVT_ID);
432
+		$data = wp_get_attachment_image_src($attachment_id, $image_size);
433
+		if (! $data) {
434
+			return null;
435
+		}
436
+		$generated = true;
437
+		if (isset($data[3])) {
438
+			$generated = $data[3];
439
+		}
440
+		return array(
441
+			'url'       => $data[0],
442
+			'width'     => $data[1],
443
+			'height'    => $data[2],
444
+			'generated' => $generated,
445
+		);
446
+	}
447
+
448
+
449
+	/**
450
+	 * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
451
+	 *
452
+	 * @param array $wpdb_row
453
+	 * @return bool
454
+	 */
455
+	protected function wpdbRowHasEventId($wpdb_row)
456
+	{
457
+		return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
458
+	}
459
+
460
+
461
+	/**
462
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
463
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
464
+	 *
465
+	 * @since 4.9.68.p
466
+	 * @return array
467
+	 */
468
+	public function schemaForCalculations()
469
+	{
470
+		$image_object_properties = array(
471
+			'url'       => array(
472
+				'type' => 'string',
473
+			),
474
+			'width'     => array(
475
+				'type' => 'number',
476
+			),
477
+			'height'    => array(
478
+				'type' => 'number',
479
+			),
480
+			'generated' => array(
481
+				'type' => 'boolean',
482
+			),
483
+		);
484
+		return array(
485
+			'optimum_sales_at_start'          => array(
486
+				'description' => esc_html__(
487
+					'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
488
+					'event_espresso'
489
+				),
490
+				'type'        => 'number',
491
+				'protected' => true,
492
+			),
493
+			'optimum_sales_now'               => array(
494
+				'description' => esc_html__(
495
+					'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
496
+					'event_espresso'
497
+				),
498
+				'type'        => 'number',
499
+				'protected' => true,
500
+			),
501
+			'spaces_remaining'                => array(
502
+				'description' => esc_html__(
503
+					'The optimum_sales_number result, minus total sales so far.',
504
+					'event_espresso'
505
+				),
506
+				'type'        => 'number',
507
+				'protected' => true,
508
+			),
509
+			'spots_taken'                     => array(
510
+				'description' => esc_html__(
511
+					'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
512
+					'event_espresso'
513
+				),
514
+				'type'        => 'number',
515
+				'protected' => true,
516
+			),
517
+			'spots_taken_pending_payment'     => array(
518
+				'description' => esc_html__(
519
+					'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
520
+					'event_espresso'
521
+				),
522
+				'type'        => 'number',
523
+				'protected' => true,
524
+			),
525
+			'registrations_checked_in_count'  => array(
526
+				'description' => esc_html__(
527
+					'The count of all the registrations who have checked into one of this event\'s datetimes.',
528
+					'event_espresso'
529
+				),
530
+				'type'        => 'number',
531
+				'protected' => true,
532
+			),
533
+			'registrations_checked_out_count' => array(
534
+				'description' => esc_html__(
535
+					'The count of all registrations who have checked out of one of this event\'s datetimes.',
536
+					'event_espresso'
537
+				),
538
+				'type'        => 'number',
539
+				'protected' => true,
540
+			),
541
+			'image_thumbnail'                 => array(
542
+				'description'          => esc_html__(
543
+					'The thumbnail image data.',
544
+					'event_espresso'
545
+				),
546
+				'type'                 => 'object',
547
+				'properties'           => $image_object_properties,
548
+				'additionalProperties' => false,
549
+			),
550
+			'image_medium'                    => array(
551
+				'description'          => esc_html__(
552
+					'The medium image data.',
553
+					'event_espresso'
554
+				),
555
+				'type'                 => 'object',
556
+				'properties'           => $image_object_properties,
557
+				'additionalProperties' => false,
558
+			),
559
+			'image_medium_large'              => array(
560
+				'description'          => esc_html__(
561
+					'The medium-large image data.',
562
+					'event_espresso'
563
+				),
564
+				'type'                 => 'object',
565
+				'properties'           => $image_object_properties,
566
+				'additionalProperties' => false,
567
+			),
568
+			'image_large'                     => array(
569
+				'description'          => esc_html__(
570
+					'The large image data.',
571
+					'event_espresso'
572
+				),
573
+				'type'                 => 'object',
574
+				'properties'           => $image_object_properties,
575
+				'additionalProperties' => false,
576
+			),
577
+			'image_post_thumbnail'            => array(
578
+				'description'          => esc_html__(
579
+					'The post-thumbnail image data.',
580
+					'event_espresso'
581
+				),
582
+				'type'                 => 'object',
583
+				'properties'           => $image_object_properties,
584
+				'additionalProperties' => false,
585
+			),
586
+			'image_full'                      => array(
587
+				'description'          => esc_html__(
588
+					'The full size image data',
589
+					'event_espresso'
590
+				),
591
+				'type'                 => 'object',
592
+				'properties'           => $image_object_properties,
593
+				'additionalProperties' => false,
594
+			),
595
+		);
596
+	}
597 597
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/rpc/Checkin.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -25,124 +25,124 @@
 block discarded – undo
25 25
  */
26 26
 class Checkin extends Base
27 27
 {
28
-    /**
29
-     * @param WP_REST_Request $request
30
-     * @param string          $version
31
-     * @return WP_Error|WP_REST_Response
32
-     */
33
-    public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
34
-    {
35
-        $controller = new Checkin();
36
-        return $controller->createCheckinCheckoutObject($request, $version);
37
-    }
28
+	/**
29
+	 * @param WP_REST_Request $request
30
+	 * @param string          $version
31
+	 * @return WP_Error|WP_REST_Response
32
+	 */
33
+	public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
34
+	{
35
+		$controller = new Checkin();
36
+		return $controller->createCheckinCheckoutObject($request, $version);
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * Toggles whether the user is checked in or not.
42
-     *
43
-     * @param WP_REST_Request $request
44
-     * @param string          $version
45
-     * @return WP_Error|WP_REST_Response
46
-     */
47
-    protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
48
-    {
49
-        $reg_id = $request->get_param('REG_ID');
50
-        $dtt_id = $request->get_param('DTT_ID');
51
-        $force = $request->get_param('force');
52
-        if ($force == 'true') {
53
-            $force = true;
54
-        } else {
55
-            $force = false;
56
-        }
57
-        $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
58
-        if (! $reg instanceof EE_Registration) {
59
-            return $this->sendResponse(
60
-                new WP_Error(
61
-                    'rest_registration_toggle_checkin_invalid_id',
62
-                    sprintf(
63
-                        esc_html__(
64
-                            'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
65
-                            'event_espresso'
66
-                        ),
67
-                        $reg_id
68
-                    ),
69
-                    array('status' => 422)
70
-                )
71
-            );
72
-        }
73
-        if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
74
-            return $this->sendResponse(
75
-                new WP_Error(
76
-                    'rest_user_cannot_toggle_checkin',
77
-                    sprintf(
78
-                        esc_html__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
79
-                        $reg_id
80
-                    ),
81
-                    array('status' => 403)
82
-                )
83
-            );
84
-        }
85
-        $success = $reg->toggle_checkin_status($dtt_id, ! $force);
86
-        if ($success === false) {
87
-            // check if we know they can't check in because they're not approved and we aren't forcing
88
-            if (! $reg->is_approved() && ! $force) {
89
-                // rely on EE_Error::add_error messages to have been added to give more data about why it failed
90
-                return $this->sendResponse(
91
-                    new WP_Error(
92
-                        'rest_toggle_checkin_failed',
93
-                        esc_html__(
94
-                        // @codingStandardsIgnoreStart
95
-                            'Registration check-in failed because the registration is not approved / awaiting review. You may attempt to force checking in though.',
96
-                            // @codingStandardsIgnoreEnd
97
-                            'event_espresso'
98
-                        )
99
-                    )
100
-                );
101
-            }
102
-            return $this->sendResponse(
103
-                new WP_Error(
104
-                    'rest_toggle_checkin_failed_not_forceable',
105
-                    esc_html__('Registration checkin failed. Please see additional error data.', 'event_espresso')
106
-                )
107
-            );
108
-        }
109
-        $checkin = EEM_Checkin::instance()->get_one(
110
-            array(
111
-                array(
112
-                    'REG_ID' => $reg_id,
113
-                    'DTT_ID' => $dtt_id,
114
-                ),
115
-                'order_by' => array(
116
-                    'CHK_timestamp' => 'DESC',
117
-                ),
118
-            )
119
-        );
120
-        if (! $checkin instanceof EE_Checkin) {
121
-            return $this->sendResponse(
122
-                new WP_Error(
123
-                    'rest_toggle_checkin_error',
124
-                    sprintf(
125
-                        esc_html__(
126
-                        // @codingStandardsIgnoreStart
127
-                            'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
128
-                            // @codingStandardsIgnoreEnd
129
-                            'event_espresso'
130
-                        ),
131
-                        $reg_id,
132
-                        $dtt_id
133
-                    )
134
-                )
135
-            );
136
-        }
137
-        $get_request = new WP_REST_Request(
138
-            'GET',
139
-            '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
140
-        );
141
-        $get_request->set_url_params(
142
-            array(
143
-                'id' => $checkin->ID(),
144
-            )
145
-        );
146
-        return Read::handleRequestGetOne($get_request, $version, 'Checkin');
147
-    }
40
+	/**
41
+	 * Toggles whether the user is checked in or not.
42
+	 *
43
+	 * @param WP_REST_Request $request
44
+	 * @param string          $version
45
+	 * @return WP_Error|WP_REST_Response
46
+	 */
47
+	protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
48
+	{
49
+		$reg_id = $request->get_param('REG_ID');
50
+		$dtt_id = $request->get_param('DTT_ID');
51
+		$force = $request->get_param('force');
52
+		if ($force == 'true') {
53
+			$force = true;
54
+		} else {
55
+			$force = false;
56
+		}
57
+		$reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
58
+		if (! $reg instanceof EE_Registration) {
59
+			return $this->sendResponse(
60
+				new WP_Error(
61
+					'rest_registration_toggle_checkin_invalid_id',
62
+					sprintf(
63
+						esc_html__(
64
+							'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
65
+							'event_espresso'
66
+						),
67
+						$reg_id
68
+					),
69
+					array('status' => 422)
70
+				)
71
+			);
72
+		}
73
+		if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
74
+			return $this->sendResponse(
75
+				new WP_Error(
76
+					'rest_user_cannot_toggle_checkin',
77
+					sprintf(
78
+						esc_html__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
79
+						$reg_id
80
+					),
81
+					array('status' => 403)
82
+				)
83
+			);
84
+		}
85
+		$success = $reg->toggle_checkin_status($dtt_id, ! $force);
86
+		if ($success === false) {
87
+			// check if we know they can't check in because they're not approved and we aren't forcing
88
+			if (! $reg->is_approved() && ! $force) {
89
+				// rely on EE_Error::add_error messages to have been added to give more data about why it failed
90
+				return $this->sendResponse(
91
+					new WP_Error(
92
+						'rest_toggle_checkin_failed',
93
+						esc_html__(
94
+						// @codingStandardsIgnoreStart
95
+							'Registration check-in failed because the registration is not approved / awaiting review. You may attempt to force checking in though.',
96
+							// @codingStandardsIgnoreEnd
97
+							'event_espresso'
98
+						)
99
+					)
100
+				);
101
+			}
102
+			return $this->sendResponse(
103
+				new WP_Error(
104
+					'rest_toggle_checkin_failed_not_forceable',
105
+					esc_html__('Registration checkin failed. Please see additional error data.', 'event_espresso')
106
+				)
107
+			);
108
+		}
109
+		$checkin = EEM_Checkin::instance()->get_one(
110
+			array(
111
+				array(
112
+					'REG_ID' => $reg_id,
113
+					'DTT_ID' => $dtt_id,
114
+				),
115
+				'order_by' => array(
116
+					'CHK_timestamp' => 'DESC',
117
+				),
118
+			)
119
+		);
120
+		if (! $checkin instanceof EE_Checkin) {
121
+			return $this->sendResponse(
122
+				new WP_Error(
123
+					'rest_toggle_checkin_error',
124
+					sprintf(
125
+						esc_html__(
126
+						// @codingStandardsIgnoreStart
127
+							'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
128
+							// @codingStandardsIgnoreEnd
129
+							'event_espresso'
130
+						),
131
+						$reg_id,
132
+						$dtt_id
133
+					)
134
+				)
135
+			);
136
+		}
137
+		$get_request = new WP_REST_Request(
138
+			'GET',
139
+			'/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
140
+		);
141
+		$get_request->set_url_params(
142
+			array(
143
+				'id' => $checkin->ID(),
144
+			)
145
+		);
146
+		return Read::handleRequestGetOne($get_request, $version, 'Checkin');
147
+	}
148 148
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model_Extensions.lib.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -14,150 +14,150 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Register_Model_Extensions implements EEI_Plugin_API
16 16
 {
17
-    protected static array $_registry = [];
17
+	protected static array $_registry = [];
18 18
 
19
-    protected static array $_extensions = [];
19
+	protected static array $_extensions = [];
20 20
 
21 21
 
22
-    /**
23
-     * register method for setting up model extensions
24
-     *
25
-     * @param string $addon_name            unique id for the extensions being setup
26
-     * @param array  $setup_args            {
27
-     * @return bool
28
-     * @throws EE_Error
29
-     * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
30
-     *                                      the models naming convention, which is:
31
-     *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
32
-     *                                      Where {your_plugin_slug} is really anything you want (but something having
33
-     *                                      to do with your addon, like 'Calendar' or '3D_View') and
34
-     *                                      model_name_extended} is the model extended.
35
-     *                                      The class contained in teh file should extend
36
-     *                                      EEME_Base_{model_name_extended}.model_ext.php.
37
-     *                                      Where {your_plugin_slug} is really anything you want (but something
38
-     *                                      having to do with your addon, like 'Calendar' or '3D_View') and
39
-     *                                      {model_name_extended} is the model extended. The class contained in teh
40
-     *                                      file should extend EEME_Base
41
-     * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
42
-     *                                      the model class extension naming convention, which is:
43
-     *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
44
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
45
-     *                                      and model_name_extended} is the name of the model extended, eg
46
-     *                                      'Attendee','Event',etc.
47
-     *                                      The class contained in the file should extend EEE_Base_Class
48
-     *                                      ._{model_name_extended}.class_ext.php.
49
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
50
-     *                                      and {model_name_extended} is the name of the model extended, eg
51
-     *                                      'Attendee','Event',etc. The class contained in the file should extend
52
-     *                                      EEE_Base_Class.
53
-     *                                      }
54
-     *
55
-     */
56
-    public static function register(string $addon_name = '', array $setup_args = []): bool
57
-    {
58
-        // required fields MUST be present, so let's make sure they are.
59
-        if (
60
-            empty($addon_name)
61
-            || ! is_array($setup_args)
62
-            || (
63
-                empty($setup_args['model_extension_paths'])
64
-                && empty($setup_args['class_extension_paths'])
65
-            )
66
-        ) {
67
-            throw new EE_Error(
68
-                esc_html__(
69
-                    'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
70
-                    'event_espresso'
71
-                )
72
-            );
73
-        }
22
+	/**
23
+	 * register method for setting up model extensions
24
+	 *
25
+	 * @param string $addon_name            unique id for the extensions being setup
26
+	 * @param array  $setup_args            {
27
+	 * @return bool
28
+	 * @throws EE_Error
29
+	 * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
30
+	 *                                      the models naming convention, which is:
31
+	 *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
32
+	 *                                      Where {your_plugin_slug} is really anything you want (but something having
33
+	 *                                      to do with your addon, like 'Calendar' or '3D_View') and
34
+	 *                                      model_name_extended} is the model extended.
35
+	 *                                      The class contained in teh file should extend
36
+	 *                                      EEME_Base_{model_name_extended}.model_ext.php.
37
+	 *                                      Where {your_plugin_slug} is really anything you want (but something
38
+	 *                                      having to do with your addon, like 'Calendar' or '3D_View') and
39
+	 *                                      {model_name_extended} is the model extended. The class contained in teh
40
+	 *                                      file should extend EEME_Base
41
+	 * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
42
+	 *                                      the model class extension naming convention, which is:
43
+	 *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
44
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
45
+	 *                                      and model_name_extended} is the name of the model extended, eg
46
+	 *                                      'Attendee','Event',etc.
47
+	 *                                      The class contained in the file should extend EEE_Base_Class
48
+	 *                                      ._{model_name_extended}.class_ext.php.
49
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
50
+	 *                                      and {model_name_extended} is the name of the model extended, eg
51
+	 *                                      'Attendee','Event',etc. The class contained in the file should extend
52
+	 *                                      EEE_Base_Class.
53
+	 *                                      }
54
+	 *
55
+	 */
56
+	public static function register(string $addon_name = '', array $setup_args = []): bool
57
+	{
58
+		// required fields MUST be present, so let's make sure they are.
59
+		if (
60
+			empty($addon_name)
61
+			|| ! is_array($setup_args)
62
+			|| (
63
+				empty($setup_args['model_extension_paths'])
64
+				&& empty($setup_args['class_extension_paths'])
65
+			)
66
+		) {
67
+			throw new EE_Error(
68
+				esc_html__(
69
+					'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
70
+					'event_espresso'
71
+				)
72
+			);
73
+		}
74 74
 
75
-        // make sure we don't register twice
76
-        if (isset(self::$_registry[ $addon_name ])) {
77
-            return true;
78
-        }
79
-        /** @var Request $request */
80
-        $request = LoaderFactory::getShared(Request::class);
81
-        if ($request->isActivation()) {
82
-            return false;
83
-        }
75
+		// make sure we don't register twice
76
+		if (isset(self::$_registry[ $addon_name ])) {
77
+			return true;
78
+		}
79
+		/** @var Request $request */
80
+		$request = LoaderFactory::getShared(Request::class);
81
+		if ($request->isActivation()) {
82
+			return false;
83
+		}
84 84
 
85
-        // check correct loading
86
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
87
-            EE_Error::doing_it_wrong(
88
-                __METHOD__,
89
-                sprintf(
90
-                    esc_html__(
91
-                        'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
92
-                        'event_espresso'
93
-                    ),
94
-                    $addon_name,
95
-                    '<br />',
96
-                    did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
97
-                    did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
98
-                ),
99
-                '4.3'
100
-            );
101
-            return false;
102
-        }
85
+		// check correct loading
86
+		if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
87
+			EE_Error::doing_it_wrong(
88
+				__METHOD__,
89
+				sprintf(
90
+					esc_html__(
91
+						'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
92
+						'event_espresso'
93
+					),
94
+					$addon_name,
95
+					'<br />',
96
+					did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
97
+					did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
98
+				),
99
+				'4.3'
100
+			);
101
+			return false;
102
+		}
103 103
 
104
-        self::$_registry[ $addon_name ]   = $setup_args;
105
-        self::$_extensions[ $addon_name ] = [];
104
+		self::$_registry[ $addon_name ]   = $setup_args;
105
+		self::$_extensions[ $addon_name ] = [];
106 106
 
107
-        if (isset($setup_args['model_extension_paths'])) {
108
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
109
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
110
-            // remove all files that are not PHP
111
-            foreach ($class_to_filepath_map as $class => $path) {
112
-                if (substr($path, strlen($path) - 3) !== 'php') {
113
-                    unset($class_to_filepath_map[ $class ]);
114
-                }
115
-            }
116
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
117
-            foreach (array_keys($class_to_filepath_map) as $classname) {
118
-                self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname();
119
-            }
120
-            unset($setup_args['model_extension_paths']);
121
-        }
122
-        if (isset($setup_args['class_extension_paths'])) {
123
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
124
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
125
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
126
-            foreach (array_keys($class_to_filepath_map) as $classname) {
127
-                self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname();
128
-            }
129
-            unset($setup_args['class_extension_paths']);
130
-        }
131
-        foreach ($setup_args as $unknown_key => $unknown_config) {
132
-            throw new EE_Error(
133
-                sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
-            );
135
-        }
136
-        return true;
137
-    }
107
+		if (isset($setup_args['model_extension_paths'])) {
108
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
109
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
110
+			// remove all files that are not PHP
111
+			foreach ($class_to_filepath_map as $class => $path) {
112
+				if (substr($path, strlen($path) - 3) !== 'php') {
113
+					unset($class_to_filepath_map[ $class ]);
114
+				}
115
+			}
116
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
117
+			foreach (array_keys($class_to_filepath_map) as $classname) {
118
+				self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname();
119
+			}
120
+			unset($setup_args['model_extension_paths']);
121
+		}
122
+		if (isset($setup_args['class_extension_paths'])) {
123
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
124
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
125
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
126
+			foreach (array_keys($class_to_filepath_map) as $classname) {
127
+				self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname();
128
+			}
129
+			unset($setup_args['class_extension_paths']);
130
+		}
131
+		foreach ($setup_args as $unknown_key => $unknown_config) {
132
+			throw new EE_Error(
133
+				sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
+			);
135
+		}
136
+		return true;
137
+	}
138 138
 
139 139
 
140
-    /**
141
-     * deregister
142
-     *
143
-     * @param string $addon_name
144
-     */
145
-    public static function deregister(string $addon_name = '')
146
-    {
147
-        if (isset(self::$_registry[ $addon_name ])) {
148
-            unset(self::$_registry[ $addon_name ]);
149
-            foreach (self::$_extensions[ $addon_name ] as $extension_of_type) {
150
-                foreach ($extension_of_type as $extension) {
151
-                    $extension->deregister();
152
-                }
153
-            }
154
-        }
155
-    }
140
+	/**
141
+	 * deregister
142
+	 *
143
+	 * @param string $addon_name
144
+	 */
145
+	public static function deregister(string $addon_name = '')
146
+	{
147
+		if (isset(self::$_registry[ $addon_name ])) {
148
+			unset(self::$_registry[ $addon_name ]);
149
+			foreach (self::$_extensions[ $addon_name ] as $extension_of_type) {
150
+				foreach ($extension_of_type as $extension) {
151
+					$extension->deregister();
152
+				}
153
+			}
154
+		}
155
+	}
156 156
 
157 157
 
158
-    public static function reset(): void
159
-    {
160
-        self::$_registry = [];
161
-        self::$_extensions = [];
162
-    }
158
+	public static function reset(): void
159
+	{
160
+		self::$_registry = [];
161
+		self::$_extensions = [];
162
+	}
163 163
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         }
74 74
 
75 75
         // make sure we don't register twice
76
-        if (isset(self::$_registry[ $addon_name ])) {
76
+        if (isset(self::$_registry[$addon_name])) {
77 77
             return true;
78 78
         }
79 79
         /** @var Request $request */
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         }
84 84
 
85 85
         // check correct loading
86
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
86
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
87 87
             EE_Error::doing_it_wrong(
88 88
                 __METHOD__,
89 89
                 sprintf(
@@ -101,30 +101,30 @@  discard block
 block discarded – undo
101 101
             return false;
102 102
         }
103 103
 
104
-        self::$_registry[ $addon_name ]   = $setup_args;
105
-        self::$_extensions[ $addon_name ] = [];
104
+        self::$_registry[$addon_name]   = $setup_args;
105
+        self::$_extensions[$addon_name] = [];
106 106
 
107 107
         if (isset($setup_args['model_extension_paths'])) {
108
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
108
+            require_once(EE_LIBRARIES.'plugin_api/db/EEME_Base.lib.php');
109 109
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
110 110
             // remove all files that are not PHP
111 111
             foreach ($class_to_filepath_map as $class => $path) {
112 112
                 if (substr($path, strlen($path) - 3) !== 'php') {
113
-                    unset($class_to_filepath_map[ $class ]);
113
+                    unset($class_to_filepath_map[$class]);
114 114
                 }
115 115
             }
116 116
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
117 117
             foreach (array_keys($class_to_filepath_map) as $classname) {
118
-                self::$_extensions[ $addon_name ]['models'][ $classname ] = new $classname();
118
+                self::$_extensions[$addon_name]['models'][$classname] = new $classname();
119 119
             }
120 120
             unset($setup_args['model_extension_paths']);
121 121
         }
122 122
         if (isset($setup_args['class_extension_paths'])) {
123
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
123
+            require_once(EE_LIBRARIES.'plugin_api/db/EEE_Base_Class.lib.php');
124 124
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
125 125
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
126 126
             foreach (array_keys($class_to_filepath_map) as $classname) {
127
-                self::$_extensions[ $addon_name ]['classes'][ $classname ] = new $classname();
127
+                self::$_extensions[$addon_name]['classes'][$classname] = new $classname();
128 128
             }
129 129
             unset($setup_args['class_extension_paths']);
130 130
         }
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
      */
145 145
     public static function deregister(string $addon_name = '')
146 146
     {
147
-        if (isset(self::$_registry[ $addon_name ])) {
148
-            unset(self::$_registry[ $addon_name ]);
149
-            foreach (self::$_extensions[ $addon_name ] as $extension_of_type) {
147
+        if (isset(self::$_registry[$addon_name])) {
148
+            unset(self::$_registry[$addon_name]);
149
+            foreach (self::$_extensions[$addon_name] as $extension_of_type) {
150 150
                 foreach ($extension_of_type as $extension) {
151 151
                     $extension->deregister();
152 152
                 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1255 added lines, -1255 removed lines patch added patch discarded remove patch
@@ -24,1259 +24,1259 @@
 block discarded – undo
24 24
  */
25 25
 class EE_Register_Addon implements EEI_Plugin_API
26 26
 {
27
-    /**
28
-     * possibly truncated version of the EE core version string
29
-     *
30
-     * @var string
31
-     */
32
-    protected static $_core_version = '';
33
-
34
-    /**
35
-     * Holds values for registered addons
36
-     *
37
-     * @var array
38
-     */
39
-    protected static $_settings = [];
40
-
41
-    /**
42
-     * @var  array $_incompatible_addons keys are addon SLUGS
43
-     *                                   (first argument passed to EE_Register_Addon::register()), keys are
44
-     *                                   their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
-     *                                   Generally this should be used sparingly, as we don't want to muddle up
46
-     *                                   EE core with knowledge of ALL the addons out there.
47
-     *                                   If you want NO versions of an addon to run with a certain version of core,
48
-     *                                   it's usually best to define the addon's "min_core_version" as part of its call
49
-     *                                   to EE_Register_Addon::register(), rather than using this array with a super
50
-     *                                   high value for its minimum plugin version.
51
-     */
52
-    protected static $_incompatible_addons = [
53
-        'Multi_Event_Registration' => '2.0.11.rc.002',
54
-        'Promotions'               => '1.0.0.rc.084',
55
-    ];
56
-
57
-    /**
58
-     * @var LoaderInterface
59
-     */
60
-    protected static $loader;
61
-
62
-
63
-    /**
64
-     * We should always be comparing core to a version like '4.3.0.rc.000',
65
-     * not just '4.3.0'.
66
-     * So if the addon developer doesn't provide that full version string,
67
-     * fill in the blanks for them
68
-     *
69
-     * @param string $min_core_version
70
-     * @return string always like '4.3.0.rc.000'
71
-     */
72
-    protected static function _effective_version(string $min_core_version): string
73
-    {
74
-        // versions: 4 . 3 . 1 . p . 123
75
-        // offsets:    0 . 1 . 2 . 3 . 4
76
-        $version_parts = explode('.', $min_core_version);
77
-        // check they specified the micro version (after 2nd period)
78
-        if (! isset($version_parts[2])) {
79
-            $version_parts[2] = '0';
80
-        }
81
-        // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
82
-        // soon we can assume that's 'rc', but this current version is 'alpha'
83
-        if (! isset($version_parts[3])) {
84
-            $version_parts[3] = 'dev';
85
-        }
86
-        if (! isset($version_parts[4])) {
87
-            $version_parts[4] = '000';
88
-        }
89
-        return implode('.', $version_parts);
90
-    }
91
-
92
-
93
-    /**
94
-     * Returns whether or not the min core version requirement of the addon is met
95
-     *
96
-     * @param string $min_core_version    the minimum core version required by the addon
97
-     * @param string $actual_core_version the actual core version, optional
98
-     * @return bool
99
-     */
100
-    public static function _meets_min_core_version_requirement(
101
-        string $min_core_version,
102
-        string $actual_core_version = EVENT_ESPRESSO_VERSION
103
-    ): bool {
104
-        return version_compare(
105
-            self::_effective_version($actual_core_version),
106
-            self::_effective_version($min_core_version),
107
-            '>='
108
-        );
109
-    }
110
-
111
-
112
-    /**
113
-     * Method for registering new EE_Addons.
114
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
115
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
116
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
117
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
118
-     * 'activate_plugin', it registers the addon still, but its components are not registered
119
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
120
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
121
-     * (so that we can detect that the addon has activated on the subsequent request)
122
-     *
123
-     * @param string                  $addon_name                       [Required] the EE_Addon's name.
124
-     * @param array                   $setup_args                       {
125
-     *                                                                  An array of arguments provided for registering
126
-     *                                                                  the message type.
127
-     * @type  string                  $class_name                       the addon's main file name.
128
-     *                                                                  If left blank, generated from the addon name,
129
-     *                                                                  changes something like "calendar" to
130
-     *                                                                  "EE_Calendar"
131
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
132
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
133
-     * @type string                   $version                          the "software" version for the addon. eg
134
-     *                                                                  "1.0.0.p" for a first stable release, or
135
-     *                                                                  "1.0.0.rc.043" for a version in progress
136
-     * @type string                   $main_file_path                   the full server path to the main file
137
-     *                                                                  loaded directly by WP
138
-     * @type DomainInterface          $domain                           child class of
139
-     *                                                                  EventEspresso\core\domain\DomainBase
140
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
141
-     *                                                                  for the addon's Domain class
142
-     *                                                                  (see EventEspresso\core\domain\Domain)
143
-     * @type string                   $admin_path                       full server path to the folder where the
144
-     *                                                                  addon\'s admin files reside
145
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
146
-     *                                                                  first invoked, can be used for hooking into
147
-     *                                                                  any admin page
148
-     * @type string                   $config_section                   the section name for this addon's
149
-     *                                                                  configuration settings section
150
-     *                                                                  (defaults to "addons")
151
-     * @type string                   $config_class                     the class name for this addon's
152
-     *                                                                  configuration settings object
153
-     * @type string                   $config_name                      the class name for this addon's
154
-     *                                                                  configuration settings object
155
-     * @type string                   $autoloader_paths                 [Required] an array of class names and the full
156
-     *                                                                  server paths to those files.
157
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
158
-     *                                                                  folders containing classes that might be
159
-     *                                                                  invoked by the addon
160
-     * @type string                   $dms_paths                        [Required] an array of full server paths to
161
-     *                                                                  folders that contain data migration scripts.
162
-     *                                                                  The key should be the EE_Addon class name that
163
-     *                                                                  this set of data migration scripts belongs to.
164
-     *                                                                  If the EE_Addon class is namespaced, then this
165
-     *                                                                  needs to be the Fully Qualified Class Name
166
-     * @type string                   $module_paths                     an array of full server paths to any
167
-     *                                                                  EED_Modules used by the addon
168
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
169
-     *                                                                  that contain EES_Shortcodes
170
-     * @type string                   $widget_paths                     an array of full server paths to folders
171
-     *                                                                  that contain WP_Widgets
172
-     * @type array                    $capabilities                     an array indexed by role name
173
-     *                                                                  (i.e administrator,author ) and the values
174
-     *                                                                  are an array of caps to add to the role.
175
-     *                                                                  'administrator' => array(
176
-     *                                                                  'read_addon',
177
-     *                                                                  'edit_addon',
178
-     *                                                                  etc.
179
-     *                                                                  ).
180
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
181
-     *                                                                  for any addons that need to register any
182
-     *                                                                  special meta mapped capabilities.  Should
183
-     *                                                                  be indexed where the key is the
184
-     *                                                                  EE_Meta_Capability_Map class name and the
185
-     *                                                                  values are the arguments sent to the class.
186
-     * @type array                    $model_paths                      array of folders containing DB models
187
-     * @return bool
188
-     * @throws DomainException
189
-     * @throws EE_Error
190
-     * @throws InvalidArgumentException
191
-     * @throws InvalidDataTypeException
192
-     * @throws InvalidInterfaceException
193
-     * @since                                                           4.3.0
194
-     * @see                                                             EE_Register_Model
195
-     * @type array                    $class_paths                      array of folders containing DB classes
196
-     * @see                                                             EE_Register_Model
197
-     * @type array                    $model_extension_paths            array of folders containing DB model
198
-     *                                                                  extensions
199
-     * @see                                                             EE_Register_Model_Extension
200
-     * @type array                    $class_extension_paths            array of folders containing DB class
201
-     *                                                                  extensions
202
-     * @see                                                             EE_Register_Model_Extension
203
-     * @type array message_types {
204
-     *                                                                  An array of message types with the key as
205
-     *                                                                  the message type name and the values as
206
-     *                                                                  below:
207
-     * @type string                   $mtfilename                       [Required] The filename of the message type
208
-     *                                                                  being registered. This will be the main
209
-     *                                                                  EE_{Message Type Name}_message_type class.
210
-     *                                                                  for example:
211
-     *                                                                  EE_Declined_Registration_message_type.class.php
212
-     * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
213
-     *                                                                  messages autoloader for the new message type.
214
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
215
-     *                                                                  type should activate with. Each value in
216
-     *                                                                  the
217
-     *                                                                  array
218
-     *                                                                  should match the name property of a
219
-     *                                                                  EE_messenger. Optional.
220
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
221
-     *                                                                  type should validate with. Each value in
222
-     *                                                                  the
223
-     *                                                                  array
224
-     *                                                                  should match the name property of an
225
-     *                                                                  EE_messenger.
226
-     *                                                                  Optional.
227
-     *                                                                  }
228
-     * @type array                    $custom_post_types
229
-     * @type array                    $custom_taxonomies
230
-     * @type array                    $payment_method_paths             each element is the folder containing the
231
-     *                                                                  EE_PMT_Base child class
232
-     *                                                                  (eg,
233
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
234
-     *                                                                  which contains the files
235
-     *                                                                  EE_PMT_Payomatic.pm.php)
236
-     * @type array                    $default_terms
237
-     * @type array                    $namespace                        {
238
-     *                                                                  An array with two items for registering the
239
-     *                                                                  addon's namespace. (If, for some reason, you
240
-     *                                                                  require additional namespaces,
241
-     *                                                                  use
242
-     *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
243
-     *                                                                  directly)
244
-     * @see                                                             EventEspresso\core\Psr4Autoloader::addNamespace()
245
-     * @type string                   $FQNS                             the namespace prefix
246
-     * @type string                   $DIR                              a base directory for class files in the
247
-     *                                                                  namespace.
248
-     *                                                                  }
249
-     *                                                                  }
250
-     * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
251
-     *                                                                  privacy policy classes) or FQCNs (specific
252
-     *                                                                  classnames of privacy policy classes)
253
-     * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
254
-     *                                                                  privacy policy classes) or FQCNs (specific
255
-     *                                                                  classnames of privacy policy classes)
256
-     * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
257
-     *                                                                  privacy policy classes) or FQCNs (specific
258
-     *                                                                  classnames of privacy policy classes)
259
-     */
260
-    public static function register(string $addon_name = '', array $setup_args = []): bool
261
-    {
262
-        // $addon_name = basename($addon_name);
263
-        if (! self::$loader instanceof LoaderInterface) {
264
-            self::$loader = LoaderFactory::getLoader();
265
-        }
266
-        // make sure this was called in the right place!
267
-        if (
268
-            ! did_action('activate_plugin')
269
-            && (
270
-                ! did_action('AHEE__EE_System__load_espresso_addons')
271
-                || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
272
-            )
273
-        ) {
274
-            EE_Error::doing_it_wrong(
275
-                __METHOD__,
276
-                sprintf(
277
-                    esc_html__(
278
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
279
-                        'event_espresso'
280
-                    ),
281
-                    $addon_name
282
-                ),
283
-                '4.3.0'
284
-            );
285
-            return false;
286
-        }
287
-        // required fields MUST be present, so let's make sure they are.
288
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
289
-        // get class name for addon
290
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
291
-        // setup $_settings array from incoming values.
292
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
293
-        // allow early addon setup or modification of addon api settings
294
-        self::$_settings = (array) apply_filters(
295
-            'FHEE__EE_Register_Addon__register',
296
-            self::$_settings,
297
-            $addon_name,
298
-            $class_name,
299
-            $setup_args
300
-        );
301
-        // does this addon work with this version of core or WordPress ?
302
-        // does this addon work with this version of core or WordPress ?
303
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
304
-            return false;
305
-        }
306
-        // register namespaces
307
-        EE_Register_Addon::_setup_namespaces($addon_settings);
308
-        // check if this is an activation request
309
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
310
-            // dont bother setting up the rest of the addon atm
311
-            return false;
312
-        }
313
-        // we need cars
314
-        EE_Register_Addon::_setup_autoloaders($addon_name);
315
-        // register new models and extensions
316
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
317
-        // setup DMS
318
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
319
-        // if config_class is present let's register config.
320
-        EE_Register_Addon::_register_config($addon_name);
321
-        // register admin pages
322
-        EE_Register_Addon::_register_admin_pages($addon_name);
323
-        // add to list of modules to be registered
324
-        EE_Register_Addon::_register_modules($addon_name);
325
-        // add to list of shortcodes to be registered
326
-        EE_Register_Addon::_register_shortcodes($addon_name);
327
-        // add to list of widgets to be registered
328
-        EE_Register_Addon::_register_widgets($addon_name);
329
-        // register capability related stuff.
330
-        EE_Register_Addon::_register_capabilities($addon_name);
331
-        // any message type to register?
332
-        EE_Register_Addon::_register_message_types($addon_name);
333
-        // any custom post type/ custom capabilities or default terms to register
334
-        EE_Register_Addon::_register_custom_post_types($addon_name);
335
-        // and any payment methods
336
-        EE_Register_Addon::_register_payment_methods($addon_name);
337
-        // and privacy policy generators
338
-        EE_Register_Addon::registerPrivacyPolicies($addon_name);
339
-        // and privacy policy generators
340
-        EE_Register_Addon::registerPersonalDataExporters($addon_name);
341
-        // and privacy policy generators
342
-        EE_Register_Addon::registerPersonalDataErasers($addon_name);
343
-        EE_Register_Addon::registerLicense($addon_name);
344
-        // load and instantiate main addon class
345
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
346
-        // delay calling after_registration hook on each addon until after all add-ons have been registered.
347
-        add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999);
348
-        return $addon instanceof EE_Addon;
349
-    }
350
-
351
-
352
-    /**
353
-     * @param string $addon_name
354
-     * @param array  $setup_args
355
-     * @return void
356
-     * @throws EE_Error
357
-     */
358
-    private static function _verify_parameters(string $addon_name, array $setup_args)
359
-    {
360
-        // required fields MUST be present, so let's make sure they are.
361
-        if (empty($addon_name) || empty($setup_args)) {
362
-            throw new EE_Error(
363
-                esc_html__(
364
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
365
-                    'event_espresso'
366
-                )
367
-            );
368
-        }
369
-        if (empty($setup_args['main_file_path'])) {
370
-            throw new EE_Error(
371
-                sprintf(
372
-                    esc_html__(
373
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
374
-                        'event_espresso'
375
-                    ),
376
-                    implode(',', array_keys($setup_args))
377
-                )
378
-            );
379
-        }
380
-        // check that addon has not already been registered with that name
381
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
382
-            throw new EE_Error(
383
-                sprintf(
384
-                    esc_html__(
385
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
386
-                        'event_espresso'
387
-                    ),
388
-                    $addon_name
389
-                )
390
-            );
391
-        }
392
-    }
393
-
394
-
395
-    /**
396
-     * @param string $addon_name
397
-     * @param array  $setup_args
398
-     * @return string
399
-     */
400
-    private static function _parse_class_name(string $addon_name, array $setup_args): string
401
-    {
402
-        if (empty($setup_args['class_name'])) {
403
-            // generate one by first separating name with spaces
404
-            $class_name = str_replace(['-', '_'], ' ', trim($addon_name));
405
-            // capitalize, then replace spaces with underscores
406
-            $class_name = str_replace(' ', '_', ucwords($class_name));
407
-        } else {
408
-            $class_name = $setup_args['class_name'];
409
-        }
410
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
411
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
412
-            ? $class_name
413
-            : 'EE_' . $class_name;
414
-    }
415
-
416
-
417
-    /**
418
-     * @param string $class_name
419
-     * @param array  $setup_args
420
-     * @return array
421
-     */
422
-    private static function _get_addon_settings(string $class_name, array $setup_args): array
423
-    {
424
-        // setup $_settings array from incoming values.
425
-        $addon_settings = [
426
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
427
-            'class_name'            => $class_name,
428
-            // the addon slug for use in URLs, etc
429
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
430
-                ? (string) $setup_args['plugin_slug']
431
-                : sanitize_key($class_name),
432
-            // page slug to be used when generating the "Settings" link on the WP plugin page
433
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
434
-                ? (string) $setup_args['plugin_action_slug']
435
-                : '',
436
-            // the "software" version for the addon
437
-            'version'               => isset($setup_args['version'])
438
-                ? (string) $setup_args['version']
439
-                : '',
440
-            // the minimum version of EE Core that the addon will work with
441
-            'min_core_version'      => isset($setup_args['min_core_version'])
442
-                ? (string) $setup_args['min_core_version']
443
-                : '',
444
-            // the minimum version of WordPress that the addon will work with
445
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
446
-                ? (string) $setup_args['min_wp_version']
447
-                : EE_MIN_WP_VER_REQUIRED,
448
-            // full server path to main file (file loaded directly by WP)
449
-            'main_file_path'        => isset($setup_args['main_file_path'])
450
-                ? (string) $setup_args['main_file_path']
451
-                : '',
452
-            // instance of \EventEspresso\core\domain\DomainInterface
453
-            'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
454
-                ? $setup_args['domain']
455
-                : null,
456
-            // Fully Qualified Class Name for the addon's Domain class
457
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
458
-                ? (string) $setup_args['domain_fqcn']
459
-                : '',
460
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
461
-            'admin_path'            => isset($setup_args['admin_path'])
462
-                ? (string) $setup_args['admin_path']
463
-                : '',
464
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
465
-            'admin_callback'        => isset($setup_args['admin_callback'])
466
-                ? (string) $setup_args['admin_callback']
467
-                : '',
468
-            // the section name for this addon's configuration settings section (defaults to "addons")
469
-            'config_section'        => isset($setup_args['config_section'])
470
-                ? (string) $setup_args['config_section']
471
-                : 'addons',
472
-            // the class name for this addon's configuration settings object
473
-            'config_class'          => isset($setup_args['config_class'])
474
-                ? (string) $setup_args['config_class']
475
-                : '',
476
-            // the name given to the config for this addons' configuration settings object (optional)
477
-            'config_name'           => isset($setup_args['config_name'])
478
-                ? (string) $setup_args['config_name']
479
-                : '',
480
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
481
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
482
-                ? (array) $setup_args['autoloader_paths']
483
-                : [],
484
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
485
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
486
-                ? (array) $setup_args['autoloader_folders']
487
-                : [],
488
-            // array of full server paths to any EE_DMS data migration scripts used by the addon.
489
-            // The key should be the EE_Addon class name that this set of data migration scripts belongs to.
490
-            // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
491
-            'dms_paths'             => isset($setup_args['dms_paths'])
492
-                ? (array) $setup_args['dms_paths']
493
-                : [],
494
-            // array of full server paths to any EED_Modules used by the addon
495
-            'module_paths'          => isset($setup_args['module_paths'])
496
-                ? (array) $setup_args['module_paths']
497
-                : [],
498
-            // array of full server paths to any EES_Shortcodes used by the addon
499
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
500
-                ? (array) $setup_args['shortcode_paths']
501
-                : [],
502
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
503
-                ? (array) $setup_args['shortcode_fqcns']
504
-                : [],
505
-            // array of full server paths to any WP_Widgets used by the addon
506
-            'widget_paths'          => isset($setup_args['widget_paths'])
507
-                ? (array) $setup_args['widget_paths']
508
-                : [],
509
-            'message_types'         => isset($setup_args['message_types'])
510
-                ? (array) $setup_args['message_types']
511
-                : [],
512
-            'capabilities'          => isset($setup_args['capabilities'])
513
-                ? (array) $setup_args['capabilities']
514
-                : [],
515
-            'capability_maps'       => isset($setup_args['capability_maps'])
516
-                ? (array) $setup_args['capability_maps']
517
-                : [],
518
-            'model_paths'           => isset($setup_args['model_paths'])
519
-                ? (array) $setup_args['model_paths']
520
-                : [],
521
-            'class_paths'           => isset($setup_args['class_paths'])
522
-                ? (array) $setup_args['class_paths']
523
-                : [],
524
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
525
-                ? (array) $setup_args['model_extension_paths']
526
-                : [],
527
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
528
-                ? (array) $setup_args['class_extension_paths']
529
-                : [],
530
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
531
-                ? (array) $setup_args['custom_post_types']
532
-                : [],
533
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
534
-                ? (array) $setup_args['custom_taxonomies']
535
-                : [],
536
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
537
-                ? (array) $setup_args['payment_method_paths']
538
-                : [],
539
-            'default_terms'         => isset($setup_args['default_terms'])
540
-                ? (array) $setup_args['default_terms']
541
-                : [],
542
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
543
-            // that can be used for adding upgrading/marketing info
544
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
545
-                ? (array) $setup_args['plugins_page_row']
546
-                : [],
547
-            'namespace'             => isset(
548
-                $setup_args['namespace']['FQNS'],
549
-                $setup_args['namespace']['DIR']
550
-            )
551
-                ? (array) $setup_args['namespace']
552
-                : [],
553
-            'privacy_policies'      => isset($setup_args['privacy_policies'])
554
-                ? (array) $setup_args['privacy_policies']
555
-                : [],
556
-            'license'               => isset($setup_args['license'])
557
-                ? (array) $setup_args['license']
558
-                : [],
559
-        ];
560
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
561
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
562
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
563
-                                                && ! empty($addon_settings['admin_path'])
564
-            ? $addon_settings['plugin_slug']
565
-            : $addon_settings['plugin_action_slug'];
566
-        // full server path to main file (file loaded directly by WP)
567
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
568
-        return $addon_settings;
569
-    }
570
-
571
-
572
-    /**
573
-     * @param string $addon_name
574
-     * @param array  $addon_settings
575
-     * @return bool
576
-     */
577
-    private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool
578
-    {
579
-        global $wp_version;
580
-        $incompatibility_message = '';
581
-        // check whether this addon version is compatible with EE core
582
-        if (
583
-            isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
584
-            && ! self::_meets_min_core_version_requirement(
585
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
586
-                $addon_settings['version']
587
-            )
588
-        ) {
589
-            $incompatibility_message = sprintf(
590
-                esc_html__(
591
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
592
-                    'event_espresso'
593
-                ),
594
-                $addon_name,
595
-                '<br />',
596
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
597
-                '<span style="font-weight: bold; color: #D54E21;">',
598
-                '</span><br />'
599
-            );
600
-        } elseif (
601
-            ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
602
-        ) {
603
-            $incompatibility_message = sprintf(
604
-                esc_html__(
605
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
606
-                    'event_espresso'
607
-                ),
608
-                $addon_name,
609
-                self::_effective_version($addon_settings['min_core_version']),
610
-                self::_effective_version(espresso_version()),
611
-                '<br />',
612
-                '<span style="font-weight: bold; color: #D54E21;">',
613
-                '</span><br />'
614
-            );
615
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
616
-            $incompatibility_message = sprintf(
617
-                esc_html__(
618
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
619
-                    'event_espresso'
620
-                ),
621
-                $addon_name,
622
-                $addon_settings['min_wp_version'],
623
-                '<br />',
624
-                '<span style="font-weight: bold; color: #D54E21;">',
625
-                '</span><br />'
626
-            );
627
-        }
628
-        if (! empty($incompatibility_message)) {
629
-            // remove 'activate' from the REQUEST
630
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
631
-            /** @var RequestInterface $request */
632
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
633
-            $request->unSetRequestParam('activate', true);
634
-            if (current_user_can('activate_plugins')) {
635
-                // show an error message indicating the plugin didn't activate properly
636
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
637
-            }
638
-            unset($_GET['activate'], $_REQUEST['activate']);
639
-            if (! function_exists('deactivate_plugins')) {
640
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
641
-            }
642
-            deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
643
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
644
-            return false;
645
-        }
646
-        // addon IS compatible
647
-        return true;
648
-    }
649
-
650
-
651
-    /**
652
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
653
-     *
654
-     * @param array $addon_settings
655
-     * @return void
656
-     * @throws EE_Error
657
-     */
658
-    private static function _setup_namespaces(array $addon_settings)
659
-    {
660
-        //
661
-        if (
662
-            isset(
663
-                $addon_settings['namespace']['FQNS'],
664
-                $addon_settings['namespace']['DIR']
665
-            )
666
-        ) {
667
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
668
-                $addon_settings['namespace']['FQNS'],
669
-                $addon_settings['namespace']['DIR']
670
-            );
671
-        }
672
-    }
673
-
674
-
675
-    /**
676
-     * @param string $addon_name
677
-     * @param array  $addon_settings
678
-     * @return bool
679
-     * @throws InvalidArgumentException
680
-     * @throws InvalidDataTypeException
681
-     * @throws InvalidInterfaceException
682
-     */
683
-    private static function _addon_activation(string $addon_name, array $addon_settings): bool
684
-    {
685
-        // this is an activation request
686
-        if (did_action('activate_plugin')) {
687
-            // to find if THIS is the addon that was activated, just check if we have already registered it or not
688
-            // (as the newly-activated addon wasn't around the first time addons were registered).
689
-            if (
690
-                ! isset(self::$_settings[ $addon_name ])
691
-                || (isset(self::$_settings[ $addon_name ])
692
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
693
-                )
694
-            ) {
695
-                self::$_settings[ $addon_name ] = $addon_settings;
696
-                $addon                          = self::_load_and_init_addon_class($addon_name);
697
-                $addon->set_activation_indicator_option();
698
-                // dont bother setting up the rest of the addon.
699
-                // we know it was just activated and the request will end soon
700
-            }
701
-            return true;
702
-        }
703
-        // make sure addon settings are set correctly without overwriting anything existing
704
-        if (isset(self::$_settings[ $addon_name ])) {
705
-            self::$_settings[ $addon_name ] += $addon_settings;
706
-        } else {
707
-            self::$_settings[ $addon_name ] = $addon_settings;
708
-        }
709
-        return false;
710
-    }
711
-
712
-
713
-    /**
714
-     * @param string $addon_name
715
-     * @return void
716
-     * @throws EE_Error
717
-     */
718
-    private static function _setup_autoloaders(string $addon_name)
719
-    {
720
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
721
-            // setup autoloader for single file
722
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
723
-        }
724
-        // setup autoloaders for folders
725
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
726
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
727
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
728
-            }
729
-        }
730
-    }
731
-
732
-
733
-    /**
734
-     * register new models and extensions
735
-     *
736
-     * @param string $addon_name
737
-     * @return void
738
-     * @throws EE_Error
739
-     */
740
-    private static function _register_models_and_extensions(string $addon_name)
741
-    {
742
-        // register new models
743
-        if (
744
-            ! empty(self::$_settings[ $addon_name ]['model_paths'])
745
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
746
-        ) {
747
-            EE_Register_Model::register(
748
-                $addon_name,
749
-                [
750
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
751
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
752
-                ]
753
-            );
754
-        }
755
-        // register model extensions
756
-        if (
757
-            ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
758
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
759
-        ) {
760
-            EE_Register_Model_Extensions::register(
761
-                $addon_name,
762
-                [
763
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
764
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
765
-                ]
766
-            );
767
-        }
768
-    }
769
-
770
-
771
-    /**
772
-     * @param string $addon_name
773
-     * @return void
774
-     * @throws EE_Error
775
-     */
776
-    private static function _register_data_migration_scripts(string $addon_name)
777
-    {
778
-        // setup DMS
779
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
780
-            EE_Register_Data_Migration_Scripts::register(
781
-                $addon_name,
782
-                ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
783
-            );
784
-        }
785
-    }
786
-
787
-
788
-    /**
789
-     * @param string $addon_name
790
-     * @return void
791
-     * @throws EE_Error
792
-     */
793
-    private static function _register_config(string $addon_name)
794
-    {
795
-        // if config_class is present let's register config.
796
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
797
-            EE_Register_Config::register(
798
-                self::$_settings[ $addon_name ]['config_class'],
799
-                [
800
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
801
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
802
-                ]
803
-            );
804
-        }
805
-    }
806
-
807
-
808
-    /**
809
-     * @param string $addon_name
810
-     * @return void
811
-     * @throws EE_Error
812
-     */
813
-    private static function _register_admin_pages(string $addon_name)
814
-    {
815
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
816
-            EE_Register_Admin_Page::register(
817
-                $addon_name,
818
-                ['page_path' => self::$_settings[ $addon_name ]['admin_path']]
819
-            );
820
-        }
821
-    }
822
-
823
-
824
-    /**
825
-     * @param string $addon_name
826
-     * @return void
827
-     * @throws EE_Error
828
-     */
829
-    private static function _register_modules(string $addon_name)
830
-    {
831
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
832
-            EE_Register_Module::register(
833
-                $addon_name,
834
-                ['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
835
-            );
836
-        }
837
-    }
838
-
839
-
840
-    /**
841
-     * @param string $addon_name
842
-     * @return void
843
-     * @throws EE_Error
844
-     */
845
-    private static function _register_shortcodes(string $addon_name)
846
-    {
847
-        if (
848
-            ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
850
-        ) {
851
-            EE_Register_Shortcode::register(
852
-                $addon_name,
853
-                [
854
-                    'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
855
-                    'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
856
-                ]
857
-            );
858
-        }
859
-    }
860
-
861
-
862
-    /**
863
-     * @param string $addon_name
864
-     * @return void
865
-     * @throws EE_Error
866
-     */
867
-    private static function _register_widgets(string $addon_name)
868
-    {
869
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
870
-            EE_Register_Widget::register(
871
-                $addon_name,
872
-                ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
873
-            );
874
-        }
875
-    }
876
-
877
-
878
-    /**
879
-     * @param string $addon_name
880
-     * @return void
881
-     * @throws EE_Error
882
-     */
883
-    private static function _register_capabilities(string $addon_name)
884
-    {
885
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
886
-            EE_Register_Capabilities::register(
887
-                $addon_name,
888
-                [
889
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
890
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
891
-                ]
892
-            );
893
-        }
894
-    }
895
-
896
-
897
-    /**
898
-     * @param string $addon_name
899
-     * @return void
900
-     */
901
-    private static function _register_message_types(string $addon_name)
902
-    {
903
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
904
-            add_action(
905
-                'EE_Brewing_Regular___messages_caf',
906
-                ['EE_Register_Addon', 'register_message_types']
907
-            );
908
-        }
909
-    }
910
-
911
-
912
-    /**
913
-     * @param string $addon_name
914
-     * @return void
915
-     * @throws EE_Error
916
-     */
917
-    private static function _register_custom_post_types(string $addon_name)
918
-    {
919
-        if (
920
-            ! empty(self::$_settings[ $addon_name ]['custom_post_types'])
921
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
922
-        ) {
923
-            EE_Register_CPT::register(
924
-                $addon_name,
925
-                [
926
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
927
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
928
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
929
-                ]
930
-            );
931
-        }
932
-    }
933
-
934
-
935
-    /**
936
-     * @param string $addon_name
937
-     * @return void
938
-     * @throws InvalidArgumentException
939
-     * @throws InvalidInterfaceException
940
-     * @throws InvalidDataTypeException
941
-     * @throws DomainException
942
-     * @throws EE_Error
943
-     */
944
-    private static function _register_payment_methods(string $addon_name)
945
-    {
946
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
947
-            EE_Register_Payment_Method::register(
948
-                $addon_name,
949
-                ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
950
-            );
951
-        }
952
-    }
953
-
954
-
955
-    /**
956
-     * @param string $addon_name
957
-     * @return void
958
-     * @throws InvalidArgumentException
959
-     * @throws InvalidInterfaceException
960
-     * @throws InvalidDataTypeException
961
-     * @throws DomainException
962
-     */
963
-    private static function registerPrivacyPolicies(string $addon_name)
964
-    {
965
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
966
-            EE_Register_Privacy_Policy::register(
967
-                $addon_name,
968
-                self::$_settings[ $addon_name ]['privacy_policies']
969
-            );
970
-        }
971
-    }
972
-
973
-
974
-    /**
975
-     * @param string $addon_name
976
-     * @return void
977
-     */
978
-    private static function registerPersonalDataExporters(string $addon_name)
979
-    {
980
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
981
-            EE_Register_Personal_Data_Eraser::register(
982
-                $addon_name,
983
-                self::$_settings[ $addon_name ]['personal_data_exporters']
984
-            );
985
-        }
986
-    }
987
-
988
-
989
-    /**
990
-     * @param string $addon_name
991
-     * @return void
992
-     */
993
-    private static function registerPersonalDataErasers(string $addon_name)
994
-    {
995
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
996
-            EE_Register_Personal_Data_Eraser::register(
997
-                $addon_name,
998
-                self::$_settings[ $addon_name ]['personal_data_erasers']
999
-            );
1000
-        }
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
1006
-     *
1007
-     * @param string $addon_name
1008
-     * @return EE_Addon
1009
-     * @throws InvalidArgumentException
1010
-     * @throws InvalidInterfaceException
1011
-     * @throws InvalidDataTypeException
1012
-     */
1013
-    private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1014
-    {
1015
-        $addon = self::$loader->getShared(
1016
-            self::$_settings[ $addon_name ]['class_name'],
1017
-            ['EE_Registry::create(addon)' => true]
1018
-        );
1019
-        if (! $addon instanceof EE_Addon) {
1020
-            throw new DomainException(
1021
-                sprintf(
1022
-                    esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1023
-                    self::$_settings[ $addon_name ]['class_name']
1024
-                )
1025
-            );
1026
-        }
1027
-        // setter inject dep map if required
1028
-        if ($addon->dependencyMap() === null) {
1029
-            $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map'));
1030
-        }
1031
-        // setter inject domain if required
1032
-        EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1033
-
1034
-        $addon->set_name($addon_name);
1035
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1036
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1037
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1038
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1039
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1040
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1041
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1042
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1043
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1044
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1045
-        do_action(
1046
-            'AHEE__EE_Register_Addon___load_and_init_addon_class',
1047
-            $addon,
1048
-            $addon_name,
1049
-            self::$_settings
1050
-        );
1051
-        // unfortunately this can't be hooked in upon construction,
1052
-        // because we don't have the plugin's mainfile path upon construction.
1053
-        register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1054
-        // call any additional admin_callback functions during load_admin_controller hook
1055
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1056
-            add_action(
1057
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
1058
-                [$addon, self::$_settings[ $addon_name ]['admin_callback']]
1059
-            );
1060
-        }
1061
-        return $addon;
1062
-    }
1063
-
1064
-
1065
-    /**
1066
-     * @param string   $addon_name
1067
-     * @param EE_Addon $addon
1068
-     * @since   4.10.13.p
1069
-     */
1070
-    private static function injectAddonDomain(string $addon_name, EE_Addon $addon)
1071
-    {
1072
-        if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1073
-            // using supplied Domain object
1074
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1075
-                ? self::$_settings[ $addon_name ]['domain']
1076
-                : null;
1077
-            // or construct one using Domain FQCN
1078
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1079
-                $domain = self::$loader->getShared(
1080
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1081
-                    [
1082
-                        new EventEspresso\core\domain\values\FilePath(
1083
-                            self::$_settings[ $addon_name ]['main_file_path']
1084
-                        ),
1085
-                        EventEspresso\core\domain\values\Version::fromString(
1086
-                            self::$_settings[ $addon_name ]['version']
1087
-                        ),
1088
-                    ]
1089
-                );
1090
-            }
1091
-            if ($domain instanceof DomainInterface) {
1092
-                $addon->setDomain($domain);
1093
-            }
1094
-        }
1095
-    }
1096
-
1097
-
1098
-    /**
1099
-     * @return void
1100
-     * @deprecated 5.0.0.p
1101
-     */
1102
-    public static function load_pue_update()
1103
-    {
1104
-    }
1105
-
1106
-
1107
-    /**
1108
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1109
-     *
1110
-     * @return void
1111
-     * @throws EE_Error
1112
-     * @since 4.4.0
1113
-     */
1114
-    public static function register_message_types()
1115
-    {
1116
-        foreach (self::$_settings as $settings) {
1117
-            if (! empty($settings['message_types'])) {
1118
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1119
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1120
-                }
1121
-            }
1122
-        }
1123
-    }
1124
-
1125
-
1126
-    private static function registerLicense($addon_name)
1127
-    {
1128
-        $addon_settings = self::$_settings[ $addon_name ] ?? [];
1129
-        if (empty($addon_settings)) {
1130
-            return;
1131
-        }
1132
-        $license_data = isset($addon_settings['license']) ? (array) $addon_settings['license'] : [];
1133
-        // copy known values from addon settings to license data if anything's missing
1134
-        $license_data += [
1135
-            'main_file_path'   => $addon_settings['main_file_path'] ?? '',
1136
-            'min_core_version' => $addon_settings['min_core_version'] ?? '',
1137
-            'plugin_id'        => 0, // no corresponding value in addon settings
1138
-            'plugin_slug'      => $addon_settings['plugin_slug'] ?? '',
1139
-            'version'          => $addon_settings['version'] ?? '',
1140
-        ];
1141
-        EventEspresso\core\services\licensing\AddonLicense::register($addon_name, $license_data);
1142
-    }
1143
-
1144
-
1145
-    /**
1146
-     * This deregisters an addon that was previously registered with a specific addon_name.
1147
-     *
1148
-     * @param string $addon_name the name for the addon that was previously registered
1149
-     * @throws DomainException
1150
-     * @throws InvalidArgumentException
1151
-     * @throws InvalidDataTypeException
1152
-     * @throws InvalidInterfaceException
1153
-     * @since    4.3.0
1154
-     */
1155
-    public static function deregister(string $addon_name = '')
1156
-    {
1157
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1158
-            try {
1159
-                do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1160
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1161
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1162
-                    // setup DMS
1163
-                    EE_Register_Data_Migration_Scripts::deregister($addon_name);
1164
-                }
1165
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1166
-                    // register admin page
1167
-                    EE_Register_Admin_Page::deregister($addon_name);
1168
-                }
1169
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1170
-                    // add to list of modules to be registered
1171
-                    EE_Register_Module::deregister($addon_name);
1172
-                }
1173
-                if (
1174
-                    ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1175
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1176
-                ) {
1177
-                    // add to list of shortcodes to be registered
1178
-                    EE_Register_Shortcode::deregister($addon_name);
1179
-                }
1180
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1181
-                    // if config_class present let's register config.
1182
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1183
-                }
1184
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1185
-                    // add to list of widgets to be registered
1186
-                    EE_Register_Widget::deregister($addon_name);
1187
-                }
1188
-                if (
1189
-                    ! empty(self::$_settings[ $addon_name ]['model_paths'])
1190
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1191
-                ) {
1192
-                    // add to list of shortcodes to be registered
1193
-                    EE_Register_Model::deregister($addon_name);
1194
-                }
1195
-                if (
1196
-                    ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1197
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1198
-                ) {
1199
-                    // add to list of shortcodes to be registered
1200
-                    EE_Register_Model_Extensions::deregister($addon_name);
1201
-                }
1202
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1203
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1204
-                        EE_Register_Message_Type::deregister($message_type);
1205
-                    }
1206
-                }
1207
-                // deregister capabilities for addon
1208
-                if (
1209
-                    ! empty(self::$_settings[ $addon_name ]['capabilities'])
1210
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1211
-                ) {
1212
-                    EE_Register_Capabilities::deregister($addon_name);
1213
-                }
1214
-                // deregister custom_post_types for addon
1215
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1216
-                    EE_Register_CPT::deregister($addon_name);
1217
-                }
1218
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1219
-                    EE_Register_Payment_Method::deregister($addon_name);
1220
-                }
1221
-                $addon = EE_Registry::instance()->getAddon($class_name);
1222
-                if ($addon instanceof EE_Addon) {
1223
-                    remove_action(
1224
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1225
-                        [$addon, 'deactivation']
1226
-                    );
1227
-                    remove_action(
1228
-                        'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1229
-                        [$addon, 'initialize_db_if_no_migrations_required']
1230
-                    );
1231
-                    // remove `after_registration` call
1232
-                    remove_action(
1233
-                        'AHEE__EE_System__load_espresso_addons__complete',
1234
-                        [$addon, 'after_registration'],
1235
-                        999
1236
-                    );
1237
-                }
1238
-                EE_Registry::instance()->removeAddon($class_name);
1239
-                LoaderFactory::getLoader()->remove($class_name);
1240
-            } catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1241
-                // the add-on was not yet registered in the registry,
1242
-                // so RegistryContainer::__get() throws this exception.
1243
-                // also no need to worry about this or log it,
1244
-                // it's ok to deregister an add-on before its registered in the registry
1245
-            } catch (Exception $e) {
1246
-                new ExceptionLogger($e);
1247
-            }
1248
-            unset(self::$_settings[ $addon_name ]);
1249
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1250
-        }
1251
-    }
1252
-
1253
-
1254
-    public static function reset(): void
1255
-    {
1256
-        EE_Register_Addon::$_settings = [];
1257
-    }
1258
-
1259
-
1260
-    public static function resetAll(): void
1261
-    {
1262
-        // EE_Register_Addon::reset();
1263
-        EE_Register_Admin_Page::reset();
1264
-        EE_Register_Capabilities::reset();
1265
-        EE_Register_Config::reset();
1266
-        EE_Register_CPT::reset();
1267
-        EE_Register_Data_Migration_Scripts::reset();
1268
-        EE_Register_Message_Type::reset();
1269
-        EE_Register_Messages_Shortcode_Library::reset();
1270
-        EE_Register_Messages_Template_Pack::reset();
1271
-        EE_Register_Messages_Template_Variations::reset();
1272
-        EE_Register_Model::reset();
1273
-        EE_Register_Model_Extensions::reset();
1274
-        EE_Register_Module::reset();
1275
-        EE_Register_Payment_Method::reset();
1276
-        EE_Register_Personal_Data_Eraser::reset();
1277
-        EE_Register_Personal_Data_Exporter::reset();
1278
-        EE_Register_Privacy_Policy::reset();
1279
-        EE_Register_Shortcode::reset();
1280
-        EE_Register_Widget::reset();
1281
-    }
27
+	/**
28
+	 * possibly truncated version of the EE core version string
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected static $_core_version = '';
33
+
34
+	/**
35
+	 * Holds values for registered addons
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected static $_settings = [];
40
+
41
+	/**
42
+	 * @var  array $_incompatible_addons keys are addon SLUGS
43
+	 *                                   (first argument passed to EE_Register_Addon::register()), keys are
44
+	 *                                   their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
+	 *                                   Generally this should be used sparingly, as we don't want to muddle up
46
+	 *                                   EE core with knowledge of ALL the addons out there.
47
+	 *                                   If you want NO versions of an addon to run with a certain version of core,
48
+	 *                                   it's usually best to define the addon's "min_core_version" as part of its call
49
+	 *                                   to EE_Register_Addon::register(), rather than using this array with a super
50
+	 *                                   high value for its minimum plugin version.
51
+	 */
52
+	protected static $_incompatible_addons = [
53
+		'Multi_Event_Registration' => '2.0.11.rc.002',
54
+		'Promotions'               => '1.0.0.rc.084',
55
+	];
56
+
57
+	/**
58
+	 * @var LoaderInterface
59
+	 */
60
+	protected static $loader;
61
+
62
+
63
+	/**
64
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
65
+	 * not just '4.3.0'.
66
+	 * So if the addon developer doesn't provide that full version string,
67
+	 * fill in the blanks for them
68
+	 *
69
+	 * @param string $min_core_version
70
+	 * @return string always like '4.3.0.rc.000'
71
+	 */
72
+	protected static function _effective_version(string $min_core_version): string
73
+	{
74
+		// versions: 4 . 3 . 1 . p . 123
75
+		// offsets:    0 . 1 . 2 . 3 . 4
76
+		$version_parts = explode('.', $min_core_version);
77
+		// check they specified the micro version (after 2nd period)
78
+		if (! isset($version_parts[2])) {
79
+			$version_parts[2] = '0';
80
+		}
81
+		// if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
82
+		// soon we can assume that's 'rc', but this current version is 'alpha'
83
+		if (! isset($version_parts[3])) {
84
+			$version_parts[3] = 'dev';
85
+		}
86
+		if (! isset($version_parts[4])) {
87
+			$version_parts[4] = '000';
88
+		}
89
+		return implode('.', $version_parts);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Returns whether or not the min core version requirement of the addon is met
95
+	 *
96
+	 * @param string $min_core_version    the minimum core version required by the addon
97
+	 * @param string $actual_core_version the actual core version, optional
98
+	 * @return bool
99
+	 */
100
+	public static function _meets_min_core_version_requirement(
101
+		string $min_core_version,
102
+		string $actual_core_version = EVENT_ESPRESSO_VERSION
103
+	): bool {
104
+		return version_compare(
105
+			self::_effective_version($actual_core_version),
106
+			self::_effective_version($min_core_version),
107
+			'>='
108
+		);
109
+	}
110
+
111
+
112
+	/**
113
+	 * Method for registering new EE_Addons.
114
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
115
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
116
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
117
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
118
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
119
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
120
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
121
+	 * (so that we can detect that the addon has activated on the subsequent request)
122
+	 *
123
+	 * @param string                  $addon_name                       [Required] the EE_Addon's name.
124
+	 * @param array                   $setup_args                       {
125
+	 *                                                                  An array of arguments provided for registering
126
+	 *                                                                  the message type.
127
+	 * @type  string                  $class_name                       the addon's main file name.
128
+	 *                                                                  If left blank, generated from the addon name,
129
+	 *                                                                  changes something like "calendar" to
130
+	 *                                                                  "EE_Calendar"
131
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
132
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
133
+	 * @type string                   $version                          the "software" version for the addon. eg
134
+	 *                                                                  "1.0.0.p" for a first stable release, or
135
+	 *                                                                  "1.0.0.rc.043" for a version in progress
136
+	 * @type string                   $main_file_path                   the full server path to the main file
137
+	 *                                                                  loaded directly by WP
138
+	 * @type DomainInterface          $domain                           child class of
139
+	 *                                                                  EventEspresso\core\domain\DomainBase
140
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
141
+	 *                                                                  for the addon's Domain class
142
+	 *                                                                  (see EventEspresso\core\domain\Domain)
143
+	 * @type string                   $admin_path                       full server path to the folder where the
144
+	 *                                                                  addon\'s admin files reside
145
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
146
+	 *                                                                  first invoked, can be used for hooking into
147
+	 *                                                                  any admin page
148
+	 * @type string                   $config_section                   the section name for this addon's
149
+	 *                                                                  configuration settings section
150
+	 *                                                                  (defaults to "addons")
151
+	 * @type string                   $config_class                     the class name for this addon's
152
+	 *                                                                  configuration settings object
153
+	 * @type string                   $config_name                      the class name for this addon's
154
+	 *                                                                  configuration settings object
155
+	 * @type string                   $autoloader_paths                 [Required] an array of class names and the full
156
+	 *                                                                  server paths to those files.
157
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
158
+	 *                                                                  folders containing classes that might be
159
+	 *                                                                  invoked by the addon
160
+	 * @type string                   $dms_paths                        [Required] an array of full server paths to
161
+	 *                                                                  folders that contain data migration scripts.
162
+	 *                                                                  The key should be the EE_Addon class name that
163
+	 *                                                                  this set of data migration scripts belongs to.
164
+	 *                                                                  If the EE_Addon class is namespaced, then this
165
+	 *                                                                  needs to be the Fully Qualified Class Name
166
+	 * @type string                   $module_paths                     an array of full server paths to any
167
+	 *                                                                  EED_Modules used by the addon
168
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
169
+	 *                                                                  that contain EES_Shortcodes
170
+	 * @type string                   $widget_paths                     an array of full server paths to folders
171
+	 *                                                                  that contain WP_Widgets
172
+	 * @type array                    $capabilities                     an array indexed by role name
173
+	 *                                                                  (i.e administrator,author ) and the values
174
+	 *                                                                  are an array of caps to add to the role.
175
+	 *                                                                  'administrator' => array(
176
+	 *                                                                  'read_addon',
177
+	 *                                                                  'edit_addon',
178
+	 *                                                                  etc.
179
+	 *                                                                  ).
180
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
181
+	 *                                                                  for any addons that need to register any
182
+	 *                                                                  special meta mapped capabilities.  Should
183
+	 *                                                                  be indexed where the key is the
184
+	 *                                                                  EE_Meta_Capability_Map class name and the
185
+	 *                                                                  values are the arguments sent to the class.
186
+	 * @type array                    $model_paths                      array of folders containing DB models
187
+	 * @return bool
188
+	 * @throws DomainException
189
+	 * @throws EE_Error
190
+	 * @throws InvalidArgumentException
191
+	 * @throws InvalidDataTypeException
192
+	 * @throws InvalidInterfaceException
193
+	 * @since                                                           4.3.0
194
+	 * @see                                                             EE_Register_Model
195
+	 * @type array                    $class_paths                      array of folders containing DB classes
196
+	 * @see                                                             EE_Register_Model
197
+	 * @type array                    $model_extension_paths            array of folders containing DB model
198
+	 *                                                                  extensions
199
+	 * @see                                                             EE_Register_Model_Extension
200
+	 * @type array                    $class_extension_paths            array of folders containing DB class
201
+	 *                                                                  extensions
202
+	 * @see                                                             EE_Register_Model_Extension
203
+	 * @type array message_types {
204
+	 *                                                                  An array of message types with the key as
205
+	 *                                                                  the message type name and the values as
206
+	 *                                                                  below:
207
+	 * @type string                   $mtfilename                       [Required] The filename of the message type
208
+	 *                                                                  being registered. This will be the main
209
+	 *                                                                  EE_{Message Type Name}_message_type class.
210
+	 *                                                                  for example:
211
+	 *                                                                  EE_Declined_Registration_message_type.class.php
212
+	 * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
213
+	 *                                                                  messages autoloader for the new message type.
214
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
215
+	 *                                                                  type should activate with. Each value in
216
+	 *                                                                  the
217
+	 *                                                                  array
218
+	 *                                                                  should match the name property of a
219
+	 *                                                                  EE_messenger. Optional.
220
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
221
+	 *                                                                  type should validate with. Each value in
222
+	 *                                                                  the
223
+	 *                                                                  array
224
+	 *                                                                  should match the name property of an
225
+	 *                                                                  EE_messenger.
226
+	 *                                                                  Optional.
227
+	 *                                                                  }
228
+	 * @type array                    $custom_post_types
229
+	 * @type array                    $custom_taxonomies
230
+	 * @type array                    $payment_method_paths             each element is the folder containing the
231
+	 *                                                                  EE_PMT_Base child class
232
+	 *                                                                  (eg,
233
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
234
+	 *                                                                  which contains the files
235
+	 *                                                                  EE_PMT_Payomatic.pm.php)
236
+	 * @type array                    $default_terms
237
+	 * @type array                    $namespace                        {
238
+	 *                                                                  An array with two items for registering the
239
+	 *                                                                  addon's namespace. (If, for some reason, you
240
+	 *                                                                  require additional namespaces,
241
+	 *                                                                  use
242
+	 *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
243
+	 *                                                                  directly)
244
+	 * @see                                                             EventEspresso\core\Psr4Autoloader::addNamespace()
245
+	 * @type string                   $FQNS                             the namespace prefix
246
+	 * @type string                   $DIR                              a base directory for class files in the
247
+	 *                                                                  namespace.
248
+	 *                                                                  }
249
+	 *                                                                  }
250
+	 * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
251
+	 *                                                                  privacy policy classes) or FQCNs (specific
252
+	 *                                                                  classnames of privacy policy classes)
253
+	 * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
254
+	 *                                                                  privacy policy classes) or FQCNs (specific
255
+	 *                                                                  classnames of privacy policy classes)
256
+	 * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
257
+	 *                                                                  privacy policy classes) or FQCNs (specific
258
+	 *                                                                  classnames of privacy policy classes)
259
+	 */
260
+	public static function register(string $addon_name = '', array $setup_args = []): bool
261
+	{
262
+		// $addon_name = basename($addon_name);
263
+		if (! self::$loader instanceof LoaderInterface) {
264
+			self::$loader = LoaderFactory::getLoader();
265
+		}
266
+		// make sure this was called in the right place!
267
+		if (
268
+			! did_action('activate_plugin')
269
+			&& (
270
+				! did_action('AHEE__EE_System__load_espresso_addons')
271
+				|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
272
+			)
273
+		) {
274
+			EE_Error::doing_it_wrong(
275
+				__METHOD__,
276
+				sprintf(
277
+					esc_html__(
278
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
279
+						'event_espresso'
280
+					),
281
+					$addon_name
282
+				),
283
+				'4.3.0'
284
+			);
285
+			return false;
286
+		}
287
+		// required fields MUST be present, so let's make sure they are.
288
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
289
+		// get class name for addon
290
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
291
+		// setup $_settings array from incoming values.
292
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
293
+		// allow early addon setup or modification of addon api settings
294
+		self::$_settings = (array) apply_filters(
295
+			'FHEE__EE_Register_Addon__register',
296
+			self::$_settings,
297
+			$addon_name,
298
+			$class_name,
299
+			$setup_args
300
+		);
301
+		// does this addon work with this version of core or WordPress ?
302
+		// does this addon work with this version of core or WordPress ?
303
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
304
+			return false;
305
+		}
306
+		// register namespaces
307
+		EE_Register_Addon::_setup_namespaces($addon_settings);
308
+		// check if this is an activation request
309
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
310
+			// dont bother setting up the rest of the addon atm
311
+			return false;
312
+		}
313
+		// we need cars
314
+		EE_Register_Addon::_setup_autoloaders($addon_name);
315
+		// register new models and extensions
316
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
317
+		// setup DMS
318
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
319
+		// if config_class is present let's register config.
320
+		EE_Register_Addon::_register_config($addon_name);
321
+		// register admin pages
322
+		EE_Register_Addon::_register_admin_pages($addon_name);
323
+		// add to list of modules to be registered
324
+		EE_Register_Addon::_register_modules($addon_name);
325
+		// add to list of shortcodes to be registered
326
+		EE_Register_Addon::_register_shortcodes($addon_name);
327
+		// add to list of widgets to be registered
328
+		EE_Register_Addon::_register_widgets($addon_name);
329
+		// register capability related stuff.
330
+		EE_Register_Addon::_register_capabilities($addon_name);
331
+		// any message type to register?
332
+		EE_Register_Addon::_register_message_types($addon_name);
333
+		// any custom post type/ custom capabilities or default terms to register
334
+		EE_Register_Addon::_register_custom_post_types($addon_name);
335
+		// and any payment methods
336
+		EE_Register_Addon::_register_payment_methods($addon_name);
337
+		// and privacy policy generators
338
+		EE_Register_Addon::registerPrivacyPolicies($addon_name);
339
+		// and privacy policy generators
340
+		EE_Register_Addon::registerPersonalDataExporters($addon_name);
341
+		// and privacy policy generators
342
+		EE_Register_Addon::registerPersonalDataErasers($addon_name);
343
+		EE_Register_Addon::registerLicense($addon_name);
344
+		// load and instantiate main addon class
345
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
346
+		// delay calling after_registration hook on each addon until after all add-ons have been registered.
347
+		add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999);
348
+		return $addon instanceof EE_Addon;
349
+	}
350
+
351
+
352
+	/**
353
+	 * @param string $addon_name
354
+	 * @param array  $setup_args
355
+	 * @return void
356
+	 * @throws EE_Error
357
+	 */
358
+	private static function _verify_parameters(string $addon_name, array $setup_args)
359
+	{
360
+		// required fields MUST be present, so let's make sure they are.
361
+		if (empty($addon_name) || empty($setup_args)) {
362
+			throw new EE_Error(
363
+				esc_html__(
364
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
365
+					'event_espresso'
366
+				)
367
+			);
368
+		}
369
+		if (empty($setup_args['main_file_path'])) {
370
+			throw new EE_Error(
371
+				sprintf(
372
+					esc_html__(
373
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
374
+						'event_espresso'
375
+					),
376
+					implode(',', array_keys($setup_args))
377
+				)
378
+			);
379
+		}
380
+		// check that addon has not already been registered with that name
381
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
382
+			throw new EE_Error(
383
+				sprintf(
384
+					esc_html__(
385
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
386
+						'event_espresso'
387
+					),
388
+					$addon_name
389
+				)
390
+			);
391
+		}
392
+	}
393
+
394
+
395
+	/**
396
+	 * @param string $addon_name
397
+	 * @param array  $setup_args
398
+	 * @return string
399
+	 */
400
+	private static function _parse_class_name(string $addon_name, array $setup_args): string
401
+	{
402
+		if (empty($setup_args['class_name'])) {
403
+			// generate one by first separating name with spaces
404
+			$class_name = str_replace(['-', '_'], ' ', trim($addon_name));
405
+			// capitalize, then replace spaces with underscores
406
+			$class_name = str_replace(' ', '_', ucwords($class_name));
407
+		} else {
408
+			$class_name = $setup_args['class_name'];
409
+		}
410
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
411
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
412
+			? $class_name
413
+			: 'EE_' . $class_name;
414
+	}
415
+
416
+
417
+	/**
418
+	 * @param string $class_name
419
+	 * @param array  $setup_args
420
+	 * @return array
421
+	 */
422
+	private static function _get_addon_settings(string $class_name, array $setup_args): array
423
+	{
424
+		// setup $_settings array from incoming values.
425
+		$addon_settings = [
426
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
427
+			'class_name'            => $class_name,
428
+			// the addon slug for use in URLs, etc
429
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
430
+				? (string) $setup_args['plugin_slug']
431
+				: sanitize_key($class_name),
432
+			// page slug to be used when generating the "Settings" link on the WP plugin page
433
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
434
+				? (string) $setup_args['plugin_action_slug']
435
+				: '',
436
+			// the "software" version for the addon
437
+			'version'               => isset($setup_args['version'])
438
+				? (string) $setup_args['version']
439
+				: '',
440
+			// the minimum version of EE Core that the addon will work with
441
+			'min_core_version'      => isset($setup_args['min_core_version'])
442
+				? (string) $setup_args['min_core_version']
443
+				: '',
444
+			// the minimum version of WordPress that the addon will work with
445
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
446
+				? (string) $setup_args['min_wp_version']
447
+				: EE_MIN_WP_VER_REQUIRED,
448
+			// full server path to main file (file loaded directly by WP)
449
+			'main_file_path'        => isset($setup_args['main_file_path'])
450
+				? (string) $setup_args['main_file_path']
451
+				: '',
452
+			// instance of \EventEspresso\core\domain\DomainInterface
453
+			'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
454
+				? $setup_args['domain']
455
+				: null,
456
+			// Fully Qualified Class Name for the addon's Domain class
457
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
458
+				? (string) $setup_args['domain_fqcn']
459
+				: '',
460
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
461
+			'admin_path'            => isset($setup_args['admin_path'])
462
+				? (string) $setup_args['admin_path']
463
+				: '',
464
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
465
+			'admin_callback'        => isset($setup_args['admin_callback'])
466
+				? (string) $setup_args['admin_callback']
467
+				: '',
468
+			// the section name for this addon's configuration settings section (defaults to "addons")
469
+			'config_section'        => isset($setup_args['config_section'])
470
+				? (string) $setup_args['config_section']
471
+				: 'addons',
472
+			// the class name for this addon's configuration settings object
473
+			'config_class'          => isset($setup_args['config_class'])
474
+				? (string) $setup_args['config_class']
475
+				: '',
476
+			// the name given to the config for this addons' configuration settings object (optional)
477
+			'config_name'           => isset($setup_args['config_name'])
478
+				? (string) $setup_args['config_name']
479
+				: '',
480
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
481
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
482
+				? (array) $setup_args['autoloader_paths']
483
+				: [],
484
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
485
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
486
+				? (array) $setup_args['autoloader_folders']
487
+				: [],
488
+			// array of full server paths to any EE_DMS data migration scripts used by the addon.
489
+			// The key should be the EE_Addon class name that this set of data migration scripts belongs to.
490
+			// If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
491
+			'dms_paths'             => isset($setup_args['dms_paths'])
492
+				? (array) $setup_args['dms_paths']
493
+				: [],
494
+			// array of full server paths to any EED_Modules used by the addon
495
+			'module_paths'          => isset($setup_args['module_paths'])
496
+				? (array) $setup_args['module_paths']
497
+				: [],
498
+			// array of full server paths to any EES_Shortcodes used by the addon
499
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
500
+				? (array) $setup_args['shortcode_paths']
501
+				: [],
502
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
503
+				? (array) $setup_args['shortcode_fqcns']
504
+				: [],
505
+			// array of full server paths to any WP_Widgets used by the addon
506
+			'widget_paths'          => isset($setup_args['widget_paths'])
507
+				? (array) $setup_args['widget_paths']
508
+				: [],
509
+			'message_types'         => isset($setup_args['message_types'])
510
+				? (array) $setup_args['message_types']
511
+				: [],
512
+			'capabilities'          => isset($setup_args['capabilities'])
513
+				? (array) $setup_args['capabilities']
514
+				: [],
515
+			'capability_maps'       => isset($setup_args['capability_maps'])
516
+				? (array) $setup_args['capability_maps']
517
+				: [],
518
+			'model_paths'           => isset($setup_args['model_paths'])
519
+				? (array) $setup_args['model_paths']
520
+				: [],
521
+			'class_paths'           => isset($setup_args['class_paths'])
522
+				? (array) $setup_args['class_paths']
523
+				: [],
524
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
525
+				? (array) $setup_args['model_extension_paths']
526
+				: [],
527
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
528
+				? (array) $setup_args['class_extension_paths']
529
+				: [],
530
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
531
+				? (array) $setup_args['custom_post_types']
532
+				: [],
533
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
534
+				? (array) $setup_args['custom_taxonomies']
535
+				: [],
536
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
537
+				? (array) $setup_args['payment_method_paths']
538
+				: [],
539
+			'default_terms'         => isset($setup_args['default_terms'])
540
+				? (array) $setup_args['default_terms']
541
+				: [],
542
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
543
+			// that can be used for adding upgrading/marketing info
544
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
545
+				? (array) $setup_args['plugins_page_row']
546
+				: [],
547
+			'namespace'             => isset(
548
+				$setup_args['namespace']['FQNS'],
549
+				$setup_args['namespace']['DIR']
550
+			)
551
+				? (array) $setup_args['namespace']
552
+				: [],
553
+			'privacy_policies'      => isset($setup_args['privacy_policies'])
554
+				? (array) $setup_args['privacy_policies']
555
+				: [],
556
+			'license'               => isset($setup_args['license'])
557
+				? (array) $setup_args['license']
558
+				: [],
559
+		];
560
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
561
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
562
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
563
+												&& ! empty($addon_settings['admin_path'])
564
+			? $addon_settings['plugin_slug']
565
+			: $addon_settings['plugin_action_slug'];
566
+		// full server path to main file (file loaded directly by WP)
567
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
568
+		return $addon_settings;
569
+	}
570
+
571
+
572
+	/**
573
+	 * @param string $addon_name
574
+	 * @param array  $addon_settings
575
+	 * @return bool
576
+	 */
577
+	private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool
578
+	{
579
+		global $wp_version;
580
+		$incompatibility_message = '';
581
+		// check whether this addon version is compatible with EE core
582
+		if (
583
+			isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
584
+			&& ! self::_meets_min_core_version_requirement(
585
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
586
+				$addon_settings['version']
587
+			)
588
+		) {
589
+			$incompatibility_message = sprintf(
590
+				esc_html__(
591
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
592
+					'event_espresso'
593
+				),
594
+				$addon_name,
595
+				'<br />',
596
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
597
+				'<span style="font-weight: bold; color: #D54E21;">',
598
+				'</span><br />'
599
+			);
600
+		} elseif (
601
+			! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
602
+		) {
603
+			$incompatibility_message = sprintf(
604
+				esc_html__(
605
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
606
+					'event_espresso'
607
+				),
608
+				$addon_name,
609
+				self::_effective_version($addon_settings['min_core_version']),
610
+				self::_effective_version(espresso_version()),
611
+				'<br />',
612
+				'<span style="font-weight: bold; color: #D54E21;">',
613
+				'</span><br />'
614
+			);
615
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
616
+			$incompatibility_message = sprintf(
617
+				esc_html__(
618
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
619
+					'event_espresso'
620
+				),
621
+				$addon_name,
622
+				$addon_settings['min_wp_version'],
623
+				'<br />',
624
+				'<span style="font-weight: bold; color: #D54E21;">',
625
+				'</span><br />'
626
+			);
627
+		}
628
+		if (! empty($incompatibility_message)) {
629
+			// remove 'activate' from the REQUEST
630
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
631
+			/** @var RequestInterface $request */
632
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
633
+			$request->unSetRequestParam('activate', true);
634
+			if (current_user_can('activate_plugins')) {
635
+				// show an error message indicating the plugin didn't activate properly
636
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
637
+			}
638
+			unset($_GET['activate'], $_REQUEST['activate']);
639
+			if (! function_exists('deactivate_plugins')) {
640
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
641
+			}
642
+			deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
643
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
644
+			return false;
645
+		}
646
+		// addon IS compatible
647
+		return true;
648
+	}
649
+
650
+
651
+	/**
652
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
653
+	 *
654
+	 * @param array $addon_settings
655
+	 * @return void
656
+	 * @throws EE_Error
657
+	 */
658
+	private static function _setup_namespaces(array $addon_settings)
659
+	{
660
+		//
661
+		if (
662
+			isset(
663
+				$addon_settings['namespace']['FQNS'],
664
+				$addon_settings['namespace']['DIR']
665
+			)
666
+		) {
667
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
668
+				$addon_settings['namespace']['FQNS'],
669
+				$addon_settings['namespace']['DIR']
670
+			);
671
+		}
672
+	}
673
+
674
+
675
+	/**
676
+	 * @param string $addon_name
677
+	 * @param array  $addon_settings
678
+	 * @return bool
679
+	 * @throws InvalidArgumentException
680
+	 * @throws InvalidDataTypeException
681
+	 * @throws InvalidInterfaceException
682
+	 */
683
+	private static function _addon_activation(string $addon_name, array $addon_settings): bool
684
+	{
685
+		// this is an activation request
686
+		if (did_action('activate_plugin')) {
687
+			// to find if THIS is the addon that was activated, just check if we have already registered it or not
688
+			// (as the newly-activated addon wasn't around the first time addons were registered).
689
+			if (
690
+				! isset(self::$_settings[ $addon_name ])
691
+				|| (isset(self::$_settings[ $addon_name ])
692
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
693
+				)
694
+			) {
695
+				self::$_settings[ $addon_name ] = $addon_settings;
696
+				$addon                          = self::_load_and_init_addon_class($addon_name);
697
+				$addon->set_activation_indicator_option();
698
+				// dont bother setting up the rest of the addon.
699
+				// we know it was just activated and the request will end soon
700
+			}
701
+			return true;
702
+		}
703
+		// make sure addon settings are set correctly without overwriting anything existing
704
+		if (isset(self::$_settings[ $addon_name ])) {
705
+			self::$_settings[ $addon_name ] += $addon_settings;
706
+		} else {
707
+			self::$_settings[ $addon_name ] = $addon_settings;
708
+		}
709
+		return false;
710
+	}
711
+
712
+
713
+	/**
714
+	 * @param string $addon_name
715
+	 * @return void
716
+	 * @throws EE_Error
717
+	 */
718
+	private static function _setup_autoloaders(string $addon_name)
719
+	{
720
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
721
+			// setup autoloader for single file
722
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
723
+		}
724
+		// setup autoloaders for folders
725
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
726
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
727
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
728
+			}
729
+		}
730
+	}
731
+
732
+
733
+	/**
734
+	 * register new models and extensions
735
+	 *
736
+	 * @param string $addon_name
737
+	 * @return void
738
+	 * @throws EE_Error
739
+	 */
740
+	private static function _register_models_and_extensions(string $addon_name)
741
+	{
742
+		// register new models
743
+		if (
744
+			! empty(self::$_settings[ $addon_name ]['model_paths'])
745
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
746
+		) {
747
+			EE_Register_Model::register(
748
+				$addon_name,
749
+				[
750
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
751
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
752
+				]
753
+			);
754
+		}
755
+		// register model extensions
756
+		if (
757
+			! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
758
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
759
+		) {
760
+			EE_Register_Model_Extensions::register(
761
+				$addon_name,
762
+				[
763
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
764
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
765
+				]
766
+			);
767
+		}
768
+	}
769
+
770
+
771
+	/**
772
+	 * @param string $addon_name
773
+	 * @return void
774
+	 * @throws EE_Error
775
+	 */
776
+	private static function _register_data_migration_scripts(string $addon_name)
777
+	{
778
+		// setup DMS
779
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
780
+			EE_Register_Data_Migration_Scripts::register(
781
+				$addon_name,
782
+				['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
783
+			);
784
+		}
785
+	}
786
+
787
+
788
+	/**
789
+	 * @param string $addon_name
790
+	 * @return void
791
+	 * @throws EE_Error
792
+	 */
793
+	private static function _register_config(string $addon_name)
794
+	{
795
+		// if config_class is present let's register config.
796
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
797
+			EE_Register_Config::register(
798
+				self::$_settings[ $addon_name ]['config_class'],
799
+				[
800
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
801
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
802
+				]
803
+			);
804
+		}
805
+	}
806
+
807
+
808
+	/**
809
+	 * @param string $addon_name
810
+	 * @return void
811
+	 * @throws EE_Error
812
+	 */
813
+	private static function _register_admin_pages(string $addon_name)
814
+	{
815
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
816
+			EE_Register_Admin_Page::register(
817
+				$addon_name,
818
+				['page_path' => self::$_settings[ $addon_name ]['admin_path']]
819
+			);
820
+		}
821
+	}
822
+
823
+
824
+	/**
825
+	 * @param string $addon_name
826
+	 * @return void
827
+	 * @throws EE_Error
828
+	 */
829
+	private static function _register_modules(string $addon_name)
830
+	{
831
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
832
+			EE_Register_Module::register(
833
+				$addon_name,
834
+				['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
835
+			);
836
+		}
837
+	}
838
+
839
+
840
+	/**
841
+	 * @param string $addon_name
842
+	 * @return void
843
+	 * @throws EE_Error
844
+	 */
845
+	private static function _register_shortcodes(string $addon_name)
846
+	{
847
+		if (
848
+			! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
850
+		) {
851
+			EE_Register_Shortcode::register(
852
+				$addon_name,
853
+				[
854
+					'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
855
+					'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
856
+				]
857
+			);
858
+		}
859
+	}
860
+
861
+
862
+	/**
863
+	 * @param string $addon_name
864
+	 * @return void
865
+	 * @throws EE_Error
866
+	 */
867
+	private static function _register_widgets(string $addon_name)
868
+	{
869
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
870
+			EE_Register_Widget::register(
871
+				$addon_name,
872
+				['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
873
+			);
874
+		}
875
+	}
876
+
877
+
878
+	/**
879
+	 * @param string $addon_name
880
+	 * @return void
881
+	 * @throws EE_Error
882
+	 */
883
+	private static function _register_capabilities(string $addon_name)
884
+	{
885
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
886
+			EE_Register_Capabilities::register(
887
+				$addon_name,
888
+				[
889
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
890
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
891
+				]
892
+			);
893
+		}
894
+	}
895
+
896
+
897
+	/**
898
+	 * @param string $addon_name
899
+	 * @return void
900
+	 */
901
+	private static function _register_message_types(string $addon_name)
902
+	{
903
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
904
+			add_action(
905
+				'EE_Brewing_Regular___messages_caf',
906
+				['EE_Register_Addon', 'register_message_types']
907
+			);
908
+		}
909
+	}
910
+
911
+
912
+	/**
913
+	 * @param string $addon_name
914
+	 * @return void
915
+	 * @throws EE_Error
916
+	 */
917
+	private static function _register_custom_post_types(string $addon_name)
918
+	{
919
+		if (
920
+			! empty(self::$_settings[ $addon_name ]['custom_post_types'])
921
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
922
+		) {
923
+			EE_Register_CPT::register(
924
+				$addon_name,
925
+				[
926
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
927
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
928
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
929
+				]
930
+			);
931
+		}
932
+	}
933
+
934
+
935
+	/**
936
+	 * @param string $addon_name
937
+	 * @return void
938
+	 * @throws InvalidArgumentException
939
+	 * @throws InvalidInterfaceException
940
+	 * @throws InvalidDataTypeException
941
+	 * @throws DomainException
942
+	 * @throws EE_Error
943
+	 */
944
+	private static function _register_payment_methods(string $addon_name)
945
+	{
946
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
947
+			EE_Register_Payment_Method::register(
948
+				$addon_name,
949
+				['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
950
+			);
951
+		}
952
+	}
953
+
954
+
955
+	/**
956
+	 * @param string $addon_name
957
+	 * @return void
958
+	 * @throws InvalidArgumentException
959
+	 * @throws InvalidInterfaceException
960
+	 * @throws InvalidDataTypeException
961
+	 * @throws DomainException
962
+	 */
963
+	private static function registerPrivacyPolicies(string $addon_name)
964
+	{
965
+		if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
966
+			EE_Register_Privacy_Policy::register(
967
+				$addon_name,
968
+				self::$_settings[ $addon_name ]['privacy_policies']
969
+			);
970
+		}
971
+	}
972
+
973
+
974
+	/**
975
+	 * @param string $addon_name
976
+	 * @return void
977
+	 */
978
+	private static function registerPersonalDataExporters(string $addon_name)
979
+	{
980
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
981
+			EE_Register_Personal_Data_Eraser::register(
982
+				$addon_name,
983
+				self::$_settings[ $addon_name ]['personal_data_exporters']
984
+			);
985
+		}
986
+	}
987
+
988
+
989
+	/**
990
+	 * @param string $addon_name
991
+	 * @return void
992
+	 */
993
+	private static function registerPersonalDataErasers(string $addon_name)
994
+	{
995
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
996
+			EE_Register_Personal_Data_Eraser::register(
997
+				$addon_name,
998
+				self::$_settings[ $addon_name ]['personal_data_erasers']
999
+			);
1000
+		}
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
1006
+	 *
1007
+	 * @param string $addon_name
1008
+	 * @return EE_Addon
1009
+	 * @throws InvalidArgumentException
1010
+	 * @throws InvalidInterfaceException
1011
+	 * @throws InvalidDataTypeException
1012
+	 */
1013
+	private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1014
+	{
1015
+		$addon = self::$loader->getShared(
1016
+			self::$_settings[ $addon_name ]['class_name'],
1017
+			['EE_Registry::create(addon)' => true]
1018
+		);
1019
+		if (! $addon instanceof EE_Addon) {
1020
+			throw new DomainException(
1021
+				sprintf(
1022
+					esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1023
+					self::$_settings[ $addon_name ]['class_name']
1024
+				)
1025
+			);
1026
+		}
1027
+		// setter inject dep map if required
1028
+		if ($addon->dependencyMap() === null) {
1029
+			$addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map'));
1030
+		}
1031
+		// setter inject domain if required
1032
+		EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1033
+
1034
+		$addon->set_name($addon_name);
1035
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1036
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1037
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1038
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1039
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1040
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
1041
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1042
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1043
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1044
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1045
+		do_action(
1046
+			'AHEE__EE_Register_Addon___load_and_init_addon_class',
1047
+			$addon,
1048
+			$addon_name,
1049
+			self::$_settings
1050
+		);
1051
+		// unfortunately this can't be hooked in upon construction,
1052
+		// because we don't have the plugin's mainfile path upon construction.
1053
+		register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1054
+		// call any additional admin_callback functions during load_admin_controller hook
1055
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1056
+			add_action(
1057
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
1058
+				[$addon, self::$_settings[ $addon_name ]['admin_callback']]
1059
+			);
1060
+		}
1061
+		return $addon;
1062
+	}
1063
+
1064
+
1065
+	/**
1066
+	 * @param string   $addon_name
1067
+	 * @param EE_Addon $addon
1068
+	 * @since   4.10.13.p
1069
+	 */
1070
+	private static function injectAddonDomain(string $addon_name, EE_Addon $addon)
1071
+	{
1072
+		if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1073
+			// using supplied Domain object
1074
+			$domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1075
+				? self::$_settings[ $addon_name ]['domain']
1076
+				: null;
1077
+			// or construct one using Domain FQCN
1078
+			if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1079
+				$domain = self::$loader->getShared(
1080
+					self::$_settings[ $addon_name ]['domain_fqcn'],
1081
+					[
1082
+						new EventEspresso\core\domain\values\FilePath(
1083
+							self::$_settings[ $addon_name ]['main_file_path']
1084
+						),
1085
+						EventEspresso\core\domain\values\Version::fromString(
1086
+							self::$_settings[ $addon_name ]['version']
1087
+						),
1088
+					]
1089
+				);
1090
+			}
1091
+			if ($domain instanceof DomainInterface) {
1092
+				$addon->setDomain($domain);
1093
+			}
1094
+		}
1095
+	}
1096
+
1097
+
1098
+	/**
1099
+	 * @return void
1100
+	 * @deprecated 5.0.0.p
1101
+	 */
1102
+	public static function load_pue_update()
1103
+	{
1104
+	}
1105
+
1106
+
1107
+	/**
1108
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1109
+	 *
1110
+	 * @return void
1111
+	 * @throws EE_Error
1112
+	 * @since 4.4.0
1113
+	 */
1114
+	public static function register_message_types()
1115
+	{
1116
+		foreach (self::$_settings as $settings) {
1117
+			if (! empty($settings['message_types'])) {
1118
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1119
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1120
+				}
1121
+			}
1122
+		}
1123
+	}
1124
+
1125
+
1126
+	private static function registerLicense($addon_name)
1127
+	{
1128
+		$addon_settings = self::$_settings[ $addon_name ] ?? [];
1129
+		if (empty($addon_settings)) {
1130
+			return;
1131
+		}
1132
+		$license_data = isset($addon_settings['license']) ? (array) $addon_settings['license'] : [];
1133
+		// copy known values from addon settings to license data if anything's missing
1134
+		$license_data += [
1135
+			'main_file_path'   => $addon_settings['main_file_path'] ?? '',
1136
+			'min_core_version' => $addon_settings['min_core_version'] ?? '',
1137
+			'plugin_id'        => 0, // no corresponding value in addon settings
1138
+			'plugin_slug'      => $addon_settings['plugin_slug'] ?? '',
1139
+			'version'          => $addon_settings['version'] ?? '',
1140
+		];
1141
+		EventEspresso\core\services\licensing\AddonLicense::register($addon_name, $license_data);
1142
+	}
1143
+
1144
+
1145
+	/**
1146
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1147
+	 *
1148
+	 * @param string $addon_name the name for the addon that was previously registered
1149
+	 * @throws DomainException
1150
+	 * @throws InvalidArgumentException
1151
+	 * @throws InvalidDataTypeException
1152
+	 * @throws InvalidInterfaceException
1153
+	 * @since    4.3.0
1154
+	 */
1155
+	public static function deregister(string $addon_name = '')
1156
+	{
1157
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1158
+			try {
1159
+				do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1160
+				$class_name = self::$_settings[ $addon_name ]['class_name'];
1161
+				if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1162
+					// setup DMS
1163
+					EE_Register_Data_Migration_Scripts::deregister($addon_name);
1164
+				}
1165
+				if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1166
+					// register admin page
1167
+					EE_Register_Admin_Page::deregister($addon_name);
1168
+				}
1169
+				if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1170
+					// add to list of modules to be registered
1171
+					EE_Register_Module::deregister($addon_name);
1172
+				}
1173
+				if (
1174
+					! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1175
+					|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1176
+				) {
1177
+					// add to list of shortcodes to be registered
1178
+					EE_Register_Shortcode::deregister($addon_name);
1179
+				}
1180
+				if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1181
+					// if config_class present let's register config.
1182
+					EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1183
+				}
1184
+				if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1185
+					// add to list of widgets to be registered
1186
+					EE_Register_Widget::deregister($addon_name);
1187
+				}
1188
+				if (
1189
+					! empty(self::$_settings[ $addon_name ]['model_paths'])
1190
+					|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1191
+				) {
1192
+					// add to list of shortcodes to be registered
1193
+					EE_Register_Model::deregister($addon_name);
1194
+				}
1195
+				if (
1196
+					! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1197
+					|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1198
+				) {
1199
+					// add to list of shortcodes to be registered
1200
+					EE_Register_Model_Extensions::deregister($addon_name);
1201
+				}
1202
+				if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1203
+					foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1204
+						EE_Register_Message_Type::deregister($message_type);
1205
+					}
1206
+				}
1207
+				// deregister capabilities for addon
1208
+				if (
1209
+					! empty(self::$_settings[ $addon_name ]['capabilities'])
1210
+					|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1211
+				) {
1212
+					EE_Register_Capabilities::deregister($addon_name);
1213
+				}
1214
+				// deregister custom_post_types for addon
1215
+				if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1216
+					EE_Register_CPT::deregister($addon_name);
1217
+				}
1218
+				if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1219
+					EE_Register_Payment_Method::deregister($addon_name);
1220
+				}
1221
+				$addon = EE_Registry::instance()->getAddon($class_name);
1222
+				if ($addon instanceof EE_Addon) {
1223
+					remove_action(
1224
+						'deactivate_' . $addon->get_main_plugin_file_basename(),
1225
+						[$addon, 'deactivation']
1226
+					);
1227
+					remove_action(
1228
+						'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1229
+						[$addon, 'initialize_db_if_no_migrations_required']
1230
+					);
1231
+					// remove `after_registration` call
1232
+					remove_action(
1233
+						'AHEE__EE_System__load_espresso_addons__complete',
1234
+						[$addon, 'after_registration'],
1235
+						999
1236
+					);
1237
+				}
1238
+				EE_Registry::instance()->removeAddon($class_name);
1239
+				LoaderFactory::getLoader()->remove($class_name);
1240
+			} catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1241
+				// the add-on was not yet registered in the registry,
1242
+				// so RegistryContainer::__get() throws this exception.
1243
+				// also no need to worry about this or log it,
1244
+				// it's ok to deregister an add-on before its registered in the registry
1245
+			} catch (Exception $e) {
1246
+				new ExceptionLogger($e);
1247
+			}
1248
+			unset(self::$_settings[ $addon_name ]);
1249
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1250
+		}
1251
+	}
1252
+
1253
+
1254
+	public static function reset(): void
1255
+	{
1256
+		EE_Register_Addon::$_settings = [];
1257
+	}
1258
+
1259
+
1260
+	public static function resetAll(): void
1261
+	{
1262
+		// EE_Register_Addon::reset();
1263
+		EE_Register_Admin_Page::reset();
1264
+		EE_Register_Capabilities::reset();
1265
+		EE_Register_Config::reset();
1266
+		EE_Register_CPT::reset();
1267
+		EE_Register_Data_Migration_Scripts::reset();
1268
+		EE_Register_Message_Type::reset();
1269
+		EE_Register_Messages_Shortcode_Library::reset();
1270
+		EE_Register_Messages_Template_Pack::reset();
1271
+		EE_Register_Messages_Template_Variations::reset();
1272
+		EE_Register_Model::reset();
1273
+		EE_Register_Model_Extensions::reset();
1274
+		EE_Register_Module::reset();
1275
+		EE_Register_Payment_Method::reset();
1276
+		EE_Register_Personal_Data_Eraser::reset();
1277
+		EE_Register_Personal_Data_Exporter::reset();
1278
+		EE_Register_Privacy_Policy::reset();
1279
+		EE_Register_Shortcode::reset();
1280
+		EE_Register_Widget::reset();
1281
+	}
1282 1282
 }
Please login to merge, or discard this patch.
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -75,15 +75,15 @@  discard block
 block discarded – undo
75 75
         // offsets:    0 . 1 . 2 . 3 . 4
76 76
         $version_parts = explode('.', $min_core_version);
77 77
         // check they specified the micro version (after 2nd period)
78
-        if (! isset($version_parts[2])) {
78
+        if ( ! isset($version_parts[2])) {
79 79
             $version_parts[2] = '0';
80 80
         }
81 81
         // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
82 82
         // soon we can assume that's 'rc', but this current version is 'alpha'
83
-        if (! isset($version_parts[3])) {
83
+        if ( ! isset($version_parts[3])) {
84 84
             $version_parts[3] = 'dev';
85 85
         }
86
-        if (! isset($version_parts[4])) {
86
+        if ( ! isset($version_parts[4])) {
87 87
             $version_parts[4] = '000';
88 88
         }
89 89
         return implode('.', $version_parts);
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
     public static function register(string $addon_name = '', array $setup_args = []): bool
261 261
     {
262 262
         // $addon_name = basename($addon_name);
263
-        if (! self::$loader instanceof LoaderInterface) {
263
+        if ( ! self::$loader instanceof LoaderInterface) {
264 264
             self::$loader = LoaderFactory::getLoader();
265 265
         }
266 266
         // make sure this was called in the right place!
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
         );
301 301
         // does this addon work with this version of core or WordPress ?
302 302
         // does this addon work with this version of core or WordPress ?
303
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
303
+        if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
304 304
             return false;
305 305
         }
306 306
         // register namespaces
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
             );
379 379
         }
380 380
         // check that addon has not already been registered with that name
381
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
381
+        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
382 382
             throw new EE_Error(
383 383
                 sprintf(
384 384
                     esc_html__(
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
         // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
411 411
         return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
412 412
             ? $class_name
413
-            : 'EE_' . $class_name;
413
+            : 'EE_'.$class_name;
414 414
     }
415 415
 
416 416
 
@@ -580,9 +580,9 @@  discard block
 block discarded – undo
580 580
         $incompatibility_message = '';
581 581
         // check whether this addon version is compatible with EE core
582 582
         if (
583
-            isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
583
+            isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
584 584
             && ! self::_meets_min_core_version_requirement(
585
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
585
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
586 586
                 $addon_settings['version']
587 587
             )
588 588
         ) {
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
                 ),
594 594
                 $addon_name,
595 595
                 '<br />',
596
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
596
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
597 597
                 '<span style="font-weight: bold; color: #D54E21;">',
598 598
                 '</span><br />'
599 599
             );
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
                 '</span><br />'
626 626
             );
627 627
         }
628
-        if (! empty($incompatibility_message)) {
628
+        if ( ! empty($incompatibility_message)) {
629 629
             // remove 'activate' from the REQUEST
630 630
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
631 631
             /** @var RequestInterface $request */
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
                 EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
637 637
             }
638 638
             unset($_GET['activate'], $_REQUEST['activate']);
639
-            if (! function_exists('deactivate_plugins')) {
640
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
639
+            if ( ! function_exists('deactivate_plugins')) {
640
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
641 641
             }
642 642
             deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
643 643
             // BAIL FROM THE ADDON REGISTRATION PROCESS
@@ -687,12 +687,12 @@  discard block
 block discarded – undo
687 687
             // to find if THIS is the addon that was activated, just check if we have already registered it or not
688 688
             // (as the newly-activated addon wasn't around the first time addons were registered).
689 689
             if (
690
-                ! isset(self::$_settings[ $addon_name ])
691
-                || (isset(self::$_settings[ $addon_name ])
692
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
690
+                ! isset(self::$_settings[$addon_name])
691
+                || (isset(self::$_settings[$addon_name])
692
+                    && ! isset(self::$_settings[$addon_name]['class_name'])
693 693
                 )
694 694
             ) {
695
-                self::$_settings[ $addon_name ] = $addon_settings;
695
+                self::$_settings[$addon_name] = $addon_settings;
696 696
                 $addon                          = self::_load_and_init_addon_class($addon_name);
697 697
                 $addon->set_activation_indicator_option();
698 698
                 // dont bother setting up the rest of the addon.
@@ -701,10 +701,10 @@  discard block
 block discarded – undo
701 701
             return true;
702 702
         }
703 703
         // make sure addon settings are set correctly without overwriting anything existing
704
-        if (isset(self::$_settings[ $addon_name ])) {
705
-            self::$_settings[ $addon_name ] += $addon_settings;
704
+        if (isset(self::$_settings[$addon_name])) {
705
+            self::$_settings[$addon_name] += $addon_settings;
706 706
         } else {
707
-            self::$_settings[ $addon_name ] = $addon_settings;
707
+            self::$_settings[$addon_name] = $addon_settings;
708 708
         }
709 709
         return false;
710 710
     }
@@ -717,13 +717,13 @@  discard block
 block discarded – undo
717 717
      */
718 718
     private static function _setup_autoloaders(string $addon_name)
719 719
     {
720
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
720
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
721 721
             // setup autoloader for single file
722
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
722
+            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
723 723
         }
724 724
         // setup autoloaders for folders
725
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
726
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
725
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
726
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
727 727
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
728 728
             }
729 729
         }
@@ -741,27 +741,27 @@  discard block
 block discarded – undo
741 741
     {
742 742
         // register new models
743 743
         if (
744
-            ! empty(self::$_settings[ $addon_name ]['model_paths'])
745
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
744
+            ! empty(self::$_settings[$addon_name]['model_paths'])
745
+            || ! empty(self::$_settings[$addon_name]['class_paths'])
746 746
         ) {
747 747
             EE_Register_Model::register(
748 748
                 $addon_name,
749 749
                 [
750
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
751
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
750
+                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
751
+                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
752 752
                 ]
753 753
             );
754 754
         }
755 755
         // register model extensions
756 756
         if (
757
-            ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
758
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
757
+            ! empty(self::$_settings[$addon_name]['model_extension_paths'])
758
+            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
759 759
         ) {
760 760
             EE_Register_Model_Extensions::register(
761 761
                 $addon_name,
762 762
                 [
763
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
764
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
763
+                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
764
+                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
765 765
                 ]
766 766
             );
767 767
         }
@@ -776,10 +776,10 @@  discard block
 block discarded – undo
776 776
     private static function _register_data_migration_scripts(string $addon_name)
777 777
     {
778 778
         // setup DMS
779
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
779
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
780 780
             EE_Register_Data_Migration_Scripts::register(
781 781
                 $addon_name,
782
-                ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
782
+                ['dms_paths' => self::$_settings[$addon_name]['dms_paths']]
783 783
             );
784 784
         }
785 785
     }
@@ -793,12 +793,12 @@  discard block
 block discarded – undo
793 793
     private static function _register_config(string $addon_name)
794 794
     {
795 795
         // if config_class is present let's register config.
796
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
796
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
797 797
             EE_Register_Config::register(
798
-                self::$_settings[ $addon_name ]['config_class'],
798
+                self::$_settings[$addon_name]['config_class'],
799 799
                 [
800
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
801
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
800
+                    'config_section' => self::$_settings[$addon_name]['config_section'],
801
+                    'config_name'    => self::$_settings[$addon_name]['config_name'],
802 802
                 ]
803 803
             );
804 804
         }
@@ -812,10 +812,10 @@  discard block
 block discarded – undo
812 812
      */
813 813
     private static function _register_admin_pages(string $addon_name)
814 814
     {
815
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
815
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
816 816
             EE_Register_Admin_Page::register(
817 817
                 $addon_name,
818
-                ['page_path' => self::$_settings[ $addon_name ]['admin_path']]
818
+                ['page_path' => self::$_settings[$addon_name]['admin_path']]
819 819
             );
820 820
         }
821 821
     }
@@ -828,10 +828,10 @@  discard block
 block discarded – undo
828 828
      */
829 829
     private static function _register_modules(string $addon_name)
830 830
     {
831
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
831
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
832 832
             EE_Register_Module::register(
833 833
                 $addon_name,
834
-                ['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
834
+                ['module_paths' => self::$_settings[$addon_name]['module_paths']]
835 835
             );
836 836
         }
837 837
     }
@@ -845,14 +845,14 @@  discard block
 block discarded – undo
845 845
     private static function _register_shortcodes(string $addon_name)
846 846
     {
847 847
         if (
848
-            ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
849
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
848
+            ! empty(self::$_settings[$addon_name]['shortcode_paths'])
849
+            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
850 850
         ) {
851 851
             EE_Register_Shortcode::register(
852 852
                 $addon_name,
853 853
                 [
854
-                    'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
855
-                    'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
854
+                    'shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'] ?? [],
855
+                    'shortcode_fqcns' => self::$_settings[$addon_name]['shortcode_fqcns'] ?? [],
856 856
                 ]
857 857
             );
858 858
         }
@@ -866,10 +866,10 @@  discard block
 block discarded – undo
866 866
      */
867 867
     private static function _register_widgets(string $addon_name)
868 868
     {
869
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
869
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
870 870
             EE_Register_Widget::register(
871 871
                 $addon_name,
872
-                ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
872
+                ['widget_paths' => self::$_settings[$addon_name]['widget_paths']]
873 873
             );
874 874
         }
875 875
     }
@@ -882,12 +882,12 @@  discard block
 block discarded – undo
882 882
      */
883 883
     private static function _register_capabilities(string $addon_name)
884 884
     {
885
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
885
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
886 886
             EE_Register_Capabilities::register(
887 887
                 $addon_name,
888 888
                 [
889
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
890
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
889
+                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
890
+                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
891 891
                 ]
892 892
             );
893 893
         }
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
      */
901 901
     private static function _register_message_types(string $addon_name)
902 902
     {
903
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
903
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
904 904
             add_action(
905 905
                 'EE_Brewing_Regular___messages_caf',
906 906
                 ['EE_Register_Addon', 'register_message_types']
@@ -917,15 +917,15 @@  discard block
 block discarded – undo
917 917
     private static function _register_custom_post_types(string $addon_name)
918 918
     {
919 919
         if (
920
-            ! empty(self::$_settings[ $addon_name ]['custom_post_types'])
921
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
920
+            ! empty(self::$_settings[$addon_name]['custom_post_types'])
921
+            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
922 922
         ) {
923 923
             EE_Register_CPT::register(
924 924
                 $addon_name,
925 925
                 [
926
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
927
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
928
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
926
+                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
927
+                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
928
+                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
929 929
                 ]
930 930
             );
931 931
         }
@@ -943,10 +943,10 @@  discard block
 block discarded – undo
943 943
      */
944 944
     private static function _register_payment_methods(string $addon_name)
945 945
     {
946
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
946
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
947 947
             EE_Register_Payment_Method::register(
948 948
                 $addon_name,
949
-                ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
949
+                ['payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']]
950 950
             );
951 951
         }
952 952
     }
@@ -962,10 +962,10 @@  discard block
 block discarded – undo
962 962
      */
963 963
     private static function registerPrivacyPolicies(string $addon_name)
964 964
     {
965
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
965
+        if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) {
966 966
             EE_Register_Privacy_Policy::register(
967 967
                 $addon_name,
968
-                self::$_settings[ $addon_name ]['privacy_policies']
968
+                self::$_settings[$addon_name]['privacy_policies']
969 969
             );
970 970
         }
971 971
     }
@@ -977,10 +977,10 @@  discard block
 block discarded – undo
977 977
      */
978 978
     private static function registerPersonalDataExporters(string $addon_name)
979 979
     {
980
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
980
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) {
981 981
             EE_Register_Personal_Data_Eraser::register(
982 982
                 $addon_name,
983
-                self::$_settings[ $addon_name ]['personal_data_exporters']
983
+                self::$_settings[$addon_name]['personal_data_exporters']
984 984
             );
985 985
         }
986 986
     }
@@ -992,10 +992,10 @@  discard block
 block discarded – undo
992 992
      */
993 993
     private static function registerPersonalDataErasers(string $addon_name)
994 994
     {
995
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
995
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) {
996 996
             EE_Register_Personal_Data_Eraser::register(
997 997
                 $addon_name,
998
-                self::$_settings[ $addon_name ]['personal_data_erasers']
998
+                self::$_settings[$addon_name]['personal_data_erasers']
999 999
             );
1000 1000
         }
1001 1001
     }
@@ -1013,14 +1013,14 @@  discard block
 block discarded – undo
1013 1013
     private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1014 1014
     {
1015 1015
         $addon = self::$loader->getShared(
1016
-            self::$_settings[ $addon_name ]['class_name'],
1016
+            self::$_settings[$addon_name]['class_name'],
1017 1017
             ['EE_Registry::create(addon)' => true]
1018 1018
         );
1019
-        if (! $addon instanceof EE_Addon) {
1019
+        if ( ! $addon instanceof EE_Addon) {
1020 1020
             throw new DomainException(
1021 1021
                 sprintf(
1022 1022
                     esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1023
-                    self::$_settings[ $addon_name ]['class_name']
1023
+                    self::$_settings[$addon_name]['class_name']
1024 1024
                 )
1025 1025
             );
1026 1026
         }
@@ -1032,16 +1032,16 @@  discard block
 block discarded – undo
1032 1032
         EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1033 1033
 
1034 1034
         $addon->set_name($addon_name);
1035
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1036
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1037
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1038
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1039
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1040
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1041
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1042
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1043
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1044
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1035
+        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
1036
+        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
1037
+        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
1038
+        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
1039
+        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
1040
+        $addon->set_version(self::$_settings[$addon_name]['version']);
1041
+        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
1042
+        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
1043
+        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
1044
+        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
1045 1045
         do_action(
1046 1046
             'AHEE__EE_Register_Addon___load_and_init_addon_class',
1047 1047
             $addon,
@@ -1052,10 +1052,10 @@  discard block
 block discarded – undo
1052 1052
         // because we don't have the plugin's mainfile path upon construction.
1053 1053
         register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1054 1054
         // call any additional admin_callback functions during load_admin_controller hook
1055
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1055
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
1056 1056
             add_action(
1057 1057
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
1058
-                [$addon, self::$_settings[ $addon_name ]['admin_callback']]
1058
+                [$addon, self::$_settings[$addon_name]['admin_callback']]
1059 1059
             );
1060 1060
         }
1061 1061
         return $addon;
@@ -1071,19 +1071,19 @@  discard block
 block discarded – undo
1071 1071
     {
1072 1072
         if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1073 1073
             // using supplied Domain object
1074
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1075
-                ? self::$_settings[ $addon_name ]['domain']
1074
+            $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface
1075
+                ? self::$_settings[$addon_name]['domain']
1076 1076
                 : null;
1077 1077
             // or construct one using Domain FQCN
1078
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1078
+            if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') {
1079 1079
                 $domain = self::$loader->getShared(
1080
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1080
+                    self::$_settings[$addon_name]['domain_fqcn'],
1081 1081
                     [
1082 1082
                         new EventEspresso\core\domain\values\FilePath(
1083
-                            self::$_settings[ $addon_name ]['main_file_path']
1083
+                            self::$_settings[$addon_name]['main_file_path']
1084 1084
                         ),
1085 1085
                         EventEspresso\core\domain\values\Version::fromString(
1086
-                            self::$_settings[ $addon_name ]['version']
1086
+                            self::$_settings[$addon_name]['version']
1087 1087
                         ),
1088 1088
                     ]
1089 1089
                 );
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
     public static function register_message_types()
1115 1115
     {
1116 1116
         foreach (self::$_settings as $settings) {
1117
-            if (! empty($settings['message_types'])) {
1117
+            if ( ! empty($settings['message_types'])) {
1118 1118
                 foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1119 1119
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
1120 1120
                 }
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 
1126 1126
     private static function registerLicense($addon_name)
1127 1127
     {
1128
-        $addon_settings = self::$_settings[ $addon_name ] ?? [];
1128
+        $addon_settings = self::$_settings[$addon_name] ?? [];
1129 1129
         if (empty($addon_settings)) {
1130 1130
             return;
1131 1131
         }
@@ -1154,74 +1154,74 @@  discard block
 block discarded – undo
1154 1154
      */
1155 1155
     public static function deregister(string $addon_name = '')
1156 1156
     {
1157
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1157
+        if (isset(self::$_settings[$addon_name]['class_name'])) {
1158 1158
             try {
1159 1159
                 do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1160
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1161
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1160
+                $class_name = self::$_settings[$addon_name]['class_name'];
1161
+                if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1162 1162
                     // setup DMS
1163 1163
                     EE_Register_Data_Migration_Scripts::deregister($addon_name);
1164 1164
                 }
1165
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1165
+                if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1166 1166
                     // register admin page
1167 1167
                     EE_Register_Admin_Page::deregister($addon_name);
1168 1168
                 }
1169
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1169
+                if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1170 1170
                     // add to list of modules to be registered
1171 1171
                     EE_Register_Module::deregister($addon_name);
1172 1172
                 }
1173 1173
                 if (
1174
-                    ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1175
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1174
+                    ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1175
+                    || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1176 1176
                 ) {
1177 1177
                     // add to list of shortcodes to be registered
1178 1178
                     EE_Register_Shortcode::deregister($addon_name);
1179 1179
                 }
1180
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1180
+                if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1181 1181
                     // if config_class present let's register config.
1182
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1182
+                    EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1183 1183
                 }
1184
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1184
+                if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1185 1185
                     // add to list of widgets to be registered
1186 1186
                     EE_Register_Widget::deregister($addon_name);
1187 1187
                 }
1188 1188
                 if (
1189
-                    ! empty(self::$_settings[ $addon_name ]['model_paths'])
1190
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1189
+                    ! empty(self::$_settings[$addon_name]['model_paths'])
1190
+                    || ! empty(self::$_settings[$addon_name]['class_paths'])
1191 1191
                 ) {
1192 1192
                     // add to list of shortcodes to be registered
1193 1193
                     EE_Register_Model::deregister($addon_name);
1194 1194
                 }
1195 1195
                 if (
1196
-                    ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1197
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1196
+                    ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1197
+                    || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1198 1198
                 ) {
1199 1199
                     // add to list of shortcodes to be registered
1200 1200
                     EE_Register_Model_Extensions::deregister($addon_name);
1201 1201
                 }
1202
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1203
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1202
+                if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1203
+                    foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1204 1204
                         EE_Register_Message_Type::deregister($message_type);
1205 1205
                     }
1206 1206
                 }
1207 1207
                 // deregister capabilities for addon
1208 1208
                 if (
1209
-                    ! empty(self::$_settings[ $addon_name ]['capabilities'])
1210
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1209
+                    ! empty(self::$_settings[$addon_name]['capabilities'])
1210
+                    || ! empty(self::$_settings[$addon_name]['capability_maps'])
1211 1211
                 ) {
1212 1212
                     EE_Register_Capabilities::deregister($addon_name);
1213 1213
                 }
1214 1214
                 // deregister custom_post_types for addon
1215
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1215
+                if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1216 1216
                     EE_Register_CPT::deregister($addon_name);
1217 1217
                 }
1218
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1218
+                if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1219 1219
                     EE_Register_Payment_Method::deregister($addon_name);
1220 1220
                 }
1221 1221
                 $addon = EE_Registry::instance()->getAddon($class_name);
1222 1222
                 if ($addon instanceof EE_Addon) {
1223 1223
                     remove_action(
1224
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1224
+                        'deactivate_'.$addon->get_main_plugin_file_basename(),
1225 1225
                         [$addon, 'deactivation']
1226 1226
                     );
1227 1227
                     remove_action(
@@ -1245,7 +1245,7 @@  discard block
 block discarded – undo
1245 1245
             } catch (Exception $e) {
1246 1246
                 new ExceptionLogger($e);
1247 1247
             }
1248
-            unset(self::$_settings[ $addon_name ]);
1248
+            unset(self::$_settings[$addon_name]);
1249 1249
             do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1250 1250
         }
1251 1251
     }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Line_Item_Shortcodes.lib.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -16,65 +16,65 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Line_Item_Shortcodes extends EE_Shortcodes
18 18
 {
19
-    protected function _init_props()
20
-    {
21
-        $this->label = esc_html__('Line Item Shortcodes', 'event_espresso');
22
-        $this->description = esc_html__('All shortcodes specific to line items', 'event_espresso');
23
-        $this->_shortcodes = array(
24
-            '[LINE_ITEM_NAME]' => esc_html__('Outputs the line item name.', 'event_espresso'),
25
-            '[LINE_ITEM_DESCRIPTION]' => esc_html__('Outputs a the description for the line item.', 'event_espresso'),
26
-            '[LINE_ITEM_QUANTITY]' => esc_html__('Outputs the quantity for this line item.', 'event_espresso'),
27
-            '[LINE_ITEM_AMOUNT]' => esc_html__(
28
-                'This will either output the unit price for a line item if its not a percent, or the percent of the line item (if it is percent).',
29
-                'event_espresso'
30
-            ),
31
-            '[LINE_ITEM_TOTAL]' => esc_html__('This outputs the line item total.', 'event_espresso'),
32
-            '[LINE_ITEM_TAXABLE_*]' => esc_html__(
33
-                'This attribute type shortcode allows users to indicate what to output if a line item is taxable or not.  One can use the key "symbol=" with the shortcode to indicate what they\'d like to represent a taxable line item.  So doing something like <code>[LINE_ITEM_TAXABLE_* symbol="*"]</code> means that when the line item is parsed, if it\'s taxable the "*" symbol will be returned.  The default symbol if no attribute is included is the "*" symbol.',
34
-                'event_espresso'
35
-            ),
36
-        );
37
-    }
19
+	protected function _init_props()
20
+	{
21
+		$this->label = esc_html__('Line Item Shortcodes', 'event_espresso');
22
+		$this->description = esc_html__('All shortcodes specific to line items', 'event_espresso');
23
+		$this->_shortcodes = array(
24
+			'[LINE_ITEM_NAME]' => esc_html__('Outputs the line item name.', 'event_espresso'),
25
+			'[LINE_ITEM_DESCRIPTION]' => esc_html__('Outputs a the description for the line item.', 'event_espresso'),
26
+			'[LINE_ITEM_QUANTITY]' => esc_html__('Outputs the quantity for this line item.', 'event_espresso'),
27
+			'[LINE_ITEM_AMOUNT]' => esc_html__(
28
+				'This will either output the unit price for a line item if its not a percent, or the percent of the line item (if it is percent).',
29
+				'event_espresso'
30
+			),
31
+			'[LINE_ITEM_TOTAL]' => esc_html__('This outputs the line item total.', 'event_espresso'),
32
+			'[LINE_ITEM_TAXABLE_*]' => esc_html__(
33
+				'This attribute type shortcode allows users to indicate what to output if a line item is taxable or not.  One can use the key "symbol=" with the shortcode to indicate what they\'d like to represent a taxable line item.  So doing something like <code>[LINE_ITEM_TAXABLE_* symbol="*"]</code> means that when the line item is parsed, if it\'s taxable the "*" symbol will be returned.  The default symbol if no attribute is included is the "*" symbol.',
34
+				'event_espresso'
35
+			),
36
+		);
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * @param string $shortcode
42
-     * @throws ReflectionException
43
-     * @throws EE_Error
44
-     */
45
-    protected function _parser($shortcode)
46
-    {
47
-        // ensure that the incoming object IS a line item.  If it isn't then bail early.
48
-        if (! $this->_data instanceof EE_Line_Item) {
49
-            return '';
50
-        }
40
+	/**
41
+	 * @param string $shortcode
42
+	 * @throws ReflectionException
43
+	 * @throws EE_Error
44
+	 */
45
+	protected function _parser($shortcode)
46
+	{
47
+		// ensure that the incoming object IS a line item.  If it isn't then bail early.
48
+		if (! $this->_data instanceof EE_Line_Item) {
49
+			return '';
50
+		}
51 51
 
52
-        $line_item = $this->_data;
52
+		$line_item = $this->_data;
53 53
 
54
-        switch ($shortcode) {
55
-            case '[LINE_ITEM_NAME]':
56
-                return $line_item->name();
54
+		switch ($shortcode) {
55
+			case '[LINE_ITEM_NAME]':
56
+				return $line_item->name();
57 57
 
58
-            case '[LINE_ITEM_DESCRIPTION]':
59
-                return $line_item->desc();
58
+			case '[LINE_ITEM_DESCRIPTION]':
59
+				return $line_item->desc();
60 60
 
61
-            case '[LINE_ITEM_QUANTITY]':
62
-                return $line_item->quantity();
61
+			case '[LINE_ITEM_QUANTITY]':
62
+				return $line_item->quantity();
63 63
 
64
-            case '[LINE_ITEM_AMOUNT]':
65
-                return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
64
+			case '[LINE_ITEM_AMOUNT]':
65
+				return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
66 66
 
67
-            case '[LINE_ITEM_TOTAL]':
68
-                return $line_item->total_no_code();
69
-        }
67
+			case '[LINE_ITEM_TOTAL]':
68
+				return $line_item->total_no_code();
69
+		}
70 70
 
71
-        if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) {
72
-            $attrs = $this->_get_shortcode_attrs($shortcode);
73
-            if ($line_item->is_taxable()) {
74
-                return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*';
75
-            }
76
-        }
71
+		if (strpos($shortcode, '[LINE_ITEM_TAXABLE_*') !== false) {
72
+			$attrs = $this->_get_shortcode_attrs($shortcode);
73
+			if ($line_item->is_taxable()) {
74
+				return ! empty($attrs['symbol']) ? $attrs['symbol'] : '*';
75
+			}
76
+		}
77 77
 
78
-        return '';
79
-    }
78
+		return '';
79
+	}
80 80
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     protected function _parser($shortcode)
46 46
     {
47 47
         // ensure that the incoming object IS a line item.  If it isn't then bail early.
48
-        if (! $this->_data instanceof EE_Line_Item) {
48
+        if ( ! $this->_data instanceof EE_Line_Item) {
49 49
             return '';
50 50
         }
51 51
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
                 return $line_item->quantity();
63 63
 
64 64
             case '[LINE_ITEM_AMOUNT]':
65
-                return $line_item->is_percent() ? $line_item->percent() . '%' : $line_item->unit_price_no_code();
65
+                return $line_item->is_percent() ? $line_item->percent().'%' : $line_item->unit_price_no_code();
66 66
 
67 67
             case '[LINE_ITEM_TOTAL]':
68 68
                 return $line_item->total_no_code();
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Event_Meta_Shortcodes.lib.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,43 +30,43 @@
 block discarded – undo
30 30
  */
31 31
 class EE_Event_Meta_Shortcodes extends EE_Shortcodes
32 32
 {
33
-    public function __construct()
34
-    {
35
-        parent::__construct();
36
-    }
33
+	public function __construct()
34
+	{
35
+		parent::__construct();
36
+	}
37 37
 
38 38
 
39
-    protected function _init_props()
40
-    {
41
-        $this->label = esc_html__('Event Meta Shortcodes', 'event_espresso');
42
-        $this->description = esc_html__('All shortcodes related to Event Meta data', 'event_espresso');
43
-        $this->_shortcodes = array();
44
-    }
39
+	protected function _init_props()
40
+	{
41
+		$this->label = esc_html__('Event Meta Shortcodes', 'event_espresso');
42
+		$this->description = esc_html__('All shortcodes related to Event Meta data', 'event_espresso');
43
+		$this->_shortcodes = array();
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * We have to overload the parent parser method because of the dynamic nature of custom event meta
49
-     *
50
-     * @param  string      $shortcode Incoming shortcode
51
-     * @param array|object $data      incoming data object/array
52
-     * @return string            parsed code.
53
-     */
54
-    public function parser(string $shortcode, $data, $extra_data = []): string
55
-    {
47
+	/**
48
+	 * We have to overload the parent parser method because of the dynamic nature of custom event meta
49
+	 *
50
+	 * @param  string      $shortcode Incoming shortcode
51
+	 * @param array|object $data      incoming data object/array
52
+	 * @return string            parsed code.
53
+	 */
54
+	public function parser(string $shortcode, $data, $extra_data = []): string
55
+	{
56 56
 
57
-        // all shortcodes will be checked in the post_meta table (assuming the shortcode matches the post_meta key);
58
-        if (empty($this->_data['ID'])) {
59
-            return '';
60
-        } // need the event id to do anything!
57
+		// all shortcodes will be checked in the post_meta table (assuming the shortcode matches the post_meta key);
58
+		if (empty($this->_data['ID'])) {
59
+			return '';
60
+		} // need the event id to do anything!
61 61
 
62
-        $meta = get_post_meta($this->_data['ID'], $shortcode, true);
62
+		$meta = get_post_meta($this->_data['ID'], $shortcode, true);
63 63
 
64
-        return ! empty($meta) ? $meta : '';
65
-    }
64
+		return ! empty($meta) ? $meta : '';
65
+	}
66 66
 
67 67
 
68
-    protected function _parser($shortcode)
69
-    {
70
-        return '';
71
-    }
68
+	protected function _parser($shortcode)
69
+	{
70
+		return '';
71
+	}
72 72
 }
Please login to merge, or discard this patch.