Completed
Branch FET-9795-new-interfaces (793e2e)
by
unknown
121:05 queued 108:17
created
core/EE_Capabilities.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
      *
815 815
      * @since                        4.5.0
816 816
      * @param string $meta_cap       What meta capability is this mapping.
817
-     * @param array  $map_values     array {
817
+     * @param string[]  $map_values     array {
818 818
      *                               //array of values that MUST match a count of 4.  It's okay to send an empty string
819 819
      *                               for capabilities that don't get mapped to.
820 820
      * @type         $map_values     [0] string A string representing the model name. Required.  String's
@@ -885,8 +885,8 @@  discard block
 block discarded – undo
885 885
      * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
886 886
      * @since 4.6.x
887 887
      * @param $caps
888
-     * @param $cap
889
-     * @param $user_id
888
+     * @param string $cap
889
+     * @param integer $user_id
890 890
      * @param $args
891 891
      * @return array
892 892
      */
Please login to merge, or discard this patch.
Indentation   +1151 added lines, -1151 removed lines patch added patch discarded remove patch
@@ -16,806 +16,806 @@  discard block
 block discarded – undo
16 16
 final class EE_Capabilities extends EE_Base
17 17
 {
18 18
 
19
-    /**
20
-     * the name of the wp option used to store caps previously initialized
21
-     */
22
-    const option_name = 'ee_caps_initialized';
23
-
24
-    /**
25
-     * instance of EE_Capabilities object
26
-     *
27
-     * @var EE_Capabilities
28
-     */
29
-    private static $_instance;
30
-
31
-    /**
32
-     * This is a map of caps that correspond to a default WP_Role.
33
-     * Array is indexed by Role and values are ee capabilities.
34
-     *
35
-     * @since 4.5.0
36
-     * @var array
37
-     */
38
-    private $_caps_map = array();
39
-
40
-    /**
41
-     * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for
42
-     * a user depending on context.
43
-     *
44
-     * @var EE_Meta_Capability_Map[]
45
-     */
46
-    private $_meta_caps = array();
47
-
48
-
49
-    /**
50
-     * singleton method used to instantiate class object
51
-     *
52
-     * @since 4.5.0
53
-     * @return EE_Capabilities
54
-     */
55
-    public static function instance()
56
-    {
57
-        //check if instantiated, and if not do so.
58
-        if (! self::$_instance instanceof EE_Capabilities) {
59
-            self::$_instance = new self();
60
-        }
61
-        return self::$_instance;
62
-    }
63
-
64
-
65
-    /**
66
-     * private constructor
67
-     *
68
-     * @since 4.5.0
69
-     */
70
-    private function __construct()
71
-    {
72
-        if (is_admin()) {
73
-            add_filter(
74
-                'FHEE__EE_Capabilities__init_caps_map__caps',
75
-                array($this, 'register_additional_capabilities'),
76
-                10
77
-            );
78
-        }
79
-    }
80
-
81
-
82
-    /**
83
-     * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
84
-     *
85
-     * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
86
-     *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
87
-     *                    ensures that they are up to date.
88
-     * @since 4.5.0
89
-     * @return void
90
-     */
91
-    public function init_caps($reset = false)
92
-    {
93
-        /**
94
-         * Note, this means that caps can only initialized on the default roles when:
95
-         * - models are queryable
96
-         * - All addons have been registered  (which happens at plugins_loaded priority 1)
97
-         * In practice, currently this method is usually called around `init`.
98
-         */
99
-        if (
100
-            did_action('AHEE__EE_System__load_espresso_addons__complete')
101
-            && EE_Maintenance_Mode::instance()->models_can_query()
102
-        ) {
103
-            $this->_caps_map = $this->_init_caps_map();
104
-            $this->init_role_caps($reset);
105
-            $this->_set_meta_caps();
106
-        }
107
-    }
108
-
109
-
110
-    /**
111
-     * This sets the meta caps property.
112
-     *
113
-     * @since 4.5.0
114
-     * @return void
115
-     */
116
-    private function _set_meta_caps()
117
-    {
118
-        //make sure we're only ever initializing the default _meta_caps array once if it's empty.
119
-        $this->_meta_caps = $this->_get_default_meta_caps_array();
120
-        $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
121
-        //add filter for map_meta_caps but only if models can query.
122
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
123
-            add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * This builds and returns the default meta_caps array only once.
130
-     *
131
-     * @since  4.8.28.rc.012
132
-     * @return array
133
-     * @throws \EE_Error
134
-     */
135
-    private function _get_default_meta_caps_array()
136
-    {
137
-        static $default_meta_caps = array();
138
-        if (empty($default_meta_caps)) {
139
-            $default_meta_caps = array(
140
-                //edits
141
-                new EE_Meta_Capability_Map_Edit(
142
-                    'ee_edit_event',
143
-                    array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
144
-                ),
145
-                new EE_Meta_Capability_Map_Edit(
146
-                    'ee_edit_venue',
147
-                    array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
148
-                ),
149
-                new EE_Meta_Capability_Map_Edit(
150
-                    'ee_edit_registration',
151
-                    array('Registration', '', 'ee_edit_others_registrations', '')
152
-                ),
153
-                new EE_Meta_Capability_Map_Edit(
154
-                    'ee_edit_checkin',
155
-                    array('Registration', '', 'ee_edit_others_checkins', '')
156
-                ),
157
-                new EE_Meta_Capability_Map_Messages_Cap(
158
-                    'ee_edit_message',
159
-                    array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
160
-                ),
161
-                new EE_Meta_Capability_Map_Edit(
162
-                    'ee_edit_default_ticket',
163
-                    array('Ticket', '', 'ee_edit_others_default_tickets', '')
164
-                ),
165
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
166
-                    'ee_edit_question',
167
-                    array('Question', '', '', 'ee_edit_system_questions')
168
-                ),
169
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
170
-                    'ee_edit_question_group',
171
-                    array('Question_Group', '', '', 'ee_edit_system_question_groups')
172
-                ),
173
-                new EE_Meta_Capability_Map_Edit(
174
-                    'ee_edit_payment_method',
175
-                    array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
176
-                ),
177
-                //reads
178
-                new EE_Meta_Capability_Map_Read(
179
-                    'ee_read_event',
180
-                    array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
181
-                ),
182
-                new EE_Meta_Capability_Map_Read(
183
-                    'ee_read_venue',
184
-                    array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
185
-                ),
186
-                new EE_Meta_Capability_Map_Read(
187
-                    'ee_read_registration',
188
-                    array('Registration', '', '', 'ee_edit_others_registrations')
189
-                ),
190
-                new EE_Meta_Capability_Map_Read(
191
-                    'ee_read_checkin',
192
-                    array('Registration', '', '', 'ee_read_others_checkins')
193
-                ),
194
-                new EE_Meta_Capability_Map_Messages_Cap(
195
-                    'ee_read_message',
196
-                    array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
197
-                ),
198
-                new EE_Meta_Capability_Map_Read(
199
-                    'ee_read_default_ticket',
200
-                    array('Ticket', '', '', 'ee_read_others_default_tickets')
201
-                ),
202
-                new EE_Meta_Capability_Map_Read(
203
-                    'ee_read_payment_method',
204
-                    array('Payment_Method', '', '', 'ee_read_others_payment_methods')
205
-                ),
206
-                //deletes
207
-                new EE_Meta_Capability_Map_Delete(
208
-                    'ee_delete_event',
209
-                    array(
210
-                        'Event',
211
-                        'ee_delete_published_events',
212
-                        'ee_delete_others_events',
213
-                        'ee_delete_private_events',
214
-                    )
215
-                ),
216
-                new EE_Meta_Capability_Map_Delete(
217
-                    'ee_delete_venue',
218
-                    array(
219
-                        'Venue',
220
-                        'ee_delete_published_venues',
221
-                        'ee_delete_others_venues',
222
-                        'ee_delete_private_venues',
223
-                    )
224
-                ),
225
-                new EE_Meta_Capability_Map_Delete(
226
-                    'ee_delete_registration',
227
-                    array('Registration', '', 'ee_delete_others_registrations', '')
228
-                ),
229
-                new EE_Meta_Capability_Map_Delete(
230
-                    'ee_delete_checkin',
231
-                    array('Registration', '', 'ee_delete_others_checkins', '')
232
-                ),
233
-                new EE_Meta_Capability_Map_Messages_Cap(
234
-                    'ee_delete_message',
235
-                    array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
236
-                ),
237
-                new EE_Meta_Capability_Map_Delete(
238
-                    'ee_delete_default_ticket',
239
-                    array('Ticket', '', 'ee_delete_others_default_tickets', '')
240
-                ),
241
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
242
-                    'ee_delete_question',
243
-                    array('Question', '', '', 'delete_system_questions')
244
-                ),
245
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
246
-                    'ee_delete_question_group',
247
-                    array('Question_Group', '', '', 'delete_system_question_groups')
248
-                ),
249
-                new EE_Meta_Capability_Map_Delete(
250
-                    'ee_delete_payment_method',
251
-                    array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
252
-                ),
253
-            );
254
-        }
255
-        return $default_meta_caps;
256
-    }
257
-
258
-
259
-    /**
260
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
261
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
262
-     * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
263
-     *
264
-     * @since 4.5.0
265
-     * @see   wp-includes/capabilities.php
266
-     * @param array  $caps    actual users capabilities
267
-     * @param string $cap     initial capability name that is being checked (the "map" key)
268
-     * @param int    $user_id The user id
269
-     * @param array  $args    Adds context to the cap. Typically the object ID.
270
-     * @return array actual users capabilities
271
-     * @throws EE_Error
272
-     */
273
-    public function map_meta_caps($caps, $cap, $user_id, $args)
274
-    {
275
-        if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
276
-            //loop through our _meta_caps array
277
-            foreach ($this->_meta_caps as $meta_map) {
278
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
279
-                    continue;
280
-                }
281
-                $meta_map->ensure_is_model();
282
-                $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
283
-            }
284
-        }
285
-        return $caps;
286
-    }
287
-
288
-
289
-    /**
290
-     * This sets up and returns the initial capabilities map for Event Espresso
291
-     *
292
-     * @since 4.5.0
293
-     * @return array
294
-     */
295
-    private function _init_caps_map()
296
-    {
297
-        $caps = array(
298
-            'administrator'           => array(
299
-                //basic access
300
-                'ee_read_ee',
301
-                //gateways
302
-                /**
303
-                 * note that with payment method capabilities, although we've implemented
304
-                 * capability mapping which will be used for accessing payment methods owned by
305
-                 * other users.  This is not fully implemented yet in the payment method ui.
306
-                 * Currently only the "plural" caps are in active use.
307
-                 * (Specific payment method caps are in use as well).
308
-                 **/
309
-                'ee_manage_gateways',
310
-                'ee_read_payment_method',
311
-                'ee_read_payment_methods',
312
-                'ee_read_others_payment_methods',
313
-                'ee_edit_payment_method',
314
-                'ee_edit_payment_methods',
315
-                'ee_edit_others_payment_methods',
316
-                'ee_delete_payment_method',
317
-                'ee_delete_payment_methods',
318
-                //events
319
-                'ee_publish_events',
320
-                'ee_read_private_events',
321
-                'ee_read_others_events',
322
-                'ee_read_event',
323
-                'ee_read_events',
324
-                'ee_edit_event',
325
-                'ee_edit_events',
326
-                'ee_edit_published_events',
327
-                'ee_edit_others_events',
328
-                'ee_edit_private_events',
329
-                'ee_delete_published_events',
330
-                'ee_delete_private_events',
331
-                'ee_delete_event',
332
-                'ee_delete_events',
333
-                'ee_delete_others_events',
334
-                //event categories
335
-                'ee_manage_event_categories',
336
-                'ee_edit_event_category',
337
-                'ee_delete_event_category',
338
-                'ee_assign_event_category',
339
-                //venues
340
-                'ee_publish_venues',
341
-                'ee_read_venue',
342
-                'ee_read_venues',
343
-                'ee_read_others_venues',
344
-                'ee_read_private_venues',
345
-                'ee_edit_venue',
346
-                'ee_edit_venues',
347
-                'ee_edit_others_venues',
348
-                'ee_edit_published_venues',
349
-                'ee_edit_private_venues',
350
-                'ee_delete_venue',
351
-                'ee_delete_venues',
352
-                'ee_delete_others_venues',
353
-                'ee_delete_private_venues',
354
-                'ee_delete_published_venues',
355
-                //venue categories
356
-                'ee_manage_venue_categories',
357
-                'ee_edit_venue_category',
358
-                'ee_delete_venue_category',
359
-                'ee_assign_venue_category',
360
-                //contacts
361
-                'ee_read_contact',
362
-                'ee_read_contacts',
363
-                'ee_edit_contact',
364
-                'ee_edit_contacts',
365
-                'ee_delete_contact',
366
-                'ee_delete_contacts',
367
-                //registrations
368
-                'ee_read_registration',
369
-                'ee_read_registrations',
370
-                'ee_read_others_registrations',
371
-                'ee_edit_registration',
372
-                'ee_edit_registrations',
373
-                'ee_edit_others_registrations',
374
-                'ee_delete_registration',
375
-                'ee_delete_registrations',
376
-                //checkins
377
-                'ee_read_checkin',
378
-                'ee_read_others_checkins',
379
-                'ee_read_checkins',
380
-                'ee_edit_checkin',
381
-                'ee_edit_checkins',
382
-                'ee_edit_others_checkins',
383
-                'ee_delete_checkin',
384
-                'ee_delete_checkins',
385
-                'ee_delete_others_checkins',
386
-                //transactions && payments
387
-                'ee_read_transaction',
388
-                'ee_read_transactions',
389
-                'ee_edit_payments',
390
-                'ee_delete_payments',
391
-                //messages
392
-                'ee_read_message',
393
-                'ee_read_messages',
394
-                'ee_read_others_messages',
395
-                'ee_read_global_messages',
396
-                'ee_edit_global_messages',
397
-                'ee_edit_message',
398
-                'ee_edit_messages',
399
-                'ee_edit_others_messages',
400
-                'ee_delete_message',
401
-                'ee_delete_messages',
402
-                'ee_delete_others_messages',
403
-                'ee_delete_global_messages',
404
-                'ee_send_message',
405
-                //tickets
406
-                'ee_read_default_ticket',
407
-                'ee_read_default_tickets',
408
-                'ee_read_others_default_tickets',
409
-                'ee_edit_default_ticket',
410
-                'ee_edit_default_tickets',
411
-                'ee_edit_others_default_tickets',
412
-                'ee_delete_default_ticket',
413
-                'ee_delete_default_tickets',
414
-                'ee_delete_others_default_tickets',
415
-                //prices
416
-                'ee_edit_default_price',
417
-                'ee_edit_default_prices',
418
-                'ee_delete_default_price',
419
-                'ee_delete_default_prices',
420
-                'ee_edit_default_price_type',
421
-                'ee_edit_default_price_types',
422
-                'ee_delete_default_price_type',
423
-                'ee_delete_default_price_types',
424
-                'ee_read_default_prices',
425
-                'ee_read_default_price_types',
426
-                //registration form
427
-                'ee_edit_question',
428
-                'ee_edit_questions',
429
-                'ee_edit_system_questions',
430
-                'ee_read_questions',
431
-                'ee_delete_question',
432
-                'ee_delete_questions',
433
-                'ee_edit_question_group',
434
-                'ee_edit_question_groups',
435
-                'ee_read_question_groups',
436
-                'ee_edit_system_question_groups',
437
-                'ee_delete_question_group',
438
-                'ee_delete_question_groups',
439
-                //event_type taxonomy
440
-                'ee_assign_event_type',
441
-                'ee_manage_event_types',
442
-                'ee_edit_event_type',
443
-                'ee_delete_event_type',
444
-            ),
445
-            'ee_events_administrator' => array(
446
-                //core wp caps
447
-                'read',
448
-                'read_private_pages',
449
-                'read_private_posts',
450
-                'edit_users',
451
-                'edit_posts',
452
-                'edit_pages',
453
-                'edit_published_posts',
454
-                'edit_published_pages',
455
-                'edit_private_pages',
456
-                'edit_private_posts',
457
-                'edit_others_posts',
458
-                'edit_others_pages',
459
-                'publish_posts',
460
-                'publish_pages',
461
-                'delete_posts',
462
-                'delete_pages',
463
-                'delete_private_pages',
464
-                'delete_private_posts',
465
-                'delete_published_pages',
466
-                'delete_published_posts',
467
-                'delete_others_posts',
468
-                'delete_others_pages',
469
-                'manage_categories',
470
-                'manage_links',
471
-                'moderate_comments',
472
-                'unfiltered_html',
473
-                'upload_files',
474
-                'export',
475
-                'import',
476
-                'list_users',
477
-                'level_1', //required if user with this role shows up in author dropdowns
478
-                //basic ee access
479
-                'ee_read_ee',
480
-                //events
481
-                'ee_publish_events',
482
-                'ee_read_private_events',
483
-                'ee_read_others_events',
484
-                'ee_read_event',
485
-                'ee_read_events',
486
-                'ee_edit_event',
487
-                'ee_edit_events',
488
-                'ee_edit_published_events',
489
-                'ee_edit_others_events',
490
-                'ee_edit_private_events',
491
-                'ee_delete_published_events',
492
-                'ee_delete_private_events',
493
-                'ee_delete_event',
494
-                'ee_delete_events',
495
-                'ee_delete_others_events',
496
-                //event categories
497
-                'ee_manage_event_categories',
498
-                'ee_edit_event_category',
499
-                'ee_delete_event_category',
500
-                'ee_assign_event_category',
501
-                //venues
502
-                'ee_publish_venues',
503
-                'ee_read_venue',
504
-                'ee_read_venues',
505
-                'ee_read_others_venues',
506
-                'ee_read_private_venues',
507
-                'ee_edit_venue',
508
-                'ee_edit_venues',
509
-                'ee_edit_others_venues',
510
-                'ee_edit_published_venues',
511
-                'ee_edit_private_venues',
512
-                'ee_delete_venue',
513
-                'ee_delete_venues',
514
-                'ee_delete_others_venues',
515
-                'ee_delete_private_venues',
516
-                'ee_delete_published_venues',
517
-                //venue categories
518
-                'ee_manage_venue_categories',
519
-                'ee_edit_venue_category',
520
-                'ee_delete_venue_category',
521
-                'ee_assign_venue_category',
522
-                //contacts
523
-                'ee_read_contact',
524
-                'ee_read_contacts',
525
-                'ee_edit_contact',
526
-                'ee_edit_contacts',
527
-                'ee_delete_contact',
528
-                'ee_delete_contacts',
529
-                //registrations
530
-                'ee_read_registration',
531
-                'ee_read_registrations',
532
-                'ee_read_others_registrations',
533
-                'ee_edit_registration',
534
-                'ee_edit_registrations',
535
-                'ee_edit_others_registrations',
536
-                'ee_delete_registration',
537
-                'ee_delete_registrations',
538
-                //checkins
539
-                'ee_read_checkin',
540
-                'ee_read_others_checkins',
541
-                'ee_read_checkins',
542
-                'ee_edit_checkin',
543
-                'ee_edit_checkins',
544
-                'ee_edit_others_checkins',
545
-                'ee_delete_checkin',
546
-                'ee_delete_checkins',
547
-                'ee_delete_others_checkins',
548
-                //transactions && payments
549
-                'ee_read_transaction',
550
-                'ee_read_transactions',
551
-                'ee_edit_payments',
552
-                'ee_delete_payments',
553
-                //messages
554
-                'ee_read_message',
555
-                'ee_read_messages',
556
-                'ee_read_others_messages',
557
-                'ee_read_global_messages',
558
-                'ee_edit_global_messages',
559
-                'ee_edit_message',
560
-                'ee_edit_messages',
561
-                'ee_edit_others_messages',
562
-                'ee_delete_message',
563
-                'ee_delete_messages',
564
-                'ee_delete_others_messages',
565
-                'ee_delete_global_messages',
566
-                'ee_send_message',
567
-                //tickets
568
-                'ee_read_default_ticket',
569
-                'ee_read_default_tickets',
570
-                'ee_read_others_default_tickets',
571
-                'ee_edit_default_ticket',
572
-                'ee_edit_default_tickets',
573
-                'ee_edit_others_default_tickets',
574
-                'ee_delete_default_ticket',
575
-                'ee_delete_default_tickets',
576
-                'ee_delete_others_default_tickets',
577
-                //prices
578
-                'ee_edit_default_price',
579
-                'ee_edit_default_prices',
580
-                'ee_delete_default_price',
581
-                'ee_delete_default_prices',
582
-                'ee_edit_default_price_type',
583
-                'ee_edit_default_price_types',
584
-                'ee_delete_default_price_type',
585
-                'ee_delete_default_price_types',
586
-                'ee_read_default_prices',
587
-                'ee_read_default_price_types',
588
-                //registration form
589
-                'ee_edit_question',
590
-                'ee_edit_questions',
591
-                'ee_edit_system_questions',
592
-                'ee_read_questions',
593
-                'ee_delete_question',
594
-                'ee_delete_questions',
595
-                'ee_edit_question_group',
596
-                'ee_edit_question_groups',
597
-                'ee_read_question_groups',
598
-                'ee_edit_system_question_groups',
599
-                'ee_delete_question_group',
600
-                'ee_delete_question_groups',
601
-                //event_type taxonomy
602
-                'ee_assign_event_type',
603
-                'ee_manage_event_types',
604
-                'ee_edit_event_type',
605
-                'ee_delete_event_type',
606
-            ),
607
-        );
608
-        $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps);
609
-        return $caps;
610
-    }
611
-
612
-
613
-    /**
614
-     * Callback for FHEE__EE_Capabilities__init_caps_map__caps that is used for registering additional core
615
-     * capabilities that get added.
616
-     * This is typically done for more dynamic cap additions such as what is registered via the
617
-     * `EE_Payment_Method_Manager`
618
-     *
619
-     * @param array $caps The existing $role=>$capability array.
620
-     * @return array.
621
-     */
622
-    public function register_additional_capabilities($caps)
623
-    {
624
-        //take care of dynamic capabilities for payment methods
625
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
626
-        $caps = EE_Payment_Method_Manager::instance()->add_payment_method_caps($caps);
627
-        return $caps;
628
-    }
629
-
630
-
631
-    /**
632
-     * This adds all the default caps to roles as registered in the _caps_map property.
633
-     *
634
-     * @since 4.5.0
635
-     * @param bool  $reset      allows for resetting the default capabilities saved on roles.  Note that this doesn't
636
-     *                          actually REMOVE any capabilities from existing roles, it just resaves defaults roles
637
-     *                          and ensures that they are up to date.
638
-     * @param array $custom_map Optional.  Can be used to send a custom map of roles and capabilities for setting them
639
-     *                          up.  Note that this should ONLY be called on activation hook or some other one-time
640
-     *                          task otherwise the caps will be added on every request.
641
-     * @return void
642
-     */
643
-    public function init_role_caps($reset = false, $custom_map = array())
644
-    {
645
-        $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map;
646
-        //first let's determine if these caps have already been set.
647
-        $caps_set_before = get_option(self::option_name, array());
648
-        //if not reset, see what caps are new for each role. if they're new, add them.
649
-        foreach ($caps_map as $role => $caps_for_role) {
650
-            foreach ($caps_for_role as $cap) {
651
-                //first check we haven't already added this cap before, or it's a reset
652
-                if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
653
-                    if ($this->add_cap_to_role($role, $cap)) {
654
-                        $caps_set_before[ $role ][] = $cap;
655
-                    }
656
-                }
657
-            }
658
-        }
659
-        //now let's just save the cap that has been set.
660
-        update_option(self::option_name, $caps_set_before);
661
-        do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before);
662
-    }
663
-
664
-
665
-    /**
666
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
667
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
668
-     * this is a wrapper for $wp_role->add_cap()
669
-     *
670
-     * @see   wp-includes/capabilities.php
671
-     * @since 4.5.0
672
-     * @param string $role  A WordPress role the capability is being added to
673
-     * @param string $cap   The capability being added to the role
674
-     * @param bool   $grant Whether to grant access to this cap on this role.
675
-     * @return bool
676
-     */
677
-    public function add_cap_to_role($role, $cap, $grant = true)
678
-    {
679
-        $role_object = get_role($role);
680
-        //if the role isn't available then we create it.
681
-        if (! $role_object instanceof WP_Role) {
682
-            //if a plugin wants to create a specific role name then they should create the role before
683
-            //EE_Capabilities does.  Otherwise this function will create the role name from the slug:
684
-            // - removes any `ee_` namespacing from the start of the slug.
685
-            // - replaces `_` with ` ` (empty space).
686
-            // - sentence case on the resulting string.
687
-            $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role)));
688
-            $role_object = add_role($role, $role_label);
689
-        }
690
-        if ($role_object instanceof WP_Role) {
691
-            $role_object->add_cap($cap, $grant);
692
-            return true;
693
-        }
694
-        return false;
695
-    }
696
-
697
-
698
-    /**
699
-     * Functions similarly to add_cap_to_role except removes cap from given role.
700
-     * Wrapper for $wp_role->remove_cap()
701
-     *
702
-     * @see   wp-includes/capabilities.php
703
-     * @since 4.5.0
704
-     * @param string $role A WordPress role the capability is being removed from.
705
-     * @param string $cap  The capability being removed
706
-     * @return void
707
-     */
708
-    public function remove_cap_from_role($role, $cap)
709
-    {
710
-        $role = get_role($role);
711
-        if ($role instanceof WP_Role) {
712
-            $role->remove_cap($cap);
713
-        }
714
-    }
715
-
716
-
717
-    /**
718
-     * Wrapper for the native WP current_user_can() method.
719
-     * This is provided as a handy method for a couple things:
720
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
721
-     * write those filters wherever current_user_can is called).
722
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
723
-     *
724
-     * @since 4.5.0
725
-     * @param string $cap     The cap being checked.
726
-     * @param string $context The context where the current_user_can is being called from.
727
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
728
-     *                        filters.
729
-     * @return bool  Whether user can or not.
730
-     */
731
-    public function current_user_can($cap, $context, $id = 0)
732
-    {
733
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
734
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
735
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
736
-            $id);
737
-        return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
738
-    }
739
-
740
-
741
-    /**
742
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
743
-     *
744
-     * @param int|WP_User $user    Either the user_id or a WP_User object
745
-     * @param string      $cap     The capability string being checked
746
-     * @param string      $context The context where the user_can is being called from (used in filters).
747
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
748
-     *                             filters)
749
-     * @return bool Whether user can or not.
750
-     */
751
-    public function user_can($user, $cap, $context, $id = 0)
752
-    {
753
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
754
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
755
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
756
-            $id);
757
-        return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
758
-    }
759
-
760
-
761
-    /**
762
-     * Wrapper for the native WP current_user_can_for_blog() method.
763
-     * This is provided as a handy method for a couple things:
764
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
765
-     * write those filters wherever current_user_can is called).
766
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
767
-     *
768
-     * @since 4.5.0
769
-     * @param int    $blog_id The blog id that is being checked for.
770
-     * @param string $cap     The cap being checked.
771
-     * @param string $context The context where the current_user_can is being called from.
772
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
773
-     *                        filters.
774
-     * @return bool  Whether user can or not.
775
-     */
776
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
777
-    {
778
-        $user_can = ! empty($id)
779
-            ? current_user_can_for_blog($blog_id, $cap, $id)
780
-            : current_user_can($blog_id, $cap);
781
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
782
-        $user_can = apply_filters(
783
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
784
-            $user_can,
785
-            $blog_id,
786
-            $cap,
787
-            $id
788
-        );
789
-        $user_can = apply_filters(
790
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
791
-            $user_can,
792
-            $context,
793
-            $blog_id,
794
-            $cap,
795
-            $id
796
-        );
797
-        return $user_can;
798
-    }
799
-
800
-
801
-    /**
802
-     * This helper method just returns an array of registered EE capabilities.
803
-     * Note this array is filtered.  It is assumed that all available EE capabilities are assigned to the administrator
804
-     * role.
805
-     *
806
-     * @since 4.5.0
807
-     * @param string $role If empty then the entire role/capability map is returned.  Otherwise just the capabilities
808
-     *                     for the given role are returned.
809
-     * @return array
810
-     */
811
-    public function get_ee_capabilities($role = 'administrator')
812
-    {
813
-        $capabilities = $this->_init_caps_map();
814
-        if (empty($role)) {
815
-            return $capabilities;
816
-        }
817
-        return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
818
-    }
19
+	/**
20
+	 * the name of the wp option used to store caps previously initialized
21
+	 */
22
+	const option_name = 'ee_caps_initialized';
23
+
24
+	/**
25
+	 * instance of EE_Capabilities object
26
+	 *
27
+	 * @var EE_Capabilities
28
+	 */
29
+	private static $_instance;
30
+
31
+	/**
32
+	 * This is a map of caps that correspond to a default WP_Role.
33
+	 * Array is indexed by Role and values are ee capabilities.
34
+	 *
35
+	 * @since 4.5.0
36
+	 * @var array
37
+	 */
38
+	private $_caps_map = array();
39
+
40
+	/**
41
+	 * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for
42
+	 * a user depending on context.
43
+	 *
44
+	 * @var EE_Meta_Capability_Map[]
45
+	 */
46
+	private $_meta_caps = array();
47
+
48
+
49
+	/**
50
+	 * singleton method used to instantiate class object
51
+	 *
52
+	 * @since 4.5.0
53
+	 * @return EE_Capabilities
54
+	 */
55
+	public static function instance()
56
+	{
57
+		//check if instantiated, and if not do so.
58
+		if (! self::$_instance instanceof EE_Capabilities) {
59
+			self::$_instance = new self();
60
+		}
61
+		return self::$_instance;
62
+	}
63
+
64
+
65
+	/**
66
+	 * private constructor
67
+	 *
68
+	 * @since 4.5.0
69
+	 */
70
+	private function __construct()
71
+	{
72
+		if (is_admin()) {
73
+			add_filter(
74
+				'FHEE__EE_Capabilities__init_caps_map__caps',
75
+				array($this, 'register_additional_capabilities'),
76
+				10
77
+			);
78
+		}
79
+	}
80
+
81
+
82
+	/**
83
+	 * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
84
+	 *
85
+	 * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
86
+	 *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
87
+	 *                    ensures that they are up to date.
88
+	 * @since 4.5.0
89
+	 * @return void
90
+	 */
91
+	public function init_caps($reset = false)
92
+	{
93
+		/**
94
+		 * Note, this means that caps can only initialized on the default roles when:
95
+		 * - models are queryable
96
+		 * - All addons have been registered  (which happens at plugins_loaded priority 1)
97
+		 * In practice, currently this method is usually called around `init`.
98
+		 */
99
+		if (
100
+			did_action('AHEE__EE_System__load_espresso_addons__complete')
101
+			&& EE_Maintenance_Mode::instance()->models_can_query()
102
+		) {
103
+			$this->_caps_map = $this->_init_caps_map();
104
+			$this->init_role_caps($reset);
105
+			$this->_set_meta_caps();
106
+		}
107
+	}
108
+
109
+
110
+	/**
111
+	 * This sets the meta caps property.
112
+	 *
113
+	 * @since 4.5.0
114
+	 * @return void
115
+	 */
116
+	private function _set_meta_caps()
117
+	{
118
+		//make sure we're only ever initializing the default _meta_caps array once if it's empty.
119
+		$this->_meta_caps = $this->_get_default_meta_caps_array();
120
+		$this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
121
+		//add filter for map_meta_caps but only if models can query.
122
+		if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
123
+			add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * This builds and returns the default meta_caps array only once.
130
+	 *
131
+	 * @since  4.8.28.rc.012
132
+	 * @return array
133
+	 * @throws \EE_Error
134
+	 */
135
+	private function _get_default_meta_caps_array()
136
+	{
137
+		static $default_meta_caps = array();
138
+		if (empty($default_meta_caps)) {
139
+			$default_meta_caps = array(
140
+				//edits
141
+				new EE_Meta_Capability_Map_Edit(
142
+					'ee_edit_event',
143
+					array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
144
+				),
145
+				new EE_Meta_Capability_Map_Edit(
146
+					'ee_edit_venue',
147
+					array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
148
+				),
149
+				new EE_Meta_Capability_Map_Edit(
150
+					'ee_edit_registration',
151
+					array('Registration', '', 'ee_edit_others_registrations', '')
152
+				),
153
+				new EE_Meta_Capability_Map_Edit(
154
+					'ee_edit_checkin',
155
+					array('Registration', '', 'ee_edit_others_checkins', '')
156
+				),
157
+				new EE_Meta_Capability_Map_Messages_Cap(
158
+					'ee_edit_message',
159
+					array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
160
+				),
161
+				new EE_Meta_Capability_Map_Edit(
162
+					'ee_edit_default_ticket',
163
+					array('Ticket', '', 'ee_edit_others_default_tickets', '')
164
+				),
165
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
166
+					'ee_edit_question',
167
+					array('Question', '', '', 'ee_edit_system_questions')
168
+				),
169
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
170
+					'ee_edit_question_group',
171
+					array('Question_Group', '', '', 'ee_edit_system_question_groups')
172
+				),
173
+				new EE_Meta_Capability_Map_Edit(
174
+					'ee_edit_payment_method',
175
+					array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
176
+				),
177
+				//reads
178
+				new EE_Meta_Capability_Map_Read(
179
+					'ee_read_event',
180
+					array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
181
+				),
182
+				new EE_Meta_Capability_Map_Read(
183
+					'ee_read_venue',
184
+					array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
185
+				),
186
+				new EE_Meta_Capability_Map_Read(
187
+					'ee_read_registration',
188
+					array('Registration', '', '', 'ee_edit_others_registrations')
189
+				),
190
+				new EE_Meta_Capability_Map_Read(
191
+					'ee_read_checkin',
192
+					array('Registration', '', '', 'ee_read_others_checkins')
193
+				),
194
+				new EE_Meta_Capability_Map_Messages_Cap(
195
+					'ee_read_message',
196
+					array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
197
+				),
198
+				new EE_Meta_Capability_Map_Read(
199
+					'ee_read_default_ticket',
200
+					array('Ticket', '', '', 'ee_read_others_default_tickets')
201
+				),
202
+				new EE_Meta_Capability_Map_Read(
203
+					'ee_read_payment_method',
204
+					array('Payment_Method', '', '', 'ee_read_others_payment_methods')
205
+				),
206
+				//deletes
207
+				new EE_Meta_Capability_Map_Delete(
208
+					'ee_delete_event',
209
+					array(
210
+						'Event',
211
+						'ee_delete_published_events',
212
+						'ee_delete_others_events',
213
+						'ee_delete_private_events',
214
+					)
215
+				),
216
+				new EE_Meta_Capability_Map_Delete(
217
+					'ee_delete_venue',
218
+					array(
219
+						'Venue',
220
+						'ee_delete_published_venues',
221
+						'ee_delete_others_venues',
222
+						'ee_delete_private_venues',
223
+					)
224
+				),
225
+				new EE_Meta_Capability_Map_Delete(
226
+					'ee_delete_registration',
227
+					array('Registration', '', 'ee_delete_others_registrations', '')
228
+				),
229
+				new EE_Meta_Capability_Map_Delete(
230
+					'ee_delete_checkin',
231
+					array('Registration', '', 'ee_delete_others_checkins', '')
232
+				),
233
+				new EE_Meta_Capability_Map_Messages_Cap(
234
+					'ee_delete_message',
235
+					array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
236
+				),
237
+				new EE_Meta_Capability_Map_Delete(
238
+					'ee_delete_default_ticket',
239
+					array('Ticket', '', 'ee_delete_others_default_tickets', '')
240
+				),
241
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
242
+					'ee_delete_question',
243
+					array('Question', '', '', 'delete_system_questions')
244
+				),
245
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
246
+					'ee_delete_question_group',
247
+					array('Question_Group', '', '', 'delete_system_question_groups')
248
+				),
249
+				new EE_Meta_Capability_Map_Delete(
250
+					'ee_delete_payment_method',
251
+					array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
252
+				),
253
+			);
254
+		}
255
+		return $default_meta_caps;
256
+	}
257
+
258
+
259
+	/**
260
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
261
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
262
+	 * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
263
+	 *
264
+	 * @since 4.5.0
265
+	 * @see   wp-includes/capabilities.php
266
+	 * @param array  $caps    actual users capabilities
267
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
268
+	 * @param int    $user_id The user id
269
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
270
+	 * @return array actual users capabilities
271
+	 * @throws EE_Error
272
+	 */
273
+	public function map_meta_caps($caps, $cap, $user_id, $args)
274
+	{
275
+		if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
276
+			//loop through our _meta_caps array
277
+			foreach ($this->_meta_caps as $meta_map) {
278
+				if (! $meta_map instanceof EE_Meta_Capability_Map) {
279
+					continue;
280
+				}
281
+				$meta_map->ensure_is_model();
282
+				$caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
283
+			}
284
+		}
285
+		return $caps;
286
+	}
287
+
288
+
289
+	/**
290
+	 * This sets up and returns the initial capabilities map for Event Espresso
291
+	 *
292
+	 * @since 4.5.0
293
+	 * @return array
294
+	 */
295
+	private function _init_caps_map()
296
+	{
297
+		$caps = array(
298
+			'administrator'           => array(
299
+				//basic access
300
+				'ee_read_ee',
301
+				//gateways
302
+				/**
303
+				 * note that with payment method capabilities, although we've implemented
304
+				 * capability mapping which will be used for accessing payment methods owned by
305
+				 * other users.  This is not fully implemented yet in the payment method ui.
306
+				 * Currently only the "plural" caps are in active use.
307
+				 * (Specific payment method caps are in use as well).
308
+				 **/
309
+				'ee_manage_gateways',
310
+				'ee_read_payment_method',
311
+				'ee_read_payment_methods',
312
+				'ee_read_others_payment_methods',
313
+				'ee_edit_payment_method',
314
+				'ee_edit_payment_methods',
315
+				'ee_edit_others_payment_methods',
316
+				'ee_delete_payment_method',
317
+				'ee_delete_payment_methods',
318
+				//events
319
+				'ee_publish_events',
320
+				'ee_read_private_events',
321
+				'ee_read_others_events',
322
+				'ee_read_event',
323
+				'ee_read_events',
324
+				'ee_edit_event',
325
+				'ee_edit_events',
326
+				'ee_edit_published_events',
327
+				'ee_edit_others_events',
328
+				'ee_edit_private_events',
329
+				'ee_delete_published_events',
330
+				'ee_delete_private_events',
331
+				'ee_delete_event',
332
+				'ee_delete_events',
333
+				'ee_delete_others_events',
334
+				//event categories
335
+				'ee_manage_event_categories',
336
+				'ee_edit_event_category',
337
+				'ee_delete_event_category',
338
+				'ee_assign_event_category',
339
+				//venues
340
+				'ee_publish_venues',
341
+				'ee_read_venue',
342
+				'ee_read_venues',
343
+				'ee_read_others_venues',
344
+				'ee_read_private_venues',
345
+				'ee_edit_venue',
346
+				'ee_edit_venues',
347
+				'ee_edit_others_venues',
348
+				'ee_edit_published_venues',
349
+				'ee_edit_private_venues',
350
+				'ee_delete_venue',
351
+				'ee_delete_venues',
352
+				'ee_delete_others_venues',
353
+				'ee_delete_private_venues',
354
+				'ee_delete_published_venues',
355
+				//venue categories
356
+				'ee_manage_venue_categories',
357
+				'ee_edit_venue_category',
358
+				'ee_delete_venue_category',
359
+				'ee_assign_venue_category',
360
+				//contacts
361
+				'ee_read_contact',
362
+				'ee_read_contacts',
363
+				'ee_edit_contact',
364
+				'ee_edit_contacts',
365
+				'ee_delete_contact',
366
+				'ee_delete_contacts',
367
+				//registrations
368
+				'ee_read_registration',
369
+				'ee_read_registrations',
370
+				'ee_read_others_registrations',
371
+				'ee_edit_registration',
372
+				'ee_edit_registrations',
373
+				'ee_edit_others_registrations',
374
+				'ee_delete_registration',
375
+				'ee_delete_registrations',
376
+				//checkins
377
+				'ee_read_checkin',
378
+				'ee_read_others_checkins',
379
+				'ee_read_checkins',
380
+				'ee_edit_checkin',
381
+				'ee_edit_checkins',
382
+				'ee_edit_others_checkins',
383
+				'ee_delete_checkin',
384
+				'ee_delete_checkins',
385
+				'ee_delete_others_checkins',
386
+				//transactions && payments
387
+				'ee_read_transaction',
388
+				'ee_read_transactions',
389
+				'ee_edit_payments',
390
+				'ee_delete_payments',
391
+				//messages
392
+				'ee_read_message',
393
+				'ee_read_messages',
394
+				'ee_read_others_messages',
395
+				'ee_read_global_messages',
396
+				'ee_edit_global_messages',
397
+				'ee_edit_message',
398
+				'ee_edit_messages',
399
+				'ee_edit_others_messages',
400
+				'ee_delete_message',
401
+				'ee_delete_messages',
402
+				'ee_delete_others_messages',
403
+				'ee_delete_global_messages',
404
+				'ee_send_message',
405
+				//tickets
406
+				'ee_read_default_ticket',
407
+				'ee_read_default_tickets',
408
+				'ee_read_others_default_tickets',
409
+				'ee_edit_default_ticket',
410
+				'ee_edit_default_tickets',
411
+				'ee_edit_others_default_tickets',
412
+				'ee_delete_default_ticket',
413
+				'ee_delete_default_tickets',
414
+				'ee_delete_others_default_tickets',
415
+				//prices
416
+				'ee_edit_default_price',
417
+				'ee_edit_default_prices',
418
+				'ee_delete_default_price',
419
+				'ee_delete_default_prices',
420
+				'ee_edit_default_price_type',
421
+				'ee_edit_default_price_types',
422
+				'ee_delete_default_price_type',
423
+				'ee_delete_default_price_types',
424
+				'ee_read_default_prices',
425
+				'ee_read_default_price_types',
426
+				//registration form
427
+				'ee_edit_question',
428
+				'ee_edit_questions',
429
+				'ee_edit_system_questions',
430
+				'ee_read_questions',
431
+				'ee_delete_question',
432
+				'ee_delete_questions',
433
+				'ee_edit_question_group',
434
+				'ee_edit_question_groups',
435
+				'ee_read_question_groups',
436
+				'ee_edit_system_question_groups',
437
+				'ee_delete_question_group',
438
+				'ee_delete_question_groups',
439
+				//event_type taxonomy
440
+				'ee_assign_event_type',
441
+				'ee_manage_event_types',
442
+				'ee_edit_event_type',
443
+				'ee_delete_event_type',
444
+			),
445
+			'ee_events_administrator' => array(
446
+				//core wp caps
447
+				'read',
448
+				'read_private_pages',
449
+				'read_private_posts',
450
+				'edit_users',
451
+				'edit_posts',
452
+				'edit_pages',
453
+				'edit_published_posts',
454
+				'edit_published_pages',
455
+				'edit_private_pages',
456
+				'edit_private_posts',
457
+				'edit_others_posts',
458
+				'edit_others_pages',
459
+				'publish_posts',
460
+				'publish_pages',
461
+				'delete_posts',
462
+				'delete_pages',
463
+				'delete_private_pages',
464
+				'delete_private_posts',
465
+				'delete_published_pages',
466
+				'delete_published_posts',
467
+				'delete_others_posts',
468
+				'delete_others_pages',
469
+				'manage_categories',
470
+				'manage_links',
471
+				'moderate_comments',
472
+				'unfiltered_html',
473
+				'upload_files',
474
+				'export',
475
+				'import',
476
+				'list_users',
477
+				'level_1', //required if user with this role shows up in author dropdowns
478
+				//basic ee access
479
+				'ee_read_ee',
480
+				//events
481
+				'ee_publish_events',
482
+				'ee_read_private_events',
483
+				'ee_read_others_events',
484
+				'ee_read_event',
485
+				'ee_read_events',
486
+				'ee_edit_event',
487
+				'ee_edit_events',
488
+				'ee_edit_published_events',
489
+				'ee_edit_others_events',
490
+				'ee_edit_private_events',
491
+				'ee_delete_published_events',
492
+				'ee_delete_private_events',
493
+				'ee_delete_event',
494
+				'ee_delete_events',
495
+				'ee_delete_others_events',
496
+				//event categories
497
+				'ee_manage_event_categories',
498
+				'ee_edit_event_category',
499
+				'ee_delete_event_category',
500
+				'ee_assign_event_category',
501
+				//venues
502
+				'ee_publish_venues',
503
+				'ee_read_venue',
504
+				'ee_read_venues',
505
+				'ee_read_others_venues',
506
+				'ee_read_private_venues',
507
+				'ee_edit_venue',
508
+				'ee_edit_venues',
509
+				'ee_edit_others_venues',
510
+				'ee_edit_published_venues',
511
+				'ee_edit_private_venues',
512
+				'ee_delete_venue',
513
+				'ee_delete_venues',
514
+				'ee_delete_others_venues',
515
+				'ee_delete_private_venues',
516
+				'ee_delete_published_venues',
517
+				//venue categories
518
+				'ee_manage_venue_categories',
519
+				'ee_edit_venue_category',
520
+				'ee_delete_venue_category',
521
+				'ee_assign_venue_category',
522
+				//contacts
523
+				'ee_read_contact',
524
+				'ee_read_contacts',
525
+				'ee_edit_contact',
526
+				'ee_edit_contacts',
527
+				'ee_delete_contact',
528
+				'ee_delete_contacts',
529
+				//registrations
530
+				'ee_read_registration',
531
+				'ee_read_registrations',
532
+				'ee_read_others_registrations',
533
+				'ee_edit_registration',
534
+				'ee_edit_registrations',
535
+				'ee_edit_others_registrations',
536
+				'ee_delete_registration',
537
+				'ee_delete_registrations',
538
+				//checkins
539
+				'ee_read_checkin',
540
+				'ee_read_others_checkins',
541
+				'ee_read_checkins',
542
+				'ee_edit_checkin',
543
+				'ee_edit_checkins',
544
+				'ee_edit_others_checkins',
545
+				'ee_delete_checkin',
546
+				'ee_delete_checkins',
547
+				'ee_delete_others_checkins',
548
+				//transactions && payments
549
+				'ee_read_transaction',
550
+				'ee_read_transactions',
551
+				'ee_edit_payments',
552
+				'ee_delete_payments',
553
+				//messages
554
+				'ee_read_message',
555
+				'ee_read_messages',
556
+				'ee_read_others_messages',
557
+				'ee_read_global_messages',
558
+				'ee_edit_global_messages',
559
+				'ee_edit_message',
560
+				'ee_edit_messages',
561
+				'ee_edit_others_messages',
562
+				'ee_delete_message',
563
+				'ee_delete_messages',
564
+				'ee_delete_others_messages',
565
+				'ee_delete_global_messages',
566
+				'ee_send_message',
567
+				//tickets
568
+				'ee_read_default_ticket',
569
+				'ee_read_default_tickets',
570
+				'ee_read_others_default_tickets',
571
+				'ee_edit_default_ticket',
572
+				'ee_edit_default_tickets',
573
+				'ee_edit_others_default_tickets',
574
+				'ee_delete_default_ticket',
575
+				'ee_delete_default_tickets',
576
+				'ee_delete_others_default_tickets',
577
+				//prices
578
+				'ee_edit_default_price',
579
+				'ee_edit_default_prices',
580
+				'ee_delete_default_price',
581
+				'ee_delete_default_prices',
582
+				'ee_edit_default_price_type',
583
+				'ee_edit_default_price_types',
584
+				'ee_delete_default_price_type',
585
+				'ee_delete_default_price_types',
586
+				'ee_read_default_prices',
587
+				'ee_read_default_price_types',
588
+				//registration form
589
+				'ee_edit_question',
590
+				'ee_edit_questions',
591
+				'ee_edit_system_questions',
592
+				'ee_read_questions',
593
+				'ee_delete_question',
594
+				'ee_delete_questions',
595
+				'ee_edit_question_group',
596
+				'ee_edit_question_groups',
597
+				'ee_read_question_groups',
598
+				'ee_edit_system_question_groups',
599
+				'ee_delete_question_group',
600
+				'ee_delete_question_groups',
601
+				//event_type taxonomy
602
+				'ee_assign_event_type',
603
+				'ee_manage_event_types',
604
+				'ee_edit_event_type',
605
+				'ee_delete_event_type',
606
+			),
607
+		);
608
+		$caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps);
609
+		return $caps;
610
+	}
611
+
612
+
613
+	/**
614
+	 * Callback for FHEE__EE_Capabilities__init_caps_map__caps that is used for registering additional core
615
+	 * capabilities that get added.
616
+	 * This is typically done for more dynamic cap additions such as what is registered via the
617
+	 * `EE_Payment_Method_Manager`
618
+	 *
619
+	 * @param array $caps The existing $role=>$capability array.
620
+	 * @return array.
621
+	 */
622
+	public function register_additional_capabilities($caps)
623
+	{
624
+		//take care of dynamic capabilities for payment methods
625
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
626
+		$caps = EE_Payment_Method_Manager::instance()->add_payment_method_caps($caps);
627
+		return $caps;
628
+	}
629
+
630
+
631
+	/**
632
+	 * This adds all the default caps to roles as registered in the _caps_map property.
633
+	 *
634
+	 * @since 4.5.0
635
+	 * @param bool  $reset      allows for resetting the default capabilities saved on roles.  Note that this doesn't
636
+	 *                          actually REMOVE any capabilities from existing roles, it just resaves defaults roles
637
+	 *                          and ensures that they are up to date.
638
+	 * @param array $custom_map Optional.  Can be used to send a custom map of roles and capabilities for setting them
639
+	 *                          up.  Note that this should ONLY be called on activation hook or some other one-time
640
+	 *                          task otherwise the caps will be added on every request.
641
+	 * @return void
642
+	 */
643
+	public function init_role_caps($reset = false, $custom_map = array())
644
+	{
645
+		$caps_map = empty($custom_map) ? $this->_caps_map : $custom_map;
646
+		//first let's determine if these caps have already been set.
647
+		$caps_set_before = get_option(self::option_name, array());
648
+		//if not reset, see what caps are new for each role. if they're new, add them.
649
+		foreach ($caps_map as $role => $caps_for_role) {
650
+			foreach ($caps_for_role as $cap) {
651
+				//first check we haven't already added this cap before, or it's a reset
652
+				if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
653
+					if ($this->add_cap_to_role($role, $cap)) {
654
+						$caps_set_before[ $role ][] = $cap;
655
+					}
656
+				}
657
+			}
658
+		}
659
+		//now let's just save the cap that has been set.
660
+		update_option(self::option_name, $caps_set_before);
661
+		do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before);
662
+	}
663
+
664
+
665
+	/**
666
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
667
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
668
+	 * this is a wrapper for $wp_role->add_cap()
669
+	 *
670
+	 * @see   wp-includes/capabilities.php
671
+	 * @since 4.5.0
672
+	 * @param string $role  A WordPress role the capability is being added to
673
+	 * @param string $cap   The capability being added to the role
674
+	 * @param bool   $grant Whether to grant access to this cap on this role.
675
+	 * @return bool
676
+	 */
677
+	public function add_cap_to_role($role, $cap, $grant = true)
678
+	{
679
+		$role_object = get_role($role);
680
+		//if the role isn't available then we create it.
681
+		if (! $role_object instanceof WP_Role) {
682
+			//if a plugin wants to create a specific role name then they should create the role before
683
+			//EE_Capabilities does.  Otherwise this function will create the role name from the slug:
684
+			// - removes any `ee_` namespacing from the start of the slug.
685
+			// - replaces `_` with ` ` (empty space).
686
+			// - sentence case on the resulting string.
687
+			$role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role)));
688
+			$role_object = add_role($role, $role_label);
689
+		}
690
+		if ($role_object instanceof WP_Role) {
691
+			$role_object->add_cap($cap, $grant);
692
+			return true;
693
+		}
694
+		return false;
695
+	}
696
+
697
+
698
+	/**
699
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
700
+	 * Wrapper for $wp_role->remove_cap()
701
+	 *
702
+	 * @see   wp-includes/capabilities.php
703
+	 * @since 4.5.0
704
+	 * @param string $role A WordPress role the capability is being removed from.
705
+	 * @param string $cap  The capability being removed
706
+	 * @return void
707
+	 */
708
+	public function remove_cap_from_role($role, $cap)
709
+	{
710
+		$role = get_role($role);
711
+		if ($role instanceof WP_Role) {
712
+			$role->remove_cap($cap);
713
+		}
714
+	}
715
+
716
+
717
+	/**
718
+	 * Wrapper for the native WP current_user_can() method.
719
+	 * This is provided as a handy method for a couple things:
720
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
721
+	 * write those filters wherever current_user_can is called).
722
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
723
+	 *
724
+	 * @since 4.5.0
725
+	 * @param string $cap     The cap being checked.
726
+	 * @param string $context The context where the current_user_can is being called from.
727
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
728
+	 *                        filters.
729
+	 * @return bool  Whether user can or not.
730
+	 */
731
+	public function current_user_can($cap, $context, $id = 0)
732
+	{
733
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
734
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
735
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
736
+			$id);
737
+		return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
738
+	}
739
+
740
+
741
+	/**
742
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
743
+	 *
744
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
745
+	 * @param string      $cap     The capability string being checked
746
+	 * @param string      $context The context where the user_can is being called from (used in filters).
747
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
748
+	 *                             filters)
749
+	 * @return bool Whether user can or not.
750
+	 */
751
+	public function user_can($user, $cap, $context, $id = 0)
752
+	{
753
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
754
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
755
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
756
+			$id);
757
+		return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
758
+	}
759
+
760
+
761
+	/**
762
+	 * Wrapper for the native WP current_user_can_for_blog() method.
763
+	 * This is provided as a handy method for a couple things:
764
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
765
+	 * write those filters wherever current_user_can is called).
766
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
767
+	 *
768
+	 * @since 4.5.0
769
+	 * @param int    $blog_id The blog id that is being checked for.
770
+	 * @param string $cap     The cap being checked.
771
+	 * @param string $context The context where the current_user_can is being called from.
772
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
773
+	 *                        filters.
774
+	 * @return bool  Whether user can or not.
775
+	 */
776
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
777
+	{
778
+		$user_can = ! empty($id)
779
+			? current_user_can_for_blog($blog_id, $cap, $id)
780
+			: current_user_can($blog_id, $cap);
781
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
782
+		$user_can = apply_filters(
783
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
784
+			$user_can,
785
+			$blog_id,
786
+			$cap,
787
+			$id
788
+		);
789
+		$user_can = apply_filters(
790
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
791
+			$user_can,
792
+			$context,
793
+			$blog_id,
794
+			$cap,
795
+			$id
796
+		);
797
+		return $user_can;
798
+	}
799
+
800
+
801
+	/**
802
+	 * This helper method just returns an array of registered EE capabilities.
803
+	 * Note this array is filtered.  It is assumed that all available EE capabilities are assigned to the administrator
804
+	 * role.
805
+	 *
806
+	 * @since 4.5.0
807
+	 * @param string $role If empty then the entire role/capability map is returned.  Otherwise just the capabilities
808
+	 *                     for the given role are returned.
809
+	 * @return array
810
+	 */
811
+	public function get_ee_capabilities($role = 'administrator')
812
+	{
813
+		$capabilities = $this->_init_caps_map();
814
+		if (empty($role)) {
815
+			return $capabilities;
816
+		}
817
+		return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
818
+	}
819 819
 }
820 820
 
821 821
 
@@ -832,134 +832,134 @@  discard block
 block discarded – undo
832 832
 abstract class EE_Meta_Capability_Map
833 833
 {
834 834
 
835
-    public $meta_cap;
836
-
837
-    /**
838
-     * @var EEM_Base
839
-     */
840
-    protected $_model;
841
-
842
-    protected $_model_name;
843
-
844
-    public $published_cap = '';
845
-
846
-    public $others_cap = '';
847
-
848
-    public $private_cap = '';
849
-
850
-
851
-    /**
852
-     * constructor.
853
-     * Receives the setup arguments for the map.
854
-     *
855
-     * @since                        4.5.0
856
-     * @param string $meta_cap       What meta capability is this mapping.
857
-     * @param array  $map_values     array {
858
-     *                               //array of values that MUST match a count of 4.  It's okay to send an empty string
859
-     *                               for capabilities that don't get mapped to.
860
-     * @type         $map_values     [0] string A string representing the model name. Required.  String's
861
-     *                               should always be used when Menu Maps are registered via the
862
-     *                               plugin API as models are not allowed to be instantiated when
863
-     *                               in maintenance mode 2 (migrations).
864
-     * @type         $map_values     [1] string represents the capability used for published. Optional.
865
-     * @type         $map_values     [2] string represents the capability used for "others". Optional.
866
-     * @type         $map_values     [3] string represents the capability used for private. Optional.
867
-     *                               }
868
-     * @throws EE_Error
869
-     */
870
-    public function __construct($meta_cap, $map_values)
871
-    {
872
-        $this->meta_cap = $meta_cap;
873
-        //verify there are four args in the $map_values array;
874
-        if (count($map_values) !== 4) {
875
-            throw new EE_Error(
876
-                sprintf(
877
-                    __(
878
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
879
-                        'event_espresso'
880
-                    ),
881
-                    '<br>' . print_r($map_values, true)
882
-                )
883
-            );
884
-        }
885
-        //set properties
886
-        $this->_model = null;
887
-        $this->_model_name = $map_values[0];
888
-        $this->published_cap = (string)$map_values[1];
889
-        $this->others_cap = (string)$map_values[2];
890
-        $this->private_cap = (string)$map_values[3];
891
-    }
892
-
893
-    /**
894
-     * Makes it so this object stops filtering caps
895
-     */
896
-    public function remove_filters()
897
-    {
898
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
899
-    }
900
-
901
-
902
-    /**
903
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
904
-     *
905
-     * @since 4.5.0
906
-     * @throws EE_Error
907
-     * @return void
908
-     */
909
-    public function ensure_is_model()
910
-    {
911
-        //is it already instantiated?
912
-        if ($this->_model instanceof EEM_Base) {
913
-            return;
914
-        }
915
-        //ensure model name is string
916
-        $this->_model_name = (string)$this->_model_name;
917
-        //error proof if the name has EEM in it
918
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
919
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
920
-        if (! $this->_model instanceof EEM_Base) {
921
-            throw new EE_Error(
922
-                sprintf(
923
-                    __(
924
-                        'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
925
-                        'event_espresso'
926
-                    ),
927
-                    get_class($this),
928
-                    $this->_model
929
-                )
930
-            );
931
-        }
932
-    }
933
-
934
-
935
-    /**
936
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
937
-     * @since 4.6.x
938
-     * @param $caps
939
-     * @param $cap
940
-     * @param $user_id
941
-     * @param $args
942
-     * @return array
943
-     */
944
-    public function map_meta_caps($caps, $cap, $user_id, $args)
945
-    {
946
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
947
-    }
948
-
949
-
950
-    /**
951
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
952
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
953
-     *
954
-     * @since 4.5.0
955
-     * @see   wp-includes/capabilities.php
956
-     * @param array  $caps    actual users capabilities
957
-     * @param string $cap     initial capability name that is being checked (the "map" key)
958
-     * @param int    $user_id The user id
959
-     * @param array  $args    Adds context to the cap. Typically the object ID.
960
-     * @return array   actual users capabilities
961
-     */
962
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
835
+	public $meta_cap;
836
+
837
+	/**
838
+	 * @var EEM_Base
839
+	 */
840
+	protected $_model;
841
+
842
+	protected $_model_name;
843
+
844
+	public $published_cap = '';
845
+
846
+	public $others_cap = '';
847
+
848
+	public $private_cap = '';
849
+
850
+
851
+	/**
852
+	 * constructor.
853
+	 * Receives the setup arguments for the map.
854
+	 *
855
+	 * @since                        4.5.0
856
+	 * @param string $meta_cap       What meta capability is this mapping.
857
+	 * @param array  $map_values     array {
858
+	 *                               //array of values that MUST match a count of 4.  It's okay to send an empty string
859
+	 *                               for capabilities that don't get mapped to.
860
+	 * @type         $map_values     [0] string A string representing the model name. Required.  String's
861
+	 *                               should always be used when Menu Maps are registered via the
862
+	 *                               plugin API as models are not allowed to be instantiated when
863
+	 *                               in maintenance mode 2 (migrations).
864
+	 * @type         $map_values     [1] string represents the capability used for published. Optional.
865
+	 * @type         $map_values     [2] string represents the capability used for "others". Optional.
866
+	 * @type         $map_values     [3] string represents the capability used for private. Optional.
867
+	 *                               }
868
+	 * @throws EE_Error
869
+	 */
870
+	public function __construct($meta_cap, $map_values)
871
+	{
872
+		$this->meta_cap = $meta_cap;
873
+		//verify there are four args in the $map_values array;
874
+		if (count($map_values) !== 4) {
875
+			throw new EE_Error(
876
+				sprintf(
877
+					__(
878
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
879
+						'event_espresso'
880
+					),
881
+					'<br>' . print_r($map_values, true)
882
+				)
883
+			);
884
+		}
885
+		//set properties
886
+		$this->_model = null;
887
+		$this->_model_name = $map_values[0];
888
+		$this->published_cap = (string)$map_values[1];
889
+		$this->others_cap = (string)$map_values[2];
890
+		$this->private_cap = (string)$map_values[3];
891
+	}
892
+
893
+	/**
894
+	 * Makes it so this object stops filtering caps
895
+	 */
896
+	public function remove_filters()
897
+	{
898
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
899
+	}
900
+
901
+
902
+	/**
903
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
904
+	 *
905
+	 * @since 4.5.0
906
+	 * @throws EE_Error
907
+	 * @return void
908
+	 */
909
+	public function ensure_is_model()
910
+	{
911
+		//is it already instantiated?
912
+		if ($this->_model instanceof EEM_Base) {
913
+			return;
914
+		}
915
+		//ensure model name is string
916
+		$this->_model_name = (string)$this->_model_name;
917
+		//error proof if the name has EEM in it
918
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
919
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
920
+		if (! $this->_model instanceof EEM_Base) {
921
+			throw new EE_Error(
922
+				sprintf(
923
+					__(
924
+						'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
925
+						'event_espresso'
926
+					),
927
+					get_class($this),
928
+					$this->_model
929
+				)
930
+			);
931
+		}
932
+	}
933
+
934
+
935
+	/**
936
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
937
+	 * @since 4.6.x
938
+	 * @param $caps
939
+	 * @param $cap
940
+	 * @param $user_id
941
+	 * @param $args
942
+	 * @return array
943
+	 */
944
+	public function map_meta_caps($caps, $cap, $user_id, $args)
945
+	{
946
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
947
+	}
948
+
949
+
950
+	/**
951
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
952
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
953
+	 *
954
+	 * @since 4.5.0
955
+	 * @see   wp-includes/capabilities.php
956
+	 * @param array  $caps    actual users capabilities
957
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
958
+	 * @param int    $user_id The user id
959
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
960
+	 * @return array   actual users capabilities
961
+	 */
962
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
963 963
 }
964 964
 
965 965
 
@@ -975,77 +975,77 @@  discard block
 block discarded – undo
975 975
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
976 976
 {
977 977
 
978
-    /**
979
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
980
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
981
-     *
982
-     * @since 4.5.0
983
-     * @see   wp-includes/capabilities.php
984
-     * @param array  $caps    actual users capabilities
985
-     * @param string $cap     initial capability name that is being checked (the "map" key)
986
-     * @param int    $user_id The user id
987
-     * @param array  $args    Adds context to the cap. Typically the object ID.
988
-     * @return array   actual users capabilities
989
-     */
990
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
991
-    {
992
-        //only process if we're checking our mapped_cap
993
-        if ($cap !== $this->meta_cap) {
994
-            return $caps;
995
-        }
996
-        /** @var EE_Base_Class $obj */
997
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
998
-        //if no obj then let's just do cap
999
-        if (! $obj instanceof EE_Base_Class) {
1000
-            $caps[] = $cap;
1001
-            return $caps;
1002
-        }
1003
-        if ($obj instanceof EE_CPT_Base) {
1004
-            //if the item author is set and the user is the author...
1005
-            if ($obj->wp_user() && $user_id == $obj->wp_user()) {
1006
-                if (empty($this->published_cap)) {
1007
-                    $caps[] = $cap;
1008
-                } else {
1009
-                    //if obj is published...
1010
-                    if ($obj->status() === 'publish') {
1011
-                        $caps[] = $this->published_cap;
1012
-                    } else {
1013
-                        $caps[] = $cap;
1014
-                    }
1015
-                }
1016
-            } else {
1017
-                //the user is trying to edit someone else's obj
1018
-                if (! empty($this->others_cap)) {
1019
-                    $caps[] = $this->others_cap;
1020
-                }
1021
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1022
-                    $caps[] = $this->published_cap;
1023
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1024
-                    $caps[] = $this->private_cap;
1025
-                }
1026
-            }
1027
-        } else {
1028
-            //not a cpt object so handled differently
1029
-            $has_cap = false;
1030
-            try {
1031
-                $has_cap = method_exists($obj, 'wp_user')
1032
-                    && $obj->wp_user()
1033
-                    && $obj->wp_user() === $user_id;
1034
-            } catch (Exception $e) {
1035
-                if (WP_DEBUG) {
1036
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1037
-                }
1038
-            }
1039
-            if ($has_cap) {
1040
-                $caps[] = $cap;
1041
-            } else {
1042
-                if (! empty($this->others_cap)) {
1043
-                    $caps[] = $this->others_cap;
1044
-                }
1045
-            }
1046
-        }
1047
-        return $caps;
1048
-    }
978
+	/**
979
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
980
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
981
+	 *
982
+	 * @since 4.5.0
983
+	 * @see   wp-includes/capabilities.php
984
+	 * @param array  $caps    actual users capabilities
985
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
986
+	 * @param int    $user_id The user id
987
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
988
+	 * @return array   actual users capabilities
989
+	 */
990
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
991
+	{
992
+		//only process if we're checking our mapped_cap
993
+		if ($cap !== $this->meta_cap) {
994
+			return $caps;
995
+		}
996
+		/** @var EE_Base_Class $obj */
997
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
998
+		//if no obj then let's just do cap
999
+		if (! $obj instanceof EE_Base_Class) {
1000
+			$caps[] = $cap;
1001
+			return $caps;
1002
+		}
1003
+		if ($obj instanceof EE_CPT_Base) {
1004
+			//if the item author is set and the user is the author...
1005
+			if ($obj->wp_user() && $user_id == $obj->wp_user()) {
1006
+				if (empty($this->published_cap)) {
1007
+					$caps[] = $cap;
1008
+				} else {
1009
+					//if obj is published...
1010
+					if ($obj->status() === 'publish') {
1011
+						$caps[] = $this->published_cap;
1012
+					} else {
1013
+						$caps[] = $cap;
1014
+					}
1015
+				}
1016
+			} else {
1017
+				//the user is trying to edit someone else's obj
1018
+				if (! empty($this->others_cap)) {
1019
+					$caps[] = $this->others_cap;
1020
+				}
1021
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1022
+					$caps[] = $this->published_cap;
1023
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1024
+					$caps[] = $this->private_cap;
1025
+				}
1026
+			}
1027
+		} else {
1028
+			//not a cpt object so handled differently
1029
+			$has_cap = false;
1030
+			try {
1031
+				$has_cap = method_exists($obj, 'wp_user')
1032
+					&& $obj->wp_user()
1033
+					&& $obj->wp_user() === $user_id;
1034
+			} catch (Exception $e) {
1035
+				if (WP_DEBUG) {
1036
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1037
+				}
1038
+			}
1039
+			if ($has_cap) {
1040
+				$caps[] = $cap;
1041
+			} else {
1042
+				if (! empty($this->others_cap)) {
1043
+					$caps[] = $this->others_cap;
1044
+				}
1045
+			}
1046
+		}
1047
+		return $caps;
1048
+	}
1049 1049
 }
1050 1050
 
1051 1051
 
@@ -1062,22 +1062,22 @@  discard block
 block discarded – undo
1062 1062
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1063 1063
 {
1064 1064
 
1065
-    /**
1066
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1067
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1068
-     *
1069
-     * @since 4.5.0
1070
-     * @see   wp-includes/capabilities.php
1071
-     * @param array  $caps    actual users capabilities
1072
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1073
-     * @param int    $user_id The user id
1074
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1075
-     * @return array   actual users capabilities
1076
-     */
1077
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1078
-    {
1079
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1080
-    }
1065
+	/**
1066
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1067
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1068
+	 *
1069
+	 * @since 4.5.0
1070
+	 * @see   wp-includes/capabilities.php
1071
+	 * @param array  $caps    actual users capabilities
1072
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1073
+	 * @param int    $user_id The user id
1074
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1075
+	 * @return array   actual users capabilities
1076
+	 */
1077
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1078
+	{
1079
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1080
+	}
1081 1081
 }
1082 1082
 
1083 1083
 
@@ -1093,69 +1093,69 @@  discard block
 block discarded – undo
1093 1093
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1094 1094
 {
1095 1095
 
1096
-    /**
1097
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1098
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1099
-     *
1100
-     * @since 4.5.0
1101
-     * @see   wp-includes/capabilities.php
1102
-     * @param array  $caps    actual users capabilities
1103
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1104
-     * @param int    $user_id The user id
1105
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1106
-     * @return array   actual users capabilities
1107
-     */
1108
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1109
-    {
1110
-        //only process if we're checking our mapped cap;
1111
-        if ($cap !== $this->meta_cap) {
1112
-            return $caps;
1113
-        }
1114
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1115
-        //if no obj then let's just do cap
1116
-        if (! $obj instanceof EE_Base_Class) {
1117
-            $caps[] = $cap;
1118
-            return $caps;
1119
-        }
1120
-        if ($obj instanceof EE_CPT_Base) {
1121
-            $status_obj = get_post_status_object($obj->status());
1122
-            if ($status_obj->public) {
1123
-                $caps[] = $cap;
1124
-                return $caps;
1125
-            }
1126
-            //if the item author is set and the user is the author...
1127
-            if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1128
-                $caps[] = $cap;
1129
-            } elseif ($status_obj->private && ! empty($this->private_cap)) {
1130
-                //the user is trying to view someone else's obj
1131
-                $caps[] = $this->private_cap;
1132
-            } elseif (! empty($this->others_cap)) {
1133
-                $caps[] = $this->others_cap;
1134
-            } else {
1135
-                $caps[] = $cap;
1136
-            }
1137
-        } else {
1138
-            //not a cpt object so handled differently
1139
-            $has_cap = false;
1140
-            try {
1141
-                $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id;
1142
-            } catch (Exception $e) {
1143
-                if (WP_DEBUG) {
1144
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1145
-                }
1146
-            }
1147
-            if ($has_cap) {
1148
-                $caps[] = $cap;
1149
-            } elseif (! empty($this->private_cap)) {
1150
-                $caps[] = $this->private_cap;
1151
-            } elseif (! empty($this->others_cap)) {
1152
-                $caps[] = $this->others_cap;
1153
-            } else {
1154
-                $caps[] = $cap;
1155
-            }
1156
-        }
1157
-        return $caps;
1158
-    }
1096
+	/**
1097
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1098
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1099
+	 *
1100
+	 * @since 4.5.0
1101
+	 * @see   wp-includes/capabilities.php
1102
+	 * @param array  $caps    actual users capabilities
1103
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1104
+	 * @param int    $user_id The user id
1105
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1106
+	 * @return array   actual users capabilities
1107
+	 */
1108
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1109
+	{
1110
+		//only process if we're checking our mapped cap;
1111
+		if ($cap !== $this->meta_cap) {
1112
+			return $caps;
1113
+		}
1114
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1115
+		//if no obj then let's just do cap
1116
+		if (! $obj instanceof EE_Base_Class) {
1117
+			$caps[] = $cap;
1118
+			return $caps;
1119
+		}
1120
+		if ($obj instanceof EE_CPT_Base) {
1121
+			$status_obj = get_post_status_object($obj->status());
1122
+			if ($status_obj->public) {
1123
+				$caps[] = $cap;
1124
+				return $caps;
1125
+			}
1126
+			//if the item author is set and the user is the author...
1127
+			if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1128
+				$caps[] = $cap;
1129
+			} elseif ($status_obj->private && ! empty($this->private_cap)) {
1130
+				//the user is trying to view someone else's obj
1131
+				$caps[] = $this->private_cap;
1132
+			} elseif (! empty($this->others_cap)) {
1133
+				$caps[] = $this->others_cap;
1134
+			} else {
1135
+				$caps[] = $cap;
1136
+			}
1137
+		} else {
1138
+			//not a cpt object so handled differently
1139
+			$has_cap = false;
1140
+			try {
1141
+				$has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id;
1142
+			} catch (Exception $e) {
1143
+				if (WP_DEBUG) {
1144
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1145
+				}
1146
+			}
1147
+			if ($has_cap) {
1148
+				$caps[] = $cap;
1149
+			} elseif (! empty($this->private_cap)) {
1150
+				$caps[] = $this->private_cap;
1151
+			} elseif (! empty($this->others_cap)) {
1152
+				$caps[] = $this->others_cap;
1153
+			} else {
1154
+				$caps[] = $cap;
1155
+			}
1156
+		}
1157
+		return $caps;
1158
+	}
1159 1159
 }
1160 1160
 
1161 1161
 
@@ -1172,46 +1172,46 @@  discard block
 block discarded – undo
1172 1172
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1173 1173
 {
1174 1174
 
1175
-    /**
1176
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1177
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1178
-     *
1179
-     * @since 4.5.0
1180
-     * @see   wp-includes/capabilities.php
1181
-     * @param array  $caps    actual users capabilities
1182
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1183
-     * @param int    $user_id The user id
1184
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1185
-     * @return array   actual users capabilities
1186
-     */
1187
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1188
-    {
1189
-        //only process if we're checking our mapped_cap
1190
-        if ($cap !== $this->meta_cap) {
1191
-            return $caps;
1192
-        }
1193
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1194
-        //if no obj then let's just do cap
1195
-        if (! $obj instanceof EE_Message_Template_Group) {
1196
-            $caps[] = $cap;
1197
-            return $caps;
1198
-        }
1199
-        $is_global = $obj->is_global();
1200
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1201
-            if ($is_global) {
1202
-                $caps[] = $this->private_cap;
1203
-            } else {
1204
-                $caps[] = $cap;
1205
-            }
1206
-        } else {
1207
-            if ($is_global) {
1208
-                $caps[] = $this->private_cap;
1209
-            } else {
1210
-                $caps[] = $this->others_cap;
1211
-            }
1212
-        }
1213
-        return $caps;
1214
-    }
1175
+	/**
1176
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1177
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1178
+	 *
1179
+	 * @since 4.5.0
1180
+	 * @see   wp-includes/capabilities.php
1181
+	 * @param array  $caps    actual users capabilities
1182
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1183
+	 * @param int    $user_id The user id
1184
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1185
+	 * @return array   actual users capabilities
1186
+	 */
1187
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1188
+	{
1189
+		//only process if we're checking our mapped_cap
1190
+		if ($cap !== $this->meta_cap) {
1191
+			return $caps;
1192
+		}
1193
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1194
+		//if no obj then let's just do cap
1195
+		if (! $obj instanceof EE_Message_Template_Group) {
1196
+			$caps[] = $cap;
1197
+			return $caps;
1198
+		}
1199
+		$is_global = $obj->is_global();
1200
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1201
+			if ($is_global) {
1202
+				$caps[] = $this->private_cap;
1203
+			} else {
1204
+				$caps[] = $cap;
1205
+			}
1206
+		} else {
1207
+			if ($is_global) {
1208
+				$caps[] = $this->private_cap;
1209
+			} else {
1210
+				$caps[] = $this->others_cap;
1211
+			}
1212
+		}
1213
+		return $caps;
1214
+	}
1215 1215
 }
1216 1216
 
1217 1217
 
@@ -1228,39 +1228,39 @@  discard block
 block discarded – undo
1228 1228
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1229 1229
 {
1230 1230
 
1231
-    /**
1232
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1233
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1234
-     *
1235
-     * @since 4.5.0
1236
-     * @see   wp-includes/capabilities.php
1237
-     * @param array  $caps    actual users capabilities
1238
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1239
-     * @param int    $user_id The user id
1240
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1241
-     * @return array   actual users capabilities
1242
-     */
1243
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1244
-    {
1245
-        //only process if we're checking our mapped_cap
1246
-        if ($cap !== $this->meta_cap) {
1247
-            return $caps;
1248
-        }
1249
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1250
-        //if no obj then let's just do cap
1251
-        if (! $obj instanceof EE_Base_Class) {
1252
-            $caps[] = $cap;
1253
-            return $caps;
1254
-        }
1255
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1256
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1257
-        if ($is_system) {
1258
-            $caps[] = $this->private_cap;
1259
-        } else {
1260
-            $caps[] = $cap;
1261
-        }
1262
-        return $caps;
1263
-    }
1231
+	/**
1232
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1233
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1234
+	 *
1235
+	 * @since 4.5.0
1236
+	 * @see   wp-includes/capabilities.php
1237
+	 * @param array  $caps    actual users capabilities
1238
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1239
+	 * @param int    $user_id The user id
1240
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1241
+	 * @return array   actual users capabilities
1242
+	 */
1243
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1244
+	{
1245
+		//only process if we're checking our mapped_cap
1246
+		if ($cap !== $this->meta_cap) {
1247
+			return $caps;
1248
+		}
1249
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1250
+		//if no obj then let's just do cap
1251
+		if (! $obj instanceof EE_Base_Class) {
1252
+			$caps[] = $cap;
1253
+			return $caps;
1254
+		}
1255
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1256
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1257
+		if ($is_system) {
1258
+			$caps[] = $this->private_cap;
1259
+		} else {
1260
+			$caps[] = $cap;
1261
+		}
1262
+		return $caps;
1263
+	}
1264 1264
 
1265 1265
 
1266 1266
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     public static function instance()
56 56
     {
57 57
         //check if instantiated, and if not do so.
58
-        if (! self::$_instance instanceof EE_Capabilities) {
58
+        if ( ! self::$_instance instanceof EE_Capabilities) {
59 59
             self::$_instance = new self();
60 60
         }
61 61
         return self::$_instance;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         $this->_meta_caps = $this->_get_default_meta_caps_array();
120 120
         $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps);
121 121
         //add filter for map_meta_caps but only if models can query.
122
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
122
+        if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
123 123
             add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
124 124
         }
125 125
     }
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
276 276
             //loop through our _meta_caps array
277 277
             foreach ($this->_meta_caps as $meta_map) {
278
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
278
+                if ( ! $meta_map instanceof EE_Meta_Capability_Map) {
279 279
                     continue;
280 280
                 }
281 281
                 $meta_map->ensure_is_model();
@@ -649,9 +649,9 @@  discard block
 block discarded – undo
649 649
         foreach ($caps_map as $role => $caps_for_role) {
650 650
             foreach ($caps_for_role as $cap) {
651 651
                 //first check we haven't already added this cap before, or it's a reset
652
-                if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) {
652
+                if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) {
653 653
                     if ($this->add_cap_to_role($role, $cap)) {
654
-                        $caps_set_before[ $role ][] = $cap;
654
+                        $caps_set_before[$role][] = $cap;
655 655
                     }
656 656
                 }
657 657
             }
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
     {
679 679
         $role_object = get_role($role);
680 680
         //if the role isn't available then we create it.
681
-        if (! $role_object instanceof WP_Role) {
681
+        if ( ! $role_object instanceof WP_Role) {
682 682
             //if a plugin wants to create a specific role name then they should create the role before
683 683
             //EE_Capabilities does.  Otherwise this function will create the role name from the slug:
684 684
             // - removes any `ee_` namespacing from the start of the slug.
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     public function current_user_can($cap, $context, $id = 0)
732 732
     {
733 733
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
734
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
734
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id);
735 735
         $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap,
736 736
             $id);
737 737
         return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap);
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
     public function user_can($user, $cap, $context, $id = 0)
752 752
     {
753 753
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
754
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
754
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id);
755 755
         $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user,
756 756
             $id);
757 757
         return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap);
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
             : current_user_can($blog_id, $cap);
781 781
         //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
782 782
         $user_can = apply_filters(
783
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
783
+            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context,
784 784
             $user_can,
785 785
             $blog_id,
786 786
             $cap,
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
         if (empty($role)) {
815 815
             return $capabilities;
816 816
         }
817
-        return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array();
817
+        return isset($capabilities[$role]) ? $capabilities[$role] : array();
818 818
     }
819 819
 }
820 820
 
@@ -878,16 +878,16 @@  discard block
 block discarded – undo
878 878
                         'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
879 879
                         'event_espresso'
880 880
                     ),
881
-                    '<br>' . print_r($map_values, true)
881
+                    '<br>'.print_r($map_values, true)
882 882
                 )
883 883
             );
884 884
         }
885 885
         //set properties
886 886
         $this->_model = null;
887 887
         $this->_model_name = $map_values[0];
888
-        $this->published_cap = (string)$map_values[1];
889
-        $this->others_cap = (string)$map_values[2];
890
-        $this->private_cap = (string)$map_values[3];
888
+        $this->published_cap = (string) $map_values[1];
889
+        $this->others_cap = (string) $map_values[2];
890
+        $this->private_cap = (string) $map_values[3];
891 891
     }
892 892
 
893 893
     /**
@@ -913,11 +913,11 @@  discard block
 block discarded – undo
913 913
             return;
914 914
         }
915 915
         //ensure model name is string
916
-        $this->_model_name = (string)$this->_model_name;
916
+        $this->_model_name = (string) $this->_model_name;
917 917
         //error proof if the name has EEM in it
918 918
         $this->_model_name = str_replace('EEM', '', $this->_model_name);
919 919
         $this->_model = EE_Registry::instance()->load_model($this->_model_name);
920
-        if (! $this->_model instanceof EEM_Base) {
920
+        if ( ! $this->_model instanceof EEM_Base) {
921 921
             throw new EE_Error(
922 922
                 sprintf(
923 923
                     __(
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
         /** @var EE_Base_Class $obj */
997 997
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
998 998
         //if no obj then let's just do cap
999
-        if (! $obj instanceof EE_Base_Class) {
999
+        if ( ! $obj instanceof EE_Base_Class) {
1000 1000
             $caps[] = $cap;
1001 1001
             return $caps;
1002 1002
         }
@@ -1015,12 +1015,12 @@  discard block
 block discarded – undo
1015 1015
                 }
1016 1016
             } else {
1017 1017
                 //the user is trying to edit someone else's obj
1018
-                if (! empty($this->others_cap)) {
1018
+                if ( ! empty($this->others_cap)) {
1019 1019
                     $caps[] = $this->others_cap;
1020 1020
                 }
1021
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1021
+                if ( ! empty($this->published_cap) && $obj->status() === 'publish') {
1022 1022
                     $caps[] = $this->published_cap;
1023
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1023
+                } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') {
1024 1024
                     $caps[] = $this->private_cap;
1025 1025
                 }
1026 1026
             }
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
             if ($has_cap) {
1040 1040
                 $caps[] = $cap;
1041 1041
             } else {
1042
-                if (! empty($this->others_cap)) {
1042
+                if ( ! empty($this->others_cap)) {
1043 1043
                     $caps[] = $this->others_cap;
1044 1044
                 }
1045 1045
             }
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
         }
1114 1114
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1115 1115
         //if no obj then let's just do cap
1116
-        if (! $obj instanceof EE_Base_Class) {
1116
+        if ( ! $obj instanceof EE_Base_Class) {
1117 1117
             $caps[] = $cap;
1118 1118
             return $caps;
1119 1119
         }
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
             } elseif ($status_obj->private && ! empty($this->private_cap)) {
1130 1130
                 //the user is trying to view someone else's obj
1131 1131
                 $caps[] = $this->private_cap;
1132
-            } elseif (! empty($this->others_cap)) {
1132
+            } elseif ( ! empty($this->others_cap)) {
1133 1133
                 $caps[] = $this->others_cap;
1134 1134
             } else {
1135 1135
                 $caps[] = $cap;
@@ -1146,9 +1146,9 @@  discard block
 block discarded – undo
1146 1146
             }
1147 1147
             if ($has_cap) {
1148 1148
                 $caps[] = $cap;
1149
-            } elseif (! empty($this->private_cap)) {
1149
+            } elseif ( ! empty($this->private_cap)) {
1150 1150
                 $caps[] = $this->private_cap;
1151
-            } elseif (! empty($this->others_cap)) {
1151
+            } elseif ( ! empty($this->others_cap)) {
1152 1152
                 $caps[] = $this->others_cap;
1153 1153
             } else {
1154 1154
                 $caps[] = $cap;
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
         }
1193 1193
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1194 1194
         //if no obj then let's just do cap
1195
-        if (! $obj instanceof EE_Message_Template_Group) {
1195
+        if ( ! $obj instanceof EE_Message_Template_Group) {
1196 1196
             $caps[] = $cap;
1197 1197
             return $caps;
1198 1198
         }
@@ -1248,7 +1248,7 @@  discard block
 block discarded – undo
1248 1248
         }
1249 1249
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1250 1250
         //if no obj then let's just do cap
1251
-        if (! $obj instanceof EE_Base_Class) {
1251
+        if ( ! $obj instanceof EE_Base_Class) {
1252 1252
             $caps[] = $cap;
1253 1253
             return $caps;
1254 1254
         }
Please login to merge, or discard this patch.
core/EE_Deprecated.core.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -955,17 +955,17 @@
 block discarded – undo
955 955
 
956 956
 
957 957
 function ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete() {
958
-    if (has_action('AHEE__EE_Brewing_Regular__construct__complete')) {
959
-        EE_Error::doing_it_wrong(
960
-            'Action Hook: AHEE__EE_Brewing_Regular__construct__complete',
961
-            esc_html__(
962
-                'This action has been replaced by `AHEE__EE_Brewing_Regular__construct_finished` which executes at plugins_loaded priority 1. Your callback hooking into this action is still being executed at plugins_loaded priority level 5 but no longer immediately at the end of the EE_Brewing_Regular::construct.',
963
-                'event_espresso'
964
-            ),
965
-            '4.9.22.p'
966
-        );
967
-    }
968
-    do_action( 'AHEE__EE_Brewing_Regular__construct__complete' );
958
+	if (has_action('AHEE__EE_Brewing_Regular__construct__complete')) {
959
+		EE_Error::doing_it_wrong(
960
+			'Action Hook: AHEE__EE_Brewing_Regular__construct__complete',
961
+			esc_html__(
962
+				'This action has been replaced by `AHEE__EE_Brewing_Regular__construct_finished` which executes at plugins_loaded priority 1. Your callback hooking into this action is still being executed at plugins_loaded priority level 5 but no longer immediately at the end of the EE_Brewing_Regular::construct.',
963
+				'event_espresso'
964
+			),
965
+			'4.9.22.p'
966
+		);
967
+	}
968
+	do_action( 'AHEE__EE_Brewing_Regular__construct__complete' );
969 969
 }
970 970
 add_action( 'AHEE__EE_System__load_core_configuration__complete', 'ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete' );
971 971
 
Please login to merge, or discard this patch.
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * ************************************************************************
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	$action_or_filter = 'action'
44 44
 ) {
45 45
 	$action_or_filter = $action_or_filter === 'action'
46
-		? esc_html__( 'action', 'event_espresso' )
47
-		: esc_html__( 'filter', 'event_espresso' );
46
+		? esc_html__('action', 'event_espresso')
47
+		: esc_html__('filter', 'event_espresso');
48 48
 	EE_Error::doing_it_wrong(
49 49
 		$deprecated_filter,
50 50
 		sprintf(
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * @param \EE_Checkout $checkout
69 69
  * @return string
70 70
  */
71
-function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) {
71
+function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) {
72 72
 	// list of old filters
73 73
 	$deprecated_filters = array(
74 74
 		'update_registration_details' => true,
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 		'proceed_to' => true,
79 79
 	);
80 80
 	// loop thru and call doing_it_wrong() or remove any that aren't being used
81
-	foreach ( $deprecated_filters as $deprecated_filter => $on ) {
81
+	foreach ($deprecated_filters as $deprecated_filter => $on) {
82 82
 		// was this filter called ?
83
-		if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) {
83
+		if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) {
84 84
 			// only display doing_it_wrong() notice to Event Admins during non-AJAX requests
85
-			if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) {
85
+			if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) {
86 86
 				EE_Error::doing_it_wrong(
87
-					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
87
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
88 88
 					sprintf(
89
-						__( 'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ),
90
-						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
89
+						__('The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'),
90
+						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
91 91
 						'<br />',
92 92
 						'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
93 93
 						'/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
 				);
97 97
 			}
98 98
 		} else {
99
-			unset( $deprecated_filters[ $deprecated_filter ] );
99
+			unset($deprecated_filters[$deprecated_filter]);
100 100
 		}
101 101
 	}
102
-	if ( ! empty( $deprecated_filters )) {
103
-
104
-		if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) {
105
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text );
106
-		} else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) {
107
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text );
108
-		} else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) {
109
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text );
102
+	if ( ! empty($deprecated_filters)) {
103
+
104
+		if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
105
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text);
106
+		} else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
107
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text);
108
+		} else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
109
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text);
110 110
 		}
111
-		if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) {
112
-			if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) {
113
-				$submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text );
111
+		if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
112
+			if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
113
+				$submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text);
114 114
 			}
115
-			if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) {
116
-				$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name();
115
+			if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
116
+				$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name();
117 117
 			}
118 118
 		}
119 119
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	return $submit_button_text;
122 122
 
123 123
 }
124
-add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 );
124
+add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2);
125 125
 
126 126
 
127 127
 
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
  * @param \EE_Checkout $checkout
133 133
  * @param boolean $status_updates
134 134
  */
135
-function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) {
135
+function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) {
136 136
 	$action_ref = NULL;
137
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
-	if ( $action_ref ) {
137
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
+	if ($action_ref) {
140 140
 
141 141
 		EE_Error::doing_it_wrong(
142 142
 			$action_ref,
143 143
 			sprintf(
144
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ),
144
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'),
145 145
 				'<br />',
146 146
 				'/core/business/EE_Transaction_Processor.class.php',
147 147
 				'AHEE__EE_Transaction_Processor__finalize',
@@ -151,39 +151,39 @@  discard block
 block discarded – undo
151 151
 			),
152 152
 			'4.6.0'
153 153
 		);
154
-		switch ( $action_ref ) {
154
+		switch ($action_ref) {
155 155
 			case 'AHEE__EE_Transaction__finalize__new_transaction' :
156
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request );
156
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request);
157 157
 				break;
158 158
 			case 'AHEE__EE_Transaction__finalize__all_transaction' :
159
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request );
159
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request);
160 160
 				break;
161 161
 		}
162 162
 	}
163 163
 }
164
-add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 );
164
+add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2);
165 165
 /**
166 166
  * ee_deprecated_finalize_registration
167 167
  *
168 168
  * @param EE_Registration $registration
169 169
  */
170
-function ee_deprecated_finalize_registration( EE_Registration $registration ) {
171
-	$action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
-	if ( $action_ref ) {
170
+function ee_deprecated_finalize_registration(EE_Registration $registration) {
171
+	$action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
+	if ($action_ref) {
173 173
 		EE_Error::doing_it_wrong(
174 174
 			$action_ref,
175 175
 			sprintf(
176
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ),
176
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'),
177 177
 				'<br />',
178 178
 				'/core/business/EE_Registration_Processor.class.php',
179 179
 				'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook'
180 180
 			),
181 181
 			'4.6.0'
182 182
 		);
183
-		do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )));
183
+		do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)));
184 184
 	}
185 185
 }
186
-add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 );
186
+add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1);
187 187
 
188 188
 
189 189
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
  * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called.
192 192
  * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately.
193 193
  */
194
-function ee_deprecated_hooks(){
194
+function ee_deprecated_hooks() {
195 195
 	/**
196 196
 	 * @var $hooks array where keys are hook names, and their values are array{
197 197
 	 *			@type string $version  when deprecated
@@ -202,25 +202,25 @@  discard block
 block discarded – undo
202 202
 	$hooks = array(
203 203
 		'AHEE__EE_System___do_setup_validations' => array(
204 204
 			'version' => '4.6.0',
205
-			'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ),
205
+			'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'),
206 206
 			'still_works' => FALSE
207 207
 		)
208 208
 	);
209
-	foreach( $hooks as $name => $deprecation_info ){
210
-		if( has_action( $name ) ){
209
+	foreach ($hooks as $name => $deprecation_info) {
210
+		if (has_action($name)) {
211 211
 			EE_Error::doing_it_wrong(
212 212
 				$name,
213 213
 				sprintf(
214
-					__('This filter is deprecated. %1$s%2$s','event_espresso'),
215
-					$deprecation_info[ 'still_works' ] ?  __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ),
216
-					isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' )
214
+					__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
215
+					$deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'),
216
+					isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso')
217 217
 				),
218
-				isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' )
218
+				isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
219 219
 			);
220 220
 		}
221 221
 	}
222 222
 }
223
-add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' );
223
+add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks');
224 224
 
225 225
 
226 226
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
  * @return boolean
232 232
  */
233 233
 function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() {
234
-	$in_use =  has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' )
235
-			|| has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' );
236
-	if( $in_use ) {
234
+	$in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
235
+			|| has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save');
236
+	if ($in_use) {
237 237
 		$msg = __(
238 238
 			'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
239 239
 			. 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
 			'event_espresso' )
243 243
 		;
244 244
 		EE_Error::doing_it_wrong(
245
-			__CLASS__ . '::' . __FUNCTION__,
245
+			__CLASS__.'::'.__FUNCTION__,
246 246
 			$msg,
247 247
 			'4.8.32.rc.000'
248 248
 		);
249 249
 		//it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
250
-		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
251
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
250
+		if (is_admin() && ! defined('DOING_AJAX')) {
251
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
252 252
 		}
253 253
 	}
254 254
 	return $in_use;
255 255
 }
256
-add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' );
256
+add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks');
257 257
 
258 258
 /**
259 259
  * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165
@@ -262,34 +262,34 @@  discard block
 block discarded – undo
262 262
  * @param EE_Admin_Page $admin_page
263 263
  * @return void
264 264
  */
265
-function ee_deprecated_update_attendee_registration_form_old( $admin_page ) {
265
+function ee_deprecated_update_attendee_registration_form_old($admin_page) {
266 266
 	//check if the old hooks are in use. If not, do the default
267
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
-		|| ! $admin_page instanceof EE_Admin_Page ) {
267
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
+		|| ! $admin_page instanceof EE_Admin_Page) {
269 269
 		return;
270 270
 	}
271 271
 	$req_data = $admin_page->get_request_data();
272
-	$qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE;
273
-	$REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE;
274
-	$qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns );
275
-	if ( ! $REG_ID || ! $qstns ) {
276
-		EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
272
+	$qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE;
273
+	$REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE;
274
+	$qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
275
+	if ( ! $REG_ID || ! $qstns) {
276
+		EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
277 277
 	}
278 278
 	$success = TRUE;
279 279
 
280 280
 	// allow others to get in on this awesome fun   :D
281
-	do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns );
281
+	do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns);
282 282
 	// loop thru questions... FINALLY!!!
283 283
 
284
-	foreach ( $qstns as $QST_ID => $qstn ) {
284
+	foreach ($qstns as $QST_ID => $qstn) {
285 285
 		//if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
286
-		if ( !is_array($qstn) ) {
287
-			$success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn);
286
+		if ( ! is_array($qstn)) {
287
+			$success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn);
288 288
 			continue;
289 289
 		}
290 290
 
291 291
 
292
-		foreach ( $qstn as $ANS_ID => $ANS_value ) {
292
+		foreach ($qstn as $ANS_ID => $ANS_value) {
293 293
 			//get answer
294 294
 			$query_params = array(
295 295
 				0 => array(
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 				);
301 301
 			$answer = EEM_Answer::instance()->get_one($query_params);
302 302
 			//this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
303
-			if ( ! $answer instanceof EE_Answer ) {
303
+			if ( ! $answer instanceof EE_Answer) {
304 304
 				$set_values = array(
305 305
 					'QST_ID' => $QST_ID,
306 306
 					'REG_ID' => $REG_ID,
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
 		}
316 316
 	}
317 317
 	$what = __('Registration Form', 'event_espresso');
318
-	$route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' );
319
-	$admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route );
318
+	$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
319
+	$admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
320 320
 	exit;
321 321
 }
322
-add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 );
322
+add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1);
323 323
 /**
324 324
  * Render the registration admin page's custom questions area in the old fashion
325 325
  * and firing the old hooks. When this method is removed, we can probably also
@@ -332,31 +332,31 @@  discard block
 block discarded – undo
332 332
  * @return bool
333 333
  * @throws \EE_Error
334 334
  */
335
-function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) {
335
+function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) {
336 336
 	//check if the old hooks are in use. If not, do the default
337
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
-		|| ! $admin_page instanceof EE_Admin_Page ) {
337
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
+		|| ! $admin_page instanceof EE_Admin_Page) {
339 339
 		return $do_default_action;
340 340
 	}
341
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 );
342
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 );
343
-	add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 );
344
-	add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 );
341
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1);
342
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1);
343
+	add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
344
+	add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
345 345
 
346
-	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') );
346
+	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID'));
347 347
 
348
-	EE_Registry::instance()->load_helper( 'Form_Fields' );
348
+	EE_Registry::instance()->load_helper('Form_Fields');
349 349
 	$template_args = array(
350
-		'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ),
350
+		'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups),
351 351
 		'reg_questions_form_action' => 'edit_registration',
352 352
 		'REG_ID' => $registration->ID()
353 353
 	);
354
-	$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
355
-	echo EEH_Template::display_template( $template_path, $template_args, TRUE );
354
+	$template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
355
+	echo EEH_Template::display_template($template_path, $template_args, TRUE);
356 356
 	//indicate that we should not do the default admin page code
357 357
 	return false;
358 358
 }
359
-add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 );
359
+add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3);
360 360
 
361 361
 
362 362
 
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 			'4.9.0'
398 398
 		);
399 399
 		/** @var EE_Message_Resource_Manager $message_resource_manager */
400
-		$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
401
-		$messenger = $message_resource_manager->get_messenger( $messenger_name );
402
-		$message_type = $message_resource_manager->get_message_type( $message_type_name );
400
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
401
+		$messenger = $message_resource_manager->get_messenger($messenger_name);
402
+		$message_type = $message_resource_manager->get_message_type($message_type_name);
403 403
 		return EE_Registry::instance()->load_lib(
404 404
 			'Messages_Template_Defaults',
405 405
 			array(
@@ -464,15 +464,15 @@  discard block
 block discarded – undo
464 464
 	/**
465 465
 	 * @param string $method
466 466
 	 */
467
-	public function _class_is_deprecated( $method ) {
467
+	public function _class_is_deprecated($method) {
468 468
 		EE_Error::doing_it_wrong(
469
-			'EE_messages::' . $method,
470
-			__( 'EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.' ),
469
+			'EE_messages::'.$method,
470
+			__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
471 471
 			'4.9.0',
472 472
 			'4.10.0.p'
473 473
 		);
474 474
 		// Please use EE_Message_Resource_Manager instead
475
-		$this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
475
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
476 476
 	}
477 477
 
478 478
 
@@ -482,10 +482,10 @@  discard block
 block discarded – undo
482 482
 	 * @param string $messenger_name
483 483
 	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
484 484
 	 */
485
-	public function ensure_messenger_is_active( $messenger_name ) {
485
+	public function ensure_messenger_is_active($messenger_name) {
486 486
 		// EE_messages has been deprecated
487
-		$this->_class_is_deprecated( __FUNCTION__ );
488
-		return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name );
487
+		$this->_class_is_deprecated(__FUNCTION__);
488
+		return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
489 489
 	}
490 490
 
491 491
 
@@ -497,10 +497,10 @@  discard block
 block discarded – undo
497 497
 	 * @return bool true if it got activated (or was active) and false if not.
498 498
 	 * @throws \EE_Error
499 499
 	 */
500
-	public function ensure_message_type_is_active( $message_type, $messenger ) {
500
+	public function ensure_message_type_is_active($message_type, $messenger) {
501 501
 		// EE_messages has been deprecated
502
-		$this->_class_is_deprecated( __FUNCTION__ );
503
-		return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger );
502
+		$this->_class_is_deprecated(__FUNCTION__);
503
+		return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
504 504
 	}
505 505
 
506 506
 
@@ -513,10 +513,10 @@  discard block
 block discarded – undo
513 513
 	 *                                            they are already setup.)
514 514
 	 * @return boolean an array of generated templates or false if nothing generated/activated.
515 515
 	 */
516
-	public function activate_messenger( $messenger_name, $mts_to_activate = array() ) {
516
+	public function activate_messenger($messenger_name, $mts_to_activate = array()) {
517 517
 		// EE_messages has been deprecated
518
-		$this->_class_is_deprecated( __FUNCTION__ );
519
-		return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate );
518
+		$this->_class_is_deprecated(__FUNCTION__);
519
+		return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
520 520
 	}
521 521
 
522 522
 
@@ -528,10 +528,10 @@  discard block
 block discarded – undo
528 528
 	 *
529 529
 	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
530 530
 	 */
531
-	public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) {
531
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) {
532 532
 		// EE_messages has been deprecated
533
-		$this->_class_is_deprecated( __FUNCTION__ );
534
-		return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type );
533
+		$this->_class_is_deprecated(__FUNCTION__);
534
+		return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
535 535
 	}
536 536
 
537 537
 
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
 	 * @param string $messenger
542 542
 	 * @return EE_messenger | null
543 543
 	 */
544
-	public function get_messenger_if_active( $messenger ) {
544
+	public function get_messenger_if_active($messenger) {
545 545
 		// EE_messages has been deprecated
546
-		$this->_class_is_deprecated( __FUNCTION__ );
547
-		return $this->_message_resource_manager->get_active_messenger( $messenger );
546
+		$this->_class_is_deprecated(__FUNCTION__);
547
+		return $this->_message_resource_manager->get_active_messenger($messenger);
548 548
 	}
549 549
 
550 550
 
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 	 *                  'message_type' => null
566 566
 	 *                  )
567 567
 	 */
568
-	public function validate_for_use( EE_Message $message ) {
568
+	public function validate_for_use(EE_Message $message) {
569 569
 		// EE_messages has been deprecated
570
-		$this->_class_is_deprecated( __FUNCTION__ );
570
+		$this->_class_is_deprecated(__FUNCTION__);
571 571
 		return array(
572 572
 			'messenger'    => $message->messenger_object(),
573 573
 			'message_type' => $message->message_type_object(),
@@ -595,41 +595,41 @@  discard block
 block discarded – undo
595 595
 		$send = true
596 596
 	) {
597 597
 		// EE_messages has been deprecated
598
-		$this->_class_is_deprecated( __FUNCTION__ );
598
+		$this->_class_is_deprecated(__FUNCTION__);
599 599
 		/** @type EE_Messages_Processor $processor */
600
-		$processor = EE_Registry::instance()->load_lib( 'Messages_Processor' );
600
+		$processor = EE_Registry::instance()->load_lib('Messages_Processor');
601 601
 		$error = false;
602 602
 		//try to intelligently determine what method we'll call based on the incoming data.
603 603
 		//if generating and sending are different then generate and send immediately.
604
-		if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) {
604
+		if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
605 605
 			//in the legacy system, when generating and sending were different, that means all the
606 606
 			//vars are already in the request object.  So let's just use that.
607 607
 			try {
608 608
 				/** @type EE_Message_To_Generate_From_Request $mtg */
609
-				$mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' );
610
-				$processor->generate_and_send_now( $mtg );
611
-			} catch ( EE_Error $e ) {
609
+				$mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
610
+				$processor->generate_and_send_now($mtg);
611
+			} catch (EE_Error $e) {
612 612
 				$error_msg = __(
613 613
 					'Please note that a system message failed to send due to a technical issue.',
614 614
 					'event_espresso'
615 615
 				);
616 616
 				// add specific message for developers if WP_DEBUG in on
617
-				$error_msg .= '||' . $e->getMessage();
618
-				EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
617
+				$error_msg .= '||'.$e->getMessage();
618
+				EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
619 619
 				$error = true;
620 620
 			}
621 621
 		} else {
622
-			$processor->generate_for_all_active_messengers( $type, $vars, $send );
622
+			$processor->generate_for_all_active_messengers($type, $vars, $send);
623 623
 			//let's find out if there were any errors and how many successfully were queued.
624 624
 			$count_errors = $processor->get_queue()->count_STS_in_queue(
625
-				array( EEM_Message::status_failed, EEM_Message::status_debug_only )
625
+				array(EEM_Message::status_failed, EEM_Message::status_debug_only)
626 626
 			);
627
-			$count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete );
628
-			$count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry );
627
+			$count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
628
+			$count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
629 629
 			$count_errors = $count_errors + $count_retry;
630
-			if ( $count_errors > 0 ) {
630
+			if ($count_errors > 0) {
631 631
 				$error = true;
632
-				if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) {
632
+				if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
633 633
 					$message = sprintf(
634 634
 						__(
635 635
 							'There were %d errors and %d messages successfully queued for generation and sending',
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 						$count_errors,
639 639
 						$count_queued
640 640
 					);
641
-				} elseif ( $count_errors > 1 && $count_queued === 1 ) {
641
+				} elseif ($count_errors > 1 && $count_queued === 1) {
642 642
 					$message = sprintf(
643 643
 						__(
644 644
 							'There were %d errors and %d message successfully queued for generation.',
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 						$count_errors,
648 648
 						$count_queued
649 649
 					);
650
-				} elseif ( $count_errors === 1 && $count_queued > 1 ) {
650
+				} elseif ($count_errors === 1 && $count_queued > 1) {
651 651
 					$message = sprintf(
652 652
 						__(
653 653
 							'There was %d error and %d messages successfully queued for generation.',
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 						$count_errors
666 666
 					);
667 667
 				}
668
-				EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ );
668
+				EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
669 669
 			} else {
670
-				if ( $count_queued === 1 ) {
670
+				if ($count_queued === 1) {
671 671
 					$message = sprintf(
672 672
 						__(
673 673
 							'%d message successfully queued for generation.',
@@ -684,18 +684,18 @@  discard block
 block discarded – undo
684 684
 						$count_queued
685 685
 					);
686 686
 				}
687
-				EE_Error::add_success( $message );
687
+				EE_Error::add_success($message);
688 688
 			}
689 689
 		}
690 690
 		//if no error then return the generated message(s).
691
-		if ( ! $error && ! $send ) {
692
-			$generated_queue = $processor->generate_queue( false );
691
+		if ( ! $error && ! $send) {
692
+			$generated_queue = $processor->generate_queue(false);
693 693
 			//get message and return.
694 694
 			$generated_queue->get_message_repository()->rewind();
695 695
 			$messages = array();
696
-			while ( $generated_queue->get_message_repository()->valid() ) {
696
+			while ($generated_queue->get_message_repository()->valid()) {
697 697
 				$message = $generated_queue->get_message_repository()->current();
698
-				if ( $message instanceof EE_Message ) {
698
+				if ($message instanceof EE_Message) {
699 699
 					//set properties that might be expected by add-ons (backward compat)
700 700
 					$message->content = $message->content();
701 701
 					$message->template_pack = $message->get_template_pack();
@@ -720,10 +720,10 @@  discard block
 block discarded – undo
720 720
 	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular preview
721 721
 	 * @return string          The body of the message.
722 722
 	 */
723
-	public function preview_message( $type, $context, $messenger, $send = false ) {
723
+	public function preview_message($type, $context, $messenger, $send = false) {
724 724
 		// EE_messages has been deprecated
725
-		$this->_class_is_deprecated( __FUNCTION__ );
726
-		return EED_Messages::preview_message( $type, $context, $messenger, $send );
725
+		$this->_class_is_deprecated(__FUNCTION__);
726
+		return EED_Messages::preview_message($type, $context, $messenger, $send);
727 727
 	}
728 728
 
729 729
 
@@ -737,14 +737,14 @@  discard block
 block discarded – undo
737 737
 	 *
738 738
 	 * @return bool          success or fail.
739 739
 	 */
740
-	public function send_message_with_messenger_only( $messenger, $message_type, $message ) {
740
+	public function send_message_with_messenger_only($messenger, $message_type, $message) {
741 741
 		// EE_messages has been deprecated
742
-		$this->_class_is_deprecated( __FUNCTION__ );
742
+		$this->_class_is_deprecated(__FUNCTION__);
743 743
 		//setup for sending to new method.
744 744
 		/** @type EE_Messages_Queue $queue */
745
-		$queue = EE_Registry::instance()->load_lib( 'Messages_Queue' );
745
+		$queue = EE_Registry::instance()->load_lib('Messages_Queue');
746 746
 		//make sure we have a proper message object
747
-		if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) {
747
+		if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
748 748
 			$msg = EE_Message_Factory::create(
749 749
 				array(
750 750
 					'MSG_messenger'    => $messenger,
@@ -756,15 +756,15 @@  discard block
 block discarded – undo
756 756
 		} else {
757 757
 			$msg = $message;
758 758
 		}
759
-		if ( ! $msg instanceof EE_Message ) {
759
+		if ( ! $msg instanceof EE_Message) {
760 760
 			return false;
761 761
 		}
762 762
 		//make sure any content in a content property (if not empty) is set on the MSG_content.
763
-		if ( ! empty( $msg->content ) ) {
764
-			$msg->set( 'MSG_content', $msg->content );
763
+		if ( ! empty($msg->content)) {
764
+			$msg->set('MSG_content', $msg->content);
765 765
 		}
766
-		$queue->add( $msg );
767
-		return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue );
766
+		$queue->add($msg);
767
+		return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
768 768
 	}
769 769
 
770 770
 
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
 	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned.
779 779
 	 * @throws \EE_Error
780 780
 	 */
781
-	public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) {
781
+	public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) {
782 782
 		// EE_messages has been deprecated
783
-		$this->_class_is_deprecated( __FUNCTION__ );
784
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
785
-		return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global );
783
+		$this->_class_is_deprecated(__FUNCTION__);
784
+		EE_Registry::instance()->load_helper('MSG_Template');
785
+		return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
786 786
 	}
787 787
 
788 788
 
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
 	 * @param  string $message_type_name name of EE_message_type
794 794
 	 * @return array
795 795
 	 */
796
-	public function get_fields( $messenger_name, $message_type_name ) {
796
+	public function get_fields($messenger_name, $message_type_name) {
797 797
 		// EE_messages has been deprecated
798
-		$this->_class_is_deprecated( __FUNCTION__ );
799
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
800
-		return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name );
798
+		$this->_class_is_deprecated(__FUNCTION__);
799
+		EE_Registry::instance()->load_helper('MSG_Template');
800
+		return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
801 801
 	}
802 802
 
803 803
 
@@ -811,13 +811,13 @@  discard block
 block discarded – undo
811 811
 	 * @return array                    multidimensional array of messenger and message_type objects
812 812
 	 *                                    (messengers index, and message_type index);
813 813
 	 */
814
-	public function get_installed( $type = 'all', $skip_cache = false ) {
814
+	public function get_installed($type = 'all', $skip_cache = false) {
815 815
 		// EE_messages has been deprecated
816
-		$this->_class_is_deprecated( __FUNCTION__ );
817
-		if ( $skip_cache ) {
816
+		$this->_class_is_deprecated(__FUNCTION__);
817
+		if ($skip_cache) {
818 818
 			$this->_message_resource_manager->reset_active_messengers_and_message_types();
819 819
 		}
820
-		switch ( $type ) {
820
+		switch ($type) {
821 821
 			case 'messengers' :
822 822
 				return array(
823 823
 					'messenger' => $this->_message_resource_manager->installed_messengers(),
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	 */
847 847
 	public function get_active_messengers() {
848 848
 		// EE_messages has been deprecated
849
-		$this->_class_is_deprecated( __FUNCTION__ );
849
+		$this->_class_is_deprecated(__FUNCTION__);
850 850
 		return $this->_message_resource_manager->active_messengers();
851 851
 	}
852 852
 
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_active_message_types() {
860 860
 		// EE_messages has been deprecated
861
-		$this->_class_is_deprecated( __FUNCTION__ );
861
+		$this->_class_is_deprecated(__FUNCTION__);
862 862
 		return $this->_message_resource_manager->list_of_active_message_types();
863 863
 	}
864 864
 
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 	 */
871 871
 	public function get_active_message_type_objects() {
872 872
 		// EE_messages has been deprecated
873
-		$this->_class_is_deprecated( __FUNCTION__ );
873
+		$this->_class_is_deprecated(__FUNCTION__);
874 874
 		return $this->_message_resource_manager->get_active_message_type_objects();
875 875
 	}
876 876
 
@@ -882,10 +882,10 @@  discard block
 block discarded – undo
882 882
 	 * @param string $messenger The messenger being checked
883 883
 	 * @return EE_message_type[]    (or empty array if none present)
884 884
 	 */
885
-	public function get_active_message_types_per_messenger( $messenger ) {
885
+	public function get_active_message_types_per_messenger($messenger) {
886 886
 		// EE_messages has been deprecated
887
-		$this->_class_is_deprecated( __FUNCTION__ );
888
-		return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger );
887
+		$this->_class_is_deprecated(__FUNCTION__);
888
+		return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
889 889
 	}
890 890
 
891 891
 
@@ -896,10 +896,10 @@  discard block
 block discarded – undo
896 896
 	 * @param string $message_type The string should correspond to a message type.
897 897
 	 * @return EE_message_type|null
898 898
 	 */
899
-	public function get_active_message_type( $messenger, $message_type ) {
899
+	public function get_active_message_type($messenger, $message_type) {
900 900
 		// EE_messages has been deprecated
901
-		$this->_class_is_deprecated( __FUNCTION__ );
902
-		return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type );
901
+		$this->_class_is_deprecated(__FUNCTION__);
902
+		return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
903 903
 	}
904 904
 
905 905
 
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	public function get_installed_message_types() {
912 912
 		// EE_messages has been deprecated
913
-		$this->_class_is_deprecated( __FUNCTION__ );
913
+		$this->_class_is_deprecated(__FUNCTION__);
914 914
 		return $this->_message_resource_manager->installed_message_types();
915 915
 	}
916 916
 
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 	 */
923 923
 	public function get_installed_messengers() {
924 924
 		// EE_messages has been deprecated
925
-		$this->_class_is_deprecated( __FUNCTION__ );
925
+		$this->_class_is_deprecated(__FUNCTION__);
926 926
 		return $this->_message_resource_manager->installed_messengers();
927 927
 	}
928 928
 
@@ -933,10 +933,10 @@  discard block
 block discarded – undo
933 933
 	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type.
934 934
 	 * @return array
935 935
 	 */
936
-	public function get_all_contexts( $slugs_only = true ) {
936
+	public function get_all_contexts($slugs_only = true) {
937 937
 		// EE_messages has been deprecated
938
-		$this->_class_is_deprecated( __FUNCTION__ );
939
-		return $this->_message_resource_manager->get_all_contexts( $slugs_only );
938
+		$this->_class_is_deprecated(__FUNCTION__);
939
+		return $this->_message_resource_manager->get_all_contexts($slugs_only);
940 940
 	}
941 941
 
942 942
 
@@ -1002,15 +1002,15 @@  discard block
 block discarded – undo
1002 1002
             '4.9.22.p'
1003 1003
         );
1004 1004
     }
1005
-    do_action( 'AHEE__EE_Brewing_Regular__construct__complete' );
1005
+    do_action('AHEE__EE_Brewing_Regular__construct__complete');
1006 1006
 }
1007
-add_action( 'AHEE__EE_System__load_core_configuration__complete', 'ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete' );
1007
+add_action('AHEE__EE_System__load_core_configuration__complete', 'ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete');
1008 1008
 
1009 1009
 
1010 1010
 add_filter(
1011 1011
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1012 1012
 	function($event_list_iframe_css) {
1013
-		if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) {
1013
+		if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1014 1014
 			return $event_list_iframe_css;
1015 1015
 		}
1016 1016
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 add_filter(
1031 1031
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1032 1032
 	function($event_list_iframe_js) {
1033
-		if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) {
1033
+		if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1034 1034
 			return $event_list_iframe_js;
1035 1035
 		}
1036 1036
 		deprecated_espresso_action_or_filter_doing_it_wrong(
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Capabilities.lib.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -47,30 +47,30 @@  discard block
 block discarded – undo
47 47
 	 * @throws EE_Error
48 48
 	 * @return void
49 49
 	 */
50
-	public static function register( $cap_reference = NULL, $setup_args = array() ) {
50
+	public static function register($cap_reference = NULL, $setup_args = array()) {
51 51
 		//required fields MUST be present, so let's make sure they are.
52
-		if ( ! isset( $cap_reference ) || ! is_array( $setup_args ) || empty( $setup_args['capabilities'] ) ) {
52
+		if ( ! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
53 53
 			throw new EE_Error(
54
-				__( 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso' )
54
+				__('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso')
55 55
 			);
56 56
 		}
57 57
 		//make sure we don't register twice
58
-		if( isset( self::$_registry[ $cap_reference ] ) ){
58
+		if (isset(self::$_registry[$cap_reference])) {
59 59
 			return;
60 60
 		}
61 61
 		//make sure this is not registered too late or too early.
62
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' ) || did_action( 'AHEE__EE_System___detect_if_activation_or_upgrade__begin' ) ) {
63
-			EE_Error::doing_it_wrong( __METHOD__, sprintf( __('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference ), '4.5.0' );
62
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) {
63
+			EE_Error::doing_it_wrong(__METHOD__, sprintf(__('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference), '4.5.0');
64 64
 		}
65 65
 		//some preliminary sanitization and setting to the $_registry property
66 66
 		self::$_registry[$cap_reference] = array(
67
-			'caps' => isset( $setup_args['capabilities'] ) && is_array( $setup_args['capabilities'] ) ? $setup_args['capabilities'] : array(),
68
-			'cap_maps' => isset( $setup_args['capability_maps'] ) ? $setup_args['capability_maps'] : array()
67
+			'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(),
68
+			'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array()
69 69
 		);
70 70
 		//set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
71
-		add_filter( 'FHEE__EE_Capabilities__init_caps_map__caps', array( 'EE_Register_Capabilities', 'register_capabilities' ), 10 );
71
+		add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array('EE_Register_Capabilities', 'register_capabilities'), 10);
72 72
 		//add filter for cap maps
73
-		add_filter( 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', array( 'EE_Register_Capabilities', 'register_cap_maps' ), 10 );
73
+		add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', array('EE_Register_Capabilities', 'register_cap_maps'), 10);
74 74
 	}
75 75
 
76 76
 
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @return array merged in new caps.
85 85
 	 */
86
-	public static function register_capabilities( $incoming_caps ) {
87
-		foreach ( self::$_registry as $ref => $caps_and_cap_map ) {
88
-			$incoming_caps = array_merge_recursive( $incoming_caps, $caps_and_cap_map[ 'caps' ] );
86
+	public static function register_capabilities($incoming_caps) {
87
+		foreach (self::$_registry as $ref => $caps_and_cap_map) {
88
+			$incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
89 89
 		}
90 90
 		return $incoming_caps;
91 91
 	}
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 	 * @return EE_Meta_Capability_Map[]
101 101
 	 * @throws EE_Error
102 102
 	 */
103
-	public static function register_cap_maps( $cap_maps ) {
103
+	public static function register_cap_maps($cap_maps) {
104 104
 		//loop through and instantiate cap maps.
105
-		foreach ( self::$_registry as $cap_reference => $setup ) {
106
-			if ( ! isset( $setup['cap_maps'] ) ) {
105
+		foreach (self::$_registry as $cap_reference => $setup) {
106
+			if ( ! isset($setup['cap_maps'])) {
107 107
 				continue;
108 108
 			}
109
-			foreach ( $setup['cap_maps'] as $cap_class => $args ) {
109
+			foreach ($setup['cap_maps'] as $cap_class => $args) {
110 110
 
111 111
 				/**
112 112
 				 * account for cases where capability maps may be indexed
@@ -133,19 +133,19 @@  discard block
 block discarded – undo
133 133
 				 * 	...
134 134
 				 * )
135 135
 				 */
136
-				if ( is_numeric( $cap_class ) ) {
137
-					$cap_class = key( $args );
136
+				if (is_numeric($cap_class)) {
137
+					$cap_class = key($args);
138 138
 					$args = $args[$cap_class];
139 139
 				}
140 140
 
141
-				if ( ! class_exists( $cap_class ) ) {
142
-					throw new EE_Error( sprintf( __( 'An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso' ), $cap_reference ) );
141
+				if ( ! class_exists($cap_class)) {
142
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso'), $cap_reference));
143 143
 				}
144 144
 
145
-				if ( count( $args ) !== 2 ) {
146
-					throw new EE_Error( sprintf( __('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.', 'event_espresso' ), $cap_reference ) );
145
+				if (count($args) !== 2) {
146
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.', 'event_espresso'), $cap_reference));
147 147
 				}
148
-				$cap_maps[] = new $cap_class( $args[0], $args[1] );
148
+				$cap_maps[] = new $cap_class($args[0], $args[1]);
149 149
 			}
150 150
 		}
151 151
 		return $cap_maps;
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 
155 155
 
156 156
 
157
-	public static function deregister( $cap_reference = NULL ) {
158
-		if ( !empty( self::$_registry[$cap_reference] ) ) {
159
-			unset( self::$_registry[ $cap_reference ] );
157
+	public static function deregister($cap_reference = NULL) {
158
+		if ( ! empty(self::$_registry[$cap_reference])) {
159
+			unset(self::$_registry[$cap_reference]);
160 160
 		}
161 161
 
162 162
 		//re init caps to grab the changes due to removed caps.
Please login to merge, or discard this patch.
core/EE_Encryption.core.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -396,7 +396,7 @@
 block discarded – undo
396 396
 
397 397
     /**
398 398
      * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
399
-     * @param $string
399
+     * @param string $string
400 400
      * @return bool
401 401
      */
402 402
     protected function valid_base_64($string)
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      */
71 71
     protected function __construct()
72 72
     {
73
-        if (! defined('ESPRESSO_ENCRYPT')) {
73
+        if ( ! defined('ESPRESSO_ENCRYPT')) {
74 74
             define('ESPRESSO_ENCRYPT', true);
75 75
         }
76 76
         if (extension_loaded('openssl')) {
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public static function instance()
94 94
     {
95 95
         // check if class object is instantiated
96
-        if (! self::$_instance instanceof EE_Encryption) {
96
+        if ( ! self::$_instance instanceof EE_Encryption) {
97 97
             self::$_instance = new self();
98 98
         }
99 99
         return self::$_instance;
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             $iv
288 288
         );
289 289
         // append the initialization vector
290
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
290
+        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv;
291 291
         // trim and maybe encode
292 292
         return $this->_use_base64_encode
293 293
             ? trim(base64_encode($encrypted_text))
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             2
320 320
         );
321 321
         // check that iv exists, and if not, maybe text was encoded using mcrypt?
322
-        if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
322
+        if ( ! isset($encrypted_components[1]) && $this->_use_mcrypt) {
323 323
             return $this->m_decrypt($encrypted_text);
324 324
         }
325 325
         // decrypt it
@@ -402,16 +402,16 @@  discard block
 block discarded – undo
402 402
     protected function valid_base_64($string)
403 403
     {
404 404
         // ensure data is a string
405
-        if (! is_string($string) || ! $this->_use_base64_encode) {
405
+        if ( ! is_string($string) || ! $this->_use_base64_encode) {
406 406
             return false;
407 407
         }
408 408
         $decoded = base64_decode($string, true);
409 409
         // Check if there is no invalid character in string
410
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
410
+        if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
411 411
             return false;
412 412
         }
413 413
         // Decode the string in strict mode and send the response
414
-        if (! base64_decode($string, true)) {
414
+        if ( ! base64_decode($string, true)) {
415 415
             return false;
416 416
         }
417 417
         // Encode and compare it to original one
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         $iterations = ceil($length / 40);
433 433
         $random_string = '';
434 434
         for ($i = 0; $i < $iterations; $i++) {
435
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
435
+            $random_string .= sha1(microtime(true).mt_rand(10000, 90000));
436 436
         }
437 437
         $random_string = substr($random_string, 0, $length);
438 438
         return $random_string;
Please login to merge, or discard this patch.
Indentation   +510 added lines, -510 removed lines patch added patch discarded remove patch
@@ -16,516 +16,516 @@
 block discarded – undo
16 16
 class EE_Encryption
17 17
 {
18 18
 
19
-    /**
20
-     * key used for saving the encryption key to the wp_options table
21
-     */
22
-    const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
-
24
-    /**
25
-     * the OPENSSL cipher method used
26
-     */
27
-    const OPENSSL_CIPHER_METHOD = 'aes-256-ctr';
28
-
29
-    /**
30
-     * the OPENSSL digest method used
31
-     */
32
-    const OPENSSL_DIGEST_METHOD = 'sha512';
33
-
34
-    /**
35
-     * separates the encrypted text from the initialization vector
36
-     */
37
-    const OPENSSL_IV_DELIMITER = ':iv:';
38
-
39
-    /**
40
-     * appended to text encrypted using the acme encryption
41
-     */
42
-    const ACME_ENCRYPTION_FLAG = '::ae';
43
-
44
-
45
-
46
-    /**
47
-     * instance of the EE_Encryption object
48
-     */
49
-    protected static $_instance;
50
-
51
-    /**
52
-     * @var string $_encryption_key
53
-     */
54
-    protected $_encryption_key;
55
-
56
-    /**
57
-     * @var boolean $_use_openssl_encrypt
58
-     */
59
-    protected $_use_openssl_encrypt = false;
60
-
61
-    /**
62
-     * @var boolean $_use_mcrypt
63
-     */
64
-    protected $_use_mcrypt = false;
65
-
66
-    /**
67
-     * @var boolean $_use_base64_encode
68
-     */
69
-    protected $_use_base64_encode = false;
70
-
71
-
72
-
73
-    /**
74
-     * protected constructor to prevent direct creation
75
-     */
76
-    protected function __construct()
77
-    {
78
-        if (! defined('ESPRESSO_ENCRYPT')) {
79
-            define('ESPRESSO_ENCRYPT', true);
80
-        }
81
-        if (extension_loaded('openssl')) {
82
-            $this->_use_openssl_encrypt = true;
83
-        } else if (extension_loaded('mcrypt')) {
84
-            $this->_use_mcrypt = true;
85
-        }
86
-        if (function_exists('base64_encode')) {
87
-            $this->_use_base64_encode = true;
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * singleton method used to instantiate class object
95
-     *
96
-     * @return EE_Encryption
97
-     */
98
-    public static function instance()
99
-    {
100
-        // check if class object is instantiated
101
-        if (! self::$_instance instanceof EE_Encryption) {
102
-            self::$_instance = new self();
103
-        }
104
-        return self::$_instance;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * get encryption key
111
-     *
112
-     * @return string
113
-     */
114
-    public function get_encryption_key()
115
-    {
116
-        // if encryption key has not been set
117
-        if (empty($this->_encryption_key)) {
118
-            // retrieve encryption_key from db
119
-            $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
120
-            // WHAT?? No encryption_key in the db ??
121
-            if ($this->_encryption_key === '') {
122
-                // let's make one. And md5 it to make it just the right size for a key
123
-                $new_key = md5($this->generate_random_string());
124
-                // now save it to the db for later
125
-                add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
126
-                // here's the key - FINALLY !
127
-                $this->_encryption_key = $new_key;
128
-            }
129
-        }
130
-        return $this->_encryption_key;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * encrypts data
137
-     *
138
-     * @param string $text_string - the text to be encrypted
139
-     * @return string
140
-     * @throws RuntimeException
141
-     */
142
-    public function encrypt($text_string = '')
143
-    {
144
-        // you give me nothing??? GET OUT !
145
-        if (empty($text_string)) {
146
-            return $text_string;
147
-        }
148
-        if ($this->_use_openssl_encrypt) {
149
-            $encrypted_text = $this->openssl_encrypt($text_string);
150
-        } else {
151
-            $encrypted_text = $this->acme_encrypt($text_string);
152
-        }
153
-        return $encrypted_text;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * decrypts data
160
-     *
161
-     * @param string $encrypted_text - the text to be decrypted
162
-     * @return string
163
-     * @throws RuntimeException
164
-     */
165
-    public function decrypt($encrypted_text = '')
166
-    {
167
-        // you give me nothing??? GET OUT !
168
-        if (empty($encrypted_text)) {
169
-            return $encrypted_text;
170
-        }
171
-        // if PHP's mcrypt functions are installed then we'll use them
172
-        if ($this->_use_openssl_encrypt) {
173
-            $decrypted_text = $this->openssl_decrypt($encrypted_text);
174
-        } else {
175
-            $decrypted_text = $this->acme_decrypt($encrypted_text);
176
-        }
177
-        return $decrypted_text;
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * encodes string with PHP's base64 encoding
184
-     *
185
-     * @see http://php.net/manual/en/function.base64-encode.php
186
-     * @param string $text_string the text to be encoded
187
-     * @return string
188
-     */
189
-    public function base64_string_encode($text_string = '')
190
-    {
191
-        // you give me nothing??? GET OUT !
192
-        if (empty($text_string) || ! $this->_use_base64_encode) {
193
-            return $text_string;
194
-        }
195
-        // encode
196
-        return base64_encode($text_string);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * decodes string that has been encoded with PHP's base64 encoding
203
-     *
204
-     * @see http://php.net/manual/en/function.base64-encode.php
205
-     * @param string $encoded_string the text to be decoded
206
-     * @return string
207
-     */
208
-    public function base64_string_decode($encoded_string = '')
209
-    {
210
-        // you give me nothing??? GET OUT !
211
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
212
-            return $encoded_string;
213
-        }
214
-        // decode
215
-        return base64_decode($encoded_string);
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * encodes  url string with PHP's base64 encoding
222
-     *
223
-     * @see http://php.net/manual/en/function.base64-encode.php
224
-     * @param string $text_string the text to be encoded
225
-     * @return string
226
-     */
227
-    public function base64_url_encode($text_string = '')
228
-    {
229
-        // you give me nothing??? GET OUT !
230
-        if (empty($text_string) || ! $this->_use_base64_encode) {
231
-            return $text_string;
232
-        }
233
-        // encode
234
-        $encoded_string = base64_encode($text_string);
235
-        // remove chars to make encoding more URL friendly
236
-        return strtr($encoded_string, '+/=', '-_,');
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * decodes  url string that has been encoded with PHP's base64 encoding
243
-     *
244
-     * @see http://php.net/manual/en/function.base64-encode.php
245
-     * @param string $encoded_string the text to be decoded
246
-     * @return string
247
-     */
248
-    public function base64_url_decode($encoded_string = '')
249
-    {
250
-        // you give me nothing??? GET OUT !
251
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
252
-            return $encoded_string;
253
-        }
254
-        // replace previously removed characters
255
-        $encoded_string = strtr($encoded_string, '-_,', '+/=');
256
-        // decode
257
-        return base64_decode($encoded_string);
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * encrypts data using PHP's openssl functions
264
-     *
265
-     * @param string $text_string the text to be encrypted
266
-     * @return string
267
-     * @throws RuntimeException
268
-     */
269
-    protected function openssl_encrypt($text_string = '')
270
-    {
271
-        // you give me nothing??? GET OUT !
272
-        if (empty($text_string)) {
273
-            return $text_string;
274
-        }
275
-        // get initialization vector size
276
-        $iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD);
277
-        // generate initialization vector
278
-        $iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
279
-        if ($iv === false || $is_strong === false) {
280
-            throw new RuntimeException(
281
-                esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
282
-            );
283
-        }
284
-        // encrypt it
285
-        $encrypted_text = openssl_encrypt(
286
-            $text_string,
287
-            EE_Encryption::OPENSSL_CIPHER_METHOD,
288
-            openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
289
-            0,
290
-            $iv
291
-        );
292
-        // append the initialization vector
293
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
294
-        // trim and maybe encode
295
-        return $this->_use_base64_encode
296
-            ? trim(base64_encode($encrypted_text))
297
-            : trim($encrypted_text);
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     * decrypts data that has been encrypted with PHP's openssl functions
304
-     *
305
-     * @param string $encrypted_text the text to be decrypted
306
-     * @return string
307
-     * @throws RuntimeException
308
-     */
309
-    protected function openssl_decrypt($encrypted_text = '')
310
-    {
311
-        // you give me nothing??? GET OUT !
312
-        if (empty($encrypted_text)) {
313
-            return $encrypted_text;
314
-        }
315
-        // decode
316
-        $encrypted_text = $this->valid_base_64($encrypted_text)
317
-            ? base64_decode($encrypted_text)
318
-            : $encrypted_text;
319
-        $encrypted_components = explode(
320
-            EE_Encryption::OPENSSL_IV_DELIMITER,
321
-            $encrypted_text,
322
-            2
323
-        );
324
-        // check that iv exists, and if not, maybe text was encoded using mcrypt?
325
-        if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
326
-            return $this->m_decrypt($encrypted_text);
327
-        }
328
-        // decrypt it
329
-        $decrypted_text = openssl_decrypt(
330
-            $encrypted_components[0],
331
-            EE_Encryption::OPENSSL_CIPHER_METHOD,
332
-            openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
333
-            0,
334
-            $encrypted_components[1]
335
-        );
336
-        $decrypted_text = trim($decrypted_text);
337
-        return $decrypted_text;
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * encrypts data for acme servers that didn't bother to install PHP mcrypt
344
-     *
345
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
346
-     * @param string $text_string the text to be decrypted
347
-     * @return string
348
-     */
349
-    protected function acme_encrypt($text_string = '')
350
-    {
351
-        // you give me nothing??? GET OUT !
352
-        if (empty($text_string)) {
353
-            return $text_string;
354
-        }
355
-        $key_bits = str_split(
356
-            str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)
357
-        );
358
-        $string_bits = str_split($text_string);
359
-        foreach ($string_bits as $k => $v) {
360
-            $temp = ord($v) + ord($key_bits[$k]);
361
-            $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
362
-        }
363
-        $encrypted_text = implode('', $string_bits);
364
-        $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
365
-        return $this->_use_base64_encode
366
-            ? base64_encode($encrypted_text)
367
-            : $encrypted_text;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * decrypts data for acme servers that didn't bother to install PHP mcrypt
374
-     *
375
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
376
-     * @param string $encrypted_text the text to be decrypted
377
-     * @return string
378
-     */
379
-    protected function acme_decrypt($encrypted_text = '')
380
-    {
381
-        // you give me nothing??? GET OUT !
382
-        if (empty($encrypted_text)) {
383
-            return $encrypted_text;
384
-        }
385
-        // decode the data ?
386
-        $encrypted_text = $this->valid_base_64($encrypted_text)
387
-            ? base64_decode($encrypted_text)
388
-            : $encrypted_text;
389
-        if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) {
390
-            return $this->m_decrypt($encrypted_text);
391
-        }
392
-        $encrypted_text = substr($encrypted_text, 0, -4);
393
-        $key_bits = str_split(
394
-            str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)
395
-        );
396
-        $string_bits = str_split($encrypted_text);
397
-        foreach ($string_bits as $k => $v) {
398
-            $temp = ord($v) - ord($key_bits[$k]);
399
-            $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
400
-        }
401
-        return implode('', $string_bits);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
408
-     * @param $string
409
-     * @return bool
410
-     */
411
-    protected function valid_base_64($string)
412
-    {
413
-        // ensure data is a string
414
-        if (! is_string($string) || ! $this->_use_base64_encode) {
415
-            return false;
416
-        }
417
-        $decoded = base64_decode($string, true);
418
-        // Check if there is no invalid character in string
419
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
420
-            return false;
421
-        }
422
-        // Decode the string in strict mode and send the response
423
-        if (! base64_decode($string, true)) {
424
-            return false;
425
-        }
426
-        // Encode and compare it to original one
427
-        return base64_encode($decoded) === $string;
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * generate random string
434
-     *
435
-     * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
436
-     * @param int $length number of characters for random string
437
-     * @return string
438
-     */
439
-    public function generate_random_string($length = 40)
440
-    {
441
-        $iterations = ceil($length / 40);
442
-        $random_string = '';
443
-        for ($i = 0; $i < $iterations; $i++) {
444
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
445
-        }
446
-        $random_string = substr($random_string, 0, $length);
447
-        return $random_string;
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     * encrypts data using PHP's mcrypt functions
454
-     *
455
-     * @deprecated 4.9.39
456
-     * @param string $text_string
457
-     * @internal   param $string - the text to be encrypted
458
-     * @return string
459
-     * @throws RuntimeException
460
-     */
461
-    protected function m_encrypt($text_string = '')
462
-    {
463
-        // you give me nothing??? GET OUT !
464
-        if (empty($text_string)) {
465
-            return $text_string;
466
-        }
467
-        // get the initialization vector size
468
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
469
-        // initialization vector
470
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
471
-        if ($iv === false) {
472
-            throw new RuntimeException(
473
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
474
-            );
475
-        }
476
-        // encrypt it
477
-        $encrypted_text = mcrypt_encrypt(
478
-            MCRYPT_RIJNDAEL_256,
479
-            $this->get_encryption_key(),
480
-            $text_string,
481
-            MCRYPT_MODE_ECB,
482
-            $iv
483
-        );
484
-        // trim and maybe encode
485
-        return $this->_use_base64_encode
486
-            ? trim(base64_encode($encrypted_text))
487
-            : trim($encrypted_text);
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * decrypts data that has been encrypted with PHP's mcrypt functions
494
-     *
495
-     * @deprecated 4.9.39
496
-     * @param string $encrypted_text the text to be decrypted
497
-     * @return string
498
-     * @throws RuntimeException
499
-     */
500
-    protected function m_decrypt($encrypted_text = '')
501
-    {
502
-        // you give me nothing??? GET OUT !
503
-        if (empty($encrypted_text)) {
504
-            return $encrypted_text;
505
-        }
506
-        // decode
507
-        $encrypted_text = $this->valid_base_64($encrypted_text)
508
-            ? base64_decode($encrypted_text)
509
-            : $encrypted_text;
510
-        // get the initialization vector size
511
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
512
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
513
-        if ($iv === false) {
514
-            throw new RuntimeException(
515
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
516
-            );
517
-        }
518
-        // decrypt it
519
-        $decrypted_text = mcrypt_decrypt(
520
-            MCRYPT_RIJNDAEL_256,
521
-            $this->get_encryption_key(),
522
-            $encrypted_text,
523
-            MCRYPT_MODE_ECB,
524
-            $iv
525
-        );
526
-        $decrypted_text = trim($decrypted_text);
527
-        return $decrypted_text;
528
-    }
19
+	/**
20
+	 * key used for saving the encryption key to the wp_options table
21
+	 */
22
+	const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
+
24
+	/**
25
+	 * the OPENSSL cipher method used
26
+	 */
27
+	const OPENSSL_CIPHER_METHOD = 'aes-256-ctr';
28
+
29
+	/**
30
+	 * the OPENSSL digest method used
31
+	 */
32
+	const OPENSSL_DIGEST_METHOD = 'sha512';
33
+
34
+	/**
35
+	 * separates the encrypted text from the initialization vector
36
+	 */
37
+	const OPENSSL_IV_DELIMITER = ':iv:';
38
+
39
+	/**
40
+	 * appended to text encrypted using the acme encryption
41
+	 */
42
+	const ACME_ENCRYPTION_FLAG = '::ae';
43
+
44
+
45
+
46
+	/**
47
+	 * instance of the EE_Encryption object
48
+	 */
49
+	protected static $_instance;
50
+
51
+	/**
52
+	 * @var string $_encryption_key
53
+	 */
54
+	protected $_encryption_key;
55
+
56
+	/**
57
+	 * @var boolean $_use_openssl_encrypt
58
+	 */
59
+	protected $_use_openssl_encrypt = false;
60
+
61
+	/**
62
+	 * @var boolean $_use_mcrypt
63
+	 */
64
+	protected $_use_mcrypt = false;
65
+
66
+	/**
67
+	 * @var boolean $_use_base64_encode
68
+	 */
69
+	protected $_use_base64_encode = false;
70
+
71
+
72
+
73
+	/**
74
+	 * protected constructor to prevent direct creation
75
+	 */
76
+	protected function __construct()
77
+	{
78
+		if (! defined('ESPRESSO_ENCRYPT')) {
79
+			define('ESPRESSO_ENCRYPT', true);
80
+		}
81
+		if (extension_loaded('openssl')) {
82
+			$this->_use_openssl_encrypt = true;
83
+		} else if (extension_loaded('mcrypt')) {
84
+			$this->_use_mcrypt = true;
85
+		}
86
+		if (function_exists('base64_encode')) {
87
+			$this->_use_base64_encode = true;
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * singleton method used to instantiate class object
95
+	 *
96
+	 * @return EE_Encryption
97
+	 */
98
+	public static function instance()
99
+	{
100
+		// check if class object is instantiated
101
+		if (! self::$_instance instanceof EE_Encryption) {
102
+			self::$_instance = new self();
103
+		}
104
+		return self::$_instance;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * get encryption key
111
+	 *
112
+	 * @return string
113
+	 */
114
+	public function get_encryption_key()
115
+	{
116
+		// if encryption key has not been set
117
+		if (empty($this->_encryption_key)) {
118
+			// retrieve encryption_key from db
119
+			$this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
120
+			// WHAT?? No encryption_key in the db ??
121
+			if ($this->_encryption_key === '') {
122
+				// let's make one. And md5 it to make it just the right size for a key
123
+				$new_key = md5($this->generate_random_string());
124
+				// now save it to the db for later
125
+				add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
126
+				// here's the key - FINALLY !
127
+				$this->_encryption_key = $new_key;
128
+			}
129
+		}
130
+		return $this->_encryption_key;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * encrypts data
137
+	 *
138
+	 * @param string $text_string - the text to be encrypted
139
+	 * @return string
140
+	 * @throws RuntimeException
141
+	 */
142
+	public function encrypt($text_string = '')
143
+	{
144
+		// you give me nothing??? GET OUT !
145
+		if (empty($text_string)) {
146
+			return $text_string;
147
+		}
148
+		if ($this->_use_openssl_encrypt) {
149
+			$encrypted_text = $this->openssl_encrypt($text_string);
150
+		} else {
151
+			$encrypted_text = $this->acme_encrypt($text_string);
152
+		}
153
+		return $encrypted_text;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * decrypts data
160
+	 *
161
+	 * @param string $encrypted_text - the text to be decrypted
162
+	 * @return string
163
+	 * @throws RuntimeException
164
+	 */
165
+	public function decrypt($encrypted_text = '')
166
+	{
167
+		// you give me nothing??? GET OUT !
168
+		if (empty($encrypted_text)) {
169
+			return $encrypted_text;
170
+		}
171
+		// if PHP's mcrypt functions are installed then we'll use them
172
+		if ($this->_use_openssl_encrypt) {
173
+			$decrypted_text = $this->openssl_decrypt($encrypted_text);
174
+		} else {
175
+			$decrypted_text = $this->acme_decrypt($encrypted_text);
176
+		}
177
+		return $decrypted_text;
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * encodes string with PHP's base64 encoding
184
+	 *
185
+	 * @see http://php.net/manual/en/function.base64-encode.php
186
+	 * @param string $text_string the text to be encoded
187
+	 * @return string
188
+	 */
189
+	public function base64_string_encode($text_string = '')
190
+	{
191
+		// you give me nothing??? GET OUT !
192
+		if (empty($text_string) || ! $this->_use_base64_encode) {
193
+			return $text_string;
194
+		}
195
+		// encode
196
+		return base64_encode($text_string);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * decodes string that has been encoded with PHP's base64 encoding
203
+	 *
204
+	 * @see http://php.net/manual/en/function.base64-encode.php
205
+	 * @param string $encoded_string the text to be decoded
206
+	 * @return string
207
+	 */
208
+	public function base64_string_decode($encoded_string = '')
209
+	{
210
+		// you give me nothing??? GET OUT !
211
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
212
+			return $encoded_string;
213
+		}
214
+		// decode
215
+		return base64_decode($encoded_string);
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * encodes  url string with PHP's base64 encoding
222
+	 *
223
+	 * @see http://php.net/manual/en/function.base64-encode.php
224
+	 * @param string $text_string the text to be encoded
225
+	 * @return string
226
+	 */
227
+	public function base64_url_encode($text_string = '')
228
+	{
229
+		// you give me nothing??? GET OUT !
230
+		if (empty($text_string) || ! $this->_use_base64_encode) {
231
+			return $text_string;
232
+		}
233
+		// encode
234
+		$encoded_string = base64_encode($text_string);
235
+		// remove chars to make encoding more URL friendly
236
+		return strtr($encoded_string, '+/=', '-_,');
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * decodes  url string that has been encoded with PHP's base64 encoding
243
+	 *
244
+	 * @see http://php.net/manual/en/function.base64-encode.php
245
+	 * @param string $encoded_string the text to be decoded
246
+	 * @return string
247
+	 */
248
+	public function base64_url_decode($encoded_string = '')
249
+	{
250
+		// you give me nothing??? GET OUT !
251
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
252
+			return $encoded_string;
253
+		}
254
+		// replace previously removed characters
255
+		$encoded_string = strtr($encoded_string, '-_,', '+/=');
256
+		// decode
257
+		return base64_decode($encoded_string);
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * encrypts data using PHP's openssl functions
264
+	 *
265
+	 * @param string $text_string the text to be encrypted
266
+	 * @return string
267
+	 * @throws RuntimeException
268
+	 */
269
+	protected function openssl_encrypt($text_string = '')
270
+	{
271
+		// you give me nothing??? GET OUT !
272
+		if (empty($text_string)) {
273
+			return $text_string;
274
+		}
275
+		// get initialization vector size
276
+		$iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD);
277
+		// generate initialization vector
278
+		$iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
279
+		if ($iv === false || $is_strong === false) {
280
+			throw new RuntimeException(
281
+				esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
282
+			);
283
+		}
284
+		// encrypt it
285
+		$encrypted_text = openssl_encrypt(
286
+			$text_string,
287
+			EE_Encryption::OPENSSL_CIPHER_METHOD,
288
+			openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
289
+			0,
290
+			$iv
291
+		);
292
+		// append the initialization vector
293
+		$encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
294
+		// trim and maybe encode
295
+		return $this->_use_base64_encode
296
+			? trim(base64_encode($encrypted_text))
297
+			: trim($encrypted_text);
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 * decrypts data that has been encrypted with PHP's openssl functions
304
+	 *
305
+	 * @param string $encrypted_text the text to be decrypted
306
+	 * @return string
307
+	 * @throws RuntimeException
308
+	 */
309
+	protected function openssl_decrypt($encrypted_text = '')
310
+	{
311
+		// you give me nothing??? GET OUT !
312
+		if (empty($encrypted_text)) {
313
+			return $encrypted_text;
314
+		}
315
+		// decode
316
+		$encrypted_text = $this->valid_base_64($encrypted_text)
317
+			? base64_decode($encrypted_text)
318
+			: $encrypted_text;
319
+		$encrypted_components = explode(
320
+			EE_Encryption::OPENSSL_IV_DELIMITER,
321
+			$encrypted_text,
322
+			2
323
+		);
324
+		// check that iv exists, and if not, maybe text was encoded using mcrypt?
325
+		if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
326
+			return $this->m_decrypt($encrypted_text);
327
+		}
328
+		// decrypt it
329
+		$decrypted_text = openssl_decrypt(
330
+			$encrypted_components[0],
331
+			EE_Encryption::OPENSSL_CIPHER_METHOD,
332
+			openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
333
+			0,
334
+			$encrypted_components[1]
335
+		);
336
+		$decrypted_text = trim($decrypted_text);
337
+		return $decrypted_text;
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * encrypts data for acme servers that didn't bother to install PHP mcrypt
344
+	 *
345
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
346
+	 * @param string $text_string the text to be decrypted
347
+	 * @return string
348
+	 */
349
+	protected function acme_encrypt($text_string = '')
350
+	{
351
+		// you give me nothing??? GET OUT !
352
+		if (empty($text_string)) {
353
+			return $text_string;
354
+		}
355
+		$key_bits = str_split(
356
+			str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)
357
+		);
358
+		$string_bits = str_split($text_string);
359
+		foreach ($string_bits as $k => $v) {
360
+			$temp = ord($v) + ord($key_bits[$k]);
361
+			$string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
362
+		}
363
+		$encrypted_text = implode('', $string_bits);
364
+		$encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
365
+		return $this->_use_base64_encode
366
+			? base64_encode($encrypted_text)
367
+			: $encrypted_text;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * decrypts data for acme servers that didn't bother to install PHP mcrypt
374
+	 *
375
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
376
+	 * @param string $encrypted_text the text to be decrypted
377
+	 * @return string
378
+	 */
379
+	protected function acme_decrypt($encrypted_text = '')
380
+	{
381
+		// you give me nothing??? GET OUT !
382
+		if (empty($encrypted_text)) {
383
+			return $encrypted_text;
384
+		}
385
+		// decode the data ?
386
+		$encrypted_text = $this->valid_base_64($encrypted_text)
387
+			? base64_decode($encrypted_text)
388
+			: $encrypted_text;
389
+		if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) {
390
+			return $this->m_decrypt($encrypted_text);
391
+		}
392
+		$encrypted_text = substr($encrypted_text, 0, -4);
393
+		$key_bits = str_split(
394
+			str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)
395
+		);
396
+		$string_bits = str_split($encrypted_text);
397
+		foreach ($string_bits as $k => $v) {
398
+			$temp = ord($v) - ord($key_bits[$k]);
399
+			$string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
400
+		}
401
+		return implode('', $string_bits);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
408
+	 * @param $string
409
+	 * @return bool
410
+	 */
411
+	protected function valid_base_64($string)
412
+	{
413
+		// ensure data is a string
414
+		if (! is_string($string) || ! $this->_use_base64_encode) {
415
+			return false;
416
+		}
417
+		$decoded = base64_decode($string, true);
418
+		// Check if there is no invalid character in string
419
+		if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
420
+			return false;
421
+		}
422
+		// Decode the string in strict mode and send the response
423
+		if (! base64_decode($string, true)) {
424
+			return false;
425
+		}
426
+		// Encode and compare it to original one
427
+		return base64_encode($decoded) === $string;
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * generate random string
434
+	 *
435
+	 * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
436
+	 * @param int $length number of characters for random string
437
+	 * @return string
438
+	 */
439
+	public function generate_random_string($length = 40)
440
+	{
441
+		$iterations = ceil($length / 40);
442
+		$random_string = '';
443
+		for ($i = 0; $i < $iterations; $i++) {
444
+			$random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
445
+		}
446
+		$random_string = substr($random_string, 0, $length);
447
+		return $random_string;
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 * encrypts data using PHP's mcrypt functions
454
+	 *
455
+	 * @deprecated 4.9.39
456
+	 * @param string $text_string
457
+	 * @internal   param $string - the text to be encrypted
458
+	 * @return string
459
+	 * @throws RuntimeException
460
+	 */
461
+	protected function m_encrypt($text_string = '')
462
+	{
463
+		// you give me nothing??? GET OUT !
464
+		if (empty($text_string)) {
465
+			return $text_string;
466
+		}
467
+		// get the initialization vector size
468
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
469
+		// initialization vector
470
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
471
+		if ($iv === false) {
472
+			throw new RuntimeException(
473
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
474
+			);
475
+		}
476
+		// encrypt it
477
+		$encrypted_text = mcrypt_encrypt(
478
+			MCRYPT_RIJNDAEL_256,
479
+			$this->get_encryption_key(),
480
+			$text_string,
481
+			MCRYPT_MODE_ECB,
482
+			$iv
483
+		);
484
+		// trim and maybe encode
485
+		return $this->_use_base64_encode
486
+			? trim(base64_encode($encrypted_text))
487
+			: trim($encrypted_text);
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * decrypts data that has been encrypted with PHP's mcrypt functions
494
+	 *
495
+	 * @deprecated 4.9.39
496
+	 * @param string $encrypted_text the text to be decrypted
497
+	 * @return string
498
+	 * @throws RuntimeException
499
+	 */
500
+	protected function m_decrypt($encrypted_text = '')
501
+	{
502
+		// you give me nothing??? GET OUT !
503
+		if (empty($encrypted_text)) {
504
+			return $encrypted_text;
505
+		}
506
+		// decode
507
+		$encrypted_text = $this->valid_base_64($encrypted_text)
508
+			? base64_decode($encrypted_text)
509
+			: $encrypted_text;
510
+		// get the initialization vector size
511
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
512
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
513
+		if ($iv === false) {
514
+			throw new RuntimeException(
515
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
516
+			);
517
+		}
518
+		// decrypt it
519
+		$decrypted_text = mcrypt_decrypt(
520
+			MCRYPT_RIJNDAEL_256,
521
+			$this->get_encryption_key(),
522
+			$encrypted_text,
523
+			MCRYPT_MODE_ECB,
524
+			$iv
525
+		);
526
+		$decrypted_text = trim($decrypted_text);
527
+		return $decrypted_text;
528
+	}
529 529
 
530 530
 }
531 531
 /* End of file EE_Encryption.class.php */
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php use EventEspresso\core\interfaces\InterminableInterface;
1
+<?php 
2 2
 
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
4 4
 
Please login to merge, or discard this patch.
modules/ticket_selector/templates/simple_ticket_selector.template.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@  discard block
 block discarded – undo
11 11
 <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>
12 12
 <?php
13 13
 if ( $ticket instanceof EE_Ticket ) {
14
-    do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
15
-    $ticket_description = $ticket->description();
16
-    $ticket_description .= ! empty( $ticket_description )
17
-        ? '<br />' . $ticket_status_display
18
-        : $ticket_status_display;
19
-    if (strpos( $ticket_description, '<div' ) === false) {
20
-        $ticket_description = "<p>{$ticket_description}</p>";
21
-    }
14
+	do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
15
+	$ticket_description = $ticket->description();
16
+	$ticket_description .= ! empty( $ticket_description )
17
+		? '<br />' . $ticket_status_display
18
+		: $ticket_status_display;
19
+	if (strpos( $ticket_description, '<div' ) === false) {
20
+		$ticket_description = "<p>{$ticket_description}</p>";
21
+	}
22 22
 ?>
23 23
 <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">
24 24
     <div class="no-tkt-slctr-ticket-content-dv">
@@ -28,6 +28,6 @@  discard block
 block discarded – undo
28 28
         <?php } ?>
29 29
     </div><!-- .no-tkt-slctr-ticket-content-dv -->
30 30
 <?php
31
-    do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
31
+	do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
32 32
 }
33 33
 ?>
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,24 +10,24 @@
 block discarded – undo
10 10
 <input type="hidden" name="tkt-slctr-qty-<?php echo $EVT_ID; ?>[]" value="1"/>
11 11
 <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>
12 12
 <?php
13
-if ( $ticket instanceof EE_Ticket ) {
14
-    do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
13
+if ($ticket instanceof EE_Ticket) {
14
+    do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event);
15 15
     $ticket_description = $ticket->description();
16
-    $ticket_description .= ! empty( $ticket_description )
17
-        ? '<br />' . $ticket_status_display
16
+    $ticket_description .= ! empty($ticket_description)
17
+        ? '<br />'.$ticket_status_display
18 18
         : $ticket_status_display;
19
-    if (strpos( $ticket_description, '<div' ) === false) {
19
+    if (strpos($ticket_description, '<div') === false) {
20 20
         $ticket_description = "<p>{$ticket_description}</p>";
21 21
     }
22 22
 ?>
23 23
 <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">
24 24
     <div class="no-tkt-slctr-ticket-content-dv">
25 25
         <h5><?php echo $ticket->name(); ?></h5>
26
-        <?php if ( ! empty( $ticket_description ) ) { ?>
26
+        <?php if ( ! empty($ticket_description)) { ?>
27 27
         <?php echo $ticket_description; ?>
28 28
         <?php } ?>
29 29
     </div><!-- .no-tkt-slctr-ticket-content-dv -->
30 30
 <?php
31
-    do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
31
+    do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event);
32 32
 }
33 33
 ?>
Please login to merge, or discard this patch.
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Indentation   +672 added lines, -672 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 use WP_Post;
17 17
 
18 18
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
-    exit( 'No direct script access allowed' );
19
+	exit( 'No direct script access allowed' );
20 20
 }
21 21
 
22 22
 
@@ -33,680 +33,680 @@  discard block
 block discarded – undo
33 33
 class DisplayTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * event that ticket selector is being generated for
38
-     *
39
-     * @access protected
40
-     * @var EE_Event $event
41
-     */
42
-    protected $event;
43
-
44
-    /**
45
-     * Used to flag when the ticket selector is being called from an external iframe.
46
-     *
47
-     * @var bool $iframe
48
-     */
49
-    protected $iframe = false;
50
-
51
-    /**
52
-     * max attendees that can register for event at one time
53
-     *
54
-     * @var int $max_attendees
55
-     */
56
-    private $max_attendees = EE_INF;
57
-
58
-    /**
59
-     *@var string $date_format
60
-     */
61
-    private $date_format;
62
-
63
-    /**
64
-     *@var string $time_format
65
-     */
66
-    private $time_format;
67
-
68
-
69
-
70
-    /**
71
-     * DisplayTicketSelector constructor.
72
-     */
73
-    public function __construct()
74
-    {
75
-        $this->date_format = apply_filters(
76
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
77
-            get_option('date_format')
78
-        );
79
-        $this->time_format = apply_filters(
80
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
81
-            get_option('time_format')
82
-        );
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * @param boolean $iframe
89
-     */
90
-    public function setIframe( $iframe = true )
91
-    {
92
-        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
93
-    }
94
-
95
-
96
-    /**
97
-     * finds and sets the \EE_Event object for use throughout class
98
-     *
99
-     * @param mixed $event
100
-     * @return bool
101
-     * @throws EE_Error
102
-     */
103
-    protected function setEvent( $event = null )
104
-    {
105
-        if ( $event === null ) {
106
-            global $post;
107
-            $event = $post;
108
-        }
109
-        if ( $event instanceof EE_Event ) {
110
-            $this->event = $event;
111
-        } else if ( $event instanceof WP_Post ) {
112
-            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
113
-                $this->event = $event->EE_Event;
114
-            } else if ( $event->post_type === 'espresso_events' ) {
115
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
116
-                $this->event = $event->EE_Event;
117
-            }
118
-        } else {
119
-            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
-            $dev_msg = $user_msg . __(
121
-                    'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122
-                    'event_espresso'
123
-                );
124
-            EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
125
-            return false;
126
-        }
127
-        return true;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return int
134
-     */
135
-    public function getMaxAttendees()
136
-    {
137
-        return $this->max_attendees;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * @param int $max_attendees
144
-     */
145
-    public function setMaxAttendees($max_attendees)
146
-    {
147
-        $this->max_attendees = absint(
148
-            apply_filters(
149
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
150
-                $max_attendees
151
-            )
152
-        );
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * creates buttons for selecting number of attendees for an event
159
-     *
160
-     * @param WP_Post|int $event
161
-     * @param bool         $view_details
162
-     * @return string
163
-     * @throws EE_Error
164
-     */
165
-    public function display( $event = null, $view_details = false )
166
-    {
167
-        // reset filter for displaying submit button
168
-        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
169
-        // poke and prod incoming event till it tells us what it is
170
-        if ( ! $this->setEvent( $event ) ) {
171
-            return false;
172
-        }
173
-        // begin gathering template arguments by getting event status
174
-        $template_args = array( 'event_status' => $this->event->get_active_status() );
175
-        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
176
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
177
-        }
178
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
179
-        $this->setMaxAttendees($this->event->additional_limit());
180
-        if ($this->getMaxAttendees() < 1) {
181
-            return $this->ticketSalesClosedMessage();
182
-        }
183
-        // is the event expired ?
184
-        $template_args['event_is_expired'] = $this->event->is_expired();
185
-        if ( $template_args[ 'event_is_expired' ] ) {
186
-            return $this->expiredEventMessage();
187
-        }
188
-        // get all tickets for this event ordered by the datetime
189
-        $tickets = $this->getTickets();
190
-        if (count($tickets) < 1) {
191
-            return $this->noTicketAvailableMessage();
192
-        }
193
-        if (EED_Events_Archive::is_iframe()){
194
-            $this->setIframe();
195
-        }
196
-        // redirecting to another site for registration ??
197
-        $external_url = (string) $this->event->external_url();
198
-        // if redirecting to another site for registration, then we don't load the TS
199
-        $ticket_selector = $external_url
200
-            ? $this->externalEventRegistration()
201
-            : $this->loadTicketSelector($tickets,$template_args);
202
-        // now set up the form (but not for the admin)
203
-        $ticket_selector = ! is_admin()
204
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
205
-            : $ticket_selector;
206
-        // submit button and form close tag
207
-        $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
208
-        return $ticket_selector;
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * displayTicketSelector
215
-     * examines the event properties and determines whether a Ticket Selector should be displayed
216
-     *
217
-     * @param WP_Post|int $event
218
-     * @param string       $_event_active_status
219
-     * @param bool         $view_details
220
-     * @return bool
221
-     * @throws EE_Error
222
-     */
223
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
224
-    {
225
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
226
-        return ! is_admin()
227
-               && (
228
-                   ! $this->event->display_ticket_selector()
229
-                   || $view_details
230
-                   || post_password_required($event_post)
231
-                   || (
232
-                       $_event_active_status !== EE_Datetime::active
233
-                       && $_event_active_status !== EE_Datetime::upcoming
234
-                       && $_event_active_status !== EE_Datetime::sold_out
235
-                       && ! (
236
-                           $_event_active_status === EE_Datetime::inactive
237
-                           && is_user_logged_in()
238
-                       )
239
-                   )
240
-               );
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * noTicketAvailableMessage
247
-     * notice displayed if event is expired
248
-     *
249
-     * @return string
250
-     * @throws EE_Error
251
-     */
252
-    protected function expiredEventMessage()
253
-    {
254
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
255
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
256
-            'event_espresso'
257
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * noTicketAvailableMessage
264
-     * notice displayed if event has no more tickets available
265
-     *
266
-     * @return string
267
-     * @throws EE_Error
268
-     */
269
-    protected function noTicketAvailableMessage()
270
-    {
271
-        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
272
-        if (current_user_can('edit_post', $this->event->ID())) {
273
-            $no_ticket_available_msg .= sprintf(
274
-                esc_html__(
275
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
276
-                    'event_espresso'
277
-                ),
278
-                '<div class="ee-attention" style="text-align: left;"><b>',
279
-                '</b><br />',
280
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
281
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
282
-            );
283
-        }
284
-        return '
36
+	/**
37
+	 * event that ticket selector is being generated for
38
+	 *
39
+	 * @access protected
40
+	 * @var EE_Event $event
41
+	 */
42
+	protected $event;
43
+
44
+	/**
45
+	 * Used to flag when the ticket selector is being called from an external iframe.
46
+	 *
47
+	 * @var bool $iframe
48
+	 */
49
+	protected $iframe = false;
50
+
51
+	/**
52
+	 * max attendees that can register for event at one time
53
+	 *
54
+	 * @var int $max_attendees
55
+	 */
56
+	private $max_attendees = EE_INF;
57
+
58
+	/**
59
+	 *@var string $date_format
60
+	 */
61
+	private $date_format;
62
+
63
+	/**
64
+	 *@var string $time_format
65
+	 */
66
+	private $time_format;
67
+
68
+
69
+
70
+	/**
71
+	 * DisplayTicketSelector constructor.
72
+	 */
73
+	public function __construct()
74
+	{
75
+		$this->date_format = apply_filters(
76
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
77
+			get_option('date_format')
78
+		);
79
+		$this->time_format = apply_filters(
80
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
81
+			get_option('time_format')
82
+		);
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * @param boolean $iframe
89
+	 */
90
+	public function setIframe( $iframe = true )
91
+	{
92
+		$this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
93
+	}
94
+
95
+
96
+	/**
97
+	 * finds and sets the \EE_Event object for use throughout class
98
+	 *
99
+	 * @param mixed $event
100
+	 * @return bool
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function setEvent( $event = null )
104
+	{
105
+		if ( $event === null ) {
106
+			global $post;
107
+			$event = $post;
108
+		}
109
+		if ( $event instanceof EE_Event ) {
110
+			$this->event = $event;
111
+		} else if ( $event instanceof WP_Post ) {
112
+			if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
113
+				$this->event = $event->EE_Event;
114
+			} else if ( $event->post_type === 'espresso_events' ) {
115
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
116
+				$this->event = $event->EE_Event;
117
+			}
118
+		} else {
119
+			$user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
+			$dev_msg = $user_msg . __(
121
+					'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122
+					'event_espresso'
123
+				);
124
+			EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
125
+			return false;
126
+		}
127
+		return true;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return int
134
+	 */
135
+	public function getMaxAttendees()
136
+	{
137
+		return $this->max_attendees;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * @param int $max_attendees
144
+	 */
145
+	public function setMaxAttendees($max_attendees)
146
+	{
147
+		$this->max_attendees = absint(
148
+			apply_filters(
149
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
150
+				$max_attendees
151
+			)
152
+		);
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * creates buttons for selecting number of attendees for an event
159
+	 *
160
+	 * @param WP_Post|int $event
161
+	 * @param bool         $view_details
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 */
165
+	public function display( $event = null, $view_details = false )
166
+	{
167
+		// reset filter for displaying submit button
168
+		remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
169
+		// poke and prod incoming event till it tells us what it is
170
+		if ( ! $this->setEvent( $event ) ) {
171
+			return false;
172
+		}
173
+		// begin gathering template arguments by getting event status
174
+		$template_args = array( 'event_status' => $this->event->get_active_status() );
175
+		if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
176
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
177
+		}
178
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
179
+		$this->setMaxAttendees($this->event->additional_limit());
180
+		if ($this->getMaxAttendees() < 1) {
181
+			return $this->ticketSalesClosedMessage();
182
+		}
183
+		// is the event expired ?
184
+		$template_args['event_is_expired'] = $this->event->is_expired();
185
+		if ( $template_args[ 'event_is_expired' ] ) {
186
+			return $this->expiredEventMessage();
187
+		}
188
+		// get all tickets for this event ordered by the datetime
189
+		$tickets = $this->getTickets();
190
+		if (count($tickets) < 1) {
191
+			return $this->noTicketAvailableMessage();
192
+		}
193
+		if (EED_Events_Archive::is_iframe()){
194
+			$this->setIframe();
195
+		}
196
+		// redirecting to another site for registration ??
197
+		$external_url = (string) $this->event->external_url();
198
+		// if redirecting to another site for registration, then we don't load the TS
199
+		$ticket_selector = $external_url
200
+			? $this->externalEventRegistration()
201
+			: $this->loadTicketSelector($tickets,$template_args);
202
+		// now set up the form (but not for the admin)
203
+		$ticket_selector = ! is_admin()
204
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
205
+			: $ticket_selector;
206
+		// submit button and form close tag
207
+		$ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
208
+		return $ticket_selector;
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * displayTicketSelector
215
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
216
+	 *
217
+	 * @param WP_Post|int $event
218
+	 * @param string       $_event_active_status
219
+	 * @param bool         $view_details
220
+	 * @return bool
221
+	 * @throws EE_Error
222
+	 */
223
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
224
+	{
225
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
226
+		return ! is_admin()
227
+			   && (
228
+				   ! $this->event->display_ticket_selector()
229
+				   || $view_details
230
+				   || post_password_required($event_post)
231
+				   || (
232
+					   $_event_active_status !== EE_Datetime::active
233
+					   && $_event_active_status !== EE_Datetime::upcoming
234
+					   && $_event_active_status !== EE_Datetime::sold_out
235
+					   && ! (
236
+						   $_event_active_status === EE_Datetime::inactive
237
+						   && is_user_logged_in()
238
+					   )
239
+				   )
240
+			   );
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * noTicketAvailableMessage
247
+	 * notice displayed if event is expired
248
+	 *
249
+	 * @return string
250
+	 * @throws EE_Error
251
+	 */
252
+	protected function expiredEventMessage()
253
+	{
254
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
255
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
256
+			'event_espresso'
257
+		) . '</span></div><!-- .ee-event-expired-notice -->';
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * noTicketAvailableMessage
264
+	 * notice displayed if event has no more tickets available
265
+	 *
266
+	 * @return string
267
+	 * @throws EE_Error
268
+	 */
269
+	protected function noTicketAvailableMessage()
270
+	{
271
+		$no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
272
+		if (current_user_can('edit_post', $this->event->ID())) {
273
+			$no_ticket_available_msg .= sprintf(
274
+				esc_html__(
275
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
276
+					'event_espresso'
277
+				),
278
+				'<div class="ee-attention" style="text-align: left;"><b>',
279
+				'</b><br />',
280
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
281
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
282
+			);
283
+		}
284
+		return '
285 285
             <div class="ee-event-expired-notice">
286 286
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
287 287
             </div><!-- .ee-event-expired-notice -->';
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * ticketSalesClosed
294
-     * notice displayed if event ticket sales are turned off
295
-     *
296
-     * @return string
297
-     * @throws EE_Error
298
-     */
299
-    protected function ticketSalesClosedMessage()
300
-    {
301
-        $sales_closed_msg = esc_html__(
302
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
303
-            'event_espresso'
304
-        );
305
-        if (current_user_can('edit_post', $this->event->ID())) {
306
-            $sales_closed_msg .= sprintf(
307
-                esc_html__(
308
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
309
-                    'event_espresso'
310
-                ),
311
-                '<div class="ee-attention" style="text-align: left;"><b>',
312
-                '</b><br />',
313
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
314
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315
-            );
316
-        }
317
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * getTickets
324
-     *
325
-     * @return \EE_Base_Class[]|\EE_Ticket[]
326
-     * @throws EE_Error
327
-     */
328
-    protected function getTickets()
329
-    {
330
-        $ticket_query_args = array(
331
-            array('Datetime.EVT_ID' => $this->event->ID()),
332
-            'order_by' => array(
333
-                'TKT_order'              => 'ASC',
334
-                'TKT_required'           => 'DESC',
335
-                'TKT_start_date'         => 'ASC',
336
-                'TKT_end_date'           => 'ASC',
337
-                'Datetime.DTT_EVT_start' => 'DESC',
338
-            ),
339
-        );
340
-        if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
341
-            //use the correct applicable time query depending on what version of core is being run.
342
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
343
-                ? time()
344
-                : current_time('timestamp');
345
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
346
-        }
347
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * loadTicketSelector
354
-     * begins to assemble template arguments
355
-     * and decides whether to load a "simple" ticket selector, or the standard
356
-     *
357
-     * @param \EE_Ticket[] $tickets
358
-     * @param array $template_args
359
-     * @return string
360
-     * @throws EE_Error
361
-     */
362
-    protected function loadTicketSelector(array $tickets, array $template_args)
363
-    {
364
-        $template_args['event'] = $this->event;
365
-        $template_args['EVT_ID'] = $this->event->ID();
366
-        $template_args['event_is_expired'] = $this->event->is_expired();
367
-        $template_args['max_atndz'] = $this->getMaxAttendees();
368
-        $template_args['date_format'] = $this->date_format;
369
-        $template_args['time_format'] = $this->time_format;
370
-        /**
371
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
372
-         *
373
-         * @since 4.9.13
374
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
375
-         * @param int $EVT_ID The Event ID
376
-         */
377
-        $template_args['anchor_id'] = apply_filters(
378
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
-            '#tkt-slctr-tbl-' . $this->event->ID(),
380
-            $this->event->ID()
381
-        );
382
-        $template_args['tickets'] = $tickets;
383
-        $template_args['ticket_count'] = count($tickets);
384
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
385
-        return $ticket_selector instanceof TicketSelectorSimple
386
-            ? $ticket_selector
387
-            : new TicketSelectorStandard(
388
-                $this->event,
389
-                $tickets,
390
-                $this->getMaxAttendees(),
391
-                $template_args,
392
-                $this->date_format,
393
-                $this->time_format
394
-            );
395
-    }
396
-
397
-
398
-
399
-    /**
400
-     * simpleTicketSelector
401
-     * there's one ticket, and max attendees is set to one,
402
-     * so if the event is free, then this is a "simple" ticket selector
403
-     * a.k.a. "Dude Where's my Ticket Selector?"
404
-     *
405
-     * @param \EE_Ticket[] $tickets
406
-     * @param array  $template_args
407
-     * @return string
408
-     * @throws EE_Error
409
-     */
410
-    protected function simpleTicketSelector($tickets, array $template_args)
411
-    {
412
-        // if there is only ONE ticket with a max qty of ONE
413
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
414
-            return '';
415
-        }
416
-        /** @var \EE_Ticket $ticket */
417
-        $ticket = reset($tickets);
418
-        // if the ticket is free... then not much need for the ticket selector
419
-        if (
420
-            apply_filters(
421
-                'FHEE__ticket_selector_chart_template__hide_ticket_selector',
422
-                $ticket->is_free(),
423
-                $this->event->ID()
424
-            )
425
-        ) {
426
-            return new TicketSelectorSimple(
427
-                $this->event,
428
-                $ticket,
429
-                $this->getMaxAttendees(),
430
-                $template_args
431
-            );
432
-        }
433
-        return '';
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     * externalEventRegistration
440
-     *
441
-     * @return string
442
-     */
443
-    public function externalEventRegistration()
444
-    {
445
-        // if not we still need to trigger the display of the submit button
446
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
447
-        //display notice to admin that registration is external
448
-        return is_admin()
449
-            ? esc_html__(
450
-                'Registration is at an external URL for this event.',
451
-                'event_espresso'
452
-            )
453
-            : '';
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * formOpen
460
-     *
461
-     * @param        int    $ID
462
-     * @param        string $external_url
463
-     * @return        string
464
-     */
465
-    public function formOpen( $ID = 0, $external_url = '' )
466
-    {
467
-        // if redirecting, we don't need any anything else
468
-        if ( $external_url ) {
469
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
470
-            // open link in new window ?
471
-            $html .= apply_filters(
472
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
473
-                EED_Events_Archive::is_iframe()
474
-            )
475
-                ? ' target="_blank"'
476
-                : '';
477
-            $html .= '>';
478
-            $query_args = EEH_URL::get_query_string( $external_url );
479
-            foreach ( (array)$query_args as $query_arg => $value ) {
480
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
481
-            }
482
-            return $html;
483
-        }
484
-        // if there is no submit button, then don't start building a form
485
-        // because the "View Details" button will build its own form
486
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
487
-            return '';
488
-        }
489
-        $checkout_url = EEH_Event_View::event_link_url( $ID );
490
-        if ( ! $checkout_url ) {
491
-            EE_Error::add_error(
492
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
493
-                __FILE__,
494
-                __FUNCTION__,
495
-                __LINE__
496
-            );
497
-        }
498
-        // set no cache headers and constants
499
-        EE_System::do_not_cache();
500
-        $extra_params = $this->iframe ? ' target="_blank"' : '';
501
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
-        $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
503
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
504
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
505
-        return $html;
506
-    }
507
-
508
-
509
-
510
-    /**
511
-     * displaySubmitButton
512
-     *
513
-     * @param  string $external_url
514
-     * @return string
515
-     * @throws EE_Error
516
-     */
517
-    public function displaySubmitButton($external_url = '')
518
-    {
519
-        $html = '';
520
-        if ( ! is_admin()) {
521
-            // standard TS displayed with submit button, ie: "Register Now"
522
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
523
-                $html .= $this->displayRegisterNowButton();
524
-                $html .= empty($external_url)
525
-                    ? $this->ticketSelectorEndDiv()
526
-                    : $this->clearTicketSelector();
527
-                $html .= '<br/>' . $this->formClose();
528
-            } else if ($this->getMaxAttendees() === 1) {
529
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
530
-                if ($this->event->is_sold_out()) {
531
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
532
-                    $html .= apply_filters(
533
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
534
-                        sprintf(
535
-                            __(
536
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
537
-                                'event_espresso'
538
-                            ),
539
-                            '<p class="no-ticket-selector-msg clear-float">',
540
-                            $this->event->name(),
541
-                            '</p>',
542
-                            '<br />'
543
-                        ),
544
-                        $this->event
545
-                    );
546
-                    if (
547
-                        apply_filters(
548
-                            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
549
-                            false,
550
-                            $this->event
551
-                        )
552
-                    ) {
553
-                        $html .= $this->displayRegisterNowButton();
554
-                    }
555
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
556
-                    $html .=  $this->ticketSelectorEndDiv();
557
-                } else if (
558
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
559
-                    && ! is_single()
560
-                ) {
561
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
562
-                    // but no tickets are available, so display event's "View Details" button.
563
-                    // it is being viewed via somewhere other than a single post
564
-                    $html .= $this->displayViewDetailsButton(true);
565
-                } else {
566
-                    $html .= $this->ticketSelectorEndDiv();
567
-                }
568
-            } else if (is_archive()) {
569
-                // event list, no tickets available so display event's "View Details" button
570
-                $html .= $this->ticketSelectorEndDiv();
571
-                $html .= $this->displayViewDetailsButton();
572
-            } else {
573
-                if (
574
-                    apply_filters(
575
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
576
-                        false,
577
-                        $this->event
578
-                    )
579
-                ) {
580
-                    $html .= $this->displayRegisterNowButton();
581
-                }
582
-                // no submit or view details button, and no additional content
583
-                $html .= $this->ticketSelectorEndDiv();
584
-            }
585
-            if ( ! $this->iframe && ! is_archive()) {
586
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
587
-            }
588
-        }
589
-        return $html;
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * @return string
596
-     * @throws EE_Error
597
-     */
598
-    public function displayRegisterNowButton()
599
-    {
600
-        $btn_text = apply_filters(
601
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
602
-            __('Register Now', 'event_espresso'),
603
-            $this->event
604
-        );
605
-        $external_url = $this->event->external_url();
606
-        $html = EEH_HTML::div(
607
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
608
-        );
609
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
610
-        $html .= ' class="ticket-selector-submit-btn ';
611
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
612
-        $html .= ' type="submit" value="' . $btn_text . '" />';
613
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
614
-        $html .= apply_filters(
615
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
616
-            '',
617
-            $this->event
618
-        );
619
-        return $html;
620
-    }
621
-
622
-
623
-    /**
624
-     * displayViewDetailsButton
625
-     *
626
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
627
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
628
-     *                    either because they are sold out, expired, or not yet on sale.
629
-     *                    In this case, we need to close the form BEFORE adding any closing divs
630
-     * @return string
631
-     * @throws EE_Error
632
-     */
633
-    public function displayViewDetailsButton( $DWMTS = false )
634
-    {
635
-        if ( ! $this->event->get_permalink() ) {
636
-            EE_Error::add_error(
637
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
638
-                __FILE__, __FUNCTION__, __LINE__
639
-            );
640
-        }
641
-        $view_details_btn = '<form method="POST" action="';
642
-        $view_details_btn .= apply_filters(
643
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
644
-            $this->event->get_permalink(),
645
-            $this->event
646
-        );
647
-        $view_details_btn .= '"';
648
-        // open link in new window ?
649
-        $view_details_btn .= apply_filters(
650
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
651
-            EED_Events_Archive::is_iframe()
652
-        )
653
-            ? ' target="_blank"'
654
-            : '';
655
-        $view_details_btn .='>';
656
-        $btn_text = apply_filters(
657
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
658
-            esc_html__('View Details', 'event_espresso'),
659
-            $this->event
660
-        );
661
-        $view_details_btn .= '<input id="ticket-selector-submit-'
662
-                             . $this->event->ID()
663
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
664
-                             . $btn_text
665
-                             . '" />';
666
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
667
-        if ($DWMTS) {
668
-            $view_details_btn .= $this->formClose();
669
-            $view_details_btn .= $this->ticketSelectorEndDiv();
670
-            $view_details_btn .= '<br/>';
671
-        } else {
672
-            $view_details_btn .= $this->clearTicketSelector();
673
-            $view_details_btn .= '<br/>';
674
-            $view_details_btn .= $this->formClose();
675
-        }
676
-        return $view_details_btn;
677
-    }
678
-
679
-
680
-
681
-    /**
682
-     * @return string
683
-     */
684
-    public function ticketSelectorEndDiv()
685
-    {
686
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
687
-    }
688
-
689
-
690
-
691
-    /**
692
-     * @return string
693
-     */
694
-    public function clearTicketSelector()
695
-    {
696
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
697
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
698
-    }
699
-
700
-
701
-
702
-    /**
703
-     * @access        public
704
-     * @return        string
705
-     */
706
-    public function formClose()
707
-    {
708
-        return '</form>';
709
-    }
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * ticketSalesClosed
294
+	 * notice displayed if event ticket sales are turned off
295
+	 *
296
+	 * @return string
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function ticketSalesClosedMessage()
300
+	{
301
+		$sales_closed_msg = esc_html__(
302
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
303
+			'event_espresso'
304
+		);
305
+		if (current_user_can('edit_post', $this->event->ID())) {
306
+			$sales_closed_msg .= sprintf(
307
+				esc_html__(
308
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
309
+					'event_espresso'
310
+				),
311
+				'<div class="ee-attention" style="text-align: left;"><b>',
312
+				'</b><br />',
313
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
314
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315
+			);
316
+		}
317
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * getTickets
324
+	 *
325
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
326
+	 * @throws EE_Error
327
+	 */
328
+	protected function getTickets()
329
+	{
330
+		$ticket_query_args = array(
331
+			array('Datetime.EVT_ID' => $this->event->ID()),
332
+			'order_by' => array(
333
+				'TKT_order'              => 'ASC',
334
+				'TKT_required'           => 'DESC',
335
+				'TKT_start_date'         => 'ASC',
336
+				'TKT_end_date'           => 'ASC',
337
+				'Datetime.DTT_EVT_start' => 'DESC',
338
+			),
339
+		);
340
+		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
341
+			//use the correct applicable time query depending on what version of core is being run.
342
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
343
+				? time()
344
+				: current_time('timestamp');
345
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
346
+		}
347
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * loadTicketSelector
354
+	 * begins to assemble template arguments
355
+	 * and decides whether to load a "simple" ticket selector, or the standard
356
+	 *
357
+	 * @param \EE_Ticket[] $tickets
358
+	 * @param array $template_args
359
+	 * @return string
360
+	 * @throws EE_Error
361
+	 */
362
+	protected function loadTicketSelector(array $tickets, array $template_args)
363
+	{
364
+		$template_args['event'] = $this->event;
365
+		$template_args['EVT_ID'] = $this->event->ID();
366
+		$template_args['event_is_expired'] = $this->event->is_expired();
367
+		$template_args['max_atndz'] = $this->getMaxAttendees();
368
+		$template_args['date_format'] = $this->date_format;
369
+		$template_args['time_format'] = $this->time_format;
370
+		/**
371
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
372
+		 *
373
+		 * @since 4.9.13
374
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
375
+		 * @param int $EVT_ID The Event ID
376
+		 */
377
+		$template_args['anchor_id'] = apply_filters(
378
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
+			'#tkt-slctr-tbl-' . $this->event->ID(),
380
+			$this->event->ID()
381
+		);
382
+		$template_args['tickets'] = $tickets;
383
+		$template_args['ticket_count'] = count($tickets);
384
+		$ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
385
+		return $ticket_selector instanceof TicketSelectorSimple
386
+			? $ticket_selector
387
+			: new TicketSelectorStandard(
388
+				$this->event,
389
+				$tickets,
390
+				$this->getMaxAttendees(),
391
+				$template_args,
392
+				$this->date_format,
393
+				$this->time_format
394
+			);
395
+	}
396
+
397
+
398
+
399
+	/**
400
+	 * simpleTicketSelector
401
+	 * there's one ticket, and max attendees is set to one,
402
+	 * so if the event is free, then this is a "simple" ticket selector
403
+	 * a.k.a. "Dude Where's my Ticket Selector?"
404
+	 *
405
+	 * @param \EE_Ticket[] $tickets
406
+	 * @param array  $template_args
407
+	 * @return string
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function simpleTicketSelector($tickets, array $template_args)
411
+	{
412
+		// if there is only ONE ticket with a max qty of ONE
413
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
414
+			return '';
415
+		}
416
+		/** @var \EE_Ticket $ticket */
417
+		$ticket = reset($tickets);
418
+		// if the ticket is free... then not much need for the ticket selector
419
+		if (
420
+			apply_filters(
421
+				'FHEE__ticket_selector_chart_template__hide_ticket_selector',
422
+				$ticket->is_free(),
423
+				$this->event->ID()
424
+			)
425
+		) {
426
+			return new TicketSelectorSimple(
427
+				$this->event,
428
+				$ticket,
429
+				$this->getMaxAttendees(),
430
+				$template_args
431
+			);
432
+		}
433
+		return '';
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 * externalEventRegistration
440
+	 *
441
+	 * @return string
442
+	 */
443
+	public function externalEventRegistration()
444
+	{
445
+		// if not we still need to trigger the display of the submit button
446
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
447
+		//display notice to admin that registration is external
448
+		return is_admin()
449
+			? esc_html__(
450
+				'Registration is at an external URL for this event.',
451
+				'event_espresso'
452
+			)
453
+			: '';
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * formOpen
460
+	 *
461
+	 * @param        int    $ID
462
+	 * @param        string $external_url
463
+	 * @return        string
464
+	 */
465
+	public function formOpen( $ID = 0, $external_url = '' )
466
+	{
467
+		// if redirecting, we don't need any anything else
468
+		if ( $external_url ) {
469
+			$html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
470
+			// open link in new window ?
471
+			$html .= apply_filters(
472
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
473
+				EED_Events_Archive::is_iframe()
474
+			)
475
+				? ' target="_blank"'
476
+				: '';
477
+			$html .= '>';
478
+			$query_args = EEH_URL::get_query_string( $external_url );
479
+			foreach ( (array)$query_args as $query_arg => $value ) {
480
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
481
+			}
482
+			return $html;
483
+		}
484
+		// if there is no submit button, then don't start building a form
485
+		// because the "View Details" button will build its own form
486
+		if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
487
+			return '';
488
+		}
489
+		$checkout_url = EEH_Event_View::event_link_url( $ID );
490
+		if ( ! $checkout_url ) {
491
+			EE_Error::add_error(
492
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
493
+				__FILE__,
494
+				__FUNCTION__,
495
+				__LINE__
496
+			);
497
+		}
498
+		// set no cache headers and constants
499
+		EE_System::do_not_cache();
500
+		$extra_params = $this->iframe ? ' target="_blank"' : '';
501
+		$html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
+		$html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
503
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
504
+		$html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
505
+		return $html;
506
+	}
507
+
508
+
509
+
510
+	/**
511
+	 * displaySubmitButton
512
+	 *
513
+	 * @param  string $external_url
514
+	 * @return string
515
+	 * @throws EE_Error
516
+	 */
517
+	public function displaySubmitButton($external_url = '')
518
+	{
519
+		$html = '';
520
+		if ( ! is_admin()) {
521
+			// standard TS displayed with submit button, ie: "Register Now"
522
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
523
+				$html .= $this->displayRegisterNowButton();
524
+				$html .= empty($external_url)
525
+					? $this->ticketSelectorEndDiv()
526
+					: $this->clearTicketSelector();
527
+				$html .= '<br/>' . $this->formClose();
528
+			} else if ($this->getMaxAttendees() === 1) {
529
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
530
+				if ($this->event->is_sold_out()) {
531
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
532
+					$html .= apply_filters(
533
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
534
+						sprintf(
535
+							__(
536
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
537
+								'event_espresso'
538
+							),
539
+							'<p class="no-ticket-selector-msg clear-float">',
540
+							$this->event->name(),
541
+							'</p>',
542
+							'<br />'
543
+						),
544
+						$this->event
545
+					);
546
+					if (
547
+						apply_filters(
548
+							'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
549
+							false,
550
+							$this->event
551
+						)
552
+					) {
553
+						$html .= $this->displayRegisterNowButton();
554
+					}
555
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
556
+					$html .=  $this->ticketSelectorEndDiv();
557
+				} else if (
558
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
559
+					&& ! is_single()
560
+				) {
561
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
562
+					// but no tickets are available, so display event's "View Details" button.
563
+					// it is being viewed via somewhere other than a single post
564
+					$html .= $this->displayViewDetailsButton(true);
565
+				} else {
566
+					$html .= $this->ticketSelectorEndDiv();
567
+				}
568
+			} else if (is_archive()) {
569
+				// event list, no tickets available so display event's "View Details" button
570
+				$html .= $this->ticketSelectorEndDiv();
571
+				$html .= $this->displayViewDetailsButton();
572
+			} else {
573
+				if (
574
+					apply_filters(
575
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
576
+						false,
577
+						$this->event
578
+					)
579
+				) {
580
+					$html .= $this->displayRegisterNowButton();
581
+				}
582
+				// no submit or view details button, and no additional content
583
+				$html .= $this->ticketSelectorEndDiv();
584
+			}
585
+			if ( ! $this->iframe && ! is_archive()) {
586
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
587
+			}
588
+		}
589
+		return $html;
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * @return string
596
+	 * @throws EE_Error
597
+	 */
598
+	public function displayRegisterNowButton()
599
+	{
600
+		$btn_text = apply_filters(
601
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
602
+			__('Register Now', 'event_espresso'),
603
+			$this->event
604
+		);
605
+		$external_url = $this->event->external_url();
606
+		$html = EEH_HTML::div(
607
+			'', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
608
+		);
609
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
610
+		$html .= ' class="ticket-selector-submit-btn ';
611
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
612
+		$html .= ' type="submit" value="' . $btn_text . '" />';
613
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
614
+		$html .= apply_filters(
615
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
616
+			'',
617
+			$this->event
618
+		);
619
+		return $html;
620
+	}
621
+
622
+
623
+	/**
624
+	 * displayViewDetailsButton
625
+	 *
626
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
627
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
628
+	 *                    either because they are sold out, expired, or not yet on sale.
629
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
630
+	 * @return string
631
+	 * @throws EE_Error
632
+	 */
633
+	public function displayViewDetailsButton( $DWMTS = false )
634
+	{
635
+		if ( ! $this->event->get_permalink() ) {
636
+			EE_Error::add_error(
637
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
638
+				__FILE__, __FUNCTION__, __LINE__
639
+			);
640
+		}
641
+		$view_details_btn = '<form method="POST" action="';
642
+		$view_details_btn .= apply_filters(
643
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
644
+			$this->event->get_permalink(),
645
+			$this->event
646
+		);
647
+		$view_details_btn .= '"';
648
+		// open link in new window ?
649
+		$view_details_btn .= apply_filters(
650
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
651
+			EED_Events_Archive::is_iframe()
652
+		)
653
+			? ' target="_blank"'
654
+			: '';
655
+		$view_details_btn .='>';
656
+		$btn_text = apply_filters(
657
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
658
+			esc_html__('View Details', 'event_espresso'),
659
+			$this->event
660
+		);
661
+		$view_details_btn .= '<input id="ticket-selector-submit-'
662
+							 . $this->event->ID()
663
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
664
+							 . $btn_text
665
+							 . '" />';
666
+		$view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
667
+		if ($DWMTS) {
668
+			$view_details_btn .= $this->formClose();
669
+			$view_details_btn .= $this->ticketSelectorEndDiv();
670
+			$view_details_btn .= '<br/>';
671
+		} else {
672
+			$view_details_btn .= $this->clearTicketSelector();
673
+			$view_details_btn .= '<br/>';
674
+			$view_details_btn .= $this->formClose();
675
+		}
676
+		return $view_details_btn;
677
+	}
678
+
679
+
680
+
681
+	/**
682
+	 * @return string
683
+	 */
684
+	public function ticketSelectorEndDiv()
685
+	{
686
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
687
+	}
688
+
689
+
690
+
691
+	/**
692
+	 * @return string
693
+	 */
694
+	public function clearTicketSelector()
695
+	{
696
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
697
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
698
+	}
699
+
700
+
701
+
702
+	/**
703
+	 * @access        public
704
+	 * @return        string
705
+	 */
706
+	public function formClose()
707
+	{
708
+		return '</form>';
709
+	}
710 710
 
711 711
 
712 712
 
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 use EEM_Ticket;
16 16
 use WP_Post;
17 17
 
18
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
-    exit( 'No direct script access allowed' );
18
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
19
+    exit('No direct script access allowed');
20 20
 }
21 21
 
22 22
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
     /**
88 88
      * @param boolean $iframe
89 89
      */
90
-    public function setIframe( $iframe = true )
90
+    public function setIframe($iframe = true)
91 91
     {
92
-        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
92
+        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
93 93
     }
94 94
 
95 95
 
@@ -100,28 +100,28 @@  discard block
 block discarded – undo
100 100
      * @return bool
101 101
      * @throws EE_Error
102 102
      */
103
-    protected function setEvent( $event = null )
103
+    protected function setEvent($event = null)
104 104
     {
105
-        if ( $event === null ) {
105
+        if ($event === null) {
106 106
             global $post;
107 107
             $event = $post;
108 108
         }
109
-        if ( $event instanceof EE_Event ) {
109
+        if ($event instanceof EE_Event) {
110 110
             $this->event = $event;
111
-        } else if ( $event instanceof WP_Post ) {
112
-            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
111
+        } else if ($event instanceof WP_Post) {
112
+            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
113 113
                 $this->event = $event->EE_Event;
114
-            } else if ( $event->post_type === 'espresso_events' ) {
115
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
114
+            } else if ($event->post_type === 'espresso_events') {
115
+                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
116 116
                 $this->event = $event->EE_Event;
117 117
             }
118 118
         } else {
119
-            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
-            $dev_msg = $user_msg . __(
119
+            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
120
+            $dev_msg = $user_msg.__(
121 121
                     'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122 122
                     'event_espresso'
123 123
                 );
124
-            EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
124
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
125 125
             return false;
126 126
         }
127 127
         return true;
@@ -162,17 +162,17 @@  discard block
 block discarded – undo
162 162
      * @return string
163 163
      * @throws EE_Error
164 164
      */
165
-    public function display( $event = null, $view_details = false )
165
+    public function display($event = null, $view_details = false)
166 166
     {
167 167
         // reset filter for displaying submit button
168
-        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
168
+        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
169 169
         // poke and prod incoming event till it tells us what it is
170
-        if ( ! $this->setEvent( $event ) ) {
170
+        if ( ! $this->setEvent($event)) {
171 171
             return false;
172 172
         }
173 173
         // begin gathering template arguments by getting event status
174
-        $template_args = array( 'event_status' => $this->event->get_active_status() );
175
-        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
174
+        $template_args = array('event_status' => $this->event->get_active_status());
175
+        if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) {
176 176
             return ! is_single() ? $this->displayViewDetailsButton() : '';
177 177
         }
178 178
         // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         }
183 183
         // is the event expired ?
184 184
         $template_args['event_is_expired'] = $this->event->is_expired();
185
-        if ( $template_args[ 'event_is_expired' ] ) {
185
+        if ($template_args['event_is_expired']) {
186 186
             return $this->expiredEventMessage();
187 187
         }
188 188
         // get all tickets for this event ordered by the datetime
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         if (count($tickets) < 1) {
191 191
             return $this->noTicketAvailableMessage();
192 192
         }
193
-        if (EED_Events_Archive::is_iframe()){
193
+        if (EED_Events_Archive::is_iframe()) {
194 194
             $this->setIframe();
195 195
         }
196 196
         // redirecting to another site for registration ??
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
         // if redirecting to another site for registration, then we don't load the TS
199 199
         $ticket_selector = $external_url
200 200
             ? $this->externalEventRegistration()
201
-            : $this->loadTicketSelector($tickets,$template_args);
201
+            : $this->loadTicketSelector($tickets, $template_args);
202 202
         // now set up the form (but not for the admin)
203 203
         $ticket_selector = ! is_admin()
204
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
204
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
205 205
             : $ticket_selector;
206 206
         // submit button and form close tag
207 207
         $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
      */
252 252
     protected function expiredEventMessage()
253 253
     {
254
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
254
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
255 255
             'We\'re sorry, but all tickets sales have ended because the event is expired.',
256 256
             'event_espresso'
257
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
257
+        ).'</span></div><!-- .ee-event-expired-notice -->';
258 258
     }
259 259
 
260 260
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      */
269 269
     protected function noTicketAvailableMessage()
270 270
     {
271
-        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
271
+        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
272 272
         if (current_user_can('edit_post', $this->event->ID())) {
273 273
             $no_ticket_available_msg .= sprintf(
274 274
                 esc_html__(
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         }
284 284
         return '
285 285
             <div class="ee-event-expired-notice">
286
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
286
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
287 287
             </div><!-- .ee-event-expired-notice -->';
288 288
     }
289 289
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
                 '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315 315
             );
316 316
         }
317
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
317
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
318 318
     }
319 319
 
320 320
 
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
          */
377 377
         $template_args['anchor_id'] = apply_filters(
378 378
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
-            '#tkt-slctr-tbl-' . $this->event->ID(),
379
+            '#tkt-slctr-tbl-'.$this->event->ID(),
380 380
             $this->event->ID()
381 381
         );
382 382
         $template_args['tickets'] = $tickets;
383 383
         $template_args['ticket_count'] = count($tickets);
384
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
384
+        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
385 385
         return $ticket_selector instanceof TicketSelectorSimple
386 386
             ? $ticket_selector
387 387
             : new TicketSelectorStandard(
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
      * @param        string $external_url
463 463
      * @return        string
464 464
      */
465
-    public function formOpen( $ID = 0, $external_url = '' )
465
+    public function formOpen($ID = 0, $external_url = '')
466 466
     {
467 467
         // if redirecting, we don't need any anything else
468
-        if ( $external_url ) {
469
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
468
+        if ($external_url) {
469
+            $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"';
470 470
             // open link in new window ?
471 471
             $html .= apply_filters(
472 472
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
@@ -475,21 +475,21 @@  discard block
 block discarded – undo
475 475
                 ? ' target="_blank"'
476 476
                 : '';
477 477
             $html .= '>';
478
-            $query_args = EEH_URL::get_query_string( $external_url );
479
-            foreach ( (array)$query_args as $query_arg => $value ) {
480
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
478
+            $query_args = EEH_URL::get_query_string($external_url);
479
+            foreach ((array) $query_args as $query_arg => $value) {
480
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
481 481
             }
482 482
             return $html;
483 483
         }
484 484
         // if there is no submit button, then don't start building a form
485 485
         // because the "View Details" button will build its own form
486
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
486
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
487 487
             return '';
488 488
         }
489
-        $checkout_url = EEH_Event_View::event_link_url( $ID );
490
-        if ( ! $checkout_url ) {
489
+        $checkout_url = EEH_Event_View::event_link_url($ID);
490
+        if ( ! $checkout_url) {
491 491
             EE_Error::add_error(
492
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
492
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
493 493
                 __FILE__,
494 494
                 __FUNCTION__,
495 495
                 __LINE__
@@ -498,10 +498,10 @@  discard block
 block discarded – undo
498 498
         // set no cache headers and constants
499 499
         EE_System::do_not_cache();
500 500
         $extra_params = $this->iframe ? ' target="_blank"' : '';
501
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
-        $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
501
+        $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>';
502
+        $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_'.$ID, true, false);
503 503
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
504
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
504
+        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
505 505
         return $html;
506 506
     }
507 507
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
                 $html .= empty($external_url)
525 525
                     ? $this->ticketSelectorEndDiv()
526 526
                     : $this->clearTicketSelector();
527
-                $html .= '<br/>' . $this->formClose();
527
+                $html .= '<br/>'.$this->formClose();
528 528
             } else if ($this->getMaxAttendees() === 1) {
529 529
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
530 530
                 if ($this->event->is_sold_out()) {
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
                         $html .= $this->displayRegisterNowButton();
554 554
                     }
555 555
                     // sold out DWMTS event, no TS, no submit or view details button, but has additional content
556
-                    $html .=  $this->ticketSelectorEndDiv();
556
+                    $html .= $this->ticketSelectorEndDiv();
557 557
                 } else if (
558 558
                     apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
559 559
                     && ! is_single()
@@ -604,13 +604,13 @@  discard block
 block discarded – undo
604 604
         );
605 605
         $external_url = $this->event->external_url();
606 606
         $html = EEH_HTML::div(
607
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
607
+            '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap'
608 608
         );
609
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
609
+        $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
610 610
         $html .= ' class="ticket-selector-submit-btn ';
611 611
         $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
612
-        $html .= ' type="submit" value="' . $btn_text . '" />';
613
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
612
+        $html .= ' type="submit" value="'.$btn_text.'" />';
613
+        $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';
614 614
         $html .= apply_filters(
615 615
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
616 616
             '',
@@ -630,11 +630,11 @@  discard block
 block discarded – undo
630 630
      * @return string
631 631
      * @throws EE_Error
632 632
      */
633
-    public function displayViewDetailsButton( $DWMTS = false )
633
+    public function displayViewDetailsButton($DWMTS = false)
634 634
     {
635
-        if ( ! $this->event->get_permalink() ) {
635
+        if ( ! $this->event->get_permalink()) {
636 636
             EE_Error::add_error(
637
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
637
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
638 638
                 __FILE__, __FUNCTION__, __LINE__
639 639
             );
640 640
         }
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
         )
653 653
             ? ' target="_blank"'
654 654
             : '';
655
-        $view_details_btn .='>';
655
+        $view_details_btn .= '>';
656 656
         $btn_text = apply_filters(
657 657
             'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
658 658
             esc_html__('View Details', 'event_espresso'),
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
                              . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
664 664
                              . $btn_text
665 665
                              . '" />';
666
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
666
+        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
667 667
         if ($DWMTS) {
668 668
             $view_details_btn .= $this->formClose();
669 669
             $view_details_btn .= $this->ticketSelectorEndDiv();
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
      */
684 684
     public function ticketSelectorEndDiv()
685 685
     {
686
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
686
+        return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';
687 687
     }
688 688
 
689 689
 
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 
376 376
 
377 377
     /**
378
-     * @param mixed  $var
378
+     * @param string  $var
379 379
      * @param string $var_name
380 380
      * @param string $file
381 381
      * @param int    $line
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 
571 571
     /**
572 572
      * @deprecated 4.9.39.rc.034
573
-     * @param null $timer_name
573
+     * @param string $timer_name
574 574
      */
575 575
     public function start_timer($timer_name = null)
576 576
     {
Please login to merge, or discard this patch.
Indentation   +636 added lines, -636 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,626 +17,626 @@  discard block
 block discarded – undo
17 17
 class EEH_Debug_Tools
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EEH_Autoloader object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $_memory_usage_points = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EEH_Debug_Tools
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
44
-            self::$_instance = new self();
45
-        }
46
-        return self::$_instance;
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * private class constructor
53
-     */
54
-    private function __construct()
55
-    {
56
-        // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
59
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
-            // so we've moved it to our test folder so that it is not included with production releases
62
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
-        }
65
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
-        //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
-        // }
68
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
69
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    show_db_name
78
-     *
79
-     * @return void
80
-     */
81
-    public static function show_db_name()
82
-    {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
-                 . DB_NAME
86
-                 . '</p>';
87
-        }
88
-        if (EE_DEBUG) {
89
-            Benchmark::displayResults();
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    dump EE_Session object at bottom of page after everything else has happened
97
-     *
98
-     * @return void
99
-     */
100
-    public function espresso_session_footer_dump()
101
-    {
102
-        if (
103
-            (defined('WP_DEBUG') && WP_DEBUG)
104
-            && ! defined('DOING_AJAX')
105
-            && class_exists('Kint')
106
-            && function_exists('wp_get_current_user')
107
-            && current_user_can('update_core')
108
-            && class_exists('EE_Registry')
109
-        ) {
110
-            Kint::dump(EE_Registry::instance()->SSN->id());
111
-            Kint::dump(EE_Registry::instance()->SSN);
112
-            //			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
-            $this->espresso_list_hooked_functions();
114
-            Benchmark::displayResults();
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *    List All Hooked Functions
122
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
-     *
125
-     * @param string $tag
126
-     * @return void
127
-     */
128
-    public function espresso_list_hooked_functions($tag = '')
129
-    {
130
-        global $wp_filter;
131
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
-        if ($tag) {
133
-            $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
135
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
-                return;
137
-            }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
139
-        } else {
140
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
-            ksort($hook);
142
-        }
143
-        foreach ($hook as $tag_name => $priorities) {
144
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
-            ksort($priorities);
146
-            foreach ($priorities as $priority => $function) {
147
-                echo $priority;
148
-                foreach ($function as $name => $properties) {
149
-                    echo "\t$name<br />";
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     *    registered_filter_callbacks
159
-     *
160
-     * @param string $hook_name
161
-     * @return array
162
-     */
163
-    public static function registered_filter_callbacks($hook_name = '')
164
-    {
165
-        $filters = array();
166
-        global $wp_filter;
167
-        if (isset($wp_filter[$hook_name])) {
168
-            $filters[$hook_name] = array();
169
-            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
-                $filters[$hook_name][$priority] = array();
171
-                foreach ($callbacks as $callback) {
172
-                    $filters[$hook_name][$priority][] = $callback['function'];
173
-                }
174
-            }
175
-        }
176
-        return $filters;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    captures plugin activation errors for debugging
183
-     *
184
-     * @return void
185
-     * @throws EE_Error
186
-     */
187
-    public static function ee_plugin_activation_errors()
188
-    {
189
-        if (WP_DEBUG) {
190
-            $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
-            }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
-            if (class_exists('EEH_File')) {
196
-                try {
197
-                    EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
-                    );
200
-                    EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
-                        $activation_errors
203
-                    );
204
-                } catch (EE_Error $e) {
205
-                    EE_Error::add_error(
206
-                        sprintf(
207
-                            __(
208
-                                'The Event Espresso activation errors file could not be setup because: %s',
209
-                                'event_espresso'
210
-                            ),
211
-                            $e->getMessage()
212
-                        ),
213
-                        __FILE__, __FUNCTION__, __LINE__
214
-                    );
215
-                }
216
-            } else {
217
-                // old school attempt
218
-                file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
-                    $activation_errors
221
-                );
222
-            }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
-            update_option('ee_plugin_activation_errors', $activation_errors);
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
-     * or we want to make sure they use something the right way.
234
-     *
235
-     * @access public
236
-     * @param string $function      The function that was called
237
-     * @param string $message       A message explaining what has been done incorrectly
238
-     * @param string $version       The version of Event Espresso where the error was added
239
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
-     *                              for a deprecated function. This allows deprecation to occur during one version,
241
-     *                              but not have any notices appear until a later version. This allows developers
242
-     *                              extra time to update their code before notices appear.
243
-     * @param int    $error_type
244
-     * @uses   trigger_error()
245
-     */
246
-    public function doing_it_wrong(
247
-        $function,
248
-        $message,
249
-        $version,
250
-        $applies_when = '',
251
-        $error_type = null
252
-    ) {
253
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
-        // because we swapped the parameter order around for the last two params,
256
-        // let's verify that some third party isn't still passing an error type value for the third param
257
-        if (is_int($applies_when)) {
258
-            $error_type = $applies_when;
259
-            $applies_when = espresso_version();
260
-        }
261
-        // if not displaying notices yet, then just leave
262
-        if (version_compare(espresso_version(), $applies_when, '<')) {
263
-            return;
264
-        }
265
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
-        $version = $version === null
267
-            ? ''
268
-            : sprintf(
269
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
-                $version
271
-            );
272
-        $error_message = sprintf(
273
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
-            $function,
275
-            '<strong>',
276
-            '</strong>',
277
-            $message,
278
-            $version
279
-        );
280
-        // don't trigger error if doing ajax,
281
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
-        if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
284
-                    'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
-                    'event_espresso'
286
-                );
287
-            $error_message .= '<ul><li>';
288
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
-            $error_message .= '</ul>';
290
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
-            //now we set this on the transient so it shows up on the next request.
292
-            EE_Error::get_notices(false, true);
293
-        } else {
294
-            trigger_error($error_message, $error_type);
295
-        }
296
-    }
297
-
298
-
299
-
300
-
301
-    /**
302
-     * Logger helpers
303
-     */
304
-    /**
305
-     * debug
306
-     *
307
-     * @param string $class
308
-     * @param string $func
309
-     * @param string $line
310
-     * @param array  $info
311
-     * @param bool   $display_request
312
-     * @param string $debug_index
313
-     * @param string $debug_key
314
-     * @throws EE_Error
315
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
-     */
317
-    public static function log(
318
-        $class = '',
319
-        $func = '',
320
-        $line = '',
321
-        $info = array(),
322
-        $display_request = false,
323
-        $debug_index = '',
324
-        $debug_key = 'EE_DEBUG_SPCO'
325
-    ) {
326
-        if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
-            $debug_data = get_option($debug_key, array());
329
-            $default_data = array(
330
-                $class => $func . '() : ' . $line,
331
-                'REQ'  => $display_request ? $_REQUEST : '',
332
-            );
333
-            // don't serialize objects
334
-            $info = self::strip_objects($info);
335
-            $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
337
-                $debug_data[$index] = array();
338
-            }
339
-            $debug_data[$index][microtime()] = array_merge($default_data, $info);
340
-            update_option($debug_key, $debug_data);
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * strip_objects
348
-     *
349
-     * @param array $info
350
-     * @return array
351
-     */
352
-    public static function strip_objects($info = array())
353
-    {
354
-        foreach ($info as $key => $value) {
355
-            if (is_array($value)) {
356
-                $info[$key] = self::strip_objects($value);
357
-            } else if (is_object($value)) {
358
-                $object_class = get_class($value);
359
-                $info[$object_class] = array();
360
-                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
-                if (method_exists($value, 'ID')) {
362
-                    $info[$object_class]['ID'] = $value->ID();
363
-                }
364
-                if (method_exists($value, 'status')) {
365
-                    $info[$object_class]['status'] = $value->status();
366
-                } else if (method_exists($value, 'status_ID')) {
367
-                    $info[$object_class]['status'] = $value->status_ID();
368
-                }
369
-                unset($info[$key]);
370
-            }
371
-        }
372
-        return (array)$info;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * @param mixed  $var
379
-     * @param string $var_name
380
-     * @param string $file
381
-     * @param int    $line
382
-     * @param int    $heading_tag
383
-     * @param bool   $die
384
-     * @param string $margin
385
-     */
386
-    public static function printv(
387
-        $var,
388
-        $var_name = '',
389
-        $file = __FILE__,
390
-        $line = __LINE__,
391
-        $heading_tag = 5,
392
-        $die = false,
393
-        $margin = ''
394
-    ) {
395
-        $var_name = ! $var_name ? 'string' : $var_name;
396
-        $var_name = ucwords(str_replace('$', '', $var_name));
397
-        $is_method = method_exists($var_name, $var);
398
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
399
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
-        $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
405
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
406
-        if ($die) {
407
-            die($result);
408
-        }
409
-        echo $result;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * @param string $var_name
416
-     * @param string $heading_tag
417
-     * @param string $margin
418
-     * @return string
419
-     */
420
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
-    {
422
-        if (defined('EE_TESTS_DIR')) {
423
-            return "\n\n{$var_name}";
424
-        }
425
-        $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @param string $heading_tag
433
-     * @return string
434
-     */
435
-    protected static function headingX($heading_tag = 'h5')
436
-    {
437
-        if (defined('EE_TESTS_DIR')) {
438
-            return "\n";
439
-        }
440
-        return '</' . $heading_tag . '>';
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * @param string $content
447
-     * @return string
448
-     */
449
-    protected static function grey_span($content = '')
450
-    {
451
-        if (defined('EE_TESTS_DIR')) {
452
-            return $content;
453
-        }
454
-        return '<span style="color:#999">' . $content . '</span>';
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * @param string $file
461
-     * @param int    $line
462
-     * @return string
463
-     */
464
-    protected static function file_and_line($file, $line)
465
-    {
466
-        if (defined('EE_TESTS_DIR')) {
467
-            return "\n (" . $file . ' line no: ' . $line . ' ) ';
468
-        }
469
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
470
-               . $file
471
-               . '<br />line no: '
472
-               . $line
473
-               . '</span>';
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * @param string $content
480
-     * @return string
481
-     */
482
-    protected static function orange_span($content = '')
483
-    {
484
-        if (defined('EE_TESTS_DIR')) {
485
-            return $content;
486
-        }
487
-        return '<span style="color:#E76700">' . $content . '</span>';
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * @param mixed $var
494
-     * @return string
495
-     */
496
-    protected static function pre_span($var)
497
-    {
498
-        ob_start();
499
-        var_dump($var);
500
-        $var = ob_get_clean();
501
-        if (defined('EE_TESTS_DIR')) {
502
-            return "\n" . $var;
503
-        }
504
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
505
-    }
506
-
507
-
508
-
509
-    /**
510
-     * @param mixed  $var
511
-     * @param string $var_name
512
-     * @param string $file
513
-     * @param int    $line
514
-     * @param int    $heading_tag
515
-     * @param bool   $die
516
-     */
517
-    public static function printr(
518
-        $var,
519
-        $var_name = '',
520
-        $file = __FILE__,
521
-        $line = __LINE__,
522
-        $heading_tag = 5,
523
-        $die = false
524
-    ) {
525
-        // return;
526
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
527
-        $margin = is_admin() ? ' 180px' : '0';
528
-        //$print_r = false;
529
-        if (is_string($var)) {
530
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
531
-            return;
532
-        }
533
-        if (is_object($var)) {
534
-            $var_name = ! $var_name ? 'object' : $var_name;
535
-            //$print_r = true;
536
-        } else if (is_array($var)) {
537
-            $var_name = ! $var_name ? 'array' : $var_name;
538
-            //$print_r = true;
539
-        } else if (is_numeric($var)) {
540
-            $var_name = ! $var_name ? 'numeric' : $var_name;
541
-        } else if ($var === null) {
542
-            $var_name = ! $var_name ? 'null' : $var_name;
543
-        }
544
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
545
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
546
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
547
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
548
-                EEH_Debug_Tools::pre_span($var)
549
-            );
550
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
551
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
552
-        if ($die) {
553
-            die($result);
554
-        }
555
-        echo $result;
556
-    }
557
-
558
-
559
-
560
-    /******************** deprecated ********************/
561
-    /**
562
-     * @deprecated 4.9.39.rc.034
563
-     */
564
-    public function reset_times()
565
-    {
566
-        Benchmark::resetTimes();
567
-    }
568
-
569
-
570
-
571
-    /**
572
-     * @deprecated 4.9.39.rc.034
573
-     * @param null $timer_name
574
-     */
575
-    public function start_timer($timer_name = null)
576
-    {
577
-        Benchmark::startTimer($timer_name);
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * @deprecated 4.9.39.rc.034
584
-     * @param string $timer_name
585
-     */
586
-    public function stop_timer($timer_name = '')
587
-    {
588
-        Benchmark::stopTimer($timer_name);
589
-    }
590
-
591
-
592
-
593
-    /**
594
-     * @deprecated 4.9.39.rc.034
595
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
596
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
597
-     * @return void
598
-     */
599
-    public function measure_memory($label, $output_now = false)
600
-    {
601
-        Benchmark::measureMemory($label, $output_now);
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     * @deprecated 4.9.39.rc.034
608
-     * @param int $size
609
-     * @return string
610
-     */
611
-    public function convert($size)
612
-    {
613
-        return Benchmark::convert($size);
614
-    }
615
-
616
-
617
-
618
-    /**
619
-     * @deprecated 4.9.39.rc.034
620
-     * @param bool $output_now
621
-     * @return string
622
-     */
623
-    public function show_times($output_now = true)
624
-    {
625
-        return Benchmark::displayResults($output_now);
626
-    }
627
-
628
-
629
-
630
-    /**
631
-     * @deprecated 4.9.39.rc.034
632
-     * @param string $timer_name
633
-     * @param float  $total_time
634
-     * @return string
635
-     */
636
-    public function format_time($timer_name, $total_time)
637
-    {
638
-        return Benchmark::formatTime($timer_name, $total_time);
639
-    }
20
+	/**
21
+	 *    instance of the EEH_Autoloader object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $_memory_usage_points = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EEH_Debug_Tools
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
44
+			self::$_instance = new self();
45
+		}
46
+		return self::$_instance;
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * private class constructor
53
+	 */
54
+	private function __construct()
55
+	{
56
+		// load Kint PHP debugging library
57
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
59
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
+			// so we've moved it to our test folder so that it is not included with production releases
62
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
+			require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
+		}
65
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
+		//add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
+		// }
68
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
69
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    show_db_name
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function show_db_name()
82
+	{
83
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
+				 . DB_NAME
86
+				 . '</p>';
87
+		}
88
+		if (EE_DEBUG) {
89
+			Benchmark::displayResults();
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    dump EE_Session object at bottom of page after everything else has happened
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function espresso_session_footer_dump()
101
+	{
102
+		if (
103
+			(defined('WP_DEBUG') && WP_DEBUG)
104
+			&& ! defined('DOING_AJAX')
105
+			&& class_exists('Kint')
106
+			&& function_exists('wp_get_current_user')
107
+			&& current_user_can('update_core')
108
+			&& class_exists('EE_Registry')
109
+		) {
110
+			Kint::dump(EE_Registry::instance()->SSN->id());
111
+			Kint::dump(EE_Registry::instance()->SSN);
112
+			//			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
+			$this->espresso_list_hooked_functions();
114
+			Benchmark::displayResults();
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *    List All Hooked Functions
122
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
+	 *
125
+	 * @param string $tag
126
+	 * @return void
127
+	 */
128
+	public function espresso_list_hooked_functions($tag = '')
129
+	{
130
+		global $wp_filter;
131
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
+		if ($tag) {
133
+			$hook[$tag] = $wp_filter[$tag];
134
+			if (! is_array($hook[$tag])) {
135
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
+				return;
137
+			}
138
+			echo '<h5>For Tag: ' . $tag . '</h5>';
139
+		} else {
140
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
+			ksort($hook);
142
+		}
143
+		foreach ($hook as $tag_name => $priorities) {
144
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
+			ksort($priorities);
146
+			foreach ($priorities as $priority => $function) {
147
+				echo $priority;
148
+				foreach ($function as $name => $properties) {
149
+					echo "\t$name<br />";
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 *    registered_filter_callbacks
159
+	 *
160
+	 * @param string $hook_name
161
+	 * @return array
162
+	 */
163
+	public static function registered_filter_callbacks($hook_name = '')
164
+	{
165
+		$filters = array();
166
+		global $wp_filter;
167
+		if (isset($wp_filter[$hook_name])) {
168
+			$filters[$hook_name] = array();
169
+			foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
+				$filters[$hook_name][$priority] = array();
171
+				foreach ($callbacks as $callback) {
172
+					$filters[$hook_name][$priority][] = $callback['function'];
173
+				}
174
+			}
175
+		}
176
+		return $filters;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    captures plugin activation errors for debugging
183
+	 *
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 */
187
+	public static function ee_plugin_activation_errors()
188
+	{
189
+		if (WP_DEBUG) {
190
+			$activation_errors = ob_get_contents();
191
+			if (! empty($activation_errors)) {
192
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
+			}
194
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
+			if (class_exists('EEH_File')) {
196
+				try {
197
+					EEH_File::ensure_file_exists_and_is_writable(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
+					);
200
+					EEH_File::write_to_file(
201
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
+						$activation_errors
203
+					);
204
+				} catch (EE_Error $e) {
205
+					EE_Error::add_error(
206
+						sprintf(
207
+							__(
208
+								'The Event Espresso activation errors file could not be setup because: %s',
209
+								'event_espresso'
210
+							),
211
+							$e->getMessage()
212
+						),
213
+						__FILE__, __FUNCTION__, __LINE__
214
+					);
215
+				}
216
+			} else {
217
+				// old school attempt
218
+				file_put_contents(
219
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
+					$activation_errors
221
+				);
222
+			}
223
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
+			update_option('ee_plugin_activation_errors', $activation_errors);
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
+	 * or we want to make sure they use something the right way.
234
+	 *
235
+	 * @access public
236
+	 * @param string $function      The function that was called
237
+	 * @param string $message       A message explaining what has been done incorrectly
238
+	 * @param string $version       The version of Event Espresso where the error was added
239
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
241
+	 *                              but not have any notices appear until a later version. This allows developers
242
+	 *                              extra time to update their code before notices appear.
243
+	 * @param int    $error_type
244
+	 * @uses   trigger_error()
245
+	 */
246
+	public function doing_it_wrong(
247
+		$function,
248
+		$message,
249
+		$version,
250
+		$applies_when = '',
251
+		$error_type = null
252
+	) {
253
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
+		// because we swapped the parameter order around for the last two params,
256
+		// let's verify that some third party isn't still passing an error type value for the third param
257
+		if (is_int($applies_when)) {
258
+			$error_type = $applies_when;
259
+			$applies_when = espresso_version();
260
+		}
261
+		// if not displaying notices yet, then just leave
262
+		if (version_compare(espresso_version(), $applies_when, '<')) {
263
+			return;
264
+		}
265
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
+		$version = $version === null
267
+			? ''
268
+			: sprintf(
269
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
+				$version
271
+			);
272
+		$error_message = sprintf(
273
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
+			$function,
275
+			'<strong>',
276
+			'</strong>',
277
+			$message,
278
+			$version
279
+		);
280
+		// don't trigger error if doing ajax,
281
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
+		if (defined('DOING_AJAX') && DOING_AJAX) {
283
+			$error_message .= ' ' . esc_html__(
284
+					'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
+					'event_espresso'
286
+				);
287
+			$error_message .= '<ul><li>';
288
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
+			$error_message .= '</ul>';
290
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
+			//now we set this on the transient so it shows up on the next request.
292
+			EE_Error::get_notices(false, true);
293
+		} else {
294
+			trigger_error($error_message, $error_type);
295
+		}
296
+	}
297
+
298
+
299
+
300
+
301
+	/**
302
+	 * Logger helpers
303
+	 */
304
+	/**
305
+	 * debug
306
+	 *
307
+	 * @param string $class
308
+	 * @param string $func
309
+	 * @param string $line
310
+	 * @param array  $info
311
+	 * @param bool   $display_request
312
+	 * @param string $debug_index
313
+	 * @param string $debug_key
314
+	 * @throws EE_Error
315
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
+	 */
317
+	public static function log(
318
+		$class = '',
319
+		$func = '',
320
+		$line = '',
321
+		$info = array(),
322
+		$display_request = false,
323
+		$debug_index = '',
324
+		$debug_key = 'EE_DEBUG_SPCO'
325
+	) {
326
+		if (WP_DEBUG) {
327
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
+			$debug_data = get_option($debug_key, array());
329
+			$default_data = array(
330
+				$class => $func . '() : ' . $line,
331
+				'REQ'  => $display_request ? $_REQUEST : '',
332
+			);
333
+			// don't serialize objects
334
+			$info = self::strip_objects($info);
335
+			$index = ! empty($debug_index) ? $debug_index : 0;
336
+			if (! isset($debug_data[$index])) {
337
+				$debug_data[$index] = array();
338
+			}
339
+			$debug_data[$index][microtime()] = array_merge($default_data, $info);
340
+			update_option($debug_key, $debug_data);
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * strip_objects
348
+	 *
349
+	 * @param array $info
350
+	 * @return array
351
+	 */
352
+	public static function strip_objects($info = array())
353
+	{
354
+		foreach ($info as $key => $value) {
355
+			if (is_array($value)) {
356
+				$info[$key] = self::strip_objects($value);
357
+			} else if (is_object($value)) {
358
+				$object_class = get_class($value);
359
+				$info[$object_class] = array();
360
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
+				if (method_exists($value, 'ID')) {
362
+					$info[$object_class]['ID'] = $value->ID();
363
+				}
364
+				if (method_exists($value, 'status')) {
365
+					$info[$object_class]['status'] = $value->status();
366
+				} else if (method_exists($value, 'status_ID')) {
367
+					$info[$object_class]['status'] = $value->status_ID();
368
+				}
369
+				unset($info[$key]);
370
+			}
371
+		}
372
+		return (array)$info;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * @param mixed  $var
379
+	 * @param string $var_name
380
+	 * @param string $file
381
+	 * @param int    $line
382
+	 * @param int    $heading_tag
383
+	 * @param bool   $die
384
+	 * @param string $margin
385
+	 */
386
+	public static function printv(
387
+		$var,
388
+		$var_name = '',
389
+		$file = __FILE__,
390
+		$line = __LINE__,
391
+		$heading_tag = 5,
392
+		$die = false,
393
+		$margin = ''
394
+	) {
395
+		$var_name = ! $var_name ? 'string' : $var_name;
396
+		$var_name = ucwords(str_replace('$', '', $var_name));
397
+		$is_method = method_exists($var_name, $var);
398
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
399
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
+		$result .= $is_method
402
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
405
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
406
+		if ($die) {
407
+			die($result);
408
+		}
409
+		echo $result;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * @param string $var_name
416
+	 * @param string $heading_tag
417
+	 * @param string $margin
418
+	 * @return string
419
+	 */
420
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
+	{
422
+		if (defined('EE_TESTS_DIR')) {
423
+			return "\n\n{$var_name}";
424
+		}
425
+		$margin = "25px 0 0 {$margin}";
426
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @param string $heading_tag
433
+	 * @return string
434
+	 */
435
+	protected static function headingX($heading_tag = 'h5')
436
+	{
437
+		if (defined('EE_TESTS_DIR')) {
438
+			return "\n";
439
+		}
440
+		return '</' . $heading_tag . '>';
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * @param string $content
447
+	 * @return string
448
+	 */
449
+	protected static function grey_span($content = '')
450
+	{
451
+		if (defined('EE_TESTS_DIR')) {
452
+			return $content;
453
+		}
454
+		return '<span style="color:#999">' . $content . '</span>';
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * @param string $file
461
+	 * @param int    $line
462
+	 * @return string
463
+	 */
464
+	protected static function file_and_line($file, $line)
465
+	{
466
+		if (defined('EE_TESTS_DIR')) {
467
+			return "\n (" . $file . ' line no: ' . $line . ' ) ';
468
+		}
469
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
470
+			   . $file
471
+			   . '<br />line no: '
472
+			   . $line
473
+			   . '</span>';
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * @param string $content
480
+	 * @return string
481
+	 */
482
+	protected static function orange_span($content = '')
483
+	{
484
+		if (defined('EE_TESTS_DIR')) {
485
+			return $content;
486
+		}
487
+		return '<span style="color:#E76700">' . $content . '</span>';
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * @param mixed $var
494
+	 * @return string
495
+	 */
496
+	protected static function pre_span($var)
497
+	{
498
+		ob_start();
499
+		var_dump($var);
500
+		$var = ob_get_clean();
501
+		if (defined('EE_TESTS_DIR')) {
502
+			return "\n" . $var;
503
+		}
504
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
505
+	}
506
+
507
+
508
+
509
+	/**
510
+	 * @param mixed  $var
511
+	 * @param string $var_name
512
+	 * @param string $file
513
+	 * @param int    $line
514
+	 * @param int    $heading_tag
515
+	 * @param bool   $die
516
+	 */
517
+	public static function printr(
518
+		$var,
519
+		$var_name = '',
520
+		$file = __FILE__,
521
+		$line = __LINE__,
522
+		$heading_tag = 5,
523
+		$die = false
524
+	) {
525
+		// return;
526
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
527
+		$margin = is_admin() ? ' 180px' : '0';
528
+		//$print_r = false;
529
+		if (is_string($var)) {
530
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
531
+			return;
532
+		}
533
+		if (is_object($var)) {
534
+			$var_name = ! $var_name ? 'object' : $var_name;
535
+			//$print_r = true;
536
+		} else if (is_array($var)) {
537
+			$var_name = ! $var_name ? 'array' : $var_name;
538
+			//$print_r = true;
539
+		} else if (is_numeric($var)) {
540
+			$var_name = ! $var_name ? 'numeric' : $var_name;
541
+		} else if ($var === null) {
542
+			$var_name = ! $var_name ? 'null' : $var_name;
543
+		}
544
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
545
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
546
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
547
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
548
+				EEH_Debug_Tools::pre_span($var)
549
+			);
550
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
551
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
552
+		if ($die) {
553
+			die($result);
554
+		}
555
+		echo $result;
556
+	}
557
+
558
+
559
+
560
+	/******************** deprecated ********************/
561
+	/**
562
+	 * @deprecated 4.9.39.rc.034
563
+	 */
564
+	public function reset_times()
565
+	{
566
+		Benchmark::resetTimes();
567
+	}
568
+
569
+
570
+
571
+	/**
572
+	 * @deprecated 4.9.39.rc.034
573
+	 * @param null $timer_name
574
+	 */
575
+	public function start_timer($timer_name = null)
576
+	{
577
+		Benchmark::startTimer($timer_name);
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * @deprecated 4.9.39.rc.034
584
+	 * @param string $timer_name
585
+	 */
586
+	public function stop_timer($timer_name = '')
587
+	{
588
+		Benchmark::stopTimer($timer_name);
589
+	}
590
+
591
+
592
+
593
+	/**
594
+	 * @deprecated 4.9.39.rc.034
595
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
596
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
597
+	 * @return void
598
+	 */
599
+	public function measure_memory($label, $output_now = false)
600
+	{
601
+		Benchmark::measureMemory($label, $output_now);
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 * @deprecated 4.9.39.rc.034
608
+	 * @param int $size
609
+	 * @return string
610
+	 */
611
+	public function convert($size)
612
+	{
613
+		return Benchmark::convert($size);
614
+	}
615
+
616
+
617
+
618
+	/**
619
+	 * @deprecated 4.9.39.rc.034
620
+	 * @param bool $output_now
621
+	 * @return string
622
+	 */
623
+	public function show_times($output_now = true)
624
+	{
625
+		return Benchmark::displayResults($output_now);
626
+	}
627
+
628
+
629
+
630
+	/**
631
+	 * @deprecated 4.9.39.rc.034
632
+	 * @param string $timer_name
633
+	 * @param float  $total_time
634
+	 * @return string
635
+	 */
636
+	public function format_time($timer_name, $total_time)
637
+	{
638
+		return Benchmark::formatTime($timer_name, $total_time);
639
+	}
640 640
 
641 641
 
642 642
 
@@ -649,31 +649,31 @@  discard block
 block discarded – undo
649 649
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
650 650
  */
651 651
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
652
-    function dump_wp_query()
653
-    {
654
-        global $wp_query;
655
-        d($wp_query);
656
-    }
652
+	function dump_wp_query()
653
+	{
654
+		global $wp_query;
655
+		d($wp_query);
656
+	}
657 657
 }
658 658
 /**
659 659
  * borrowed from Kint Debugger
660 660
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
661 661
  */
662 662
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
663
-    function dump_wp()
664
-    {
665
-        global $wp;
666
-        d($wp);
667
-    }
663
+	function dump_wp()
664
+	{
665
+		global $wp;
666
+		d($wp);
667
+	}
668 668
 }
669 669
 /**
670 670
  * borrowed from Kint Debugger
671 671
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
672 672
  */
673 673
 if (class_exists('Kint') && ! function_exists('dump_post')) {
674
-    function dump_post()
675
-    {
676
-        global $post;
677
-        d($post);
678
-    }
674
+	function dump_post()
675
+	{
676
+		global $post;
677
+		d($post);
678
+	}
679 679
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public static function instance()
41 41
     {
42 42
         // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
43
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
44 44
             self::$_instance = new self();
45 45
         }
46 46
         return self::$_instance;
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
     private function __construct()
55 55
     {
56 56
         // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
57
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) {
58 58
             // despite EE4 having a check for an existing copy of the Kint debugging class,
59 59
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60 60
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61 61
             // so we've moved it to our test folder so that it is not included with production releases
62 62
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
63
+            require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php');
64 64
         }
65 65
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66 66
         //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function show_db_name()
82 82
     {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84 84
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85 85
                  . DB_NAME
86 86
                  . '</p>';
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132 132
         if ($tag) {
133 133
             $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
134
+            if ( ! is_array($hook[$tag])) {
135 135
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136 136
                 return;
137 137
             }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
138
+            echo '<h5>For Tag: '.$tag.'</h5>';
139 139
         } else {
140 140
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141 141
             ksort($hook);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
     {
189 189
         if (WP_DEBUG) {
190 190
             $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+            if ( ! empty($activation_errors)) {
192
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
193 193
             }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
194
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
195 195
             if (class_exists('EEH_File')) {
196 196
                 try {
197 197
                     EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'
199 199
                     );
200 200
                     EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
201
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
202 202
                         $activation_errors
203 203
                     );
204 204
                 } catch (EE_Error $e) {
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
             } else {
217 217
                 // old school attempt
218 218
                 file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
219
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
220 220
                     $activation_errors
221 221
                 );
222 222
             }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
224 224
             update_option('ee_plugin_activation_errors', $activation_errors);
225 225
         }
226 226
     }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         // don't trigger error if doing ajax,
281 281
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282 282
         if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
283
+            $error_message .= ' '.esc_html__(
284 284
                     'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285 285
                     'event_espresso'
286 286
                 );
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
         $debug_key = 'EE_DEBUG_SPCO'
325 325
     ) {
326 326
         if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
328 328
             $debug_data = get_option($debug_key, array());
329 329
             $default_data = array(
330
-                $class => $func . '() : ' . $line,
330
+                $class => $func.'() : '.$line,
331 331
                 'REQ'  => $display_request ? $_REQUEST : '',
332 332
             );
333 333
             // don't serialize objects
334 334
             $info = self::strip_objects($info);
335 335
             $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
336
+            if ( ! isset($debug_data[$index])) {
337 337
                 $debug_data[$index] = array();
338 338
             }
339 339
             $debug_data[$index][microtime()] = array_merge($default_data, $info);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 unset($info[$key]);
370 370
             }
371 371
         }
372
-        return (array)$info;
372
+        return (array) $info;
373 373
     }
374 374
 
375 375
 
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400 400
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401 401
         $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
402
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
403
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
404 404
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
405 405
         $result .= EEH_Debug_Tools::headingX($heading_tag);
406 406
         if ($die) {
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
             return "\n\n{$var_name}";
424 424
         }
425 425
         $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
426
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
427 427
     }
428 428
 
429 429
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         if (defined('EE_TESTS_DIR')) {
438 438
             return "\n";
439 439
         }
440
-        return '</' . $heading_tag . '>';
440
+        return '</'.$heading_tag.'>';
441 441
     }
442 442
 
443 443
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         if (defined('EE_TESTS_DIR')) {
452 452
             return $content;
453 453
         }
454
-        return '<span style="color:#999">' . $content . '</span>';
454
+        return '<span style="color:#999">'.$content.'</span>';
455 455
     }
456 456
 
457 457
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
     protected static function file_and_line($file, $line)
465 465
     {
466 466
         if (defined('EE_TESTS_DIR')) {
467
-            return "\n (" . $file . ' line no: ' . $line . ' ) ';
467
+            return "\n (".$file.' line no: '.$line.' ) ';
468 468
         }
469 469
         return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
470 470
                . $file
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
         if (defined('EE_TESTS_DIR')) {
485 485
             return $content;
486 486
         }
487
-        return '<span style="color:#E76700">' . $content . '</span>';
487
+        return '<span style="color:#E76700">'.$content.'</span>';
488 488
     }
489 489
 
490 490
 
@@ -499,9 +499,9 @@  discard block
 block discarded – undo
499 499
         var_dump($var);
500 500
         $var = ob_get_clean();
501 501
         if (defined('EE_TESTS_DIR')) {
502
-            return "\n" . $var;
502
+            return "\n".$var;
503 503
         }
504
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
504
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
505 505
     }
506 506
 
507 507
 
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
         $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
545 545
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
546 546
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
547
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
547
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
548 548
                 EEH_Debug_Tools::pre_span($var)
549 549
             );
550 550
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
Please login to merge, or discard this patch.
core/services/Benchmark.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     {
123 123
         add_action(
124 124
             'shutdown',
125
-            function () {
125
+            function() {
126 126
                 Benchmark::displayResults();
127 127
             }
128 128
         );
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
             return '';
143 143
         }
144 144
         $output = '';
145
-        if (! empty(Benchmark::$times)) {
145
+        if ( ! empty(Benchmark::$times)) {
146 146
             $total = 0;
147 147
             $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />';
148 148
             foreach (Benchmark::$times as $timer_name => $total_time) {
149
-                $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />';
149
+                $output .= Benchmark::formatTime($timer_name, $total_time).'<br />';
150 150
                 $total += $total_time;
151 151
             }
152 152
             $output .= '<br />';
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
             $output .= '<span style="color:darkorange">Zoinks!</span><br />';
163 163
             $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
164 164
         }
165
-        if (! empty(Benchmark::$memory_usage)) {
166
-            $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage);
165
+        if ( ! empty(Benchmark::$memory_usage)) {
166
+            $output .= '<h5>Memory</h5>'.implode('<br />', Benchmark::$memory_usage);
167 167
         }
168 168
         if (empty($output)) {
169 169
             return '';
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     public static function convert($size)
193 193
     {
194 194
         $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
195
-        return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)];
195
+        return round($size / pow(1024, $i = floor(log($size, 1024))), 2).' '.$unit[absint($i)];
196 196
     }
197 197
 
198 198
 
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -17,229 +17,229 @@
 block discarded – undo
17 17
 class Benchmark
18 18
 {
19 19
 
20
-    /**
21
-     * array containing the start time for the timers
22
-     */
23
-    private static $start_times;
24
-
25
-    /**
26
-     * array containing all the timer'd times, which can be outputted via show_times()
27
-     */
28
-    private static $times = array();
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    protected static $memory_usage = array();
34
-
35
-
36
-
37
-    /**
38
-     * whether to benchmark code or not
39
-     */
40
-    public static function doNotRun()
41
-    {
42
-        return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * resetTimes
49
-     */
50
-    public static function resetTimes()
51
-    {
52
-        Benchmark::$times = array();
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
-     *
60
-     * @param null $timer_name
61
-     */
62
-    public static function startTimer($timer_name = null)
63
-    {
64
-        if (Benchmark::doNotRun()) {
65
-            return;
66
-        }
67
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
-        Benchmark::$start_times[$timer_name] = microtime(true);
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
-     *
76
-     * @param string $timer_name
77
-     */
78
-    public static function stopTimer($timer_name = '')
79
-    {
80
-        if (Benchmark::doNotRun()) {
81
-            return;
82
-        }
83
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
-        if (isset(Benchmark::$start_times[$timer_name])) {
85
-            $start_time = Benchmark::$start_times[$timer_name];
86
-            unset(Benchmark::$start_times[$timer_name]);
87
-        } else {
88
-            $start_time = array_pop(Benchmark::$start_times);
89
-        }
90
-        Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * Measure the memory usage by PHP so far.
97
-     *
98
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
-     * @return void
101
-     */
102
-    public static function measureMemory($label, $output_now = false)
103
-    {
104
-        if (Benchmark::doNotRun()) {
105
-            return;
106
-        }
107
-        $memory_used = Benchmark::convert(memory_get_peak_usage(true));
108
-        Benchmark::$memory_usage[$label] = $memory_used;
109
-        if ($output_now) {
110
-            echo "\r\n<br>$label : $memory_used";
111
-        }
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * will display the benchmarking results at shutdown
118
-     *
119
-     * @return void
120
-     */
121
-    public static function displayResultsAtShutdown()
122
-    {
123
-        add_action(
124
-            'shutdown',
125
-            function () {
126
-                Benchmark::displayResults();
127
-            }
128
-        );
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * displayResults
135
-     *
136
-     * @param bool $echo
137
-     * @return string
138
-     */
139
-    public static function displayResults($echo = true)
140
-    {
141
-        if (Benchmark::doNotRun()) {
142
-            return '';
143
-        }
144
-        $output = '';
145
-        if (! empty(Benchmark::$times)) {
146
-            $total = 0;
147
-            $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />';
148
-            foreach (Benchmark::$times as $timer_name => $total_time) {
149
-                $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />';
150
-                $total += $total_time;
151
-            }
152
-            $output .= '<br />';
153
-            $output .= '<h4>TOTAL TIME</h4>';
154
-            $output .= Benchmark::formatTime('', $total);
155
-            $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
156
-            $output .= '<br />';
157
-            $output .= '<h5>Performance scale (from best to worse)</h5>';
158
-            $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
159
-            $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
160
-            $output .= '<span style="color:limegreen">Like...groovy!</span><br />';
161
-            $output .= '<span style="color:gold">Ruh Oh</span><br />';
162
-            $output .= '<span style="color:darkorange">Zoinks!</span><br />';
163
-            $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
164
-        }
165
-        if (! empty(Benchmark::$memory_usage)) {
166
-            $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage);
167
-        }
168
-        if (empty($output)) {
169
-            return '';
170
-        }
171
-        $output = '<div style="border:1px solid #dddddd; background-color:#ffffff;'
172
-                  . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;')
173
-                  . ' padding:2em;">'
174
-                  . '<h4>BENCHMARKING</h4>'
175
-                  . $output
176
-                  . '</div>';
177
-        if ($echo) {
178
-            echo $output;
179
-            return '';
180
-        }
181
-        return $output;
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
188
-     *
189
-     * @param int $size
190
-     * @return string
191
-     */
192
-    public static function convert($size)
193
-    {
194
-        $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
195
-        return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)];
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @param string $timer_name
202
-     * @param float  $total_time
203
-     * @return string
204
-     */
205
-    public static function formatTime($timer_name, $total_time)
206
-    {
207
-        $total_time *= 1000;
208
-        switch ($total_time) {
209
-            case $total_time > 12500 :
210
-                $color = 'red';
211
-                $bold = 'bold';
212
-                break;
213
-            case $total_time > 2500 :
214
-                $color = 'darkorange';
215
-                $bold = 'bold';
216
-                break;
217
-            case $total_time > 500 :
218
-                $color = 'gold';
219
-                $bold = 'bold';
220
-                break;
221
-            case $total_time > 100 :
222
-                $color = 'limegreen';
223
-                $bold = 'normal';
224
-                break;
225
-            case $total_time > 20 :
226
-                $color = 'deepskyblue';
227
-                $bold = 'normal';
228
-                break;
229
-            default :
230
-                $color = 'mediumpurple';
231
-                $bold = 'normal';
232
-                break;
233
-        }
234
-        return '<span style="min-width: 10px; margin:0 1em; color:'
235
-               . $color
236
-               . '; font-weight:'
237
-               . $bold
238
-               . '; font-size:1.2em;">'
239
-               . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
240
-               . '</span> '
241
-               . $timer_name;
242
-    }
20
+	/**
21
+	 * array containing the start time for the timers
22
+	 */
23
+	private static $start_times;
24
+
25
+	/**
26
+	 * array containing all the timer'd times, which can be outputted via show_times()
27
+	 */
28
+	private static $times = array();
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	protected static $memory_usage = array();
34
+
35
+
36
+
37
+	/**
38
+	 * whether to benchmark code or not
39
+	 */
40
+	public static function doNotRun()
41
+	{
42
+		return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * resetTimes
49
+	 */
50
+	public static function resetTimes()
51
+	{
52
+		Benchmark::$times = array();
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
+	 *
60
+	 * @param null $timer_name
61
+	 */
62
+	public static function startTimer($timer_name = null)
63
+	{
64
+		if (Benchmark::doNotRun()) {
65
+			return;
66
+		}
67
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
+		Benchmark::$start_times[$timer_name] = microtime(true);
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
+	 *
76
+	 * @param string $timer_name
77
+	 */
78
+	public static function stopTimer($timer_name = '')
79
+	{
80
+		if (Benchmark::doNotRun()) {
81
+			return;
82
+		}
83
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
+		if (isset(Benchmark::$start_times[$timer_name])) {
85
+			$start_time = Benchmark::$start_times[$timer_name];
86
+			unset(Benchmark::$start_times[$timer_name]);
87
+		} else {
88
+			$start_time = array_pop(Benchmark::$start_times);
89
+		}
90
+		Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * Measure the memory usage by PHP so far.
97
+	 *
98
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
+	 * @return void
101
+	 */
102
+	public static function measureMemory($label, $output_now = false)
103
+	{
104
+		if (Benchmark::doNotRun()) {
105
+			return;
106
+		}
107
+		$memory_used = Benchmark::convert(memory_get_peak_usage(true));
108
+		Benchmark::$memory_usage[$label] = $memory_used;
109
+		if ($output_now) {
110
+			echo "\r\n<br>$label : $memory_used";
111
+		}
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * will display the benchmarking results at shutdown
118
+	 *
119
+	 * @return void
120
+	 */
121
+	public static function displayResultsAtShutdown()
122
+	{
123
+		add_action(
124
+			'shutdown',
125
+			function () {
126
+				Benchmark::displayResults();
127
+			}
128
+		);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * displayResults
135
+	 *
136
+	 * @param bool $echo
137
+	 * @return string
138
+	 */
139
+	public static function displayResults($echo = true)
140
+	{
141
+		if (Benchmark::doNotRun()) {
142
+			return '';
143
+		}
144
+		$output = '';
145
+		if (! empty(Benchmark::$times)) {
146
+			$total = 0;
147
+			$output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />';
148
+			foreach (Benchmark::$times as $timer_name => $total_time) {
149
+				$output .= Benchmark::formatTime($timer_name, $total_time) . '<br />';
150
+				$total += $total_time;
151
+			}
152
+			$output .= '<br />';
153
+			$output .= '<h4>TOTAL TIME</h4>';
154
+			$output .= Benchmark::formatTime('', $total);
155
+			$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
156
+			$output .= '<br />';
157
+			$output .= '<h5>Performance scale (from best to worse)</h5>';
158
+			$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
159
+			$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
160
+			$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
161
+			$output .= '<span style="color:gold">Ruh Oh</span><br />';
162
+			$output .= '<span style="color:darkorange">Zoinks!</span><br />';
163
+			$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
164
+		}
165
+		if (! empty(Benchmark::$memory_usage)) {
166
+			$output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage);
167
+		}
168
+		if (empty($output)) {
169
+			return '';
170
+		}
171
+		$output = '<div style="border:1px solid #dddddd; background-color:#ffffff;'
172
+				  . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;')
173
+				  . ' padding:2em;">'
174
+				  . '<h4>BENCHMARKING</h4>'
175
+				  . $output
176
+				  . '</div>';
177
+		if ($echo) {
178
+			echo $output;
179
+			return '';
180
+		}
181
+		return $output;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
188
+	 *
189
+	 * @param int $size
190
+	 * @return string
191
+	 */
192
+	public static function convert($size)
193
+	{
194
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
195
+		return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)];
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @param string $timer_name
202
+	 * @param float  $total_time
203
+	 * @return string
204
+	 */
205
+	public static function formatTime($timer_name, $total_time)
206
+	{
207
+		$total_time *= 1000;
208
+		switch ($total_time) {
209
+			case $total_time > 12500 :
210
+				$color = 'red';
211
+				$bold = 'bold';
212
+				break;
213
+			case $total_time > 2500 :
214
+				$color = 'darkorange';
215
+				$bold = 'bold';
216
+				break;
217
+			case $total_time > 500 :
218
+				$color = 'gold';
219
+				$bold = 'bold';
220
+				break;
221
+			case $total_time > 100 :
222
+				$color = 'limegreen';
223
+				$bold = 'normal';
224
+				break;
225
+			case $total_time > 20 :
226
+				$color = 'deepskyblue';
227
+				$bold = 'normal';
228
+				break;
229
+			default :
230
+				$color = 'mediumpurple';
231
+				$bold = 'normal';
232
+				break;
233
+		}
234
+		return '<span style="min-width: 10px; margin:0 1em; color:'
235
+			   . $color
236
+			   . '; font-weight:'
237
+			   . $bold
238
+			   . '; font-size:1.2em;">'
239
+			   . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
240
+			   . '</span> '
241
+			   . $timer_name;
242
+	}
243 243
 
244 244
 
245 245
 
Please login to merge, or discard this patch.
acceptance_tests/Helpers/TicketSelector.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
     /**
16 16
      * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page).
17 17
      * @param int|string $event_id
18
-     * @param int|string $quantity
18
+     * @param integer $quantity
19 19
      */
20 20
     public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1)
21 21
     {
Please login to merge, or discard this patch.
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -12,23 +12,23 @@
 block discarded – undo
12 12
 trait TicketSelector
13 13
 {
14 14
 
15
-    /**
16
-     * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page).
17
-     * @param int|string $event_id
18
-     * @param int|string $quantity
19
-     */
20
-    public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1)
21
-    {
22
-        $this->actor()->selectOption(TicketSelectorElements::ticketOptionByEventIdSelector($event_id), $quantity);
23
-    }
15
+	/**
16
+	 * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page).
17
+	 * @param int|string $event_id
18
+	 * @param int|string $quantity
19
+	 */
20
+	public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1)
21
+	{
22
+		$this->actor()->selectOption(TicketSelectorElements::ticketOptionByEventIdSelector($event_id), $quantity);
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * Used to submit the ticket selection for the given event id (so this can be used on an event archive page).
28
-     * @param int|string $event_id
29
-     */
30
-    public function submitTicketSelectionsForEventId($event_id)
31
-    {
32
-        $this->actor()->click(TicketSelectorElements::ticketSelectionSubmitSelectorByEventId($event_id));
33
-    }
26
+	/**
27
+	 * Used to submit the ticket selection for the given event id (so this can be used on an event archive page).
28
+	 * @param int|string $event_id
29
+	 */
30
+	public function submitTicketSelectionsForEventId($event_id)
31
+	{
32
+		$this->actor()->click(TicketSelectorElements::ticketSelectionSubmitSelectorByEventId($event_id));
33
+	}
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.