Completed
Branch FET-9856-direct-instantiation (142681)
by
unknown
108:29 queued 96:36
created
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 patches
Indentation   +1169 added lines, -1169 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,1173 +17,1173 @@  discard block
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * This is used to hold the reports template data which is setup early in the request.
22
-     *
23
-     * @type array
24
-     */
25
-    protected $_reports_template_data = array();
26
-
27
-
28
-
29
-    /**
30
-     * Extend_Registrations_Admin_Page constructor.
31
-     *
32
-     * @param bool $routing
33
-     */
34
-    public function __construct($routing = true)
35
-    {
36
-        parent::__construct($routing);
37
-        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
41
-        }
42
-    }
43
-
44
-
45
-
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
-        // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
54
-        // 	? $this->_req_data['post'] : $att_id;
55
-        $new_page_routes = array(
56
-            'reports'                  => array(
57
-                'func'       => '_registration_reports',
58
-                'capability' => 'ee_read_registrations',
59
-            ),
60
-            'registration_checkins'    => array(
61
-                'func'       => '_registration_checkin_list_table',
62
-                'capability' => 'ee_read_checkins',
63
-            ),
64
-            'newsletter_selected_send' => array(
65
-                'func'       => '_newsletter_selected_send',
66
-                'noheader'   => true,
67
-                'capability' => 'ee_send_message',
68
-            ),
69
-            'delete_checkin_rows'      => array(
70
-                'func'       => '_delete_checkin_rows',
71
-                'noheader'   => true,
72
-                'capability' => 'ee_delete_checkins',
73
-            ),
74
-            'delete_checkin_row'       => array(
75
-                'func'       => '_delete_checkin_row',
76
-                'noheader'   => true,
77
-                'capability' => 'ee_delete_checkin',
78
-                'obj_id'     => $reg_id,
79
-            ),
80
-            'toggle_checkin_status'    => array(
81
-                'func'       => '_toggle_checkin_status',
82
-                'noheader'   => true,
83
-                'capability' => 'ee_edit_checkin',
84
-                'obj_id'     => $reg_id,
85
-            ),
86
-            'event_registrations'      => array(
87
-                'func'       => '_event_registrations_list_table',
88
-                'capability' => 'ee_read_checkins',
89
-            ),
90
-            'registrations_checkin_report' => array(
91
-                'func'       => '_registrations_checkin_report',
92
-                'noheader'   => true,
93
-                'capability' => 'ee_read_registrations',
94
-            ),
95
-        );
96
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
97
-        $new_page_config = array(
98
-            'reports'               => array(
99
-                'nav'           => array(
100
-                    'label' => __('Reports', 'event_espresso'),
101
-                    'order' => 30,
102
-                ),
103
-                'help_tabs'     => array(
104
-                    'registrations_reports_help_tab' => array(
105
-                        'title'    => __('Registration Reports', 'event_espresso'),
106
-                        'filename' => 'registrations_reports',
107
-                    ),
108
-                ),
109
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
110
-                'require_nonce' => false,
111
-            ),
112
-            'event_registrations'   => array(
113
-                'nav'           => array(
114
-                    'label'      => __('Event Check-In', 'event_espresso'),
115
-                    'order'      => 10,
116
-                    'persistent' => true,
117
-                ),
118
-                'help_tabs'     => array(
119
-                    'registrations_event_checkin_help_tab'                       => array(
120
-                        'title'    => __('Registrations Event Check-In', 'event_espresso'),
121
-                        'filename' => 'registrations_event_checkin',
122
-                    ),
123
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
124
-                        'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
125
-                        'filename' => 'registrations_event_checkin_table_column_headings',
126
-                    ),
127
-                    'registrations_event_checkin_filters_help_tab'               => array(
128
-                        'title'    => __('Event Check-In Filters', 'event_espresso'),
129
-                        'filename' => 'registrations_event_checkin_filters',
130
-                    ),
131
-                    'registrations_event_checkin_views_help_tab'                 => array(
132
-                        'title'    => __('Event Check-In Views', 'event_espresso'),
133
-                        'filename' => 'registrations_event_checkin_views',
134
-                    ),
135
-                    'registrations_event_checkin_other_help_tab'                 => array(
136
-                        'title'    => __('Event Check-In Other', 'event_espresso'),
137
-                        'filename' => 'registrations_event_checkin_other',
138
-                    ),
139
-                ),
140
-                'help_tour'     => array('Event_Checkin_Help_Tour'),
141
-                'qtips'         => array('Registration_List_Table_Tips'),
142
-                'list_table'    => 'EE_Event_Registrations_List_Table',
143
-                'metaboxes'     => array(),
144
-                'require_nonce' => false,
145
-            ),
146
-            'registration_checkins' => array(
147
-                'nav'           => array(
148
-                    'label'      => __('Check-In Records', 'event_espresso'),
149
-                    'order'      => 15,
150
-                    'persistent' => false,
151
-                ),
152
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
153
-                //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
154
-                'metaboxes'     => array(),
155
-                'require_nonce' => false,
156
-            ),
157
-        );
158
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
159
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
-    }
162
-
163
-
164
-
165
-    protected function _ajax_hooks()
166
-    {
167
-        parent::_ajax_hooks();
168
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
169
-    }
170
-
171
-
172
-
173
-    public function load_scripts_styles()
174
-    {
175
-        parent::load_scripts_styles();
176
-        //if newsletter message type is active then let's add filter and load js for it.
177
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
178
-            //enqueue newsletter js
179
-            wp_enqueue_script(
180
-                'ee-newsletter-trigger',
181
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
182
-                array('ee-dialog'),
183
-                EVENT_ESPRESSO_VERSION,
184
-                true
185
-            );
186
-            wp_enqueue_style(
187
-                'ee-newsletter-trigger-css',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
189
-                array(),
190
-                EVENT_ESPRESSO_VERSION
191
-            );
192
-            //hook in buttons for newsletter message type trigger.
193
-            add_action(
194
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
195
-                array($this, 'add_newsletter_action_buttons'),
196
-                10
197
-            );
198
-        }
199
-    }
200
-
201
-
202
-
203
-    public function load_scripts_styles_reports()
204
-    {
205
-        wp_register_script(
206
-            'ee-reg-reports-js',
207
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
208
-            array('google-charts'),
209
-            EVENT_ESPRESSO_VERSION,
210
-            true
211
-        );
212
-        wp_enqueue_script('ee-reg-reports-js');
213
-        $this->_registration_reports_js_setup();
214
-    }
215
-
216
-
217
-
218
-    protected function _add_screen_options_event_registrations()
219
-    {
220
-        $this->_per_page_screen_option();
221
-    }
222
-
223
-
224
-
225
-    protected function _add_screen_options_registration_checkins()
226
-    {
227
-        $page_title = $this->_admin_page_title;
228
-        $this->_admin_page_title = __('Check-In Records', 'event_espresso');
229
-        $this->_per_page_screen_option();
230
-        $this->_admin_page_title = $page_title;
231
-    }
232
-
233
-
234
-
235
-    protected function _set_list_table_views_event_registrations()
236
-    {
237
-        $this->_views = array(
238
-            'all' => array(
239
-                'slug'        => 'all',
240
-                'label'       => __('All', 'event_espresso'),
241
-                'count'       => 0,
242
-                'bulk_action' => ! isset($this->_req_data['event_id'])
243
-                    ? array()
244
-                    : array(
245
-                        'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
246
-                        //'trash_registrations' => __('Trash Registrations', 'event_espresso')
247
-                    ),
248
-            ),
249
-        );
250
-    }
251
-
252
-
253
-
254
-    protected function _set_list_table_views_registration_checkins()
255
-    {
256
-        $this->_views = array(
257
-            'all' => array(
258
-                'slug'        => 'all',
259
-                'label'       => __('All', 'event_espresso'),
260
-                'count'       => 0,
261
-                'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
262
-            ),
263
-        );
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * callback for ajax action.
270
-     *
271
-     * @since 4.3.0
272
-     * @return void (JSON)
273
-     * @throws \EE_Error
274
-     */
275
-    public function get_newsletter_form_content()
276
-    {
277
-        //do a nonce check cause we're not coming in from an normal route here.
278
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
279
-            $this->_req_data['get_newsletter_form_content_nonce']
280
-        ) : '';
281
-        $nonce_ref = 'get_newsletter_form_content_nonce';
282
-        $this->_verify_nonce($nonce, $nonce_ref);
283
-        //let's get the mtp for the incoming MTP_ ID
284
-        if ( ! isset($this->_req_data['GRP_ID'])) {
285
-            EE_Error::add_error(
286
-                __(
287
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
288
-                    'event_espresso'
289
-                ),
290
-                __FILE__,
291
-                __FUNCTION__,
292
-                __LINE__
293
-            );
294
-            $this->_template_args['success'] = false;
295
-            $this->_template_args['error'] = true;
296
-            $this->_return_json();
297
-        }
298
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
299
-        if ( ! $MTPG instanceof EE_Message_Template_Group) {
300
-            EE_Error::add_error(
301
-                sprintf(
302
-                    __(
303
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
304
-                        'event_espresso'
305
-                    ),
306
-                    $this->_req_data['GRP_ID']
307
-                ),
308
-                __FILE__,
309
-                __FUNCTION__,
310
-                __LINE__
311
-            );
312
-            $this->_template_args['success'] = false;
313
-            $this->_template_args['error'] = true;
314
-            $this->_return_json();
315
-        }
316
-        $MTPs = $MTPG->context_templates();
317
-        $MTPs = $MTPs['attendee'];
318
-        $template_fields = array();
319
-        /** @var EE_Message_Template $MTP */
320
-        foreach ($MTPs as $MTP) {
321
-            $field = $MTP->get('MTP_template_field');
322
-            if ($field === 'content') {
323
-                $content = $MTP->get('MTP_content');
324
-                if ( ! empty($content['newsletter_content'])) {
325
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
326
-                }
327
-                continue;
328
-            }
329
-            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
330
-        }
331
-        $this->_template_args['success'] = true;
332
-        $this->_template_args['error'] = false;
333
-        $this->_template_args['data'] = array(
334
-            'batch_message_from'    => isset($template_fields['from'])
335
-                ? $template_fields['from']
336
-                : '',
337
-            'batch_message_subject' => isset($template_fields['subject'])
338
-                ? $template_fields['subject']
339
-                : '',
340
-            'batch_message_content' => isset($template_fields['newsletter_content'])
341
-                ? $template_fields['newsletter_content']
342
-                : '',
343
-        );
344
-        $this->_return_json();
345
-    }
346
-
347
-
348
-
349
-    /**
350
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
351
-     *
352
-     * @since 4.3.0
353
-     * @param EE_Admin_List_Table $list_table
354
-     * @return void
355
-     */
356
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
357
-    {
358
-        if ( ! EE_Registry::instance()->CAP->current_user_can(
359
-            'ee_send_message',
360
-            'espresso_registrations_newsletter_selected_send'
361
-        )
362
-        ) {
363
-            return;
364
-        }
365
-        $routes_to_add_to = array(
366
-            'contact_list',
367
-            'event_registrations',
368
-            'default',
369
-        );
370
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
371
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
372
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
373
-            ) {
374
-                echo '';
375
-            } else {
376
-                $button_text = sprintf(
377
-                    __('Send Batch Message (%s selected)', 'event_espresso'),
378
-                    '<span class="send-selected-newsletter-count">0</span>'
379
-                );
380
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
381
-                     . $button_text
382
-                     . '</button>';
383
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
384
-            }
385
-        }
386
-    }
387
-
388
-
389
-
390
-    public function newsletter_send_form_skeleton()
391
-    {
392
-        $list_table = $this->_list_table_object;
393
-        $codes = array();
394
-        //need to templates for the newsletter message type for the template selector.
395
-        $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
396
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
397
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
398
-        );
399
-        foreach ($mtps as $mtp) {
400
-            $name = $mtp->name();
401
-            $values[] = array(
402
-                'text' => empty($name) ? __('Global', 'event_espresso') : $name,
403
-                'id'   => $mtp->ID(),
404
-            );
405
-        }
406
-        //need to get a list of shortcodes that are available for the newsletter message type.
407
-        $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
408
-        foreach ($shortcodes as $field => $shortcode_array) {
409
-            $codes[$field] = implode(', ', array_keys($shortcode_array));
410
-        }
411
-        $shortcodes = $codes;
412
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
413
-        $form_template_args = array(
414
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415
-            'form_route'        => 'newsletter_selected_send',
416
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
417
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
418
-            'redirect_back_to'  => $this->_req_action,
419
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
420
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
421
-            'shortcodes'        => $shortcodes,
422
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
423
-        );
424
-        EEH_Template::display_template($form_template, $form_template_args);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Handles sending selected registrations/contacts a newsletter.
431
-     *
432
-     * @since  4.3.0
433
-     * @return void
434
-     * @throws \EE_Error
435
-     */
436
-    protected function _newsletter_selected_send()
437
-    {
438
-        $success = true;
439
-        //first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
440
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
441
-            EE_Error::add_error(
442
-                __(
443
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
444
-                    'event_espresso'
445
-                ),
446
-                __FILE__,
447
-                __FUNCTION__,
448
-                __LINE__
449
-            );
450
-            $success = false;
451
-        }
452
-        if ($success) {
453
-            //update Message template in case there are any changes
454
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
455
-                $this->_req_data['newsletter_mtp_selected']
456
-            );
457
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
458
-                ? $Message_Template_Group->context_templates()
459
-                : array();
460
-            if (empty($Message_Templates)) {
461
-                EE_Error::add_error(
462
-                    __(
463
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
464
-                        'event_espresso'
465
-                    ),
466
-                    __FILE__,
467
-                    __FUNCTION__,
468
-                    __LINE__
469
-                );
470
-            }
471
-            //let's just update the specific fields
472
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
473
-                if ($Message_Template instanceof EE_Message_Template) {
474
-                    $field = $Message_Template->get('MTP_template_field');
475
-                    $content = $Message_Template->get('MTP_content');
476
-                    $new_content = $content;
477
-                    switch ($field) {
478
-                        case 'from' :
479
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
480
-                                ? $this->_req_data['batch_message']['from']
481
-                                : $content;
482
-                            break;
483
-                        case 'subject' :
484
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
485
-                                ? $this->_req_data['batch_message']['subject']
486
-                                : $content;
487
-                            break;
488
-                        case 'content' :
489
-                            $new_content = $content;
490
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
491
-                                ? $this->_req_data['batch_message']['content']
492
-                                : $content['newsletter_content'];
493
-                            break;
494
-                        default :
495
-                            //continue the foreach loop, we don't want to set $new_content nor save.
496
-                            continue 2;
497
-                    }
498
-                    $Message_Template->set('MTP_content', $new_content);
499
-                    $Message_Template->save();
500
-                }
501
-            }
502
-            //great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
503
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
504
-                ? $this->_req_data['batch_message']['id_type']
505
-                : 'registration';
506
-            //id_type will affect how we assemble the ids.
507
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
508
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
509
-                : array();
510
-            $registrations_used_for_contact_data = array();
511
-            //using switch because eventually we'll have other contexts that will be used for generating messages.
512
-            switch ($id_type) {
513
-                case 'registration' :
514
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
515
-                        array(
516
-                            array(
517
-                                'REG_ID' => array('IN', $ids),
518
-                            ),
519
-                        )
520
-                    );
521
-                    break;
522
-                case 'contact' :
523
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
524
-                                                                           ->get_latest_registration_for_each_of_given_contacts($ids);
525
-                    break;
526
-            }
527
-            do_action(
528
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
529
-                $registrations_used_for_contact_data,
530
-                $Message_Template_Group->ID()
531
-            );
532
-            //kept for backward compat, internally we no longer use this action.
533
-            //@deprecated 4.8.36.rc.002
534
-            $contacts = $id_type === 'registration'
535
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
536
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
537
-            do_action(
538
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
539
-                $contacts,
540
-                $Message_Template_Group->ID()
541
-            );
542
-        }
543
-        $query_args = array(
544
-            'action' => ! empty($this->_req_data['redirect_back_to'])
545
-                ? $this->_req_data['redirect_back_to']
546
-                : 'default',
547
-        );
548
-        $this->_redirect_after_action(false, '', '', $query_args, true);
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
555
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
556
-     */
557
-    protected function _registration_reports_js_setup()
558
-    {
559
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
560
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     *        generates Business Reports regarding Registrations
567
-     *
568
-     * @access protected
569
-     * @return void
570
-     */
571
-    protected function _registration_reports()
572
-    {
573
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
574
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
575
-            $template_path,
576
-            $this->_reports_template_data,
577
-            true
578
-        );
579
-        // the final template wrapper
580
-        $this->display_admin_page_with_no_sidebar();
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * Generates Business Report showing total registrations per day.
587
-     *
588
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
589
-     * @return string
590
-     */
591
-    private function _registrations_per_day_report($period = '-1 month')
592
-    {
593
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
594
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
-        $results = (array)$results;
596
-        $regs = array();
597
-        $subtitle = '';
598
-        if ($results) {
599
-            $column_titles = array();
600
-            $tracker = 0;
601
-            foreach ($results as $result) {
602
-                $report_column_values = array();
603
-                foreach ($result as $property_name => $property_value) {
604
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
605
-                        : (int)$property_value;
606
-                    $report_column_values[] = $property_value;
607
-                    if ($tracker === 0) {
608
-                        if ($property_name === 'Registration_REG_date') {
609
-                            $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
610
-                        } else {
611
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
612
-                        }
613
-                    }
614
-                }
615
-                $tracker++;
616
-                $regs[] = $report_column_values;
617
-            }
618
-            //make sure the column_titles is pushed to the beginning of the array
619
-            array_unshift($regs, $column_titles);
620
-            //setup the date range.
621
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
623
-            $ending_date = new DateTime("now", $DateTimeZone);
624
-            $subtitle = sprintf(
625
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
626
-                $beginning_date->format('Y-m-d'),
627
-                $ending_date->format('Y-m-d')
628
-            );
629
-        }
630
-        $report_title = __('Total Registrations per Day', 'event_espresso');
631
-        $report_params = array(
632
-            'title'     => $report_title,
633
-            'subtitle'  => $subtitle,
634
-            'id'        => $report_ID,
635
-            'regs'      => $regs,
636
-            'noResults' => empty($regs),
637
-            'noRegsMsg' => sprintf(
638
-                __(
639
-                    '%sThere are currently no registration records in the last month for this report.%s',
640
-                    'event_espresso'
641
-                ),
642
-                '<h2>' . $report_title . '</h2><p>',
643
-                '</p>'
644
-            ),
645
-        );
646
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
647
-        return $report_ID;
648
-    }
649
-
650
-
651
-
652
-    /**
653
-     * Generates Business Report showing total registrations per event.
654
-     *
655
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
656
-     * @return string
657
-     */
658
-    private function _registrations_per_event_report($period = '-1 month')
659
-    {
660
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
661
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
-        $results = (array)$results;
663
-        $regs = array();
664
-        $subtitle = '';
665
-        if ($results) {
666
-            $column_titles = array();
667
-            $tracker = 0;
668
-            foreach ($results as $result) {
669
-                $report_column_values = array();
670
-                foreach ($result as $property_name => $property_value) {
671
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
672
-                        $property_value,
673
-                        4,
674
-                        '...'
675
-                    ) : (int)$property_value;
676
-                    $report_column_values[] = $property_value;
677
-                    if ($tracker === 0) {
678
-                        if ($property_name === 'Registration_Event') {
679
-                            $column_titles[] = __('Event', 'event_espresso');
680
-                        } else {
681
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
682
-                        }
683
-                    }
684
-                }
685
-                $tracker++;
686
-                $regs[] = $report_column_values;
687
-            }
688
-            //make sure the column_titles is pushed to the beginning of the array
689
-            array_unshift($regs, $column_titles);
690
-            //setup the date range.
691
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
693
-            $ending_date = new DateTime("now", $DateTimeZone);
694
-            $subtitle = sprintf(
695
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
696
-                $beginning_date->format('Y-m-d'),
697
-                $ending_date->format('Y-m-d')
698
-            );
699
-        }
700
-        $report_title = __('Total Registrations per Event', 'event_espresso');
701
-        $report_params = array(
702
-            'title'     => $report_title,
703
-            'subtitle'  => $subtitle,
704
-            'id'        => $report_ID,
705
-            'regs'      => $regs,
706
-            'noResults' => empty($regs),
707
-            'noRegsMsg' => sprintf(
708
-                __(
709
-                    '%sThere are currently no registration records in the last month for this report.%s',
710
-                    'event_espresso'
711
-                ),
712
-                '<h2>' . $report_title . '</h2><p>',
713
-                '</p>'
714
-            ),
715
-        );
716
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
717
-        return $report_ID;
718
-    }
719
-
720
-
721
-
722
-    /**
723
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
724
-     *
725
-     * @access protected
726
-     * @return void
727
-     * @throws \EE_Error
728
-     */
729
-    protected function _registration_checkin_list_table()
730
-    {
731
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
732
-        $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
733
-        /** @var EE_Registration $registration */
734
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
735
-        $attendee = $registration->attendee();
736
-        $this->_admin_page_title .= $this->get_action_link_or_button(
737
-            'new_registration',
738
-            'add-registrant',
739
-            array('event_id' => $registration->event_ID()),
740
-            'add-new-h2'
741
-        );
742
-        $legend_items = array(
743
-            'checkin'  => array(
744
-                'class' => 'ee-icon ee-icon-check-in',
745
-                'desc'  => __('This indicates the attendee has been checked in', 'event_espresso'),
746
-            ),
747
-            'checkout' => array(
748
-                'class' => 'ee-icon ee-icon-check-out',
749
-                'desc'  => __('This indicates the attendee has been checked out', 'event_espresso'),
750
-            ),
751
-        );
752
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
753
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
754
-        /** @var EE_Datetime $datetime */
755
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
756
-        $datetime_label = '';
757
-        if ($datetime instanceof EE_Datetime) {
758
-            $datetime_label = $datetime->get_dtt_display_name(true);
759
-            $datetime_label .= ! empty($datetime_label)
760
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
761
-                : $datetime->get_dtt_display_name();
762
-        }
763
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
764
-            ? EE_Admin_Page::add_query_args_and_nonce(
765
-                array(
766
-                    'action'   => 'event_registrations',
767
-                    'event_id' => $registration->event_ID(),
768
-                    'DTT_ID'   => $dtt_id,
769
-                ),
770
-                $this->_admin_base_url
771
-            )
772
-            : '';
773
-        $datetime_link = ! empty($datetime_link)
774
-            ? '<a href="' . $datetime_link . '">'
775
-              . '<span id="checkin-dtt">'
776
-              . $datetime_label
777
-              . '</span></a>'
778
-            : $datetime_label;
779
-        $attendee_name = $attendee instanceof EE_Attendee
780
-            ? $attendee->full_name()
781
-            : '';
782
-        $attendee_link = $attendee instanceof EE_Attendee
783
-            ? $attendee->get_admin_details_link()
784
-            : '';
785
-        $attendee_link = ! empty($attendee_link)
786
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
787
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
788
-              . '<span id="checkin-attendee-name">'
789
-              . $attendee_name
790
-              . '</span></a>'
791
-            : '';
792
-        $event_link = $registration->event() instanceof EE_Event
793
-            ? $registration->event()->get_admin_details_link()
794
-            : '';
795
-        $event_link = ! empty($event_link)
796
-            ? '<a href="' . $event_link . '"'
797
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
798
-              . '<span id="checkin-event-name">'
799
-              . $registration->event_name()
800
-              . '</span>'
801
-              . '</a>'
802
-            : '';
803
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
-            ? '<h2>' . sprintf(
805
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806
-                $attendee_link,
807
-                $datetime_link,
808
-                $event_link
809
-            ) . '</h2>'
810
-            : '';
811
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
813
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
815
-        $this->display_admin_list_table_page_with_no_sidebar();
816
-    }
817
-
818
-
819
-
820
-    /**
821
-     * toggle the Check-in status for the given registration (coming from ajax)
822
-     *
823
-     * @return void (JSON)
824
-     */
825
-    public function toggle_checkin_status()
826
-    {
827
-        //first make sure we have the necessary data
828
-        if ( ! isset($this->_req_data['_regid'])) {
829
-            EE_Error::add_error(
830
-                __(
831
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
832
-                    'event_espresso'
833
-                ),
834
-                __FILE__,
835
-                __FUNCTION__,
836
-                __LINE__
837
-            );
838
-            $this->_template_args['success'] = false;
839
-            $this->_template_args['error'] = true;
840
-            $this->_return_json();
841
-        };
842
-        //do a nonce check cause we're not coming in from an normal route here.
843
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
844
-            : '';
845
-        $nonce_ref = 'checkin_nonce';
846
-        $this->_verify_nonce($nonce, $nonce_ref);
847
-        //beautiful! Made it this far so let's get the status.
848
-        $new_status = $this->_toggle_checkin_status();
849
-        //setup new class to return via ajax
850
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-'
851
-                                                      . $new_status;
852
-        $this->_template_args['success'] = true;
853
-        $this->_return_json();
854
-    }
855
-
856
-
857
-
858
-    /**
859
-     * handles toggling the checkin status for the registration,
860
-     *
861
-     * @access protected
862
-     * @return int|void
863
-     */
864
-    protected function _toggle_checkin_status()
865
-    {
866
-        //first let's get the query args out of the way for the redirect
867
-        $query_args = array(
868
-            'action'   => 'event_registrations',
869
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
870
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
871
-        );
872
-        $new_status = false;
873
-        // bulk action check in toggle
874
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
-            // cycle thru checkboxes
876
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
877
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
878
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
879
-            }
880
-        } elseif (isset($this->_req_data['_regid'])) {
881
-            //coming from ajax request
882
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
883
-            $query_args['DTT_ID'] = $DTT_ID;
884
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
885
-        } else {
886
-            EE_Error::add_error(
887
-                __('Missing some required data to toggle the Check-in', 'event_espresso'),
888
-                __FILE__,
889
-                __FUNCTION__,
890
-                __LINE__
891
-            );
892
-        }
893
-        if (defined('DOING_AJAX')) {
894
-            return $new_status;
895
-        }
896
-        $this->_redirect_after_action(false, '', '', $query_args, true);
897
-    }
898
-
899
-
900
-
901
-    /**
902
-     * This is toggles a single Check-in for the given registration and datetime.
903
-     *
904
-     * @param  int $REG_ID The registration we're toggling
905
-     * @param  int $DTT_ID The datetime we're toggling
906
-     * @return int            The new status toggled to.
907
-     * @throws \EE_Error
908
-     */
909
-    private function _toggle_checkin($REG_ID, $DTT_ID)
910
-    {
911
-        /** @var EE_Registration $REG */
912
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
913
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
914
-        if ($new_status !== false) {
915
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
916
-        } else {
917
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
918
-            $new_status = false;
919
-        }
920
-        return $new_status;
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     * Takes care of deleting multiple EE_Checkin table rows
927
-     *
928
-     * @access protected
929
-     * @return void
930
-     * @throws \EE_Error
931
-     */
932
-    protected function _delete_checkin_rows()
933
-    {
934
-        $query_args = array(
935
-            'action' => 'registration_checkins',
936
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
937
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
938
-        );
939
-        $errors = 0;
940
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
941
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
942
-                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
943
-                    $errors++;
944
-                }
945
-            }
946
-        } else {
947
-            EE_Error::add_error(
948
-                __(
949
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
950
-                    'event_espresso'
951
-                ),
952
-                __FILE__,
953
-                __FUNCTION__,
954
-                __LINE__
955
-            );
956
-            $this->_redirect_after_action(false, '', '', $query_args, true);
957
-        }
958
-        if ($errors > 0) {
959
-            EE_Error::add_error(
960
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
961
-                __FILE__,
962
-                __FUNCTION__,
963
-                __LINE__
964
-            );
965
-        } else {
966
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
967
-        }
968
-        $this->_redirect_after_action(false, '', '', $query_args, true);
969
-    }
970
-
971
-
972
-
973
-    /**
974
-     * Deletes a single EE_Checkin row
975
-     *
976
-     * @return void
977
-     * @throws \EE_Error
978
-     */
979
-    protected function _delete_checkin_row()
980
-    {
981
-        $query_args = array(
982
-            'action' => 'registration_checkins',
983
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
984
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
985
-        );
986
-        if ( ! empty($this->_req_data['CHK_ID'])) {
987
-            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
988
-                EE_Error::add_error(
989
-                    __('Something went wrong and this check-in record was not deleted', 'event_espresso'),
990
-                    __FILE__,
991
-                    __FUNCTION__,
992
-                    __LINE__
993
-                );
994
-            } else {
995
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
996
-            }
997
-        } else {
998
-            EE_Error::add_error(
999
-                __(
1000
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1001
-                    'event_espresso'
1002
-                ),
1003
-                __FILE__,
1004
-                __FUNCTION__,
1005
-                __LINE__
1006
-            );
1007
-        }
1008
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     *        generates HTML for the Event Registrations List Table
1015
-     *
1016
-     * @access protected
1017
-     * @return void
1018
-     * @throws \EE_Error
1019
-     */
1020
-    protected function _event_registrations_list_table()
1021
-    {
1022
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1023
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1024
-            ? $this->get_action_link_or_button(
1025
-                'new_registration',
1026
-                'add-registrant',
1027
-                array('event_id' => $this->_req_data['event_id']),
1028
-                'add-new-h2',
1029
-                '',
1030
-                false
1031
-            )
1032
-            : '';
1033
-        $legend_items = array(
1034
-            'star-icon'        => array(
1035
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
-                'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1037
-            ),
1038
-            'checkin'          => array(
1039
-                'class' => 'ee-icon ee-icon-check-in',
1040
-                'desc'  => __('This Registrant has been Checked In', 'event_espresso'),
1041
-            ),
1042
-            'checkout'         => array(
1043
-                'class' => 'ee-icon ee-icon-check-out',
1044
-                'desc'  => __('This Registrant has been Checked Out', 'event_espresso'),
1045
-            ),
1046
-            'nocheckinrecord'  => array(
1047
-                'class' => 'dashicons dashicons-no',
1048
-                'desc'  => __('No Check-in Record has been Created for this Registrant', 'event_espresso'),
1049
-            ),
1050
-            'view_details'     => array(
1051
-                'class' => 'dashicons dashicons-search',
1052
-                'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053
-            ),
1054
-            'approved_status'  => array(
1055
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1056
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057
-            ),
1058
-            'cancelled_status' => array(
1059
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1060
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061
-            ),
1062
-            'declined_status'  => array(
1063
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1064
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065
-            ),
1066
-            'not_approved'     => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1068
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069
-            ),
1070
-            'pending_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1072
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073
-            ),
1074
-            'wait_list'        => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1076
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077
-            ),
1078
-        );
1079
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081
-        $this->_template_args['before_list_table'] = ! empty($event_id)
1082
-            ? '<h2>' . sprintf(
1083
-                __('Viewing Registrations for Event: %s', 'event_espresso'),
1084
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
-            ) . '</h2>'
1086
-            : '';
1087
-        //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088
-        /** @var EE_Event $event */
1089
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1090
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1091
-        $datetime = null;
1092
-        if ($event instanceof EE_Event) {
1093
-            $datetimes_on_event = $event->datetimes();
1094
-            if (count($datetimes_on_event) === 1) {
1095
-                $datetime = reset($datetimes_on_event);
1096
-            }
1097
-        }
1098
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1099
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1100
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1101
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103
-            $this->_template_args['before_list_table'] .= $datetime->name();
1104
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1105
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1106
-        }
1107
-        //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1108
-        //represents
1109
-        if ( ! $datetime instanceof EE_Datetime) {
1110
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1111
-                                                          . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1112
-                    'event_espresso')
1113
-                                                          . '</p>';
1114
-        }
1115
-        $this->display_admin_list_table_page_with_no_sidebar();
1116
-    }
1117
-
1118
-    /**
1119
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1120
-     * conditions)
1121
-     *
1122
-     * @return void ends the request by a redirect or download
1123
-     */
1124
-    public function _registrations_checkin_report()
1125
-    {
1126
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1127
-    }
1128
-
1129
-    /**
1130
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1131
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1132
-     *
1133
-     * @param array     $request
1134
-     * @param int  $per_page
1135
-     * @param bool $count
1136
-     * @return array
1137
-     */
1138
-    protected function _get_checkin_query_params_from_request(
1139
-        $request,
1140
-        $per_page = 10,
1141
-        $count = false
1142
-    ) {
1143
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1144
-        //unlike the regular registrations list table,
1145
-        $status_ids_array = apply_filters(
1146
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1147
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1148
-        );
1149
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1150
-        return $query_params;
1151
-    }
1152
-
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * Gets registrations for an event
1158
-     *
1159
-     * @param int    $per_page
1160
-     * @param bool   $count whether to return count or data.
1161
-     * @param bool   $trash
1162
-     * @param string $orderby
1163
-     * @return EE_Registration[]|int
1164
-     * @throws \EE_Error
1165
-     */
1166
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1167
-    {
1168
-        //normalize some request params that get setup by the parent `get_registrations` method.
1169
-        $request = $this->_req_data;
1170
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
-        if($trash){
1173
-            $request['status'] = 'trash';
1174
-        }
1175
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1176
-        /**
1177
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1179
-         * @see EEM_Base::get_all()
1180
-         */
1181
-        $query_params['group_by'] = '';
1182
-
1183
-        return $count
1184
-            ? EEM_Registration::instance()->count($query_params)
1185
-            /** @type EE_Registration[] */
1186
-            : EEM_Registration::instance()->get_all($query_params);
1187
-    }
20
+	/**
21
+	 * This is used to hold the reports template data which is setup early in the request.
22
+	 *
23
+	 * @type array
24
+	 */
25
+	protected $_reports_template_data = array();
26
+
27
+
28
+
29
+	/**
30
+	 * Extend_Registrations_Admin_Page constructor.
31
+	 *
32
+	 * @param bool $routing
33
+	 */
34
+	public function __construct($routing = true)
35
+	{
36
+		parent::__construct($routing);
37
+		if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
41
+		}
42
+	}
43
+
44
+
45
+
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		// $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
53
+		// $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
54
+		// 	? $this->_req_data['post'] : $att_id;
55
+		$new_page_routes = array(
56
+			'reports'                  => array(
57
+				'func'       => '_registration_reports',
58
+				'capability' => 'ee_read_registrations',
59
+			),
60
+			'registration_checkins'    => array(
61
+				'func'       => '_registration_checkin_list_table',
62
+				'capability' => 'ee_read_checkins',
63
+			),
64
+			'newsletter_selected_send' => array(
65
+				'func'       => '_newsletter_selected_send',
66
+				'noheader'   => true,
67
+				'capability' => 'ee_send_message',
68
+			),
69
+			'delete_checkin_rows'      => array(
70
+				'func'       => '_delete_checkin_rows',
71
+				'noheader'   => true,
72
+				'capability' => 'ee_delete_checkins',
73
+			),
74
+			'delete_checkin_row'       => array(
75
+				'func'       => '_delete_checkin_row',
76
+				'noheader'   => true,
77
+				'capability' => 'ee_delete_checkin',
78
+				'obj_id'     => $reg_id,
79
+			),
80
+			'toggle_checkin_status'    => array(
81
+				'func'       => '_toggle_checkin_status',
82
+				'noheader'   => true,
83
+				'capability' => 'ee_edit_checkin',
84
+				'obj_id'     => $reg_id,
85
+			),
86
+			'event_registrations'      => array(
87
+				'func'       => '_event_registrations_list_table',
88
+				'capability' => 'ee_read_checkins',
89
+			),
90
+			'registrations_checkin_report' => array(
91
+				'func'       => '_registrations_checkin_report',
92
+				'noheader'   => true,
93
+				'capability' => 'ee_read_registrations',
94
+			),
95
+		);
96
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
97
+		$new_page_config = array(
98
+			'reports'               => array(
99
+				'nav'           => array(
100
+					'label' => __('Reports', 'event_espresso'),
101
+					'order' => 30,
102
+				),
103
+				'help_tabs'     => array(
104
+					'registrations_reports_help_tab' => array(
105
+						'title'    => __('Registration Reports', 'event_espresso'),
106
+						'filename' => 'registrations_reports',
107
+					),
108
+				),
109
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
110
+				'require_nonce' => false,
111
+			),
112
+			'event_registrations'   => array(
113
+				'nav'           => array(
114
+					'label'      => __('Event Check-In', 'event_espresso'),
115
+					'order'      => 10,
116
+					'persistent' => true,
117
+				),
118
+				'help_tabs'     => array(
119
+					'registrations_event_checkin_help_tab'                       => array(
120
+						'title'    => __('Registrations Event Check-In', 'event_espresso'),
121
+						'filename' => 'registrations_event_checkin',
122
+					),
123
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
124
+						'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
125
+						'filename' => 'registrations_event_checkin_table_column_headings',
126
+					),
127
+					'registrations_event_checkin_filters_help_tab'               => array(
128
+						'title'    => __('Event Check-In Filters', 'event_espresso'),
129
+						'filename' => 'registrations_event_checkin_filters',
130
+					),
131
+					'registrations_event_checkin_views_help_tab'                 => array(
132
+						'title'    => __('Event Check-In Views', 'event_espresso'),
133
+						'filename' => 'registrations_event_checkin_views',
134
+					),
135
+					'registrations_event_checkin_other_help_tab'                 => array(
136
+						'title'    => __('Event Check-In Other', 'event_espresso'),
137
+						'filename' => 'registrations_event_checkin_other',
138
+					),
139
+				),
140
+				'help_tour'     => array('Event_Checkin_Help_Tour'),
141
+				'qtips'         => array('Registration_List_Table_Tips'),
142
+				'list_table'    => 'EE_Event_Registrations_List_Table',
143
+				'metaboxes'     => array(),
144
+				'require_nonce' => false,
145
+			),
146
+			'registration_checkins' => array(
147
+				'nav'           => array(
148
+					'label'      => __('Check-In Records', 'event_espresso'),
149
+					'order'      => 15,
150
+					'persistent' => false,
151
+				),
152
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
153
+				//'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
154
+				'metaboxes'     => array(),
155
+				'require_nonce' => false,
156
+			),
157
+		);
158
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
159
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
160
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
161
+	}
162
+
163
+
164
+
165
+	protected function _ajax_hooks()
166
+	{
167
+		parent::_ajax_hooks();
168
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
169
+	}
170
+
171
+
172
+
173
+	public function load_scripts_styles()
174
+	{
175
+		parent::load_scripts_styles();
176
+		//if newsletter message type is active then let's add filter and load js for it.
177
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
178
+			//enqueue newsletter js
179
+			wp_enqueue_script(
180
+				'ee-newsletter-trigger',
181
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
182
+				array('ee-dialog'),
183
+				EVENT_ESPRESSO_VERSION,
184
+				true
185
+			);
186
+			wp_enqueue_style(
187
+				'ee-newsletter-trigger-css',
188
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
189
+				array(),
190
+				EVENT_ESPRESSO_VERSION
191
+			);
192
+			//hook in buttons for newsletter message type trigger.
193
+			add_action(
194
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
195
+				array($this, 'add_newsletter_action_buttons'),
196
+				10
197
+			);
198
+		}
199
+	}
200
+
201
+
202
+
203
+	public function load_scripts_styles_reports()
204
+	{
205
+		wp_register_script(
206
+			'ee-reg-reports-js',
207
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
208
+			array('google-charts'),
209
+			EVENT_ESPRESSO_VERSION,
210
+			true
211
+		);
212
+		wp_enqueue_script('ee-reg-reports-js');
213
+		$this->_registration_reports_js_setup();
214
+	}
215
+
216
+
217
+
218
+	protected function _add_screen_options_event_registrations()
219
+	{
220
+		$this->_per_page_screen_option();
221
+	}
222
+
223
+
224
+
225
+	protected function _add_screen_options_registration_checkins()
226
+	{
227
+		$page_title = $this->_admin_page_title;
228
+		$this->_admin_page_title = __('Check-In Records', 'event_espresso');
229
+		$this->_per_page_screen_option();
230
+		$this->_admin_page_title = $page_title;
231
+	}
232
+
233
+
234
+
235
+	protected function _set_list_table_views_event_registrations()
236
+	{
237
+		$this->_views = array(
238
+			'all' => array(
239
+				'slug'        => 'all',
240
+				'label'       => __('All', 'event_espresso'),
241
+				'count'       => 0,
242
+				'bulk_action' => ! isset($this->_req_data['event_id'])
243
+					? array()
244
+					: array(
245
+						'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'),
246
+						//'trash_registrations' => __('Trash Registrations', 'event_espresso')
247
+					),
248
+			),
249
+		);
250
+	}
251
+
252
+
253
+
254
+	protected function _set_list_table_views_registration_checkins()
255
+	{
256
+		$this->_views = array(
257
+			'all' => array(
258
+				'slug'        => 'all',
259
+				'label'       => __('All', 'event_espresso'),
260
+				'count'       => 0,
261
+				'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
262
+			),
263
+		);
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * callback for ajax action.
270
+	 *
271
+	 * @since 4.3.0
272
+	 * @return void (JSON)
273
+	 * @throws \EE_Error
274
+	 */
275
+	public function get_newsletter_form_content()
276
+	{
277
+		//do a nonce check cause we're not coming in from an normal route here.
278
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
279
+			$this->_req_data['get_newsletter_form_content_nonce']
280
+		) : '';
281
+		$nonce_ref = 'get_newsletter_form_content_nonce';
282
+		$this->_verify_nonce($nonce, $nonce_ref);
283
+		//let's get the mtp for the incoming MTP_ ID
284
+		if ( ! isset($this->_req_data['GRP_ID'])) {
285
+			EE_Error::add_error(
286
+				__(
287
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
288
+					'event_espresso'
289
+				),
290
+				__FILE__,
291
+				__FUNCTION__,
292
+				__LINE__
293
+			);
294
+			$this->_template_args['success'] = false;
295
+			$this->_template_args['error'] = true;
296
+			$this->_return_json();
297
+		}
298
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
299
+		if ( ! $MTPG instanceof EE_Message_Template_Group) {
300
+			EE_Error::add_error(
301
+				sprintf(
302
+					__(
303
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
304
+						'event_espresso'
305
+					),
306
+					$this->_req_data['GRP_ID']
307
+				),
308
+				__FILE__,
309
+				__FUNCTION__,
310
+				__LINE__
311
+			);
312
+			$this->_template_args['success'] = false;
313
+			$this->_template_args['error'] = true;
314
+			$this->_return_json();
315
+		}
316
+		$MTPs = $MTPG->context_templates();
317
+		$MTPs = $MTPs['attendee'];
318
+		$template_fields = array();
319
+		/** @var EE_Message_Template $MTP */
320
+		foreach ($MTPs as $MTP) {
321
+			$field = $MTP->get('MTP_template_field');
322
+			if ($field === 'content') {
323
+				$content = $MTP->get('MTP_content');
324
+				if ( ! empty($content['newsletter_content'])) {
325
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
326
+				}
327
+				continue;
328
+			}
329
+			$template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
330
+		}
331
+		$this->_template_args['success'] = true;
332
+		$this->_template_args['error'] = false;
333
+		$this->_template_args['data'] = array(
334
+			'batch_message_from'    => isset($template_fields['from'])
335
+				? $template_fields['from']
336
+				: '',
337
+			'batch_message_subject' => isset($template_fields['subject'])
338
+				? $template_fields['subject']
339
+				: '',
340
+			'batch_message_content' => isset($template_fields['newsletter_content'])
341
+				? $template_fields['newsletter_content']
342
+				: '',
343
+		);
344
+		$this->_return_json();
345
+	}
346
+
347
+
348
+
349
+	/**
350
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
351
+	 *
352
+	 * @since 4.3.0
353
+	 * @param EE_Admin_List_Table $list_table
354
+	 * @return void
355
+	 */
356
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
357
+	{
358
+		if ( ! EE_Registry::instance()->CAP->current_user_can(
359
+			'ee_send_message',
360
+			'espresso_registrations_newsletter_selected_send'
361
+		)
362
+		) {
363
+			return;
364
+		}
365
+		$routes_to_add_to = array(
366
+			'contact_list',
367
+			'event_registrations',
368
+			'default',
369
+		);
370
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
371
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
372
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
373
+			) {
374
+				echo '';
375
+			} else {
376
+				$button_text = sprintf(
377
+					__('Send Batch Message (%s selected)', 'event_espresso'),
378
+					'<span class="send-selected-newsletter-count">0</span>'
379
+				);
380
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
381
+					 . $button_text
382
+					 . '</button>';
383
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
384
+			}
385
+		}
386
+	}
387
+
388
+
389
+
390
+	public function newsletter_send_form_skeleton()
391
+	{
392
+		$list_table = $this->_list_table_object;
393
+		$codes = array();
394
+		//need to templates for the newsletter message type for the template selector.
395
+		$values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
396
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
397
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
398
+		);
399
+		foreach ($mtps as $mtp) {
400
+			$name = $mtp->name();
401
+			$values[] = array(
402
+				'text' => empty($name) ? __('Global', 'event_espresso') : $name,
403
+				'id'   => $mtp->ID(),
404
+			);
405
+		}
406
+		//need to get a list of shortcodes that are available for the newsletter message type.
407
+		$shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
408
+		foreach ($shortcodes as $field => $shortcode_array) {
409
+			$codes[$field] = implode(', ', array_keys($shortcode_array));
410
+		}
411
+		$shortcodes = $codes;
412
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
413
+		$form_template_args = array(
414
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415
+			'form_route'        => 'newsletter_selected_send',
416
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
417
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
418
+			'redirect_back_to'  => $this->_req_action,
419
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
420
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
421
+			'shortcodes'        => $shortcodes,
422
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
423
+		);
424
+		EEH_Template::display_template($form_template, $form_template_args);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Handles sending selected registrations/contacts a newsletter.
431
+	 *
432
+	 * @since  4.3.0
433
+	 * @return void
434
+	 * @throws \EE_Error
435
+	 */
436
+	protected function _newsletter_selected_send()
437
+	{
438
+		$success = true;
439
+		//first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
440
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
441
+			EE_Error::add_error(
442
+				__(
443
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
444
+					'event_espresso'
445
+				),
446
+				__FILE__,
447
+				__FUNCTION__,
448
+				__LINE__
449
+			);
450
+			$success = false;
451
+		}
452
+		if ($success) {
453
+			//update Message template in case there are any changes
454
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
455
+				$this->_req_data['newsletter_mtp_selected']
456
+			);
457
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
458
+				? $Message_Template_Group->context_templates()
459
+				: array();
460
+			if (empty($Message_Templates)) {
461
+				EE_Error::add_error(
462
+					__(
463
+						'Unable to retrieve message template fields from the db. Messages not sent.',
464
+						'event_espresso'
465
+					),
466
+					__FILE__,
467
+					__FUNCTION__,
468
+					__LINE__
469
+				);
470
+			}
471
+			//let's just update the specific fields
472
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
473
+				if ($Message_Template instanceof EE_Message_Template) {
474
+					$field = $Message_Template->get('MTP_template_field');
475
+					$content = $Message_Template->get('MTP_content');
476
+					$new_content = $content;
477
+					switch ($field) {
478
+						case 'from' :
479
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
480
+								? $this->_req_data['batch_message']['from']
481
+								: $content;
482
+							break;
483
+						case 'subject' :
484
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
485
+								? $this->_req_data['batch_message']['subject']
486
+								: $content;
487
+							break;
488
+						case 'content' :
489
+							$new_content = $content;
490
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
491
+								? $this->_req_data['batch_message']['content']
492
+								: $content['newsletter_content'];
493
+							break;
494
+						default :
495
+							//continue the foreach loop, we don't want to set $new_content nor save.
496
+							continue 2;
497
+					}
498
+					$Message_Template->set('MTP_content', $new_content);
499
+					$Message_Template->save();
500
+				}
501
+			}
502
+			//great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
503
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
504
+				? $this->_req_data['batch_message']['id_type']
505
+				: 'registration';
506
+			//id_type will affect how we assemble the ids.
507
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
508
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
509
+				: array();
510
+			$registrations_used_for_contact_data = array();
511
+			//using switch because eventually we'll have other contexts that will be used for generating messages.
512
+			switch ($id_type) {
513
+				case 'registration' :
514
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
515
+						array(
516
+							array(
517
+								'REG_ID' => array('IN', $ids),
518
+							),
519
+						)
520
+					);
521
+					break;
522
+				case 'contact' :
523
+					$registrations_used_for_contact_data = EEM_Registration::instance()
524
+																		   ->get_latest_registration_for_each_of_given_contacts($ids);
525
+					break;
526
+			}
527
+			do_action(
528
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
529
+				$registrations_used_for_contact_data,
530
+				$Message_Template_Group->ID()
531
+			);
532
+			//kept for backward compat, internally we no longer use this action.
533
+			//@deprecated 4.8.36.rc.002
534
+			$contacts = $id_type === 'registration'
535
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
536
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
537
+			do_action(
538
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
539
+				$contacts,
540
+				$Message_Template_Group->ID()
541
+			);
542
+		}
543
+		$query_args = array(
544
+			'action' => ! empty($this->_req_data['redirect_back_to'])
545
+				? $this->_req_data['redirect_back_to']
546
+				: 'default',
547
+		);
548
+		$this->_redirect_after_action(false, '', '', $query_args, true);
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
555
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
556
+	 */
557
+	protected function _registration_reports_js_setup()
558
+	{
559
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
560
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 *        generates Business Reports regarding Registrations
567
+	 *
568
+	 * @access protected
569
+	 * @return void
570
+	 */
571
+	protected function _registration_reports()
572
+	{
573
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
574
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
575
+			$template_path,
576
+			$this->_reports_template_data,
577
+			true
578
+		);
579
+		// the final template wrapper
580
+		$this->display_admin_page_with_no_sidebar();
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * Generates Business Report showing total registrations per day.
587
+	 *
588
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
589
+	 * @return string
590
+	 */
591
+	private function _registrations_per_day_report($period = '-1 month')
592
+	{
593
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
594
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
+		$results = (array)$results;
596
+		$regs = array();
597
+		$subtitle = '';
598
+		if ($results) {
599
+			$column_titles = array();
600
+			$tracker = 0;
601
+			foreach ($results as $result) {
602
+				$report_column_values = array();
603
+				foreach ($result as $property_name => $property_value) {
604
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
605
+						: (int)$property_value;
606
+					$report_column_values[] = $property_value;
607
+					if ($tracker === 0) {
608
+						if ($property_name === 'Registration_REG_date') {
609
+							$column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
610
+						} else {
611
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
612
+						}
613
+					}
614
+				}
615
+				$tracker++;
616
+				$regs[] = $report_column_values;
617
+			}
618
+			//make sure the column_titles is pushed to the beginning of the array
619
+			array_unshift($regs, $column_titles);
620
+			//setup the date range.
621
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
623
+			$ending_date = new DateTime("now", $DateTimeZone);
624
+			$subtitle = sprintf(
625
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
626
+				$beginning_date->format('Y-m-d'),
627
+				$ending_date->format('Y-m-d')
628
+			);
629
+		}
630
+		$report_title = __('Total Registrations per Day', 'event_espresso');
631
+		$report_params = array(
632
+			'title'     => $report_title,
633
+			'subtitle'  => $subtitle,
634
+			'id'        => $report_ID,
635
+			'regs'      => $regs,
636
+			'noResults' => empty($regs),
637
+			'noRegsMsg' => sprintf(
638
+				__(
639
+					'%sThere are currently no registration records in the last month for this report.%s',
640
+					'event_espresso'
641
+				),
642
+				'<h2>' . $report_title . '</h2><p>',
643
+				'</p>'
644
+			),
645
+		);
646
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
647
+		return $report_ID;
648
+	}
649
+
650
+
651
+
652
+	/**
653
+	 * Generates Business Report showing total registrations per event.
654
+	 *
655
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
656
+	 * @return string
657
+	 */
658
+	private function _registrations_per_event_report($period = '-1 month')
659
+	{
660
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
661
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
+		$results = (array)$results;
663
+		$regs = array();
664
+		$subtitle = '';
665
+		if ($results) {
666
+			$column_titles = array();
667
+			$tracker = 0;
668
+			foreach ($results as $result) {
669
+				$report_column_values = array();
670
+				foreach ($result as $property_name => $property_value) {
671
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
672
+						$property_value,
673
+						4,
674
+						'...'
675
+					) : (int)$property_value;
676
+					$report_column_values[] = $property_value;
677
+					if ($tracker === 0) {
678
+						if ($property_name === 'Registration_Event') {
679
+							$column_titles[] = __('Event', 'event_espresso');
680
+						} else {
681
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
682
+						}
683
+					}
684
+				}
685
+				$tracker++;
686
+				$regs[] = $report_column_values;
687
+			}
688
+			//make sure the column_titles is pushed to the beginning of the array
689
+			array_unshift($regs, $column_titles);
690
+			//setup the date range.
691
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
693
+			$ending_date = new DateTime("now", $DateTimeZone);
694
+			$subtitle = sprintf(
695
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
696
+				$beginning_date->format('Y-m-d'),
697
+				$ending_date->format('Y-m-d')
698
+			);
699
+		}
700
+		$report_title = __('Total Registrations per Event', 'event_espresso');
701
+		$report_params = array(
702
+			'title'     => $report_title,
703
+			'subtitle'  => $subtitle,
704
+			'id'        => $report_ID,
705
+			'regs'      => $regs,
706
+			'noResults' => empty($regs),
707
+			'noRegsMsg' => sprintf(
708
+				__(
709
+					'%sThere are currently no registration records in the last month for this report.%s',
710
+					'event_espresso'
711
+				),
712
+				'<h2>' . $report_title . '</h2><p>',
713
+				'</p>'
714
+			),
715
+		);
716
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
717
+		return $report_ID;
718
+	}
719
+
720
+
721
+
722
+	/**
723
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
724
+	 *
725
+	 * @access protected
726
+	 * @return void
727
+	 * @throws \EE_Error
728
+	 */
729
+	protected function _registration_checkin_list_table()
730
+	{
731
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
732
+		$reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
733
+		/** @var EE_Registration $registration */
734
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
735
+		$attendee = $registration->attendee();
736
+		$this->_admin_page_title .= $this->get_action_link_or_button(
737
+			'new_registration',
738
+			'add-registrant',
739
+			array('event_id' => $registration->event_ID()),
740
+			'add-new-h2'
741
+		);
742
+		$legend_items = array(
743
+			'checkin'  => array(
744
+				'class' => 'ee-icon ee-icon-check-in',
745
+				'desc'  => __('This indicates the attendee has been checked in', 'event_espresso'),
746
+			),
747
+			'checkout' => array(
748
+				'class' => 'ee-icon ee-icon-check-out',
749
+				'desc'  => __('This indicates the attendee has been checked out', 'event_espresso'),
750
+			),
751
+		);
752
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
753
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
754
+		/** @var EE_Datetime $datetime */
755
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
756
+		$datetime_label = '';
757
+		if ($datetime instanceof EE_Datetime) {
758
+			$datetime_label = $datetime->get_dtt_display_name(true);
759
+			$datetime_label .= ! empty($datetime_label)
760
+				? ' (' . $datetime->get_dtt_display_name() . ')'
761
+				: $datetime->get_dtt_display_name();
762
+		}
763
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
764
+			? EE_Admin_Page::add_query_args_and_nonce(
765
+				array(
766
+					'action'   => 'event_registrations',
767
+					'event_id' => $registration->event_ID(),
768
+					'DTT_ID'   => $dtt_id,
769
+				),
770
+				$this->_admin_base_url
771
+			)
772
+			: '';
773
+		$datetime_link = ! empty($datetime_link)
774
+			? '<a href="' . $datetime_link . '">'
775
+			  . '<span id="checkin-dtt">'
776
+			  . $datetime_label
777
+			  . '</span></a>'
778
+			: $datetime_label;
779
+		$attendee_name = $attendee instanceof EE_Attendee
780
+			? $attendee->full_name()
781
+			: '';
782
+		$attendee_link = $attendee instanceof EE_Attendee
783
+			? $attendee->get_admin_details_link()
784
+			: '';
785
+		$attendee_link = ! empty($attendee_link)
786
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
787
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
788
+			  . '<span id="checkin-attendee-name">'
789
+			  . $attendee_name
790
+			  . '</span></a>'
791
+			: '';
792
+		$event_link = $registration->event() instanceof EE_Event
793
+			? $registration->event()->get_admin_details_link()
794
+			: '';
795
+		$event_link = ! empty($event_link)
796
+			? '<a href="' . $event_link . '"'
797
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
798
+			  . '<span id="checkin-event-name">'
799
+			  . $registration->event_name()
800
+			  . '</span>'
801
+			  . '</a>'
802
+			: '';
803
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
+			? '<h2>' . sprintf(
805
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806
+				$attendee_link,
807
+				$datetime_link,
808
+				$event_link
809
+			) . '</h2>'
810
+			: '';
811
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
+			? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
813
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
815
+		$this->display_admin_list_table_page_with_no_sidebar();
816
+	}
817
+
818
+
819
+
820
+	/**
821
+	 * toggle the Check-in status for the given registration (coming from ajax)
822
+	 *
823
+	 * @return void (JSON)
824
+	 */
825
+	public function toggle_checkin_status()
826
+	{
827
+		//first make sure we have the necessary data
828
+		if ( ! isset($this->_req_data['_regid'])) {
829
+			EE_Error::add_error(
830
+				__(
831
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
832
+					'event_espresso'
833
+				),
834
+				__FILE__,
835
+				__FUNCTION__,
836
+				__LINE__
837
+			);
838
+			$this->_template_args['success'] = false;
839
+			$this->_template_args['error'] = true;
840
+			$this->_return_json();
841
+		};
842
+		//do a nonce check cause we're not coming in from an normal route here.
843
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
844
+			: '';
845
+		$nonce_ref = 'checkin_nonce';
846
+		$this->_verify_nonce($nonce, $nonce_ref);
847
+		//beautiful! Made it this far so let's get the status.
848
+		$new_status = $this->_toggle_checkin_status();
849
+		//setup new class to return via ajax
850
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-'
851
+													  . $new_status;
852
+		$this->_template_args['success'] = true;
853
+		$this->_return_json();
854
+	}
855
+
856
+
857
+
858
+	/**
859
+	 * handles toggling the checkin status for the registration,
860
+	 *
861
+	 * @access protected
862
+	 * @return int|void
863
+	 */
864
+	protected function _toggle_checkin_status()
865
+	{
866
+		//first let's get the query args out of the way for the redirect
867
+		$query_args = array(
868
+			'action'   => 'event_registrations',
869
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
870
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
871
+		);
872
+		$new_status = false;
873
+		// bulk action check in toggle
874
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
+			// cycle thru checkboxes
876
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
877
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
878
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
879
+			}
880
+		} elseif (isset($this->_req_data['_regid'])) {
881
+			//coming from ajax request
882
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
883
+			$query_args['DTT_ID'] = $DTT_ID;
884
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
885
+		} else {
886
+			EE_Error::add_error(
887
+				__('Missing some required data to toggle the Check-in', 'event_espresso'),
888
+				__FILE__,
889
+				__FUNCTION__,
890
+				__LINE__
891
+			);
892
+		}
893
+		if (defined('DOING_AJAX')) {
894
+			return $new_status;
895
+		}
896
+		$this->_redirect_after_action(false, '', '', $query_args, true);
897
+	}
898
+
899
+
900
+
901
+	/**
902
+	 * This is toggles a single Check-in for the given registration and datetime.
903
+	 *
904
+	 * @param  int $REG_ID The registration we're toggling
905
+	 * @param  int $DTT_ID The datetime we're toggling
906
+	 * @return int            The new status toggled to.
907
+	 * @throws \EE_Error
908
+	 */
909
+	private function _toggle_checkin($REG_ID, $DTT_ID)
910
+	{
911
+		/** @var EE_Registration $REG */
912
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
913
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
914
+		if ($new_status !== false) {
915
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
916
+		} else {
917
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
918
+			$new_status = false;
919
+		}
920
+		return $new_status;
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 * Takes care of deleting multiple EE_Checkin table rows
927
+	 *
928
+	 * @access protected
929
+	 * @return void
930
+	 * @throws \EE_Error
931
+	 */
932
+	protected function _delete_checkin_rows()
933
+	{
934
+		$query_args = array(
935
+			'action' => 'registration_checkins',
936
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
937
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
938
+		);
939
+		$errors = 0;
940
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
941
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
942
+				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
943
+					$errors++;
944
+				}
945
+			}
946
+		} else {
947
+			EE_Error::add_error(
948
+				__(
949
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
950
+					'event_espresso'
951
+				),
952
+				__FILE__,
953
+				__FUNCTION__,
954
+				__LINE__
955
+			);
956
+			$this->_redirect_after_action(false, '', '', $query_args, true);
957
+		}
958
+		if ($errors > 0) {
959
+			EE_Error::add_error(
960
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
961
+				__FILE__,
962
+				__FUNCTION__,
963
+				__LINE__
964
+			);
965
+		} else {
966
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
967
+		}
968
+		$this->_redirect_after_action(false, '', '', $query_args, true);
969
+	}
970
+
971
+
972
+
973
+	/**
974
+	 * Deletes a single EE_Checkin row
975
+	 *
976
+	 * @return void
977
+	 * @throws \EE_Error
978
+	 */
979
+	protected function _delete_checkin_row()
980
+	{
981
+		$query_args = array(
982
+			'action' => 'registration_checkins',
983
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
984
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
985
+		);
986
+		if ( ! empty($this->_req_data['CHK_ID'])) {
987
+			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
988
+				EE_Error::add_error(
989
+					__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
990
+					__FILE__,
991
+					__FUNCTION__,
992
+					__LINE__
993
+				);
994
+			} else {
995
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
996
+			}
997
+		} else {
998
+			EE_Error::add_error(
999
+				__(
1000
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1001
+					'event_espresso'
1002
+				),
1003
+				__FILE__,
1004
+				__FUNCTION__,
1005
+				__LINE__
1006
+			);
1007
+		}
1008
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 *        generates HTML for the Event Registrations List Table
1015
+	 *
1016
+	 * @access protected
1017
+	 * @return void
1018
+	 * @throws \EE_Error
1019
+	 */
1020
+	protected function _event_registrations_list_table()
1021
+	{
1022
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1023
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1024
+			? $this->get_action_link_or_button(
1025
+				'new_registration',
1026
+				'add-registrant',
1027
+				array('event_id' => $this->_req_data['event_id']),
1028
+				'add-new-h2',
1029
+				'',
1030
+				false
1031
+			)
1032
+			: '';
1033
+		$legend_items = array(
1034
+			'star-icon'        => array(
1035
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1036
+				'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1037
+			),
1038
+			'checkin'          => array(
1039
+				'class' => 'ee-icon ee-icon-check-in',
1040
+				'desc'  => __('This Registrant has been Checked In', 'event_espresso'),
1041
+			),
1042
+			'checkout'         => array(
1043
+				'class' => 'ee-icon ee-icon-check-out',
1044
+				'desc'  => __('This Registrant has been Checked Out', 'event_espresso'),
1045
+			),
1046
+			'nocheckinrecord'  => array(
1047
+				'class' => 'dashicons dashicons-no',
1048
+				'desc'  => __('No Check-in Record has been Created for this Registrant', 'event_espresso'),
1049
+			),
1050
+			'view_details'     => array(
1051
+				'class' => 'dashicons dashicons-search',
1052
+				'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053
+			),
1054
+			'approved_status'  => array(
1055
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1056
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057
+			),
1058
+			'cancelled_status' => array(
1059
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1060
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061
+			),
1062
+			'declined_status'  => array(
1063
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1064
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065
+			),
1066
+			'not_approved'     => array(
1067
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1068
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069
+			),
1070
+			'pending_status'   => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1072
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073
+			),
1074
+			'wait_list'        => array(
1075
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1076
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077
+			),
1078
+		);
1079
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081
+		$this->_template_args['before_list_table'] = ! empty($event_id)
1082
+			? '<h2>' . sprintf(
1083
+				__('Viewing Registrations for Event: %s', 'event_espresso'),
1084
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
+			) . '</h2>'
1086
+			: '';
1087
+		//need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088
+		/** @var EE_Event $event */
1089
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1090
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1091
+		$datetime = null;
1092
+		if ($event instanceof EE_Event) {
1093
+			$datetimes_on_event = $event->datetimes();
1094
+			if (count($datetimes_on_event) === 1) {
1095
+				$datetime = reset($datetimes_on_event);
1096
+			}
1097
+		}
1098
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1099
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1100
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1101
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103
+			$this->_template_args['before_list_table'] .= $datetime->name();
1104
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1105
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1106
+		}
1107
+		//if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1108
+		//represents
1109
+		if ( ! $datetime instanceof EE_Datetime) {
1110
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1111
+														  . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1112
+					'event_espresso')
1113
+														  . '</p>';
1114
+		}
1115
+		$this->display_admin_list_table_page_with_no_sidebar();
1116
+	}
1117
+
1118
+	/**
1119
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1120
+	 * conditions)
1121
+	 *
1122
+	 * @return void ends the request by a redirect or download
1123
+	 */
1124
+	public function _registrations_checkin_report()
1125
+	{
1126
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1127
+	}
1128
+
1129
+	/**
1130
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1131
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1132
+	 *
1133
+	 * @param array     $request
1134
+	 * @param int  $per_page
1135
+	 * @param bool $count
1136
+	 * @return array
1137
+	 */
1138
+	protected function _get_checkin_query_params_from_request(
1139
+		$request,
1140
+		$per_page = 10,
1141
+		$count = false
1142
+	) {
1143
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1144
+		//unlike the regular registrations list table,
1145
+		$status_ids_array = apply_filters(
1146
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1147
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1148
+		);
1149
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1150
+		return $query_params;
1151
+	}
1152
+
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * Gets registrations for an event
1158
+	 *
1159
+	 * @param int    $per_page
1160
+	 * @param bool   $count whether to return count or data.
1161
+	 * @param bool   $trash
1162
+	 * @param string $orderby
1163
+	 * @return EE_Registration[]|int
1164
+	 * @throws \EE_Error
1165
+	 */
1166
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1167
+	{
1168
+		//normalize some request params that get setup by the parent `get_registrations` method.
1169
+		$request = $this->_req_data;
1170
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
+		$request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
+		if($trash){
1173
+			$request['status'] = 'trash';
1174
+		}
1175
+		$query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1176
+		/**
1177
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1179
+		 * @see EEM_Base::get_all()
1180
+		 */
1181
+		$query_params['group_by'] = '';
1182
+
1183
+		return $count
1184
+			? EEM_Registration::instance()->count($query_params)
1185
+			/** @type EE_Registration[] */
1186
+			: EEM_Registration::instance()->get_all($query_params);
1187
+	}
1188 1188
 
1189 1189
 } //end class Registrations Admin Page
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
     {
36 36
         parent::__construct($routing);
37 37
         if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
38
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
39
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
40
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
38
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
39
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
40
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
41 41
         }
42 42
     }
43 43
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -178,14 +178,14 @@  discard block
 block discarded – undo
178 178
             //enqueue newsletter js
179 179
             wp_enqueue_script(
180 180
                 'ee-newsletter-trigger',
181
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
181
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
182 182
                 array('ee-dialog'),
183 183
                 EVENT_ESPRESSO_VERSION,
184 184
                 true
185 185
             );
186 186
             wp_enqueue_style(
187 187
                 'ee-newsletter-trigger-css',
188
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
188
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
189 189
                 array(),
190 190
                 EVENT_ESPRESSO_VERSION
191 191
             );
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     {
205 205
         wp_register_script(
206 206
             'ee-reg-reports-js',
207
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
207
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
208 208
             array('google-charts'),
209 209
             EVENT_ESPRESSO_VERSION,
210 210
             true
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
             $codes[$field] = implode(', ', array_keys($shortcode_array));
410 410
         }
411 411
         $shortcodes = $codes;
412
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
412
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
413 413
         $form_template_args = array(
414 414
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
415 415
             'form_route'        => 'newsletter_selected_send',
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
      */
571 571
     protected function _registration_reports()
572 572
     {
573
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
573
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
574 574
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
575 575
             $template_path,
576 576
             $this->_reports_template_data,
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
     {
593 593
         $report_ID = 'reg-admin-registrations-per-day-report-dv';
594 594
         $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
595
-        $results = (array)$results;
595
+        $results = (array) $results;
596 596
         $regs = array();
597 597
         $subtitle = '';
598 598
         if ($results) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                 $report_column_values = array();
603 603
                 foreach ($result as $property_name => $property_value) {
604 604
                     $property_value = $property_name === 'Registration_REG_date' ? $property_value
605
-                        : (int)$property_value;
605
+                        : (int) $property_value;
606 606
                     $report_column_values[] = $property_value;
607 607
                     if ($tracker === 0) {
608 608
                         if ($property_name === 'Registration_REG_date') {
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
             array_unshift($regs, $column_titles);
620 620
             //setup the date range.
621 621
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
622
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
622
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
623 623
             $ending_date = new DateTime("now", $DateTimeZone);
624 624
             $subtitle = sprintf(
625 625
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                     '%sThere are currently no registration records in the last month for this report.%s',
640 640
                     'event_espresso'
641 641
                 ),
642
-                '<h2>' . $report_title . '</h2><p>',
642
+                '<h2>'.$report_title.'</h2><p>',
643 643
                 '</p>'
644 644
             ),
645 645
         );
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
     {
660 660
         $report_ID = 'reg-admin-registrations-per-event-report-dv';
661 661
         $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
662
-        $results = (array)$results;
662
+        $results = (array) $results;
663 663
         $regs = array();
664 664
         $subtitle = '';
665 665
         if ($results) {
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
                         $property_value,
673 673
                         4,
674 674
                         '...'
675
-                    ) : (int)$property_value;
675
+                    ) : (int) $property_value;
676 676
                     $report_column_values[] = $property_value;
677 677
                     if ($tracker === 0) {
678 678
                         if ($property_name === 'Registration_Event') {
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
             array_unshift($regs, $column_titles);
690 690
             //setup the date range.
691 691
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
692
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
692
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
693 693
             $ending_date = new DateTime("now", $DateTimeZone);
694 694
             $subtitle = sprintf(
695 695
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
                     '%sThere are currently no registration records in the last month for this report.%s',
710 710
                     'event_espresso'
711 711
                 ),
712
-                '<h2>' . $report_title . '</h2><p>',
712
+                '<h2>'.$report_title.'</h2><p>',
713 713
                 '</p>'
714 714
             ),
715 715
         );
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
         if ($datetime instanceof EE_Datetime) {
758 758
             $datetime_label = $datetime->get_dtt_display_name(true);
759 759
             $datetime_label .= ! empty($datetime_label)
760
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
760
+                ? ' ('.$datetime->get_dtt_display_name().')'
761 761
                 : $datetime->get_dtt_display_name();
762 762
         }
763 763
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
             )
772 772
             : '';
773 773
         $datetime_link = ! empty($datetime_link)
774
-            ? '<a href="' . $datetime_link . '">'
774
+            ? '<a href="'.$datetime_link.'">'
775 775
               . '<span id="checkin-dtt">'
776 776
               . $datetime_label
777 777
               . '</span></a>'
@@ -783,8 +783,8 @@  discard block
 block discarded – undo
783 783
             ? $attendee->get_admin_details_link()
784 784
             : '';
785 785
         $attendee_link = ! empty($attendee_link)
786
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
787
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
786
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
787
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
788 788
               . '<span id="checkin-attendee-name">'
789 789
               . $attendee_name
790 790
               . '</span></a>'
@@ -793,25 +793,25 @@  discard block
 block discarded – undo
793 793
             ? $registration->event()->get_admin_details_link()
794 794
             : '';
795 795
         $event_link = ! empty($event_link)
796
-            ? '<a href="' . $event_link . '"'
797
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
796
+            ? '<a href="'.$event_link.'"'
797
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
798 798
               . '<span id="checkin-event-name">'
799 799
               . $registration->event_name()
800 800
               . '</span>'
801 801
               . '</a>'
802 802
             : '';
803 803
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
804
-            ? '<h2>' . sprintf(
804
+            ? '<h2>'.sprintf(
805 805
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
806 806
                 $attendee_link,
807 807
                 $datetime_link,
808 808
                 $event_link
809
-            ) . '</h2>'
809
+            ).'</h2>'
810 810
             : '';
811 811
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
812
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
812
+            ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : '';
813 813
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
814
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
814
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
815 815
         $this->display_admin_list_table_page_with_no_sidebar();
816 816
     }
817 817
 
@@ -1052,37 +1052,37 @@  discard block
 block discarded – undo
1052 1052
                 'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1053 1053
             ),
1054 1054
             'approved_status'  => array(
1055
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1055
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1056 1056
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1057 1057
             ),
1058 1058
             'cancelled_status' => array(
1059
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1059
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1060 1060
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1061 1061
             ),
1062 1062
             'declined_status'  => array(
1063
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1063
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1064 1064
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1065 1065
             ),
1066 1066
             'not_approved'     => array(
1067
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1067
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1068 1068
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1069 1069
             ),
1070 1070
             'pending_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1071
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1072 1072
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1073 1073
             ),
1074 1074
             'wait_list'        => array(
1075
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1075
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1076 1076
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1077 1077
             ),
1078 1078
         );
1079 1079
         $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1080 1080
         $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1081 1081
         $this->_template_args['before_list_table'] = ! empty($event_id)
1082
-            ? '<h2>' . sprintf(
1082
+            ? '<h2>'.sprintf(
1083 1083
                 __('Viewing Registrations for Event: %s', 'event_espresso'),
1084 1084
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1085
-            ) . '</h2>'
1085
+            ).'</h2>'
1086 1086
             : '';
1087 1087
         //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1088 1088
         /** @var EE_Event $event */
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1102 1102
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1103 1103
             $this->_template_args['before_list_table'] .= $datetime->name();
1104
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1104
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1105 1105
             $this->_template_args['before_list_table'] .= '</span></h2>';
1106 1106
         }
1107 1107
         //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
@@ -1168,11 +1168,11 @@  discard block
 block discarded – undo
1168 1168
         //normalize some request params that get setup by the parent `get_registrations` method.
1169 1169
         $request = $this->_req_data;
1170 1170
         $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1171
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
-        if($trash){
1171
+        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1172
+        if ($trash) {
1173 1173
             $request['status'] = 'trash';
1174 1174
         }
1175
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1175
+        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1176 1176
         /**
1177 1177
          * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1178 1178
          * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
Please login to merge, or discard this patch.
core/EE_Request_Handler.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 
277 277
     /**
278
-     * @param $string
278
+     * @param string $string
279 279
      * @return void
280 280
      */
281 281
     public function add_output($string)
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
 
329 329
     /**
330
-     * @return    mixed
330
+     * @return    boolean
331 331
      */
332 332
     public function is_espresso_page()
333 333
     {
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
     /**
390 390
      * remove param
391 391
      *
392
-     * @param $key
392
+     * @param string $key
393 393
      * @return    void
394 394
      */
395 395
     public function un_set($key)
Please login to merge, or discard this patch.
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -13,389 +13,389 @@
 block discarded – undo
13 13
 final class EE_Request_Handler implements InterminableInterface
14 14
 {
15 15
 
16
-    /**
17
-     * @var EE_Request $request
18
-     */
19
-    private $request;
20
-
21
-    /**
22
-     * @var array $_notice
23
-     */
24
-    private $_notice = array();
25
-
26
-    /**
27
-     * rendered output to be returned to WP
28
-     *
29
-     * @var string $_output
30
-     */
31
-    private $_output = '';
32
-
33
-    /**
34
-     * whether current request is via AJAX
35
-     *
36
-     * @var boolean $ajax
37
-     */
38
-    public $ajax = false;
39
-
40
-    /**
41
-     * whether current request is via AJAX from the frontend of the site
42
-     *
43
-     * @var boolean $front_ajax
44
-     */
45
-    public $front_ajax = false;
46
-
47
-
48
-
49
-    /**
50
-     * @param  EE_Request $request
51
-     */
52
-    public function __construct(EE_Request $request)
53
-    {
54
-        $this->request = $request;
55
-        $this->ajax = $this->request->ajax;
56
-        $this->front_ajax = $this->request->front_ajax;
57
-        do_action('AHEE__EE_Request_Handler__construct__complete');
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @param WP $wp
64
-     * @return void
65
-     * @throws EE_Error
66
-     * @throws ReflectionException
67
-     */
68
-    public function parse_request($wp = null)
69
-    {
70
-        //if somebody forgot to provide us with WP, that's ok because its global
71
-        if (! $wp instanceof WP) {
72
-            global $wp;
73
-        }
74
-        $this->set_request_vars($wp);
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @param WP $wp
81
-     * @return void
82
-     * @throws EE_Error
83
-     * @throws ReflectionException
84
-     */
85
-    public function set_request_vars($wp = null)
86
-    {
87
-        if (! is_admin()) {
88
-            // set request post_id
89
-            $this->request->set('post_id', $this->get_post_id_from_request($wp));
90
-            // set request post name
91
-            $this->request->set('post_name', $this->get_post_name_from_request($wp));
92
-            // set request post_type
93
-            $this->request->set('post_type', $this->get_post_type_from_request($wp));
94
-            // true or false ? is this page being used by EE ?
95
-            $this->set_espresso_page();
96
-        }
97
-    }
98
-
99
-
100
-
101
-    /**
102
-     * @param WP $wp
103
-     * @return int
104
-     */
105
-    public function get_post_id_from_request($wp = null)
106
-    {
107
-        if (! $wp instanceof WP) {
108
-            global $wp;
109
-        }
110
-        $post_id = null;
111
-        if (isset($wp->query_vars['p'])) {
112
-            $post_id = $wp->query_vars['p'];
113
-        }
114
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
115
-            $post_id = $wp->query_vars['page_id'];
116
-        }
117
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118
-            $post_id = basename($wp->request);
119
-        }
120
-        return $post_id;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @param WP $wp
127
-     * @return string
128
-     */
129
-    public function get_post_name_from_request($wp = null)
130
-    {
131
-        if (! $wp instanceof WP) {
132
-            global $wp;
133
-        }
134
-        $post_name = null;
135
-        if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136
-            $post_name = $wp->query_vars['name'];
137
-        }
138
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139
-            $post_name = $wp->query_vars['pagename'];
140
-        }
141
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
142
-            $possible_post_name = basename($wp->request);
143
-            if (! is_numeric($possible_post_name)) {
144
-                /** @type WPDB $wpdb */
145
-                global $wpdb;
146
-                $SQL =
147
-                    "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
148
-                $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
149
-                if ($possible_post_name) {
150
-                    $post_name = $possible_post_name;
151
-                }
152
-            }
153
-        }
154
-        if (! $post_name && $this->get('post_id')) {
155
-            /** @type WPDB $wpdb */
156
-            global $wpdb;
157
-            $SQL =
158
-                "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
159
-            $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
160
-            if ($possible_post_name) {
161
-                $post_name = $possible_post_name;
162
-            }
163
-        }
164
-        return $post_name;
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * @param WP $wp
171
-     * @return mixed
172
-     */
173
-    public function get_post_type_from_request($wp = null)
174
-    {
175
-        if (! $wp instanceof WP) {
176
-            global $wp;
177
-        }
178
-        return isset($wp->query_vars['post_type'])
179
-            ? $wp->query_vars['post_type']
180
-            : null;
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * Just a helper method for getting the url for the displayed page.
187
-     *
188
-     * @param  WP $wp
189
-     * @return string
190
-     */
191
-    public function get_current_page_permalink($wp = null)
192
-    {
193
-        $post_id = $this->get_post_id_from_request($wp);
194
-        if ($post_id) {
195
-            $current_page_permalink = get_permalink($post_id);
196
-        } else {
197
-            if (! $wp instanceof WP) {
198
-                global $wp;
199
-            }
200
-            if ($wp->request) {
201
-                $current_page_permalink = site_url($wp->request);
202
-            } else {
203
-                $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
204
-            }
205
-        }
206
-        return $current_page_permalink;
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * @return bool
213
-     * @throws EE_Error
214
-     * @throws ReflectionException
215
-     */
216
-    public function test_for_espresso_page()
217
-    {
218
-        global $wp;
219
-        /** @type EE_CPT_Strategy $EE_CPT_Strategy */
220
-        $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
221
-        $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
222
-        if (is_array($espresso_CPT_taxonomies)) {
223
-            foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
224
-                if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
225
-                    return true;
226
-                }
227
-            }
228
-        }
229
-        // load espresso CPT endpoints
230
-        $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231
-        $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
-        $post_types = (array)$this->get('post_type');
233
-        foreach ($post_types as $post_type) {
234
-            // was a post name passed ?
235
-            if (isset($post_type_CPT_endpoints[$post_type])) {
236
-                // kk we know this is an espresso page, but is it a specific post ?
237
-                if (! $this->get('post_name')) {
238
-                    // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239
-                    $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240
-                        ? $post_type_CPT_endpoints[$this->get('post_type')]
241
-                        : '';
242
-                    // if the post type matches on of our then set the endpoint
243
-                    if ($post_name) {
244
-                        $this->set('post_name', $post_name);
245
-                    }
246
-                }
247
-                return true;
248
-            }
249
-        }
250
-        return false;
251
-    }
252
-    /**
253
-     * @param $key
254
-     * @param $value
255
-     * @return    void
256
-     */
257
-    public function set_notice($key, $value)
258
-    {
259
-        $this->_notice[$key] = $value;
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     * @param $key
266
-     * @return    mixed
267
-     */
268
-    public function get_notice($key)
269
-    {
270
-        return isset($this->_notice[$key])
271
-            ? $this->_notice[$key]
272
-            : null;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * @param $string
279
-     * @return void
280
-     */
281
-    public function add_output($string)
282
-    {
283
-        $this->_output .= $string;
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * @return string
290
-     */
291
-    public function get_output()
292
-    {
293
-        return $this->_output;
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @param $item
300
-     * @param $key
301
-     */
302
-    public function sanitize_text_field_for_array_walk(&$item, &$key)
303
-    {
304
-        $item = strpos($item, 'email') !== false
305
-            ? sanitize_email($item)
306
-            : sanitize_text_field($item);
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * @param null|bool $value
313
-     * @return void
314
-     * @throws EE_Error
315
-     * @throws ReflectionException
316
-     */
317
-    public function set_espresso_page($value = null)
318
-    {
319
-        $this->request->set(
320
-            'is_espresso_page',
321
-            ! empty($value)
322
-                ? $value
323
-                : $this->test_for_espresso_page()
324
-        );
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * @return    mixed
331
-     */
332
-    public function is_espresso_page()
333
-    {
334
-        return $this->request->is_set('is_espresso_page');
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * returns contents of $_REQUEST
341
-     *
342
-     * @return array
343
-     */
344
-    public function params()
345
-    {
346
-        return $this->request->params();
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * @param      $key
353
-     * @param      $value
354
-     * @param bool $override_ee
355
-     * @return    void
356
-     */
357
-    public function set($key, $value, $override_ee = false)
358
-    {
359
-        $this->request->set($key, $value, $override_ee);
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * @param      $key
366
-     * @param null $default
367
-     * @return    mixed
368
-     */
369
-    public function get($key, $default = null)
370
-    {
371
-        return $this->request->get($key, $default);
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * check if param exists
378
-     *
379
-     * @param $key
380
-     * @return    boolean
381
-     */
382
-    public function is_set($key)
383
-    {
384
-        return $this->request->is_set($key);
385
-    }
386
-
387
-
388
-
389
-    /**
390
-     * remove param
391
-     *
392
-     * @param $key
393
-     * @return    void
394
-     */
395
-    public function un_set($key)
396
-    {
397
-        $this->request->un_set($key);
398
-    }
16
+	/**
17
+	 * @var EE_Request $request
18
+	 */
19
+	private $request;
20
+
21
+	/**
22
+	 * @var array $_notice
23
+	 */
24
+	private $_notice = array();
25
+
26
+	/**
27
+	 * rendered output to be returned to WP
28
+	 *
29
+	 * @var string $_output
30
+	 */
31
+	private $_output = '';
32
+
33
+	/**
34
+	 * whether current request is via AJAX
35
+	 *
36
+	 * @var boolean $ajax
37
+	 */
38
+	public $ajax = false;
39
+
40
+	/**
41
+	 * whether current request is via AJAX from the frontend of the site
42
+	 *
43
+	 * @var boolean $front_ajax
44
+	 */
45
+	public $front_ajax = false;
46
+
47
+
48
+
49
+	/**
50
+	 * @param  EE_Request $request
51
+	 */
52
+	public function __construct(EE_Request $request)
53
+	{
54
+		$this->request = $request;
55
+		$this->ajax = $this->request->ajax;
56
+		$this->front_ajax = $this->request->front_ajax;
57
+		do_action('AHEE__EE_Request_Handler__construct__complete');
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @param WP $wp
64
+	 * @return void
65
+	 * @throws EE_Error
66
+	 * @throws ReflectionException
67
+	 */
68
+	public function parse_request($wp = null)
69
+	{
70
+		//if somebody forgot to provide us with WP, that's ok because its global
71
+		if (! $wp instanceof WP) {
72
+			global $wp;
73
+		}
74
+		$this->set_request_vars($wp);
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @param WP $wp
81
+	 * @return void
82
+	 * @throws EE_Error
83
+	 * @throws ReflectionException
84
+	 */
85
+	public function set_request_vars($wp = null)
86
+	{
87
+		if (! is_admin()) {
88
+			// set request post_id
89
+			$this->request->set('post_id', $this->get_post_id_from_request($wp));
90
+			// set request post name
91
+			$this->request->set('post_name', $this->get_post_name_from_request($wp));
92
+			// set request post_type
93
+			$this->request->set('post_type', $this->get_post_type_from_request($wp));
94
+			// true or false ? is this page being used by EE ?
95
+			$this->set_espresso_page();
96
+		}
97
+	}
98
+
99
+
100
+
101
+	/**
102
+	 * @param WP $wp
103
+	 * @return int
104
+	 */
105
+	public function get_post_id_from_request($wp = null)
106
+	{
107
+		if (! $wp instanceof WP) {
108
+			global $wp;
109
+		}
110
+		$post_id = null;
111
+		if (isset($wp->query_vars['p'])) {
112
+			$post_id = $wp->query_vars['p'];
113
+		}
114
+		if (! $post_id && isset($wp->query_vars['page_id'])) {
115
+			$post_id = $wp->query_vars['page_id'];
116
+		}
117
+		if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118
+			$post_id = basename($wp->request);
119
+		}
120
+		return $post_id;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @param WP $wp
127
+	 * @return string
128
+	 */
129
+	public function get_post_name_from_request($wp = null)
130
+	{
131
+		if (! $wp instanceof WP) {
132
+			global $wp;
133
+		}
134
+		$post_name = null;
135
+		if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136
+			$post_name = $wp->query_vars['name'];
137
+		}
138
+		if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139
+			$post_name = $wp->query_vars['pagename'];
140
+		}
141
+		if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
142
+			$possible_post_name = basename($wp->request);
143
+			if (! is_numeric($possible_post_name)) {
144
+				/** @type WPDB $wpdb */
145
+				global $wpdb;
146
+				$SQL =
147
+					"SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
148
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
149
+				if ($possible_post_name) {
150
+					$post_name = $possible_post_name;
151
+				}
152
+			}
153
+		}
154
+		if (! $post_name && $this->get('post_id')) {
155
+			/** @type WPDB $wpdb */
156
+			global $wpdb;
157
+			$SQL =
158
+				"SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
159
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
160
+			if ($possible_post_name) {
161
+				$post_name = $possible_post_name;
162
+			}
163
+		}
164
+		return $post_name;
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * @param WP $wp
171
+	 * @return mixed
172
+	 */
173
+	public function get_post_type_from_request($wp = null)
174
+	{
175
+		if (! $wp instanceof WP) {
176
+			global $wp;
177
+		}
178
+		return isset($wp->query_vars['post_type'])
179
+			? $wp->query_vars['post_type']
180
+			: null;
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * Just a helper method for getting the url for the displayed page.
187
+	 *
188
+	 * @param  WP $wp
189
+	 * @return string
190
+	 */
191
+	public function get_current_page_permalink($wp = null)
192
+	{
193
+		$post_id = $this->get_post_id_from_request($wp);
194
+		if ($post_id) {
195
+			$current_page_permalink = get_permalink($post_id);
196
+		} else {
197
+			if (! $wp instanceof WP) {
198
+				global $wp;
199
+			}
200
+			if ($wp->request) {
201
+				$current_page_permalink = site_url($wp->request);
202
+			} else {
203
+				$current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
204
+			}
205
+		}
206
+		return $current_page_permalink;
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * @return bool
213
+	 * @throws EE_Error
214
+	 * @throws ReflectionException
215
+	 */
216
+	public function test_for_espresso_page()
217
+	{
218
+		global $wp;
219
+		/** @type EE_CPT_Strategy $EE_CPT_Strategy */
220
+		$EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
221
+		$espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
222
+		if (is_array($espresso_CPT_taxonomies)) {
223
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
224
+				if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
225
+					return true;
226
+				}
227
+			}
228
+		}
229
+		// load espresso CPT endpoints
230
+		$espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
+		$post_types = (array)$this->get('post_type');
233
+		foreach ($post_types as $post_type) {
234
+			// was a post name passed ?
235
+			if (isset($post_type_CPT_endpoints[$post_type])) {
236
+				// kk we know this is an espresso page, but is it a specific post ?
237
+				if (! $this->get('post_name')) {
238
+					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239
+					$post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240
+						? $post_type_CPT_endpoints[$this->get('post_type')]
241
+						: '';
242
+					// if the post type matches on of our then set the endpoint
243
+					if ($post_name) {
244
+						$this->set('post_name', $post_name);
245
+					}
246
+				}
247
+				return true;
248
+			}
249
+		}
250
+		return false;
251
+	}
252
+	/**
253
+	 * @param $key
254
+	 * @param $value
255
+	 * @return    void
256
+	 */
257
+	public function set_notice($key, $value)
258
+	{
259
+		$this->_notice[$key] = $value;
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 * @param $key
266
+	 * @return    mixed
267
+	 */
268
+	public function get_notice($key)
269
+	{
270
+		return isset($this->_notice[$key])
271
+			? $this->_notice[$key]
272
+			: null;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * @param $string
279
+	 * @return void
280
+	 */
281
+	public function add_output($string)
282
+	{
283
+		$this->_output .= $string;
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * @return string
290
+	 */
291
+	public function get_output()
292
+	{
293
+		return $this->_output;
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @param $item
300
+	 * @param $key
301
+	 */
302
+	public function sanitize_text_field_for_array_walk(&$item, &$key)
303
+	{
304
+		$item = strpos($item, 'email') !== false
305
+			? sanitize_email($item)
306
+			: sanitize_text_field($item);
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * @param null|bool $value
313
+	 * @return void
314
+	 * @throws EE_Error
315
+	 * @throws ReflectionException
316
+	 */
317
+	public function set_espresso_page($value = null)
318
+	{
319
+		$this->request->set(
320
+			'is_espresso_page',
321
+			! empty($value)
322
+				? $value
323
+				: $this->test_for_espresso_page()
324
+		);
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * @return    mixed
331
+	 */
332
+	public function is_espresso_page()
333
+	{
334
+		return $this->request->is_set('is_espresso_page');
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * returns contents of $_REQUEST
341
+	 *
342
+	 * @return array
343
+	 */
344
+	public function params()
345
+	{
346
+		return $this->request->params();
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * @param      $key
353
+	 * @param      $value
354
+	 * @param bool $override_ee
355
+	 * @return    void
356
+	 */
357
+	public function set($key, $value, $override_ee = false)
358
+	{
359
+		$this->request->set($key, $value, $override_ee);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * @param      $key
366
+	 * @param null $default
367
+	 * @return    mixed
368
+	 */
369
+	public function get($key, $default = null)
370
+	{
371
+		return $this->request->get($key, $default);
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * check if param exists
378
+	 *
379
+	 * @param $key
380
+	 * @return    boolean
381
+	 */
382
+	public function is_set($key)
383
+	{
384
+		return $this->request->is_set($key);
385
+	}
386
+
387
+
388
+
389
+	/**
390
+	 * remove param
391
+	 *
392
+	 * @param $key
393
+	 * @return    void
394
+	 */
395
+	public function un_set($key)
396
+	{
397
+		$this->request->un_set($key);
398
+	}
399 399
 
400 400
 
401 401
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public function parse_request($wp = null)
69 69
     {
70 70
         //if somebody forgot to provide us with WP, that's ok because its global
71
-        if (! $wp instanceof WP) {
71
+        if ( ! $wp instanceof WP) {
72 72
             global $wp;
73 73
         }
74 74
         $this->set_request_vars($wp);
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function set_request_vars($wp = null)
86 86
     {
87
-        if (! is_admin()) {
87
+        if ( ! is_admin()) {
88 88
             // set request post_id
89 89
             $this->request->set('post_id', $this->get_post_id_from_request($wp));
90 90
             // set request post name
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function get_post_id_from_request($wp = null)
106 106
     {
107
-        if (! $wp instanceof WP) {
107
+        if ( ! $wp instanceof WP) {
108 108
             global $wp;
109 109
         }
110 110
         $post_id = null;
111 111
         if (isset($wp->query_vars['p'])) {
112 112
             $post_id = $wp->query_vars['p'];
113 113
         }
114
-        if (! $post_id && isset($wp->query_vars['page_id'])) {
114
+        if ( ! $post_id && isset($wp->query_vars['page_id'])) {
115 115
             $post_id = $wp->query_vars['page_id'];
116 116
         }
117
-        if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
117
+        if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) {
118 118
             $post_id = basename($wp->request);
119 119
         }
120 120
         return $post_id;
@@ -128,19 +128,19 @@  discard block
 block discarded – undo
128 128
      */
129 129
     public function get_post_name_from_request($wp = null)
130 130
     {
131
-        if (! $wp instanceof WP) {
131
+        if ( ! $wp instanceof WP) {
132 132
             global $wp;
133 133
         }
134 134
         $post_name = null;
135 135
         if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
136 136
             $post_name = $wp->query_vars['name'];
137 137
         }
138
-        if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
138
+        if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
139 139
             $post_name = $wp->query_vars['pagename'];
140 140
         }
141
-        if (! $post_name && $wp->request !== null && ! empty($wp->request)) {
141
+        if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) {
142 142
             $possible_post_name = basename($wp->request);
143
-            if (! is_numeric($possible_post_name)) {
143
+            if ( ! is_numeric($possible_post_name)) {
144 144
                 /** @type WPDB $wpdb */
145 145
                 global $wpdb;
146 146
                 $SQL =
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                 }
152 152
             }
153 153
         }
154
-        if (! $post_name && $this->get('post_id')) {
154
+        if ( ! $post_name && $this->get('post_id')) {
155 155
             /** @type WPDB $wpdb */
156 156
             global $wpdb;
157 157
             $SQL =
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function get_post_type_from_request($wp = null)
174 174
     {
175
-        if (! $wp instanceof WP) {
175
+        if ( ! $wp instanceof WP) {
176 176
             global $wp;
177 177
         }
178 178
         return isset($wp->query_vars['post_type'])
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         if ($post_id) {
195 195
             $current_page_permalink = get_permalink($post_id);
196 196
         } else {
197
-            if (! $wp instanceof WP) {
197
+            if ( ! $wp instanceof WP) {
198 198
                 global $wp;
199 199
             }
200 200
             if ($wp->request) {
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
         // load espresso CPT endpoints
230 230
         $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
231 231
         $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
232
-        $post_types = (array)$this->get('post_type');
232
+        $post_types = (array) $this->get('post_type');
233 233
         foreach ($post_types as $post_type) {
234 234
             // was a post name passed ?
235 235
             if (isset($post_type_CPT_endpoints[$post_type])) {
236 236
                 // kk we know this is an espresso page, but is it a specific post ?
237
-                if (! $this->get('post_name')) {
237
+                if ( ! $this->get('post_name')) {
238 238
                     // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
239 239
                     $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
240 240
                         ? $post_type_CPT_endpoints[$this->get('post_type')]
Please login to merge, or discard this patch.
core/EE_Module_Request_Router.core.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -17,248 +17,248 @@
 block discarded – undo
17 17
 final class EE_Module_Request_Router implements InterminableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var EE_Request $request
22
-     */
23
-    private $request;
20
+	/**
21
+	 * @var EE_Request $request
22
+	 */
23
+	private $request;
24 24
 
25
-    /**
26
-     * @var array $_previous_routes
27
-     */
28
-    private static $_previous_routes = array();
25
+	/**
26
+	 * @var array $_previous_routes
27
+	 */
28
+	private static $_previous_routes = array();
29 29
 
30
-    /**
31
-     * @var WP_Query $WP_Query
32
-     */
33
-    public $WP_Query;
30
+	/**
31
+	 * @var WP_Query $WP_Query
32
+	 */
33
+	public $WP_Query;
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * EE_Module_Request_Router constructor.
39
-     *
40
-     * @param EE_Request $request
41
-     */
42
-    public function __construct(EE_Request $request)
43
-    {
44
-        $this->request = $request;
45
-    }
37
+	/**
38
+	 * EE_Module_Request_Router constructor.
39
+	 *
40
+	 * @param EE_Request $request
41
+	 */
42
+	public function __construct(EE_Request $request)
43
+	{
44
+		$this->request = $request;
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * on the first call  to this method, it checks the EE_Request_Handler for a "route"
51
-     * on subsequent calls to this method,
52
-     * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
53
-     * and checks if the last called route has any forwarding routes registered for it
54
-     *
55
-     * @param WP_Query $WP_Query
56
-     * @return NULL|string
57
-     * @throws EE_Error
58
-     * @throws ReflectionException
59
-     */
60
-    public function get_route(WP_Query $WP_Query)
61
-    {
62
-        $this->WP_Query = $WP_Query;
63
-        // assume this if first route being called
64
-        $previous_route = false;
65
-        // but is it really ???
66
-        if (! empty(self::$_previous_routes)) {
67
-            // get last run route
68
-            $previous_routes = array_values(self::$_previous_routes);
69
-            $previous_route = array_pop($previous_routes);
70
-        }
71
-        //  has another route already been run ?
72
-        if ($previous_route) {
73
-            // check if  forwarding has been set
74
-            $current_route = $this->get_forward($previous_route);
75
-            try {
76
-                //check for recursive forwarding
77
-                if (isset(self::$_previous_routes[$current_route])) {
78
-                    throw new EE_Error(
79
-                        sprintf(
80
-                            __(
81
-                                'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
82
-                                'event_espresso'
83
-                            ),
84
-                            $current_route
85
-                        )
86
-                    );
87
-                }
88
-            } catch (EE_Error $e) {
89
-                $e->get_error();
90
-                return null;
91
-            }
92
-        } else {
93
-            // first route called
94
-            $current_route = null;
95
-            // grab all routes
96
-            $routes = EE_Config::get_routes();
97
-            //d( $routes );
98
-            foreach ($routes as $key => $route) {
99
-                // check request for module route
100
-                if ($this->request->is_set($key)) {
101
-                    $current_route = sanitize_text_field($this->request->get($key));
102
-                    if ($current_route) {
103
-                        $current_route = array($key, $current_route);
104
-                        break;
105
-                    }
106
-                }
107
-            }
108
-        }
109
-        // sorry, but I can't read what you route !
110
-        if (empty($current_route)) {
111
-            return null;
112
-        }
113
-        //add route to previous routes array
114
-        self::$_previous_routes[] = $current_route;
115
-        return $current_route;
116
-    }
49
+	/**
50
+	 * on the first call  to this method, it checks the EE_Request_Handler for a "route"
51
+	 * on subsequent calls to this method,
52
+	 * instead of checking the EE_Request_Handler for a route, it checks the previous routes array,
53
+	 * and checks if the last called route has any forwarding routes registered for it
54
+	 *
55
+	 * @param WP_Query $WP_Query
56
+	 * @return NULL|string
57
+	 * @throws EE_Error
58
+	 * @throws ReflectionException
59
+	 */
60
+	public function get_route(WP_Query $WP_Query)
61
+	{
62
+		$this->WP_Query = $WP_Query;
63
+		// assume this if first route being called
64
+		$previous_route = false;
65
+		// but is it really ???
66
+		if (! empty(self::$_previous_routes)) {
67
+			// get last run route
68
+			$previous_routes = array_values(self::$_previous_routes);
69
+			$previous_route = array_pop($previous_routes);
70
+		}
71
+		//  has another route already been run ?
72
+		if ($previous_route) {
73
+			// check if  forwarding has been set
74
+			$current_route = $this->get_forward($previous_route);
75
+			try {
76
+				//check for recursive forwarding
77
+				if (isset(self::$_previous_routes[$current_route])) {
78
+					throw new EE_Error(
79
+						sprintf(
80
+							__(
81
+								'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
82
+								'event_espresso'
83
+							),
84
+							$current_route
85
+						)
86
+					);
87
+				}
88
+			} catch (EE_Error $e) {
89
+				$e->get_error();
90
+				return null;
91
+			}
92
+		} else {
93
+			// first route called
94
+			$current_route = null;
95
+			// grab all routes
96
+			$routes = EE_Config::get_routes();
97
+			//d( $routes );
98
+			foreach ($routes as $key => $route) {
99
+				// check request for module route
100
+				if ($this->request->is_set($key)) {
101
+					$current_route = sanitize_text_field($this->request->get($key));
102
+					if ($current_route) {
103
+						$current_route = array($key, $current_route);
104
+						break;
105
+					}
106
+				}
107
+			}
108
+		}
109
+		// sorry, but I can't read what you route !
110
+		if (empty($current_route)) {
111
+			return null;
112
+		}
113
+		//add route to previous routes array
114
+		self::$_previous_routes[] = $current_route;
115
+		return $current_route;
116
+	}
117 117
 
118 118
 
119 119
 
120
-    /**
121
-     * this method simply takes a valid route, and resolves what module class method the route points to
122
-     *
123
-     * @param string $key
124
-     * @param string $current_route
125
-     * @return mixed EED_Module | boolean
126
-     * @throws EE_Error
127
-     * @throws ReflectionException
128
-     */
129
-    public function resolve_route($key, $current_route)
130
-    {
131
-        // get module method that route has been mapped to
132
-        $module_method = EE_Config::get_route($current_route, $key);
133
-        // verify result was returned
134
-        if (empty($module_method)) {
135
-            $msg = sprintf(
136
-                __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
137
-                $current_route
138
-            );
139
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
140
-            return false;
141
-        }
142
-        // verify that result is an array
143
-        if (! is_array($module_method)) {
144
-            $msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
145
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
146
-            return false;
147
-        }
148
-        // grab module name
149
-        $module_name = $module_method[0];
150
-        // verify that a class method was registered properly
151
-        if (! isset($module_method[1])) {
152
-            $msg = sprintf(
153
-                __('A class method for the %s  route has not been properly registered.', 'event_espresso'),
154
-                $current_route
155
-            );
156
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
157
-            return false;
158
-        }
159
-        // grab method
160
-        $method = $module_method[1];
161
-        // verify that class exists
162
-        if (! class_exists($module_name)) {
163
-            $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
164
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
165
-            return false;
166
-        }
167
-        // verify that method exists
168
-        if (! method_exists($module_name, $method)) {
169
-            $msg = sprintf(
170
-                __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route
171
-            );
172
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
173
-            return false;
174
-        }
175
-        // instantiate module and call route method
176
-        return $this->_module_router($module_name, $method);
177
-    }
120
+	/**
121
+	 * this method simply takes a valid route, and resolves what module class method the route points to
122
+	 *
123
+	 * @param string $key
124
+	 * @param string $current_route
125
+	 * @return mixed EED_Module | boolean
126
+	 * @throws EE_Error
127
+	 * @throws ReflectionException
128
+	 */
129
+	public function resolve_route($key, $current_route)
130
+	{
131
+		// get module method that route has been mapped to
132
+		$module_method = EE_Config::get_route($current_route, $key);
133
+		// verify result was returned
134
+		if (empty($module_method)) {
135
+			$msg = sprintf(
136
+				__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
137
+				$current_route
138
+			);
139
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
140
+			return false;
141
+		}
142
+		// verify that result is an array
143
+		if (! is_array($module_method)) {
144
+			$msg = sprintf(__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
145
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
146
+			return false;
147
+		}
148
+		// grab module name
149
+		$module_name = $module_method[0];
150
+		// verify that a class method was registered properly
151
+		if (! isset($module_method[1])) {
152
+			$msg = sprintf(
153
+				__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
154
+				$current_route
155
+			);
156
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
157
+			return false;
158
+		}
159
+		// grab method
160
+		$method = $module_method[1];
161
+		// verify that class exists
162
+		if (! class_exists($module_name)) {
163
+			$msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name);
164
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
165
+			return false;
166
+		}
167
+		// verify that method exists
168
+		if (! method_exists($module_name, $method)) {
169
+			$msg = sprintf(
170
+				__('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route
171
+			);
172
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
173
+			return false;
174
+		}
175
+		// instantiate module and call route method
176
+		return $this->_module_router($module_name, $method);
177
+	}
178 178
 
179 179
 
180 180
 
181
-    /**
182
-     * this method instantiates modules and calls the method that was defined when the route was registered
183
-     *
184
-     * @param string $module_name
185
-     * @return EED_Module|object|null
186
-     * @throws ReflectionException
187
-     */
188
-    public static function module_factory($module_name)
189
-    {
190
-        if ($module_name === 'EED_Module') {
191
-            EE_Error::add_error(
192
-                sprintf(
193
-                    __(
194
-                        'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
195
-                        'event_espresso'
196
-                    ), $module_name
197
-                ), __FILE__, __FUNCTION__, __LINE__
198
-            );
199
-            return null;
200
-        }
201
-        // instantiate module class
202
-        $module = new $module_name();
203
-        // ensure that class is actually a module
204
-        if (! $module instanceof EED_Module) {
205
-            EE_Error::add_error(
206
-                sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
207
-                __FILE__, __FUNCTION__, __LINE__
208
-            );
209
-            return null;
210
-        }
211
-        return $module;
212
-    }
181
+	/**
182
+	 * this method instantiates modules and calls the method that was defined when the route was registered
183
+	 *
184
+	 * @param string $module_name
185
+	 * @return EED_Module|object|null
186
+	 * @throws ReflectionException
187
+	 */
188
+	public static function module_factory($module_name)
189
+	{
190
+		if ($module_name === 'EED_Module') {
191
+			EE_Error::add_error(
192
+				sprintf(
193
+					__(
194
+						'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
195
+						'event_espresso'
196
+					), $module_name
197
+				), __FILE__, __FUNCTION__, __LINE__
198
+			);
199
+			return null;
200
+		}
201
+		// instantiate module class
202
+		$module = new $module_name();
203
+		// ensure that class is actually a module
204
+		if (! $module instanceof EED_Module) {
205
+			EE_Error::add_error(
206
+				sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
207
+				__FILE__, __FUNCTION__, __LINE__
208
+			);
209
+			return null;
210
+		}
211
+		return $module;
212
+	}
213 213
 
214 214
 
215 215
 
216
-    /**
217
-     * this method instantiates modules and calls the method that was defined when the route was registered
218
-     *
219
-     * @param string $module_name
220
-     * @param string $method
221
-     * @return EED_Module|null
222
-     * @throws EE_Error
223
-     * @throws ReflectionException
224
-     */
225
-    private function _module_router($module_name, $method)
226
-    {
227
-        // instantiate module class
228
-        $module = EE_Module_Request_Router::module_factory($module_name);
229
-        if ($module instanceof EED_Module) {
230
-            // and call whatever action the route was for
231
-            try {
232
-                call_user_func(array($module, $method), $this->WP_Query);
233
-            } catch (EE_Error $e) {
234
-                $e->get_error();
235
-                return null;
236
-            }
237
-        }
238
-        return $module;
239
-    }
216
+	/**
217
+	 * this method instantiates modules and calls the method that was defined when the route was registered
218
+	 *
219
+	 * @param string $module_name
220
+	 * @param string $method
221
+	 * @return EED_Module|null
222
+	 * @throws EE_Error
223
+	 * @throws ReflectionException
224
+	 */
225
+	private function _module_router($module_name, $method)
226
+	{
227
+		// instantiate module class
228
+		$module = EE_Module_Request_Router::module_factory($module_name);
229
+		if ($module instanceof EED_Module) {
230
+			// and call whatever action the route was for
231
+			try {
232
+				call_user_func(array($module, $method), $this->WP_Query);
233
+			} catch (EE_Error $e) {
234
+				$e->get_error();
235
+				return null;
236
+			}
237
+		}
238
+		return $module;
239
+	}
240 240
 
241 241
 
242 242
 
243
-    /**
244
-     * @param $current_route
245
-     * @return string
246
-     */
247
-    public function get_forward($current_route)
248
-    {
249
-        return EE_Config::get_forward($current_route);
250
-    }
243
+	/**
244
+	 * @param $current_route
245
+	 * @return string
246
+	 */
247
+	public function get_forward($current_route)
248
+	{
249
+		return EE_Config::get_forward($current_route);
250
+	}
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * @param $current_route
256
-     * @return string
257
-     */
258
-    public function get_view($current_route)
259
-    {
260
-        return EE_Config::get_view($current_route);
261
-    }
254
+	/**
255
+	 * @param $current_route
256
+	 * @return string
257
+	 */
258
+	public function get_view($current_route)
259
+	{
260
+		return EE_Config::get_view($current_route);
261
+	}
262 262
 
263 263
 
264 264
 }
Please login to merge, or discard this patch.
core/request_stack/EE_Request.core.php 2 patches
Indentation   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -15,289 +15,289 @@
 block discarded – undo
15 15
 class EE_Request implements InterminableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * $_GET parameters
20
-     *
21
-     * @var array $_get
22
-     */
23
-    private $_get;
24
-
25
-    /**
26
-     * $_POST parameters
27
-     *
28
-     * @var    array $_post
29
-     */
30
-    private $_post;
31
-
32
-    /**
33
-     * $_COOKIE parameters
34
-     *
35
-     * @var array $_cookie
36
-     */
37
-    private $_cookie;
38
-
39
-    /**
40
-     * $_REQUEST parameters
41
-     *
42
-     * @var array $_params
43
-     */
44
-    private $_params;
45
-
46
-    /**
47
-     * whether current request is via AJAX
48
-     *
49
-     * @access public
50
-     */
51
-    public $ajax = false;
52
-
53
-    /**
54
-     * whether current request is via AJAX from the frontend of the site
55
-     *
56
-     * @access public
57
-     */
58
-    public $front_ajax = false;
59
-
60
-    /**
61
-     * IP address for request
62
-     *
63
-     * @var string $_ip_address
64
-     */
65
-    private $_ip_address;
66
-
67
-
68
-
69
-    /**
70
-     * class constructor
71
-     *
72
-     * @access    public
73
-     * @param array $get
74
-     * @param array $post
75
-     * @param array $cookie
76
-     */
77
-    public function __construct(array $get, array $post, array $cookie)
78
-    {
79
-        // grab request vars
80
-        $this->_get = (array)$get;
81
-        $this->_post = (array)$post;
82
-        $this->_cookie = (array)$cookie;
83
-        $this->_params = array_merge($this->_get, $this->_post);
84
-        // AJAX ???
85
-        $this->ajax = defined('DOING_AJAX') ? true : false;
86
-        $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1;
87
-        // grab user IP
88
-        $this->_ip_address = $this->_visitor_ip();
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * @return array
95
-     */
96
-    public function get_params()
97
-    {
98
-        return $this->_get;
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     * @return array
105
-     */
106
-    public function post_params()
107
-    {
108
-        return $this->_post;
109
-    }
110
-
111
-
112
-
113
-    /**
114
-     * @return array
115
-     */
116
-    public function cookie_params()
117
-    {
118
-        return $this->_cookie;
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * returns contents of $_REQUEST
125
-     *
126
-     * @return array
127
-     */
128
-    public function params()
129
-    {
130
-        return $this->_params;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * @param      $key
137
-     * @param      $value
138
-     * @param bool $override_ee
139
-     * @return    void
140
-     */
141
-    public function set($key, $value, $override_ee = false)
142
-    {
143
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
144
-        if (
145
-            $key !== 'ee'
146
-            || ($key === 'ee' && empty($this->_params['ee']))
147
-            || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
148
-        ) {
149
-            $this->_params[$key] = $value;
150
-        }
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * returns   the value for a request param if the given key exists
157
-     *
158
-     * @param       $key
159
-     * @param null  $default
160
-     * @return mixed
161
-     */
162
-    public function get($key, $default = null)
163
-    {
164
-        return $this->request_parameter_drill_down($key, $default, 'get');
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * check if param exists
171
-     * @param       $key
172
-     * @return bool
173
-     */
174
-    public function is_set($key)
175
-    {
176
-        return $this->request_parameter_drill_down($key);
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * the supplied key can be a simple string to represent a "top-level" request parameter
183
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
184
-     * by using square brackets to surround keys for deeper array elements.
185
-     * For example :
186
-     * if the supplied $key was: "first[second][third]"
187
-     * then this will attempt to drill down into the request parameter array to find a value.
188
-     * Given the following request parameters:
189
-     *  array(
190
-     *      'first' => array(
191
-     *          'second' => array(
192
-     *              'third' => 'has a value'
193
-     *          )
194
-     *      )
195
-     *  )
196
-     * would return true
197
-     *
198
-     * @param string $is_set_or_get
199
-     * @param        $key
200
-     * @param null   $default
201
-     * @param array  $request_params
202
-     * @return bool|mixed|null
203
-     */
204
-    private function request_parameter_drill_down(
205
-        $key,
206
-        $default = null,
207
-        $is_set_or_get = 'is_set',
208
-        array $request_params = array()
209
-    ) {
210
-        $request_params = ! empty($request_params)
211
-            ? $request_params
212
-            : $this->_params;
213
-        // does incoming key represent an array like 'first[second][third]'  ?
214
-        if (strpos($key, '[') !== false) {
215
-            // turn it into an actual array
216
-            $key = str_replace(']', '', $key);
217
-            $keys = explode('[', $key);
218
-            $key = array_shift($keys);
219
-            // check if top level key exists
220
-            if (isset($request_params[$key])) {
221
-                // build a new key to pass along like: 'second[third]'
222
-                // or just 'second' depending on depth of keys
223
-                $key_string = array_shift($keys);
224
-                if (! empty($keys)) {
225
-                    $key_string .= '[' . implode('][', $keys) . ']';
226
-                }
227
-                return $this->request_parameter_drill_down(
228
-                    $key_string,
229
-                    $default,
230
-                    $is_set_or_get,
231
-                    $request_params[$key]
232
-                );
233
-            }
234
-        }
235
-        if ($is_set_or_get === 'is_set') {
236
-            return isset($request_params[$key]);
237
-        }
238
-        return isset($request_params[$key])
239
-            ? $request_params[$key]
240
-            : $default;
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * remove param
247
-     * @param      $key
248
-     * @param bool $unset_from_global_too
249
-     */
250
-    public function un_set($key, $unset_from_global_too = false)
251
-    {
252
-        unset($this->_params[$key]);
253
-        if ($unset_from_global_too) {
254
-            unset($_REQUEST[$key]);
255
-        }
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * @return string
262
-     */
263
-    public function ip_address()
264
-    {
265
-        return $this->_ip_address;
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * _visitor_ip
272
-     *    attempt to get IP address of current visitor from server
273
-     * plz see: http://stackoverflow.com/a/2031935/1475279
274
-     *
275
-     * @access public
276
-     * @return string
277
-     */
278
-    private function _visitor_ip()
279
-    {
280
-        $visitor_ip = '0.0.0.0';
281
-        $server_keys = array(
282
-            'HTTP_CLIENT_IP',
283
-            'HTTP_X_FORWARDED_FOR',
284
-            'HTTP_X_FORWARDED',
285
-            'HTTP_X_CLUSTER_CLIENT_IP',
286
-            'HTTP_FORWARDED_FOR',
287
-            'HTTP_FORWARDED',
288
-            'REMOTE_ADDR',
289
-        );
290
-        foreach ($server_keys as $key) {
291
-            if (isset($_SERVER[$key])) {
292
-                foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
293
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
294
-                        $visitor_ip = $ip;
295
-                    }
296
-                }
297
-            }
298
-        }
299
-        return $visitor_ip;
300
-    }
18
+	/**
19
+	 * $_GET parameters
20
+	 *
21
+	 * @var array $_get
22
+	 */
23
+	private $_get;
24
+
25
+	/**
26
+	 * $_POST parameters
27
+	 *
28
+	 * @var    array $_post
29
+	 */
30
+	private $_post;
31
+
32
+	/**
33
+	 * $_COOKIE parameters
34
+	 *
35
+	 * @var array $_cookie
36
+	 */
37
+	private $_cookie;
38
+
39
+	/**
40
+	 * $_REQUEST parameters
41
+	 *
42
+	 * @var array $_params
43
+	 */
44
+	private $_params;
45
+
46
+	/**
47
+	 * whether current request is via AJAX
48
+	 *
49
+	 * @access public
50
+	 */
51
+	public $ajax = false;
52
+
53
+	/**
54
+	 * whether current request is via AJAX from the frontend of the site
55
+	 *
56
+	 * @access public
57
+	 */
58
+	public $front_ajax = false;
59
+
60
+	/**
61
+	 * IP address for request
62
+	 *
63
+	 * @var string $_ip_address
64
+	 */
65
+	private $_ip_address;
66
+
67
+
68
+
69
+	/**
70
+	 * class constructor
71
+	 *
72
+	 * @access    public
73
+	 * @param array $get
74
+	 * @param array $post
75
+	 * @param array $cookie
76
+	 */
77
+	public function __construct(array $get, array $post, array $cookie)
78
+	{
79
+		// grab request vars
80
+		$this->_get = (array)$get;
81
+		$this->_post = (array)$post;
82
+		$this->_cookie = (array)$cookie;
83
+		$this->_params = array_merge($this->_get, $this->_post);
84
+		// AJAX ???
85
+		$this->ajax = defined('DOING_AJAX') ? true : false;
86
+		$this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1;
87
+		// grab user IP
88
+		$this->_ip_address = $this->_visitor_ip();
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * @return array
95
+	 */
96
+	public function get_params()
97
+	{
98
+		return $this->_get;
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 * @return array
105
+	 */
106
+	public function post_params()
107
+	{
108
+		return $this->_post;
109
+	}
110
+
111
+
112
+
113
+	/**
114
+	 * @return array
115
+	 */
116
+	public function cookie_params()
117
+	{
118
+		return $this->_cookie;
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * returns contents of $_REQUEST
125
+	 *
126
+	 * @return array
127
+	 */
128
+	public function params()
129
+	{
130
+		return $this->_params;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * @param      $key
137
+	 * @param      $value
138
+	 * @param bool $override_ee
139
+	 * @return    void
140
+	 */
141
+	public function set($key, $value, $override_ee = false)
142
+	{
143
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
144
+		if (
145
+			$key !== 'ee'
146
+			|| ($key === 'ee' && empty($this->_params['ee']))
147
+			|| ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
148
+		) {
149
+			$this->_params[$key] = $value;
150
+		}
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * returns   the value for a request param if the given key exists
157
+	 *
158
+	 * @param       $key
159
+	 * @param null  $default
160
+	 * @return mixed
161
+	 */
162
+	public function get($key, $default = null)
163
+	{
164
+		return $this->request_parameter_drill_down($key, $default, 'get');
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * check if param exists
171
+	 * @param       $key
172
+	 * @return bool
173
+	 */
174
+	public function is_set($key)
175
+	{
176
+		return $this->request_parameter_drill_down($key);
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
183
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
184
+	 * by using square brackets to surround keys for deeper array elements.
185
+	 * For example :
186
+	 * if the supplied $key was: "first[second][third]"
187
+	 * then this will attempt to drill down into the request parameter array to find a value.
188
+	 * Given the following request parameters:
189
+	 *  array(
190
+	 *      'first' => array(
191
+	 *          'second' => array(
192
+	 *              'third' => 'has a value'
193
+	 *          )
194
+	 *      )
195
+	 *  )
196
+	 * would return true
197
+	 *
198
+	 * @param string $is_set_or_get
199
+	 * @param        $key
200
+	 * @param null   $default
201
+	 * @param array  $request_params
202
+	 * @return bool|mixed|null
203
+	 */
204
+	private function request_parameter_drill_down(
205
+		$key,
206
+		$default = null,
207
+		$is_set_or_get = 'is_set',
208
+		array $request_params = array()
209
+	) {
210
+		$request_params = ! empty($request_params)
211
+			? $request_params
212
+			: $this->_params;
213
+		// does incoming key represent an array like 'first[second][third]'  ?
214
+		if (strpos($key, '[') !== false) {
215
+			// turn it into an actual array
216
+			$key = str_replace(']', '', $key);
217
+			$keys = explode('[', $key);
218
+			$key = array_shift($keys);
219
+			// check if top level key exists
220
+			if (isset($request_params[$key])) {
221
+				// build a new key to pass along like: 'second[third]'
222
+				// or just 'second' depending on depth of keys
223
+				$key_string = array_shift($keys);
224
+				if (! empty($keys)) {
225
+					$key_string .= '[' . implode('][', $keys) . ']';
226
+				}
227
+				return $this->request_parameter_drill_down(
228
+					$key_string,
229
+					$default,
230
+					$is_set_or_get,
231
+					$request_params[$key]
232
+				);
233
+			}
234
+		}
235
+		if ($is_set_or_get === 'is_set') {
236
+			return isset($request_params[$key]);
237
+		}
238
+		return isset($request_params[$key])
239
+			? $request_params[$key]
240
+			: $default;
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * remove param
247
+	 * @param      $key
248
+	 * @param bool $unset_from_global_too
249
+	 */
250
+	public function un_set($key, $unset_from_global_too = false)
251
+	{
252
+		unset($this->_params[$key]);
253
+		if ($unset_from_global_too) {
254
+			unset($_REQUEST[$key]);
255
+		}
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * @return string
262
+	 */
263
+	public function ip_address()
264
+	{
265
+		return $this->_ip_address;
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * _visitor_ip
272
+	 *    attempt to get IP address of current visitor from server
273
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
274
+	 *
275
+	 * @access public
276
+	 * @return string
277
+	 */
278
+	private function _visitor_ip()
279
+	{
280
+		$visitor_ip = '0.0.0.0';
281
+		$server_keys = array(
282
+			'HTTP_CLIENT_IP',
283
+			'HTTP_X_FORWARDED_FOR',
284
+			'HTTP_X_FORWARDED',
285
+			'HTTP_X_CLUSTER_CLIENT_IP',
286
+			'HTTP_FORWARDED_FOR',
287
+			'HTTP_FORWARDED',
288
+			'REMOTE_ADDR',
289
+		);
290
+		foreach ($server_keys as $key) {
291
+			if (isset($_SERVER[$key])) {
292
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
293
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
294
+						$visitor_ip = $ip;
295
+					}
296
+				}
297
+			}
298
+		}
299
+		return $visitor_ip;
300
+	}
301 301
 
302 302
 
303 303
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -77,13 +77,13 @@  discard block
 block discarded – undo
77 77
     public function __construct(array $get, array $post, array $cookie)
78 78
     {
79 79
         // grab request vars
80
-        $this->_get = (array)$get;
81
-        $this->_post = (array)$post;
82
-        $this->_cookie = (array)$cookie;
80
+        $this->_get = (array) $get;
81
+        $this->_post = (array) $post;
82
+        $this->_cookie = (array) $cookie;
83 83
         $this->_params = array_merge($this->_get, $this->_post);
84 84
         // AJAX ???
85 85
         $this->ajax = defined('DOING_AJAX') ? true : false;
86
-        $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1;
86
+        $this->front_ajax = $this->is_set('ee_front_ajax') && (int) $this->get('ee_front_ajax') === 1;
87 87
         // grab user IP
88 88
         $this->_ip_address = $this->_visitor_ip();
89 89
     }
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
                 // build a new key to pass along like: 'second[third]'
222 222
                 // or just 'second' depending on depth of keys
223 223
                 $key_string = array_shift($keys);
224
-                if (! empty($keys)) {
225
-                    $key_string .= '[' . implode('][', $keys) . ']';
224
+                if ( ! empty($keys)) {
225
+                    $key_string .= '['.implode('][', $keys).']';
226 226
                 }
227 227
                 return $this->request_parameter_drill_down(
228 228
                     $key_string,
Please login to merge, or discard this patch.
core/services/loaders/Loader.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -22,103 +22,103 @@
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * @var LoaderDecoratorInterface $new_loader
27
-     */
28
-    private $new_loader;
29
-
30
-
31
-    /**
32
-     * @var LoaderDecoratorInterface $shared_loader
33
-     */
34
-    private $shared_loader;
35
-
36
-
37
-
38
-    /**
39
-     * Loader constructor.
40
-     *
41
-     * @param LoaderDecoratorInterface|null $new_loader
42
-     * @param LoaderDecoratorInterface|null $shared_loader
43
-     * @throws InvalidInterfaceException
44
-     * @throws InvalidArgumentException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader)
48
-    {
49
-        $this->new_loader = $new_loader;
50
-        $this->shared_loader = $shared_loader;
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * @return LoaderDecoratorInterface
57
-     */
58
-    public function getNewLoader()
59
-    {
60
-        return $this->new_loader;
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * @return LoaderDecoratorInterface
67
-     */
68
-    public function getSharedLoader()
69
-    {
70
-        return $this->shared_loader;
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     * @param string $fqcn
77
-     * @param array  $arguments
78
-     * @param bool   $shared
79
-     * @return mixed
80
-     */
81
-    public function load($fqcn, $arguments = array(), $shared = true)
82
-    {
83
-        return $shared
84
-            ? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
85
-            : $this->getNewLoader()->load($fqcn, $arguments, $shared);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * @param string $fqcn
92
-     * @param array  $arguments
93
-     * @return mixed
94
-     */
95
-    public function getNew($fqcn, $arguments = array())
96
-    {
97
-        return $this->getNewLoader()->load($fqcn, $arguments, false);
98
-    }
99
-
100
-
101
-
102
-    /**
103
-     * @param string $fqcn
104
-     * @param array  $arguments
105
-     * @return mixed
106
-     */
107
-    public function getShared($fqcn, $arguments = array())
108
-    {
109
-        return $this->getSharedLoader()->load($fqcn, $arguments, true);
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * calls reset() on loaders if that method exists
116
-     */
117
-    public function reset()
118
-    {
119
-        $this->new_loader->reset();
120
-        $this->shared_loader->reset();
121
-    }
25
+	/**
26
+	 * @var LoaderDecoratorInterface $new_loader
27
+	 */
28
+	private $new_loader;
29
+
30
+
31
+	/**
32
+	 * @var LoaderDecoratorInterface $shared_loader
33
+	 */
34
+	private $shared_loader;
35
+
36
+
37
+
38
+	/**
39
+	 * Loader constructor.
40
+	 *
41
+	 * @param LoaderDecoratorInterface|null $new_loader
42
+	 * @param LoaderDecoratorInterface|null $shared_loader
43
+	 * @throws InvalidInterfaceException
44
+	 * @throws InvalidArgumentException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	public function __construct(LoaderDecoratorInterface $new_loader, LoaderDecoratorInterface $shared_loader)
48
+	{
49
+		$this->new_loader = $new_loader;
50
+		$this->shared_loader = $shared_loader;
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * @return LoaderDecoratorInterface
57
+	 */
58
+	public function getNewLoader()
59
+	{
60
+		return $this->new_loader;
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * @return LoaderDecoratorInterface
67
+	 */
68
+	public function getSharedLoader()
69
+	{
70
+		return $this->shared_loader;
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 * @param string $fqcn
77
+	 * @param array  $arguments
78
+	 * @param bool   $shared
79
+	 * @return mixed
80
+	 */
81
+	public function load($fqcn, $arguments = array(), $shared = true)
82
+	{
83
+		return $shared
84
+			? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
85
+			: $this->getNewLoader()->load($fqcn, $arguments, $shared);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * @param string $fqcn
92
+	 * @param array  $arguments
93
+	 * @return mixed
94
+	 */
95
+	public function getNew($fqcn, $arguments = array())
96
+	{
97
+		return $this->getNewLoader()->load($fqcn, $arguments, false);
98
+	}
99
+
100
+
101
+
102
+	/**
103
+	 * @param string $fqcn
104
+	 * @param array  $arguments
105
+	 * @return mixed
106
+	 */
107
+	public function getShared($fqcn, $arguments = array())
108
+	{
109
+		return $this->getSharedLoader()->load($fqcn, $arguments, true);
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * calls reset() on loaders if that method exists
116
+	 */
117
+	public function reset()
118
+	{
119
+		$this->new_loader->reset();
120
+		$this->shared_loader->reset();
121
+	}
122 122
 
123 123
 }
124 124
 // End of file Loader.php
Please login to merge, or discard this patch.
core/services/loaders/CoreLoader.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -26,67 +26,67 @@
 block discarded – undo
26 26
 class CoreLoader implements LoaderDecoratorInterface
27 27
 {
28 28
 
29
-    /**
30
-     * @var EE_Registry|CoffeeShop $generator
31
-     */
32
-    private $generator;
33
-
34
-
35
-
36
-    /**
37
-     * CoreLoader constructor.
38
-     *
39
-     * @param EE_Registry|CoffeeShop $generator
40
-     * @throws InvalidArgumentException
41
-     */
42
-    public function __construct($generator)
43
-    {
44
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
45
-            throw new InvalidArgumentException(
46
-                esc_html__(
47
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
48
-                    'event_espresso'
49
-                )
50
-            );
51
-        }
52
-        $this->generator = $generator;
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * @param string $fqcn
59
-     * @param array  $arguments
60
-     * @param bool   $shared
61
-     * @return mixed
62
-     * @throws EE_Error
63
-     * @throws ServiceNotFoundException
64
-     * @throws ReflectionException
65
-     */
66
-    public function load($fqcn, $arguments = array(), $shared = true)
67
-    {
68
-        if($this->generator instanceof EE_Registry) {
69
-            return $this->generator->create($fqcn, $arguments, $shared);
70
-        }
71
-        $shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW;
72
-        return $this->generator->brew($fqcn, $arguments, $shared);
73
-
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     * calls reset() on generator if method exists
80
-     *
81
-     * @throws EE_Error
82
-     * @throws ReflectionException
83
-     */
84
-    public function reset()
85
-    {
86
-        if (method_exists($this->generator, 'reset')) {
87
-            $this->generator->reset();
88
-        }
89
-    }
29
+	/**
30
+	 * @var EE_Registry|CoffeeShop $generator
31
+	 */
32
+	private $generator;
33
+
34
+
35
+
36
+	/**
37
+	 * CoreLoader constructor.
38
+	 *
39
+	 * @param EE_Registry|CoffeeShop $generator
40
+	 * @throws InvalidArgumentException
41
+	 */
42
+	public function __construct($generator)
43
+	{
44
+		if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
45
+			throw new InvalidArgumentException(
46
+				esc_html__(
47
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
48
+					'event_espresso'
49
+				)
50
+			);
51
+		}
52
+		$this->generator = $generator;
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * @param string $fqcn
59
+	 * @param array  $arguments
60
+	 * @param bool   $shared
61
+	 * @return mixed
62
+	 * @throws EE_Error
63
+	 * @throws ServiceNotFoundException
64
+	 * @throws ReflectionException
65
+	 */
66
+	public function load($fqcn, $arguments = array(), $shared = true)
67
+	{
68
+		if($this->generator instanceof EE_Registry) {
69
+			return $this->generator->create($fqcn, $arguments, $shared);
70
+		}
71
+		$shared = $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW;
72
+		return $this->generator->brew($fqcn, $arguments, $shared);
73
+
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 * calls reset() on generator if method exists
80
+	 *
81
+	 * @throws EE_Error
82
+	 * @throws ReflectionException
83
+	 */
84
+	public function reset()
85
+	{
86
+		if (method_exists($this->generator, 'reset')) {
87
+			$this->generator->reset();
88
+		}
89
+	}
90 90
 
91 91
 }
92 92
 // End of file CoreLoader.php
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/DatetimeOffsetFix.php 2 patches
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -18,305 +18,305 @@
 block discarded – undo
18 18
 class DatetimeOffsetFix extends JobHandler
19 19
 {
20 20
 
21
-    /**
22
-     * Key for the option used to track which models have been processed when doing the batches.
23
-     */
24
-    const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix';
25
-
26
-
27
-    const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed';
28
-
29
-    /**
30
-     * Key for the option used to track what the current offset is that will be applied when this tool is executed.
31
-     */
32
-    const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply';
33
-
34
-
35
-    /**
36
-     * String labelling the datetime offset fix type for change-log entries.
37
-     */
38
-    const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix';
39
-
40
-
41
-    /**
42
-     * String labelling a datetime offset fix error for change-log entries.
43
-     */
44
-    const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error';
45
-
46
-    /**
47
-     * @var EEM_Base[]
48
-     */
49
-    protected $models_with_datetime_fields = array();
50
-
51
-
52
-    /**
53
-     * Performs any necessary setup for starting the job. This is also a good
54
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
55
-     * when continue_job will be called
56
-     *
57
-     * @param JobParameters $job_parameters
58
-     * @throws BatchRequestException
59
-     * @return JobStepResponse
60
-     */
61
-    public function create_job(JobParameters $job_parameters)
62
-    {
63
-        $models_with_datetime_fields = $this->getModelsWithDatetimeFields();
64
-        //we'll be doing each model as a batch.
65
-        $job_parameters->set_job_size(count($models_with_datetime_fields));
66
-        return new JobStepResponse(
67
-            $job_parameters,
68
-            esc_html__('Starting Datetime Offset Fix', 'event_espresso')
69
-        );
70
-    }
71
-
72
-    /**
73
-     * Performs another step of the job
74
-     *
75
-     * @param JobParameters $job_parameters
76
-     * @param int           $batch_size
77
-     * @return JobStepResponse
78
-     * @throws \EE_Error
79
-     */
80
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
81
-    {
82
-        $models_to_process = $this->getModelsWithDatetimeFields();
83
-        //let's pop off the a model and do the query to apply the offset.
84
-        $model_to_process = array_pop($models_to_process);
85
-        //update our record
86
-        $this->setModelsToProcess($models_to_process);
87
-        $this->processModel($model_to_process);
88
-        $this->updateCountOfModelsProcessed();
89
-        $job_parameters->set_units_processed($this->getCountOfModelsProcessed());
90
-        if (count($models_to_process) > 0) {
91
-            $job_parameters->set_status(JobParameters::status_continue);
92
-        } else {
93
-            $job_parameters->set_status(JobParameters::status_complete);
94
-        }
95
-        return new JobStepResponse(
96
-            $job_parameters,
97
-            sprintf(
98
-                esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'),
99
-                $model_to_process
100
-            )
101
-        );
102
-    }
103
-
104
-    /**
105
-     * Performs any clean-up logic when we know the job is completed
106
-     *
107
-     * @param JobParameters $job_parameters
108
-     * @return JobStepResponse
109
-     * @throws BatchRequestException
110
-     */
111
-    public function cleanup_job(JobParameters $job_parameters)
112
-    {
113
-        //delete important saved options.
114
-        delete_option(self::MODELS_TO_PROCESS_OPTION_KEY);
115
-        delete_option(self::COUNT_OF_MODELS_PROCESSED);
116
-        return new JobStepResponse($job_parameters, esc_html__(
117
-            'Offset has been applied to all affected fields.',
118
-            'event_espresso'
119
-        ));
120
-    }
121
-
122
-
123
-    /**
124
-     * Contains the logic for processing a model and applying the datetime offset to affected fields on that model.
125
-     * @param string $model_class_name
126
-     * @throws \EE_Error
127
-     */
128
-    protected function processModel($model_class_name)
129
-    {
130
-        global $wpdb;
131
-        /** @var EEM_Base $model */
132
-        $model = $model_class_name::instance();
133
-        $original_offset = self::getOffset();
134
-        $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB';
135
-        $offset = abs($original_offset) * 60;
136
-        //since some affected models might have two tables, we have to get our tables and set up a query for each table.
137
-        foreach ($model->get_tables() as $table) {
138
-            $query = 'UPDATE ' . $table->get_table_name();
139
-            $fields_affected = array();
140
-            $inner_query = array();
141
-            foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
142
-                if ($model_field instanceof EE_Datetime_Field) {
143
-                    $inner_query[] = $model_field->get_table_column() . ' = '
144
-                                     . $sql_date_function . '('
145
-                                     . $model_field->get_table_column()
146
-                                     . ", INTERVAL $offset MINUTE)";
147
-                    $fields_affected[] = $model_field;
148
-                }
149
-            }
150
-            if (! $fields_affected) {
151
-                continue;
152
-            }
153
-            //k convert innerquery to string
154
-            $query .= ' SET ' . implode(',', $inner_query);
155
-            //execute query
156
-            $result = $wpdb->query($query);
157
-            //record log
158
-            if ($result !== false) {
159
-                $this->recordChangeLog($model, $original_offset, $table, $fields_affected);
160
-            } else {
161
-                //record error.
162
-                $error_message = $wpdb->last_error;
163
-                //handle the edgecases where last_error might be empty.
164
-                if (! $error_message) {
165
-                    $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso');
166
-                }
167
-                $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message);
168
-            }
169
-        }
170
-    }
171
-
172
-
173
-    /**
174
-     * Records a changelog entry using the given information.
175
-     *
176
-     * @param EEM_Base              $model
177
-     * @param float                 $offset
178
-     * @param EE_Table_Base         $table
179
-     * @param EE_Model_Field_Base[] $model_fields_affected
180
-     * @param string                $error_message   If present then there was an error so let's record that instead.
181
-     * @throws \EE_Error
182
-     */
183
-    private function recordChangeLog(
184
-        EEM_Base $model,
185
-        $offset,
186
-        EE_Table_Base $table,
187
-        $model_fields_affected,
188
-        $error_message = ''
189
-    ) {
190
-        //setup $fields list.
191
-        $fields = array();
192
-        /** @var EE_Datetime_Field $model_field */
193
-        foreach ($model_fields_affected as $model_field) {
194
-            if (! $model_field instanceof EE_Datetime_Field) {
195
-                continue;
196
-            }
197
-            $fields[] = $model_field->get_name();
198
-        }
199
-        //setup the message for the changelog entry.
200
-        $message = $error_message
201
-            ? sprintf(
202
-                esc_html__(
203
-                    'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s',
204
-                    'event_espresso'
205
-                ),
206
-                $table->get_table_name(),
207
-                $model->get_this_model_name(),
208
-                $offset,
209
-                implode(',', $fields),
210
-                $error_message
211
-            )
212
-            : sprintf(
213
-                esc_html__(
214
-                    'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s',
215
-                    'event_espresso'
216
-                ),
217
-                $table->get_table_name(),
218
-                $model->get_this_model_name(),
219
-                $offset,
220
-                implode(',', $fields)
221
-            );
222
-        //write to the log
223
-        $changelog = EE_Change_Log::new_instance(array(
224
-            'LOG_type' => $error_message
225
-                ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE
226
-                : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE,
227
-            'LOG_message' => $message
228
-        ));
229
-        $changelog->save();
230
-    }
231
-
232
-
233
-    /**
234
-     * Returns an array of models that have datetime fields.
235
-     * This array is added to a short lived transient cache to keep having to build this list to a minimum.
236
-     * @return array  an array of model class names.
237
-     */
238
-    private function getModelsWithDatetimeFields()
239
-    {
240
-        $this->getModelsToProcess();
241
-        if (! empty($this->models_with_datetime_fields)) {
242
-            return $this->models_with_datetime_fields;
243
-        }
244
-
245
-        $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models;
246
-        foreach ($all_non_abstract_models as $non_abstract_model) {
247
-            //get model instance
248
-            /** @var EEM_Base $non_abstract_model */
249
-            $non_abstract_model = $non_abstract_model::instance();
250
-            if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) {
251
-                $this->models_with_datetime_fields[] = get_class($non_abstract_model);
252
-            }
253
-        }
254
-        $this->setModelsToProcess($this->models_with_datetime_fields);
255
-        return $this->models_with_datetime_fields;
256
-    }
257
-
258
-
259
-    /**
260
-     * This simply records the models that have been processed with our tracking option.
261
-     * @param array $models_to_set  array of model class names.
262
-     */
263
-    private function setModelsToProcess($models_to_set)
264
-    {
265
-        update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set);
266
-    }
267
-
268
-
269
-    /**
270
-     * Used to keep track of how many models have been processed for the batch
271
-     * @param $count
272
-     */
273
-    private function updateCountOfModelsProcessed($count = 1)
274
-    {
275
-        $count = $this->getCountOfModelsProcessed() + (int) $count;
276
-        update_option(self::COUNT_OF_MODELS_PROCESSED, $count);
277
-    }
278
-
279
-
280
-    /**
281
-     * Retrieve the tracked number of models processed between requests.
282
-     * @return int
283
-     */
284
-    private function getCountOfModelsProcessed()
285
-    {
286
-        return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0);
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns the models that are left to process.
292
-     * @return array  an array of model class names.
293
-     */
294
-    private function getModelsToProcess()
295
-    {
296
-        if (empty($this->models_with_datetime_fields)) {
297
-            $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array());
298
-        }
299
-        return $this->models_with_datetime_fields;
300
-    }
301
-
302
-
303
-    /**
304
-     * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns.
305
-     * @param float $offset
306
-     */
307
-    public static function updateOffset($offset)
308
-    {
309
-        update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset);
310
-    }
311
-
312
-
313
-    /**
314
-     * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns.
315
-     *
316
-     * @return float
317
-     */
318
-    public static function getOffset()
319
-    {
320
-        return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0);
321
-    }
21
+	/**
22
+	 * Key for the option used to track which models have been processed when doing the batches.
23
+	 */
24
+	const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix';
25
+
26
+
27
+	const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed';
28
+
29
+	/**
30
+	 * Key for the option used to track what the current offset is that will be applied when this tool is executed.
31
+	 */
32
+	const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply';
33
+
34
+
35
+	/**
36
+	 * String labelling the datetime offset fix type for change-log entries.
37
+	 */
38
+	const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix';
39
+
40
+
41
+	/**
42
+	 * String labelling a datetime offset fix error for change-log entries.
43
+	 */
44
+	const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error';
45
+
46
+	/**
47
+	 * @var EEM_Base[]
48
+	 */
49
+	protected $models_with_datetime_fields = array();
50
+
51
+
52
+	/**
53
+	 * Performs any necessary setup for starting the job. This is also a good
54
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
55
+	 * when continue_job will be called
56
+	 *
57
+	 * @param JobParameters $job_parameters
58
+	 * @throws BatchRequestException
59
+	 * @return JobStepResponse
60
+	 */
61
+	public function create_job(JobParameters $job_parameters)
62
+	{
63
+		$models_with_datetime_fields = $this->getModelsWithDatetimeFields();
64
+		//we'll be doing each model as a batch.
65
+		$job_parameters->set_job_size(count($models_with_datetime_fields));
66
+		return new JobStepResponse(
67
+			$job_parameters,
68
+			esc_html__('Starting Datetime Offset Fix', 'event_espresso')
69
+		);
70
+	}
71
+
72
+	/**
73
+	 * Performs another step of the job
74
+	 *
75
+	 * @param JobParameters $job_parameters
76
+	 * @param int           $batch_size
77
+	 * @return JobStepResponse
78
+	 * @throws \EE_Error
79
+	 */
80
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
81
+	{
82
+		$models_to_process = $this->getModelsWithDatetimeFields();
83
+		//let's pop off the a model and do the query to apply the offset.
84
+		$model_to_process = array_pop($models_to_process);
85
+		//update our record
86
+		$this->setModelsToProcess($models_to_process);
87
+		$this->processModel($model_to_process);
88
+		$this->updateCountOfModelsProcessed();
89
+		$job_parameters->set_units_processed($this->getCountOfModelsProcessed());
90
+		if (count($models_to_process) > 0) {
91
+			$job_parameters->set_status(JobParameters::status_continue);
92
+		} else {
93
+			$job_parameters->set_status(JobParameters::status_complete);
94
+		}
95
+		return new JobStepResponse(
96
+			$job_parameters,
97
+			sprintf(
98
+				esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'),
99
+				$model_to_process
100
+			)
101
+		);
102
+	}
103
+
104
+	/**
105
+	 * Performs any clean-up logic when we know the job is completed
106
+	 *
107
+	 * @param JobParameters $job_parameters
108
+	 * @return JobStepResponse
109
+	 * @throws BatchRequestException
110
+	 */
111
+	public function cleanup_job(JobParameters $job_parameters)
112
+	{
113
+		//delete important saved options.
114
+		delete_option(self::MODELS_TO_PROCESS_OPTION_KEY);
115
+		delete_option(self::COUNT_OF_MODELS_PROCESSED);
116
+		return new JobStepResponse($job_parameters, esc_html__(
117
+			'Offset has been applied to all affected fields.',
118
+			'event_espresso'
119
+		));
120
+	}
121
+
122
+
123
+	/**
124
+	 * Contains the logic for processing a model and applying the datetime offset to affected fields on that model.
125
+	 * @param string $model_class_name
126
+	 * @throws \EE_Error
127
+	 */
128
+	protected function processModel($model_class_name)
129
+	{
130
+		global $wpdb;
131
+		/** @var EEM_Base $model */
132
+		$model = $model_class_name::instance();
133
+		$original_offset = self::getOffset();
134
+		$sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB';
135
+		$offset = abs($original_offset) * 60;
136
+		//since some affected models might have two tables, we have to get our tables and set up a query for each table.
137
+		foreach ($model->get_tables() as $table) {
138
+			$query = 'UPDATE ' . $table->get_table_name();
139
+			$fields_affected = array();
140
+			$inner_query = array();
141
+			foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
142
+				if ($model_field instanceof EE_Datetime_Field) {
143
+					$inner_query[] = $model_field->get_table_column() . ' = '
144
+									 . $sql_date_function . '('
145
+									 . $model_field->get_table_column()
146
+									 . ", INTERVAL $offset MINUTE)";
147
+					$fields_affected[] = $model_field;
148
+				}
149
+			}
150
+			if (! $fields_affected) {
151
+				continue;
152
+			}
153
+			//k convert innerquery to string
154
+			$query .= ' SET ' . implode(',', $inner_query);
155
+			//execute query
156
+			$result = $wpdb->query($query);
157
+			//record log
158
+			if ($result !== false) {
159
+				$this->recordChangeLog($model, $original_offset, $table, $fields_affected);
160
+			} else {
161
+				//record error.
162
+				$error_message = $wpdb->last_error;
163
+				//handle the edgecases where last_error might be empty.
164
+				if (! $error_message) {
165
+					$error_message = esc_html__('Unknown mysql error occured.', 'event_espresso');
166
+				}
167
+				$this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message);
168
+			}
169
+		}
170
+	}
171
+
172
+
173
+	/**
174
+	 * Records a changelog entry using the given information.
175
+	 *
176
+	 * @param EEM_Base              $model
177
+	 * @param float                 $offset
178
+	 * @param EE_Table_Base         $table
179
+	 * @param EE_Model_Field_Base[] $model_fields_affected
180
+	 * @param string                $error_message   If present then there was an error so let's record that instead.
181
+	 * @throws \EE_Error
182
+	 */
183
+	private function recordChangeLog(
184
+		EEM_Base $model,
185
+		$offset,
186
+		EE_Table_Base $table,
187
+		$model_fields_affected,
188
+		$error_message = ''
189
+	) {
190
+		//setup $fields list.
191
+		$fields = array();
192
+		/** @var EE_Datetime_Field $model_field */
193
+		foreach ($model_fields_affected as $model_field) {
194
+			if (! $model_field instanceof EE_Datetime_Field) {
195
+				continue;
196
+			}
197
+			$fields[] = $model_field->get_name();
198
+		}
199
+		//setup the message for the changelog entry.
200
+		$message = $error_message
201
+			? sprintf(
202
+				esc_html__(
203
+					'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s',
204
+					'event_espresso'
205
+				),
206
+				$table->get_table_name(),
207
+				$model->get_this_model_name(),
208
+				$offset,
209
+				implode(',', $fields),
210
+				$error_message
211
+			)
212
+			: sprintf(
213
+				esc_html__(
214
+					'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s',
215
+					'event_espresso'
216
+				),
217
+				$table->get_table_name(),
218
+				$model->get_this_model_name(),
219
+				$offset,
220
+				implode(',', $fields)
221
+			);
222
+		//write to the log
223
+		$changelog = EE_Change_Log::new_instance(array(
224
+			'LOG_type' => $error_message
225
+				? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE
226
+				: self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE,
227
+			'LOG_message' => $message
228
+		));
229
+		$changelog->save();
230
+	}
231
+
232
+
233
+	/**
234
+	 * Returns an array of models that have datetime fields.
235
+	 * This array is added to a short lived transient cache to keep having to build this list to a minimum.
236
+	 * @return array  an array of model class names.
237
+	 */
238
+	private function getModelsWithDatetimeFields()
239
+	{
240
+		$this->getModelsToProcess();
241
+		if (! empty($this->models_with_datetime_fields)) {
242
+			return $this->models_with_datetime_fields;
243
+		}
244
+
245
+		$all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models;
246
+		foreach ($all_non_abstract_models as $non_abstract_model) {
247
+			//get model instance
248
+			/** @var EEM_Base $non_abstract_model */
249
+			$non_abstract_model = $non_abstract_model::instance();
250
+			if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) {
251
+				$this->models_with_datetime_fields[] = get_class($non_abstract_model);
252
+			}
253
+		}
254
+		$this->setModelsToProcess($this->models_with_datetime_fields);
255
+		return $this->models_with_datetime_fields;
256
+	}
257
+
258
+
259
+	/**
260
+	 * This simply records the models that have been processed with our tracking option.
261
+	 * @param array $models_to_set  array of model class names.
262
+	 */
263
+	private function setModelsToProcess($models_to_set)
264
+	{
265
+		update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set);
266
+	}
267
+
268
+
269
+	/**
270
+	 * Used to keep track of how many models have been processed for the batch
271
+	 * @param $count
272
+	 */
273
+	private function updateCountOfModelsProcessed($count = 1)
274
+	{
275
+		$count = $this->getCountOfModelsProcessed() + (int) $count;
276
+		update_option(self::COUNT_OF_MODELS_PROCESSED, $count);
277
+	}
278
+
279
+
280
+	/**
281
+	 * Retrieve the tracked number of models processed between requests.
282
+	 * @return int
283
+	 */
284
+	private function getCountOfModelsProcessed()
285
+	{
286
+		return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0);
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns the models that are left to process.
292
+	 * @return array  an array of model class names.
293
+	 */
294
+	private function getModelsToProcess()
295
+	{
296
+		if (empty($this->models_with_datetime_fields)) {
297
+			$this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array());
298
+		}
299
+		return $this->models_with_datetime_fields;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns.
305
+	 * @param float $offset
306
+	 */
307
+	public static function updateOffset($offset)
308
+	{
309
+		update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset);
310
+	}
311
+
312
+
313
+	/**
314
+	 * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns.
315
+	 *
316
+	 * @return float
317
+	 */
318
+	public static function getOffset()
319
+	{
320
+		return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0);
321
+	}
322 322
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -135,23 +135,23 @@  discard block
 block discarded – undo
135 135
         $offset = abs($original_offset) * 60;
136 136
         //since some affected models might have two tables, we have to get our tables and set up a query for each table.
137 137
         foreach ($model->get_tables() as $table) {
138
-            $query = 'UPDATE ' . $table->get_table_name();
138
+            $query = 'UPDATE '.$table->get_table_name();
139 139
             $fields_affected = array();
140 140
             $inner_query = array();
141 141
             foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
142 142
                 if ($model_field instanceof EE_Datetime_Field) {
143
-                    $inner_query[] = $model_field->get_table_column() . ' = '
144
-                                     . $sql_date_function . '('
143
+                    $inner_query[] = $model_field->get_table_column().' = '
144
+                                     . $sql_date_function.'('
145 145
                                      . $model_field->get_table_column()
146 146
                                      . ", INTERVAL $offset MINUTE)";
147 147
                     $fields_affected[] = $model_field;
148 148
                 }
149 149
             }
150
-            if (! $fields_affected) {
150
+            if ( ! $fields_affected) {
151 151
                 continue;
152 152
             }
153 153
             //k convert innerquery to string
154
-            $query .= ' SET ' . implode(',', $inner_query);
154
+            $query .= ' SET '.implode(',', $inner_query);
155 155
             //execute query
156 156
             $result = $wpdb->query($query);
157 157
             //record log
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
                 //record error.
162 162
                 $error_message = $wpdb->last_error;
163 163
                 //handle the edgecases where last_error might be empty.
164
-                if (! $error_message) {
164
+                if ( ! $error_message) {
165 165
                     $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso');
166 166
                 }
167 167
                 $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         $fields = array();
192 192
         /** @var EE_Datetime_Field $model_field */
193 193
         foreach ($model_fields_affected as $model_field) {
194
-            if (! $model_field instanceof EE_Datetime_Field) {
194
+            if ( ! $model_field instanceof EE_Datetime_Field) {
195 195
                 continue;
196 196
             }
197 197
             $fields[] = $model_field->get_name();
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     private function getModelsWithDatetimeFields()
239 239
     {
240 240
         $this->getModelsToProcess();
241
-        if (! empty($this->models_with_datetime_fields)) {
241
+        if ( ! empty($this->models_with_datetime_fields)) {
242 242
             return $this->models_with_datetime_fields;
243 243
         }
244 244
 
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Shortcode.lib.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -20,159 +20,159 @@
 block discarded – undo
20 20
 class EE_Register_Shortcode implements EEI_Plugin_API
21 21
 {
22 22
 
23
-    /**
24
-     * Holds values for registered shortcodes
25
-     *
26
-     * @var array
27
-     */
28
-    protected static $_settings = array();
23
+	/**
24
+	 * Holds values for registered shortcodes
25
+	 *
26
+	 * @var array
27
+	 */
28
+	protected static $_settings = array();
29 29
 
30 30
 
31
-    /**
32
-     *    Method for registering new EE_Shortcodes
33
-     *
34
-     * @since    4.3.0
35
-     * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
36
-     * @param string $shortcode_id a unique identifier for this set of modules Required.
37
-     * @param  array $setup_args   an array of arguments provided for registering shortcodes Required.
38
-     *               @type array shortcode_paths        an array of full server paths to folders containing any
39
-     *                                                  EES_Shortcodes
40
-     *               @type array shortcode_fqcns        an array of fully qualified class names for any new shortcode
41
-     *                                                  classes to register.  Shortcode classes should extend
42
-     *                                                  EspressoShortcode and be properly namespaced so they are
43
-     *                                                  autoloaded.
44
-     * @throws EE_Error
45
-     * @return void
46
-     */
47
-    public static function register($shortcode_id = null, $setup_args = array())
48
-    {
49
-        //required fields MUST be present, so let's make sure they are.
50
-        if (empty($shortcode_id)
51
-            || ! is_array($setup_args)
52
-            || (
53
-                empty($setup_args['shortcode_paths']))
54
-                && empty($setup_args['shortcode_fqcns'])
55
-            ) {
56
-            throw new EE_Error(
57
-                esc_html__(
58
-                    'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
59
-                    'event_espresso'
60
-                )
61
-            );
62
-        }
31
+	/**
32
+	 *    Method for registering new EE_Shortcodes
33
+	 *
34
+	 * @since    4.3.0
35
+	 * @since    4.9.46.rc.025  for the new `shortcode_fqcns` array argument.
36
+	 * @param string $shortcode_id a unique identifier for this set of modules Required.
37
+	 * @param  array $setup_args   an array of arguments provided for registering shortcodes Required.
38
+	 *               @type array shortcode_paths        an array of full server paths to folders containing any
39
+	 *                                                  EES_Shortcodes
40
+	 *               @type array shortcode_fqcns        an array of fully qualified class names for any new shortcode
41
+	 *                                                  classes to register.  Shortcode classes should extend
42
+	 *                                                  EspressoShortcode and be properly namespaced so they are
43
+	 *                                                  autoloaded.
44
+	 * @throws EE_Error
45
+	 * @return void
46
+	 */
47
+	public static function register($shortcode_id = null, $setup_args = array())
48
+	{
49
+		//required fields MUST be present, so let's make sure they are.
50
+		if (empty($shortcode_id)
51
+			|| ! is_array($setup_args)
52
+			|| (
53
+				empty($setup_args['shortcode_paths']))
54
+				&& empty($setup_args['shortcode_fqcns'])
55
+			) {
56
+			throw new EE_Error(
57
+				esc_html__(
58
+					'In order to register Modules with EE_Register_Shortcode::register(), you must include a "shortcode_id" (a unique identifier for this set of shortcodes), and an array containing the following keys: "shortcode_paths" (an array of full server paths to folders that contain shortcodes, or to the shortcode files themselves)',
59
+					'event_espresso'
60
+				)
61
+			);
62
+		}
63 63
 
64
-        //make sure we don't register twice
65
-        if (isset(self::$_settings[$shortcode_id])) {
66
-            return;
67
-        }
64
+		//make sure we don't register twice
65
+		if (isset(self::$_settings[$shortcode_id])) {
66
+			return;
67
+		}
68 68
 
69
-        //make sure this was called in the right place!
70
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
71
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72
-        ) {
73
-            EE_Error::doing_it_wrong(
74
-                __METHOD__,
75
-                esc_html__(
76
-                    'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
77
-                    'event_espresso'
78
-                ),
79
-                '4.3.0'
80
-            );
81
-        }
82
-        //setup $_settings array from incoming values.
83
-        self::$_settings[$shortcode_id] = array(
84
-            // array of full server paths to any EES_Shortcodes used by the shortcode
85
-            'shortcode_paths' => isset($setup_args['shortcode_paths'])
86
-                ? (array) $setup_args['shortcode_paths']
87
-                : array(),
88
-            'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
89
-                ? (array) $setup_args['shortcode_fqcns']
90
-                : array()
91
-        );
92
-        // add to list of shortcodes to be registered
93
-        add_filter(
94
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
95
-            array('EE_Register_Shortcode', 'add_shortcodes')
96
-        );
69
+		//make sure this was called in the right place!
70
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
71
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72
+		) {
73
+			EE_Error::doing_it_wrong(
74
+				__METHOD__,
75
+				esc_html__(
76
+					'An attempt to register shortcodes has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register shortcodes.',
77
+					'event_espresso'
78
+				),
79
+				'4.3.0'
80
+			);
81
+		}
82
+		//setup $_settings array from incoming values.
83
+		self::$_settings[$shortcode_id] = array(
84
+			// array of full server paths to any EES_Shortcodes used by the shortcode
85
+			'shortcode_paths' => isset($setup_args['shortcode_paths'])
86
+				? (array) $setup_args['shortcode_paths']
87
+				: array(),
88
+			'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
89
+				? (array) $setup_args['shortcode_fqcns']
90
+				: array()
91
+		);
92
+		// add to list of shortcodes to be registered
93
+		add_filter(
94
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
95
+			array('EE_Register_Shortcode', 'add_shortcodes')
96
+		);
97 97
 
98
-        add_filter(
99
-            'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
100
-            array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection')
101
-        );
102
-    }
98
+		add_filter(
99
+			'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
100
+			array('EE_Register_Shortcode', 'instantiateAndAddToShortcodeCollection')
101
+		);
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * Filters the list of shortcodes to add ours.
107
-     * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
108
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...)
109
-     *
110
-     * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
111
-     * @return array
112
-     */
113
-    public static function add_shortcodes($shortcodes_to_register)
114
-    {
115
-        foreach (self::$_settings as $settings) {
116
-            $shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
117
-        }
118
-        return $shortcodes_to_register;
119
-    }
105
+	/**
106
+	 * Filters the list of shortcodes to add ours.
107
+	 * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg.
108
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey',...)
109
+	 *
110
+	 * @param array $shortcodes_to_register array of paths to all shortcodes that require registering
111
+	 * @return array
112
+	 */
113
+	public static function add_shortcodes($shortcodes_to_register)
114
+	{
115
+		foreach (self::$_settings as $settings) {
116
+			$shortcodes_to_register = array_merge($shortcodes_to_register, $settings['shortcode_paths']);
117
+		}
118
+		return $shortcodes_to_register;
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection
124
-     * and registers any provided shortcode fully qualified class names.
125
-     * @param CollectionInterface $shortcodes_collection
126
-     * @return CollectionInterface
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidClassException
129
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
130
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
131
-     */
132
-    public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
133
-    {
134
-        foreach (self::$_settings as $settings) {
135
-            if (! empty($settings['shortcode_fqcns'])) {
136
-                foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
137
-                    if (! class_exists($shortcode_fqcn)) {
138
-                        throw new InvalidClassException(
139
-                            sprintf(
140
-                                esc_html__(
141
-                                    'Are you sure %s is the right fully qualified class name for the shortcode class?',
142
-                                    'event_espresso'
143
-                                ),
144
-                                $shortcode_fqcn
145
-                            )
146
-                        );
147
-                    }
148
-                    if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
149
-                        //register dependencies
150
-                        EE_Dependency_Map::register_dependencies(
151
-                            $shortcode_fqcn,
152
-                            array(
153
-                                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
154
-                            )
155
-                        );
156
-                    }
157
-                    $shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
158
-                }
159
-            }
160
-        }
161
-        return $shortcodes_collection;
162
-    }
122
+	/**
123
+	 * Hooks into FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection
124
+	 * and registers any provided shortcode fully qualified class names.
125
+	 * @param CollectionInterface $shortcodes_collection
126
+	 * @return CollectionInterface
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidClassException
129
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
130
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
131
+	 */
132
+	public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
133
+	{
134
+		foreach (self::$_settings as $settings) {
135
+			if (! empty($settings['shortcode_fqcns'])) {
136
+				foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
137
+					if (! class_exists($shortcode_fqcn)) {
138
+						throw new InvalidClassException(
139
+							sprintf(
140
+								esc_html__(
141
+									'Are you sure %s is the right fully qualified class name for the shortcode class?',
142
+									'event_espresso'
143
+								),
144
+								$shortcode_fqcn
145
+							)
146
+						);
147
+					}
148
+					if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
149
+						//register dependencies
150
+						EE_Dependency_Map::register_dependencies(
151
+							$shortcode_fqcn,
152
+							array(
153
+								'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
154
+							)
155
+						);
156
+					}
157
+					$shortcodes_collection->add(LoaderFactory::getLoader()->getShared($shortcode_fqcn));
158
+				}
159
+			}
160
+		}
161
+		return $shortcodes_collection;
162
+	}
163 163
 
164 164
 
165
-    /**
166
-     * This deregisters a shortcode that was previously registered with a specific $shortcode_id.
167
-     *
168
-     * @since    4.3.0
169
-     * @param string $shortcode_id the name for the shortcode that was previously registered
170
-     * @return void
171
-     */
172
-    public static function deregister($shortcode_id = null)
173
-    {
174
-        if (isset(self::$_settings[$shortcode_id])) {
175
-            unset(self::$_settings[$shortcode_id]);
176
-        }
177
-    }
165
+	/**
166
+	 * This deregisters a shortcode that was previously registered with a specific $shortcode_id.
167
+	 *
168
+	 * @since    4.3.0
169
+	 * @param string $shortcode_id the name for the shortcode that was previously registered
170
+	 * @return void
171
+	 */
172
+	public static function deregister($shortcode_id = null)
173
+	{
174
+		if (isset(self::$_settings[$shortcode_id])) {
175
+			unset(self::$_settings[$shortcode_id]);
176
+		}
177
+	}
178 178
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         }
68 68
 
69 69
         //make sure this was called in the right place!
70
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
70
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
71 71
             || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
72 72
         ) {
73 73
             EE_Error::doing_it_wrong(
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
     public static function instantiateAndAddToShortcodeCollection(CollectionInterface $shortcodes_collection)
133 133
     {
134 134
         foreach (self::$_settings as $settings) {
135
-            if (! empty($settings['shortcode_fqcns'])) {
135
+            if ( ! empty($settings['shortcode_fqcns'])) {
136 136
                 foreach ($settings['shortcode_fqcns'] as $shortcode_fqcn) {
137
-                    if (! class_exists($shortcode_fqcn)) {
137
+                    if ( ! class_exists($shortcode_fqcn)) {
138 138
                         throw new InvalidClassException(
139 139
                             sprintf(
140 140
                                 esc_html__(
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                             )
146 146
                         );
147 147
                     }
148
-                    if (! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
148
+                    if ( ! EE_Dependency_Map::instance()->has_dependency_for_class($shortcode_fqcn)) {
149 149
                         //register dependencies
150 150
                         EE_Dependency_Map::register_dependencies(
151 151
                             $shortcode_fqcn,
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1005 added lines, -1005 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -19,1064 +19,1064 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * possibly truncated version of the EE core version string
24
-     *
25
-     * @var string
26
-     */
27
-    protected static $_core_version = '';
22
+	/**
23
+	 * possibly truncated version of the EE core version string
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected static $_core_version = '';
28 28
 
29
-    /**
30
-     * Holds values for registered addons
31
-     *
32
-     * @var array
33
-     */
34
-    protected static $_settings = array();
29
+	/**
30
+	 * Holds values for registered addons
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected static $_settings = array();
35 35
 
36
-    /**
37
-     * @var  array $_incompatible_addons keys are addon SLUGS
38
-     * (first argument passed to EE_Register_Addon::register()), keys are
39
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
40
-     * Generally this should be used sparingly, as we don't want to muddle up
41
-     * EE core with knowledge of ALL the addons out there.
42
-     * If you want NO versions of an addon to run with a certain version of core,
43
-     * it's usually best to define the addon's "min_core_version" as part of its call
44
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
45
-     * minimum plugin version.
46
-     * @access    protected
47
-     */
48
-    protected static $_incompatible_addons = array(
49
-        'Multi_Event_Registration' => '2.0.11.rc.002',
50
-        'Promotions'               => '1.0.0.rc.084',
51
-    );
36
+	/**
37
+	 * @var  array $_incompatible_addons keys are addon SLUGS
38
+	 * (first argument passed to EE_Register_Addon::register()), keys are
39
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
40
+	 * Generally this should be used sparingly, as we don't want to muddle up
41
+	 * EE core with knowledge of ALL the addons out there.
42
+	 * If you want NO versions of an addon to run with a certain version of core,
43
+	 * it's usually best to define the addon's "min_core_version" as part of its call
44
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
45
+	 * minimum plugin version.
46
+	 * @access    protected
47
+	 */
48
+	protected static $_incompatible_addons = array(
49
+		'Multi_Event_Registration' => '2.0.11.rc.002',
50
+		'Promotions'               => '1.0.0.rc.084',
51
+	);
52 52
 
53 53
 
54
-    /**
55
-     * We should always be comparing core to a version like '4.3.0.rc.000',
56
-     * not just '4.3.0'.
57
-     * So if the addon developer doesn't provide that full version string,
58
-     * fill in the blanks for them
59
-     *
60
-     * @param string $min_core_version
61
-     * @return string always like '4.3.0.rc.000'
62
-     */
63
-    protected static function _effective_version($min_core_version)
64
-    {
65
-        // versions: 4 . 3 . 1 . p . 123
66
-        // offsets:    0 . 1 . 2 . 3 . 4
67
-        $version_parts = explode('.', $min_core_version);
68
-        //check they specified the micro version (after 2nd period)
69
-        if (! isset($version_parts[2])) {
70
-            $version_parts[2] = '0';
71
-        }
72
-        //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73
-        //soon we can assume that's 'rc', but this current version is 'alpha'
74
-        if (! isset($version_parts[3])) {
75
-            $version_parts[3] = 'dev';
76
-        }
77
-        if (! isset($version_parts[4])) {
78
-            $version_parts[4] = '000';
79
-        }
80
-        return implode('.', $version_parts);
81
-    }
54
+	/**
55
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
56
+	 * not just '4.3.0'.
57
+	 * So if the addon developer doesn't provide that full version string,
58
+	 * fill in the blanks for them
59
+	 *
60
+	 * @param string $min_core_version
61
+	 * @return string always like '4.3.0.rc.000'
62
+	 */
63
+	protected static function _effective_version($min_core_version)
64
+	{
65
+		// versions: 4 . 3 . 1 . p . 123
66
+		// offsets:    0 . 1 . 2 . 3 . 4
67
+		$version_parts = explode('.', $min_core_version);
68
+		//check they specified the micro version (after 2nd period)
69
+		if (! isset($version_parts[2])) {
70
+			$version_parts[2] = '0';
71
+		}
72
+		//if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73
+		//soon we can assume that's 'rc', but this current version is 'alpha'
74
+		if (! isset($version_parts[3])) {
75
+			$version_parts[3] = 'dev';
76
+		}
77
+		if (! isset($version_parts[4])) {
78
+			$version_parts[4] = '000';
79
+		}
80
+		return implode('.', $version_parts);
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * Returns whether or not the min core version requirement of the addon is met
86
-     *
87
-     * @param string $min_core_version    the minimum core version required by the addon
88
-     * @param string $actual_core_version the actual core version, optional
89
-     * @return boolean
90
-     */
91
-    public static function _meets_min_core_version_requirement(
92
-        $min_core_version,
93
-        $actual_core_version = EVENT_ESPRESSO_VERSION
94
-    ) {
95
-        return version_compare(
96
-            self::_effective_version($actual_core_version),
97
-            self::_effective_version($min_core_version),
98
-            '>='
99
-        );
100
-    }
84
+	/**
85
+	 * Returns whether or not the min core version requirement of the addon is met
86
+	 *
87
+	 * @param string $min_core_version    the minimum core version required by the addon
88
+	 * @param string $actual_core_version the actual core version, optional
89
+	 * @return boolean
90
+	 */
91
+	public static function _meets_min_core_version_requirement(
92
+		$min_core_version,
93
+		$actual_core_version = EVENT_ESPRESSO_VERSION
94
+	) {
95
+		return version_compare(
96
+			self::_effective_version($actual_core_version),
97
+			self::_effective_version($min_core_version),
98
+			'>='
99
+		);
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     *    Method for registering new EE_Addons.
105
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
106
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
107
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
108
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
109
-     * 'activate_plugin', it registers the addon still, but its components are not registered
110
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
111
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
112
-     * (so that we can detect that the addon has activated on the subsequent request)
113
-     *
114
-     * @since    4.3.0
115
-     * @param string                  $addon_name                           the EE_Addon's name. Required.
116
-     * @param  array                  $setup_args                           {                                    An
117
-     *                                                                      array of arguments provided for registering
118
-     *                                                                      the message type.
119
-     * @type  string                  $class_name                           the addon's main file name.
120
-     *                                                                      If left blank, generated from the addon
121
-     *                                                                      name, changes something like "calendar" to
122
-     *                                                                      "EE_Calendar"
123
-     * @type string                   $min_core_version                     the minimum version of EE Core that the
124
-     *       addon will work with. eg "4.8.1.rc.084"
125
-     * @type string                   $version                              the "software" version for the addon. eg
126
-     *       "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress
127
-     * @type string                   $main_file_path                       the full server path to the main file
128
-     *       loaded
129
-     *                                                                      directly by WP
130
-     * @type string                   $admin_path                           full server path to the folder where the
131
-     *       addon\'s admin files reside
132
-     * @type string                   $admin_callback                       a method to be called when the EE Admin is
133
-     *       first invoked, can be used for hooking into any admin page
134
-     * @type string                   $config_section                       the section name for this addon's
135
-     *       configuration settings section (defaults to "addons")
136
-     * @type string                   $config_class                         the class name for this addon's
137
-     *       configuration settings object
138
-     * @type string                   $config_name                          the class name for this addon's
139
-     *       configuration settings object
140
-     * @type string                   $autoloader_paths                     an array of class names and the full server
141
-     *       paths to those files. Required.
142
-     * @type string                   $autoloader_folders                   an array of  "full server paths" for any
143
-     *       folders containing classes that might be invoked by the addon
144
-     * @type string                   $dms_paths                            an array of full server paths to folders
145
-     *       that contain data migration scripts. Required.
146
-     * @type string                   $module_paths                         an array of full server paths to any
147
-     *       EED_Modules used by the addon
148
-     * @type string                   $shortcode_paths                      an array of full server paths to folders
149
-     *       that contain EES_Shortcodes
150
-     * @type string                   $widget_paths                         an array of full server paths to folders
151
-     *       that contain WP_Widgets
152
-     * @type string                   $pue_options
153
-     * @type array                    $capabilities                         an array indexed by role name
154
-     *                                                                      (i.e administrator,author ) and the values
155
-     *                                                                      are an array of caps to add to the role.
156
-     *                                                                      'administrator' => array(
157
-     *                                                                      'read_addon', 'edit_addon', etc.
158
-     *                                                                      ).
159
-     * @type EE_Meta_Capability_Map[] $capability_maps                      an array of EE_Meta_Capability_Map object
160
-     *       for any addons that need to register any special meta mapped capabilities.  Should be indexed where the
161
-     *       key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class.
162
-     * @type array                    $model_paths                          array of folders containing DB models
163
-     * @see      EE_Register_Model
164
-     * @type array                    $class_paths                          array of folders containing DB classes
165
-     * @see      EE_Register_Model
166
-     * @type array                    $model_extension_paths                array of folders containing DB model
167
-     *       extensions
168
-     * @see      EE_Register_Model_Extension
169
-     * @type array                    $class_extension_paths                array of folders containing DB class
170
-     *       extensions
171
-     * @see      EE_Register_Model_Extension
172
-     * @type array message_types {
173
-     *                                                                      An array of message types with the key as
174
-     *                                                                      the message type name and the values as
175
-     *                                                                      below:
176
-     * @type string                   $mtfilename                           The filename of the message type being
177
-     *       registered. This will be the main EE_{Messagetype_Name}_message_type class.
178
-     *                                                                      (eg.
179
-     *                                                                      EE_Declined_Registration_message_type.class.php)
180
-     *                                                                      Required.
181
-     * @type array                    $autoloadpaths                        An array of paths to add to the messages
182
-     *                                                                      autoloader for the new message type.
183
-     *                                                                      Required.
184
-     * @type array                    $messengers_to_activate_with          An array of messengers that this message
185
-     *                                                                      type should activate with. Each value in
186
-     *                                                                      the
187
-     *                                                                      array
188
-     *                                                                      should match the name property of a
189
-     *                                                                      EE_messenger. Optional.
190
-     * @type array                    $messengers_to_validate_with          An array of messengers that this message
191
-     *                                                                      type should validate with. Each value in
192
-     *                                                                      the
193
-     *                                                                      array
194
-     *                                                                      should match the name property of an
195
-     *                                                                      EE_messenger.
196
-     *                                                                      Optional.
197
-     *                                                                      }
198
-     * @type array                    $custom_post_types
199
-     * @type array                    $custom_taxonomies
200
-     * @type array                    $payment_method_paths                 each element is the folder containing the
201
-     *                                                                      EE_PMT_Base child class
202
-     *                                                                      (eg,
203
-     *                                                                      '/wp-content/plugins/my_plugin/Payomatic/'
204
-     *                                                                      which contains the files
205
-     *                                                                      EE_PMT_Payomatic.pm.php)
206
-     * @type array                    $default_terms
207
-     * @type array                    $namespace                            {
208
-     *                                                                      An array with two items for registering the
209
-     *                                                                      addon's namespace. (If, for some reason,
210
-     *                                                                      you
211
-     *                                                                      require additional namespaces, use
212
-     *                                                                      EventEspresso\core\Psr4Autoloader::addNamespace()
213
-     *                                                                      directly)
214
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
215
-     * @type string                   $FQNS                                 the namespace prefix
216
-     * @type string                   $DIR                                  a base directory for class files in the
217
-     *       namespace.
218
-     *                                                                      }
219
-     *                                                                      }
220
-     * @throws EE_Error
221
-     * @return void
222
-     */
223
-    public static function register($addon_name = '', $setup_args = array())
224
-    {
225
-        // required fields MUST be present, so let's make sure they are.
226
-        \EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
227
-        // get class name for addon
228
-        $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
229
-        //setup $_settings array from incoming values.
230
-        $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
231
-        // setup PUE
232
-        \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233
-        // does this addon work with this version of core or WordPress ?
234
-        if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235
-            return;
236
-        }
237
-        // register namespaces
238
-        \EE_Register_Addon::_setup_namespaces($addon_settings);
239
-        // check if this is an activation request
240
-        if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
241
-            // dont bother setting up the rest of the addon atm
242
-            return;
243
-        }
244
-        // we need cars
245
-        \EE_Register_Addon::_setup_autoloaders($addon_name);
246
-        // register new models and extensions
247
-        \EE_Register_Addon::_register_models_and_extensions($addon_name);
248
-        // setup DMS
249
-        \EE_Register_Addon::_register_data_migration_scripts($addon_name);
250
-        // if config_class is present let's register config.
251
-        \EE_Register_Addon::_register_config($addon_name);
252
-        // register admin pages
253
-        \EE_Register_Addon::_register_admin_pages($addon_name);
254
-        // add to list of modules to be registered
255
-        \EE_Register_Addon::_register_modules($addon_name);
256
-        // add to list of shortcodes to be registered
257
-        \EE_Register_Addon::_register_shortcodes($addon_name);
258
-        // add to list of widgets to be registered
259
-        \EE_Register_Addon::_register_widgets($addon_name);
260
-        // register capability related stuff.
261
-        \EE_Register_Addon::_register_capabilities($addon_name);
262
-        // any message type to register?
263
-        \EE_Register_Addon::_register_message_types($addon_name);
264
-        // any custom post type/ custom capabilities or default terms to register
265
-        \EE_Register_Addon::_register_custom_post_types($addon_name);
266
-        // and any payment methods
267
-        \EE_Register_Addon::_register_payment_methods($addon_name);
268
-        // load and instantiate main addon class
269
-        $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
270
-        $addon->after_registration();
271
-    }
103
+	/**
104
+	 *    Method for registering new EE_Addons.
105
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
106
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
107
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
108
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
109
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
110
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
111
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
112
+	 * (so that we can detect that the addon has activated on the subsequent request)
113
+	 *
114
+	 * @since    4.3.0
115
+	 * @param string                  $addon_name                           the EE_Addon's name. Required.
116
+	 * @param  array                  $setup_args                           {                                    An
117
+	 *                                                                      array of arguments provided for registering
118
+	 *                                                                      the message type.
119
+	 * @type  string                  $class_name                           the addon's main file name.
120
+	 *                                                                      If left blank, generated from the addon
121
+	 *                                                                      name, changes something like "calendar" to
122
+	 *                                                                      "EE_Calendar"
123
+	 * @type string                   $min_core_version                     the minimum version of EE Core that the
124
+	 *       addon will work with. eg "4.8.1.rc.084"
125
+	 * @type string                   $version                              the "software" version for the addon. eg
126
+	 *       "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress
127
+	 * @type string                   $main_file_path                       the full server path to the main file
128
+	 *       loaded
129
+	 *                                                                      directly by WP
130
+	 * @type string                   $admin_path                           full server path to the folder where the
131
+	 *       addon\'s admin files reside
132
+	 * @type string                   $admin_callback                       a method to be called when the EE Admin is
133
+	 *       first invoked, can be used for hooking into any admin page
134
+	 * @type string                   $config_section                       the section name for this addon's
135
+	 *       configuration settings section (defaults to "addons")
136
+	 * @type string                   $config_class                         the class name for this addon's
137
+	 *       configuration settings object
138
+	 * @type string                   $config_name                          the class name for this addon's
139
+	 *       configuration settings object
140
+	 * @type string                   $autoloader_paths                     an array of class names and the full server
141
+	 *       paths to those files. Required.
142
+	 * @type string                   $autoloader_folders                   an array of  "full server paths" for any
143
+	 *       folders containing classes that might be invoked by the addon
144
+	 * @type string                   $dms_paths                            an array of full server paths to folders
145
+	 *       that contain data migration scripts. Required.
146
+	 * @type string                   $module_paths                         an array of full server paths to any
147
+	 *       EED_Modules used by the addon
148
+	 * @type string                   $shortcode_paths                      an array of full server paths to folders
149
+	 *       that contain EES_Shortcodes
150
+	 * @type string                   $widget_paths                         an array of full server paths to folders
151
+	 *       that contain WP_Widgets
152
+	 * @type string                   $pue_options
153
+	 * @type array                    $capabilities                         an array indexed by role name
154
+	 *                                                                      (i.e administrator,author ) and the values
155
+	 *                                                                      are an array of caps to add to the role.
156
+	 *                                                                      'administrator' => array(
157
+	 *                                                                      'read_addon', 'edit_addon', etc.
158
+	 *                                                                      ).
159
+	 * @type EE_Meta_Capability_Map[] $capability_maps                      an array of EE_Meta_Capability_Map object
160
+	 *       for any addons that need to register any special meta mapped capabilities.  Should be indexed where the
161
+	 *       key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class.
162
+	 * @type array                    $model_paths                          array of folders containing DB models
163
+	 * @see      EE_Register_Model
164
+	 * @type array                    $class_paths                          array of folders containing DB classes
165
+	 * @see      EE_Register_Model
166
+	 * @type array                    $model_extension_paths                array of folders containing DB model
167
+	 *       extensions
168
+	 * @see      EE_Register_Model_Extension
169
+	 * @type array                    $class_extension_paths                array of folders containing DB class
170
+	 *       extensions
171
+	 * @see      EE_Register_Model_Extension
172
+	 * @type array message_types {
173
+	 *                                                                      An array of message types with the key as
174
+	 *                                                                      the message type name and the values as
175
+	 *                                                                      below:
176
+	 * @type string                   $mtfilename                           The filename of the message type being
177
+	 *       registered. This will be the main EE_{Messagetype_Name}_message_type class.
178
+	 *                                                                      (eg.
179
+	 *                                                                      EE_Declined_Registration_message_type.class.php)
180
+	 *                                                                      Required.
181
+	 * @type array                    $autoloadpaths                        An array of paths to add to the messages
182
+	 *                                                                      autoloader for the new message type.
183
+	 *                                                                      Required.
184
+	 * @type array                    $messengers_to_activate_with          An array of messengers that this message
185
+	 *                                                                      type should activate with. Each value in
186
+	 *                                                                      the
187
+	 *                                                                      array
188
+	 *                                                                      should match the name property of a
189
+	 *                                                                      EE_messenger. Optional.
190
+	 * @type array                    $messengers_to_validate_with          An array of messengers that this message
191
+	 *                                                                      type should validate with. Each value in
192
+	 *                                                                      the
193
+	 *                                                                      array
194
+	 *                                                                      should match the name property of an
195
+	 *                                                                      EE_messenger.
196
+	 *                                                                      Optional.
197
+	 *                                                                      }
198
+	 * @type array                    $custom_post_types
199
+	 * @type array                    $custom_taxonomies
200
+	 * @type array                    $payment_method_paths                 each element is the folder containing the
201
+	 *                                                                      EE_PMT_Base child class
202
+	 *                                                                      (eg,
203
+	 *                                                                      '/wp-content/plugins/my_plugin/Payomatic/'
204
+	 *                                                                      which contains the files
205
+	 *                                                                      EE_PMT_Payomatic.pm.php)
206
+	 * @type array                    $default_terms
207
+	 * @type array                    $namespace                            {
208
+	 *                                                                      An array with two items for registering the
209
+	 *                                                                      addon's namespace. (If, for some reason,
210
+	 *                                                                      you
211
+	 *                                                                      require additional namespaces, use
212
+	 *                                                                      EventEspresso\core\Psr4Autoloader::addNamespace()
213
+	 *                                                                      directly)
214
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
215
+	 * @type string                   $FQNS                                 the namespace prefix
216
+	 * @type string                   $DIR                                  a base directory for class files in the
217
+	 *       namespace.
218
+	 *                                                                      }
219
+	 *                                                                      }
220
+	 * @throws EE_Error
221
+	 * @return void
222
+	 */
223
+	public static function register($addon_name = '', $setup_args = array())
224
+	{
225
+		// required fields MUST be present, so let's make sure they are.
226
+		\EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
227
+		// get class name for addon
228
+		$class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
229
+		//setup $_settings array from incoming values.
230
+		$addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
231
+		// setup PUE
232
+		\EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233
+		// does this addon work with this version of core or WordPress ?
234
+		if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235
+			return;
236
+		}
237
+		// register namespaces
238
+		\EE_Register_Addon::_setup_namespaces($addon_settings);
239
+		// check if this is an activation request
240
+		if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
241
+			// dont bother setting up the rest of the addon atm
242
+			return;
243
+		}
244
+		// we need cars
245
+		\EE_Register_Addon::_setup_autoloaders($addon_name);
246
+		// register new models and extensions
247
+		\EE_Register_Addon::_register_models_and_extensions($addon_name);
248
+		// setup DMS
249
+		\EE_Register_Addon::_register_data_migration_scripts($addon_name);
250
+		// if config_class is present let's register config.
251
+		\EE_Register_Addon::_register_config($addon_name);
252
+		// register admin pages
253
+		\EE_Register_Addon::_register_admin_pages($addon_name);
254
+		// add to list of modules to be registered
255
+		\EE_Register_Addon::_register_modules($addon_name);
256
+		// add to list of shortcodes to be registered
257
+		\EE_Register_Addon::_register_shortcodes($addon_name);
258
+		// add to list of widgets to be registered
259
+		\EE_Register_Addon::_register_widgets($addon_name);
260
+		// register capability related stuff.
261
+		\EE_Register_Addon::_register_capabilities($addon_name);
262
+		// any message type to register?
263
+		\EE_Register_Addon::_register_message_types($addon_name);
264
+		// any custom post type/ custom capabilities or default terms to register
265
+		\EE_Register_Addon::_register_custom_post_types($addon_name);
266
+		// and any payment methods
267
+		\EE_Register_Addon::_register_payment_methods($addon_name);
268
+		// load and instantiate main addon class
269
+		$addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
270
+		$addon->after_registration();
271
+	}
272 272
 
273 273
 
274
-    /**
275
-     * @param string $addon_name
276
-     * @param array  $setup_args
277
-     * @return void
278
-     * @throws \EE_Error
279
-     */
280
-    private static function _verify_parameters($addon_name, array $setup_args)
281
-    {
282
-        // required fields MUST be present, so let's make sure they are.
283
-        if (empty($addon_name) || ! is_array($setup_args)) {
284
-            throw new EE_Error(
285
-                __(
286
-                    '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.',
287
-                    'event_espresso'
288
-                )
289
-            );
290
-        }
291
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292
-            throw new EE_Error(
293
-                sprintf(
294
-                    __(
295
-                        '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',
296
-                        'event_espresso'
297
-                    ),
298
-                    implode(',', array_keys($setup_args))
299
-                )
300
-            );
301
-        }
302
-        // check that addon has not already been registered with that name
303
-        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
304
-            throw new EE_Error(
305
-                sprintf(
306
-                    __(
307
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
308
-                        'event_espresso'
309
-                    ),
310
-                    $addon_name
311
-                )
312
-            );
313
-        }
314
-    }
274
+	/**
275
+	 * @param string $addon_name
276
+	 * @param array  $setup_args
277
+	 * @return void
278
+	 * @throws \EE_Error
279
+	 */
280
+	private static function _verify_parameters($addon_name, array $setup_args)
281
+	{
282
+		// required fields MUST be present, so let's make sure they are.
283
+		if (empty($addon_name) || ! is_array($setup_args)) {
284
+			throw new EE_Error(
285
+				__(
286
+					'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.',
287
+					'event_espresso'
288
+				)
289
+			);
290
+		}
291
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292
+			throw new EE_Error(
293
+				sprintf(
294
+					__(
295
+						'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',
296
+						'event_espresso'
297
+					),
298
+					implode(',', array_keys($setup_args))
299
+				)
300
+			);
301
+		}
302
+		// check that addon has not already been registered with that name
303
+		if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
304
+			throw new EE_Error(
305
+				sprintf(
306
+					__(
307
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
308
+						'event_espresso'
309
+					),
310
+					$addon_name
311
+				)
312
+			);
313
+		}
314
+	}
315 315
 
316 316
 
317
-    /**
318
-     * @param string $addon_name
319
-     * @param array  $setup_args
320
-     * @return string
321
-     */
322
-    private static function _parse_class_name($addon_name, array $setup_args)
323
-    {
324
-        if (empty($setup_args['class_name'])) {
325
-            // generate one by first separating name with spaces
326
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
327
-            //capitalize, then replace spaces with underscores
328
-            $class_name = str_replace(' ', '_', ucwords($class_name));
329
-        } else {
330
-            $class_name = $setup_args['class_name'];
331
-        }
332
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
333
-    }
317
+	/**
318
+	 * @param string $addon_name
319
+	 * @param array  $setup_args
320
+	 * @return string
321
+	 */
322
+	private static function _parse_class_name($addon_name, array $setup_args)
323
+	{
324
+		if (empty($setup_args['class_name'])) {
325
+			// generate one by first separating name with spaces
326
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
327
+			//capitalize, then replace spaces with underscores
328
+			$class_name = str_replace(' ', '_', ucwords($class_name));
329
+		} else {
330
+			$class_name = $setup_args['class_name'];
331
+		}
332
+		return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
333
+	}
334 334
 
335 335
 
336
-    /**
337
-     * @param string $class_name
338
-     * @param array  $setup_args
339
-     * @return array
340
-     */
341
-    private static function _get_addon_settings($class_name, array $setup_args)
342
-    {
343
-        //setup $_settings array from incoming values.
344
-        $addon_settings = array(
345
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
346
-            'class_name'            => $class_name,
347
-            // the addon slug for use in URLs, etc
348
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
349
-                ? (string)$setup_args['plugin_slug']
350
-                : '',
351
-            // page slug to be used when generating the "Settings" link on the WP plugin page
352
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
-                ? (string)$setup_args['plugin_action_slug']
354
-                : '',
355
-            // the "software" version for the addon
356
-            'version'               => isset($setup_args['version'])
357
-                ? (string)$setup_args['version']
358
-                : '',
359
-            // the minimum version of EE Core that the addon will work with
360
-            'min_core_version'      => isset($setup_args['min_core_version'])
361
-                ? (string)$setup_args['min_core_version']
362
-                : '',
363
-            // the minimum version of WordPress that the addon will work with
364
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
365
-                ? (string)$setup_args['min_wp_version']
366
-                : EE_MIN_WP_VER_REQUIRED,
367
-            // full server path to main file (file loaded directly by WP)
368
-            'main_file_path'        => isset($setup_args['main_file_path'])
369
-                ? (string)$setup_args['main_file_path']
370
-                : '',
371
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372
-            'admin_path'            => isset($setup_args['admin_path'])
373
-                ? (string)$setup_args['admin_path'] : '',
374
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375
-            'admin_callback'        => isset($setup_args['admin_callback'])
376
-                ? (string)$setup_args['admin_callback']
377
-                : '',
378
-            // the section name for this addon's configuration settings section (defaults to "addons")
379
-            'config_section'        => isset($setup_args['config_section'])
380
-                ? (string)$setup_args['config_section']
381
-                : 'addons',
382
-            // the class name for this addon's configuration settings object
383
-            'config_class'          => isset($setup_args['config_class'])
384
-                ? (string)$setup_args['config_class'] : '',
385
-            //the name given to the config for this addons' configuration settings object (optional)
386
-            'config_name'           => isset($setup_args['config_name'])
387
-                ? (string)$setup_args['config_name'] : '',
388
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
-                ? (array)$setup_args['autoloader_paths']
391
-                : array(),
392
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
-                ? (array)$setup_args['autoloader_folders']
395
-                : array(),
396
-            // array of full server paths to any EE_DMS data migration scripts used by the addon
397
-            'dms_paths'             => isset($setup_args['dms_paths'])
398
-                ? (array)$setup_args['dms_paths']
399
-                : array(),
400
-            // array of full server paths to any EED_Modules used by the addon
401
-            'module_paths'          => isset($setup_args['module_paths'])
402
-                ? (array)$setup_args['module_paths']
403
-                : array(),
404
-            // array of full server paths to any EES_Shortcodes used by the addon
405
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
-                ? (array)$setup_args['shortcode_paths']
407
-                : array(),
408
-            'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
409
-                ? (array) $setup_args['shortcode_fqcns']
410
-                : array(),
411
-            // array of full server paths to any WP_Widgets used by the addon
412
-            'widget_paths'          => isset($setup_args['widget_paths'])
413
-                ? (array)$setup_args['widget_paths']
414
-                : array(),
415
-            // array of PUE options used by the addon
416
-            'pue_options'           => isset($setup_args['pue_options'])
417
-                ? (array)$setup_args['pue_options']
418
-                : array(),
419
-            'message_types'         => isset($setup_args['message_types'])
420
-                ? (array)$setup_args['message_types']
421
-                : array(),
422
-            'capabilities'          => isset($setup_args['capabilities'])
423
-                ? (array)$setup_args['capabilities']
424
-                : array(),
425
-            'capability_maps'       => isset($setup_args['capability_maps'])
426
-                ? (array)$setup_args['capability_maps']
427
-                : array(),
428
-            'model_paths'           => isset($setup_args['model_paths'])
429
-                ? (array)$setup_args['model_paths']
430
-                : array(),
431
-            'class_paths'           => isset($setup_args['class_paths'])
432
-                ? (array)$setup_args['class_paths']
433
-                : array(),
434
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
435
-                ? (array)$setup_args['model_extension_paths']
436
-                : array(),
437
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
438
-                ? (array)$setup_args['class_extension_paths']
439
-                : array(),
440
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
441
-                ? (array)$setup_args['custom_post_types']
442
-                : array(),
443
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
444
-                ? (array)$setup_args['custom_taxonomies']
445
-                : array(),
446
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
447
-                ? (array)$setup_args['payment_method_paths']
448
-                : array(),
449
-            'default_terms'         => isset($setup_args['default_terms'])
450
-                ? (array)$setup_args['default_terms']
451
-                : array(),
452
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
453
-            // that can be used for adding upgrading/marketing info
454
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
455
-                ? $setup_args['plugins_page_row']
456
-                : '',
457
-            'namespace'             => isset(
458
-                $setup_args['namespace'],
459
-                $setup_args['namespace']['FQNS'],
460
-                $setup_args['namespace']['DIR']
461
-            )
462
-                ? (array)$setup_args['namespace']
463
-                : array(),
464
-        );
465
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
466
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
467
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
468
-                                                && ! empty($addon_settings['admin_path'])
469
-            ? $addon_settings['plugin_slug']
470
-            : $addon_settings['plugin_action_slug'];
471
-        // full server path to main file (file loaded directly by WP)
472
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
473
-        return $addon_settings;
474
-    }
336
+	/**
337
+	 * @param string $class_name
338
+	 * @param array  $setup_args
339
+	 * @return array
340
+	 */
341
+	private static function _get_addon_settings($class_name, array $setup_args)
342
+	{
343
+		//setup $_settings array from incoming values.
344
+		$addon_settings = array(
345
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
346
+			'class_name'            => $class_name,
347
+			// the addon slug for use in URLs, etc
348
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
349
+				? (string)$setup_args['plugin_slug']
350
+				: '',
351
+			// page slug to be used when generating the "Settings" link on the WP plugin page
352
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
+				? (string)$setup_args['plugin_action_slug']
354
+				: '',
355
+			// the "software" version for the addon
356
+			'version'               => isset($setup_args['version'])
357
+				? (string)$setup_args['version']
358
+				: '',
359
+			// the minimum version of EE Core that the addon will work with
360
+			'min_core_version'      => isset($setup_args['min_core_version'])
361
+				? (string)$setup_args['min_core_version']
362
+				: '',
363
+			// the minimum version of WordPress that the addon will work with
364
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
365
+				? (string)$setup_args['min_wp_version']
366
+				: EE_MIN_WP_VER_REQUIRED,
367
+			// full server path to main file (file loaded directly by WP)
368
+			'main_file_path'        => isset($setup_args['main_file_path'])
369
+				? (string)$setup_args['main_file_path']
370
+				: '',
371
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372
+			'admin_path'            => isset($setup_args['admin_path'])
373
+				? (string)$setup_args['admin_path'] : '',
374
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375
+			'admin_callback'        => isset($setup_args['admin_callback'])
376
+				? (string)$setup_args['admin_callback']
377
+				: '',
378
+			// the section name for this addon's configuration settings section (defaults to "addons")
379
+			'config_section'        => isset($setup_args['config_section'])
380
+				? (string)$setup_args['config_section']
381
+				: 'addons',
382
+			// the class name for this addon's configuration settings object
383
+			'config_class'          => isset($setup_args['config_class'])
384
+				? (string)$setup_args['config_class'] : '',
385
+			//the name given to the config for this addons' configuration settings object (optional)
386
+			'config_name'           => isset($setup_args['config_name'])
387
+				? (string)$setup_args['config_name'] : '',
388
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
+				? (array)$setup_args['autoloader_paths']
391
+				: array(),
392
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
+				? (array)$setup_args['autoloader_folders']
395
+				: array(),
396
+			// array of full server paths to any EE_DMS data migration scripts used by the addon
397
+			'dms_paths'             => isset($setup_args['dms_paths'])
398
+				? (array)$setup_args['dms_paths']
399
+				: array(),
400
+			// array of full server paths to any EED_Modules used by the addon
401
+			'module_paths'          => isset($setup_args['module_paths'])
402
+				? (array)$setup_args['module_paths']
403
+				: array(),
404
+			// array of full server paths to any EES_Shortcodes used by the addon
405
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
+				? (array)$setup_args['shortcode_paths']
407
+				: array(),
408
+			'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
409
+				? (array) $setup_args['shortcode_fqcns']
410
+				: array(),
411
+			// array of full server paths to any WP_Widgets used by the addon
412
+			'widget_paths'          => isset($setup_args['widget_paths'])
413
+				? (array)$setup_args['widget_paths']
414
+				: array(),
415
+			// array of PUE options used by the addon
416
+			'pue_options'           => isset($setup_args['pue_options'])
417
+				? (array)$setup_args['pue_options']
418
+				: array(),
419
+			'message_types'         => isset($setup_args['message_types'])
420
+				? (array)$setup_args['message_types']
421
+				: array(),
422
+			'capabilities'          => isset($setup_args['capabilities'])
423
+				? (array)$setup_args['capabilities']
424
+				: array(),
425
+			'capability_maps'       => isset($setup_args['capability_maps'])
426
+				? (array)$setup_args['capability_maps']
427
+				: array(),
428
+			'model_paths'           => isset($setup_args['model_paths'])
429
+				? (array)$setup_args['model_paths']
430
+				: array(),
431
+			'class_paths'           => isset($setup_args['class_paths'])
432
+				? (array)$setup_args['class_paths']
433
+				: array(),
434
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
435
+				? (array)$setup_args['model_extension_paths']
436
+				: array(),
437
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
438
+				? (array)$setup_args['class_extension_paths']
439
+				: array(),
440
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
441
+				? (array)$setup_args['custom_post_types']
442
+				: array(),
443
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
444
+				? (array)$setup_args['custom_taxonomies']
445
+				: array(),
446
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
447
+				? (array)$setup_args['payment_method_paths']
448
+				: array(),
449
+			'default_terms'         => isset($setup_args['default_terms'])
450
+				? (array)$setup_args['default_terms']
451
+				: array(),
452
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
453
+			// that can be used for adding upgrading/marketing info
454
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
455
+				? $setup_args['plugins_page_row']
456
+				: '',
457
+			'namespace'             => isset(
458
+				$setup_args['namespace'],
459
+				$setup_args['namespace']['FQNS'],
460
+				$setup_args['namespace']['DIR']
461
+			)
462
+				? (array)$setup_args['namespace']
463
+				: array(),
464
+		);
465
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
466
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
467
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
468
+												&& ! empty($addon_settings['admin_path'])
469
+			? $addon_settings['plugin_slug']
470
+			: $addon_settings['plugin_action_slug'];
471
+		// full server path to main file (file loaded directly by WP)
472
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
473
+		return $addon_settings;
474
+	}
475 475
 
476 476
 
477
-    /**
478
-     * @param string $addon_name
479
-     * @param array  $addon_settings
480
-     * @return boolean
481
-     */
482
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
483
-    {
484
-        global $wp_version;
485
-        $incompatibility_message = '';
486
-        //check whether this addon version is compatible with EE core
487
-        if (
488
-            isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
489
-            && ! self::_meets_min_core_version_requirement(
490
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
491
-                $addon_settings['version']
492
-            )
493
-        ) {
494
-            $incompatibility_message = sprintf(
495
-                __(
496
-                    '%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.'
497
-                ),
498
-                $addon_name,
499
-                '<br />',
500
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
501
-                '<span style="font-weight: bold; color: #D54E21;">',
502
-                '</span><br />'
503
-            );
504
-        } else if (
505
-        ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
506
-        ) {
507
-            $incompatibility_message = sprintf(
508
-                __(
509
-                    '%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".',
510
-                    'event_espresso'
511
-                ),
512
-                $addon_name,
513
-                self::_effective_version($addon_settings['min_core_version']),
514
-                self::_effective_version(espresso_version()),
515
-                '<br />',
516
-                '<span style="font-weight: bold; color: #D54E21;">',
517
-                '</span><br />'
518
-            );
519
-        } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
520
-            $incompatibility_message = sprintf(
521
-                __(
522
-                    '%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.',
523
-                    'event_espresso'
524
-                ),
525
-                $addon_name,
526
-                $addon_settings['min_wp_version'],
527
-                '<br />',
528
-                '<span style="font-weight: bold; color: #D54E21;">',
529
-                '</span><br />'
530
-            );
531
-        }
532
-        if (! empty($incompatibility_message)) {
533
-            // remove 'activate' from the REQUEST
534
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
535
-            unset($_GET['activate'], $_REQUEST['activate']);
536
-            if (current_user_can('activate_plugins')) {
537
-                // show an error message indicating the plugin didn't activate properly
538
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
539
-            }
540
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
541
-            return false;
542
-        }
543
-        // addon IS compatible
544
-        return true;
545
-    }
477
+	/**
478
+	 * @param string $addon_name
479
+	 * @param array  $addon_settings
480
+	 * @return boolean
481
+	 */
482
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
483
+	{
484
+		global $wp_version;
485
+		$incompatibility_message = '';
486
+		//check whether this addon version is compatible with EE core
487
+		if (
488
+			isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
489
+			&& ! self::_meets_min_core_version_requirement(
490
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
491
+				$addon_settings['version']
492
+			)
493
+		) {
494
+			$incompatibility_message = sprintf(
495
+				__(
496
+					'%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.'
497
+				),
498
+				$addon_name,
499
+				'<br />',
500
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
501
+				'<span style="font-weight: bold; color: #D54E21;">',
502
+				'</span><br />'
503
+			);
504
+		} else if (
505
+		! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
506
+		) {
507
+			$incompatibility_message = sprintf(
508
+				__(
509
+					'%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".',
510
+					'event_espresso'
511
+				),
512
+				$addon_name,
513
+				self::_effective_version($addon_settings['min_core_version']),
514
+				self::_effective_version(espresso_version()),
515
+				'<br />',
516
+				'<span style="font-weight: bold; color: #D54E21;">',
517
+				'</span><br />'
518
+			);
519
+		} else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
520
+			$incompatibility_message = sprintf(
521
+				__(
522
+					'%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.',
523
+					'event_espresso'
524
+				),
525
+				$addon_name,
526
+				$addon_settings['min_wp_version'],
527
+				'<br />',
528
+				'<span style="font-weight: bold; color: #D54E21;">',
529
+				'</span><br />'
530
+			);
531
+		}
532
+		if (! empty($incompatibility_message)) {
533
+			// remove 'activate' from the REQUEST
534
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
535
+			unset($_GET['activate'], $_REQUEST['activate']);
536
+			if (current_user_can('activate_plugins')) {
537
+				// show an error message indicating the plugin didn't activate properly
538
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
539
+			}
540
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
541
+			return false;
542
+		}
543
+		// addon IS compatible
544
+		return true;
545
+	}
546 546
 
547 547
 
548
-    /**
549
-     * if plugin update engine is being used for auto-updates,
550
-     * then let's set that up now before going any further so that ALL addons can be updated
551
-     * (not needed if PUE is not being used)
552
-     *
553
-     * @param string $addon_name
554
-     * @param string $class_name
555
-     * @param array  $setup_args
556
-     * @return void
557
-     */
558
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
559
-    {
560
-        if (! empty($setup_args['pue_options'])) {
561
-            self::$_settings[$addon_name]['pue_options'] = array(
562
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
563
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
564
-                    : 'espresso_' . strtolower($class_name),
565
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
566
-                    ? (string)$setup_args['pue_options']['plugin_basename']
567
-                    : plugin_basename($setup_args['main_file_path']),
568
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
569
-                    ? (string)$setup_args['pue_options']['checkPeriod']
570
-                    : '24',
571
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
572
-                    ? (string)$setup_args['pue_options']['use_wp_update']
573
-                    : false,
574
-            );
575
-            add_action(
576
-                'AHEE__EE_System__brew_espresso__after_pue_init',
577
-                array('EE_Register_Addon', 'load_pue_update')
578
-            );
579
-        }
580
-    }
548
+	/**
549
+	 * if plugin update engine is being used for auto-updates,
550
+	 * then let's set that up now before going any further so that ALL addons can be updated
551
+	 * (not needed if PUE is not being used)
552
+	 *
553
+	 * @param string $addon_name
554
+	 * @param string $class_name
555
+	 * @param array  $setup_args
556
+	 * @return void
557
+	 */
558
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
559
+	{
560
+		if (! empty($setup_args['pue_options'])) {
561
+			self::$_settings[$addon_name]['pue_options'] = array(
562
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
563
+					? (string)$setup_args['pue_options']['pue_plugin_slug']
564
+					: 'espresso_' . strtolower($class_name),
565
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
566
+					? (string)$setup_args['pue_options']['plugin_basename']
567
+					: plugin_basename($setup_args['main_file_path']),
568
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
569
+					? (string)$setup_args['pue_options']['checkPeriod']
570
+					: '24',
571
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
572
+					? (string)$setup_args['pue_options']['use_wp_update']
573
+					: false,
574
+			);
575
+			add_action(
576
+				'AHEE__EE_System__brew_espresso__after_pue_init',
577
+				array('EE_Register_Addon', 'load_pue_update')
578
+			);
579
+		}
580
+	}
581 581
 
582 582
 
583
-    /**
584
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
585
-     *
586
-     * @param array $addon_settings
587
-     * @return void
588
-     */
589
-    private static function _setup_namespaces(array $addon_settings)
590
-    {
591
-        //
592
-        if (
593
-        isset(
594
-            $addon_settings['namespace'],
595
-            $addon_settings['namespace']['FQNS'],
596
-            $addon_settings['namespace']['DIR']
597
-        )
598
-        ) {
599
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
600
-                $addon_settings['namespace']['FQNS'],
601
-                $addon_settings['namespace']['DIR']
602
-            );
603
-        }
604
-    }
583
+	/**
584
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
585
+	 *
586
+	 * @param array $addon_settings
587
+	 * @return void
588
+	 */
589
+	private static function _setup_namespaces(array $addon_settings)
590
+	{
591
+		//
592
+		if (
593
+		isset(
594
+			$addon_settings['namespace'],
595
+			$addon_settings['namespace']['FQNS'],
596
+			$addon_settings['namespace']['DIR']
597
+		)
598
+		) {
599
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
600
+				$addon_settings['namespace']['FQNS'],
601
+				$addon_settings['namespace']['DIR']
602
+			);
603
+		}
604
+	}
605 605
 
606 606
 
607
-    /**
608
-     * @param string $addon_name
609
-     * @param array  $addon_settings
610
-     * @return bool
611
-     */
612
-    private static function _addon_activation($addon_name, array $addon_settings)
613
-    {
614
-        // this is an activation request
615
-        if (did_action('activate_plugin')) {
616
-            //to find if THIS is the addon that was activated, just check if we have already registered it or not
617
-            //(as the newly-activated addon wasn't around the first time addons were registered).
618
-            //Note: the presence of pue_options in the addon registration options will initialize the $_settings
619
-            //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
620
-            if (! isset(self::$_settings[$addon_name])
621
-                || (isset(self::$_settings[$addon_name])
622
-                    && ! isset(self::$_settings[$addon_name]['class_name'])
623
-                )
624
-            ) {
625
-                self::$_settings[$addon_name] = $addon_settings;
626
-                $addon                        = self::_load_and_init_addon_class($addon_name);
627
-                $addon->set_activation_indicator_option();
628
-                // dont bother setting up the rest of the addon.
629
-                // we know it was just activated and the request will end soon
630
-            }
631
-            return true;
632
-        }
633
-        // make sure this was called in the right place!
634
-        if (
635
-            ! did_action('AHEE__EE_System__load_espresso_addons')
636
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
637
-        ) {
638
-            EE_Error::doing_it_wrong(
639
-                __METHOD__,
640
-                sprintf(
641
-                    __(
642
-                        '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.',
643
-                        'event_espresso'
644
-                    ),
645
-                    $addon_name
646
-                ),
647
-                '4.3.0'
648
-            );
649
-        }
650
-        // make sure addon settings are set correctly without overwriting anything existing
651
-        if (isset(self::$_settings[$addon_name])) {
652
-            self::$_settings[$addon_name] += $addon_settings;
653
-        } else {
654
-            self::$_settings[$addon_name] = $addon_settings;
655
-        }
656
-        return false;
657
-    }
607
+	/**
608
+	 * @param string $addon_name
609
+	 * @param array  $addon_settings
610
+	 * @return bool
611
+	 */
612
+	private static function _addon_activation($addon_name, array $addon_settings)
613
+	{
614
+		// this is an activation request
615
+		if (did_action('activate_plugin')) {
616
+			//to find if THIS is the addon that was activated, just check if we have already registered it or not
617
+			//(as the newly-activated addon wasn't around the first time addons were registered).
618
+			//Note: the presence of pue_options in the addon registration options will initialize the $_settings
619
+			//property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
620
+			if (! isset(self::$_settings[$addon_name])
621
+				|| (isset(self::$_settings[$addon_name])
622
+					&& ! isset(self::$_settings[$addon_name]['class_name'])
623
+				)
624
+			) {
625
+				self::$_settings[$addon_name] = $addon_settings;
626
+				$addon                        = self::_load_and_init_addon_class($addon_name);
627
+				$addon->set_activation_indicator_option();
628
+				// dont bother setting up the rest of the addon.
629
+				// we know it was just activated and the request will end soon
630
+			}
631
+			return true;
632
+		}
633
+		// make sure this was called in the right place!
634
+		if (
635
+			! did_action('AHEE__EE_System__load_espresso_addons')
636
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
637
+		) {
638
+			EE_Error::doing_it_wrong(
639
+				__METHOD__,
640
+				sprintf(
641
+					__(
642
+						'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.',
643
+						'event_espresso'
644
+					),
645
+					$addon_name
646
+				),
647
+				'4.3.0'
648
+			);
649
+		}
650
+		// make sure addon settings are set correctly without overwriting anything existing
651
+		if (isset(self::$_settings[$addon_name])) {
652
+			self::$_settings[$addon_name] += $addon_settings;
653
+		} else {
654
+			self::$_settings[$addon_name] = $addon_settings;
655
+		}
656
+		return false;
657
+	}
658 658
 
659 659
 
660
-    /**
661
-     * @param string $addon_name
662
-     * @return void
663
-     * @throws \EE_Error
664
-     */
665
-    private static function _setup_autoloaders($addon_name)
666
-    {
667
-        if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
668
-            // setup autoloader for single file
669
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
670
-        }
671
-        // setup autoloaders for folders
672
-        if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
674
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
675
-            }
676
-        }
677
-    }
660
+	/**
661
+	 * @param string $addon_name
662
+	 * @return void
663
+	 * @throws \EE_Error
664
+	 */
665
+	private static function _setup_autoloaders($addon_name)
666
+	{
667
+		if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
668
+			// setup autoloader for single file
669
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
670
+		}
671
+		// setup autoloaders for folders
672
+		if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
+			foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
674
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
675
+			}
676
+		}
677
+	}
678 678
 
679 679
 
680
-    /**
681
-     * register new models and extensions
682
-     *
683
-     * @param string $addon_name
684
-     * @return void
685
-     * @throws \EE_Error
686
-     */
687
-    private static function _register_models_and_extensions($addon_name)
688
-    {
689
-        // register new models
690
-        if (
691
-            ! empty(self::$_settings[$addon_name]['model_paths'])
692
-            || ! empty(self::$_settings[$addon_name]['class_paths'])
693
-        ) {
694
-            EE_Register_Model::register(
695
-                $addon_name,
696
-                array(
697
-                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
698
-                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
699
-                )
700
-            );
701
-        }
702
-        // register model extensions
703
-        if (
704
-            ! empty(self::$_settings[$addon_name]['model_extension_paths'])
705
-            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
706
-        ) {
707
-            EE_Register_Model_Extensions::register(
708
-                $addon_name,
709
-                array(
710
-                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
711
-                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
712
-                )
713
-            );
714
-        }
715
-    }
680
+	/**
681
+	 * register new models and extensions
682
+	 *
683
+	 * @param string $addon_name
684
+	 * @return void
685
+	 * @throws \EE_Error
686
+	 */
687
+	private static function _register_models_and_extensions($addon_name)
688
+	{
689
+		// register new models
690
+		if (
691
+			! empty(self::$_settings[$addon_name]['model_paths'])
692
+			|| ! empty(self::$_settings[$addon_name]['class_paths'])
693
+		) {
694
+			EE_Register_Model::register(
695
+				$addon_name,
696
+				array(
697
+					'model_paths' => self::$_settings[$addon_name]['model_paths'],
698
+					'class_paths' => self::$_settings[$addon_name]['class_paths'],
699
+				)
700
+			);
701
+		}
702
+		// register model extensions
703
+		if (
704
+			! empty(self::$_settings[$addon_name]['model_extension_paths'])
705
+			|| ! empty(self::$_settings[$addon_name]['class_extension_paths'])
706
+		) {
707
+			EE_Register_Model_Extensions::register(
708
+				$addon_name,
709
+				array(
710
+					'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
711
+					'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
712
+				)
713
+			);
714
+		}
715
+	}
716 716
 
717 717
 
718
-    /**
719
-     * @param string $addon_name
720
-     * @return void
721
-     * @throws \EE_Error
722
-     */
723
-    private static function _register_data_migration_scripts($addon_name)
724
-    {
725
-        // setup DMS
726
-        if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
727
-            EE_Register_Data_Migration_Scripts::register(
728
-                $addon_name,
729
-                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
730
-            );
731
-        }
732
-    }
718
+	/**
719
+	 * @param string $addon_name
720
+	 * @return void
721
+	 * @throws \EE_Error
722
+	 */
723
+	private static function _register_data_migration_scripts($addon_name)
724
+	{
725
+		// setup DMS
726
+		if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
727
+			EE_Register_Data_Migration_Scripts::register(
728
+				$addon_name,
729
+				array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
730
+			);
731
+		}
732
+	}
733 733
 
734 734
 
735
-    /**
736
-     * @param string $addon_name
737
-     * @return void
738
-     * @throws \EE_Error
739
-     */
740
-    private static function _register_config($addon_name)
741
-    {
742
-        // if config_class is present let's register config.
743
-        if (! empty(self::$_settings[$addon_name]['config_class'])) {
744
-            EE_Register_Config::register(
745
-                self::$_settings[$addon_name]['config_class'],
746
-                array(
747
-                    'config_section' => self::$_settings[$addon_name]['config_section'],
748
-                    'config_name'    => self::$_settings[$addon_name]['config_name'],
749
-                )
750
-            );
751
-        }
752
-    }
735
+	/**
736
+	 * @param string $addon_name
737
+	 * @return void
738
+	 * @throws \EE_Error
739
+	 */
740
+	private static function _register_config($addon_name)
741
+	{
742
+		// if config_class is present let's register config.
743
+		if (! empty(self::$_settings[$addon_name]['config_class'])) {
744
+			EE_Register_Config::register(
745
+				self::$_settings[$addon_name]['config_class'],
746
+				array(
747
+					'config_section' => self::$_settings[$addon_name]['config_section'],
748
+					'config_name'    => self::$_settings[$addon_name]['config_name'],
749
+				)
750
+			);
751
+		}
752
+	}
753 753
 
754 754
 
755
-    /**
756
-     * @param string $addon_name
757
-     * @return void
758
-     * @throws \EE_Error
759
-     */
760
-    private static function _register_admin_pages($addon_name)
761
-    {
762
-        if (! empty(self::$_settings[$addon_name]['admin_path'])) {
763
-            EE_Register_Admin_Page::register(
764
-                $addon_name,
765
-                array('page_path' => self::$_settings[$addon_name]['admin_path'])
766
-            );
767
-        }
768
-    }
755
+	/**
756
+	 * @param string $addon_name
757
+	 * @return void
758
+	 * @throws \EE_Error
759
+	 */
760
+	private static function _register_admin_pages($addon_name)
761
+	{
762
+		if (! empty(self::$_settings[$addon_name]['admin_path'])) {
763
+			EE_Register_Admin_Page::register(
764
+				$addon_name,
765
+				array('page_path' => self::$_settings[$addon_name]['admin_path'])
766
+			);
767
+		}
768
+	}
769 769
 
770 770
 
771
-    /**
772
-     * @param string $addon_name
773
-     * @return void
774
-     * @throws \EE_Error
775
-     */
776
-    private static function _register_modules($addon_name)
777
-    {
778
-        if (! empty(self::$_settings[$addon_name]['module_paths'])) {
779
-            EE_Register_Module::register(
780
-                $addon_name,
781
-                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
782
-            );
783
-        }
784
-    }
771
+	/**
772
+	 * @param string $addon_name
773
+	 * @return void
774
+	 * @throws \EE_Error
775
+	 */
776
+	private static function _register_modules($addon_name)
777
+	{
778
+		if (! empty(self::$_settings[$addon_name]['module_paths'])) {
779
+			EE_Register_Module::register(
780
+				$addon_name,
781
+				array('module_paths' => self::$_settings[$addon_name]['module_paths'])
782
+			);
783
+		}
784
+	}
785 785
 
786 786
 
787
-    /**
788
-     * @param string $addon_name
789
-     * @return void
790
-     * @throws \EE_Error
791
-     */
792
-    private static function _register_shortcodes($addon_name)
793
-    {
794
-        if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
795
-            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
796
-        ) {
797
-            EE_Register_Shortcode::register(
798
-                $addon_name,
799
-                array(
800
-                    'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
801
-                        ? self::$_settings[$addon_name]['shortcode_paths']
802
-                        : array(),
803
-                    'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
804
-                        ? self::$_settings[$addon_name]['shortcode_fqcns']
805
-                        : array()
806
-                )
807
-            );
808
-        }
809
-    }
787
+	/**
788
+	 * @param string $addon_name
789
+	 * @return void
790
+	 * @throws \EE_Error
791
+	 */
792
+	private static function _register_shortcodes($addon_name)
793
+	{
794
+		if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
795
+			|| ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
796
+		) {
797
+			EE_Register_Shortcode::register(
798
+				$addon_name,
799
+				array(
800
+					'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
801
+						? self::$_settings[$addon_name]['shortcode_paths']
802
+						: array(),
803
+					'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
804
+						? self::$_settings[$addon_name]['shortcode_fqcns']
805
+						: array()
806
+				)
807
+			);
808
+		}
809
+	}
810 810
 
811 811
 
812
-    /**
813
-     * @param string $addon_name
814
-     * @return void
815
-     * @throws \EE_Error
816
-     */
817
-    private static function _register_widgets($addon_name)
818
-    {
819
-        if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
820
-            EE_Register_Widget::register(
821
-                $addon_name,
822
-                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
823
-            );
824
-        }
825
-    }
812
+	/**
813
+	 * @param string $addon_name
814
+	 * @return void
815
+	 * @throws \EE_Error
816
+	 */
817
+	private static function _register_widgets($addon_name)
818
+	{
819
+		if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
820
+			EE_Register_Widget::register(
821
+				$addon_name,
822
+				array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
823
+			);
824
+		}
825
+	}
826 826
 
827 827
 
828
-    /**
829
-     * @param string $addon_name
830
-     * @return void
831
-     * @throws \EE_Error
832
-     */
833
-    private static function _register_capabilities($addon_name)
834
-    {
835
-        if (! empty(self::$_settings[$addon_name]['capabilities'])) {
836
-            EE_Register_Capabilities::register(
837
-                $addon_name,
838
-                array(
839
-                    'capabilities'       => self::$_settings[$addon_name]['capabilities'],
840
-                    'capability_maps'    => self::$_settings[$addon_name]['capability_maps'],
841
-                )
842
-            );
843
-        }
844
-    }
828
+	/**
829
+	 * @param string $addon_name
830
+	 * @return void
831
+	 * @throws \EE_Error
832
+	 */
833
+	private static function _register_capabilities($addon_name)
834
+	{
835
+		if (! empty(self::$_settings[$addon_name]['capabilities'])) {
836
+			EE_Register_Capabilities::register(
837
+				$addon_name,
838
+				array(
839
+					'capabilities'       => self::$_settings[$addon_name]['capabilities'],
840
+					'capability_maps'    => self::$_settings[$addon_name]['capability_maps'],
841
+				)
842
+			);
843
+		}
844
+	}
845 845
 
846 846
 
847
-    /**
848
-     * @param string $addon_name
849
-     * @return void
850
-     * @throws \EE_Error
851
-     */
852
-    private static function _register_message_types($addon_name)
853
-    {
854
-        if (! empty(self::$_settings[$addon_name]['message_types'])) {
855
-            add_action(
856
-                'EE_Brewing_Regular___messages_caf',
857
-                array('EE_Register_Addon', 'register_message_types')
858
-            );
859
-        }
860
-    }
847
+	/**
848
+	 * @param string $addon_name
849
+	 * @return void
850
+	 * @throws \EE_Error
851
+	 */
852
+	private static function _register_message_types($addon_name)
853
+	{
854
+		if (! empty(self::$_settings[$addon_name]['message_types'])) {
855
+			add_action(
856
+				'EE_Brewing_Regular___messages_caf',
857
+				array('EE_Register_Addon', 'register_message_types')
858
+			);
859
+		}
860
+	}
861 861
 
862 862
 
863
-    /**
864
-     * @param string $addon_name
865
-     * @return void
866
-     * @throws \EE_Error
867
-     */
868
-    private static function _register_custom_post_types($addon_name)
869
-    {
870
-        if (
871
-            ! empty(self::$_settings[$addon_name]['custom_post_types'])
872
-            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
873
-        ) {
874
-            EE_Register_CPT::register(
875
-                $addon_name,
876
-                array(
877
-                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
878
-                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
879
-                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
880
-                )
881
-            );
882
-        }
883
-    }
863
+	/**
864
+	 * @param string $addon_name
865
+	 * @return void
866
+	 * @throws \EE_Error
867
+	 */
868
+	private static function _register_custom_post_types($addon_name)
869
+	{
870
+		if (
871
+			! empty(self::$_settings[$addon_name]['custom_post_types'])
872
+			|| ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
873
+		) {
874
+			EE_Register_CPT::register(
875
+				$addon_name,
876
+				array(
877
+					'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
878
+					'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
879
+					'default_terms' => self::$_settings[$addon_name]['default_terms'],
880
+				)
881
+			);
882
+		}
883
+	}
884 884
 
885 885
 
886
-    /**
887
-     * @param string $addon_name
888
-     * @return void
889
-     * @throws \EE_Error
890
-     */
891
-    private static function _register_payment_methods($addon_name)
892
-    {
893
-        if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
894
-            EE_Register_Payment_Method::register(
895
-                $addon_name,
896
-                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
897
-            );
898
-        }
899
-    }
886
+	/**
887
+	 * @param string $addon_name
888
+	 * @return void
889
+	 * @throws \EE_Error
890
+	 */
891
+	private static function _register_payment_methods($addon_name)
892
+	{
893
+		if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
894
+			EE_Register_Payment_Method::register(
895
+				$addon_name,
896
+				array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
897
+			);
898
+		}
899
+	}
900 900
 
901 901
 
902
-    /**
903
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
904
-     *
905
-     * @param string $addon_name
906
-     * @return EE_Addon
907
-     */
908
-    private static function _load_and_init_addon_class($addon_name)
909
-    {
910
-        $addon = EE_Registry::instance()->load_addon(
911
-            dirname(self::$_settings[$addon_name]['main_file_path']),
912
-            self::$_settings[$addon_name]['class_name']
913
-        );
914
-        $addon->set_name($addon_name);
915
-        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
916
-        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
917
-        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
918
-        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
919
-        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
920
-        $addon->set_version(self::$_settings[$addon_name]['version']);
921
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
922
-        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
923
-        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
924
-        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
925
-        //unfortunately this can't be hooked in upon construction, because we don't have
926
-        //the plugin mainfile's path upon construction.
927
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
928
-        // call any additional admin_callback functions during load_admin_controller hook
929
-        if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
930
-            add_action(
931
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
932
-                array($addon, self::$_settings[$addon_name]['admin_callback'])
933
-            );
934
-        }
935
-        return $addon;
936
-    }
902
+	/**
903
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
904
+	 *
905
+	 * @param string $addon_name
906
+	 * @return EE_Addon
907
+	 */
908
+	private static function _load_and_init_addon_class($addon_name)
909
+	{
910
+		$addon = EE_Registry::instance()->load_addon(
911
+			dirname(self::$_settings[$addon_name]['main_file_path']),
912
+			self::$_settings[$addon_name]['class_name']
913
+		);
914
+		$addon->set_name($addon_name);
915
+		$addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
916
+		$addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
917
+		$addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
918
+		$addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
919
+		$addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
920
+		$addon->set_version(self::$_settings[$addon_name]['version']);
921
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
922
+		$addon->set_config_section(self::$_settings[$addon_name]['config_section']);
923
+		$addon->set_config_class(self::$_settings[$addon_name]['config_class']);
924
+		$addon->set_config_name(self::$_settings[$addon_name]['config_name']);
925
+		//unfortunately this can't be hooked in upon construction, because we don't have
926
+		//the plugin mainfile's path upon construction.
927
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
928
+		// call any additional admin_callback functions during load_admin_controller hook
929
+		if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
930
+			add_action(
931
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
932
+				array($addon, self::$_settings[$addon_name]['admin_callback'])
933
+			);
934
+		}
935
+		return $addon;
936
+	}
937 937
 
938 938
 
939
-    /**
940
-     *    load_pue_update - Update notifications
941
-     *
942
-     * @return    void
943
-     */
944
-    public static function load_pue_update()
945
-    {
946
-        // load PUE client
947
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
948
-        // cycle thru settings
949
-        foreach (self::$_settings as $settings) {
950
-            if (! empty($settings['pue_options'])) {
951
-                // initiate the class and start the plugin update engine!
952
-                new PluginUpdateEngineChecker(
953
-                // host file URL
954
-                    'https://eventespresso.com',
955
-                    // plugin slug(s)
956
-                    array(
957
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
958
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
959
-                    ),
960
-                    // options
961
-                    array(
962
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
963
-                        'lang_domain'       => 'event_espresso',
964
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
965
-                        'option_key'        => 'site_license_key',
966
-                        'options_page_slug' => 'event_espresso',
967
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
968
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
969
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
970
-                    )
971
-                );
972
-            }
973
-        }
974
-    }
939
+	/**
940
+	 *    load_pue_update - Update notifications
941
+	 *
942
+	 * @return    void
943
+	 */
944
+	public static function load_pue_update()
945
+	{
946
+		// load PUE client
947
+		require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
948
+		// cycle thru settings
949
+		foreach (self::$_settings as $settings) {
950
+			if (! empty($settings['pue_options'])) {
951
+				// initiate the class and start the plugin update engine!
952
+				new PluginUpdateEngineChecker(
953
+				// host file URL
954
+					'https://eventespresso.com',
955
+					// plugin slug(s)
956
+					array(
957
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
958
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
959
+					),
960
+					// options
961
+					array(
962
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
963
+						'lang_domain'       => 'event_espresso',
964
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
965
+						'option_key'        => 'site_license_key',
966
+						'options_page_slug' => 'event_espresso',
967
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
968
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
969
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
970
+					)
971
+				);
972
+			}
973
+		}
974
+	}
975 975
 
976 976
 
977
-    /**
978
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
979
-     *
980
-     * @since 4.4.0
981
-     * @return void
982
-     * @throws \EE_Error
983
-     */
984
-    public static function register_message_types()
985
-    {
986
-        foreach (self::$_settings as $addon_name => $settings) {
987
-            if (! empty($settings['message_types'])) {
988
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
989
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
990
-                }
991
-            }
992
-        }
993
-    }
977
+	/**
978
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
979
+	 *
980
+	 * @since 4.4.0
981
+	 * @return void
982
+	 * @throws \EE_Error
983
+	 */
984
+	public static function register_message_types()
985
+	{
986
+		foreach (self::$_settings as $addon_name => $settings) {
987
+			if (! empty($settings['message_types'])) {
988
+				foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
989
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
990
+				}
991
+			}
992
+		}
993
+	}
994 994
 
995 995
 
996
-    /**
997
-     * This deregisters an addon that was previously registered with a specific addon_name.
998
-     *
999
-     * @since    4.3.0
1000
-     * @param string $addon_name the name for the addon that was previously registered
1001
-     * @throws EE_Error
1002
-     * @return void
1003
-     */
1004
-    public static function deregister($addon_name = null)
1005
-    {
1006
-        if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
1007
-            do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1008
-            $class_name = self::$_settings[$addon_name]['class_name'];
1009
-            if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
1010
-                // setup DMS
1011
-                EE_Register_Data_Migration_Scripts::deregister($addon_name);
1012
-            }
1013
-            if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1014
-                // register admin page
1015
-                EE_Register_Admin_Page::deregister($addon_name);
1016
-            }
1017
-            if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1018
-                // add to list of modules to be registered
1019
-                EE_Register_Module::deregister($addon_name);
1020
-            }
1021
-            if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
1022
-                || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1023
-            ) {
1024
-                // add to list of shortcodes to be registered
1025
-                EE_Register_Shortcode::deregister($addon_name);
1026
-            }
1027
-            if (! empty(self::$_settings[$addon_name]['config_class'])) {
1028
-                // if config_class present let's register config.
1029
-                EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1030
-            }
1031
-            if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1032
-                // add to list of widgets to be registered
1033
-                EE_Register_Widget::deregister($addon_name);
1034
-            }
1035
-            if (! empty(self::$_settings[$addon_name]['model_paths'])
1036
-                ||
1037
-                ! empty(self::$_settings[$addon_name]['class_paths'])
1038
-            ) {
1039
-                // add to list of shortcodes to be registered
1040
-                EE_Register_Model::deregister($addon_name);
1041
-            }
1042
-            if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1043
-                ||
1044
-                ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1045
-            ) {
1046
-                // add to list of shortcodes to be registered
1047
-                EE_Register_Model_Extensions::deregister($addon_name);
1048
-            }
1049
-            if (! empty(self::$_settings[$addon_name]['message_types'])) {
1050
-                foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1051
-                    EE_Register_Message_Type::deregister($message_type);
1052
-                }
1053
-            }
1054
-            //deregister capabilities for addon
1055
-            if (
1056
-                ! empty(self::$_settings[$addon_name]['capabilities'])
1057
-                || ! empty(self::$_settings[$addon_name]['capability_maps'])
1058
-            ) {
1059
-                EE_Register_Capabilities::deregister($addon_name);
1060
-            }
1061
-            //deregister custom_post_types for addon
1062
-            if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1063
-                EE_Register_CPT::deregister($addon_name);
1064
-            }
1065
-            if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1066
-                EE_Register_Payment_Method::deregister($addon_name);
1067
-            }
1068
-            remove_action(
1069
-                'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1070
-                array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1071
-            );
1072
-            remove_action(
1073
-                'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1074
-                array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required')
1075
-            );
1076
-            unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]);
1077
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1078
-        }
1079
-    }
996
+	/**
997
+	 * This deregisters an addon that was previously registered with a specific addon_name.
998
+	 *
999
+	 * @since    4.3.0
1000
+	 * @param string $addon_name the name for the addon that was previously registered
1001
+	 * @throws EE_Error
1002
+	 * @return void
1003
+	 */
1004
+	public static function deregister($addon_name = null)
1005
+	{
1006
+		if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
1007
+			do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1008
+			$class_name = self::$_settings[$addon_name]['class_name'];
1009
+			if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
1010
+				// setup DMS
1011
+				EE_Register_Data_Migration_Scripts::deregister($addon_name);
1012
+			}
1013
+			if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1014
+				// register admin page
1015
+				EE_Register_Admin_Page::deregister($addon_name);
1016
+			}
1017
+			if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1018
+				// add to list of modules to be registered
1019
+				EE_Register_Module::deregister($addon_name);
1020
+			}
1021
+			if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
1022
+				|| ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1023
+			) {
1024
+				// add to list of shortcodes to be registered
1025
+				EE_Register_Shortcode::deregister($addon_name);
1026
+			}
1027
+			if (! empty(self::$_settings[$addon_name]['config_class'])) {
1028
+				// if config_class present let's register config.
1029
+				EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1030
+			}
1031
+			if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1032
+				// add to list of widgets to be registered
1033
+				EE_Register_Widget::deregister($addon_name);
1034
+			}
1035
+			if (! empty(self::$_settings[$addon_name]['model_paths'])
1036
+				||
1037
+				! empty(self::$_settings[$addon_name]['class_paths'])
1038
+			) {
1039
+				// add to list of shortcodes to be registered
1040
+				EE_Register_Model::deregister($addon_name);
1041
+			}
1042
+			if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1043
+				||
1044
+				! empty(self::$_settings[$addon_name]['class_extension_paths'])
1045
+			) {
1046
+				// add to list of shortcodes to be registered
1047
+				EE_Register_Model_Extensions::deregister($addon_name);
1048
+			}
1049
+			if (! empty(self::$_settings[$addon_name]['message_types'])) {
1050
+				foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1051
+					EE_Register_Message_Type::deregister($message_type);
1052
+				}
1053
+			}
1054
+			//deregister capabilities for addon
1055
+			if (
1056
+				! empty(self::$_settings[$addon_name]['capabilities'])
1057
+				|| ! empty(self::$_settings[$addon_name]['capability_maps'])
1058
+			) {
1059
+				EE_Register_Capabilities::deregister($addon_name);
1060
+			}
1061
+			//deregister custom_post_types for addon
1062
+			if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1063
+				EE_Register_CPT::deregister($addon_name);
1064
+			}
1065
+			if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1066
+				EE_Register_Payment_Method::deregister($addon_name);
1067
+			}
1068
+			remove_action(
1069
+				'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1070
+				array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1071
+			);
1072
+			remove_action(
1073
+				'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1074
+				array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required')
1075
+			);
1076
+			unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]);
1077
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1078
+		}
1079
+	}
1080 1080
 
1081 1081
 
1082 1082
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
         // offsets:    0 . 1 . 2 . 3 . 4
67 67
         $version_parts = explode('.', $min_core_version);
68 68
         //check they specified the micro version (after 2nd period)
69
-        if (! isset($version_parts[2])) {
69
+        if ( ! isset($version_parts[2])) {
70 70
             $version_parts[2] = '0';
71 71
         }
72 72
         //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73 73
         //soon we can assume that's 'rc', but this current version is 'alpha'
74
-        if (! isset($version_parts[3])) {
74
+        if ( ! isset($version_parts[3])) {
75 75
             $version_parts[3] = 'dev';
76 76
         }
77
-        if (! isset($version_parts[4])) {
77
+        if ( ! isset($version_parts[4])) {
78 78
             $version_parts[4] = '000';
79 79
         }
80 80
         return implode('.', $version_parts);
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         // setup PUE
232 232
         \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233 233
         // does this addon work with this version of core or WordPress ?
234
-        if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
234
+        if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235 235
             return;
236 236
         }
237 237
         // register namespaces
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 )
289 289
             );
290 290
         }
291
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
291
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292 292
             throw new EE_Error(
293 293
                 sprintf(
294 294
                     __(
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         } else {
330 330
             $class_name = $setup_args['class_name'];
331 331
         }
332
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
332
+        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name;
333 333
     }
334 334
 
335 335
 
@@ -346,108 +346,108 @@  discard block
 block discarded – undo
346 346
             'class_name'            => $class_name,
347 347
             // the addon slug for use in URLs, etc
348 348
             'plugin_slug'           => isset($setup_args['plugin_slug'])
349
-                ? (string)$setup_args['plugin_slug']
349
+                ? (string) $setup_args['plugin_slug']
350 350
                 : '',
351 351
             // page slug to be used when generating the "Settings" link on the WP plugin page
352 352
             'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
-                ? (string)$setup_args['plugin_action_slug']
353
+                ? (string) $setup_args['plugin_action_slug']
354 354
                 : '',
355 355
             // the "software" version for the addon
356 356
             'version'               => isset($setup_args['version'])
357
-                ? (string)$setup_args['version']
357
+                ? (string) $setup_args['version']
358 358
                 : '',
359 359
             // the minimum version of EE Core that the addon will work with
360 360
             'min_core_version'      => isset($setup_args['min_core_version'])
361
-                ? (string)$setup_args['min_core_version']
361
+                ? (string) $setup_args['min_core_version']
362 362
                 : '',
363 363
             // the minimum version of WordPress that the addon will work with
364 364
             'min_wp_version'        => isset($setup_args['min_wp_version'])
365
-                ? (string)$setup_args['min_wp_version']
365
+                ? (string) $setup_args['min_wp_version']
366 366
                 : EE_MIN_WP_VER_REQUIRED,
367 367
             // full server path to main file (file loaded directly by WP)
368 368
             'main_file_path'        => isset($setup_args['main_file_path'])
369
-                ? (string)$setup_args['main_file_path']
369
+                ? (string) $setup_args['main_file_path']
370 370
                 : '',
371 371
             // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372 372
             'admin_path'            => isset($setup_args['admin_path'])
373
-                ? (string)$setup_args['admin_path'] : '',
373
+                ? (string) $setup_args['admin_path'] : '',
374 374
             // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375 375
             'admin_callback'        => isset($setup_args['admin_callback'])
376
-                ? (string)$setup_args['admin_callback']
376
+                ? (string) $setup_args['admin_callback']
377 377
                 : '',
378 378
             // the section name for this addon's configuration settings section (defaults to "addons")
379 379
             'config_section'        => isset($setup_args['config_section'])
380
-                ? (string)$setup_args['config_section']
380
+                ? (string) $setup_args['config_section']
381 381
                 : 'addons',
382 382
             // the class name for this addon's configuration settings object
383 383
             'config_class'          => isset($setup_args['config_class'])
384
-                ? (string)$setup_args['config_class'] : '',
384
+                ? (string) $setup_args['config_class'] : '',
385 385
             //the name given to the config for this addons' configuration settings object (optional)
386 386
             'config_name'           => isset($setup_args['config_name'])
387
-                ? (string)$setup_args['config_name'] : '',
387
+                ? (string) $setup_args['config_name'] : '',
388 388
             // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389 389
             'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
-                ? (array)$setup_args['autoloader_paths']
390
+                ? (array) $setup_args['autoloader_paths']
391 391
                 : array(),
392 392
             // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393 393
             'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
-                ? (array)$setup_args['autoloader_folders']
394
+                ? (array) $setup_args['autoloader_folders']
395 395
                 : array(),
396 396
             // array of full server paths to any EE_DMS data migration scripts used by the addon
397 397
             'dms_paths'             => isset($setup_args['dms_paths'])
398
-                ? (array)$setup_args['dms_paths']
398
+                ? (array) $setup_args['dms_paths']
399 399
                 : array(),
400 400
             // array of full server paths to any EED_Modules used by the addon
401 401
             'module_paths'          => isset($setup_args['module_paths'])
402
-                ? (array)$setup_args['module_paths']
402
+                ? (array) $setup_args['module_paths']
403 403
                 : array(),
404 404
             // array of full server paths to any EES_Shortcodes used by the addon
405 405
             'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
-                ? (array)$setup_args['shortcode_paths']
406
+                ? (array) $setup_args['shortcode_paths']
407 407
                 : array(),
408 408
             'shortcode_fqcns' => isset($setup_args['shortcode_fqcns'])
409 409
                 ? (array) $setup_args['shortcode_fqcns']
410 410
                 : array(),
411 411
             // array of full server paths to any WP_Widgets used by the addon
412 412
             'widget_paths'          => isset($setup_args['widget_paths'])
413
-                ? (array)$setup_args['widget_paths']
413
+                ? (array) $setup_args['widget_paths']
414 414
                 : array(),
415 415
             // array of PUE options used by the addon
416 416
             'pue_options'           => isset($setup_args['pue_options'])
417
-                ? (array)$setup_args['pue_options']
417
+                ? (array) $setup_args['pue_options']
418 418
                 : array(),
419 419
             'message_types'         => isset($setup_args['message_types'])
420
-                ? (array)$setup_args['message_types']
420
+                ? (array) $setup_args['message_types']
421 421
                 : array(),
422 422
             'capabilities'          => isset($setup_args['capabilities'])
423
-                ? (array)$setup_args['capabilities']
423
+                ? (array) $setup_args['capabilities']
424 424
                 : array(),
425 425
             'capability_maps'       => isset($setup_args['capability_maps'])
426
-                ? (array)$setup_args['capability_maps']
426
+                ? (array) $setup_args['capability_maps']
427 427
                 : array(),
428 428
             'model_paths'           => isset($setup_args['model_paths'])
429
-                ? (array)$setup_args['model_paths']
429
+                ? (array) $setup_args['model_paths']
430 430
                 : array(),
431 431
             'class_paths'           => isset($setup_args['class_paths'])
432
-                ? (array)$setup_args['class_paths']
432
+                ? (array) $setup_args['class_paths']
433 433
                 : array(),
434 434
             'model_extension_paths' => isset($setup_args['model_extension_paths'])
435
-                ? (array)$setup_args['model_extension_paths']
435
+                ? (array) $setup_args['model_extension_paths']
436 436
                 : array(),
437 437
             'class_extension_paths' => isset($setup_args['class_extension_paths'])
438
-                ? (array)$setup_args['class_extension_paths']
438
+                ? (array) $setup_args['class_extension_paths']
439 439
                 : array(),
440 440
             'custom_post_types'     => isset($setup_args['custom_post_types'])
441
-                ? (array)$setup_args['custom_post_types']
441
+                ? (array) $setup_args['custom_post_types']
442 442
                 : array(),
443 443
             'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
444
-                ? (array)$setup_args['custom_taxonomies']
444
+                ? (array) $setup_args['custom_taxonomies']
445 445
                 : array(),
446 446
             'payment_method_paths'  => isset($setup_args['payment_method_paths'])
447
-                ? (array)$setup_args['payment_method_paths']
447
+                ? (array) $setup_args['payment_method_paths']
448 448
                 : array(),
449 449
             'default_terms'         => isset($setup_args['default_terms'])
450
-                ? (array)$setup_args['default_terms']
450
+                ? (array) $setup_args['default_terms']
451 451
                 : array(),
452 452
             // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
453 453
             // that can be used for adding upgrading/marketing info
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
                 $setup_args['namespace']['FQNS'],
460 460
                 $setup_args['namespace']['DIR']
461 461
             )
462
-                ? (array)$setup_args['namespace']
462
+                ? (array) $setup_args['namespace']
463 463
                 : array(),
464 464
         );
465 465
         // if plugin_action_slug is NOT set, but an admin page path IS set,
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
                 '</span><br />'
530 530
             );
531 531
         }
532
-        if (! empty($incompatibility_message)) {
532
+        if ( ! empty($incompatibility_message)) {
533 533
             // remove 'activate' from the REQUEST
534 534
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
535 535
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -557,19 +557,19 @@  discard block
 block discarded – undo
557 557
      */
558 558
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
559 559
     {
560
-        if (! empty($setup_args['pue_options'])) {
560
+        if ( ! empty($setup_args['pue_options'])) {
561 561
             self::$_settings[$addon_name]['pue_options'] = array(
562 562
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
563
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
564
-                    : 'espresso_' . strtolower($class_name),
563
+                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
564
+                    : 'espresso_'.strtolower($class_name),
565 565
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
566
-                    ? (string)$setup_args['pue_options']['plugin_basename']
566
+                    ? (string) $setup_args['pue_options']['plugin_basename']
567 567
                     : plugin_basename($setup_args['main_file_path']),
568 568
                 'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
569
-                    ? (string)$setup_args['pue_options']['checkPeriod']
569
+                    ? (string) $setup_args['pue_options']['checkPeriod']
570 570
                     : '24',
571 571
                 'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
572
-                    ? (string)$setup_args['pue_options']['use_wp_update']
572
+                    ? (string) $setup_args['pue_options']['use_wp_update']
573 573
                     : false,
574 574
             );
575 575
             add_action(
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
             //(as the newly-activated addon wasn't around the first time addons were registered).
618 618
             //Note: the presence of pue_options in the addon registration options will initialize the $_settings
619 619
             //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
620
-            if (! isset(self::$_settings[$addon_name])
620
+            if ( ! isset(self::$_settings[$addon_name])
621 621
                 || (isset(self::$_settings[$addon_name])
622 622
                     && ! isset(self::$_settings[$addon_name]['class_name'])
623 623
                 )
@@ -664,13 +664,13 @@  discard block
 block discarded – undo
664 664
      */
665 665
     private static function _setup_autoloaders($addon_name)
666 666
     {
667
-        if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
667
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
668 668
             // setup autoloader for single file
669 669
             EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
670 670
         }
671 671
         // setup autoloaders for folders
672
-        if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
672
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
673
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
674 674
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
675 675
             }
676 676
         }
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
     private static function _register_data_migration_scripts($addon_name)
724 724
     {
725 725
         // setup DMS
726
-        if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
726
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
727 727
             EE_Register_Data_Migration_Scripts::register(
728 728
                 $addon_name,
729 729
                 array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
     private static function _register_config($addon_name)
741 741
     {
742 742
         // if config_class is present let's register config.
743
-        if (! empty(self::$_settings[$addon_name]['config_class'])) {
743
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
744 744
             EE_Register_Config::register(
745 745
                 self::$_settings[$addon_name]['config_class'],
746 746
                 array(
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
      */
760 760
     private static function _register_admin_pages($addon_name)
761 761
     {
762
-        if (! empty(self::$_settings[$addon_name]['admin_path'])) {
762
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
763 763
             EE_Register_Admin_Page::register(
764 764
                 $addon_name,
765 765
                 array('page_path' => self::$_settings[$addon_name]['admin_path'])
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
      */
776 776
     private static function _register_modules($addon_name)
777 777
     {
778
-        if (! empty(self::$_settings[$addon_name]['module_paths'])) {
778
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
779 779
             EE_Register_Module::register(
780 780
                 $addon_name,
781 781
                 array('module_paths' => self::$_settings[$addon_name]['module_paths'])
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
      */
792 792
     private static function _register_shortcodes($addon_name)
793 793
     {
794
-        if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
794
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
795 795
             || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
796 796
         ) {
797 797
             EE_Register_Shortcode::register(
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
      */
817 817
     private static function _register_widgets($addon_name)
818 818
     {
819
-        if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
819
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
820 820
             EE_Register_Widget::register(
821 821
                 $addon_name,
822 822
                 array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
      */
833 833
     private static function _register_capabilities($addon_name)
834 834
     {
835
-        if (! empty(self::$_settings[$addon_name]['capabilities'])) {
835
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
836 836
             EE_Register_Capabilities::register(
837 837
                 $addon_name,
838 838
                 array(
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
      */
852 852
     private static function _register_message_types($addon_name)
853 853
     {
854
-        if (! empty(self::$_settings[$addon_name]['message_types'])) {
854
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
855 855
             add_action(
856 856
                 'EE_Brewing_Regular___messages_caf',
857 857
                 array('EE_Register_Addon', 'register_message_types')
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
      */
891 891
     private static function _register_payment_methods($addon_name)
892 892
     {
893
-        if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
893
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
894 894
             EE_Register_Payment_Method::register(
895 895
                 $addon_name,
896 896
                 array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
         //the plugin mainfile's path upon construction.
927 927
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
928 928
         // call any additional admin_callback functions during load_admin_controller hook
929
-        if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
929
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
930 930
             add_action(
931 931
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
932 932
                 array($addon, self::$_settings[$addon_name]['admin_callback'])
@@ -944,10 +944,10 @@  discard block
 block discarded – undo
944 944
     public static function load_pue_update()
945 945
     {
946 946
         // load PUE client
947
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
947
+        require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php';
948 948
         // cycle thru settings
949 949
         foreach (self::$_settings as $settings) {
950
-            if (! empty($settings['pue_options'])) {
950
+            if ( ! empty($settings['pue_options'])) {
951 951
                 // initiate the class and start the plugin update engine!
952 952
                 new PluginUpdateEngineChecker(
953 953
                 // host file URL
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
                     // plugin slug(s)
956 956
                     array(
957 957
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
958
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
958
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
959 959
                     ),
960 960
                     // options
961 961
                     array(
@@ -984,8 +984,8 @@  discard block
 block discarded – undo
984 984
     public static function register_message_types()
985 985
     {
986 986
         foreach (self::$_settings as $addon_name => $settings) {
987
-            if (! empty($settings['message_types'])) {
988
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
987
+            if ( ! empty($settings['message_types'])) {
988
+                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
989 989
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
990 990
                 }
991 991
             }
@@ -1006,48 +1006,48 @@  discard block
 block discarded – undo
1006 1006
         if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
1007 1007
             do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1008 1008
             $class_name = self::$_settings[$addon_name]['class_name'];
1009
-            if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
1009
+            if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1010 1010
                 // setup DMS
1011 1011
                 EE_Register_Data_Migration_Scripts::deregister($addon_name);
1012 1012
             }
1013
-            if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1013
+            if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1014 1014
                 // register admin page
1015 1015
                 EE_Register_Admin_Page::deregister($addon_name);
1016 1016
             }
1017
-            if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1017
+            if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1018 1018
                 // add to list of modules to be registered
1019 1019
                 EE_Register_Module::deregister($addon_name);
1020 1020
             }
1021
-            if (! empty(self::$_settings[$addon_name]['shortcode_paths'])
1021
+            if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1022 1022
                 || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1023 1023
             ) {
1024 1024
                 // add to list of shortcodes to be registered
1025 1025
                 EE_Register_Shortcode::deregister($addon_name);
1026 1026
             }
1027
-            if (! empty(self::$_settings[$addon_name]['config_class'])) {
1027
+            if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1028 1028
                 // if config_class present let's register config.
1029 1029
                 EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1030 1030
             }
1031
-            if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1031
+            if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1032 1032
                 // add to list of widgets to be registered
1033 1033
                 EE_Register_Widget::deregister($addon_name);
1034 1034
             }
1035
-            if (! empty(self::$_settings[$addon_name]['model_paths'])
1035
+            if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1036 1036
                 ||
1037 1037
                 ! empty(self::$_settings[$addon_name]['class_paths'])
1038 1038
             ) {
1039 1039
                 // add to list of shortcodes to be registered
1040 1040
                 EE_Register_Model::deregister($addon_name);
1041 1041
             }
1042
-            if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1042
+            if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1043 1043
                 ||
1044 1044
                 ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1045 1045
             ) {
1046 1046
                 // add to list of shortcodes to be registered
1047 1047
                 EE_Register_Model_Extensions::deregister($addon_name);
1048 1048
             }
1049
-            if (! empty(self::$_settings[$addon_name]['message_types'])) {
1050
-                foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1049
+            if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1050
+                foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1051 1051
                     EE_Register_Message_Type::deregister($message_type);
1052 1052
                 }
1053 1053
             }
@@ -1059,14 +1059,14 @@  discard block
 block discarded – undo
1059 1059
                 EE_Register_Capabilities::deregister($addon_name);
1060 1060
             }
1061 1061
             //deregister custom_post_types for addon
1062
-            if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1062
+            if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1063 1063
                 EE_Register_CPT::deregister($addon_name);
1064 1064
             }
1065
-            if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1065
+            if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1066 1066
                 EE_Register_Payment_Method::deregister($addon_name);
1067 1067
             }
1068 1068
             remove_action(
1069
-                'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1069
+                'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1070 1070
                 array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1071 1071
             );
1072 1072
             remove_action(
Please login to merge, or discard this patch.