Completed
Branch FET-10724-event-editor-cleanup (955656)
by
unknown
149:38 queued 136:37
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.
caffeinated/brewing_regular.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\services\database\TableAnalysis;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 /**
8 8
  * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE
@@ -27,277 +27,277 @@  discard block
 block discarded – undo
27 27
 class EE_Brewing_Regular extends EE_BASE
28 28
 {
29 29
 
30
-    /**
31
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
32
-     */
33
-    protected $_table_analysis;
34
-
35
-
36
-
37
-    /**
38
-     * EE_Brewing_Regular constructor.
39
-     */
40
-    public function __construct(TableAnalysis $table_analysis)
41
-    {
42
-        $this->_table_analysis = $table_analysis;
43
-        if (defined('EE_CAFF_PATH')) {
44
-            // activation
45
-            add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
46
-            // load caff init
47
-            add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
48
-            // remove the "powered by" credit link from receipts and invoices
49
-            add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
50
-            // add caffeinated modules
51
-            add_filter(
52
-                'FHEE__EE_Config__register_modules__modules_to_register',
53
-                array($this, 'caffeinated_modules_to_register')
54
-            );
55
-            // load caff scripts
56
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
57
-            add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
58
-            add_filter(
59
-                'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
60
-                array($this, 'caf_payment_methods')
61
-            );
62
-            // caffeinated constructed
63
-            do_action('AHEE__EE_Brewing_Regular__construct__finished');
64
-            //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
65
-            add_filter('FHEE__ee_show_affiliate_links', '__return_false');
66
-        }
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
73
-     *
74
-     * @param array $paths original helper paths array
75
-     * @return array             new array of paths
76
-     */
77
-    public function caf_helper_paths($paths)
78
-    {
79
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
80
-        return $paths;
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
87
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
88
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
89
-     * This action should only be called when EE 4.x.0.P is initially activated.
90
-     * Right now the only CAF content are these global prices. If there's more in the future, then
91
-     * we should probably create a caf file to contain it all instead just a function like this.
92
-     * Right now, we ASSUME the only price types in the system are default ones
93
-     *
94
-     * @global wpdb $wpdb
95
-     */
96
-    public function initialize_caf_db_content()
97
-    {
98
-        global $wpdb;
99
-        //use same method of getting creator id as the version introducing the change
100
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
101
-        $price_type_table = $wpdb->prefix . "esp_price_type";
102
-        $price_table = $wpdb->prefix . "esp_price";
103
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
104
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
105
-            $tax_price_type_count = $wpdb->get_var($SQL);
106
-            if ($tax_price_type_count <= 1) {
107
-                $wpdb->insert(
108
-                    $price_type_table,
109
-                    array(
110
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
111
-                        'PBT_ID'         => 4,
112
-                        'PRT_is_percent' => true,
113
-                        'PRT_order'      => 60,
114
-                        'PRT_deleted'    => false,
115
-                        'PRT_wp_user'    => $default_creator_id,
116
-                    ),
117
-                    array(
118
-                        '%s',//PRT_name
119
-                        '%d',//PBT_id
120
-                        '%d',//PRT_is_percent
121
-                        '%d',//PRT_order
122
-                        '%d',//PRT_deleted
123
-                        '%d', //PRT_wp_user
124
-                    )
125
-                );
126
-                //federal tax
127
-                $result = $wpdb->insert(
128
-                    $price_type_table,
129
-                    array(
130
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
131
-                        'PBT_ID'         => 4,
132
-                        'PRT_is_percent' => true,
133
-                        'PRT_order'      => 70,
134
-                        'PRT_deleted'    => false,
135
-                        'PRT_wp_user'    => $default_creator_id,
136
-                    ),
137
-                    array(
138
-                        '%s',//PRT_name
139
-                        '%d',//PBT_id
140
-                        '%d',//PRT_is_percent
141
-                        '%d',//PRT_order
142
-                        '%d',//PRT_deleted
143
-                        '%d' //PRT_wp_user
144
-                    )
145
-                );
146
-                if ($result) {
147
-                    $wpdb->insert(
148
-                        $price_table,
149
-                        array(
150
-                            'PRT_ID'         => $wpdb->insert_id,
151
-                            'PRC_amount'     => 15.00,
152
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
153
-                            'PRC_desc'       => '',
154
-                            'PRC_is_default' => true,
155
-                            'PRC_overrides'  => null,
156
-                            'PRC_deleted'    => false,
157
-                            'PRC_order'      => 50,
158
-                            'PRC_parent'     => null,
159
-                            'PRC_wp_user'    => $default_creator_id,
160
-                        ),
161
-                        array(
162
-                            '%d',//PRT_id
163
-                            '%f',//PRC_amount
164
-                            '%s',//PRC_name
165
-                            '%s',//PRC_desc
166
-                            '%d',//PRC_is_default
167
-                            '%d',//PRC_overrides
168
-                            '%d',//PRC_deleted
169
-                            '%d',//PRC_order
170
-                            '%d',//PRC_parent
171
-                            '%d' //PRC_wp_user
172
-                        )
173
-                    );
174
-                }
175
-            }
176
-        }
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    caffeinated_modules_to_register
183
-     *
184
-     * @access public
185
-     * @param array $modules_to_register
186
-     * @return array
187
-     */
188
-    public function caffeinated_modules_to_register($modules_to_register = array())
189
-    {
190
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
191
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
192
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
193
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
194
-            }
195
-        }
196
-        return $modules_to_register;
197
-    }
198
-
199
-
200
-
201
-    public function caffeinated_init()
202
-    {
203
-        // EE_Register_CPTs hooks
204
-        add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
205
-        add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
206
-        add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
207
-        EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
208
-        // caffeinated_init__complete hook
209
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
210
-    }
211
-
212
-
213
-
214
-    public function enqueue_caffeinated_scripts()
215
-    {
216
-        // sound of crickets...
217
-    }
218
-
219
-
220
-
221
-    /**
222
-     * callbacks below here
223
-     *
224
-     * @param array $taxonomy_array
225
-     * @return array
226
-     */
227
-    public function filter_taxonomies(array $taxonomy_array)
228
-    {
229
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
230
-        return $taxonomy_array;
231
-    }
232
-
233
-
234
-
235
-    /**
236
-     * @param array $cpt_array
237
-     * @return mixed
238
-     */
239
-    public function filter_cpts(array $cpt_array)
240
-    {
241
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
242
-        return $cpt_array;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * @param array $menuitems
249
-     * @return array
250
-     */
251
-    public function nav_metabox_items(array $menuitems)
252
-    {
253
-        $menuitems[] = array(
254
-            'title'       => __('Venue List', 'event_espresso'),
255
-            'url'         => get_post_type_archive_link('espresso_venues'),
256
-            'description' => __('Archive page for all venues.', 'event_espresso'),
257
-        );
258
-        return $menuitems;
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
265
-     *
266
-     * @param array $payment_method_paths
267
-     * @return array values are folder paths to payment method folders
268
-     */
269
-    public function caf_payment_methods($payment_method_paths)
270
-    {
271
-        $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
272
-        $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
273
-        return $payment_method_paths;
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     * Gets the injected table analyzer, or throws an exception
280
-     *
281
-     * @return TableAnalysis
282
-     * @throws \EE_Error
283
-     */
284
-    protected function _get_table_analysis()
285
-    {
286
-        if ($this->_table_analysis instanceof TableAnalysis) {
287
-            return $this->_table_analysis;
288
-        } else {
289
-            throw new \EE_Error(
290
-                sprintf(
291
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
292
-                    get_class($this)
293
-                )
294
-            );
295
-        }
296
-    }
30
+	/**
31
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
32
+	 */
33
+	protected $_table_analysis;
34
+
35
+
36
+
37
+	/**
38
+	 * EE_Brewing_Regular constructor.
39
+	 */
40
+	public function __construct(TableAnalysis $table_analysis)
41
+	{
42
+		$this->_table_analysis = $table_analysis;
43
+		if (defined('EE_CAFF_PATH')) {
44
+			// activation
45
+			add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
46
+			// load caff init
47
+			add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
48
+			// remove the "powered by" credit link from receipts and invoices
49
+			add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
50
+			// add caffeinated modules
51
+			add_filter(
52
+				'FHEE__EE_Config__register_modules__modules_to_register',
53
+				array($this, 'caffeinated_modules_to_register')
54
+			);
55
+			// load caff scripts
56
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
57
+			add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
58
+			add_filter(
59
+				'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
60
+				array($this, 'caf_payment_methods')
61
+			);
62
+			// caffeinated constructed
63
+			do_action('AHEE__EE_Brewing_Regular__construct__finished');
64
+			//seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
65
+			add_filter('FHEE__ee_show_affiliate_links', '__return_false');
66
+		}
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
73
+	 *
74
+	 * @param array $paths original helper paths array
75
+	 * @return array             new array of paths
76
+	 */
77
+	public function caf_helper_paths($paths)
78
+	{
79
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
80
+		return $paths;
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
87
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
88
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
89
+	 * This action should only be called when EE 4.x.0.P is initially activated.
90
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
91
+	 * we should probably create a caf file to contain it all instead just a function like this.
92
+	 * Right now, we ASSUME the only price types in the system are default ones
93
+	 *
94
+	 * @global wpdb $wpdb
95
+	 */
96
+	public function initialize_caf_db_content()
97
+	{
98
+		global $wpdb;
99
+		//use same method of getting creator id as the version introducing the change
100
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
101
+		$price_type_table = $wpdb->prefix . "esp_price_type";
102
+		$price_table = $wpdb->prefix . "esp_price";
103
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
104
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
105
+			$tax_price_type_count = $wpdb->get_var($SQL);
106
+			if ($tax_price_type_count <= 1) {
107
+				$wpdb->insert(
108
+					$price_type_table,
109
+					array(
110
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
111
+						'PBT_ID'         => 4,
112
+						'PRT_is_percent' => true,
113
+						'PRT_order'      => 60,
114
+						'PRT_deleted'    => false,
115
+						'PRT_wp_user'    => $default_creator_id,
116
+					),
117
+					array(
118
+						'%s',//PRT_name
119
+						'%d',//PBT_id
120
+						'%d',//PRT_is_percent
121
+						'%d',//PRT_order
122
+						'%d',//PRT_deleted
123
+						'%d', //PRT_wp_user
124
+					)
125
+				);
126
+				//federal tax
127
+				$result = $wpdb->insert(
128
+					$price_type_table,
129
+					array(
130
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
131
+						'PBT_ID'         => 4,
132
+						'PRT_is_percent' => true,
133
+						'PRT_order'      => 70,
134
+						'PRT_deleted'    => false,
135
+						'PRT_wp_user'    => $default_creator_id,
136
+					),
137
+					array(
138
+						'%s',//PRT_name
139
+						'%d',//PBT_id
140
+						'%d',//PRT_is_percent
141
+						'%d',//PRT_order
142
+						'%d',//PRT_deleted
143
+						'%d' //PRT_wp_user
144
+					)
145
+				);
146
+				if ($result) {
147
+					$wpdb->insert(
148
+						$price_table,
149
+						array(
150
+							'PRT_ID'         => $wpdb->insert_id,
151
+							'PRC_amount'     => 15.00,
152
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
153
+							'PRC_desc'       => '',
154
+							'PRC_is_default' => true,
155
+							'PRC_overrides'  => null,
156
+							'PRC_deleted'    => false,
157
+							'PRC_order'      => 50,
158
+							'PRC_parent'     => null,
159
+							'PRC_wp_user'    => $default_creator_id,
160
+						),
161
+						array(
162
+							'%d',//PRT_id
163
+							'%f',//PRC_amount
164
+							'%s',//PRC_name
165
+							'%s',//PRC_desc
166
+							'%d',//PRC_is_default
167
+							'%d',//PRC_overrides
168
+							'%d',//PRC_deleted
169
+							'%d',//PRC_order
170
+							'%d',//PRC_parent
171
+							'%d' //PRC_wp_user
172
+						)
173
+					);
174
+				}
175
+			}
176
+		}
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    caffeinated_modules_to_register
183
+	 *
184
+	 * @access public
185
+	 * @param array $modules_to_register
186
+	 * @return array
187
+	 */
188
+	public function caffeinated_modules_to_register($modules_to_register = array())
189
+	{
190
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
191
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
192
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
193
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
194
+			}
195
+		}
196
+		return $modules_to_register;
197
+	}
198
+
199
+
200
+
201
+	public function caffeinated_init()
202
+	{
203
+		// EE_Register_CPTs hooks
204
+		add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
205
+		add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
206
+		add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
207
+		EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
208
+		// caffeinated_init__complete hook
209
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
210
+	}
211
+
212
+
213
+
214
+	public function enqueue_caffeinated_scripts()
215
+	{
216
+		// sound of crickets...
217
+	}
218
+
219
+
220
+
221
+	/**
222
+	 * callbacks below here
223
+	 *
224
+	 * @param array $taxonomy_array
225
+	 * @return array
226
+	 */
227
+	public function filter_taxonomies(array $taxonomy_array)
228
+	{
229
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
230
+		return $taxonomy_array;
231
+	}
232
+
233
+
234
+
235
+	/**
236
+	 * @param array $cpt_array
237
+	 * @return mixed
238
+	 */
239
+	public function filter_cpts(array $cpt_array)
240
+	{
241
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
242
+		return $cpt_array;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * @param array $menuitems
249
+	 * @return array
250
+	 */
251
+	public function nav_metabox_items(array $menuitems)
252
+	{
253
+		$menuitems[] = array(
254
+			'title'       => __('Venue List', 'event_espresso'),
255
+			'url'         => get_post_type_archive_link('espresso_venues'),
256
+			'description' => __('Archive page for all venues.', 'event_espresso'),
257
+		);
258
+		return $menuitems;
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods
265
+	 *
266
+	 * @param array $payment_method_paths
267
+	 * @return array values are folder paths to payment method folders
268
+	 */
269
+	public function caf_payment_methods($payment_method_paths)
270
+	{
271
+		$caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
272
+		$payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths);
273
+		return $payment_method_paths;
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 * Gets the injected table analyzer, or throws an exception
280
+	 *
281
+	 * @return TableAnalysis
282
+	 * @throws \EE_Error
283
+	 */
284
+	protected function _get_table_analysis()
285
+	{
286
+		if ($this->_table_analysis instanceof TableAnalysis) {
287
+			return $this->_table_analysis;
288
+		} else {
289
+			throw new \EE_Error(
290
+				sprintf(
291
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
292
+					get_class($this)
293
+				)
294
+			);
295
+		}
296
+	}
297 297
 }
298 298
 
299 299
 
300 300
 
301 301
 $brewing = new EE_Brewing_Regular(
302
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
302
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
303 303
 );
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 3 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.
caffeinated/payment_methods/Paypal_Pro/EEG_Paypal_Pro.gateway.php 2 patches
Indentation   +587 added lines, -587 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -25,591 +25,591 @@  discard block
 block discarded – undo
25 25
 class EEG_Paypal_Pro extends EE_Onsite_Gateway
26 26
 {
27 27
 
28
-    /**
29
-     * @var $_paypal_api_username string
30
-     */
31
-    protected $_username = null;
32
-
33
-    /**
34
-     * @var $_password string
35
-     */
36
-    protected $_password = null;
37
-
38
-    /**
39
-     * @var $_signature string
40
-     */
41
-    protected $_signature = null;
42
-
43
-    /**
44
-     * @var $_credit_card_types array with the keys for credit card types accepted on this account
45
-     */
46
-    protected $_credit_card_types    = null;
47
-
48
-    protected $_currencies_supported = array(
49
-        'USD',
50
-        'GBP',
51
-        'CAD',
52
-        'AUD',
53
-        'BRL',
54
-        'CHF',
55
-        'CZK',
56
-        'DKK',
57
-        'EUR',
58
-        'HKD',
59
-        'HUF',
60
-        'ILS',
61
-        'JPY',
62
-        'MXN',
63
-        'MYR',
64
-        'NOK',
65
-        'NZD',
66
-        'PHP',
67
-        'PLN',
68
-        'SEK',
69
-        'SGD',
70
-        'THB',
71
-        'TRY',
72
-        'TWD',
73
-        'RUB',
74
-    );
75
-
76
-
77
-
78
-    /**
79
-     * @param EEI_Payment $payment
80
-     * @param array       $billing_info {
81
-     * @type string $credit_card
82
-     * @type string $credit_card_type
83
-     * @type string $exp_month always 2 characters
84
-     * @type string $exp_year always 4 characters
85
-     * @type string $cvv
86
-     * }
87
-     * @see      parent::do_direct_payment for more info
88
-     * @return EE_Payment|EEI_Payment
89
-     * @throws EE_Error
90
-     */
91
-    public function do_direct_payment($payment, $billing_info = null)
92
-    {
93
-        $transaction = $payment->transaction();
94
-        if (! $transaction instanceof EEI_Transaction) {
95
-            throw new EE_Error(
96
-                esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
97
-            );
98
-        }
99
-        $primary_registrant = $transaction->primary_registration();
100
-        if (! $primary_registrant instanceof EEI_Registration) {
101
-            throw new EE_Error(
102
-                esc_html__(
103
-                    'No primary registration on transaction while paying with PayPal Pro.',
104
-                    'event_espresso'
105
-                )
106
-            );
107
-        }
108
-        $attendee = $primary_registrant->attendee();
109
-        if (! $attendee instanceof EEI_Attendee) {
110
-            throw new EE_Error(
111
-                esc_html__(
112
-                    'No attendee on primary registration while paying with PayPal Pro.',
113
-                    'event_espresso'
114
-                )
115
-            );
116
-        }
117
-        $order_description = substr($this->_format_order_description($payment), 0, 127);
118
-        //charge for the full amount. Show itemized list
119
-        if ($this->_can_easily_itemize_transaction_for($payment)) {
120
-            $item_num = 1;
121
-            $total_line_item = $transaction->total_line_item();
122
-            $order_items = array();
123
-            foreach ($total_line_item->get_items() as $line_item) {
124
-                //ignore line items with a quantity of 0
125
-                if ($line_item->quantity() == 0) {
126
-                    continue;
127
-                }
128
-                $item = array(
129
-                    // Item Name.  127 char max.
130
-                    'l_name'                 => substr(
131
-                        $this->_format_line_item_name($line_item, $payment),
132
-                        0,
133
-                        127
134
-                    ),
135
-                    // Item description.  127 char max.
136
-                    'l_desc'                 => substr(
137
-                        $this->_format_line_item_desc($line_item, $payment),
138
-                        0,
139
-                        127
140
-                    ),
141
-                    // Cost of individual item.
142
-                    'l_amt'                  => $line_item->unit_price(),
143
-                    // Item Number.  127 char max.
144
-                    'l_number'               => $item_num++,
145
-                    // Item quantity.  Must be any positive integer.
146
-                    'l_qty'                  => $line_item->quantity(),
147
-                    // Item's sales tax amount.
148
-                    'l_taxamt'               => '',
149
-                    // eBay auction number of item.
150
-                    'l_ebayitemnumber'       => '',
151
-                    // eBay transaction ID of purchased item.
152
-                    'l_ebayitemauctiontxnid' => '',
153
-                    // eBay order ID for the item.
154
-                    'l_ebayitemorderid'      => '',
155
-                );
156
-                // add to array of all items
157
-                array_push($order_items, $item);
158
-            }
159
-            $item_amount = $total_line_item->get_items_total();
160
-            $tax_amount = $total_line_item->get_total_tax();
161
-        } else {
162
-            $order_items = array();
163
-            $item_amount = $payment->amount();
164
-            $tax_amount = 0;
165
-            array_push($order_items, array(
166
-                // Item Name.  127 char max.
167
-                'l_name'   => substr(
168
-                    $this->_format_partial_payment_line_item_name($payment),
169
-                    0,
170
-                    127
171
-                ),
172
-                // Item description.  127 char max.
173
-                'l_desc'   => substr(
174
-                    $this->_format_partial_payment_line_item_desc($payment),
175
-                    0,
176
-                    127
177
-                ),
178
-                // Cost of individual item.
179
-                'l_amt'    => $payment->amount(),
180
-                // Item Number.  127 char max.
181
-                'l_number' => 1,
182
-                // Item quantity.  Must be any positive integer.
183
-                'l_qty'    => 1,
184
-            ));
185
-        }
186
-        // Populate data arrays with order data.
187
-        $DPFields = array(
188
-            // How you want to obtain payment ?
189
-            // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture.
190
-            // Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
191
-            'paymentaction'    => 'Sale',
192
-            // Required.  IP address of the payer's browser.
193
-            'ipaddress'        => $_SERVER['REMOTE_ADDR'],
194
-            // Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
195
-            'returnfmfdetails' => '1',
196
-        );
197
-        $CCDetails = array(
198
-            // Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
199
-            // If Maestro or Solo, the currency code must be GBP.
200
-            //  In addition, either start date or issue number must be specified.
201
-            'creditcardtype' => $billing_info['credit_card_type'],
202
-            // Required.  Credit card number.  No spaces or punctuation.
203
-            'acct'           => $billing_info['credit_card'],
204
-            // Required.  Credit card expiration date.  Format is MMYYYY
205
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
206
-            // Requirements determined by your PayPal account settings.  Security digits for credit card.
207
-            'cvv2'           => $billing_info['cvv'],
208
-        );
209
-        $PayerInfo = array(
210
-            // Email address of payer.
211
-            'email'       => $billing_info['email'],
212
-            // Unique PayPal customer ID for payer.
213
-            'payerid'     => '',
214
-            // Status of payer.  Values are verified or unverified
215
-            'payerstatus' => '',
216
-            // Payer's business name.
217
-            'business'    => '',
218
-        );
219
-        $PayerName = array(
220
-            // Payer's salutation.  20 char max.
221
-            'salutation' => '',
222
-            // Payer's first name.  25 char max.
223
-            'firstname'  => substr($billing_info['first_name'], 0, 25),
224
-            // Payer's middle name.  25 char max.
225
-            'middlename' => '',
226
-            // Payer's last name.  25 char max.
227
-            'lastname'   => substr($billing_info['last_name'], 0, 25),
228
-            // Payer's suffix.  12 char max.
229
-            'suffix'     => '',
230
-        );
231
-        $BillingAddress = array(
232
-            // Required.  First street address.
233
-            'street'      => $billing_info['address'],
234
-            // Second street address.
235
-            'street2'     => $billing_info['address2'],
236
-            // Required.  Name of City.
237
-            'city'        => $billing_info['city'],
238
-            // Required. Name of State or Province.
239
-            'state'       => substr($billing_info['state'], 0, 40),
240
-            // Required.  Country code.
241
-            'countrycode' => $billing_info['country'],
242
-            // Required.  Postal code of payer.
243
-            'zip'         => $billing_info['zip'],
244
-        );
245
-        //check if the registration info contains the needed fields for paypal pro
246
-        //(see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
247
-        if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
248
-            $use_registration_address_info = true;
249
-        } else {
250
-            $use_registration_address_info = false;
251
-        }
252
-        //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
253
-        // If not, use the billing info again
254
-        $ShippingAddress = array(
255
-            'shiptoname'     => substr($use_registration_address_info
256
-                ? $attendee->full_name()
257
-                : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
258
-            'shiptostreet'   => substr($use_registration_address_info
259
-                ? $attendee->address()
260
-                : $billing_info['address'], 0, 100),
261
-            'shiptostreet2'  => substr($use_registration_address_info
262
-                ? $attendee->address2() : $billing_info['address2'], 0, 100),
263
-            'shiptocity'     => substr($use_registration_address_info
264
-                ? $attendee->city()
265
-                : $billing_info['city'], 0, 40),
266
-            'state'          => substr($use_registration_address_info
267
-                ? $attendee->state_name()
268
-                : $billing_info['state'], 0, 40),
269
-            'shiptocountry'  => $use_registration_address_info
270
-                ? $attendee->country_ID()
271
-                : $billing_info['country'],
272
-            'shiptozip'      => substr($use_registration_address_info
273
-                ? $attendee->zip()
274
-                : $billing_info['zip'], 0, 20),
275
-            'shiptophonenum' => substr($use_registration_address_info
276
-                ? $attendee->phone()
277
-                : $billing_info['phone'], 0, 20),
278
-        );
279
-        $PaymentDetails = array(
280
-            // Required.  Total amount of order, including shipping, handling, and tax.
281
-            'amt'          => $this->format_currency($payment->amount()),
282
-            // Required.  Three-letter currency code.  Default is USD.
283
-            'currencycode' => $payment->currency_code(),
284
-            // Required if you include itemized cart details. (L_AMTn, etc.)
285
-            //Subtotal of items not including S&H, or tax.
286
-            'itemamt'      => $this->format_currency($item_amount),//
287
-            // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
288
-            'shippingamt'  => '',
289
-            // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
290
-            'handlingamt'  => '',
291
-            // Required if you specify itemized cart tax details.
292
-            // Sum of tax for all items on the order.  Total sales tax.
293
-            'taxamt'       => $this->format_currency($tax_amount),
294
-            // Description of the order the customer is purchasing.  127 char max.
295
-            'desc'         => $order_description,
296
-            // Free-form field for your own use.  256 char max.
297
-            'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
298
-            // Your own invoice or tracking number
299
-            'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
300
-            // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
301
-            'notifyurl'    => '',
302
-            'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
303
-        );
304
-        // Wrap all data arrays into a single, "master" array which will be passed into the class function.
305
-        $PayPalRequestData = array(
306
-            'DPFields'        => $DPFields,
307
-            'CCDetails'       => $CCDetails,
308
-            'PayerInfo'       => $PayerInfo,
309
-            'PayerName'       => $PayerName,
310
-            'BillingAddress'  => $BillingAddress,
311
-            'ShippingAddress' => $ShippingAddress,
312
-            'PaymentDetails'  => $PaymentDetails,
313
-            'OrderItems'      => $order_items,
314
-        );
315
-        $this->_log_clean_request($PayPalRequestData, $payment);
316
-        try {
317
-            $PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
318
-            //remove PCI-sensitive data so it doesn't get stored
319
-            $PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
320
-            $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
321
-            if (empty($PayPalResult['RAWRESPONSE'])) {
322
-                $payment->set_status($this->_pay_model->failed_status());
323
-                $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
324
-                $payment->set_details($PayPalResult);
325
-            } else {
326
-                if ($this->_APICallSuccessful($PayPalResult)) {
327
-                    $payment->set_status($this->_pay_model->approved_status());
328
-                } else {
329
-                    $payment->set_status($this->_pay_model->declined_status());
330
-                }
331
-                //make sure we interpret the AMT as a float, not an international string
332
-                // (where periods are thousand separators)
333
-                $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
334
-                $payment->set_gateway_response($message);
335
-                $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
336
-                    ? $PayPalResult['TRANSACTIONID']
337
-                    : null);
338
-                $primary_registration_code = $primary_registrant instanceof EE_Registration
339
-                    ? $primary_registrant->reg_code()
340
-                    : '';
341
-                $payment->set_extra_accntng($primary_registration_code);
342
-                $payment->set_details($PayPalResult);
343
-            }
344
-        } catch (Exception $e) {
345
-            $payment->set_status($this->_pay_model->failed_status());
346
-            $payment->set_gateway_response($e->getMessage());
347
-        }
348
-        //$payment->set_status( $this->_pay_model->declined_status() );
349
-        //$payment->set_gateway_response( '' );
350
-        return $payment;
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * CLeans out sensitive CC data and then logs it, and returns the cleaned request
357
-     *
358
-     * @param array       $request
359
-     * @param EEI_Payment $payment
360
-     * @return void
361
-     */
362
-    private function _log_clean_request($request, $payment)
363
-    {
364
-        $cleaned_request_data = $request;
365
-        unset($cleaned_request_data['CCDetails']['acct']);
366
-        unset($cleaned_request_data['CCDetails']['cvv2']);
367
-        unset($cleaned_request_data['CCDetails']['expdate']);
368
-        $this->log(array('Paypal Request' => $cleaned_request_data), $payment);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Cleans the response, logs it, and returns it
375
-     *
376
-     * @param array       $response
377
-     * @param EEI_Payment $payment
378
-     * @return array cleaned
379
-     */
380
-    private function _log_clean_response($response, $payment)
381
-    {
382
-        unset($response['REQUESTDATA']['CREDITCARDTYPE']);
383
-        unset($response['REQUESTDATA']['ACCT']);
384
-        unset($response['REQUESTDATA']['EXPDATE']);
385
-        unset($response['REQUESTDATA']['CVV2']);
386
-        unset($response['RAWREQUEST']);
387
-        $this->log(array('Paypal Response' => $response), $payment);
388
-        return $response;
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     * @param $DataArray
395
-     * @return array
396
-     */
397
-    private function prep_and_curl_request($DataArray)
398
-    {
399
-        // Create empty holders for each portion of the NVP string
400
-        $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
401
-        $CCDetailsNVP = '';
402
-        $PayerInfoNVP = '';
403
-        $PayerNameNVP = '';
404
-        $BillingAddressNVP = '';
405
-        $ShippingAddressNVP = '';
406
-        $PaymentDetailsNVP = '';
407
-        $OrderItemsNVP = '';
408
-        $Secure3DNVP = '';
409
-        // DP Fields
410
-        $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
411
-        foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
412
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
413
-        }
414
-        // CC Details Fields
415
-        $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
416
-        foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
417
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
418
-        }
419
-        // PayerInfo Type Fields
420
-        $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
421
-        foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
422
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
423
-        }
424
-        // Payer Name Fields
425
-        $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
426
-        foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
427
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
428
-        }
429
-        // Address Fields (Billing)
430
-        $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
431
-        foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
432
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
433
-        }
434
-        // Payment Details Type Fields
435
-        $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
436
-        foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
437
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
438
-        }
439
-        // Payment Details Item Type Fields
440
-        $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
441
-        $n = 0;
442
-        foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
443
-            $CurrentItem = $OrderItems[$OrderItemsVar];
444
-            foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
445
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
446
-            }
447
-            $n++;
448
-        }
449
-        // Ship To Address Fields
450
-        $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
451
-        foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
452
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
453
-        }
454
-        // 3D Secure Fields
455
-        $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
456
-        foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
457
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
458
-        }
459
-        // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
460
-        $NVPRequest = 'USER='
461
-                      . $this->_username
462
-                      . '&PWD='
463
-                      . $this->_password
464
-                      . '&VERSION=64.0'
465
-                      . '&SIGNATURE='
466
-                      . $this->_signature
467
-                      . $DPFieldsNVP
468
-                      . $CCDetailsNVP
469
-                      . $PayerInfoNVP
470
-                      . $PayerNameNVP
471
-                      . $BillingAddressNVP
472
-                      . $PaymentDetailsNVP
473
-                      . $OrderItemsNVP
474
-                      . $ShippingAddressNVP
475
-                      . $Secure3DNVP;
476
-        $NVPResponse = $this->_CURLRequest($NVPRequest);
477
-        $NVPRequestArray = $this->_NVPToArray($NVPRequest);
478
-        $NVPResponseArray = $this->_NVPToArray($NVPResponse);
479
-        $Errors = $this->_GetErrors($NVPResponseArray);
480
-        $NVPResponseArray['ERRORS'] = $Errors;
481
-        $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
482
-        $NVPResponseArray['RAWREQUEST'] = $NVPRequest;
483
-        $NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
484
-        return $NVPResponseArray;
485
-    }
486
-
487
-
488
-
489
-    /**
490
-     * @param $Request
491
-     * @return mixed
492
-     */
493
-    private function _CURLRequest($Request)
494
-    {
495
-        $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
496
-        $curl = curl_init();
497
-        curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
498
-        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
499
-        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
500
-        curl_setopt($curl, CURLOPT_URL, $EndPointURL);
501
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
502
-        curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
503
-        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
504
-        //execute the curl POST
505
-        $Response = curl_exec($curl);
506
-        curl_close($curl);
507
-        return $Response;
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param $NVPString
514
-     * @return array
515
-     */
516
-    private function _NVPToArray($NVPString)
517
-    {
518
-        // prepare responses into array
519
-        $proArray = array();
520
-        while (strlen($NVPString)) {
521
-            // name
522
-            $keypos = strpos($NVPString, '=');
523
-            $keyval = substr($NVPString, 0, $keypos);
524
-            // value
525
-            $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
526
-            $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
527
-            // decoding the response
528
-            $proArray[$keyval] = urldecode($valval);
529
-            $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
530
-        }
531
-        return $proArray;
532
-    }
533
-
534
-
535
-
536
-    /**
537
-     * @param array $PayPalResult
538
-     * @return bool
539
-     */
540
-    private function _APICallSuccessful($PayPalResult)
541
-    {
542
-        $approved = false;
543
-        // check main response message from PayPal
544
-        if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
545
-            $ack = strtoupper($PayPalResult['ACK']);
546
-            $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
547
-        }
548
-        return $approved;
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * @param $DataArray
555
-     * @return array
556
-     */
557
-    private function _GetErrors($DataArray)
558
-    {
559
-        $Errors = array();
560
-        $n = 0;
561
-        while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
562
-            $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
563
-            $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . ''])
564
-                ? $DataArray['L_SHORTMESSAGE' . $n . '']
565
-                : '';
566
-            $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . ''])
567
-                ? $DataArray['L_LONGMESSAGE' . $n . '']
568
-                : '';
569
-            $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . ''])
570
-                ? $DataArray['L_SEVERITYCODE' . $n . '']
571
-                : '';
572
-            $CurrentItem = array(
573
-                'L_ERRORCODE'    => $LErrorCode,
574
-                'L_SHORTMESSAGE' => $LShortMessage,
575
-                'L_LONGMESSAGE'  => $LLongMessage,
576
-                'L_SEVERITYCODE' => $LSeverityCode,
577
-            );
578
-            array_push($Errors, $CurrentItem);
579
-            $n++;
580
-        }
581
-        return $Errors;
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     *        nothing to see here...  move along....
588
-     *
589
-     * @access protected
590
-     * @param $Errors
591
-     * @return string
592
-     */
593
-    private function _DisplayErrors($Errors)
594
-    {
595
-        $error = '';
596
-        foreach ($Errors as $ErrorVar => $ErrorVal) {
597
-            $CurrentError = $Errors[$ErrorVar];
598
-            foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
599
-                $CurrentVarName = '';
600
-                if ($CurrentErrorVar == 'L_ERRORCODE') {
601
-                    $CurrentVarName = 'Error Code';
602
-                } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
603
-                    $CurrentVarName = 'Short Message';
604
-                } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
605
-                    $CurrentVarName = 'Long Message';
606
-                } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
607
-                    $CurrentVarName = 'Severity Code';
608
-                }
609
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
610
-            }
611
-        }
612
-        return $error;
613
-    }
28
+	/**
29
+	 * @var $_paypal_api_username string
30
+	 */
31
+	protected $_username = null;
32
+
33
+	/**
34
+	 * @var $_password string
35
+	 */
36
+	protected $_password = null;
37
+
38
+	/**
39
+	 * @var $_signature string
40
+	 */
41
+	protected $_signature = null;
42
+
43
+	/**
44
+	 * @var $_credit_card_types array with the keys for credit card types accepted on this account
45
+	 */
46
+	protected $_credit_card_types    = null;
47
+
48
+	protected $_currencies_supported = array(
49
+		'USD',
50
+		'GBP',
51
+		'CAD',
52
+		'AUD',
53
+		'BRL',
54
+		'CHF',
55
+		'CZK',
56
+		'DKK',
57
+		'EUR',
58
+		'HKD',
59
+		'HUF',
60
+		'ILS',
61
+		'JPY',
62
+		'MXN',
63
+		'MYR',
64
+		'NOK',
65
+		'NZD',
66
+		'PHP',
67
+		'PLN',
68
+		'SEK',
69
+		'SGD',
70
+		'THB',
71
+		'TRY',
72
+		'TWD',
73
+		'RUB',
74
+	);
75
+
76
+
77
+
78
+	/**
79
+	 * @param EEI_Payment $payment
80
+	 * @param array       $billing_info {
81
+	 * @type string $credit_card
82
+	 * @type string $credit_card_type
83
+	 * @type string $exp_month always 2 characters
84
+	 * @type string $exp_year always 4 characters
85
+	 * @type string $cvv
86
+	 * }
87
+	 * @see      parent::do_direct_payment for more info
88
+	 * @return EE_Payment|EEI_Payment
89
+	 * @throws EE_Error
90
+	 */
91
+	public function do_direct_payment($payment, $billing_info = null)
92
+	{
93
+		$transaction = $payment->transaction();
94
+		if (! $transaction instanceof EEI_Transaction) {
95
+			throw new EE_Error(
96
+				esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
97
+			);
98
+		}
99
+		$primary_registrant = $transaction->primary_registration();
100
+		if (! $primary_registrant instanceof EEI_Registration) {
101
+			throw new EE_Error(
102
+				esc_html__(
103
+					'No primary registration on transaction while paying with PayPal Pro.',
104
+					'event_espresso'
105
+				)
106
+			);
107
+		}
108
+		$attendee = $primary_registrant->attendee();
109
+		if (! $attendee instanceof EEI_Attendee) {
110
+			throw new EE_Error(
111
+				esc_html__(
112
+					'No attendee on primary registration while paying with PayPal Pro.',
113
+					'event_espresso'
114
+				)
115
+			);
116
+		}
117
+		$order_description = substr($this->_format_order_description($payment), 0, 127);
118
+		//charge for the full amount. Show itemized list
119
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
120
+			$item_num = 1;
121
+			$total_line_item = $transaction->total_line_item();
122
+			$order_items = array();
123
+			foreach ($total_line_item->get_items() as $line_item) {
124
+				//ignore line items with a quantity of 0
125
+				if ($line_item->quantity() == 0) {
126
+					continue;
127
+				}
128
+				$item = array(
129
+					// Item Name.  127 char max.
130
+					'l_name'                 => substr(
131
+						$this->_format_line_item_name($line_item, $payment),
132
+						0,
133
+						127
134
+					),
135
+					// Item description.  127 char max.
136
+					'l_desc'                 => substr(
137
+						$this->_format_line_item_desc($line_item, $payment),
138
+						0,
139
+						127
140
+					),
141
+					// Cost of individual item.
142
+					'l_amt'                  => $line_item->unit_price(),
143
+					// Item Number.  127 char max.
144
+					'l_number'               => $item_num++,
145
+					// Item quantity.  Must be any positive integer.
146
+					'l_qty'                  => $line_item->quantity(),
147
+					// Item's sales tax amount.
148
+					'l_taxamt'               => '',
149
+					// eBay auction number of item.
150
+					'l_ebayitemnumber'       => '',
151
+					// eBay transaction ID of purchased item.
152
+					'l_ebayitemauctiontxnid' => '',
153
+					// eBay order ID for the item.
154
+					'l_ebayitemorderid'      => '',
155
+				);
156
+				// add to array of all items
157
+				array_push($order_items, $item);
158
+			}
159
+			$item_amount = $total_line_item->get_items_total();
160
+			$tax_amount = $total_line_item->get_total_tax();
161
+		} else {
162
+			$order_items = array();
163
+			$item_amount = $payment->amount();
164
+			$tax_amount = 0;
165
+			array_push($order_items, array(
166
+				// Item Name.  127 char max.
167
+				'l_name'   => substr(
168
+					$this->_format_partial_payment_line_item_name($payment),
169
+					0,
170
+					127
171
+				),
172
+				// Item description.  127 char max.
173
+				'l_desc'   => substr(
174
+					$this->_format_partial_payment_line_item_desc($payment),
175
+					0,
176
+					127
177
+				),
178
+				// Cost of individual item.
179
+				'l_amt'    => $payment->amount(),
180
+				// Item Number.  127 char max.
181
+				'l_number' => 1,
182
+				// Item quantity.  Must be any positive integer.
183
+				'l_qty'    => 1,
184
+			));
185
+		}
186
+		// Populate data arrays with order data.
187
+		$DPFields = array(
188
+			// How you want to obtain payment ?
189
+			// Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture.
190
+			// Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
191
+			'paymentaction'    => 'Sale',
192
+			// Required.  IP address of the payer's browser.
193
+			'ipaddress'        => $_SERVER['REMOTE_ADDR'],
194
+			// Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
195
+			'returnfmfdetails' => '1',
196
+		);
197
+		$CCDetails = array(
198
+			// Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
199
+			// If Maestro or Solo, the currency code must be GBP.
200
+			//  In addition, either start date or issue number must be specified.
201
+			'creditcardtype' => $billing_info['credit_card_type'],
202
+			// Required.  Credit card number.  No spaces or punctuation.
203
+			'acct'           => $billing_info['credit_card'],
204
+			// Required.  Credit card expiration date.  Format is MMYYYY
205
+			'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
206
+			// Requirements determined by your PayPal account settings.  Security digits for credit card.
207
+			'cvv2'           => $billing_info['cvv'],
208
+		);
209
+		$PayerInfo = array(
210
+			// Email address of payer.
211
+			'email'       => $billing_info['email'],
212
+			// Unique PayPal customer ID for payer.
213
+			'payerid'     => '',
214
+			// Status of payer.  Values are verified or unverified
215
+			'payerstatus' => '',
216
+			// Payer's business name.
217
+			'business'    => '',
218
+		);
219
+		$PayerName = array(
220
+			// Payer's salutation.  20 char max.
221
+			'salutation' => '',
222
+			// Payer's first name.  25 char max.
223
+			'firstname'  => substr($billing_info['first_name'], 0, 25),
224
+			// Payer's middle name.  25 char max.
225
+			'middlename' => '',
226
+			// Payer's last name.  25 char max.
227
+			'lastname'   => substr($billing_info['last_name'], 0, 25),
228
+			// Payer's suffix.  12 char max.
229
+			'suffix'     => '',
230
+		);
231
+		$BillingAddress = array(
232
+			// Required.  First street address.
233
+			'street'      => $billing_info['address'],
234
+			// Second street address.
235
+			'street2'     => $billing_info['address2'],
236
+			// Required.  Name of City.
237
+			'city'        => $billing_info['city'],
238
+			// Required. Name of State or Province.
239
+			'state'       => substr($billing_info['state'], 0, 40),
240
+			// Required.  Country code.
241
+			'countrycode' => $billing_info['country'],
242
+			// Required.  Postal code of payer.
243
+			'zip'         => $billing_info['zip'],
244
+		);
245
+		//check if the registration info contains the needed fields for paypal pro
246
+		//(see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
247
+		if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
248
+			$use_registration_address_info = true;
249
+		} else {
250
+			$use_registration_address_info = false;
251
+		}
252
+		//so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
253
+		// If not, use the billing info again
254
+		$ShippingAddress = array(
255
+			'shiptoname'     => substr($use_registration_address_info
256
+				? $attendee->full_name()
257
+				: $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
258
+			'shiptostreet'   => substr($use_registration_address_info
259
+				? $attendee->address()
260
+				: $billing_info['address'], 0, 100),
261
+			'shiptostreet2'  => substr($use_registration_address_info
262
+				? $attendee->address2() : $billing_info['address2'], 0, 100),
263
+			'shiptocity'     => substr($use_registration_address_info
264
+				? $attendee->city()
265
+				: $billing_info['city'], 0, 40),
266
+			'state'          => substr($use_registration_address_info
267
+				? $attendee->state_name()
268
+				: $billing_info['state'], 0, 40),
269
+			'shiptocountry'  => $use_registration_address_info
270
+				? $attendee->country_ID()
271
+				: $billing_info['country'],
272
+			'shiptozip'      => substr($use_registration_address_info
273
+				? $attendee->zip()
274
+				: $billing_info['zip'], 0, 20),
275
+			'shiptophonenum' => substr($use_registration_address_info
276
+				? $attendee->phone()
277
+				: $billing_info['phone'], 0, 20),
278
+		);
279
+		$PaymentDetails = array(
280
+			// Required.  Total amount of order, including shipping, handling, and tax.
281
+			'amt'          => $this->format_currency($payment->amount()),
282
+			// Required.  Three-letter currency code.  Default is USD.
283
+			'currencycode' => $payment->currency_code(),
284
+			// Required if you include itemized cart details. (L_AMTn, etc.)
285
+			//Subtotal of items not including S&H, or tax.
286
+			'itemamt'      => $this->format_currency($item_amount),//
287
+			// Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
288
+			'shippingamt'  => '',
289
+			// Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
290
+			'handlingamt'  => '',
291
+			// Required if you specify itemized cart tax details.
292
+			// Sum of tax for all items on the order.  Total sales tax.
293
+			'taxamt'       => $this->format_currency($tax_amount),
294
+			// Description of the order the customer is purchasing.  127 char max.
295
+			'desc'         => $order_description,
296
+			// Free-form field for your own use.  256 char max.
297
+			'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
298
+			// Your own invoice or tracking number
299
+			'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
300
+			// URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
301
+			'notifyurl'    => '',
302
+			'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
303
+		);
304
+		// Wrap all data arrays into a single, "master" array which will be passed into the class function.
305
+		$PayPalRequestData = array(
306
+			'DPFields'        => $DPFields,
307
+			'CCDetails'       => $CCDetails,
308
+			'PayerInfo'       => $PayerInfo,
309
+			'PayerName'       => $PayerName,
310
+			'BillingAddress'  => $BillingAddress,
311
+			'ShippingAddress' => $ShippingAddress,
312
+			'PaymentDetails'  => $PaymentDetails,
313
+			'OrderItems'      => $order_items,
314
+		);
315
+		$this->_log_clean_request($PayPalRequestData, $payment);
316
+		try {
317
+			$PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
318
+			//remove PCI-sensitive data so it doesn't get stored
319
+			$PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
320
+			$message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
321
+			if (empty($PayPalResult['RAWRESPONSE'])) {
322
+				$payment->set_status($this->_pay_model->failed_status());
323
+				$payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
324
+				$payment->set_details($PayPalResult);
325
+			} else {
326
+				if ($this->_APICallSuccessful($PayPalResult)) {
327
+					$payment->set_status($this->_pay_model->approved_status());
328
+				} else {
329
+					$payment->set_status($this->_pay_model->declined_status());
330
+				}
331
+				//make sure we interpret the AMT as a float, not an international string
332
+				// (where periods are thousand separators)
333
+				$payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
334
+				$payment->set_gateway_response($message);
335
+				$payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
336
+					? $PayPalResult['TRANSACTIONID']
337
+					: null);
338
+				$primary_registration_code = $primary_registrant instanceof EE_Registration
339
+					? $primary_registrant->reg_code()
340
+					: '';
341
+				$payment->set_extra_accntng($primary_registration_code);
342
+				$payment->set_details($PayPalResult);
343
+			}
344
+		} catch (Exception $e) {
345
+			$payment->set_status($this->_pay_model->failed_status());
346
+			$payment->set_gateway_response($e->getMessage());
347
+		}
348
+		//$payment->set_status( $this->_pay_model->declined_status() );
349
+		//$payment->set_gateway_response( '' );
350
+		return $payment;
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * CLeans out sensitive CC data and then logs it, and returns the cleaned request
357
+	 *
358
+	 * @param array       $request
359
+	 * @param EEI_Payment $payment
360
+	 * @return void
361
+	 */
362
+	private function _log_clean_request($request, $payment)
363
+	{
364
+		$cleaned_request_data = $request;
365
+		unset($cleaned_request_data['CCDetails']['acct']);
366
+		unset($cleaned_request_data['CCDetails']['cvv2']);
367
+		unset($cleaned_request_data['CCDetails']['expdate']);
368
+		$this->log(array('Paypal Request' => $cleaned_request_data), $payment);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Cleans the response, logs it, and returns it
375
+	 *
376
+	 * @param array       $response
377
+	 * @param EEI_Payment $payment
378
+	 * @return array cleaned
379
+	 */
380
+	private function _log_clean_response($response, $payment)
381
+	{
382
+		unset($response['REQUESTDATA']['CREDITCARDTYPE']);
383
+		unset($response['REQUESTDATA']['ACCT']);
384
+		unset($response['REQUESTDATA']['EXPDATE']);
385
+		unset($response['REQUESTDATA']['CVV2']);
386
+		unset($response['RAWREQUEST']);
387
+		$this->log(array('Paypal Response' => $response), $payment);
388
+		return $response;
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 * @param $DataArray
395
+	 * @return array
396
+	 */
397
+	private function prep_and_curl_request($DataArray)
398
+	{
399
+		// Create empty holders for each portion of the NVP string
400
+		$DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
401
+		$CCDetailsNVP = '';
402
+		$PayerInfoNVP = '';
403
+		$PayerNameNVP = '';
404
+		$BillingAddressNVP = '';
405
+		$ShippingAddressNVP = '';
406
+		$PaymentDetailsNVP = '';
407
+		$OrderItemsNVP = '';
408
+		$Secure3DNVP = '';
409
+		// DP Fields
410
+		$DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
411
+		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
412
+			$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
413
+		}
414
+		// CC Details Fields
415
+		$CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
416
+		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
417
+			$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
418
+		}
419
+		// PayerInfo Type Fields
420
+		$PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
421
+		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
422
+			$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
423
+		}
424
+		// Payer Name Fields
425
+		$PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
426
+		foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
427
+			$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
428
+		}
429
+		// Address Fields (Billing)
430
+		$BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
431
+		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
432
+			$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
433
+		}
434
+		// Payment Details Type Fields
435
+		$PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
436
+		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
437
+			$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
438
+		}
439
+		// Payment Details Item Type Fields
440
+		$OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
441
+		$n = 0;
442
+		foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
443
+			$CurrentItem = $OrderItems[$OrderItemsVar];
444
+			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
445
+				$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
446
+			}
447
+			$n++;
448
+		}
449
+		// Ship To Address Fields
450
+		$ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
451
+		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
452
+			$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
453
+		}
454
+		// 3D Secure Fields
455
+		$Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
456
+		foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
457
+			$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
458
+		}
459
+		// Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
460
+		$NVPRequest = 'USER='
461
+					  . $this->_username
462
+					  . '&PWD='
463
+					  . $this->_password
464
+					  . '&VERSION=64.0'
465
+					  . '&SIGNATURE='
466
+					  . $this->_signature
467
+					  . $DPFieldsNVP
468
+					  . $CCDetailsNVP
469
+					  . $PayerInfoNVP
470
+					  . $PayerNameNVP
471
+					  . $BillingAddressNVP
472
+					  . $PaymentDetailsNVP
473
+					  . $OrderItemsNVP
474
+					  . $ShippingAddressNVP
475
+					  . $Secure3DNVP;
476
+		$NVPResponse = $this->_CURLRequest($NVPRequest);
477
+		$NVPRequestArray = $this->_NVPToArray($NVPRequest);
478
+		$NVPResponseArray = $this->_NVPToArray($NVPResponse);
479
+		$Errors = $this->_GetErrors($NVPResponseArray);
480
+		$NVPResponseArray['ERRORS'] = $Errors;
481
+		$NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
482
+		$NVPResponseArray['RAWREQUEST'] = $NVPRequest;
483
+		$NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
484
+		return $NVPResponseArray;
485
+	}
486
+
487
+
488
+
489
+	/**
490
+	 * @param $Request
491
+	 * @return mixed
492
+	 */
493
+	private function _CURLRequest($Request)
494
+	{
495
+		$EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
496
+		$curl = curl_init();
497
+		curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
498
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
499
+		curl_setopt($curl, CURLOPT_TIMEOUT, 60);
500
+		curl_setopt($curl, CURLOPT_URL, $EndPointURL);
501
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
502
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
503
+		curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
504
+		//execute the curl POST
505
+		$Response = curl_exec($curl);
506
+		curl_close($curl);
507
+		return $Response;
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param $NVPString
514
+	 * @return array
515
+	 */
516
+	private function _NVPToArray($NVPString)
517
+	{
518
+		// prepare responses into array
519
+		$proArray = array();
520
+		while (strlen($NVPString)) {
521
+			// name
522
+			$keypos = strpos($NVPString, '=');
523
+			$keyval = substr($NVPString, 0, $keypos);
524
+			// value
525
+			$valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
526
+			$valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
527
+			// decoding the response
528
+			$proArray[$keyval] = urldecode($valval);
529
+			$NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
530
+		}
531
+		return $proArray;
532
+	}
533
+
534
+
535
+
536
+	/**
537
+	 * @param array $PayPalResult
538
+	 * @return bool
539
+	 */
540
+	private function _APICallSuccessful($PayPalResult)
541
+	{
542
+		$approved = false;
543
+		// check main response message from PayPal
544
+		if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
545
+			$ack = strtoupper($PayPalResult['ACK']);
546
+			$approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
547
+		}
548
+		return $approved;
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * @param $DataArray
555
+	 * @return array
556
+	 */
557
+	private function _GetErrors($DataArray)
558
+	{
559
+		$Errors = array();
560
+		$n = 0;
561
+		while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
562
+			$LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
563
+			$LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . ''])
564
+				? $DataArray['L_SHORTMESSAGE' . $n . '']
565
+				: '';
566
+			$LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . ''])
567
+				? $DataArray['L_LONGMESSAGE' . $n . '']
568
+				: '';
569
+			$LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . ''])
570
+				? $DataArray['L_SEVERITYCODE' . $n . '']
571
+				: '';
572
+			$CurrentItem = array(
573
+				'L_ERRORCODE'    => $LErrorCode,
574
+				'L_SHORTMESSAGE' => $LShortMessage,
575
+				'L_LONGMESSAGE'  => $LLongMessage,
576
+				'L_SEVERITYCODE' => $LSeverityCode,
577
+			);
578
+			array_push($Errors, $CurrentItem);
579
+			$n++;
580
+		}
581
+		return $Errors;
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 *        nothing to see here...  move along....
588
+	 *
589
+	 * @access protected
590
+	 * @param $Errors
591
+	 * @return string
592
+	 */
593
+	private function _DisplayErrors($Errors)
594
+	{
595
+		$error = '';
596
+		foreach ($Errors as $ErrorVar => $ErrorVal) {
597
+			$CurrentError = $Errors[$ErrorVar];
598
+			foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
599
+				$CurrentVarName = '';
600
+				if ($CurrentErrorVar == 'L_ERRORCODE') {
601
+					$CurrentVarName = 'Error Code';
602
+				} elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
603
+					$CurrentVarName = 'Short Message';
604
+				} elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
605
+					$CurrentVarName = 'Long Message';
606
+				} elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
607
+					$CurrentVarName = 'Severity Code';
608
+				}
609
+				$error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
610
+			}
611
+		}
612
+		return $error;
613
+	}
614 614
 }
615 615
 // End of file EEG_Paypal_Pro.gateway.php
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
     public function do_direct_payment($payment, $billing_info = null)
92 92
     {
93 93
         $transaction = $payment->transaction();
94
-        if (! $transaction instanceof EEI_Transaction) {
94
+        if ( ! $transaction instanceof EEI_Transaction) {
95 95
             throw new EE_Error(
96 96
                 esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
97 97
             );
98 98
         }
99 99
         $primary_registrant = $transaction->primary_registration();
100
-        if (! $primary_registrant instanceof EEI_Registration) {
100
+        if ( ! $primary_registrant instanceof EEI_Registration) {
101 101
             throw new EE_Error(
102 102
                 esc_html__(
103 103
                     'No primary registration on transaction while paying with PayPal Pro.',
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
             );
107 107
         }
108 108
         $attendee = $primary_registrant->attendee();
109
-        if (! $attendee instanceof EEI_Attendee) {
109
+        if ( ! $attendee instanceof EEI_Attendee) {
110 110
             throw new EE_Error(
111 111
                 esc_html__(
112 112
                     'No attendee on primary registration while paying with PayPal Pro.',
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             // Required.  Credit card number.  No spaces or punctuation.
203 203
             'acct'           => $billing_info['credit_card'],
204 204
             // Required.  Credit card expiration date.  Format is MMYYYY
205
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
205
+            'expdate'        => $billing_info['exp_month'].$billing_info['exp_year'],
206 206
             // Requirements determined by your PayPal account settings.  Security digits for credit card.
207 207
             'cvv2'           => $billing_info['cvv'],
208 208
         );
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         $ShippingAddress = array(
255 255
             'shiptoname'     => substr($use_registration_address_info
256 256
                 ? $attendee->full_name()
257
-                : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
257
+                : $billing_info['first_name'].' '.$billing_info['last_name'], 0, 32),
258 258
             'shiptostreet'   => substr($use_registration_address_info
259 259
                 ? $attendee->address()
260 260
                 : $billing_info['address'], 0, 100),
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
             'currencycode' => $payment->currency_code(),
284 284
             // Required if you include itemized cart details. (L_AMTn, etc.)
285 285
             //Subtotal of items not including S&H, or tax.
286
-            'itemamt'      => $this->format_currency($item_amount),//
286
+            'itemamt'      => $this->format_currency($item_amount), //
287 287
             // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
288 288
             'shippingamt'  => '',
289 289
             // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
             // Free-form field for your own use.  256 char max.
297 297
             'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
298 298
             // Your own invoice or tracking number
299
-            'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
299
+            'invnum'       => wp_generate_password(12, false), //$transaction->ID(),
300 300
             // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
301 301
             'notifyurl'    => '',
302
-            'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
302
+            'buttonsource' => 'EventEspresso_SP', //EE will blow up if you change this
303 303
         );
304 304
         // Wrap all data arrays into a single, "master" array which will be passed into the class function.
305 305
         $PayPalRequestData = array(
@@ -409,32 +409,32 @@  discard block
 block discarded – undo
409 409
         // DP Fields
410 410
         $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
411 411
         foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
412
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
412
+            $DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal);
413 413
         }
414 414
         // CC Details Fields
415 415
         $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
416 416
         foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
417
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
417
+            $CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal);
418 418
         }
419 419
         // PayerInfo Type Fields
420 420
         $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
421 421
         foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
422
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
422
+            $PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal);
423 423
         }
424 424
         // Payer Name Fields
425 425
         $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
426 426
         foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
427
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
427
+            $PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal);
428 428
         }
429 429
         // Address Fields (Billing)
430 430
         $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
431 431
         foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
432
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
432
+            $BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal);
433 433
         }
434 434
         // Payment Details Type Fields
435 435
         $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
436 436
         foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
437
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
437
+            $PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal);
438 438
         }
439 439
         // Payment Details Item Type Fields
440 440
         $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
@@ -442,19 +442,19 @@  discard block
 block discarded – undo
442 442
         foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
443 443
             $CurrentItem = $OrderItems[$OrderItemsVar];
444 444
             foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
445
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
445
+                $OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal);
446 446
             }
447 447
             $n++;
448 448
         }
449 449
         // Ship To Address Fields
450 450
         $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
451 451
         foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
452
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
452
+            $ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal);
453 453
         }
454 454
         // 3D Secure Fields
455 455
         $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
456 456
         foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
457
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
457
+            $Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal);
458 458
         }
459 459
         // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
460 460
         $NVPRequest = 'USER='
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
     {
559 559
         $Errors = array();
560 560
         $n = 0;
561
-        while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
562
-            $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
563
-            $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . ''])
564
-                ? $DataArray['L_SHORTMESSAGE' . $n . '']
561
+        while (isset($DataArray['L_ERRORCODE'.$n.''])) {
562
+            $LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : '';
563
+            $LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.''])
564
+                ? $DataArray['L_SHORTMESSAGE'.$n.'']
565 565
                 : '';
566
-            $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . ''])
567
-                ? $DataArray['L_LONGMESSAGE' . $n . '']
566
+            $LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.''])
567
+                ? $DataArray['L_LONGMESSAGE'.$n.'']
568 568
                 : '';
569
-            $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . ''])
570
-                ? $DataArray['L_SEVERITYCODE' . $n . '']
569
+            $LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.''])
570
+                ? $DataArray['L_SEVERITYCODE'.$n.'']
571 571
                 : '';
572 572
             $CurrentItem = array(
573 573
                 'L_ERRORCODE'    => $LErrorCode,
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
                 } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
607 607
                     $CurrentVarName = 'Severity Code';
608 608
                 }
609
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
609
+                $error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal;
610 610
             }
611 611
         }
612 612
         return $error;
Please login to merge, or discard this patch.
core/services/cache/BasicCacheManager.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -19,118 +19,118 @@
 block discarded – undo
19 19
 class BasicCacheManager implements CacheManagerInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @type string
24
-     */
25
-    const CACHE_PREFIX = 'ee_cache_';
26
-
27
-    /**
28
-     * set to true to monitor when content is being served from cache or not
29
-     *
30
-     * @type boolean
31
-     */
32
-    const DEBUG = false;
33
-
34
-    /**
35
-     * @var CacheStorageInterface $cache_storage
36
-     */
37
-    private $cache_storage;
38
-
39
-
40
-
41
-    /**
42
-     * BasicCacheManager constructor.
43
-     *
44
-     * @param CacheStorageInterface $cache_storage [required]
45
-     */
46
-    public function __construct(CacheStorageInterface $cache_storage)
47
-    {
48
-        $this->cache_storage = $cache_storage;
49
-    }
50
-
51
-
52
-
53
-    /**
54
-     * returns a string that will be prepended to all cache identifiers
55
-     *
56
-     * @return string
57
-     */
58
-    public function cachePrefix()
59
-    {
60
-        return BasicCacheManager::CACHE_PREFIX;
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * @param string  $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types.
67
-     *                           May also be helpful to include an additional specific identifier,
68
-     *                           such as a post ID as part of the $id_prefix so that individual caches
69
-     *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
70
-     *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
71
-     * @param string  $cache_id  [required] Additional identifying details that make this cache unique.
72
-     *                           It is advisable to use some of the actual data
73
-     *                           that is used to generate the content being cached,
74
-     *                           in order to guarantee that the cache id is unique for that content.
75
-     *                           The cache id will be md5'd before usage to make it more db friendly,
76
-     *                           and the entire cache id string will be truncated to 190 characters.
77
-     * @param Closure $callback  [required] since the point of caching is to avoid generating content when not
78
-     *                           necessary,
79
-     *                           we wrap our content creation in a Closure so that it is not executed until needed.
80
-     * @param int     $expiration
81
-     * @return Closure|mixed
82
-     */
83
-    public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS)
84
-    {
85
-        $content = '';
86
-        // how long should we cache this content for? 0 means no caching.
87
-        $expiration = ! WP_DEBUG ? $expiration : 0;
88
-        $expiration = absint(
89
-            apply_filters(
90
-                'FHEE__CacheManager__get__cache_expiration',
91
-                $expiration,
92
-                $id_prefix,
93
-                $cache_id
94
-            )
95
-        );
96
-        $cache_id = substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
97
-        // is caching enabled for this content ?
98
-        if ($expiration) {
99
-            $content = $this->cache_storage->get($cache_id);
100
-        }
101
-        // any existing content ?
102
-        if (empty($content)) {
103
-            // nope! let's generate some new stuff
104
-            $content = $callback();
105
-            // save the new content if caching is enabled
106
-            if ($expiration) {
107
-                if (BasicCacheManager::DEBUG) {
108
-                    EEH_Debug_Tools::printr($cache_id, 'REFRESH CACHE', __FILE__, __LINE__);
109
-                }
110
-                $this->cache_storage->add($cache_id, $content, $expiration);
111
-            }
112
-        } else {
113
-            if (BasicCacheManager::DEBUG) {
114
-                EEH_Debug_Tools::printr($cache_id, 'CACHED CONTENT', __FILE__, __LINE__);
115
-            }
116
-        }
117
-        return $content;
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
124
-     *                               or a specific ID targeting a single cache item
125
-     * @return void
126
-     */
127
-    public function clear($cache_id)
128
-    {
129
-        // ensure incoming arg is in an array
130
-        $cache_id = is_array($cache_id) ? $cache_id : array($cache_id);
131
-        // delete corresponding transients for the supplied id prefix
132
-        $this->cache_storage->deleteMany($cache_id);
133
-    }
22
+	/**
23
+	 * @type string
24
+	 */
25
+	const CACHE_PREFIX = 'ee_cache_';
26
+
27
+	/**
28
+	 * set to true to monitor when content is being served from cache or not
29
+	 *
30
+	 * @type boolean
31
+	 */
32
+	const DEBUG = false;
33
+
34
+	/**
35
+	 * @var CacheStorageInterface $cache_storage
36
+	 */
37
+	private $cache_storage;
38
+
39
+
40
+
41
+	/**
42
+	 * BasicCacheManager constructor.
43
+	 *
44
+	 * @param CacheStorageInterface $cache_storage [required]
45
+	 */
46
+	public function __construct(CacheStorageInterface $cache_storage)
47
+	{
48
+		$this->cache_storage = $cache_storage;
49
+	}
50
+
51
+
52
+
53
+	/**
54
+	 * returns a string that will be prepended to all cache identifiers
55
+	 *
56
+	 * @return string
57
+	 */
58
+	public function cachePrefix()
59
+	{
60
+		return BasicCacheManager::CACHE_PREFIX;
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * @param string  $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types.
67
+	 *                           May also be helpful to include an additional specific identifier,
68
+	 *                           such as a post ID as part of the $id_prefix so that individual caches
69
+	 *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
70
+	 *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
71
+	 * @param string  $cache_id  [required] Additional identifying details that make this cache unique.
72
+	 *                           It is advisable to use some of the actual data
73
+	 *                           that is used to generate the content being cached,
74
+	 *                           in order to guarantee that the cache id is unique for that content.
75
+	 *                           The cache id will be md5'd before usage to make it more db friendly,
76
+	 *                           and the entire cache id string will be truncated to 190 characters.
77
+	 * @param Closure $callback  [required] since the point of caching is to avoid generating content when not
78
+	 *                           necessary,
79
+	 *                           we wrap our content creation in a Closure so that it is not executed until needed.
80
+	 * @param int     $expiration
81
+	 * @return Closure|mixed
82
+	 */
83
+	public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS)
84
+	{
85
+		$content = '';
86
+		// how long should we cache this content for? 0 means no caching.
87
+		$expiration = ! WP_DEBUG ? $expiration : 0;
88
+		$expiration = absint(
89
+			apply_filters(
90
+				'FHEE__CacheManager__get__cache_expiration',
91
+				$expiration,
92
+				$id_prefix,
93
+				$cache_id
94
+			)
95
+		);
96
+		$cache_id = substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
97
+		// is caching enabled for this content ?
98
+		if ($expiration) {
99
+			$content = $this->cache_storage->get($cache_id);
100
+		}
101
+		// any existing content ?
102
+		if (empty($content)) {
103
+			// nope! let's generate some new stuff
104
+			$content = $callback();
105
+			// save the new content if caching is enabled
106
+			if ($expiration) {
107
+				if (BasicCacheManager::DEBUG) {
108
+					EEH_Debug_Tools::printr($cache_id, 'REFRESH CACHE', __FILE__, __LINE__);
109
+				}
110
+				$this->cache_storage->add($cache_id, $content, $expiration);
111
+			}
112
+		} else {
113
+			if (BasicCacheManager::DEBUG) {
114
+				EEH_Debug_Tools::printr($cache_id, 'CACHED CONTENT', __FILE__, __LINE__);
115
+			}
116
+		}
117
+		return $content;
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
124
+	 *                               or a specific ID targeting a single cache item
125
+	 * @return void
126
+	 */
127
+	public function clear($cache_id)
128
+	{
129
+		// ensure incoming arg is in an array
130
+		$cache_id = is_array($cache_id) ? $cache_id : array($cache_id);
131
+		// delete corresponding transients for the supplied id prefix
132
+		$this->cache_storage->deleteMany($cache_id);
133
+	}
134 134
 
135 135
 
136 136
 
Please login to merge, or discard this patch.
acceptance_tests/Helpers/BaseCoreAdmin.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@
 block discarded – undo
13 13
 trait BaseCoreAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * Core method for going to an Event Espresso Admin page.
18
-     * @param string $page
19
-     * @param string $action
20
-     * @param string $additional_params
21
-     */
22
-    public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
-    {
24
-        $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
-    }
16
+	/**
17
+	 * Core method for going to an Event Espresso Admin page.
18
+	 * @param string $page
19
+	 * @param string $action
20
+	 * @param string $additional_params
21
+	 */
22
+	public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
+	{
24
+		$this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
+	}
26 26
 
27 27
 
28
-    /**
29
-     * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
-     * @return \EventEspressoAcceptanceTester;
31
-     */
32
-    protected function actor()
33
-    {
34
-        /** @var \EventEspressoAcceptanceTester $this */
35
-        return $this;
36
-    }
28
+	/**
29
+	 * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
+	 * @return \EventEspressoAcceptanceTester;
31
+	 */
32
+	protected function actor()
33
+	{
34
+		/** @var \EventEspressoAcceptanceTester $this */
35
+		return $this;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * Use this to set the per page option for a list table page.
41
-     * Assumes you are on a page that has this field exposed.
42
-     * @param int|string $per_page_value
43
-     */
44
-    public function setPerPageOptionForScreen($per_page_value)
45
-    {
46
-        $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
47
-        $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
48
-        $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
49
-        $this->actor()->wait(8);
50
-    }
39
+	/**
40
+	 * Use this to set the per page option for a list table page.
41
+	 * Assumes you are on a page that has this field exposed.
42
+	 * @param int|string $per_page_value
43
+	 */
44
+	public function setPerPageOptionForScreen($per_page_value)
45
+	{
46
+		$this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
47
+		$this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
48
+		$this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
49
+		$this->actor()->wait(8);
50
+	}
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Page/CoreAdmin.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,63 +13,63 @@
 block discarded – undo
13 13
 class CoreAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * @var string
18
-     */
19
-    const URL_PREFIX = 'admin.php?page=';
16
+	/**
17
+	 * @var string
18
+	 */
19
+	const URL_PREFIX = 'admin.php?page=';
20 20
 
21 21
 
22
-    /**
23
-     * This is the selector for the next page button on list tables.
24
-     * @var string
25
-     */
26
-    const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page';
22
+	/**
23
+	 * This is the selector for the next page button on list tables.
24
+	 * @var string
25
+	 */
26
+	const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page';
27 27
 
28 28
 
29
-    /**
30
-     * The selector for the search input submit button on list table pages
31
-     * @var string
32
-     */
33
-    const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit';
29
+	/**
30
+	 * The selector for the search input submit button on list table pages
31
+	 * @var string
32
+	 */
33
+	const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit';
34 34
 
35 35
 
36
-    /**
37
-     * Selector for the screen options dropdown.
38
-     * @var string
39
-     */
40
-    const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link';
36
+	/**
37
+	 * Selector for the screen options dropdown.
38
+	 * @var string
39
+	 */
40
+	const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link';
41 41
 
42 42
 
43
-    /**
44
-     * Selector for the per page field setting selector (found within screen options dropdown)
45
-     * @var string
46
-     */
47
-    const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page';
43
+	/**
44
+	 * Selector for the per page field setting selector (found within screen options dropdown)
45
+	 * @var string
46
+	 */
47
+	const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page';
48 48
 
49 49
 
50
-    /**
51
-     * Selector for apply screen options settings.
52
-     * @var string
53
-     */
54
-    const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply';
50
+	/**
51
+	 * Selector for apply screen options settings.
52
+	 * @var string
53
+	 */
54
+	const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply';
55 55
 
56 56
 
57
-    /**
58
-     * Get the EE admin url for the given properties.
59
-     * Note, this is JUST the endpoint for the admin route.  It is expected that the actor/test would be calling this
60
-     * with `amOnAdminPage` action.
61
-     *
62
-     * @param string $page
63
-     * @param string $action
64
-     * @param string $additional_params
65
-     * @return string
66
-     */
67
-    public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
68
-    {
69
-        $url = self::URL_PREFIX . $page;
70
-        $url .= $action ? '&action=' . $action : '';
71
-        $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
72
-        return $url;
73
-    }
57
+	/**
58
+	 * Get the EE admin url for the given properties.
59
+	 * Note, this is JUST the endpoint for the admin route.  It is expected that the actor/test would be calling this
60
+	 * with `amOnAdminPage` action.
61
+	 *
62
+	 * @param string $page
63
+	 * @param string $action
64
+	 * @param string $additional_params
65
+	 * @return string
66
+	 */
67
+	public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '')
68
+	{
69
+		$url = self::URL_PREFIX . $page;
70
+		$url .= $action ? '&action=' . $action : '';
71
+		$url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : '';
72
+		return $url;
73
+	}
74 74
 
75 75
 }
76 76
\ No newline at end of file
Please login to merge, or discard this patch.