Completed
Branch back-compat-edtr-taxes (752e0e)
by
unknown
12:08 queued 09:43
created
core/exceptions/InvalidAliasException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
 class InvalidAliasException extends DomainException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidClassException constructor.
21
-     *
22
-     * @param string    $fqcn
23
-     * @param string    $alias
24
-     * @param string    $message
25
-     * @param int       $code
26
-     * @param Exception $previous
27
-     */
28
-    public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null)
29
-    {
30
-        if (empty($message)) {
31
-            $message = sprintf(
32
-                esc_html__(
33
-                    '"%1$s" can not be used as an alias because the "%2$s"  class does not extend or implement it.',
34
-                    'event_espresso'
35
-                ),
36
-                $alias,
37
-                $fqcn
38
-            );
39
-        }
40
-        parent::__construct($message, $code, $previous);
41
-    }
19
+	/**
20
+	 * InvalidClassException constructor.
21
+	 *
22
+	 * @param string    $fqcn
23
+	 * @param string    $alias
24
+	 * @param string    $message
25
+	 * @param int       $code
26
+	 * @param Exception $previous
27
+	 */
28
+	public function __construct($fqcn, $alias, $message = '', $code = 0, Exception $previous = null)
29
+	{
30
+		if (empty($message)) {
31
+			$message = sprintf(
32
+				esc_html__(
33
+					'"%1$s" can not be used as an alias because the "%2$s"  class does not extend or implement it.',
34
+					'event_espresso'
35
+				),
36
+				$alias,
37
+				$fqcn
38
+			);
39
+		}
40
+		parent::__construct($message, $code, $previous);
41
+	}
42 42
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidInterfaceException.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -16,22 +16,22 @@
 block discarded – undo
16 16
 class InvalidInterfaceException extends DomainException
17 17
 {
18 18
 
19
-    /**
20
-     * InvalidInterfaceException constructor.
21
-     *
22
-     * @param string     $interface_name
23
-     * @param string     $message
24
-     * @param int        $code
25
-     * @param \Exception $previous
26
-     */
27
-    public function __construct($interface_name, $message = '', $code = 0, \Exception $previous = null)
28
-    {
29
-        if (empty($message)) {
30
-            $message = sprintf(
31
-                esc_html__('The "%1$s" Interface is either missing or invalid.', 'event_espresso'),
32
-                $interface_name
33
-            );
34
-        }
35
-        parent::__construct($message, $code, $previous);
36
-    }
19
+	/**
20
+	 * InvalidInterfaceException constructor.
21
+	 *
22
+	 * @param string     $interface_name
23
+	 * @param string     $message
24
+	 * @param int        $code
25
+	 * @param \Exception $previous
26
+	 */
27
+	public function __construct($interface_name, $message = '', $code = 0, \Exception $previous = null)
28
+	{
29
+		if (empty($message)) {
30
+			$message = sprintf(
31
+				esc_html__('The "%1$s" Interface is either missing or invalid.', 'event_espresso'),
32
+				$interface_name
33
+			);
34
+		}
35
+		parent::__construct($message, $code, $previous);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
core/exceptions/InvalidFormSubmissionException.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -13,25 +13,25 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * InvalidFormSubmissionException constructor
18
-     *
19
-     * @param string     $form_name
20
-     * @param string     $message
21
-     * @param int        $code
22
-     * @param \Exception $previous
23
-     */
24
-    public function __construct($form_name, $message = '', $code = 0, \Exception $previous = null)
25
-    {
26
-        if (empty($message)) {
27
-            $message = sprintf(
28
-                esc_html__(
29
-                    'The data for the "%1$s" form, is either missing or was not submitted properly.',
30
-                    'event_espresso'
31
-                ),
32
-                $form_name
33
-            );
34
-        }
35
-        parent::__construct($message, $code, $previous);
36
-    }
16
+	/**
17
+	 * InvalidFormSubmissionException constructor
18
+	 *
19
+	 * @param string     $form_name
20
+	 * @param string     $message
21
+	 * @param int        $code
22
+	 * @param \Exception $previous
23
+	 */
24
+	public function __construct($form_name, $message = '', $code = 0, \Exception $previous = null)
25
+	{
26
+		if (empty($message)) {
27
+			$message = sprintf(
28
+				esc_html__(
29
+					'The data for the "%1$s" form, is either missing or was not submitted properly.',
30
+					'event_espresso'
31
+				),
32
+				$form_name
33
+			);
34
+		}
35
+		parent::__construct($message, $code, $previous);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
core/exceptions/InsufficientPermissionsException.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -13,24 +13,24 @@
 block discarded – undo
13 13
 class InsufficientPermissionsException extends \RuntimeException
14 14
 {
15 15
 
16
-    /**
17
-     * @access public
18
-     * @param  string     $action
19
-     * @param  string     $message
20
-     * @param  int        $code
21
-     * @param  \Exception $previous
22
-     */
23
-    public function __construct($action, $message = '', $code = 0, \Exception $previous = null)
24
-    {
25
-        if (empty($message)) {
26
-            $message = sprintf(
27
-                esc_html__(
28
-                    'We\'re sorry, but you do not have the required permissions to perform the following action: %1$s',
29
-                    'event_espresso'
30
-                ),
31
-                ucwords(str_replace('_', ' ', $action))
32
-            );
33
-        }
34
-        parent::__construct($message, $code, $previous);
35
-    }
16
+	/**
17
+	 * @access public
18
+	 * @param  string     $action
19
+	 * @param  string     $message
20
+	 * @param  int        $code
21
+	 * @param  \Exception $previous
22
+	 */
23
+	public function __construct($action, $message = '', $code = 0, \Exception $previous = null)
24
+	{
25
+		if (empty($message)) {
26
+			$message = sprintf(
27
+				esc_html__(
28
+					'We\'re sorry, but you do not have the required permissions to perform the following action: %1$s',
29
+					'event_espresso'
30
+				),
31
+				ucwords(str_replace('_', ' ', $action))
32
+			);
33
+		}
34
+		parent::__construct($message, $code, $previous);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
core/exceptions/EntityNotFoundException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,27 +15,27 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * EntityNotFoundException constructor
20
-     *
21
-     * @param string     $identifier_type the name of the identifier used (ie: ID, Name, etc)
22
-     * @param string     $identifier      the actual data value used to retrieve the entity
23
-     * @param string     $message
24
-     * @param int        $code
25
-     * @param \Exception $previous
26
-     */
27
-    public function __construct($identifier_type, $identifier, $message = '', $code = 0, \Exception $previous = null)
28
-    {
29
-        if (empty($message)) {
30
-            $message = sprintf(
31
-                esc_html__(
32
-                    'The requested entity with %1$s="%2$s" was not found.',
33
-                    'event_espresso'
34
-                ),
35
-                $identifier_type,
36
-                $identifier
37
-            );
38
-        }
39
-        parent::__construct($message, $code, $previous);
40
-    }
18
+	/**
19
+	 * EntityNotFoundException constructor
20
+	 *
21
+	 * @param string     $identifier_type the name of the identifier used (ie: ID, Name, etc)
22
+	 * @param string     $identifier      the actual data value used to retrieve the entity
23
+	 * @param string     $message
24
+	 * @param int        $code
25
+	 * @param \Exception $previous
26
+	 */
27
+	public function __construct($identifier_type, $identifier, $message = '', $code = 0, \Exception $previous = null)
28
+	{
29
+		if (empty($message)) {
30
+			$message = sprintf(
31
+				esc_html__(
32
+					'The requested entity with %1$s="%2$s" was not found.',
33
+					'event_espresso'
34
+				),
35
+				$identifier_type,
36
+				$identifier
37
+			);
38
+		}
39
+		parent::__construct($message, $code, $previous);
40
+	}
41 41
 }
Please login to merge, or discard this patch.
core/EE_Capabilities.core.php 2 patches
Indentation   +1373 added lines, -1373 removed lines patch added patch discarded remove patch
@@ -14,984 +14,984 @@  discard block
 block discarded – undo
14 14
 final class EE_Capabilities extends EE_Base
15 15
 {
16 16
 
17
-    /**
18
-     * the name of the wp option used to store caps previously initialized
19
-     */
20
-    const option_name = 'ee_caps_initialized';
21
-
22
-    /**
23
-     * instance of EE_Capabilities object
24
-     *
25
-     * @var EE_Capabilities
26
-     */
27
-    private static $_instance;
28
-
29
-
30
-    /**
31
-     * This is a map of caps that correspond to a default WP_Role.
32
-     * Array is indexed by Role and values are ee capabilities.
33
-     *
34
-     * @since 4.5.0
35
-     *
36
-     * @var array
37
-     */
38
-    private $capabilities_map = array();
39
-
40
-    /**
41
-     * This used to hold an array of EE_Meta_Capability_Map objects
42
-     * that define the granular capabilities mapped to for a user depending on context.
43
-     *
44
-     * @var EE_Meta_Capability_Map[]
45
-     */
46
-    private $_meta_caps = array();
47
-
48
-    /**
49
-     * The internal $capabilities_map needs to be initialized before it can be used.
50
-     * This flag tracks whether that has happened or not.
51
-     * But for this to work, we need three states to indicate:
52
-     *      initialization has not occurred at all
53
-     *      initialization has started but is not complete
54
-     *      initialization is complete
55
-     * The reason this is needed is because the addCaps() method
56
-     * normally requires the $capabilities_map to be initialized,
57
-     * but is also used during the initialization process.
58
-     * So:
59
-     *      If initialized === null, init_caps() will be called before any other methods will run.
60
-     *      If initialized === false, then init_caps() is in the process of running it's logic.
61
-     *      If initialized === true, then init_caps() has completed the initialization process.
62
-     *
63
-     * @var boolean|null $initialized
64
-     */
65
-    private $initialized;
66
-
67
-    /**
68
-     * @var boolean $reset
69
-     */
70
-    private $reset = false;
71
-
72
-
73
-    /**
74
-     * singleton method used to instantiate class object
75
-     *
76
-     * @since 4.5.0
77
-     *
78
-     * @return EE_Capabilities
79
-     */
80
-    public static function instance()
81
-    {
82
-        // check if instantiated, and if not do so.
83
-        if (! self::$_instance instanceof EE_Capabilities) {
84
-            self::$_instance = new self();
85
-        }
86
-        return self::$_instance;
87
-    }
88
-
89
-
90
-    /**
91
-     * private constructor
92
-     *
93
-     * @since 4.5.0
94
-     */
95
-    private function __construct()
96
-    {
97
-    }
98
-
99
-
100
-    /**
101
-     * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
102
-     *
103
-     * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
104
-     *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
105
-     *                    ensures that they are up to date.
106
-     *
107
-     * @since 4.5.0
108
-     * @return bool
109
-     * @throws EE_Error
110
-     */
111
-    public function init_caps($reset = false)
112
-    {
113
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
114
-            return false;
115
-        }
116
-        $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
117
-        // if reset, then completely delete the cache option and clear the $capabilities_map property.
118
-        if ($this->reset) {
119
-            $this->initialized = null;
120
-            $this->capabilities_map = array();
121
-            delete_option(self::option_name);
122
-        }
123
-        if ($this->initialized === null) {
124
-            $this->initialized = false;
125
-            do_action(
126
-                'AHEE__EE_Capabilities__init_caps__before_initialization',
127
-                $this->reset
128
-            );
129
-            $this->addCaps($this->_init_caps_map());
130
-            $this->_set_meta_caps();
131
-            do_action(
132
-                'AHEE__EE_Capabilities__init_caps__after_initialization',
133
-                $this->capabilities_map
134
-            );
135
-            $this->initialized = true;
136
-        }
137
-        // reset $this->reset so that it's not stuck on true if init_caps() gets called again
138
-        $this->reset = false;
139
-        return true;
140
-    }
141
-
142
-
143
-    /**
144
-     * This sets the meta caps property.
145
-     *
146
-     * @since 4.5.0
147
-     * @return void
148
-     * @throws EE_Error
149
-     */
150
-    private function _set_meta_caps()
151
-    {
152
-        // get default meta caps and filter the returned array
153
-        $this->_meta_caps = apply_filters(
154
-            'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
155
-            $this->_get_default_meta_caps_array()
156
-        );
157
-        // add filter for map_meta_caps but only if models can query.
158
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159
-            add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160
-        }
161
-    }
162
-
163
-
164
-    /**
165
-     * This builds and returns the default meta_caps array only once.
166
-     *
167
-     * @since  4.8.28.rc.012
168
-     * @return array
169
-     * @throws EE_Error
170
-     */
171
-    private function _get_default_meta_caps_array()
172
-    {
173
-        static $default_meta_caps = array();
174
-        // make sure we're only ever initializing the default _meta_caps array once if it's empty.
175
-        if (empty($default_meta_caps)) {
176
-            $default_meta_caps = array(
177
-                // edits
178
-                new EE_Meta_Capability_Map_Edit(
179
-                    'ee_edit_event',
180
-                    array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
181
-                ),
182
-                new EE_Meta_Capability_Map_Edit(
183
-                    'ee_edit_venue',
184
-                    array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
185
-                ),
186
-                new EE_Meta_Capability_Map_Edit(
187
-                    'ee_edit_registration',
188
-                    array('Registration', '', 'ee_edit_others_registrations', '')
189
-                ),
190
-                new EE_Meta_Capability_Map_Edit(
191
-                    'ee_edit_checkin',
192
-                    array('Registration', '', 'ee_edit_others_checkins', '')
193
-                ),
194
-                new EE_Meta_Capability_Map_Messages_Cap(
195
-                    'ee_edit_message',
196
-                    array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
197
-                ),
198
-                new EE_Meta_Capability_Map_Edit(
199
-                    'ee_edit_default_ticket',
200
-                    array('Ticket', '', 'ee_edit_others_default_tickets', '')
201
-                ),
202
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
203
-                    'ee_edit_question',
204
-                    array('Question', '', '', 'ee_edit_system_questions')
205
-                ),
206
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
207
-                    'ee_edit_question_group',
208
-                    array('Question_Group', '', '', 'ee_edit_system_question_groups')
209
-                ),
210
-                new EE_Meta_Capability_Map_Edit(
211
-                    'ee_edit_payment_method',
212
-                    array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
213
-                ),
214
-                // reads
215
-                new EE_Meta_Capability_Map_Read(
216
-                    'ee_read_event',
217
-                    array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
218
-                ),
219
-                new EE_Meta_Capability_Map_Read(
220
-                    'ee_read_venue',
221
-                    array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
222
-                ),
223
-                new EE_Meta_Capability_Map_Read(
224
-                    'ee_read_registration',
225
-                    array('Registration', '', 'ee_read_others_registrations', '')
226
-                ),
227
-                new EE_Meta_Capability_Map_Read(
228
-                    'ee_read_checkin',
229
-                    array('Registration', '', 'ee_read_others_checkins', '')
230
-                ),
231
-                new EE_Meta_Capability_Map_Messages_Cap(
232
-                    'ee_read_message',
233
-                    array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
234
-                ),
235
-                new EE_Meta_Capability_Map_Read(
236
-                    'ee_read_default_ticket',
237
-                    array('Ticket', '', 'ee_read_others_default_tickets', '')
238
-                ),
239
-                new EE_Meta_Capability_Map_Read(
240
-                    'ee_read_payment_method',
241
-                    array('Payment_Method', '', 'ee_read_others_payment_methods', '')
242
-                ),
243
-                // deletes
244
-                new EE_Meta_Capability_Map_Delete(
245
-                    'ee_delete_event',
246
-                    array(
247
-                        'Event',
248
-                        'ee_delete_published_events',
249
-                        'ee_delete_others_events',
250
-                        'ee_delete_private_events',
251
-                    )
252
-                ),
253
-                new EE_Meta_Capability_Map_Delete(
254
-                    'ee_delete_venue',
255
-                    array(
256
-                        'Venue',
257
-                        'ee_delete_published_venues',
258
-                        'ee_delete_others_venues',
259
-                        'ee_delete_private_venues',
260
-                    )
261
-                ),
262
-                new EE_Meta_Capability_Map_Delete(
263
-                    'ee_delete_registration',
264
-                    array('Registration', '', 'ee_delete_others_registrations', '')
265
-                ),
266
-                new EE_Meta_Capability_Map_Delete(
267
-                    'ee_delete_checkin',
268
-                    array('Registration', '', 'ee_delete_others_checkins', '')
269
-                ),
270
-                new EE_Meta_Capability_Map_Messages_Cap(
271
-                    'ee_delete_message',
272
-                    array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
273
-                ),
274
-                new EE_Meta_Capability_Map_Delete(
275
-                    'ee_delete_default_ticket',
276
-                    array('Ticket', '', 'ee_delete_others_default_tickets', '')
277
-                ),
278
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
279
-                    'ee_delete_question',
280
-                    array('Question', '', '', 'delete_system_questions')
281
-                ),
282
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
283
-                    'ee_delete_question_group',
284
-                    array('Question_Group', '', '', 'delete_system_question_groups')
285
-                ),
286
-                new EE_Meta_Capability_Map_Delete(
287
-                    'ee_delete_payment_method',
288
-                    array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
289
-                ),
290
-            );
291
-        }
292
-        return $default_meta_caps;
293
-    }
294
-
295
-
296
-    /**
297
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
298
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
299
-     *
300
-     * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
301
-     *
302
-     * @since 4.5.0
303
-     * @see   wp-includes/capabilities.php
304
-     *
305
-     * @param array  $caps    actual users capabilities
306
-     * @param string $cap     initial capability name that is being checked (the "map" key)
307
-     * @param int    $user_id The user id
308
-     * @param array  $args    Adds context to the cap. Typically the object ID.
309
-     * @return array actual users capabilities
310
-     * @throws EE_Error
311
-     */
312
-    public function map_meta_caps($caps, $cap, $user_id, $args)
313
-    {
314
-        if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315
-            // loop through our _meta_caps array
316
-            foreach ($this->_meta_caps as $meta_map) {
317
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
318
-                    continue;
319
-                }
320
-                // don't load models if there is no object ID in the args
321
-                if (! empty($args[0])) {
322
-                    $meta_map->ensure_is_model();
323
-                }
324
-                $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
325
-            }
326
-        }
327
-        return $caps;
328
-    }
329
-
330
-
331
-    /**
332
-     * This sets up and returns the initial capabilities map for Event Espresso
333
-     * Note this array is filtered.
334
-     * It is assumed that all available EE capabilities are assigned to the administrator role.
335
-     *
336
-     * @since 4.5.0
337
-     *
338
-     * @return array
339
-     */
340
-    private function _init_caps_map()
341
-    {
342
-        return apply_filters(
343
-            'FHEE__EE_Capabilities__init_caps_map__caps',
344
-            array(
345
-                'administrator'           => array(
346
-                    // basic access
347
-                    'ee_read_ee',
348
-                    // gateways
349
-                    /**
350
-                     * note that with payment method capabilities, although we've implemented
351
-                     * capability mapping which will be used for accessing payment methods owned by
352
-                     * other users.  This is not fully implemented yet in the payment method ui.
353
-                     * Currently only the "plural" caps are in active use.
354
-                     * (Specific payment method caps are in use as well).
355
-                     **/
356
-                    'ee_manage_gateways',
357
-                    'ee_read_payment_methods',
358
-                    'ee_read_others_payment_methods',
359
-                    'ee_edit_payment_methods',
360
-                    'ee_edit_others_payment_methods',
361
-                    'ee_delete_payment_methods',
362
-                    // events
363
-                    'ee_publish_events',
364
-                    'ee_read_private_events',
365
-                    'ee_read_others_events',
366
-                    'ee_read_events',
367
-                    'ee_edit_events',
368
-                    'ee_edit_published_events',
369
-                    'ee_edit_others_events',
370
-                    'ee_edit_private_events',
371
-                    'ee_delete_published_events',
372
-                    'ee_delete_private_events',
373
-                    'ee_delete_events',
374
-                    'ee_delete_others_events',
375
-                    // event categories
376
-                    'ee_manage_event_categories',
377
-                    'ee_edit_event_category',
378
-                    'ee_delete_event_category',
379
-                    'ee_assign_event_category',
380
-                    // venues
381
-                    'ee_publish_venues',
382
-                    'ee_read_venues',
383
-                    'ee_read_others_venues',
384
-                    'ee_read_private_venues',
385
-                    'ee_edit_venues',
386
-                    'ee_edit_others_venues',
387
-                    'ee_edit_published_venues',
388
-                    'ee_edit_private_venues',
389
-                    'ee_delete_venues',
390
-                    'ee_delete_others_venues',
391
-                    'ee_delete_private_venues',
392
-                    'ee_delete_published_venues',
393
-                    // venue categories
394
-                    'ee_manage_venue_categories',
395
-                    'ee_edit_venue_category',
396
-                    'ee_delete_venue_category',
397
-                    'ee_assign_venue_category',
398
-                    // contacts
399
-                    'ee_read_contacts',
400
-                    'ee_edit_contacts',
401
-                    'ee_delete_contacts',
402
-                    // registrations
403
-                    'ee_read_registrations',
404
-                    'ee_read_others_registrations',
405
-                    'ee_edit_registrations',
406
-                    'ee_edit_others_registrations',
407
-                    'ee_delete_registrations',
408
-                    'ee_delete_others_registrations',
409
-                    // checkins
410
-                    'ee_read_others_checkins',
411
-                    'ee_read_checkins',
412
-                    'ee_edit_checkins',
413
-                    'ee_edit_others_checkins',
414
-                    'ee_delete_checkins',
415
-                    'ee_delete_others_checkins',
416
-                    // transactions && payments
417
-                    'ee_read_transaction',
418
-                    'ee_read_transactions',
419
-                    'ee_edit_payments',
420
-                    'ee_delete_payments',
421
-                    // messages
422
-                    'ee_read_messages',
423
-                    'ee_read_others_messages',
424
-                    'ee_read_global_messages',
425
-                    'ee_edit_global_messages',
426
-                    'ee_edit_messages',
427
-                    'ee_edit_others_messages',
428
-                    'ee_delete_messages',
429
-                    'ee_delete_others_messages',
430
-                    'ee_delete_global_messages',
431
-                    'ee_send_message',
432
-                    // tickets
433
-                    'ee_read_default_tickets',
434
-                    'ee_read_others_default_tickets',
435
-                    'ee_edit_default_tickets',
436
-                    'ee_edit_others_default_tickets',
437
-                    'ee_delete_default_tickets',
438
-                    'ee_delete_others_default_tickets',
439
-                    // prices
440
-                    'ee_edit_default_price',
441
-                    'ee_edit_default_prices',
442
-                    'ee_delete_default_price',
443
-                    'ee_delete_default_prices',
444
-                    'ee_edit_default_price_type',
445
-                    'ee_edit_default_price_types',
446
-                    'ee_delete_default_price_type',
447
-                    'ee_delete_default_price_types',
448
-                    'ee_read_default_prices',
449
-                    'ee_read_default_price_types',
450
-                    // registration form
451
-                    'ee_edit_questions',
452
-                    'ee_edit_system_questions',
453
-                    'ee_read_questions',
454
-                    'ee_delete_questions',
455
-                    'ee_edit_question_groups',
456
-                    'ee_read_question_groups',
457
-                    'ee_edit_system_question_groups',
458
-                    'ee_delete_question_groups',
459
-                    // event_type taxonomy
460
-                    'ee_assign_event_type',
461
-                    'ee_manage_event_types',
462
-                    'ee_edit_event_type',
463
-                    'ee_delete_event_type',
464
-                ),
465
-                'ee_events_administrator' => array(
466
-                    // core wp caps
467
-                    'read',
468
-                    'read_private_pages',
469
-                    'read_private_posts',
470
-                    'edit_users',
471
-                    'edit_posts',
472
-                    'edit_pages',
473
-                    'edit_published_posts',
474
-                    'edit_published_pages',
475
-                    'edit_private_pages',
476
-                    'edit_private_posts',
477
-                    'edit_others_posts',
478
-                    'edit_others_pages',
479
-                    'publish_posts',
480
-                    'publish_pages',
481
-                    'delete_posts',
482
-                    'delete_pages',
483
-                    'delete_private_pages',
484
-                    'delete_private_posts',
485
-                    'delete_published_pages',
486
-                    'delete_published_posts',
487
-                    'delete_others_posts',
488
-                    'delete_others_pages',
489
-                    'manage_categories',
490
-                    'manage_links',
491
-                    'moderate_comments',
492
-                    'unfiltered_html',
493
-                    'upload_files',
494
-                    'export',
495
-                    'import',
496
-                    'list_users',
497
-                    'level_1', // required if user with this role shows up in author dropdowns
498
-                    // basic ee access
499
-                    'ee_read_ee',
500
-                    // events
501
-                    'ee_publish_events',
502
-                    'ee_read_private_events',
503
-                    'ee_read_others_events',
504
-                    'ee_read_event',
505
-                    'ee_read_events',
506
-                    'ee_edit_event',
507
-                    'ee_edit_events',
508
-                    'ee_edit_published_events',
509
-                    'ee_edit_others_events',
510
-                    'ee_edit_private_events',
511
-                    'ee_delete_published_events',
512
-                    'ee_delete_private_events',
513
-                    'ee_delete_event',
514
-                    'ee_delete_events',
515
-                    'ee_delete_others_events',
516
-                    // event categories
517
-                    'ee_manage_event_categories',
518
-                    'ee_edit_event_category',
519
-                    'ee_delete_event_category',
520
-                    'ee_assign_event_category',
521
-                    // venues
522
-                    'ee_publish_venues',
523
-                    'ee_read_venue',
524
-                    'ee_read_venues',
525
-                    'ee_read_others_venues',
526
-                    'ee_read_private_venues',
527
-                    'ee_edit_venue',
528
-                    'ee_edit_venues',
529
-                    'ee_edit_others_venues',
530
-                    'ee_edit_published_venues',
531
-                    'ee_edit_private_venues',
532
-                    'ee_delete_venue',
533
-                    'ee_delete_venues',
534
-                    'ee_delete_others_venues',
535
-                    'ee_delete_private_venues',
536
-                    'ee_delete_published_venues',
537
-                    // venue categories
538
-                    'ee_manage_venue_categories',
539
-                    'ee_edit_venue_category',
540
-                    'ee_delete_venue_category',
541
-                    'ee_assign_venue_category',
542
-                    // contacts
543
-                    'ee_read_contacts',
544
-                    'ee_edit_contacts',
545
-                    'ee_delete_contacts',
546
-                    // registrations
547
-                    'ee_read_registrations',
548
-                    'ee_read_others_registrations',
549
-                    'ee_edit_registration',
550
-                    'ee_edit_registrations',
551
-                    'ee_edit_others_registrations',
552
-                    'ee_delete_registration',
553
-                    'ee_delete_registrations',
554
-                    'ee_delete_others_registrations',
555
-                    // checkins
556
-                    'ee_read_others_checkins',
557
-                    'ee_read_checkins',
558
-                    'ee_edit_checkins',
559
-                    'ee_edit_others_checkins',
560
-                    'ee_delete_checkins',
561
-                    'ee_delete_others_checkins',
562
-                    // transactions && payments
563
-                    'ee_read_transaction',
564
-                    'ee_read_transactions',
565
-                    'ee_edit_payments',
566
-                    'ee_delete_payments',
567
-                    // messages
568
-                    'ee_read_messages',
569
-                    'ee_read_others_messages',
570
-                    'ee_read_global_messages',
571
-                    'ee_edit_global_messages',
572
-                    'ee_edit_messages',
573
-                    'ee_edit_others_messages',
574
-                    'ee_delete_messages',
575
-                    'ee_delete_others_messages',
576
-                    'ee_delete_global_messages',
577
-                    'ee_send_message',
578
-                    // tickets
579
-                    'ee_read_default_tickets',
580
-                    'ee_read_others_default_tickets',
581
-                    'ee_edit_default_tickets',
582
-                    'ee_edit_others_default_tickets',
583
-                    'ee_delete_default_tickets',
584
-                    'ee_delete_others_default_tickets',
585
-                    // prices
586
-                    'ee_edit_default_price',
587
-                    'ee_edit_default_prices',
588
-                    'ee_delete_default_price',
589
-                    'ee_delete_default_prices',
590
-                    'ee_edit_default_price_type',
591
-                    'ee_edit_default_price_types',
592
-                    'ee_delete_default_price_type',
593
-                    'ee_delete_default_price_types',
594
-                    'ee_read_default_prices',
595
-                    'ee_read_default_price_types',
596
-                    // registration form
597
-                    'ee_edit_questions',
598
-                    'ee_edit_system_questions',
599
-                    'ee_read_questions',
600
-                    'ee_delete_questions',
601
-                    'ee_edit_question_groups',
602
-                    'ee_read_question_groups',
603
-                    'ee_edit_system_question_groups',
604
-                    'ee_delete_question_groups',
605
-                    // event_type taxonomy
606
-                    'ee_assign_event_type',
607
-                    'ee_manage_event_types',
608
-                    'ee_edit_event_type',
609
-                    'ee_delete_event_type',
610
-                ),
611
-            )
612
-        );
613
-    }
614
-
615
-
616
-    /**
617
-     * @return bool
618
-     * @throws EE_Error
619
-     */
620
-    private function setupCapabilitiesMap()
621
-    {
622
-        // if the initialization process hasn't even started, then we need to call init_caps()
623
-        if ($this->initialized === null) {
624
-            return $this->init_caps();
625
-        }
626
-        // unless resetting, get caps from db if we haven't already
627
-        $this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
628
-            ? $this->capabilities_map
629
-            : get_option(self::option_name, array());
630
-        return true;
631
-    }
632
-
633
-
634
-    /**
635
-     * @param bool $update
636
-     * @return bool
637
-     */
638
-    private function updateCapabilitiesMap($update = true)
639
-    {
640
-        return $update ? update_option(self::option_name, $this->capabilities_map) : false;
641
-    }
642
-
643
-
644
-    /**
645
-     * Adds capabilities to roles.
646
-     *
647
-     * @since 4.9.42
648
-     * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
649
-     *                                   Note that this should ONLY be called on activation hook
650
-     *                                   otherwise the caps will be added on every request.
651
-     * @return bool
652
-     * @throws \EE_Error
653
-     */
654
-    public function addCaps(array $capabilities_to_add)
655
-    {
656
-        // don't do anything if the capabilities map can not be initialized
657
-        if (! $this->setupCapabilitiesMap()) {
658
-            return false;
659
-        }
660
-        // and filter the array so others can get in on the fun during resets
661
-        $capabilities_to_add = apply_filters(
662
-            'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
663
-            $capabilities_to_add,
664
-            $this->reset,
665
-            $this->capabilities_map
666
-        );
667
-        $update_capabilities_map = false;
668
-        // if not reset, see what caps are new for each role. if they're new, add them.
669
-        foreach ($capabilities_to_add as $role => $caps_for_role) {
670
-            if (is_array($caps_for_role)) {
671
-                foreach ($caps_for_role as $cap) {
672
-                    if (
673
-                        ! $this->capHasBeenAddedToRole($role, $cap)
674
-                        && $this->add_cap_to_role($role, $cap, true, false)
675
-                    ) {
676
-                        $update_capabilities_map = true;
677
-                    }
678
-                }
679
-            }
680
-        }
681
-        // now let's just save the cap that has been set but only if there's been a change.
682
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
683
-        $this->flushWpUser($updated);
684
-        do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
685
-        return $updated;
686
-    }
687
-
688
-
689
-    /**
690
-     * Loops through the capabilities map and removes the role caps specified by the incoming array
691
-     *
692
-     * @param array $caps_map map of capabilities to be removed (indexed by roles)
693
-     * @return bool
694
-     * @throws \EE_Error
695
-     */
696
-    public function removeCaps($caps_map)
697
-    {
698
-        // don't do anything if the capabilities map can not be initialized
699
-        if (! $this->setupCapabilitiesMap()) {
700
-            return false;
701
-        }
702
-        $update_capabilities_map = false;
703
-        foreach ($caps_map as $role => $caps_for_role) {
704
-            if (is_array($caps_for_role)) {
705
-                foreach ($caps_for_role as $cap) {
706
-                    if (
707
-                        $this->capHasBeenAddedToRole($role, $cap)
708
-                        && $this->remove_cap_from_role($role, $cap, false)
709
-                    ) {
710
-                        $update_capabilities_map = true;
711
-                    }
712
-                }
713
-            }
714
-        }
715
-        // maybe resave the caps
716
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
717
-        $this->flushWpUser($updated);
718
-        return $updated;
719
-    }
720
-
721
-
722
-    /**
723
-     * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
724
-     * the roles on that user.
725
-     *
726
-     * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
727
-     */
728
-    private function flushWpUser($flush = true)
729
-    {
730
-        if ($flush) {
731
-            $user = wp_get_current_user();
732
-            if ($user instanceof WP_User) {
733
-                $user->get_role_caps();
734
-            }
735
-        }
736
-    }
737
-
738
-
739
-    /**
740
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
741
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
742
-     * this is a wrapper for $wp_role->add_cap()
743
-     *
744
-     * @see   wp-includes/capabilities.php
745
-     * @since 4.5.0
746
-     * @param string|WP_Role $role  A WordPress role the capability is being added to
747
-     * @param string         $cap   The capability being added to the role
748
-     * @param bool           $grant Whether to grant access to this cap on this role.
749
-     * @param bool           $update_capabilities_map
750
-     * @return bool
751
-     * @throws \EE_Error
752
-     */
753
-    public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
754
-    {
755
-        // capture incoming value for $role because we may need it to create a new WP_Role
756
-        $orig_role = $role;
757
-        $role = $role instanceof WP_Role ? $role : get_role($role);
758
-        // if the role isn't available then we create it.
759
-        if (! $role instanceof WP_Role) {
760
-            // if a plugin wants to create a specific role name then they should create the role before
761
-            // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
762
-            // - removes any `ee_` namespacing from the start of the slug.
763
-            // - replaces `_` with ` ` (empty space).
764
-            // - sentence case on the resulting string.
765
-            $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
766
-            $role = add_role($orig_role, $role_label);
767
-        }
768
-        if ($role instanceof WP_Role) {
769
-            // don't do anything if the capabilities map can not be initialized
770
-            if (! $this->setupCapabilitiesMap()) {
771
-                return false;
772
-            }
773
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
774
-                $role->add_cap($cap, $grant);
775
-                $this->capabilities_map[ $role->name ][] = $cap;
776
-                $this->updateCapabilitiesMap($update_capabilities_map);
777
-                return true;
778
-            }
779
-        }
780
-        return false;
781
-    }
782
-
783
-
784
-    /**
785
-     * Functions similarly to add_cap_to_role except removes cap from given role.
786
-     * Wrapper for $wp_role->remove_cap()
787
-     *
788
-     * @see   wp-includes/capabilities.php
789
-     * @since 4.5.0
790
-     * @param string|WP_Role $role A WordPress role the capability is being removed from.
791
-     * @param string         $cap  The capability being removed
792
-     * @param bool           $update_capabilities_map
793
-     * @return bool
794
-     * @throws \EE_Error
795
-     */
796
-    public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
797
-    {
798
-        // don't do anything if the capabilities map can not be initialized
799
-        if (! $this->setupCapabilitiesMap()) {
800
-            return false;
801
-        }
802
-
803
-        $role = $role instanceof WP_Role ? $role : get_role($role);
804
-        if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
805
-            $role->remove_cap($cap);
806
-            unset($this->capabilities_map[ $role->name ][ $index ]);
807
-            $this->updateCapabilitiesMap($update_capabilities_map);
808
-            return true;
809
-        }
810
-        return false;
811
-    }
812
-
813
-
814
-    /**
815
-     * @param string $role_name
816
-     * @param string $cap
817
-     * @param bool   $get_index
818
-     * @return bool|mixed
819
-     */
820
-    private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
821
-    {
822
-        if (
823
-            isset($this->capabilities_map[ $role_name ])
824
-            && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
825
-        ) {
826
-            return $get_index ? $index : true;
827
-        }
828
-        return false;
829
-    }
830
-
831
-
832
-    /**
833
-     * Wrapper for the native WP current_user_can() method.
834
-     * This is provided as a handy method for a couple things:
835
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
836
-     * write those filters wherever current_user_can is called).
837
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
838
-     *
839
-     * @since 4.5.0
840
-     *
841
-     * @param string $cap     The cap being checked.
842
-     * @param string $context The context where the current_user_can is being called from.
843
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
844
-     *                        filters.
845
-     *
846
-     * @return bool  Whether user can or not.
847
-     */
848
-    public function current_user_can($cap, $context, $id = 0)
849
-    {
850
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
851
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
852
-        $filtered_cap = apply_filters(
853
-            'FHEE__EE_Capabilities__current_user_can__cap',
854
-            $filtered_cap,
855
-            $context,
856
-            $cap,
857
-            $id
858
-        );
859
-        return ! empty($id)
860
-            ? current_user_can($filtered_cap, $id)
861
-            : current_user_can($filtered_cap);
862
-    }
863
-
864
-
865
-    /**
866
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
867
-     *
868
-     * @param int|WP_User $user    Either the user_id or a WP_User object
869
-     * @param string      $cap     The capability string being checked
870
-     * @param string      $context The context where the user_can is being called from (used in filters).
871
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
872
-     *                             filters)
873
-     *
874
-     * @return bool Whether user can or not.
875
-     */
876
-    public function user_can($user, $cap, $context, $id = 0)
877
-    {
878
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
879
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
880
-        $filtered_cap = apply_filters(
881
-            'FHEE__EE_Capabilities__user_can__cap',
882
-            $filtered_cap,
883
-            $context,
884
-            $cap,
885
-            $user,
886
-            $id
887
-        );
888
-        return ! empty($id)
889
-            ? user_can($user, $filtered_cap, $id)
890
-            : user_can($user, $filtered_cap);
891
-    }
892
-
893
-
894
-    /**
895
-     * Wrapper for the native WP current_user_can_for_blog() method.
896
-     * This is provided as a handy method for a couple things:
897
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
898
-     * write those filters wherever current_user_can is called).
899
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
900
-     *
901
-     * @since 4.5.0
902
-     *
903
-     * @param int    $blog_id The blog id that is being checked for.
904
-     * @param string $cap     The cap being checked.
905
-     * @param string $context The context where the current_user_can is being called from.
906
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
907
-     *                        filters.
908
-     *
909
-     * @return bool  Whether user can or not.
910
-     */
911
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
912
-    {
913
-        $user_can = ! empty($id)
914
-            ? current_user_can_for_blog($blog_id, $cap, $id)
915
-            : current_user_can($blog_id, $cap);
916
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
917
-        $user_can = apply_filters(
918
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
919
-            $user_can,
920
-            $blog_id,
921
-            $cap,
922
-            $id
923
-        );
924
-        $user_can = apply_filters(
925
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
926
-            $user_can,
927
-            $context,
928
-            $blog_id,
929
-            $cap,
930
-            $id
931
-        );
932
-        return $user_can;
933
-    }
934
-
935
-
936
-    /**
937
-     * This helper method just returns an array of registered EE capabilities.
938
-     *
939
-     * @since 4.5.0
940
-     * @param string $role If empty then the entire role/capability map is returned.
941
-     *                     Otherwise just the capabilities for the given role are returned.
942
-     * @return array
943
-     * @throws EE_Error
944
-     */
945
-    public function get_ee_capabilities($role = 'administrator')
946
-    {
947
-        if (! $this->initialized) {
948
-            $this->init_caps();
949
-        }
950
-        if (empty($role)) {
951
-            return $this->capabilities_map;
952
-        }
953
-        return isset($this->capabilities_map[ $role ])
954
-            ? $this->capabilities_map[ $role ]
955
-            : array();
956
-    }
957
-
958
-
959
-    /**
960
-     * @deprecated 4.9.42
961
-     * @param bool  $reset      If you need to reset Event Espresso's capabilities,
962
-     *                          then please use the init_caps() method with the "$reset" parameter set to "true"
963
-     * @param array $caps_map   Optional.
964
-     *                          Can be used to send a custom map of roles and capabilities for setting them up.
965
-     *                          Note that this should ONLY be called on activation hook or some other one-time
966
-     *                          task otherwise the caps will be added on every request.
967
-     * @return void
968
-     * @throws EE_Error
969
-     */
970
-    public function init_role_caps($reset = false, $caps_map = array())
971
-    {
972
-        // If this method is called directly and reset is set as 'true',
973
-        // then display a doing it wrong notice, because we want resets to go through init_caps()
974
-        // to guarantee that everything is set up correctly.
975
-        // This prevents the capabilities map getting reset incorrectly by direct calls to this method.
976
-        if ($reset) {
977
-            EE_Error::doing_it_wrong(
978
-                __METHOD__,
979
-                sprintf(
980
-                    esc_html__(
981
-                        'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
982
-                        'event_espresso'
983
-                    ),
984
-                    '$reset',
985
-                    __METHOD__ . '()',
986
-                    'EE_Capabilities::init_caps()',
987
-                    'true'
988
-                ),
989
-                '4.9.42',
990
-                '5.0.0'
991
-            );
992
-        }
993
-        $this->addCaps($caps_map);
994
-    }
17
+	/**
18
+	 * the name of the wp option used to store caps previously initialized
19
+	 */
20
+	const option_name = 'ee_caps_initialized';
21
+
22
+	/**
23
+	 * instance of EE_Capabilities object
24
+	 *
25
+	 * @var EE_Capabilities
26
+	 */
27
+	private static $_instance;
28
+
29
+
30
+	/**
31
+	 * This is a map of caps that correspond to a default WP_Role.
32
+	 * Array is indexed by Role and values are ee capabilities.
33
+	 *
34
+	 * @since 4.5.0
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private $capabilities_map = array();
39
+
40
+	/**
41
+	 * This used to hold an array of EE_Meta_Capability_Map objects
42
+	 * that define the granular capabilities mapped to for a user depending on context.
43
+	 *
44
+	 * @var EE_Meta_Capability_Map[]
45
+	 */
46
+	private $_meta_caps = array();
47
+
48
+	/**
49
+	 * The internal $capabilities_map needs to be initialized before it can be used.
50
+	 * This flag tracks whether that has happened or not.
51
+	 * But for this to work, we need three states to indicate:
52
+	 *      initialization has not occurred at all
53
+	 *      initialization has started but is not complete
54
+	 *      initialization is complete
55
+	 * The reason this is needed is because the addCaps() method
56
+	 * normally requires the $capabilities_map to be initialized,
57
+	 * but is also used during the initialization process.
58
+	 * So:
59
+	 *      If initialized === null, init_caps() will be called before any other methods will run.
60
+	 *      If initialized === false, then init_caps() is in the process of running it's logic.
61
+	 *      If initialized === true, then init_caps() has completed the initialization process.
62
+	 *
63
+	 * @var boolean|null $initialized
64
+	 */
65
+	private $initialized;
66
+
67
+	/**
68
+	 * @var boolean $reset
69
+	 */
70
+	private $reset = false;
71
+
72
+
73
+	/**
74
+	 * singleton method used to instantiate class object
75
+	 *
76
+	 * @since 4.5.0
77
+	 *
78
+	 * @return EE_Capabilities
79
+	 */
80
+	public static function instance()
81
+	{
82
+		// check if instantiated, and if not do so.
83
+		if (! self::$_instance instanceof EE_Capabilities) {
84
+			self::$_instance = new self();
85
+		}
86
+		return self::$_instance;
87
+	}
88
+
89
+
90
+	/**
91
+	 * private constructor
92
+	 *
93
+	 * @since 4.5.0
94
+	 */
95
+	private function __construct()
96
+	{
97
+	}
98
+
99
+
100
+	/**
101
+	 * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
102
+	 *
103
+	 * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
104
+	 *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
105
+	 *                    ensures that they are up to date.
106
+	 *
107
+	 * @since 4.5.0
108
+	 * @return bool
109
+	 * @throws EE_Error
110
+	 */
111
+	public function init_caps($reset = false)
112
+	{
113
+		if (! EE_Maintenance_Mode::instance()->models_can_query()) {
114
+			return false;
115
+		}
116
+		$this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
117
+		// if reset, then completely delete the cache option and clear the $capabilities_map property.
118
+		if ($this->reset) {
119
+			$this->initialized = null;
120
+			$this->capabilities_map = array();
121
+			delete_option(self::option_name);
122
+		}
123
+		if ($this->initialized === null) {
124
+			$this->initialized = false;
125
+			do_action(
126
+				'AHEE__EE_Capabilities__init_caps__before_initialization',
127
+				$this->reset
128
+			);
129
+			$this->addCaps($this->_init_caps_map());
130
+			$this->_set_meta_caps();
131
+			do_action(
132
+				'AHEE__EE_Capabilities__init_caps__after_initialization',
133
+				$this->capabilities_map
134
+			);
135
+			$this->initialized = true;
136
+		}
137
+		// reset $this->reset so that it's not stuck on true if init_caps() gets called again
138
+		$this->reset = false;
139
+		return true;
140
+	}
141
+
142
+
143
+	/**
144
+	 * This sets the meta caps property.
145
+	 *
146
+	 * @since 4.5.0
147
+	 * @return void
148
+	 * @throws EE_Error
149
+	 */
150
+	private function _set_meta_caps()
151
+	{
152
+		// get default meta caps and filter the returned array
153
+		$this->_meta_caps = apply_filters(
154
+			'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
155
+			$this->_get_default_meta_caps_array()
156
+		);
157
+		// add filter for map_meta_caps but only if models can query.
158
+		if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159
+			add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160
+		}
161
+	}
162
+
163
+
164
+	/**
165
+	 * This builds and returns the default meta_caps array only once.
166
+	 *
167
+	 * @since  4.8.28.rc.012
168
+	 * @return array
169
+	 * @throws EE_Error
170
+	 */
171
+	private function _get_default_meta_caps_array()
172
+	{
173
+		static $default_meta_caps = array();
174
+		// make sure we're only ever initializing the default _meta_caps array once if it's empty.
175
+		if (empty($default_meta_caps)) {
176
+			$default_meta_caps = array(
177
+				// edits
178
+				new EE_Meta_Capability_Map_Edit(
179
+					'ee_edit_event',
180
+					array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
181
+				),
182
+				new EE_Meta_Capability_Map_Edit(
183
+					'ee_edit_venue',
184
+					array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
185
+				),
186
+				new EE_Meta_Capability_Map_Edit(
187
+					'ee_edit_registration',
188
+					array('Registration', '', 'ee_edit_others_registrations', '')
189
+				),
190
+				new EE_Meta_Capability_Map_Edit(
191
+					'ee_edit_checkin',
192
+					array('Registration', '', 'ee_edit_others_checkins', '')
193
+				),
194
+				new EE_Meta_Capability_Map_Messages_Cap(
195
+					'ee_edit_message',
196
+					array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
197
+				),
198
+				new EE_Meta_Capability_Map_Edit(
199
+					'ee_edit_default_ticket',
200
+					array('Ticket', '', 'ee_edit_others_default_tickets', '')
201
+				),
202
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
203
+					'ee_edit_question',
204
+					array('Question', '', '', 'ee_edit_system_questions')
205
+				),
206
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
207
+					'ee_edit_question_group',
208
+					array('Question_Group', '', '', 'ee_edit_system_question_groups')
209
+				),
210
+				new EE_Meta_Capability_Map_Edit(
211
+					'ee_edit_payment_method',
212
+					array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
213
+				),
214
+				// reads
215
+				new EE_Meta_Capability_Map_Read(
216
+					'ee_read_event',
217
+					array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
218
+				),
219
+				new EE_Meta_Capability_Map_Read(
220
+					'ee_read_venue',
221
+					array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
222
+				),
223
+				new EE_Meta_Capability_Map_Read(
224
+					'ee_read_registration',
225
+					array('Registration', '', 'ee_read_others_registrations', '')
226
+				),
227
+				new EE_Meta_Capability_Map_Read(
228
+					'ee_read_checkin',
229
+					array('Registration', '', 'ee_read_others_checkins', '')
230
+				),
231
+				new EE_Meta_Capability_Map_Messages_Cap(
232
+					'ee_read_message',
233
+					array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
234
+				),
235
+				new EE_Meta_Capability_Map_Read(
236
+					'ee_read_default_ticket',
237
+					array('Ticket', '', 'ee_read_others_default_tickets', '')
238
+				),
239
+				new EE_Meta_Capability_Map_Read(
240
+					'ee_read_payment_method',
241
+					array('Payment_Method', '', 'ee_read_others_payment_methods', '')
242
+				),
243
+				// deletes
244
+				new EE_Meta_Capability_Map_Delete(
245
+					'ee_delete_event',
246
+					array(
247
+						'Event',
248
+						'ee_delete_published_events',
249
+						'ee_delete_others_events',
250
+						'ee_delete_private_events',
251
+					)
252
+				),
253
+				new EE_Meta_Capability_Map_Delete(
254
+					'ee_delete_venue',
255
+					array(
256
+						'Venue',
257
+						'ee_delete_published_venues',
258
+						'ee_delete_others_venues',
259
+						'ee_delete_private_venues',
260
+					)
261
+				),
262
+				new EE_Meta_Capability_Map_Delete(
263
+					'ee_delete_registration',
264
+					array('Registration', '', 'ee_delete_others_registrations', '')
265
+				),
266
+				new EE_Meta_Capability_Map_Delete(
267
+					'ee_delete_checkin',
268
+					array('Registration', '', 'ee_delete_others_checkins', '')
269
+				),
270
+				new EE_Meta_Capability_Map_Messages_Cap(
271
+					'ee_delete_message',
272
+					array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
273
+				),
274
+				new EE_Meta_Capability_Map_Delete(
275
+					'ee_delete_default_ticket',
276
+					array('Ticket', '', 'ee_delete_others_default_tickets', '')
277
+				),
278
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
279
+					'ee_delete_question',
280
+					array('Question', '', '', 'delete_system_questions')
281
+				),
282
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
283
+					'ee_delete_question_group',
284
+					array('Question_Group', '', '', 'delete_system_question_groups')
285
+				),
286
+				new EE_Meta_Capability_Map_Delete(
287
+					'ee_delete_payment_method',
288
+					array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
289
+				),
290
+			);
291
+		}
292
+		return $default_meta_caps;
293
+	}
294
+
295
+
296
+	/**
297
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
298
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
299
+	 *
300
+	 * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
301
+	 *
302
+	 * @since 4.5.0
303
+	 * @see   wp-includes/capabilities.php
304
+	 *
305
+	 * @param array  $caps    actual users capabilities
306
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
307
+	 * @param int    $user_id The user id
308
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
309
+	 * @return array actual users capabilities
310
+	 * @throws EE_Error
311
+	 */
312
+	public function map_meta_caps($caps, $cap, $user_id, $args)
313
+	{
314
+		if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315
+			// loop through our _meta_caps array
316
+			foreach ($this->_meta_caps as $meta_map) {
317
+				if (! $meta_map instanceof EE_Meta_Capability_Map) {
318
+					continue;
319
+				}
320
+				// don't load models if there is no object ID in the args
321
+				if (! empty($args[0])) {
322
+					$meta_map->ensure_is_model();
323
+				}
324
+				$caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
325
+			}
326
+		}
327
+		return $caps;
328
+	}
329
+
330
+
331
+	/**
332
+	 * This sets up and returns the initial capabilities map for Event Espresso
333
+	 * Note this array is filtered.
334
+	 * It is assumed that all available EE capabilities are assigned to the administrator role.
335
+	 *
336
+	 * @since 4.5.0
337
+	 *
338
+	 * @return array
339
+	 */
340
+	private function _init_caps_map()
341
+	{
342
+		return apply_filters(
343
+			'FHEE__EE_Capabilities__init_caps_map__caps',
344
+			array(
345
+				'administrator'           => array(
346
+					// basic access
347
+					'ee_read_ee',
348
+					// gateways
349
+					/**
350
+					 * note that with payment method capabilities, although we've implemented
351
+					 * capability mapping which will be used for accessing payment methods owned by
352
+					 * other users.  This is not fully implemented yet in the payment method ui.
353
+					 * Currently only the "plural" caps are in active use.
354
+					 * (Specific payment method caps are in use as well).
355
+					 **/
356
+					'ee_manage_gateways',
357
+					'ee_read_payment_methods',
358
+					'ee_read_others_payment_methods',
359
+					'ee_edit_payment_methods',
360
+					'ee_edit_others_payment_methods',
361
+					'ee_delete_payment_methods',
362
+					// events
363
+					'ee_publish_events',
364
+					'ee_read_private_events',
365
+					'ee_read_others_events',
366
+					'ee_read_events',
367
+					'ee_edit_events',
368
+					'ee_edit_published_events',
369
+					'ee_edit_others_events',
370
+					'ee_edit_private_events',
371
+					'ee_delete_published_events',
372
+					'ee_delete_private_events',
373
+					'ee_delete_events',
374
+					'ee_delete_others_events',
375
+					// event categories
376
+					'ee_manage_event_categories',
377
+					'ee_edit_event_category',
378
+					'ee_delete_event_category',
379
+					'ee_assign_event_category',
380
+					// venues
381
+					'ee_publish_venues',
382
+					'ee_read_venues',
383
+					'ee_read_others_venues',
384
+					'ee_read_private_venues',
385
+					'ee_edit_venues',
386
+					'ee_edit_others_venues',
387
+					'ee_edit_published_venues',
388
+					'ee_edit_private_venues',
389
+					'ee_delete_venues',
390
+					'ee_delete_others_venues',
391
+					'ee_delete_private_venues',
392
+					'ee_delete_published_venues',
393
+					// venue categories
394
+					'ee_manage_venue_categories',
395
+					'ee_edit_venue_category',
396
+					'ee_delete_venue_category',
397
+					'ee_assign_venue_category',
398
+					// contacts
399
+					'ee_read_contacts',
400
+					'ee_edit_contacts',
401
+					'ee_delete_contacts',
402
+					// registrations
403
+					'ee_read_registrations',
404
+					'ee_read_others_registrations',
405
+					'ee_edit_registrations',
406
+					'ee_edit_others_registrations',
407
+					'ee_delete_registrations',
408
+					'ee_delete_others_registrations',
409
+					// checkins
410
+					'ee_read_others_checkins',
411
+					'ee_read_checkins',
412
+					'ee_edit_checkins',
413
+					'ee_edit_others_checkins',
414
+					'ee_delete_checkins',
415
+					'ee_delete_others_checkins',
416
+					// transactions && payments
417
+					'ee_read_transaction',
418
+					'ee_read_transactions',
419
+					'ee_edit_payments',
420
+					'ee_delete_payments',
421
+					// messages
422
+					'ee_read_messages',
423
+					'ee_read_others_messages',
424
+					'ee_read_global_messages',
425
+					'ee_edit_global_messages',
426
+					'ee_edit_messages',
427
+					'ee_edit_others_messages',
428
+					'ee_delete_messages',
429
+					'ee_delete_others_messages',
430
+					'ee_delete_global_messages',
431
+					'ee_send_message',
432
+					// tickets
433
+					'ee_read_default_tickets',
434
+					'ee_read_others_default_tickets',
435
+					'ee_edit_default_tickets',
436
+					'ee_edit_others_default_tickets',
437
+					'ee_delete_default_tickets',
438
+					'ee_delete_others_default_tickets',
439
+					// prices
440
+					'ee_edit_default_price',
441
+					'ee_edit_default_prices',
442
+					'ee_delete_default_price',
443
+					'ee_delete_default_prices',
444
+					'ee_edit_default_price_type',
445
+					'ee_edit_default_price_types',
446
+					'ee_delete_default_price_type',
447
+					'ee_delete_default_price_types',
448
+					'ee_read_default_prices',
449
+					'ee_read_default_price_types',
450
+					// registration form
451
+					'ee_edit_questions',
452
+					'ee_edit_system_questions',
453
+					'ee_read_questions',
454
+					'ee_delete_questions',
455
+					'ee_edit_question_groups',
456
+					'ee_read_question_groups',
457
+					'ee_edit_system_question_groups',
458
+					'ee_delete_question_groups',
459
+					// event_type taxonomy
460
+					'ee_assign_event_type',
461
+					'ee_manage_event_types',
462
+					'ee_edit_event_type',
463
+					'ee_delete_event_type',
464
+				),
465
+				'ee_events_administrator' => array(
466
+					// core wp caps
467
+					'read',
468
+					'read_private_pages',
469
+					'read_private_posts',
470
+					'edit_users',
471
+					'edit_posts',
472
+					'edit_pages',
473
+					'edit_published_posts',
474
+					'edit_published_pages',
475
+					'edit_private_pages',
476
+					'edit_private_posts',
477
+					'edit_others_posts',
478
+					'edit_others_pages',
479
+					'publish_posts',
480
+					'publish_pages',
481
+					'delete_posts',
482
+					'delete_pages',
483
+					'delete_private_pages',
484
+					'delete_private_posts',
485
+					'delete_published_pages',
486
+					'delete_published_posts',
487
+					'delete_others_posts',
488
+					'delete_others_pages',
489
+					'manage_categories',
490
+					'manage_links',
491
+					'moderate_comments',
492
+					'unfiltered_html',
493
+					'upload_files',
494
+					'export',
495
+					'import',
496
+					'list_users',
497
+					'level_1', // required if user with this role shows up in author dropdowns
498
+					// basic ee access
499
+					'ee_read_ee',
500
+					// events
501
+					'ee_publish_events',
502
+					'ee_read_private_events',
503
+					'ee_read_others_events',
504
+					'ee_read_event',
505
+					'ee_read_events',
506
+					'ee_edit_event',
507
+					'ee_edit_events',
508
+					'ee_edit_published_events',
509
+					'ee_edit_others_events',
510
+					'ee_edit_private_events',
511
+					'ee_delete_published_events',
512
+					'ee_delete_private_events',
513
+					'ee_delete_event',
514
+					'ee_delete_events',
515
+					'ee_delete_others_events',
516
+					// event categories
517
+					'ee_manage_event_categories',
518
+					'ee_edit_event_category',
519
+					'ee_delete_event_category',
520
+					'ee_assign_event_category',
521
+					// venues
522
+					'ee_publish_venues',
523
+					'ee_read_venue',
524
+					'ee_read_venues',
525
+					'ee_read_others_venues',
526
+					'ee_read_private_venues',
527
+					'ee_edit_venue',
528
+					'ee_edit_venues',
529
+					'ee_edit_others_venues',
530
+					'ee_edit_published_venues',
531
+					'ee_edit_private_venues',
532
+					'ee_delete_venue',
533
+					'ee_delete_venues',
534
+					'ee_delete_others_venues',
535
+					'ee_delete_private_venues',
536
+					'ee_delete_published_venues',
537
+					// venue categories
538
+					'ee_manage_venue_categories',
539
+					'ee_edit_venue_category',
540
+					'ee_delete_venue_category',
541
+					'ee_assign_venue_category',
542
+					// contacts
543
+					'ee_read_contacts',
544
+					'ee_edit_contacts',
545
+					'ee_delete_contacts',
546
+					// registrations
547
+					'ee_read_registrations',
548
+					'ee_read_others_registrations',
549
+					'ee_edit_registration',
550
+					'ee_edit_registrations',
551
+					'ee_edit_others_registrations',
552
+					'ee_delete_registration',
553
+					'ee_delete_registrations',
554
+					'ee_delete_others_registrations',
555
+					// checkins
556
+					'ee_read_others_checkins',
557
+					'ee_read_checkins',
558
+					'ee_edit_checkins',
559
+					'ee_edit_others_checkins',
560
+					'ee_delete_checkins',
561
+					'ee_delete_others_checkins',
562
+					// transactions && payments
563
+					'ee_read_transaction',
564
+					'ee_read_transactions',
565
+					'ee_edit_payments',
566
+					'ee_delete_payments',
567
+					// messages
568
+					'ee_read_messages',
569
+					'ee_read_others_messages',
570
+					'ee_read_global_messages',
571
+					'ee_edit_global_messages',
572
+					'ee_edit_messages',
573
+					'ee_edit_others_messages',
574
+					'ee_delete_messages',
575
+					'ee_delete_others_messages',
576
+					'ee_delete_global_messages',
577
+					'ee_send_message',
578
+					// tickets
579
+					'ee_read_default_tickets',
580
+					'ee_read_others_default_tickets',
581
+					'ee_edit_default_tickets',
582
+					'ee_edit_others_default_tickets',
583
+					'ee_delete_default_tickets',
584
+					'ee_delete_others_default_tickets',
585
+					// prices
586
+					'ee_edit_default_price',
587
+					'ee_edit_default_prices',
588
+					'ee_delete_default_price',
589
+					'ee_delete_default_prices',
590
+					'ee_edit_default_price_type',
591
+					'ee_edit_default_price_types',
592
+					'ee_delete_default_price_type',
593
+					'ee_delete_default_price_types',
594
+					'ee_read_default_prices',
595
+					'ee_read_default_price_types',
596
+					// registration form
597
+					'ee_edit_questions',
598
+					'ee_edit_system_questions',
599
+					'ee_read_questions',
600
+					'ee_delete_questions',
601
+					'ee_edit_question_groups',
602
+					'ee_read_question_groups',
603
+					'ee_edit_system_question_groups',
604
+					'ee_delete_question_groups',
605
+					// event_type taxonomy
606
+					'ee_assign_event_type',
607
+					'ee_manage_event_types',
608
+					'ee_edit_event_type',
609
+					'ee_delete_event_type',
610
+				),
611
+			)
612
+		);
613
+	}
614
+
615
+
616
+	/**
617
+	 * @return bool
618
+	 * @throws EE_Error
619
+	 */
620
+	private function setupCapabilitiesMap()
621
+	{
622
+		// if the initialization process hasn't even started, then we need to call init_caps()
623
+		if ($this->initialized === null) {
624
+			return $this->init_caps();
625
+		}
626
+		// unless resetting, get caps from db if we haven't already
627
+		$this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
628
+			? $this->capabilities_map
629
+			: get_option(self::option_name, array());
630
+		return true;
631
+	}
632
+
633
+
634
+	/**
635
+	 * @param bool $update
636
+	 * @return bool
637
+	 */
638
+	private function updateCapabilitiesMap($update = true)
639
+	{
640
+		return $update ? update_option(self::option_name, $this->capabilities_map) : false;
641
+	}
642
+
643
+
644
+	/**
645
+	 * Adds capabilities to roles.
646
+	 *
647
+	 * @since 4.9.42
648
+	 * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
649
+	 *                                   Note that this should ONLY be called on activation hook
650
+	 *                                   otherwise the caps will be added on every request.
651
+	 * @return bool
652
+	 * @throws \EE_Error
653
+	 */
654
+	public function addCaps(array $capabilities_to_add)
655
+	{
656
+		// don't do anything if the capabilities map can not be initialized
657
+		if (! $this->setupCapabilitiesMap()) {
658
+			return false;
659
+		}
660
+		// and filter the array so others can get in on the fun during resets
661
+		$capabilities_to_add = apply_filters(
662
+			'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
663
+			$capabilities_to_add,
664
+			$this->reset,
665
+			$this->capabilities_map
666
+		);
667
+		$update_capabilities_map = false;
668
+		// if not reset, see what caps are new for each role. if they're new, add them.
669
+		foreach ($capabilities_to_add as $role => $caps_for_role) {
670
+			if (is_array($caps_for_role)) {
671
+				foreach ($caps_for_role as $cap) {
672
+					if (
673
+						! $this->capHasBeenAddedToRole($role, $cap)
674
+						&& $this->add_cap_to_role($role, $cap, true, false)
675
+					) {
676
+						$update_capabilities_map = true;
677
+					}
678
+				}
679
+			}
680
+		}
681
+		// now let's just save the cap that has been set but only if there's been a change.
682
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
683
+		$this->flushWpUser($updated);
684
+		do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
685
+		return $updated;
686
+	}
687
+
688
+
689
+	/**
690
+	 * Loops through the capabilities map and removes the role caps specified by the incoming array
691
+	 *
692
+	 * @param array $caps_map map of capabilities to be removed (indexed by roles)
693
+	 * @return bool
694
+	 * @throws \EE_Error
695
+	 */
696
+	public function removeCaps($caps_map)
697
+	{
698
+		// don't do anything if the capabilities map can not be initialized
699
+		if (! $this->setupCapabilitiesMap()) {
700
+			return false;
701
+		}
702
+		$update_capabilities_map = false;
703
+		foreach ($caps_map as $role => $caps_for_role) {
704
+			if (is_array($caps_for_role)) {
705
+				foreach ($caps_for_role as $cap) {
706
+					if (
707
+						$this->capHasBeenAddedToRole($role, $cap)
708
+						&& $this->remove_cap_from_role($role, $cap, false)
709
+					) {
710
+						$update_capabilities_map = true;
711
+					}
712
+				}
713
+			}
714
+		}
715
+		// maybe resave the caps
716
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
717
+		$this->flushWpUser($updated);
718
+		return $updated;
719
+	}
720
+
721
+
722
+	/**
723
+	 * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
724
+	 * the roles on that user.
725
+	 *
726
+	 * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
727
+	 */
728
+	private function flushWpUser($flush = true)
729
+	{
730
+		if ($flush) {
731
+			$user = wp_get_current_user();
732
+			if ($user instanceof WP_User) {
733
+				$user->get_role_caps();
734
+			}
735
+		}
736
+	}
737
+
738
+
739
+	/**
740
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
741
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
742
+	 * this is a wrapper for $wp_role->add_cap()
743
+	 *
744
+	 * @see   wp-includes/capabilities.php
745
+	 * @since 4.5.0
746
+	 * @param string|WP_Role $role  A WordPress role the capability is being added to
747
+	 * @param string         $cap   The capability being added to the role
748
+	 * @param bool           $grant Whether to grant access to this cap on this role.
749
+	 * @param bool           $update_capabilities_map
750
+	 * @return bool
751
+	 * @throws \EE_Error
752
+	 */
753
+	public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
754
+	{
755
+		// capture incoming value for $role because we may need it to create a new WP_Role
756
+		$orig_role = $role;
757
+		$role = $role instanceof WP_Role ? $role : get_role($role);
758
+		// if the role isn't available then we create it.
759
+		if (! $role instanceof WP_Role) {
760
+			// if a plugin wants to create a specific role name then they should create the role before
761
+			// EE_Capabilities does.  Otherwise this function will create the role name from the slug:
762
+			// - removes any `ee_` namespacing from the start of the slug.
763
+			// - replaces `_` with ` ` (empty space).
764
+			// - sentence case on the resulting string.
765
+			$role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
766
+			$role = add_role($orig_role, $role_label);
767
+		}
768
+		if ($role instanceof WP_Role) {
769
+			// don't do anything if the capabilities map can not be initialized
770
+			if (! $this->setupCapabilitiesMap()) {
771
+				return false;
772
+			}
773
+			if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
774
+				$role->add_cap($cap, $grant);
775
+				$this->capabilities_map[ $role->name ][] = $cap;
776
+				$this->updateCapabilitiesMap($update_capabilities_map);
777
+				return true;
778
+			}
779
+		}
780
+		return false;
781
+	}
782
+
783
+
784
+	/**
785
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
786
+	 * Wrapper for $wp_role->remove_cap()
787
+	 *
788
+	 * @see   wp-includes/capabilities.php
789
+	 * @since 4.5.0
790
+	 * @param string|WP_Role $role A WordPress role the capability is being removed from.
791
+	 * @param string         $cap  The capability being removed
792
+	 * @param bool           $update_capabilities_map
793
+	 * @return bool
794
+	 * @throws \EE_Error
795
+	 */
796
+	public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
797
+	{
798
+		// don't do anything if the capabilities map can not be initialized
799
+		if (! $this->setupCapabilitiesMap()) {
800
+			return false;
801
+		}
802
+
803
+		$role = $role instanceof WP_Role ? $role : get_role($role);
804
+		if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
805
+			$role->remove_cap($cap);
806
+			unset($this->capabilities_map[ $role->name ][ $index ]);
807
+			$this->updateCapabilitiesMap($update_capabilities_map);
808
+			return true;
809
+		}
810
+		return false;
811
+	}
812
+
813
+
814
+	/**
815
+	 * @param string $role_name
816
+	 * @param string $cap
817
+	 * @param bool   $get_index
818
+	 * @return bool|mixed
819
+	 */
820
+	private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
821
+	{
822
+		if (
823
+			isset($this->capabilities_map[ $role_name ])
824
+			&& ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
825
+		) {
826
+			return $get_index ? $index : true;
827
+		}
828
+		return false;
829
+	}
830
+
831
+
832
+	/**
833
+	 * Wrapper for the native WP current_user_can() method.
834
+	 * This is provided as a handy method for a couple things:
835
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
836
+	 * write those filters wherever current_user_can is called).
837
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
838
+	 *
839
+	 * @since 4.5.0
840
+	 *
841
+	 * @param string $cap     The cap being checked.
842
+	 * @param string $context The context where the current_user_can is being called from.
843
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
844
+	 *                        filters.
845
+	 *
846
+	 * @return bool  Whether user can or not.
847
+	 */
848
+	public function current_user_can($cap, $context, $id = 0)
849
+	{
850
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
851
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
852
+		$filtered_cap = apply_filters(
853
+			'FHEE__EE_Capabilities__current_user_can__cap',
854
+			$filtered_cap,
855
+			$context,
856
+			$cap,
857
+			$id
858
+		);
859
+		return ! empty($id)
860
+			? current_user_can($filtered_cap, $id)
861
+			: current_user_can($filtered_cap);
862
+	}
863
+
864
+
865
+	/**
866
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
867
+	 *
868
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
869
+	 * @param string      $cap     The capability string being checked
870
+	 * @param string      $context The context where the user_can is being called from (used in filters).
871
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
872
+	 *                             filters)
873
+	 *
874
+	 * @return bool Whether user can or not.
875
+	 */
876
+	public function user_can($user, $cap, $context, $id = 0)
877
+	{
878
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
879
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
880
+		$filtered_cap = apply_filters(
881
+			'FHEE__EE_Capabilities__user_can__cap',
882
+			$filtered_cap,
883
+			$context,
884
+			$cap,
885
+			$user,
886
+			$id
887
+		);
888
+		return ! empty($id)
889
+			? user_can($user, $filtered_cap, $id)
890
+			: user_can($user, $filtered_cap);
891
+	}
892
+
893
+
894
+	/**
895
+	 * Wrapper for the native WP current_user_can_for_blog() method.
896
+	 * This is provided as a handy method for a couple things:
897
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
898
+	 * write those filters wherever current_user_can is called).
899
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
900
+	 *
901
+	 * @since 4.5.0
902
+	 *
903
+	 * @param int    $blog_id The blog id that is being checked for.
904
+	 * @param string $cap     The cap being checked.
905
+	 * @param string $context The context where the current_user_can is being called from.
906
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
907
+	 *                        filters.
908
+	 *
909
+	 * @return bool  Whether user can or not.
910
+	 */
911
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
912
+	{
913
+		$user_can = ! empty($id)
914
+			? current_user_can_for_blog($blog_id, $cap, $id)
915
+			: current_user_can($blog_id, $cap);
916
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
917
+		$user_can = apply_filters(
918
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
919
+			$user_can,
920
+			$blog_id,
921
+			$cap,
922
+			$id
923
+		);
924
+		$user_can = apply_filters(
925
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
926
+			$user_can,
927
+			$context,
928
+			$blog_id,
929
+			$cap,
930
+			$id
931
+		);
932
+		return $user_can;
933
+	}
934
+
935
+
936
+	/**
937
+	 * This helper method just returns an array of registered EE capabilities.
938
+	 *
939
+	 * @since 4.5.0
940
+	 * @param string $role If empty then the entire role/capability map is returned.
941
+	 *                     Otherwise just the capabilities for the given role are returned.
942
+	 * @return array
943
+	 * @throws EE_Error
944
+	 */
945
+	public function get_ee_capabilities($role = 'administrator')
946
+	{
947
+		if (! $this->initialized) {
948
+			$this->init_caps();
949
+		}
950
+		if (empty($role)) {
951
+			return $this->capabilities_map;
952
+		}
953
+		return isset($this->capabilities_map[ $role ])
954
+			? $this->capabilities_map[ $role ]
955
+			: array();
956
+	}
957
+
958
+
959
+	/**
960
+	 * @deprecated 4.9.42
961
+	 * @param bool  $reset      If you need to reset Event Espresso's capabilities,
962
+	 *                          then please use the init_caps() method with the "$reset" parameter set to "true"
963
+	 * @param array $caps_map   Optional.
964
+	 *                          Can be used to send a custom map of roles and capabilities for setting them up.
965
+	 *                          Note that this should ONLY be called on activation hook or some other one-time
966
+	 *                          task otherwise the caps will be added on every request.
967
+	 * @return void
968
+	 * @throws EE_Error
969
+	 */
970
+	public function init_role_caps($reset = false, $caps_map = array())
971
+	{
972
+		// If this method is called directly and reset is set as 'true',
973
+		// then display a doing it wrong notice, because we want resets to go through init_caps()
974
+		// to guarantee that everything is set up correctly.
975
+		// This prevents the capabilities map getting reset incorrectly by direct calls to this method.
976
+		if ($reset) {
977
+			EE_Error::doing_it_wrong(
978
+				__METHOD__,
979
+				sprintf(
980
+					esc_html__(
981
+						'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
982
+						'event_espresso'
983
+					),
984
+					'$reset',
985
+					__METHOD__ . '()',
986
+					'EE_Capabilities::init_caps()',
987
+					'true'
988
+				),
989
+				'4.9.42',
990
+				'5.0.0'
991
+			);
992
+		}
993
+		$this->addCaps($caps_map);
994
+	}
995 995
 }
996 996
 
997 997
 
@@ -1008,142 +1008,142 @@  discard block
 block discarded – undo
1008 1008
 abstract class EE_Meta_Capability_Map
1009 1009
 {
1010 1010
 
1011
-    public $meta_cap;
1012
-
1013
-    /**
1014
-     * @var EEM_Base
1015
-     */
1016
-    protected $_model;
1017
-
1018
-    protected $_model_name;
1019
-
1020
-    public $published_cap = '';
1021
-
1022
-    public $others_cap = '';
1023
-
1024
-    public $private_cap = '';
1025
-
1026
-
1027
-    /**
1028
-     * constructor.
1029
-     * Receives the setup arguments for the map.
1030
-     *
1031
-     * @since                        4.5.0
1032
-     *
1033
-     * @param string $meta_cap   What meta capability is this mapping.
1034
-     * @param array  $map_values array {
1035
-     *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1036
-     *                           capabilities that don't get mapped to.
1037
-     *
1038
-     * @type         $map_values [0] string A string representing the model name. Required.  String's
1039
-     *                               should always be used when Menu Maps are registered via the
1040
-     *                               plugin API as models are not allowed to be instantiated when
1041
-     *                               in maintenance mode 2 (migrations).
1042
-     * @type         $map_values [1] string represents the capability used for published. Optional.
1043
-     * @type         $map_values [2] string represents the capability used for "others". Optional.
1044
-     * @type         $map_values [3] string represents the capability used for private. Optional.
1045
-     *                               }
1046
-     * @throws EE_Error
1047
-     */
1048
-    public function __construct($meta_cap, $map_values)
1049
-    {
1050
-        $this->meta_cap = $meta_cap;
1051
-        // verify there are four args in the $map_values array;
1052
-        if (count($map_values) !== 4) {
1053
-            throw new EE_Error(
1054
-                sprintf(
1055
-                    esc_html__(
1056
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1057
-                        'event_espresso'
1058
-                    ),
1059
-                    '<br>' . print_r($map_values, true)
1060
-                )
1061
-            );
1062
-        }
1063
-        // set properties
1064
-        $this->_model = null;
1065
-        $this->_model_name = $map_values[0];
1066
-        $this->published_cap = (string) $map_values[1];
1067
-        $this->others_cap = (string) $map_values[2];
1068
-        $this->private_cap = (string) $map_values[3];
1069
-    }
1070
-
1071
-    /**
1072
-     * Makes it so this object stops filtering caps
1073
-     */
1074
-    public function remove_filters()
1075
-    {
1076
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1077
-    }
1078
-
1079
-
1080
-    /**
1081
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1082
-     *
1083
-     * @since 4.5.0
1084
-     * @throws EE_Error
1085
-     *
1086
-     * @return void
1087
-     */
1088
-    public function ensure_is_model()
1089
-    {
1090
-        // is it already instantiated?
1091
-        if ($this->_model instanceof EEM_Base) {
1092
-            return;
1093
-        }
1094
-        // ensure model name is string
1095
-        $this->_model_name = (string) $this->_model_name;
1096
-        // error proof if the name has EEM in it
1097
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
1098
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1099
-        if (! $this->_model instanceof EEM_Base) {
1100
-            throw new EE_Error(
1101
-                sprintf(
1102
-                    esc_html__(
1103
-                        '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',
1104
-                        'event_espresso'
1105
-                    ),
1106
-                    get_class($this),
1107
-                    $this->_model
1108
-                )
1109
-            );
1110
-        }
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     *
1116
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1117
-     * @since 4.6.x
1118
-     *
1119
-     * @param $caps
1120
-     * @param $cap
1121
-     * @param $user_id
1122
-     * @param $args
1123
-     *
1124
-     * @return array
1125
-     */
1126
-    public function map_meta_caps($caps, $cap, $user_id, $args)
1127
-    {
1128
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1129
-    }
1130
-
1131
-
1132
-    /**
1133
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1134
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1135
-     *
1136
-     * @since 4.5.0
1137
-     * @see   wp-includes/capabilities.php
1138
-     *
1139
-     * @param array  $caps    actual users capabilities
1140
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1141
-     * @param int    $user_id The user id
1142
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1143
-     *
1144
-     * @return array   actual users capabilities
1145
-     */
1146
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1011
+	public $meta_cap;
1012
+
1013
+	/**
1014
+	 * @var EEM_Base
1015
+	 */
1016
+	protected $_model;
1017
+
1018
+	protected $_model_name;
1019
+
1020
+	public $published_cap = '';
1021
+
1022
+	public $others_cap = '';
1023
+
1024
+	public $private_cap = '';
1025
+
1026
+
1027
+	/**
1028
+	 * constructor.
1029
+	 * Receives the setup arguments for the map.
1030
+	 *
1031
+	 * @since                        4.5.0
1032
+	 *
1033
+	 * @param string $meta_cap   What meta capability is this mapping.
1034
+	 * @param array  $map_values array {
1035
+	 *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1036
+	 *                           capabilities that don't get mapped to.
1037
+	 *
1038
+	 * @type         $map_values [0] string A string representing the model name. Required.  String's
1039
+	 *                               should always be used when Menu Maps are registered via the
1040
+	 *                               plugin API as models are not allowed to be instantiated when
1041
+	 *                               in maintenance mode 2 (migrations).
1042
+	 * @type         $map_values [1] string represents the capability used for published. Optional.
1043
+	 * @type         $map_values [2] string represents the capability used for "others". Optional.
1044
+	 * @type         $map_values [3] string represents the capability used for private. Optional.
1045
+	 *                               }
1046
+	 * @throws EE_Error
1047
+	 */
1048
+	public function __construct($meta_cap, $map_values)
1049
+	{
1050
+		$this->meta_cap = $meta_cap;
1051
+		// verify there are four args in the $map_values array;
1052
+		if (count($map_values) !== 4) {
1053
+			throw new EE_Error(
1054
+				sprintf(
1055
+					esc_html__(
1056
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1057
+						'event_espresso'
1058
+					),
1059
+					'<br>' . print_r($map_values, true)
1060
+				)
1061
+			);
1062
+		}
1063
+		// set properties
1064
+		$this->_model = null;
1065
+		$this->_model_name = $map_values[0];
1066
+		$this->published_cap = (string) $map_values[1];
1067
+		$this->others_cap = (string) $map_values[2];
1068
+		$this->private_cap = (string) $map_values[3];
1069
+	}
1070
+
1071
+	/**
1072
+	 * Makes it so this object stops filtering caps
1073
+	 */
1074
+	public function remove_filters()
1075
+	{
1076
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1077
+	}
1078
+
1079
+
1080
+	/**
1081
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1082
+	 *
1083
+	 * @since 4.5.0
1084
+	 * @throws EE_Error
1085
+	 *
1086
+	 * @return void
1087
+	 */
1088
+	public function ensure_is_model()
1089
+	{
1090
+		// is it already instantiated?
1091
+		if ($this->_model instanceof EEM_Base) {
1092
+			return;
1093
+		}
1094
+		// ensure model name is string
1095
+		$this->_model_name = (string) $this->_model_name;
1096
+		// error proof if the name has EEM in it
1097
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
1098
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
1099
+		if (! $this->_model instanceof EEM_Base) {
1100
+			throw new EE_Error(
1101
+				sprintf(
1102
+					esc_html__(
1103
+						'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',
1104
+						'event_espresso'
1105
+					),
1106
+					get_class($this),
1107
+					$this->_model
1108
+				)
1109
+			);
1110
+		}
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 *
1116
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1117
+	 * @since 4.6.x
1118
+	 *
1119
+	 * @param $caps
1120
+	 * @param $cap
1121
+	 * @param $user_id
1122
+	 * @param $args
1123
+	 *
1124
+	 * @return array
1125
+	 */
1126
+	public function map_meta_caps($caps, $cap, $user_id, $args)
1127
+	{
1128
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1129
+	}
1130
+
1131
+
1132
+	/**
1133
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1134
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1135
+	 *
1136
+	 * @since 4.5.0
1137
+	 * @see   wp-includes/capabilities.php
1138
+	 *
1139
+	 * @param array  $caps    actual users capabilities
1140
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1141
+	 * @param int    $user_id The user id
1142
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1143
+	 *
1144
+	 * @return array   actual users capabilities
1145
+	 */
1146
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1147 1147
 }
1148 1148
 
1149 1149
 
@@ -1159,81 +1159,81 @@  discard block
 block discarded – undo
1159 1159
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
1160 1160
 {
1161 1161
 
1162
-    /**
1163
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1164
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1165
-     *
1166
-     * @since 4.5.0
1167
-     * @see   wp-includes/capabilities.php
1168
-     *
1169
-     * @param array  $caps    actual users capabilities
1170
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1171
-     * @param int    $user_id The user id
1172
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1173
-     *
1174
-     * @return array   actual users capabilities
1175
-     */
1176
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1177
-    {
1178
-        // only process if we're checking our mapped_cap
1179
-        if ($cap !== $this->meta_cap) {
1180
-            return $caps;
1181
-        }
1182
-
1183
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1184
-        if (($key = array_search($cap, $caps)) !== false) {
1185
-            unset($caps[ $key ]);
1186
-        }
1187
-
1188
-        // cast $user_id to int for later explicit comparisons
1189
-        $user_id = (int) $user_id;
1190
-
1191
-        /** @var EE_Base_Class $obj */
1192
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1193
-        // if no obj then let's just do cap
1194
-        if (! $obj instanceof EE_Base_Class) {
1195
-            $caps[] = 'do_not_allow';
1196
-            return $caps;
1197
-        }
1198
-        $caps[] = $cap . 's';
1199
-        if ($obj instanceof EE_CPT_Base) {
1200
-            // if the item author is set and the user is the author...
1201
-            if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1202
-                // if obj is published...
1203
-                if ($obj->status() === 'publish') {
1204
-                    $caps[] = $this->published_cap;
1205
-                }
1206
-            } else {
1207
-                // the user is trying to edit someone else's obj
1208
-                if (! empty($this->others_cap)) {
1209
-                    $caps[] = $this->others_cap;
1210
-                }
1211
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1212
-                    $caps[] = $this->published_cap;
1213
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1214
-                    $caps[] = $this->private_cap;
1215
-                }
1216
-            }
1217
-        } else {
1218
-            // not a cpt object so handled differently
1219
-            $has_cap = false;
1220
-            try {
1221
-                $has_cap = method_exists($obj, 'wp_user')
1222
-                           && $obj->wp_user()
1223
-                           && $obj->wp_user() === $user_id;
1224
-            } catch (Exception $e) {
1225
-                if (WP_DEBUG) {
1226
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1227
-                }
1228
-            }
1229
-            if (! $has_cap) {
1230
-                if (! empty($this->others_cap)) {
1231
-                    $caps[] = $this->others_cap;
1232
-                }
1233
-            }
1234
-        }
1235
-        return $caps;
1236
-    }
1162
+	/**
1163
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1164
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1165
+	 *
1166
+	 * @since 4.5.0
1167
+	 * @see   wp-includes/capabilities.php
1168
+	 *
1169
+	 * @param array  $caps    actual users capabilities
1170
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1171
+	 * @param int    $user_id The user id
1172
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1173
+	 *
1174
+	 * @return array   actual users capabilities
1175
+	 */
1176
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1177
+	{
1178
+		// only process if we're checking our mapped_cap
1179
+		if ($cap !== $this->meta_cap) {
1180
+			return $caps;
1181
+		}
1182
+
1183
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1184
+		if (($key = array_search($cap, $caps)) !== false) {
1185
+			unset($caps[ $key ]);
1186
+		}
1187
+
1188
+		// cast $user_id to int for later explicit comparisons
1189
+		$user_id = (int) $user_id;
1190
+
1191
+		/** @var EE_Base_Class $obj */
1192
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1193
+		// if no obj then let's just do cap
1194
+		if (! $obj instanceof EE_Base_Class) {
1195
+			$caps[] = 'do_not_allow';
1196
+			return $caps;
1197
+		}
1198
+		$caps[] = $cap . 's';
1199
+		if ($obj instanceof EE_CPT_Base) {
1200
+			// if the item author is set and the user is the author...
1201
+			if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1202
+				// if obj is published...
1203
+				if ($obj->status() === 'publish') {
1204
+					$caps[] = $this->published_cap;
1205
+				}
1206
+			} else {
1207
+				// the user is trying to edit someone else's obj
1208
+				if (! empty($this->others_cap)) {
1209
+					$caps[] = $this->others_cap;
1210
+				}
1211
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1212
+					$caps[] = $this->published_cap;
1213
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1214
+					$caps[] = $this->private_cap;
1215
+				}
1216
+			}
1217
+		} else {
1218
+			// not a cpt object so handled differently
1219
+			$has_cap = false;
1220
+			try {
1221
+				$has_cap = method_exists($obj, 'wp_user')
1222
+						   && $obj->wp_user()
1223
+						   && $obj->wp_user() === $user_id;
1224
+			} catch (Exception $e) {
1225
+				if (WP_DEBUG) {
1226
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1227
+				}
1228
+			}
1229
+			if (! $has_cap) {
1230
+				if (! empty($this->others_cap)) {
1231
+					$caps[] = $this->others_cap;
1232
+				}
1233
+			}
1234
+		}
1235
+		return $caps;
1236
+	}
1237 1237
 }
1238 1238
 
1239 1239
 
@@ -1250,24 +1250,24 @@  discard block
 block discarded – undo
1250 1250
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1251 1251
 {
1252 1252
 
1253
-    /**
1254
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1255
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1256
-     *
1257
-     * @since 4.5.0
1258
-     * @see   wp-includes/capabilities.php
1259
-     *
1260
-     * @param array  $caps    actual users capabilities
1261
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1262
-     * @param int    $user_id The user id
1263
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1264
-     *
1265
-     * @return array   actual users capabilities
1266
-     */
1267
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1268
-    {
1269
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1270
-    }
1253
+	/**
1254
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1255
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1256
+	 *
1257
+	 * @since 4.5.0
1258
+	 * @see   wp-includes/capabilities.php
1259
+	 *
1260
+	 * @param array  $caps    actual users capabilities
1261
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1262
+	 * @param int    $user_id The user id
1263
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1264
+	 *
1265
+	 * @return array   actual users capabilities
1266
+	 */
1267
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1268
+	{
1269
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1270
+	}
1271 1271
 }
1272 1272
 
1273 1273
 
@@ -1283,86 +1283,86 @@  discard block
 block discarded – undo
1283 1283
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1284 1284
 {
1285 1285
 
1286
-    /**
1287
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1288
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1289
-     *
1290
-     * @since 4.5.0
1291
-     * @see   wp-includes/capabilities.php
1292
-     *
1293
-     * @param array  $caps    actual users capabilities
1294
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1295
-     * @param int    $user_id The user id
1296
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1297
-     *
1298
-     * @return array   actual users capabilities
1299
-     */
1300
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1301
-    {
1302
-        // only process if we're checking our mapped cap;
1303
-        if ($cap !== $this->meta_cap) {
1304
-            return $caps;
1305
-        }
1306
-
1307
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1308
-        if (($key = array_search($cap, $caps)) !== false) {
1309
-            unset($caps[ $key ]);
1310
-        }
1311
-
1312
-        // cast $user_id to int for later explicit comparisons
1313
-        $user_id = (int) $user_id;
1314
-
1315
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1316
-        // if no obj then let's just do cap
1317
-        if (! $obj instanceof EE_Base_Class) {
1318
-            $caps[] = 'do_not_allow';
1319
-            return $caps;
1320
-        }
1321
-
1322
-        $caps[] = $cap . 's';
1323
-        if ($obj instanceof EE_CPT_Base) {
1324
-            $status_obj = get_post_status_object($obj->status());
1325
-            if ($status_obj->public) {
1326
-                return $caps;
1327
-            }
1328
-            // if the item author is set and the user is not the author...
1329
-            if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1330
-                if (! empty($this->others_cap)) {
1331
-                    $caps[] = $this->others_cap;
1332
-                }
1333
-            }
1334
-            // yes this means that if users created the private post, they are able to see it regardless of private cap.
1335
-            if (
1336
-                $status_obj->private
1337
-                && ! empty($this->private_cap)
1338
-                && $obj->wp_user() !== $user_id
1339
-            ) {
1340
-                // the user is trying to view a private object for an object they don't own.
1341
-                $caps[] = $this->private_cap;
1342
-            }
1343
-        } else {
1344
-            // not a cpt object so handled differently
1345
-            $has_cap = false;
1346
-            try {
1347
-                $has_cap = method_exists($obj, 'wp_user')
1348
-                           && $obj->wp_user()
1349
-                           && $obj->wp_user() === $user_id;
1350
-            } catch (Exception $e) {
1351
-                if (WP_DEBUG) {
1352
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1353
-                }
1354
-            }
1355
-            if (! $has_cap) {
1356
-                if (! empty($this->private_cap)) {
1357
-                    $caps[] = $this->private_cap;
1358
-                }
1359
-                if (! empty($this->others_cap)) {
1360
-                    $caps[] = $this->others_cap;
1361
-                }
1362
-            }
1363
-        }
1364
-        return $caps;
1365
-    }
1286
+	/**
1287
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1288
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1289
+	 *
1290
+	 * @since 4.5.0
1291
+	 * @see   wp-includes/capabilities.php
1292
+	 *
1293
+	 * @param array  $caps    actual users capabilities
1294
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1295
+	 * @param int    $user_id The user id
1296
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1297
+	 *
1298
+	 * @return array   actual users capabilities
1299
+	 */
1300
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1301
+	{
1302
+		// only process if we're checking our mapped cap;
1303
+		if ($cap !== $this->meta_cap) {
1304
+			return $caps;
1305
+		}
1306
+
1307
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1308
+		if (($key = array_search($cap, $caps)) !== false) {
1309
+			unset($caps[ $key ]);
1310
+		}
1311
+
1312
+		// cast $user_id to int for later explicit comparisons
1313
+		$user_id = (int) $user_id;
1314
+
1315
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1316
+		// if no obj then let's just do cap
1317
+		if (! $obj instanceof EE_Base_Class) {
1318
+			$caps[] = 'do_not_allow';
1319
+			return $caps;
1320
+		}
1321
+
1322
+		$caps[] = $cap . 's';
1323
+		if ($obj instanceof EE_CPT_Base) {
1324
+			$status_obj = get_post_status_object($obj->status());
1325
+			if ($status_obj->public) {
1326
+				return $caps;
1327
+			}
1328
+			// if the item author is set and the user is not the author...
1329
+			if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1330
+				if (! empty($this->others_cap)) {
1331
+					$caps[] = $this->others_cap;
1332
+				}
1333
+			}
1334
+			// yes this means that if users created the private post, they are able to see it regardless of private cap.
1335
+			if (
1336
+				$status_obj->private
1337
+				&& ! empty($this->private_cap)
1338
+				&& $obj->wp_user() !== $user_id
1339
+			) {
1340
+				// the user is trying to view a private object for an object they don't own.
1341
+				$caps[] = $this->private_cap;
1342
+			}
1343
+		} else {
1344
+			// not a cpt object so handled differently
1345
+			$has_cap = false;
1346
+			try {
1347
+				$has_cap = method_exists($obj, 'wp_user')
1348
+						   && $obj->wp_user()
1349
+						   && $obj->wp_user() === $user_id;
1350
+			} catch (Exception $e) {
1351
+				if (WP_DEBUG) {
1352
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1353
+				}
1354
+			}
1355
+			if (! $has_cap) {
1356
+				if (! empty($this->private_cap)) {
1357
+					$caps[] = $this->private_cap;
1358
+				}
1359
+				if (! empty($this->others_cap)) {
1360
+					$caps[] = $this->others_cap;
1361
+				}
1362
+			}
1363
+		}
1364
+		return $caps;
1365
+	}
1366 1366
 }
1367 1367
 
1368 1368
 
@@ -1379,56 +1379,56 @@  discard block
 block discarded – undo
1379 1379
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1380 1380
 {
1381 1381
 
1382
-    /**
1383
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1384
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1385
-     *
1386
-     * @since 4.5.0
1387
-     * @see   wp-includes/capabilities.php
1388
-     *
1389
-     * @param array  $caps    actual users capabilities
1390
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1391
-     * @param int    $user_id The user id
1392
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1393
-     *
1394
-     * @return array   actual users capabilities
1395
-     */
1396
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1397
-    {
1398
-        // only process if we're checking our mapped_cap
1399
-        if ($cap !== $this->meta_cap) {
1400
-            return $caps;
1401
-        }
1402
-
1403
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1404
-        if (($key = array_search($cap, $caps)) !== false) {
1405
-            unset($caps[ $key ]);
1406
-        }
1407
-
1408
-        // cast $user_id to int for later explicit comparisons
1409
-        $user_id = (int) $user_id;
1410
-
1411
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1412
-        // if no obj then let's just do cap
1413
-        if (! $obj instanceof EE_Message_Template_Group) {
1414
-            $caps[] = 'do_not_allow';
1415
-            return $caps;
1416
-        }
1417
-        $caps[] = $cap . 's';
1418
-        $is_global = $obj->is_global();
1419
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1420
-            if ($is_global) {
1421
-                $caps[] = $this->private_cap;
1422
-            }
1423
-        } else {
1424
-            if ($is_global) {
1425
-                $caps[] = $this->private_cap;
1426
-            } else {
1427
-                $caps[] = $this->others_cap;
1428
-            }
1429
-        }
1430
-        return $caps;
1431
-    }
1382
+	/**
1383
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1384
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1385
+	 *
1386
+	 * @since 4.5.0
1387
+	 * @see   wp-includes/capabilities.php
1388
+	 *
1389
+	 * @param array  $caps    actual users capabilities
1390
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1391
+	 * @param int    $user_id The user id
1392
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1393
+	 *
1394
+	 * @return array   actual users capabilities
1395
+	 */
1396
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1397
+	{
1398
+		// only process if we're checking our mapped_cap
1399
+		if ($cap !== $this->meta_cap) {
1400
+			return $caps;
1401
+		}
1402
+
1403
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1404
+		if (($key = array_search($cap, $caps)) !== false) {
1405
+			unset($caps[ $key ]);
1406
+		}
1407
+
1408
+		// cast $user_id to int for later explicit comparisons
1409
+		$user_id = (int) $user_id;
1410
+
1411
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1412
+		// if no obj then let's just do cap
1413
+		if (! $obj instanceof EE_Message_Template_Group) {
1414
+			$caps[] = 'do_not_allow';
1415
+			return $caps;
1416
+		}
1417
+		$caps[] = $cap . 's';
1418
+		$is_global = $obj->is_global();
1419
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1420
+			if ($is_global) {
1421
+				$caps[] = $this->private_cap;
1422
+			}
1423
+		} else {
1424
+			if ($is_global) {
1425
+				$caps[] = $this->private_cap;
1426
+			} else {
1427
+				$caps[] = $this->others_cap;
1428
+			}
1429
+		}
1430
+		return $caps;
1431
+	}
1432 1432
 }
1433 1433
 
1434 1434
 
@@ -1445,40 +1445,40 @@  discard block
 block discarded – undo
1445 1445
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1446 1446
 {
1447 1447
 
1448
-    /**
1449
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1450
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1451
-     *
1452
-     * @since 4.5.0
1453
-     * @see   wp-includes/capabilities.php
1454
-     * @param array  $caps    actual users capabilities
1455
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1456
-     * @param int    $user_id The user id
1457
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1458
-     * @return array   actual users capabilities
1459
-     */
1460
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1461
-    {
1462
-        // only process if we're checking our mapped_cap
1463
-        if ($cap !== $this->meta_cap) {
1464
-            return $caps;
1465
-        }
1466
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1467
-        if (($key = array_search($cap, $caps)) !== false) {
1468
-            unset($caps[ $key ]);
1469
-        }
1470
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1471
-        // if no obj then let's just do cap
1472
-        if (! $obj instanceof EE_Base_Class) {
1473
-            $caps[] = 'do_not_allow';
1474
-            return $caps;
1475
-        }
1476
-        $caps[] = $cap . 's';
1477
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1478
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1479
-        if ($is_system) {
1480
-            $caps[] = $this->private_cap;
1481
-        }
1482
-        return $caps;
1483
-    }
1448
+	/**
1449
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1450
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1451
+	 *
1452
+	 * @since 4.5.0
1453
+	 * @see   wp-includes/capabilities.php
1454
+	 * @param array  $caps    actual users capabilities
1455
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1456
+	 * @param int    $user_id The user id
1457
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1458
+	 * @return array   actual users capabilities
1459
+	 */
1460
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1461
+	{
1462
+		// only process if we're checking our mapped_cap
1463
+		if ($cap !== $this->meta_cap) {
1464
+			return $caps;
1465
+		}
1466
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1467
+		if (($key = array_search($cap, $caps)) !== false) {
1468
+			unset($caps[ $key ]);
1469
+		}
1470
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1471
+		// if no obj then let's just do cap
1472
+		if (! $obj instanceof EE_Base_Class) {
1473
+			$caps[] = 'do_not_allow';
1474
+			return $caps;
1475
+		}
1476
+		$caps[] = $cap . 's';
1477
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1478
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1479
+		if ($is_system) {
1480
+			$caps[] = $this->private_cap;
1481
+		}
1482
+		return $caps;
1483
+	}
1484 1484
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     public static function instance()
81 81
     {
82 82
         // check if instantiated, and if not do so.
83
-        if (! self::$_instance instanceof EE_Capabilities) {
83
+        if ( ! self::$_instance instanceof EE_Capabilities) {
84 84
             self::$_instance = new self();
85 85
         }
86 86
         return self::$_instance;
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public function init_caps($reset = false)
112 112
     {
113
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
113
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
114 114
             return false;
115 115
         }
116 116
         $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $this->_get_default_meta_caps_array()
156 156
         );
157 157
         // add filter for map_meta_caps but only if models can query.
158
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
158
+        if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159 159
             add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160 160
         }
161 161
     }
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
         if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315 315
             // loop through our _meta_caps array
316 316
             foreach ($this->_meta_caps as $meta_map) {
317
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
317
+                if ( ! $meta_map instanceof EE_Meta_Capability_Map) {
318 318
                     continue;
319 319
                 }
320 320
                 // don't load models if there is no object ID in the args
321
-                if (! empty($args[0])) {
321
+                if ( ! empty($args[0])) {
322 322
                     $meta_map->ensure_is_model();
323 323
                 }
324 324
                 $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
     public function addCaps(array $capabilities_to_add)
655 655
     {
656 656
         // don't do anything if the capabilities map can not be initialized
657
-        if (! $this->setupCapabilitiesMap()) {
657
+        if ( ! $this->setupCapabilitiesMap()) {
658 658
             return false;
659 659
         }
660 660
         // and filter the array so others can get in on the fun during resets
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
     public function removeCaps($caps_map)
697 697
     {
698 698
         // don't do anything if the capabilities map can not be initialized
699
-        if (! $this->setupCapabilitiesMap()) {
699
+        if ( ! $this->setupCapabilitiesMap()) {
700 700
             return false;
701 701
         }
702 702
         $update_capabilities_map = false;
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
         $orig_role = $role;
757 757
         $role = $role instanceof WP_Role ? $role : get_role($role);
758 758
         // if the role isn't available then we create it.
759
-        if (! $role instanceof WP_Role) {
759
+        if ( ! $role instanceof WP_Role) {
760 760
             // if a plugin wants to create a specific role name then they should create the role before
761 761
             // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
762 762
             // - removes any `ee_` namespacing from the start of the slug.
@@ -767,12 +767,12 @@  discard block
 block discarded – undo
767 767
         }
768 768
         if ($role instanceof WP_Role) {
769 769
             // don't do anything if the capabilities map can not be initialized
770
-            if (! $this->setupCapabilitiesMap()) {
770
+            if ( ! $this->setupCapabilitiesMap()) {
771 771
                 return false;
772 772
             }
773
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
773
+            if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) {
774 774
                 $role->add_cap($cap, $grant);
775
-                $this->capabilities_map[ $role->name ][] = $cap;
775
+                $this->capabilities_map[$role->name][] = $cap;
776 776
                 $this->updateCapabilitiesMap($update_capabilities_map);
777 777
                 return true;
778 778
             }
@@ -796,14 +796,14 @@  discard block
 block discarded – undo
796 796
     public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
797 797
     {
798 798
         // don't do anything if the capabilities map can not be initialized
799
-        if (! $this->setupCapabilitiesMap()) {
799
+        if ( ! $this->setupCapabilitiesMap()) {
800 800
             return false;
801 801
         }
802 802
 
803 803
         $role = $role instanceof WP_Role ? $role : get_role($role);
804 804
         if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
805 805
             $role->remove_cap($cap);
806
-            unset($this->capabilities_map[ $role->name ][ $index ]);
806
+            unset($this->capabilities_map[$role->name][$index]);
807 807
             $this->updateCapabilitiesMap($update_capabilities_map);
808 808
             return true;
809 809
         }
@@ -820,8 +820,8 @@  discard block
 block discarded – undo
820 820
     private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
821 821
     {
822 822
         if (
823
-            isset($this->capabilities_map[ $role_name ])
824
-            && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
823
+            isset($this->capabilities_map[$role_name])
824
+            && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false
825 825
         ) {
826 826
             return $get_index ? $index : true;
827 827
         }
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
     public function current_user_can($cap, $context, $id = 0)
849 849
     {
850 850
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
851
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
851
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id);
852 852
         $filtered_cap = apply_filters(
853 853
             'FHEE__EE_Capabilities__current_user_can__cap',
854 854
             $filtered_cap,
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
     public function user_can($user, $cap, $context, $id = 0)
877 877
     {
878 878
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
879
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
879
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id);
880 880
         $filtered_cap = apply_filters(
881 881
             'FHEE__EE_Capabilities__user_can__cap',
882 882
             $filtered_cap,
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
             : current_user_can($blog_id, $cap);
916 916
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
917 917
         $user_can = apply_filters(
918
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
918
+            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context,
919 919
             $user_can,
920 920
             $blog_id,
921 921
             $cap,
@@ -944,14 +944,14 @@  discard block
 block discarded – undo
944 944
      */
945 945
     public function get_ee_capabilities($role = 'administrator')
946 946
     {
947
-        if (! $this->initialized) {
947
+        if ( ! $this->initialized) {
948 948
             $this->init_caps();
949 949
         }
950 950
         if (empty($role)) {
951 951
             return $this->capabilities_map;
952 952
         }
953
-        return isset($this->capabilities_map[ $role ])
954
-            ? $this->capabilities_map[ $role ]
953
+        return isset($this->capabilities_map[$role])
954
+            ? $this->capabilities_map[$role]
955 955
             : array();
956 956
     }
957 957
 
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                         'event_espresso'
983 983
                     ),
984 984
                     '$reset',
985
-                    __METHOD__ . '()',
985
+                    __METHOD__.'()',
986 986
                     'EE_Capabilities::init_caps()',
987 987
                     'true'
988 988
                 ),
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
                         'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1057 1057
                         'event_espresso'
1058 1058
                     ),
1059
-                    '<br>' . print_r($map_values, true)
1059
+                    '<br>'.print_r($map_values, true)
1060 1060
                 )
1061 1061
             );
1062 1062
         }
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
         // error proof if the name has EEM in it
1097 1097
         $this->_model_name = str_replace('EEM', '', $this->_model_name);
1098 1098
         $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1099
-        if (! $this->_model instanceof EEM_Base) {
1099
+        if ( ! $this->_model instanceof EEM_Base) {
1100 1100
             throw new EE_Error(
1101 1101
                 sprintf(
1102 1102
                     esc_html__(
@@ -1182,7 +1182,7 @@  discard block
 block discarded – undo
1182 1182
 
1183 1183
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1184 1184
         if (($key = array_search($cap, $caps)) !== false) {
1185
-            unset($caps[ $key ]);
1185
+            unset($caps[$key]);
1186 1186
         }
1187 1187
 
1188 1188
         // cast $user_id to int for later explicit comparisons
@@ -1191,11 +1191,11 @@  discard block
 block discarded – undo
1191 1191
         /** @var EE_Base_Class $obj */
1192 1192
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1193 1193
         // if no obj then let's just do cap
1194
-        if (! $obj instanceof EE_Base_Class) {
1194
+        if ( ! $obj instanceof EE_Base_Class) {
1195 1195
             $caps[] = 'do_not_allow';
1196 1196
             return $caps;
1197 1197
         }
1198
-        $caps[] = $cap . 's';
1198
+        $caps[] = $cap.'s';
1199 1199
         if ($obj instanceof EE_CPT_Base) {
1200 1200
             // if the item author is set and the user is the author...
1201 1201
             if ($obj->wp_user() && $user_id === $obj->wp_user()) {
@@ -1205,12 +1205,12 @@  discard block
 block discarded – undo
1205 1205
                 }
1206 1206
             } else {
1207 1207
                 // the user is trying to edit someone else's obj
1208
-                if (! empty($this->others_cap)) {
1208
+                if ( ! empty($this->others_cap)) {
1209 1209
                     $caps[] = $this->others_cap;
1210 1210
                 }
1211
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1211
+                if ( ! empty($this->published_cap) && $obj->status() === 'publish') {
1212 1212
                     $caps[] = $this->published_cap;
1213
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1213
+                } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') {
1214 1214
                     $caps[] = $this->private_cap;
1215 1215
                 }
1216 1216
             }
@@ -1226,8 +1226,8 @@  discard block
 block discarded – undo
1226 1226
                     EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1227 1227
                 }
1228 1228
             }
1229
-            if (! $has_cap) {
1230
-                if (! empty($this->others_cap)) {
1229
+            if ( ! $has_cap) {
1230
+                if ( ! empty($this->others_cap)) {
1231 1231
                     $caps[] = $this->others_cap;
1232 1232
                 }
1233 1233
             }
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
 
1307 1307
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1308 1308
         if (($key = array_search($cap, $caps)) !== false) {
1309
-            unset($caps[ $key ]);
1309
+            unset($caps[$key]);
1310 1310
         }
1311 1311
 
1312 1312
         // cast $user_id to int for later explicit comparisons
@@ -1314,12 +1314,12 @@  discard block
 block discarded – undo
1314 1314
 
1315 1315
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1316 1316
         // if no obj then let's just do cap
1317
-        if (! $obj instanceof EE_Base_Class) {
1317
+        if ( ! $obj instanceof EE_Base_Class) {
1318 1318
             $caps[] = 'do_not_allow';
1319 1319
             return $caps;
1320 1320
         }
1321 1321
 
1322
-        $caps[] = $cap . 's';
1322
+        $caps[] = $cap.'s';
1323 1323
         if ($obj instanceof EE_CPT_Base) {
1324 1324
             $status_obj = get_post_status_object($obj->status());
1325 1325
             if ($status_obj->public) {
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
             }
1328 1328
             // if the item author is set and the user is not the author...
1329 1329
             if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1330
-                if (! empty($this->others_cap)) {
1330
+                if ( ! empty($this->others_cap)) {
1331 1331
                     $caps[] = $this->others_cap;
1332 1332
                 }
1333 1333
             }
@@ -1352,11 +1352,11 @@  discard block
 block discarded – undo
1352 1352
                     EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1353 1353
                 }
1354 1354
             }
1355
-            if (! $has_cap) {
1356
-                if (! empty($this->private_cap)) {
1355
+            if ( ! $has_cap) {
1356
+                if ( ! empty($this->private_cap)) {
1357 1357
                     $caps[] = $this->private_cap;
1358 1358
                 }
1359
-                if (! empty($this->others_cap)) {
1359
+                if ( ! empty($this->others_cap)) {
1360 1360
                     $caps[] = $this->others_cap;
1361 1361
                 }
1362 1362
             }
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
 
1403 1403
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1404 1404
         if (($key = array_search($cap, $caps)) !== false) {
1405
-            unset($caps[ $key ]);
1405
+            unset($caps[$key]);
1406 1406
         }
1407 1407
 
1408 1408
         // cast $user_id to int for later explicit comparisons
@@ -1410,11 +1410,11 @@  discard block
 block discarded – undo
1410 1410
 
1411 1411
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1412 1412
         // if no obj then let's just do cap
1413
-        if (! $obj instanceof EE_Message_Template_Group) {
1413
+        if ( ! $obj instanceof EE_Message_Template_Group) {
1414 1414
             $caps[] = 'do_not_allow';
1415 1415
             return $caps;
1416 1416
         }
1417
-        $caps[] = $cap . 's';
1417
+        $caps[] = $cap.'s';
1418 1418
         $is_global = $obj->is_global();
1419 1419
         if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1420 1420
             if ($is_global) {
@@ -1465,15 +1465,15 @@  discard block
 block discarded – undo
1465 1465
         }
1466 1466
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1467 1467
         if (($key = array_search($cap, $caps)) !== false) {
1468
-            unset($caps[ $key ]);
1468
+            unset($caps[$key]);
1469 1469
         }
1470 1470
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1471 1471
         // if no obj then let's just do cap
1472
-        if (! $obj instanceof EE_Base_Class) {
1472
+        if ( ! $obj instanceof EE_Base_Class) {
1473 1473
             $caps[] = 'do_not_allow';
1474 1474
             return $caps;
1475 1475
         }
1476
-        $caps[] = $cap . 's';
1476
+        $caps[] = $cap.'s';
1477 1477
         $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1478 1478
         $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1479 1479
         if ($is_system) {
Please login to merge, or discard this patch.
espresso_event_attendees/EES_Espresso_Event_Attendees.shortcode.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,56 +13,56 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * run - initial module setup
18
-     *
19
-     * @access    public
20
-     * @param       WP $WP
21
-     * @return    void
22
-     */
23
-    public function run(WP $WP)
24
-    {
25
-    }
16
+	/**
17
+	 * run - initial module setup
18
+	 *
19
+	 * @access    public
20
+	 * @param       WP $WP
21
+	 * @return    void
22
+	 */
23
+	public function run(WP $WP)
24
+	{
25
+	}
26 26
 
27 27
 
28
-    /**
29
-     *  set_hooks - for hooking into EE Core, modules, etc
30
-     *
31
-     *  @access     public
32
-     *  @return     void
33
-     */
34
-    public static function set_hooks()
35
-    {
36
-    }
28
+	/**
29
+	 *  set_hooks - for hooking into EE Core, modules, etc
30
+	 *
31
+	 *  @access     public
32
+	 *  @return     void
33
+	 */
34
+	public static function set_hooks()
35
+	{
36
+	}
37 37
 
38
-    /**
39
-     *  set_hooks_admin - for hooking into EE Admin Core, modules, etc
40
-     *
41
-     *  @access     public
42
-     *  @return     void
43
-     */
44
-    public static function set_hooks_admin()
45
-    {
46
-    }
38
+	/**
39
+	 *  set_hooks_admin - for hooking into EE Admin Core, modules, etc
40
+	 *
41
+	 *  @access     public
42
+	 *  @return     void
43
+	 */
44
+	public static function set_hooks_admin()
45
+	{
46
+	}
47 47
 
48 48
 
49 49
 
50
-    /**
51
-     * @deprecated 4.9.27
52
-     * @param array $attributes
53
-     * @return string
54
-     * @throws \EE_Error
55
-     */
56
-    public function process_shortcode($attributes = array())
57
-    {
58
-        \EE_Error::doing_it_wrong(
59
-            __METHOD__,
60
-            esc_html__(
61
-                'Usage is deprecated. Please use \EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendeesShortcode instead.',
62
-                'event_espresso'
63
-            ),
64
-            '4.9.27'
65
-        );
66
-        return '';
67
-    }
50
+	/**
51
+	 * @deprecated 4.9.27
52
+	 * @param array $attributes
53
+	 * @return string
54
+	 * @throws \EE_Error
55
+	 */
56
+	public function process_shortcode($attributes = array())
57
+	{
58
+		\EE_Error::doing_it_wrong(
59
+			__METHOD__,
60
+			esc_html__(
61
+				'Usage is deprecated. Please use \EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendeesShortcode instead.',
62
+				'event_espresso'
63
+			),
64
+			'4.9.27'
65
+		);
66
+		return '';
67
+	}
68 68
 }
Please login to merge, or discard this patch.
shortcodes/espresso_txn_page/EES_Espresso_Txn_Page.shortcode.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @deprecated 4.9.27
17
-     * @return  void
18
-     */
19
-    public static function set_hooks()
20
-    {
21
-    }
15
+	/**
16
+	 * @deprecated 4.9.27
17
+	 * @return  void
18
+	 */
19
+	public static function set_hooks()
20
+	{
21
+	}
22 22
 
23
-    /**
24
-     * @deprecated 4.9.27
25
-     * @return  void
26
-     */
27
-    public static function set_hooks_admin()
28
-    {
29
-    }
23
+	/**
24
+	 * @deprecated 4.9.27
25
+	 * @return  void
26
+	 */
27
+	public static function set_hooks_admin()
28
+	{
29
+	}
30 30
 
31 31
 
32 32
 
33
-    /**
34
-     * @deprecated 4.9.27
35
-     * @return  void
36
-     */
37
-    public static function set_definitions()
38
-    {
39
-    }
33
+	/**
34
+	 * @deprecated 4.9.27
35
+	 * @return  void
36
+	 */
37
+	public static function set_definitions()
38
+	{
39
+	}
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * @deprecated 4.9.27
45
-     * @param  WP $WP
46
-     * @return void
47
-     * @throws \Exception
48
-     * @throws \EE_Error
49
-     */
50
-    public function run(WP $WP)
51
-    {
52
-    }
43
+	/**
44
+	 * @deprecated 4.9.27
45
+	 * @param  WP $WP
46
+	 * @return void
47
+	 * @throws \Exception
48
+	 * @throws \EE_Error
49
+	 */
50
+	public function run(WP $WP)
51
+	{
52
+	}
53 53
 
54 54
 
55 55
 
56 56
 
57
-    /**
58
-     * @deprecated 4.9.27
59
-     * @param array $attributes
60
-     * @return string
61
-     */
62
-    public function process_shortcode($attributes = array())
63
-    {
64
-        return esc_html__('This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.', 'event_espresso');
65
-    }
57
+	/**
58
+	 * @deprecated 4.9.27
59
+	 * @param array $attributes
60
+	 * @return string
61
+	 */
62
+	public function process_shortcode($attributes = array())
63
+	{
64
+		return esc_html__('This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.', 'event_espresso');
65
+	}
66 66
 }
Please login to merge, or discard this patch.
espresso_ticket_selector/EES_Espresso_Ticket_Selector.shortcode.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -11,50 +11,50 @@
 block discarded – undo
11 11
 class EES_Espresso_Ticket_Selector extends EES_Shortcode
12 12
 {
13 13
 
14
-    /**
15
-     * @deprecated 4.9.27
16
-     * @return  void
17
-     */
18
-    public static function set_hooks()
19
-    {
20
-    }
21
-
22
-
23
-
24
-    /**
25
-     * @deprecated 4.9.27
26
-     * @return  void
27
-     */
28
-    public static function set_hooks_admin()
29
-    {
30
-    }
31
-
32
-
33
-
34
-    /**
35
-     * @deprecated 4.9.27
36
-     * @param \WP $WP
37
-     */
38
-    public function run(WP $WP)
39
-    {
40
-    }
41
-
42
-
43
-    /**
44
-     * @deprecated 4.9.27
45
-     * @param       array   $attributes
46
-     * @return  string
47
-     */
48
-    public function process_shortcode($attributes = array())
49
-    {
50
-        \EE_Error::doing_it_wrong(
51
-            __METHOD__,
52
-            esc_html__(
53
-                'Usage is deprecated. Please use \EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector instead.',
54
-                'event_espresso'
55
-            ),
56
-            '4.9.27'
57
-        );
58
-        return '';
59
-    }
14
+	/**
15
+	 * @deprecated 4.9.27
16
+	 * @return  void
17
+	 */
18
+	public static function set_hooks()
19
+	{
20
+	}
21
+
22
+
23
+
24
+	/**
25
+	 * @deprecated 4.9.27
26
+	 * @return  void
27
+	 */
28
+	public static function set_hooks_admin()
29
+	{
30
+	}
31
+
32
+
33
+
34
+	/**
35
+	 * @deprecated 4.9.27
36
+	 * @param \WP $WP
37
+	 */
38
+	public function run(WP $WP)
39
+	{
40
+	}
41
+
42
+
43
+	/**
44
+	 * @deprecated 4.9.27
45
+	 * @param       array   $attributes
46
+	 * @return  string
47
+	 */
48
+	public function process_shortcode($attributes = array())
49
+	{
50
+		\EE_Error::doing_it_wrong(
51
+			__METHOD__,
52
+			esc_html__(
53
+				'Usage is deprecated. Please use \EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector instead.',
54
+				'event_espresso'
55
+			),
56
+			'4.9.27'
57
+		);
58
+		return '';
59
+	}
60 60
 }
Please login to merge, or discard this patch.