@@ -16,808 +16,808 @@ discard block |
||
16 | 16 | final class EE_Capabilities extends EE_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * the name of the wp option used to store caps previously initialized |
|
21 | - */ |
|
22 | - const option_name = 'ee_caps_initialized'; |
|
23 | - |
|
24 | - /** |
|
25 | - * instance of EE_Capabilities object |
|
26 | - * |
|
27 | - * @var EE_Capabilities |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * This is a map of caps that correspond to a default WP_Role. |
|
33 | - * Array is indexed by Role and values are ee capabilities. |
|
34 | - * |
|
35 | - * @since 4.5.0 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - private $_caps_map = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for |
|
42 | - * a user depending on context. |
|
43 | - * |
|
44 | - * @var EE_Meta_Capability_Map[] |
|
45 | - */ |
|
46 | - private $_meta_caps = array(); |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * singleton method used to instantiate class object |
|
51 | - * |
|
52 | - * @since 4.5.0 |
|
53 | - * @return EE_Capabilities |
|
54 | - */ |
|
55 | - public static function instance() |
|
56 | - { |
|
57 | - //check if instantiated, and if not do so. |
|
58 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
59 | - self::$_instance = new self(); |
|
60 | - } |
|
61 | - return self::$_instance; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * private constructor |
|
67 | - * |
|
68 | - * @since 4.5.0 |
|
69 | - */ |
|
70 | - private function __construct() |
|
71 | - { |
|
72 | - if (is_admin()) { |
|
73 | - add_filter( |
|
74 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
75 | - array($this, 'register_additional_capabilities'), |
|
76 | - 10 |
|
77 | - ); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
84 | - * |
|
85 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
86 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
87 | - * ensures that they are up to date. |
|
88 | - * @since 4.5.0 |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function init_caps($reset = false) |
|
92 | - { |
|
93 | - /** |
|
94 | - * Note, this means that caps can only initialized on the default roles when: |
|
95 | - * - models are queryable |
|
96 | - * - All addons have been registered (which happens at plugins_loaded priority 1) |
|
97 | - * In practice, currently this method is usually called around `init`. |
|
98 | - */ |
|
99 | - if ( |
|
100 | - did_action('AHEE__EE_System__load_espresso_addons__complete') |
|
101 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
102 | - ) { |
|
103 | - $this->_caps_map = $this->_init_caps_map(); |
|
104 | - $this->init_role_caps($reset); |
|
105 | - $this->_set_meta_caps(); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * This sets the meta caps property. |
|
112 | - * |
|
113 | - * @since 4.5.0 |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - private function _set_meta_caps() |
|
117 | - { |
|
118 | - //make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
119 | - $this->_meta_caps = $this->_get_default_meta_caps_array(); |
|
120 | - $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps); |
|
121 | - //add filter for map_meta_caps but only if models can query. |
|
122 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
123 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * This builds and returns the default meta_caps array only once. |
|
130 | - * |
|
131 | - * @since 4.8.28.rc.012 |
|
132 | - * @return array |
|
133 | - * @throws \EE_Error |
|
134 | - */ |
|
135 | - private function _get_default_meta_caps_array() |
|
136 | - { |
|
137 | - static $default_meta_caps = array(); |
|
138 | - if (empty($default_meta_caps)) { |
|
139 | - $default_meta_caps = array( |
|
140 | - //edits |
|
141 | - new EE_Meta_Capability_Map_Edit( |
|
142 | - 'ee_edit_event', |
|
143 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
144 | - ), |
|
145 | - new EE_Meta_Capability_Map_Edit( |
|
146 | - 'ee_edit_venue', |
|
147 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
148 | - ), |
|
149 | - new EE_Meta_Capability_Map_Edit( |
|
150 | - 'ee_edit_registration', |
|
151 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
152 | - ), |
|
153 | - new EE_Meta_Capability_Map_Edit( |
|
154 | - 'ee_edit_checkin', |
|
155 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
156 | - ), |
|
157 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
158 | - 'ee_edit_message', |
|
159 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
160 | - ), |
|
161 | - new EE_Meta_Capability_Map_Edit( |
|
162 | - 'ee_edit_default_ticket', |
|
163 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
164 | - ), |
|
165 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
166 | - 'ee_edit_question', |
|
167 | - array('Question', '', '', 'ee_edit_system_questions') |
|
168 | - ), |
|
169 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
170 | - 'ee_edit_question_group', |
|
171 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
172 | - ), |
|
173 | - new EE_Meta_Capability_Map_Edit( |
|
174 | - 'ee_edit_payment_method', |
|
175 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
176 | - ), |
|
177 | - //reads |
|
178 | - new EE_Meta_Capability_Map_Read( |
|
179 | - 'ee_read_event', |
|
180 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
181 | - ), |
|
182 | - new EE_Meta_Capability_Map_Read( |
|
183 | - 'ee_read_venue', |
|
184 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
185 | - ), |
|
186 | - new EE_Meta_Capability_Map_Read( |
|
187 | - 'ee_read_registration', |
|
188 | - array('Registration', '', '', 'ee_edit_others_registrations') |
|
189 | - ), |
|
190 | - new EE_Meta_Capability_Map_Read( |
|
191 | - 'ee_read_checkin', |
|
192 | - array('Registration', '', '', 'ee_read_others_checkins') |
|
193 | - ), |
|
194 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
195 | - 'ee_read_message', |
|
196 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
197 | - ), |
|
198 | - new EE_Meta_Capability_Map_Read( |
|
199 | - 'ee_read_default_ticket', |
|
200 | - array('Ticket', '', '', 'ee_read_others_default_tickets') |
|
201 | - ), |
|
202 | - new EE_Meta_Capability_Map_Read( |
|
203 | - 'ee_read_payment_method', |
|
204 | - array('Payment_Method', '', '', 'ee_read_others_payment_methods') |
|
205 | - ), |
|
206 | - //deletes |
|
207 | - new EE_Meta_Capability_Map_Delete( |
|
208 | - 'ee_delete_event', |
|
209 | - array( |
|
210 | - 'Event', |
|
211 | - 'ee_delete_published_events', |
|
212 | - 'ee_delete_others_events', |
|
213 | - 'ee_delete_private_events', |
|
214 | - ) |
|
215 | - ), |
|
216 | - new EE_Meta_Capability_Map_Delete( |
|
217 | - 'ee_delete_venue', |
|
218 | - array( |
|
219 | - 'Venue', |
|
220 | - 'ee_delete_published_venues', |
|
221 | - 'ee_delete_others_venues', |
|
222 | - 'ee_delete_private_venues', |
|
223 | - ) |
|
224 | - ), |
|
225 | - new EE_Meta_Capability_Map_Delete( |
|
226 | - 'ee_delete_registration', |
|
227 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
228 | - ), |
|
229 | - new EE_Meta_Capability_Map_Delete( |
|
230 | - 'ee_delete_checkin', |
|
231 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
232 | - ), |
|
233 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
234 | - 'ee_delete_message', |
|
235 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
236 | - ), |
|
237 | - new EE_Meta_Capability_Map_Delete( |
|
238 | - 'ee_delete_default_ticket', |
|
239 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
240 | - ), |
|
241 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
242 | - 'ee_delete_question', |
|
243 | - array('Question', '', '', 'delete_system_questions') |
|
244 | - ), |
|
245 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
246 | - 'ee_delete_question_group', |
|
247 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
248 | - ), |
|
249 | - new EE_Meta_Capability_Map_Delete( |
|
250 | - 'ee_delete_payment_method', |
|
251 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
252 | - ), |
|
253 | - ); |
|
254 | - } |
|
255 | - return $default_meta_caps; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
261 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
262 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
263 | - * |
|
264 | - * @since 4.5.0 |
|
265 | - * @see wp-includes/capabilities.php |
|
266 | - * @param array $caps actual users capabilities |
|
267 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
268 | - * @param int $user_id The user id |
|
269 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
270 | - * @return array actual users capabilities |
|
271 | - * @throws EE_Error |
|
272 | - */ |
|
273 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
274 | - { |
|
275 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
276 | - //loop through our _meta_caps array |
|
277 | - foreach ($this->_meta_caps as $meta_map) { |
|
278 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
279 | - continue; |
|
280 | - } |
|
281 | - if(!empty($args[0])){ |
|
282 | - $meta_map->ensure_is_model(); |
|
283 | - } |
|
284 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
285 | - } |
|
286 | - } |
|
287 | - return $caps; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
293 | - * |
|
294 | - * @since 4.5.0 |
|
295 | - * @return array |
|
296 | - */ |
|
297 | - private function _init_caps_map() |
|
298 | - { |
|
299 | - $caps = array( |
|
300 | - 'administrator' => array( |
|
301 | - //basic access |
|
302 | - 'ee_read_ee', |
|
303 | - //gateways |
|
304 | - /** |
|
305 | - * note that with payment method capabilities, although we've implemented |
|
306 | - * capability mapping which will be used for accessing payment methods owned by |
|
307 | - * other users. This is not fully implemented yet in the payment method ui. |
|
308 | - * Currently only the "plural" caps are in active use. |
|
309 | - * (Specific payment method caps are in use as well). |
|
310 | - **/ |
|
311 | - 'ee_manage_gateways', |
|
312 | - 'ee_read_payment_method', |
|
313 | - 'ee_read_payment_methods', |
|
314 | - 'ee_read_others_payment_methods', |
|
315 | - 'ee_edit_payment_method', |
|
316 | - 'ee_edit_payment_methods', |
|
317 | - 'ee_edit_others_payment_methods', |
|
318 | - 'ee_delete_payment_method', |
|
319 | - 'ee_delete_payment_methods', |
|
320 | - //events |
|
321 | - 'ee_publish_events', |
|
322 | - 'ee_read_private_events', |
|
323 | - 'ee_read_others_events', |
|
324 | - 'ee_read_event', |
|
325 | - 'ee_read_events', |
|
326 | - 'ee_edit_event', |
|
327 | - 'ee_edit_events', |
|
328 | - 'ee_edit_published_events', |
|
329 | - 'ee_edit_others_events', |
|
330 | - 'ee_edit_private_events', |
|
331 | - 'ee_delete_published_events', |
|
332 | - 'ee_delete_private_events', |
|
333 | - 'ee_delete_event', |
|
334 | - 'ee_delete_events', |
|
335 | - 'ee_delete_others_events', |
|
336 | - //event categories |
|
337 | - 'ee_manage_event_categories', |
|
338 | - 'ee_edit_event_category', |
|
339 | - 'ee_delete_event_category', |
|
340 | - 'ee_assign_event_category', |
|
341 | - //venues |
|
342 | - 'ee_publish_venues', |
|
343 | - 'ee_read_venue', |
|
344 | - 'ee_read_venues', |
|
345 | - 'ee_read_others_venues', |
|
346 | - 'ee_read_private_venues', |
|
347 | - 'ee_edit_venue', |
|
348 | - 'ee_edit_venues', |
|
349 | - 'ee_edit_others_venues', |
|
350 | - 'ee_edit_published_venues', |
|
351 | - 'ee_edit_private_venues', |
|
352 | - 'ee_delete_venue', |
|
353 | - 'ee_delete_venues', |
|
354 | - 'ee_delete_others_venues', |
|
355 | - 'ee_delete_private_venues', |
|
356 | - 'ee_delete_published_venues', |
|
357 | - //venue categories |
|
358 | - 'ee_manage_venue_categories', |
|
359 | - 'ee_edit_venue_category', |
|
360 | - 'ee_delete_venue_category', |
|
361 | - 'ee_assign_venue_category', |
|
362 | - //contacts |
|
363 | - 'ee_read_contact', |
|
364 | - 'ee_read_contacts', |
|
365 | - 'ee_edit_contact', |
|
366 | - 'ee_edit_contacts', |
|
367 | - 'ee_delete_contact', |
|
368 | - 'ee_delete_contacts', |
|
369 | - //registrations |
|
370 | - 'ee_read_registration', |
|
371 | - 'ee_read_registrations', |
|
372 | - 'ee_read_others_registrations', |
|
373 | - 'ee_edit_registration', |
|
374 | - 'ee_edit_registrations', |
|
375 | - 'ee_edit_others_registrations', |
|
376 | - 'ee_delete_registration', |
|
377 | - 'ee_delete_registrations', |
|
378 | - //checkins |
|
379 | - 'ee_read_checkin', |
|
380 | - 'ee_read_others_checkins', |
|
381 | - 'ee_read_checkins', |
|
382 | - 'ee_edit_checkin', |
|
383 | - 'ee_edit_checkins', |
|
384 | - 'ee_edit_others_checkins', |
|
385 | - 'ee_delete_checkin', |
|
386 | - 'ee_delete_checkins', |
|
387 | - 'ee_delete_others_checkins', |
|
388 | - //transactions && payments |
|
389 | - 'ee_read_transaction', |
|
390 | - 'ee_read_transactions', |
|
391 | - 'ee_edit_payments', |
|
392 | - 'ee_delete_payments', |
|
393 | - //messages |
|
394 | - 'ee_read_message', |
|
395 | - 'ee_read_messages', |
|
396 | - 'ee_read_others_messages', |
|
397 | - 'ee_read_global_messages', |
|
398 | - 'ee_edit_global_messages', |
|
399 | - 'ee_edit_message', |
|
400 | - 'ee_edit_messages', |
|
401 | - 'ee_edit_others_messages', |
|
402 | - 'ee_delete_message', |
|
403 | - 'ee_delete_messages', |
|
404 | - 'ee_delete_others_messages', |
|
405 | - 'ee_delete_global_messages', |
|
406 | - 'ee_send_message', |
|
407 | - //tickets |
|
408 | - 'ee_read_default_ticket', |
|
409 | - 'ee_read_default_tickets', |
|
410 | - 'ee_read_others_default_tickets', |
|
411 | - 'ee_edit_default_ticket', |
|
412 | - 'ee_edit_default_tickets', |
|
413 | - 'ee_edit_others_default_tickets', |
|
414 | - 'ee_delete_default_ticket', |
|
415 | - 'ee_delete_default_tickets', |
|
416 | - 'ee_delete_others_default_tickets', |
|
417 | - //prices |
|
418 | - 'ee_edit_default_price', |
|
419 | - 'ee_edit_default_prices', |
|
420 | - 'ee_delete_default_price', |
|
421 | - 'ee_delete_default_prices', |
|
422 | - 'ee_edit_default_price_type', |
|
423 | - 'ee_edit_default_price_types', |
|
424 | - 'ee_delete_default_price_type', |
|
425 | - 'ee_delete_default_price_types', |
|
426 | - 'ee_read_default_prices', |
|
427 | - 'ee_read_default_price_types', |
|
428 | - //registration form |
|
429 | - 'ee_edit_question', |
|
430 | - 'ee_edit_questions', |
|
431 | - 'ee_edit_system_questions', |
|
432 | - 'ee_read_questions', |
|
433 | - 'ee_delete_question', |
|
434 | - 'ee_delete_questions', |
|
435 | - 'ee_edit_question_group', |
|
436 | - 'ee_edit_question_groups', |
|
437 | - 'ee_read_question_groups', |
|
438 | - 'ee_edit_system_question_groups', |
|
439 | - 'ee_delete_question_group', |
|
440 | - 'ee_delete_question_groups', |
|
441 | - //event_type taxonomy |
|
442 | - 'ee_assign_event_type', |
|
443 | - 'ee_manage_event_types', |
|
444 | - 'ee_edit_event_type', |
|
445 | - 'ee_delete_event_type', |
|
446 | - ), |
|
447 | - 'ee_events_administrator' => array( |
|
448 | - //core wp caps |
|
449 | - 'read', |
|
450 | - 'read_private_pages', |
|
451 | - 'read_private_posts', |
|
452 | - 'edit_users', |
|
453 | - 'edit_posts', |
|
454 | - 'edit_pages', |
|
455 | - 'edit_published_posts', |
|
456 | - 'edit_published_pages', |
|
457 | - 'edit_private_pages', |
|
458 | - 'edit_private_posts', |
|
459 | - 'edit_others_posts', |
|
460 | - 'edit_others_pages', |
|
461 | - 'publish_posts', |
|
462 | - 'publish_pages', |
|
463 | - 'delete_posts', |
|
464 | - 'delete_pages', |
|
465 | - 'delete_private_pages', |
|
466 | - 'delete_private_posts', |
|
467 | - 'delete_published_pages', |
|
468 | - 'delete_published_posts', |
|
469 | - 'delete_others_posts', |
|
470 | - 'delete_others_pages', |
|
471 | - 'manage_categories', |
|
472 | - 'manage_links', |
|
473 | - 'moderate_comments', |
|
474 | - 'unfiltered_html', |
|
475 | - 'upload_files', |
|
476 | - 'export', |
|
477 | - 'import', |
|
478 | - 'list_users', |
|
479 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
480 | - //basic ee access |
|
481 | - 'ee_read_ee', |
|
482 | - //events |
|
483 | - 'ee_publish_events', |
|
484 | - 'ee_read_private_events', |
|
485 | - 'ee_read_others_events', |
|
486 | - 'ee_read_event', |
|
487 | - 'ee_read_events', |
|
488 | - 'ee_edit_event', |
|
489 | - 'ee_edit_events', |
|
490 | - 'ee_edit_published_events', |
|
491 | - 'ee_edit_others_events', |
|
492 | - 'ee_edit_private_events', |
|
493 | - 'ee_delete_published_events', |
|
494 | - 'ee_delete_private_events', |
|
495 | - 'ee_delete_event', |
|
496 | - 'ee_delete_events', |
|
497 | - 'ee_delete_others_events', |
|
498 | - //event categories |
|
499 | - 'ee_manage_event_categories', |
|
500 | - 'ee_edit_event_category', |
|
501 | - 'ee_delete_event_category', |
|
502 | - 'ee_assign_event_category', |
|
503 | - //venues |
|
504 | - 'ee_publish_venues', |
|
505 | - 'ee_read_venue', |
|
506 | - 'ee_read_venues', |
|
507 | - 'ee_read_others_venues', |
|
508 | - 'ee_read_private_venues', |
|
509 | - 'ee_edit_venue', |
|
510 | - 'ee_edit_venues', |
|
511 | - 'ee_edit_others_venues', |
|
512 | - 'ee_edit_published_venues', |
|
513 | - 'ee_edit_private_venues', |
|
514 | - 'ee_delete_venue', |
|
515 | - 'ee_delete_venues', |
|
516 | - 'ee_delete_others_venues', |
|
517 | - 'ee_delete_private_venues', |
|
518 | - 'ee_delete_published_venues', |
|
519 | - //venue categories |
|
520 | - 'ee_manage_venue_categories', |
|
521 | - 'ee_edit_venue_category', |
|
522 | - 'ee_delete_venue_category', |
|
523 | - 'ee_assign_venue_category', |
|
524 | - //contacts |
|
525 | - 'ee_read_contact', |
|
526 | - 'ee_read_contacts', |
|
527 | - 'ee_edit_contact', |
|
528 | - 'ee_edit_contacts', |
|
529 | - 'ee_delete_contact', |
|
530 | - 'ee_delete_contacts', |
|
531 | - //registrations |
|
532 | - 'ee_read_registration', |
|
533 | - 'ee_read_registrations', |
|
534 | - 'ee_read_others_registrations', |
|
535 | - 'ee_edit_registration', |
|
536 | - 'ee_edit_registrations', |
|
537 | - 'ee_edit_others_registrations', |
|
538 | - 'ee_delete_registration', |
|
539 | - 'ee_delete_registrations', |
|
540 | - //checkins |
|
541 | - 'ee_read_checkin', |
|
542 | - 'ee_read_others_checkins', |
|
543 | - 'ee_read_checkins', |
|
544 | - 'ee_edit_checkin', |
|
545 | - 'ee_edit_checkins', |
|
546 | - 'ee_edit_others_checkins', |
|
547 | - 'ee_delete_checkin', |
|
548 | - 'ee_delete_checkins', |
|
549 | - 'ee_delete_others_checkins', |
|
550 | - //transactions && payments |
|
551 | - 'ee_read_transaction', |
|
552 | - 'ee_read_transactions', |
|
553 | - 'ee_edit_payments', |
|
554 | - 'ee_delete_payments', |
|
555 | - //messages |
|
556 | - 'ee_read_message', |
|
557 | - 'ee_read_messages', |
|
558 | - 'ee_read_others_messages', |
|
559 | - 'ee_read_global_messages', |
|
560 | - 'ee_edit_global_messages', |
|
561 | - 'ee_edit_message', |
|
562 | - 'ee_edit_messages', |
|
563 | - 'ee_edit_others_messages', |
|
564 | - 'ee_delete_message', |
|
565 | - 'ee_delete_messages', |
|
566 | - 'ee_delete_others_messages', |
|
567 | - 'ee_delete_global_messages', |
|
568 | - 'ee_send_message', |
|
569 | - //tickets |
|
570 | - 'ee_read_default_ticket', |
|
571 | - 'ee_read_default_tickets', |
|
572 | - 'ee_read_others_default_tickets', |
|
573 | - 'ee_edit_default_ticket', |
|
574 | - 'ee_edit_default_tickets', |
|
575 | - 'ee_edit_others_default_tickets', |
|
576 | - 'ee_delete_default_ticket', |
|
577 | - 'ee_delete_default_tickets', |
|
578 | - 'ee_delete_others_default_tickets', |
|
579 | - //prices |
|
580 | - 'ee_edit_default_price', |
|
581 | - 'ee_edit_default_prices', |
|
582 | - 'ee_delete_default_price', |
|
583 | - 'ee_delete_default_prices', |
|
584 | - 'ee_edit_default_price_type', |
|
585 | - 'ee_edit_default_price_types', |
|
586 | - 'ee_delete_default_price_type', |
|
587 | - 'ee_delete_default_price_types', |
|
588 | - 'ee_read_default_prices', |
|
589 | - 'ee_read_default_price_types', |
|
590 | - //registration form |
|
591 | - 'ee_edit_question', |
|
592 | - 'ee_edit_questions', |
|
593 | - 'ee_edit_system_questions', |
|
594 | - 'ee_read_questions', |
|
595 | - 'ee_delete_question', |
|
596 | - 'ee_delete_questions', |
|
597 | - 'ee_edit_question_group', |
|
598 | - 'ee_edit_question_groups', |
|
599 | - 'ee_read_question_groups', |
|
600 | - 'ee_edit_system_question_groups', |
|
601 | - 'ee_delete_question_group', |
|
602 | - 'ee_delete_question_groups', |
|
603 | - //event_type taxonomy |
|
604 | - 'ee_assign_event_type', |
|
605 | - 'ee_manage_event_types', |
|
606 | - 'ee_edit_event_type', |
|
607 | - 'ee_delete_event_type', |
|
608 | - ), |
|
609 | - ); |
|
610 | - $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps); |
|
611 | - return $caps; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Callback for FHEE__EE_Capabilities__init_caps_map__caps that is used for registering additional core |
|
617 | - * capabilities that get added. |
|
618 | - * This is typically done for more dynamic cap additions such as what is registered via the |
|
619 | - * `EE_Payment_Method_Manager` |
|
620 | - * |
|
621 | - * @param array $caps The existing $role=>$capability array. |
|
622 | - * @return array. |
|
623 | - */ |
|
624 | - public function register_additional_capabilities($caps) |
|
625 | - { |
|
626 | - //take care of dynamic capabilities for payment methods |
|
627 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
628 | - $caps = EE_Payment_Method_Manager::instance()->add_payment_method_caps($caps); |
|
629 | - return $caps; |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * This adds all the default caps to roles as registered in the _caps_map property. |
|
635 | - * |
|
636 | - * @since 4.5.0 |
|
637 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
638 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles |
|
639 | - * and ensures that they are up to date. |
|
640 | - * @param array $custom_map Optional. Can be used to send a custom map of roles and capabilities for setting them |
|
641 | - * up. Note that this should ONLY be called on activation hook or some other one-time |
|
642 | - * task otherwise the caps will be added on every request. |
|
643 | - * @return void |
|
644 | - */ |
|
645 | - public function init_role_caps($reset = false, $custom_map = array()) |
|
646 | - { |
|
647 | - $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map; |
|
648 | - //first let's determine if these caps have already been set. |
|
649 | - $caps_set_before = get_option(self::option_name, array()); |
|
650 | - //if not reset, see what caps are new for each role. if they're new, add them. |
|
651 | - foreach ($caps_map as $role => $caps_for_role) { |
|
652 | - foreach ($caps_for_role as $cap) { |
|
653 | - //first check we haven't already added this cap before, or it's a reset |
|
654 | - if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) { |
|
655 | - if ($this->add_cap_to_role($role, $cap)) { |
|
656 | - $caps_set_before[ $role ][] = $cap; |
|
657 | - } |
|
658 | - } |
|
659 | - } |
|
660 | - } |
|
661 | - //now let's just save the cap that has been set. |
|
662 | - update_option(self::option_name, $caps_set_before); |
|
663 | - do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
669 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
670 | - * this is a wrapper for $wp_role->add_cap() |
|
671 | - * |
|
672 | - * @see wp-includes/capabilities.php |
|
673 | - * @since 4.5.0 |
|
674 | - * @param string $role A WordPress role the capability is being added to |
|
675 | - * @param string $cap The capability being added to the role |
|
676 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
677 | - * @return bool |
|
678 | - */ |
|
679 | - public function add_cap_to_role($role, $cap, $grant = true) |
|
680 | - { |
|
681 | - $role_object = get_role($role); |
|
682 | - //if the role isn't available then we create it. |
|
683 | - if (! $role_object instanceof WP_Role) { |
|
684 | - //if a plugin wants to create a specific role name then they should create the role before |
|
685 | - //EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
686 | - // - removes any `ee_` namespacing from the start of the slug. |
|
687 | - // - replaces `_` with ` ` (empty space). |
|
688 | - // - sentence case on the resulting string. |
|
689 | - $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role))); |
|
690 | - $role_object = add_role($role, $role_label); |
|
691 | - } |
|
692 | - if ($role_object instanceof WP_Role) { |
|
693 | - $role_object->add_cap($cap, $grant); |
|
694 | - return true; |
|
695 | - } |
|
696 | - return false; |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
702 | - * Wrapper for $wp_role->remove_cap() |
|
703 | - * |
|
704 | - * @see wp-includes/capabilities.php |
|
705 | - * @since 4.5.0 |
|
706 | - * @param string $role A WordPress role the capability is being removed from. |
|
707 | - * @param string $cap The capability being removed |
|
708 | - * @return void |
|
709 | - */ |
|
710 | - public function remove_cap_from_role($role, $cap) |
|
711 | - { |
|
712 | - $role = get_role($role); |
|
713 | - if ($role instanceof WP_Role) { |
|
714 | - $role->remove_cap($cap); |
|
715 | - } |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * Wrapper for the native WP current_user_can() method. |
|
721 | - * This is provided as a handy method for a couple things: |
|
722 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
723 | - * write those filters wherever current_user_can is called). |
|
724 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
725 | - * |
|
726 | - * @since 4.5.0 |
|
727 | - * @param string $cap The cap being checked. |
|
728 | - * @param string $context The context where the current_user_can is being called from. |
|
729 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
730 | - * filters. |
|
731 | - * @return bool Whether user can or not. |
|
732 | - */ |
|
733 | - public function current_user_can($cap, $context, $id = 0) |
|
734 | - { |
|
735 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
736 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
737 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
|
738 | - $id); |
|
739 | - return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap); |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - /** |
|
744 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
745 | - * |
|
746 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
747 | - * @param string $cap The capability string being checked |
|
748 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
749 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
750 | - * filters) |
|
751 | - * @return bool Whether user can or not. |
|
752 | - */ |
|
753 | - public function user_can($user, $cap, $context, $id = 0) |
|
754 | - { |
|
755 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
756 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
757 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
|
758 | - $id); |
|
759 | - return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap); |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
765 | - * This is provided as a handy method for a couple things: |
|
766 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
767 | - * write those filters wherever current_user_can is called). |
|
768 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
769 | - * |
|
770 | - * @since 4.5.0 |
|
771 | - * @param int $blog_id The blog id that is being checked for. |
|
772 | - * @param string $cap The cap being checked. |
|
773 | - * @param string $context The context where the current_user_can is being called from. |
|
774 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
775 | - * filters. |
|
776 | - * @return bool Whether user can or not. |
|
777 | - */ |
|
778 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
779 | - { |
|
780 | - $user_can = ! empty($id) |
|
781 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
782 | - : current_user_can($blog_id, $cap); |
|
783 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
784 | - $user_can = apply_filters( |
|
785 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
786 | - $user_can, |
|
787 | - $blog_id, |
|
788 | - $cap, |
|
789 | - $id |
|
790 | - ); |
|
791 | - $user_can = apply_filters( |
|
792 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
793 | - $user_can, |
|
794 | - $context, |
|
795 | - $blog_id, |
|
796 | - $cap, |
|
797 | - $id |
|
798 | - ); |
|
799 | - return $user_can; |
|
800 | - } |
|
801 | - |
|
802 | - |
|
803 | - /** |
|
804 | - * This helper method just returns an array of registered EE capabilities. |
|
805 | - * Note this array is filtered. It is assumed that all available EE capabilities are assigned to the administrator |
|
806 | - * role. |
|
807 | - * |
|
808 | - * @since 4.5.0 |
|
809 | - * @param string $role If empty then the entire role/capability map is returned. Otherwise just the capabilities |
|
810 | - * for the given role are returned. |
|
811 | - * @return array |
|
812 | - */ |
|
813 | - public function get_ee_capabilities($role = 'administrator') |
|
814 | - { |
|
815 | - $capabilities = $this->_init_caps_map(); |
|
816 | - if (empty($role)) { |
|
817 | - return $capabilities; |
|
818 | - } |
|
819 | - return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array(); |
|
820 | - } |
|
19 | + /** |
|
20 | + * the name of the wp option used to store caps previously initialized |
|
21 | + */ |
|
22 | + const option_name = 'ee_caps_initialized'; |
|
23 | + |
|
24 | + /** |
|
25 | + * instance of EE_Capabilities object |
|
26 | + * |
|
27 | + * @var EE_Capabilities |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * This is a map of caps that correspond to a default WP_Role. |
|
33 | + * Array is indexed by Role and values are ee capabilities. |
|
34 | + * |
|
35 | + * @since 4.5.0 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + private $_caps_map = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for |
|
42 | + * a user depending on context. |
|
43 | + * |
|
44 | + * @var EE_Meta_Capability_Map[] |
|
45 | + */ |
|
46 | + private $_meta_caps = array(); |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * singleton method used to instantiate class object |
|
51 | + * |
|
52 | + * @since 4.5.0 |
|
53 | + * @return EE_Capabilities |
|
54 | + */ |
|
55 | + public static function instance() |
|
56 | + { |
|
57 | + //check if instantiated, and if not do so. |
|
58 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
59 | + self::$_instance = new self(); |
|
60 | + } |
|
61 | + return self::$_instance; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * private constructor |
|
67 | + * |
|
68 | + * @since 4.5.0 |
|
69 | + */ |
|
70 | + private function __construct() |
|
71 | + { |
|
72 | + if (is_admin()) { |
|
73 | + add_filter( |
|
74 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
75 | + array($this, 'register_additional_capabilities'), |
|
76 | + 10 |
|
77 | + ); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
84 | + * |
|
85 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
86 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
87 | + * ensures that they are up to date. |
|
88 | + * @since 4.5.0 |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function init_caps($reset = false) |
|
92 | + { |
|
93 | + /** |
|
94 | + * Note, this means that caps can only initialized on the default roles when: |
|
95 | + * - models are queryable |
|
96 | + * - All addons have been registered (which happens at plugins_loaded priority 1) |
|
97 | + * In practice, currently this method is usually called around `init`. |
|
98 | + */ |
|
99 | + if ( |
|
100 | + did_action('AHEE__EE_System__load_espresso_addons__complete') |
|
101 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
102 | + ) { |
|
103 | + $this->_caps_map = $this->_init_caps_map(); |
|
104 | + $this->init_role_caps($reset); |
|
105 | + $this->_set_meta_caps(); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * This sets the meta caps property. |
|
112 | + * |
|
113 | + * @since 4.5.0 |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + private function _set_meta_caps() |
|
117 | + { |
|
118 | + //make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
119 | + $this->_meta_caps = $this->_get_default_meta_caps_array(); |
|
120 | + $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps); |
|
121 | + //add filter for map_meta_caps but only if models can query. |
|
122 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
123 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * This builds and returns the default meta_caps array only once. |
|
130 | + * |
|
131 | + * @since 4.8.28.rc.012 |
|
132 | + * @return array |
|
133 | + * @throws \EE_Error |
|
134 | + */ |
|
135 | + private function _get_default_meta_caps_array() |
|
136 | + { |
|
137 | + static $default_meta_caps = array(); |
|
138 | + if (empty($default_meta_caps)) { |
|
139 | + $default_meta_caps = array( |
|
140 | + //edits |
|
141 | + new EE_Meta_Capability_Map_Edit( |
|
142 | + 'ee_edit_event', |
|
143 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
144 | + ), |
|
145 | + new EE_Meta_Capability_Map_Edit( |
|
146 | + 'ee_edit_venue', |
|
147 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
148 | + ), |
|
149 | + new EE_Meta_Capability_Map_Edit( |
|
150 | + 'ee_edit_registration', |
|
151 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
152 | + ), |
|
153 | + new EE_Meta_Capability_Map_Edit( |
|
154 | + 'ee_edit_checkin', |
|
155 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
156 | + ), |
|
157 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
158 | + 'ee_edit_message', |
|
159 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
160 | + ), |
|
161 | + new EE_Meta_Capability_Map_Edit( |
|
162 | + 'ee_edit_default_ticket', |
|
163 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
164 | + ), |
|
165 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
166 | + 'ee_edit_question', |
|
167 | + array('Question', '', '', 'ee_edit_system_questions') |
|
168 | + ), |
|
169 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
170 | + 'ee_edit_question_group', |
|
171 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
172 | + ), |
|
173 | + new EE_Meta_Capability_Map_Edit( |
|
174 | + 'ee_edit_payment_method', |
|
175 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
176 | + ), |
|
177 | + //reads |
|
178 | + new EE_Meta_Capability_Map_Read( |
|
179 | + 'ee_read_event', |
|
180 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
181 | + ), |
|
182 | + new EE_Meta_Capability_Map_Read( |
|
183 | + 'ee_read_venue', |
|
184 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
185 | + ), |
|
186 | + new EE_Meta_Capability_Map_Read( |
|
187 | + 'ee_read_registration', |
|
188 | + array('Registration', '', '', 'ee_edit_others_registrations') |
|
189 | + ), |
|
190 | + new EE_Meta_Capability_Map_Read( |
|
191 | + 'ee_read_checkin', |
|
192 | + array('Registration', '', '', 'ee_read_others_checkins') |
|
193 | + ), |
|
194 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
195 | + 'ee_read_message', |
|
196 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
197 | + ), |
|
198 | + new EE_Meta_Capability_Map_Read( |
|
199 | + 'ee_read_default_ticket', |
|
200 | + array('Ticket', '', '', 'ee_read_others_default_tickets') |
|
201 | + ), |
|
202 | + new EE_Meta_Capability_Map_Read( |
|
203 | + 'ee_read_payment_method', |
|
204 | + array('Payment_Method', '', '', 'ee_read_others_payment_methods') |
|
205 | + ), |
|
206 | + //deletes |
|
207 | + new EE_Meta_Capability_Map_Delete( |
|
208 | + 'ee_delete_event', |
|
209 | + array( |
|
210 | + 'Event', |
|
211 | + 'ee_delete_published_events', |
|
212 | + 'ee_delete_others_events', |
|
213 | + 'ee_delete_private_events', |
|
214 | + ) |
|
215 | + ), |
|
216 | + new EE_Meta_Capability_Map_Delete( |
|
217 | + 'ee_delete_venue', |
|
218 | + array( |
|
219 | + 'Venue', |
|
220 | + 'ee_delete_published_venues', |
|
221 | + 'ee_delete_others_venues', |
|
222 | + 'ee_delete_private_venues', |
|
223 | + ) |
|
224 | + ), |
|
225 | + new EE_Meta_Capability_Map_Delete( |
|
226 | + 'ee_delete_registration', |
|
227 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
228 | + ), |
|
229 | + new EE_Meta_Capability_Map_Delete( |
|
230 | + 'ee_delete_checkin', |
|
231 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
232 | + ), |
|
233 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
234 | + 'ee_delete_message', |
|
235 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
236 | + ), |
|
237 | + new EE_Meta_Capability_Map_Delete( |
|
238 | + 'ee_delete_default_ticket', |
|
239 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
240 | + ), |
|
241 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
242 | + 'ee_delete_question', |
|
243 | + array('Question', '', '', 'delete_system_questions') |
|
244 | + ), |
|
245 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
246 | + 'ee_delete_question_group', |
|
247 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
248 | + ), |
|
249 | + new EE_Meta_Capability_Map_Delete( |
|
250 | + 'ee_delete_payment_method', |
|
251 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
252 | + ), |
|
253 | + ); |
|
254 | + } |
|
255 | + return $default_meta_caps; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
261 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
262 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
263 | + * |
|
264 | + * @since 4.5.0 |
|
265 | + * @see wp-includes/capabilities.php |
|
266 | + * @param array $caps actual users capabilities |
|
267 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
268 | + * @param int $user_id The user id |
|
269 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
270 | + * @return array actual users capabilities |
|
271 | + * @throws EE_Error |
|
272 | + */ |
|
273 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
274 | + { |
|
275 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
276 | + //loop through our _meta_caps array |
|
277 | + foreach ($this->_meta_caps as $meta_map) { |
|
278 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
279 | + continue; |
|
280 | + } |
|
281 | + if(!empty($args[0])){ |
|
282 | + $meta_map->ensure_is_model(); |
|
283 | + } |
|
284 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
285 | + } |
|
286 | + } |
|
287 | + return $caps; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
293 | + * |
|
294 | + * @since 4.5.0 |
|
295 | + * @return array |
|
296 | + */ |
|
297 | + private function _init_caps_map() |
|
298 | + { |
|
299 | + $caps = array( |
|
300 | + 'administrator' => array( |
|
301 | + //basic access |
|
302 | + 'ee_read_ee', |
|
303 | + //gateways |
|
304 | + /** |
|
305 | + * note that with payment method capabilities, although we've implemented |
|
306 | + * capability mapping which will be used for accessing payment methods owned by |
|
307 | + * other users. This is not fully implemented yet in the payment method ui. |
|
308 | + * Currently only the "plural" caps are in active use. |
|
309 | + * (Specific payment method caps are in use as well). |
|
310 | + **/ |
|
311 | + 'ee_manage_gateways', |
|
312 | + 'ee_read_payment_method', |
|
313 | + 'ee_read_payment_methods', |
|
314 | + 'ee_read_others_payment_methods', |
|
315 | + 'ee_edit_payment_method', |
|
316 | + 'ee_edit_payment_methods', |
|
317 | + 'ee_edit_others_payment_methods', |
|
318 | + 'ee_delete_payment_method', |
|
319 | + 'ee_delete_payment_methods', |
|
320 | + //events |
|
321 | + 'ee_publish_events', |
|
322 | + 'ee_read_private_events', |
|
323 | + 'ee_read_others_events', |
|
324 | + 'ee_read_event', |
|
325 | + 'ee_read_events', |
|
326 | + 'ee_edit_event', |
|
327 | + 'ee_edit_events', |
|
328 | + 'ee_edit_published_events', |
|
329 | + 'ee_edit_others_events', |
|
330 | + 'ee_edit_private_events', |
|
331 | + 'ee_delete_published_events', |
|
332 | + 'ee_delete_private_events', |
|
333 | + 'ee_delete_event', |
|
334 | + 'ee_delete_events', |
|
335 | + 'ee_delete_others_events', |
|
336 | + //event categories |
|
337 | + 'ee_manage_event_categories', |
|
338 | + 'ee_edit_event_category', |
|
339 | + 'ee_delete_event_category', |
|
340 | + 'ee_assign_event_category', |
|
341 | + //venues |
|
342 | + 'ee_publish_venues', |
|
343 | + 'ee_read_venue', |
|
344 | + 'ee_read_venues', |
|
345 | + 'ee_read_others_venues', |
|
346 | + 'ee_read_private_venues', |
|
347 | + 'ee_edit_venue', |
|
348 | + 'ee_edit_venues', |
|
349 | + 'ee_edit_others_venues', |
|
350 | + 'ee_edit_published_venues', |
|
351 | + 'ee_edit_private_venues', |
|
352 | + 'ee_delete_venue', |
|
353 | + 'ee_delete_venues', |
|
354 | + 'ee_delete_others_venues', |
|
355 | + 'ee_delete_private_venues', |
|
356 | + 'ee_delete_published_venues', |
|
357 | + //venue categories |
|
358 | + 'ee_manage_venue_categories', |
|
359 | + 'ee_edit_venue_category', |
|
360 | + 'ee_delete_venue_category', |
|
361 | + 'ee_assign_venue_category', |
|
362 | + //contacts |
|
363 | + 'ee_read_contact', |
|
364 | + 'ee_read_contacts', |
|
365 | + 'ee_edit_contact', |
|
366 | + 'ee_edit_contacts', |
|
367 | + 'ee_delete_contact', |
|
368 | + 'ee_delete_contacts', |
|
369 | + //registrations |
|
370 | + 'ee_read_registration', |
|
371 | + 'ee_read_registrations', |
|
372 | + 'ee_read_others_registrations', |
|
373 | + 'ee_edit_registration', |
|
374 | + 'ee_edit_registrations', |
|
375 | + 'ee_edit_others_registrations', |
|
376 | + 'ee_delete_registration', |
|
377 | + 'ee_delete_registrations', |
|
378 | + //checkins |
|
379 | + 'ee_read_checkin', |
|
380 | + 'ee_read_others_checkins', |
|
381 | + 'ee_read_checkins', |
|
382 | + 'ee_edit_checkin', |
|
383 | + 'ee_edit_checkins', |
|
384 | + 'ee_edit_others_checkins', |
|
385 | + 'ee_delete_checkin', |
|
386 | + 'ee_delete_checkins', |
|
387 | + 'ee_delete_others_checkins', |
|
388 | + //transactions && payments |
|
389 | + 'ee_read_transaction', |
|
390 | + 'ee_read_transactions', |
|
391 | + 'ee_edit_payments', |
|
392 | + 'ee_delete_payments', |
|
393 | + //messages |
|
394 | + 'ee_read_message', |
|
395 | + 'ee_read_messages', |
|
396 | + 'ee_read_others_messages', |
|
397 | + 'ee_read_global_messages', |
|
398 | + 'ee_edit_global_messages', |
|
399 | + 'ee_edit_message', |
|
400 | + 'ee_edit_messages', |
|
401 | + 'ee_edit_others_messages', |
|
402 | + 'ee_delete_message', |
|
403 | + 'ee_delete_messages', |
|
404 | + 'ee_delete_others_messages', |
|
405 | + 'ee_delete_global_messages', |
|
406 | + 'ee_send_message', |
|
407 | + //tickets |
|
408 | + 'ee_read_default_ticket', |
|
409 | + 'ee_read_default_tickets', |
|
410 | + 'ee_read_others_default_tickets', |
|
411 | + 'ee_edit_default_ticket', |
|
412 | + 'ee_edit_default_tickets', |
|
413 | + 'ee_edit_others_default_tickets', |
|
414 | + 'ee_delete_default_ticket', |
|
415 | + 'ee_delete_default_tickets', |
|
416 | + 'ee_delete_others_default_tickets', |
|
417 | + //prices |
|
418 | + 'ee_edit_default_price', |
|
419 | + 'ee_edit_default_prices', |
|
420 | + 'ee_delete_default_price', |
|
421 | + 'ee_delete_default_prices', |
|
422 | + 'ee_edit_default_price_type', |
|
423 | + 'ee_edit_default_price_types', |
|
424 | + 'ee_delete_default_price_type', |
|
425 | + 'ee_delete_default_price_types', |
|
426 | + 'ee_read_default_prices', |
|
427 | + 'ee_read_default_price_types', |
|
428 | + //registration form |
|
429 | + 'ee_edit_question', |
|
430 | + 'ee_edit_questions', |
|
431 | + 'ee_edit_system_questions', |
|
432 | + 'ee_read_questions', |
|
433 | + 'ee_delete_question', |
|
434 | + 'ee_delete_questions', |
|
435 | + 'ee_edit_question_group', |
|
436 | + 'ee_edit_question_groups', |
|
437 | + 'ee_read_question_groups', |
|
438 | + 'ee_edit_system_question_groups', |
|
439 | + 'ee_delete_question_group', |
|
440 | + 'ee_delete_question_groups', |
|
441 | + //event_type taxonomy |
|
442 | + 'ee_assign_event_type', |
|
443 | + 'ee_manage_event_types', |
|
444 | + 'ee_edit_event_type', |
|
445 | + 'ee_delete_event_type', |
|
446 | + ), |
|
447 | + 'ee_events_administrator' => array( |
|
448 | + //core wp caps |
|
449 | + 'read', |
|
450 | + 'read_private_pages', |
|
451 | + 'read_private_posts', |
|
452 | + 'edit_users', |
|
453 | + 'edit_posts', |
|
454 | + 'edit_pages', |
|
455 | + 'edit_published_posts', |
|
456 | + 'edit_published_pages', |
|
457 | + 'edit_private_pages', |
|
458 | + 'edit_private_posts', |
|
459 | + 'edit_others_posts', |
|
460 | + 'edit_others_pages', |
|
461 | + 'publish_posts', |
|
462 | + 'publish_pages', |
|
463 | + 'delete_posts', |
|
464 | + 'delete_pages', |
|
465 | + 'delete_private_pages', |
|
466 | + 'delete_private_posts', |
|
467 | + 'delete_published_pages', |
|
468 | + 'delete_published_posts', |
|
469 | + 'delete_others_posts', |
|
470 | + 'delete_others_pages', |
|
471 | + 'manage_categories', |
|
472 | + 'manage_links', |
|
473 | + 'moderate_comments', |
|
474 | + 'unfiltered_html', |
|
475 | + 'upload_files', |
|
476 | + 'export', |
|
477 | + 'import', |
|
478 | + 'list_users', |
|
479 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
480 | + //basic ee access |
|
481 | + 'ee_read_ee', |
|
482 | + //events |
|
483 | + 'ee_publish_events', |
|
484 | + 'ee_read_private_events', |
|
485 | + 'ee_read_others_events', |
|
486 | + 'ee_read_event', |
|
487 | + 'ee_read_events', |
|
488 | + 'ee_edit_event', |
|
489 | + 'ee_edit_events', |
|
490 | + 'ee_edit_published_events', |
|
491 | + 'ee_edit_others_events', |
|
492 | + 'ee_edit_private_events', |
|
493 | + 'ee_delete_published_events', |
|
494 | + 'ee_delete_private_events', |
|
495 | + 'ee_delete_event', |
|
496 | + 'ee_delete_events', |
|
497 | + 'ee_delete_others_events', |
|
498 | + //event categories |
|
499 | + 'ee_manage_event_categories', |
|
500 | + 'ee_edit_event_category', |
|
501 | + 'ee_delete_event_category', |
|
502 | + 'ee_assign_event_category', |
|
503 | + //venues |
|
504 | + 'ee_publish_venues', |
|
505 | + 'ee_read_venue', |
|
506 | + 'ee_read_venues', |
|
507 | + 'ee_read_others_venues', |
|
508 | + 'ee_read_private_venues', |
|
509 | + 'ee_edit_venue', |
|
510 | + 'ee_edit_venues', |
|
511 | + 'ee_edit_others_venues', |
|
512 | + 'ee_edit_published_venues', |
|
513 | + 'ee_edit_private_venues', |
|
514 | + 'ee_delete_venue', |
|
515 | + 'ee_delete_venues', |
|
516 | + 'ee_delete_others_venues', |
|
517 | + 'ee_delete_private_venues', |
|
518 | + 'ee_delete_published_venues', |
|
519 | + //venue categories |
|
520 | + 'ee_manage_venue_categories', |
|
521 | + 'ee_edit_venue_category', |
|
522 | + 'ee_delete_venue_category', |
|
523 | + 'ee_assign_venue_category', |
|
524 | + //contacts |
|
525 | + 'ee_read_contact', |
|
526 | + 'ee_read_contacts', |
|
527 | + 'ee_edit_contact', |
|
528 | + 'ee_edit_contacts', |
|
529 | + 'ee_delete_contact', |
|
530 | + 'ee_delete_contacts', |
|
531 | + //registrations |
|
532 | + 'ee_read_registration', |
|
533 | + 'ee_read_registrations', |
|
534 | + 'ee_read_others_registrations', |
|
535 | + 'ee_edit_registration', |
|
536 | + 'ee_edit_registrations', |
|
537 | + 'ee_edit_others_registrations', |
|
538 | + 'ee_delete_registration', |
|
539 | + 'ee_delete_registrations', |
|
540 | + //checkins |
|
541 | + 'ee_read_checkin', |
|
542 | + 'ee_read_others_checkins', |
|
543 | + 'ee_read_checkins', |
|
544 | + 'ee_edit_checkin', |
|
545 | + 'ee_edit_checkins', |
|
546 | + 'ee_edit_others_checkins', |
|
547 | + 'ee_delete_checkin', |
|
548 | + 'ee_delete_checkins', |
|
549 | + 'ee_delete_others_checkins', |
|
550 | + //transactions && payments |
|
551 | + 'ee_read_transaction', |
|
552 | + 'ee_read_transactions', |
|
553 | + 'ee_edit_payments', |
|
554 | + 'ee_delete_payments', |
|
555 | + //messages |
|
556 | + 'ee_read_message', |
|
557 | + 'ee_read_messages', |
|
558 | + 'ee_read_others_messages', |
|
559 | + 'ee_read_global_messages', |
|
560 | + 'ee_edit_global_messages', |
|
561 | + 'ee_edit_message', |
|
562 | + 'ee_edit_messages', |
|
563 | + 'ee_edit_others_messages', |
|
564 | + 'ee_delete_message', |
|
565 | + 'ee_delete_messages', |
|
566 | + 'ee_delete_others_messages', |
|
567 | + 'ee_delete_global_messages', |
|
568 | + 'ee_send_message', |
|
569 | + //tickets |
|
570 | + 'ee_read_default_ticket', |
|
571 | + 'ee_read_default_tickets', |
|
572 | + 'ee_read_others_default_tickets', |
|
573 | + 'ee_edit_default_ticket', |
|
574 | + 'ee_edit_default_tickets', |
|
575 | + 'ee_edit_others_default_tickets', |
|
576 | + 'ee_delete_default_ticket', |
|
577 | + 'ee_delete_default_tickets', |
|
578 | + 'ee_delete_others_default_tickets', |
|
579 | + //prices |
|
580 | + 'ee_edit_default_price', |
|
581 | + 'ee_edit_default_prices', |
|
582 | + 'ee_delete_default_price', |
|
583 | + 'ee_delete_default_prices', |
|
584 | + 'ee_edit_default_price_type', |
|
585 | + 'ee_edit_default_price_types', |
|
586 | + 'ee_delete_default_price_type', |
|
587 | + 'ee_delete_default_price_types', |
|
588 | + 'ee_read_default_prices', |
|
589 | + 'ee_read_default_price_types', |
|
590 | + //registration form |
|
591 | + 'ee_edit_question', |
|
592 | + 'ee_edit_questions', |
|
593 | + 'ee_edit_system_questions', |
|
594 | + 'ee_read_questions', |
|
595 | + 'ee_delete_question', |
|
596 | + 'ee_delete_questions', |
|
597 | + 'ee_edit_question_group', |
|
598 | + 'ee_edit_question_groups', |
|
599 | + 'ee_read_question_groups', |
|
600 | + 'ee_edit_system_question_groups', |
|
601 | + 'ee_delete_question_group', |
|
602 | + 'ee_delete_question_groups', |
|
603 | + //event_type taxonomy |
|
604 | + 'ee_assign_event_type', |
|
605 | + 'ee_manage_event_types', |
|
606 | + 'ee_edit_event_type', |
|
607 | + 'ee_delete_event_type', |
|
608 | + ), |
|
609 | + ); |
|
610 | + $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps); |
|
611 | + return $caps; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Callback for FHEE__EE_Capabilities__init_caps_map__caps that is used for registering additional core |
|
617 | + * capabilities that get added. |
|
618 | + * This is typically done for more dynamic cap additions such as what is registered via the |
|
619 | + * `EE_Payment_Method_Manager` |
|
620 | + * |
|
621 | + * @param array $caps The existing $role=>$capability array. |
|
622 | + * @return array. |
|
623 | + */ |
|
624 | + public function register_additional_capabilities($caps) |
|
625 | + { |
|
626 | + //take care of dynamic capabilities for payment methods |
|
627 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
628 | + $caps = EE_Payment_Method_Manager::instance()->add_payment_method_caps($caps); |
|
629 | + return $caps; |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * This adds all the default caps to roles as registered in the _caps_map property. |
|
635 | + * |
|
636 | + * @since 4.5.0 |
|
637 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
638 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles |
|
639 | + * and ensures that they are up to date. |
|
640 | + * @param array $custom_map Optional. Can be used to send a custom map of roles and capabilities for setting them |
|
641 | + * up. Note that this should ONLY be called on activation hook or some other one-time |
|
642 | + * task otherwise the caps will be added on every request. |
|
643 | + * @return void |
|
644 | + */ |
|
645 | + public function init_role_caps($reset = false, $custom_map = array()) |
|
646 | + { |
|
647 | + $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map; |
|
648 | + //first let's determine if these caps have already been set. |
|
649 | + $caps_set_before = get_option(self::option_name, array()); |
|
650 | + //if not reset, see what caps are new for each role. if they're new, add them. |
|
651 | + foreach ($caps_map as $role => $caps_for_role) { |
|
652 | + foreach ($caps_for_role as $cap) { |
|
653 | + //first check we haven't already added this cap before, or it's a reset |
|
654 | + if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) { |
|
655 | + if ($this->add_cap_to_role($role, $cap)) { |
|
656 | + $caps_set_before[ $role ][] = $cap; |
|
657 | + } |
|
658 | + } |
|
659 | + } |
|
660 | + } |
|
661 | + //now let's just save the cap that has been set. |
|
662 | + update_option(self::option_name, $caps_set_before); |
|
663 | + do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
669 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
670 | + * this is a wrapper for $wp_role->add_cap() |
|
671 | + * |
|
672 | + * @see wp-includes/capabilities.php |
|
673 | + * @since 4.5.0 |
|
674 | + * @param string $role A WordPress role the capability is being added to |
|
675 | + * @param string $cap The capability being added to the role |
|
676 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
677 | + * @return bool |
|
678 | + */ |
|
679 | + public function add_cap_to_role($role, $cap, $grant = true) |
|
680 | + { |
|
681 | + $role_object = get_role($role); |
|
682 | + //if the role isn't available then we create it. |
|
683 | + if (! $role_object instanceof WP_Role) { |
|
684 | + //if a plugin wants to create a specific role name then they should create the role before |
|
685 | + //EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
686 | + // - removes any `ee_` namespacing from the start of the slug. |
|
687 | + // - replaces `_` with ` ` (empty space). |
|
688 | + // - sentence case on the resulting string. |
|
689 | + $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role))); |
|
690 | + $role_object = add_role($role, $role_label); |
|
691 | + } |
|
692 | + if ($role_object instanceof WP_Role) { |
|
693 | + $role_object->add_cap($cap, $grant); |
|
694 | + return true; |
|
695 | + } |
|
696 | + return false; |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
702 | + * Wrapper for $wp_role->remove_cap() |
|
703 | + * |
|
704 | + * @see wp-includes/capabilities.php |
|
705 | + * @since 4.5.0 |
|
706 | + * @param string $role A WordPress role the capability is being removed from. |
|
707 | + * @param string $cap The capability being removed |
|
708 | + * @return void |
|
709 | + */ |
|
710 | + public function remove_cap_from_role($role, $cap) |
|
711 | + { |
|
712 | + $role = get_role($role); |
|
713 | + if ($role instanceof WP_Role) { |
|
714 | + $role->remove_cap($cap); |
|
715 | + } |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * Wrapper for the native WP current_user_can() method. |
|
721 | + * This is provided as a handy method for a couple things: |
|
722 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
723 | + * write those filters wherever current_user_can is called). |
|
724 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
725 | + * |
|
726 | + * @since 4.5.0 |
|
727 | + * @param string $cap The cap being checked. |
|
728 | + * @param string $context The context where the current_user_can is being called from. |
|
729 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
730 | + * filters. |
|
731 | + * @return bool Whether user can or not. |
|
732 | + */ |
|
733 | + public function current_user_can($cap, $context, $id = 0) |
|
734 | + { |
|
735 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
736 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
737 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
|
738 | + $id); |
|
739 | + return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap); |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
745 | + * |
|
746 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
747 | + * @param string $cap The capability string being checked |
|
748 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
749 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
750 | + * filters) |
|
751 | + * @return bool Whether user can or not. |
|
752 | + */ |
|
753 | + public function user_can($user, $cap, $context, $id = 0) |
|
754 | + { |
|
755 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
756 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
757 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
|
758 | + $id); |
|
759 | + return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap); |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
765 | + * This is provided as a handy method for a couple things: |
|
766 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
767 | + * write those filters wherever current_user_can is called). |
|
768 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
769 | + * |
|
770 | + * @since 4.5.0 |
|
771 | + * @param int $blog_id The blog id that is being checked for. |
|
772 | + * @param string $cap The cap being checked. |
|
773 | + * @param string $context The context where the current_user_can is being called from. |
|
774 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
775 | + * filters. |
|
776 | + * @return bool Whether user can or not. |
|
777 | + */ |
|
778 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
779 | + { |
|
780 | + $user_can = ! empty($id) |
|
781 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
782 | + : current_user_can($blog_id, $cap); |
|
783 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
784 | + $user_can = apply_filters( |
|
785 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
786 | + $user_can, |
|
787 | + $blog_id, |
|
788 | + $cap, |
|
789 | + $id |
|
790 | + ); |
|
791 | + $user_can = apply_filters( |
|
792 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
793 | + $user_can, |
|
794 | + $context, |
|
795 | + $blog_id, |
|
796 | + $cap, |
|
797 | + $id |
|
798 | + ); |
|
799 | + return $user_can; |
|
800 | + } |
|
801 | + |
|
802 | + |
|
803 | + /** |
|
804 | + * This helper method just returns an array of registered EE capabilities. |
|
805 | + * Note this array is filtered. It is assumed that all available EE capabilities are assigned to the administrator |
|
806 | + * role. |
|
807 | + * |
|
808 | + * @since 4.5.0 |
|
809 | + * @param string $role If empty then the entire role/capability map is returned. Otherwise just the capabilities |
|
810 | + * for the given role are returned. |
|
811 | + * @return array |
|
812 | + */ |
|
813 | + public function get_ee_capabilities($role = 'administrator') |
|
814 | + { |
|
815 | + $capabilities = $this->_init_caps_map(); |
|
816 | + if (empty($role)) { |
|
817 | + return $capabilities; |
|
818 | + } |
|
819 | + return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array(); |
|
820 | + } |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | |
@@ -834,134 +834,134 @@ discard block |
||
834 | 834 | abstract class EE_Meta_Capability_Map |
835 | 835 | { |
836 | 836 | |
837 | - public $meta_cap; |
|
838 | - |
|
839 | - /** |
|
840 | - * @var EEM_Base |
|
841 | - */ |
|
842 | - protected $_model; |
|
843 | - |
|
844 | - protected $_model_name; |
|
845 | - |
|
846 | - public $published_cap = ''; |
|
847 | - |
|
848 | - public $others_cap = ''; |
|
849 | - |
|
850 | - public $private_cap = ''; |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * constructor. |
|
855 | - * Receives the setup arguments for the map. |
|
856 | - * |
|
857 | - * @since 4.5.0 |
|
858 | - * @param string $meta_cap What meta capability is this mapping. |
|
859 | - * @param array $map_values array { |
|
860 | - * //array of values that MUST match a count of 4. It's okay to send an empty string |
|
861 | - * for capabilities that don't get mapped to. |
|
862 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
863 | - * should always be used when Menu Maps are registered via the |
|
864 | - * plugin API as models are not allowed to be instantiated when |
|
865 | - * in maintenance mode 2 (migrations). |
|
866 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
867 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
868 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
869 | - * } |
|
870 | - * @throws EE_Error |
|
871 | - */ |
|
872 | - public function __construct($meta_cap, $map_values) |
|
873 | - { |
|
874 | - $this->meta_cap = $meta_cap; |
|
875 | - //verify there are four args in the $map_values array; |
|
876 | - if (count($map_values) !== 4) { |
|
877 | - throw new EE_Error( |
|
878 | - sprintf( |
|
879 | - __( |
|
880 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
881 | - 'event_espresso' |
|
882 | - ), |
|
883 | - '<br>' . print_r($map_values, true) |
|
884 | - ) |
|
885 | - ); |
|
886 | - } |
|
887 | - //set properties |
|
888 | - $this->_model = null; |
|
889 | - $this->_model_name = $map_values[0]; |
|
890 | - $this->published_cap = (string)$map_values[1]; |
|
891 | - $this->others_cap = (string)$map_values[2]; |
|
892 | - $this->private_cap = (string)$map_values[3]; |
|
893 | - } |
|
894 | - |
|
895 | - /** |
|
896 | - * Makes it so this object stops filtering caps |
|
897 | - */ |
|
898 | - public function remove_filters() |
|
899 | - { |
|
900 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
901 | - } |
|
902 | - |
|
903 | - |
|
904 | - /** |
|
905 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
906 | - * |
|
907 | - * @since 4.5.0 |
|
908 | - * @throws EE_Error |
|
909 | - * @return void |
|
910 | - */ |
|
911 | - public function ensure_is_model() |
|
912 | - { |
|
913 | - //is it already instantiated? |
|
914 | - if ($this->_model instanceof EEM_Base) { |
|
915 | - return; |
|
916 | - } |
|
917 | - //ensure model name is string |
|
918 | - $this->_model_name = (string)$this->_model_name; |
|
919 | - //error proof if the name has EEM in it |
|
920 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
921 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
922 | - if (! $this->_model instanceof EEM_Base) { |
|
923 | - throw new EE_Error( |
|
924 | - sprintf( |
|
925 | - __( |
|
926 | - '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', |
|
927 | - 'event_espresso' |
|
928 | - ), |
|
929 | - get_class($this), |
|
930 | - $this->_model |
|
931 | - ) |
|
932 | - ); |
|
933 | - } |
|
934 | - } |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
939 | - * @since 4.6.x |
|
940 | - * @param $caps |
|
941 | - * @param $cap |
|
942 | - * @param $user_id |
|
943 | - * @param $args |
|
944 | - * @return array |
|
945 | - */ |
|
946 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
947 | - { |
|
948 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - /** |
|
953 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
954 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
955 | - * |
|
956 | - * @since 4.5.0 |
|
957 | - * @see wp-includes/capabilities.php |
|
958 | - * @param array $caps actual users capabilities |
|
959 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
960 | - * @param int $user_id The user id |
|
961 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
962 | - * @return array actual users capabilities |
|
963 | - */ |
|
964 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
837 | + public $meta_cap; |
|
838 | + |
|
839 | + /** |
|
840 | + * @var EEM_Base |
|
841 | + */ |
|
842 | + protected $_model; |
|
843 | + |
|
844 | + protected $_model_name; |
|
845 | + |
|
846 | + public $published_cap = ''; |
|
847 | + |
|
848 | + public $others_cap = ''; |
|
849 | + |
|
850 | + public $private_cap = ''; |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * constructor. |
|
855 | + * Receives the setup arguments for the map. |
|
856 | + * |
|
857 | + * @since 4.5.0 |
|
858 | + * @param string $meta_cap What meta capability is this mapping. |
|
859 | + * @param array $map_values array { |
|
860 | + * //array of values that MUST match a count of 4. It's okay to send an empty string |
|
861 | + * for capabilities that don't get mapped to. |
|
862 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
863 | + * should always be used when Menu Maps are registered via the |
|
864 | + * plugin API as models are not allowed to be instantiated when |
|
865 | + * in maintenance mode 2 (migrations). |
|
866 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
867 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
868 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
869 | + * } |
|
870 | + * @throws EE_Error |
|
871 | + */ |
|
872 | + public function __construct($meta_cap, $map_values) |
|
873 | + { |
|
874 | + $this->meta_cap = $meta_cap; |
|
875 | + //verify there are four args in the $map_values array; |
|
876 | + if (count($map_values) !== 4) { |
|
877 | + throw new EE_Error( |
|
878 | + sprintf( |
|
879 | + __( |
|
880 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
881 | + 'event_espresso' |
|
882 | + ), |
|
883 | + '<br>' . print_r($map_values, true) |
|
884 | + ) |
|
885 | + ); |
|
886 | + } |
|
887 | + //set properties |
|
888 | + $this->_model = null; |
|
889 | + $this->_model_name = $map_values[0]; |
|
890 | + $this->published_cap = (string)$map_values[1]; |
|
891 | + $this->others_cap = (string)$map_values[2]; |
|
892 | + $this->private_cap = (string)$map_values[3]; |
|
893 | + } |
|
894 | + |
|
895 | + /** |
|
896 | + * Makes it so this object stops filtering caps |
|
897 | + */ |
|
898 | + public function remove_filters() |
|
899 | + { |
|
900 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
901 | + } |
|
902 | + |
|
903 | + |
|
904 | + /** |
|
905 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
906 | + * |
|
907 | + * @since 4.5.0 |
|
908 | + * @throws EE_Error |
|
909 | + * @return void |
|
910 | + */ |
|
911 | + public function ensure_is_model() |
|
912 | + { |
|
913 | + //is it already instantiated? |
|
914 | + if ($this->_model instanceof EEM_Base) { |
|
915 | + return; |
|
916 | + } |
|
917 | + //ensure model name is string |
|
918 | + $this->_model_name = (string)$this->_model_name; |
|
919 | + //error proof if the name has EEM in it |
|
920 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
921 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
922 | + if (! $this->_model instanceof EEM_Base) { |
|
923 | + throw new EE_Error( |
|
924 | + sprintf( |
|
925 | + __( |
|
926 | + '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', |
|
927 | + 'event_espresso' |
|
928 | + ), |
|
929 | + get_class($this), |
|
930 | + $this->_model |
|
931 | + ) |
|
932 | + ); |
|
933 | + } |
|
934 | + } |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
939 | + * @since 4.6.x |
|
940 | + * @param $caps |
|
941 | + * @param $cap |
|
942 | + * @param $user_id |
|
943 | + * @param $args |
|
944 | + * @return array |
|
945 | + */ |
|
946 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
947 | + { |
|
948 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + /** |
|
953 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
954 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
955 | + * |
|
956 | + * @since 4.5.0 |
|
957 | + * @see wp-includes/capabilities.php |
|
958 | + * @param array $caps actual users capabilities |
|
959 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
960 | + * @param int $user_id The user id |
|
961 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
962 | + * @return array actual users capabilities |
|
963 | + */ |
|
964 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | |
@@ -977,81 +977,81 @@ discard block |
||
977 | 977 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
978 | 978 | { |
979 | 979 | |
980 | - /** |
|
981 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
982 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
983 | - * |
|
984 | - * @since 4.5.0 |
|
985 | - * @see wp-includes/capabilities.php |
|
986 | - * @param array $caps actual users capabilities |
|
987 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
988 | - * @param int $user_id The user id |
|
989 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
990 | - * @return array actual users capabilities |
|
991 | - */ |
|
992 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
993 | - { |
|
994 | - //only process if we're checking our mapped_cap |
|
995 | - if ($cap !== $this->meta_cap) { |
|
996 | - return $caps; |
|
997 | - } |
|
998 | - |
|
999 | - //cast $user_id to int for later explicit comparisons |
|
1000 | - $user_id = (int) $user_id; |
|
1001 | - |
|
1002 | - /** @var EE_Base_Class $obj */ |
|
1003 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1004 | - //if no obj then let's just do cap |
|
1005 | - if (! $obj instanceof EE_Base_Class) { |
|
1006 | - $caps[] = $cap; |
|
1007 | - return $caps; |
|
1008 | - } |
|
1009 | - if ($obj instanceof EE_CPT_Base) { |
|
1010 | - //if the item author is set and the user is the author... |
|
1011 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
1012 | - if (empty($this->published_cap)) { |
|
1013 | - $caps[] = $cap; |
|
1014 | - } else { |
|
1015 | - //if obj is published... |
|
1016 | - if ($obj->status() === 'publish') { |
|
1017 | - $caps[] = $this->published_cap; |
|
1018 | - } else { |
|
1019 | - $caps[] = $cap; |
|
1020 | - } |
|
1021 | - } |
|
1022 | - } else { |
|
1023 | - //the user is trying to edit someone else's obj |
|
1024 | - if (! empty($this->others_cap)) { |
|
1025 | - $caps[] = $this->others_cap; |
|
1026 | - } |
|
1027 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1028 | - $caps[] = $this->published_cap; |
|
1029 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1030 | - $caps[] = $this->private_cap; |
|
1031 | - } |
|
1032 | - } |
|
1033 | - } else { |
|
1034 | - //not a cpt object so handled differently |
|
1035 | - $has_cap = false; |
|
1036 | - try { |
|
1037 | - $has_cap = method_exists($obj, 'wp_user') |
|
1038 | - && $obj->wp_user() |
|
1039 | - && $obj->wp_user() === $user_id; |
|
1040 | - } catch (Exception $e) { |
|
1041 | - if (WP_DEBUG) { |
|
1042 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1043 | - } |
|
1044 | - } |
|
1045 | - if ($has_cap) { |
|
1046 | - $caps[] = $cap; |
|
1047 | - } else { |
|
1048 | - if (! empty($this->others_cap)) { |
|
1049 | - $caps[] = $this->others_cap; |
|
1050 | - } |
|
1051 | - } |
|
1052 | - } |
|
1053 | - return $caps; |
|
1054 | - } |
|
980 | + /** |
|
981 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
982 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
983 | + * |
|
984 | + * @since 4.5.0 |
|
985 | + * @see wp-includes/capabilities.php |
|
986 | + * @param array $caps actual users capabilities |
|
987 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
988 | + * @param int $user_id The user id |
|
989 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
990 | + * @return array actual users capabilities |
|
991 | + */ |
|
992 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
993 | + { |
|
994 | + //only process if we're checking our mapped_cap |
|
995 | + if ($cap !== $this->meta_cap) { |
|
996 | + return $caps; |
|
997 | + } |
|
998 | + |
|
999 | + //cast $user_id to int for later explicit comparisons |
|
1000 | + $user_id = (int) $user_id; |
|
1001 | + |
|
1002 | + /** @var EE_Base_Class $obj */ |
|
1003 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1004 | + //if no obj then let's just do cap |
|
1005 | + if (! $obj instanceof EE_Base_Class) { |
|
1006 | + $caps[] = $cap; |
|
1007 | + return $caps; |
|
1008 | + } |
|
1009 | + if ($obj instanceof EE_CPT_Base) { |
|
1010 | + //if the item author is set and the user is the author... |
|
1011 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
1012 | + if (empty($this->published_cap)) { |
|
1013 | + $caps[] = $cap; |
|
1014 | + } else { |
|
1015 | + //if obj is published... |
|
1016 | + if ($obj->status() === 'publish') { |
|
1017 | + $caps[] = $this->published_cap; |
|
1018 | + } else { |
|
1019 | + $caps[] = $cap; |
|
1020 | + } |
|
1021 | + } |
|
1022 | + } else { |
|
1023 | + //the user is trying to edit someone else's obj |
|
1024 | + if (! empty($this->others_cap)) { |
|
1025 | + $caps[] = $this->others_cap; |
|
1026 | + } |
|
1027 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1028 | + $caps[] = $this->published_cap; |
|
1029 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1030 | + $caps[] = $this->private_cap; |
|
1031 | + } |
|
1032 | + } |
|
1033 | + } else { |
|
1034 | + //not a cpt object so handled differently |
|
1035 | + $has_cap = false; |
|
1036 | + try { |
|
1037 | + $has_cap = method_exists($obj, 'wp_user') |
|
1038 | + && $obj->wp_user() |
|
1039 | + && $obj->wp_user() === $user_id; |
|
1040 | + } catch (Exception $e) { |
|
1041 | + if (WP_DEBUG) { |
|
1042 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1043 | + } |
|
1044 | + } |
|
1045 | + if ($has_cap) { |
|
1046 | + $caps[] = $cap; |
|
1047 | + } else { |
|
1048 | + if (! empty($this->others_cap)) { |
|
1049 | + $caps[] = $this->others_cap; |
|
1050 | + } |
|
1051 | + } |
|
1052 | + } |
|
1053 | + return $caps; |
|
1054 | + } |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | |
@@ -1068,22 +1068,22 @@ discard block |
||
1068 | 1068 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
1069 | 1069 | { |
1070 | 1070 | |
1071 | - /** |
|
1072 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1073 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1074 | - * |
|
1075 | - * @since 4.5.0 |
|
1076 | - * @see wp-includes/capabilities.php |
|
1077 | - * @param array $caps actual users capabilities |
|
1078 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1079 | - * @param int $user_id The user id |
|
1080 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1081 | - * @return array actual users capabilities |
|
1082 | - */ |
|
1083 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1084 | - { |
|
1085 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1086 | - } |
|
1071 | + /** |
|
1072 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1073 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1074 | + * |
|
1075 | + * @since 4.5.0 |
|
1076 | + * @see wp-includes/capabilities.php |
|
1077 | + * @param array $caps actual users capabilities |
|
1078 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1079 | + * @param int $user_id The user id |
|
1080 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1081 | + * @return array actual users capabilities |
|
1082 | + */ |
|
1083 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1084 | + { |
|
1085 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1086 | + } |
|
1087 | 1087 | } |
1088 | 1088 | |
1089 | 1089 | |
@@ -1099,73 +1099,73 @@ discard block |
||
1099 | 1099 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
1100 | 1100 | { |
1101 | 1101 | |
1102 | - /** |
|
1103 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1104 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1105 | - * |
|
1106 | - * @since 4.5.0 |
|
1107 | - * @see wp-includes/capabilities.php |
|
1108 | - * @param array $caps actual users capabilities |
|
1109 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1110 | - * @param int $user_id The user id |
|
1111 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1112 | - * @return array actual users capabilities |
|
1113 | - */ |
|
1114 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1115 | - { |
|
1116 | - //only process if we're checking our mapped cap; |
|
1117 | - if ($cap !== $this->meta_cap) { |
|
1118 | - return $caps; |
|
1119 | - } |
|
1120 | - |
|
1121 | - //cast $user_id to int for later explicit comparisons |
|
1122 | - $user_id = (int) $user_id; |
|
1123 | - |
|
1124 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1125 | - //if no obj then let's just do cap |
|
1126 | - if (! $obj instanceof EE_Base_Class) { |
|
1127 | - $caps[] = $cap; |
|
1128 | - return $caps; |
|
1129 | - } |
|
1130 | - if ($obj instanceof EE_CPT_Base) { |
|
1131 | - $status_obj = get_post_status_object($obj->status()); |
|
1132 | - if ($status_obj->public) { |
|
1133 | - $caps[] = $cap; |
|
1134 | - return $caps; |
|
1135 | - } |
|
1136 | - //if the item author is set and the user is the author... |
|
1137 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1138 | - $caps[] = $cap; |
|
1139 | - } elseif ($status_obj->private && ! empty($this->private_cap)) { |
|
1140 | - //the user is trying to view someone else's obj |
|
1141 | - $caps[] = $this->private_cap; |
|
1142 | - } elseif (! empty($this->others_cap)) { |
|
1143 | - $caps[] = $this->others_cap; |
|
1144 | - } else { |
|
1145 | - $caps[] = $cap; |
|
1146 | - } |
|
1147 | - } else { |
|
1148 | - //not a cpt object so handled differently |
|
1149 | - $has_cap = false; |
|
1150 | - try { |
|
1151 | - $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id; |
|
1152 | - } catch (Exception $e) { |
|
1153 | - if (WP_DEBUG) { |
|
1154 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1155 | - } |
|
1156 | - } |
|
1157 | - if ($has_cap) { |
|
1158 | - $caps[] = $cap; |
|
1159 | - } elseif (! empty($this->private_cap)) { |
|
1160 | - $caps[] = $this->private_cap; |
|
1161 | - } elseif (! empty($this->others_cap)) { |
|
1162 | - $caps[] = $this->others_cap; |
|
1163 | - } else { |
|
1164 | - $caps[] = $cap; |
|
1165 | - } |
|
1166 | - } |
|
1167 | - return $caps; |
|
1168 | - } |
|
1102 | + /** |
|
1103 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1104 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1105 | + * |
|
1106 | + * @since 4.5.0 |
|
1107 | + * @see wp-includes/capabilities.php |
|
1108 | + * @param array $caps actual users capabilities |
|
1109 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1110 | + * @param int $user_id The user id |
|
1111 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1112 | + * @return array actual users capabilities |
|
1113 | + */ |
|
1114 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1115 | + { |
|
1116 | + //only process if we're checking our mapped cap; |
|
1117 | + if ($cap !== $this->meta_cap) { |
|
1118 | + return $caps; |
|
1119 | + } |
|
1120 | + |
|
1121 | + //cast $user_id to int for later explicit comparisons |
|
1122 | + $user_id = (int) $user_id; |
|
1123 | + |
|
1124 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1125 | + //if no obj then let's just do cap |
|
1126 | + if (! $obj instanceof EE_Base_Class) { |
|
1127 | + $caps[] = $cap; |
|
1128 | + return $caps; |
|
1129 | + } |
|
1130 | + if ($obj instanceof EE_CPT_Base) { |
|
1131 | + $status_obj = get_post_status_object($obj->status()); |
|
1132 | + if ($status_obj->public) { |
|
1133 | + $caps[] = $cap; |
|
1134 | + return $caps; |
|
1135 | + } |
|
1136 | + //if the item author is set and the user is the author... |
|
1137 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1138 | + $caps[] = $cap; |
|
1139 | + } elseif ($status_obj->private && ! empty($this->private_cap)) { |
|
1140 | + //the user is trying to view someone else's obj |
|
1141 | + $caps[] = $this->private_cap; |
|
1142 | + } elseif (! empty($this->others_cap)) { |
|
1143 | + $caps[] = $this->others_cap; |
|
1144 | + } else { |
|
1145 | + $caps[] = $cap; |
|
1146 | + } |
|
1147 | + } else { |
|
1148 | + //not a cpt object so handled differently |
|
1149 | + $has_cap = false; |
|
1150 | + try { |
|
1151 | + $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $obj->wp_user() === $user_id; |
|
1152 | + } catch (Exception $e) { |
|
1153 | + if (WP_DEBUG) { |
|
1154 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1155 | + } |
|
1156 | + } |
|
1157 | + if ($has_cap) { |
|
1158 | + $caps[] = $cap; |
|
1159 | + } elseif (! empty($this->private_cap)) { |
|
1160 | + $caps[] = $this->private_cap; |
|
1161 | + } elseif (! empty($this->others_cap)) { |
|
1162 | + $caps[] = $this->others_cap; |
|
1163 | + } else { |
|
1164 | + $caps[] = $cap; |
|
1165 | + } |
|
1166 | + } |
|
1167 | + return $caps; |
|
1168 | + } |
|
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | |
@@ -1182,50 +1182,50 @@ discard block |
||
1182 | 1182 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
1183 | 1183 | { |
1184 | 1184 | |
1185 | - /** |
|
1186 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1187 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1188 | - * |
|
1189 | - * @since 4.5.0 |
|
1190 | - * @see wp-includes/capabilities.php |
|
1191 | - * @param array $caps actual users capabilities |
|
1192 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1193 | - * @param int $user_id The user id |
|
1194 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1195 | - * @return array actual users capabilities |
|
1196 | - */ |
|
1197 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1198 | - { |
|
1199 | - //only process if we're checking our mapped_cap |
|
1200 | - if ($cap !== $this->meta_cap) { |
|
1201 | - return $caps; |
|
1202 | - } |
|
1203 | - |
|
1204 | - //cast $user_id to int for later explicit comparisons |
|
1205 | - $user_id = (int) $user_id; |
|
1206 | - |
|
1207 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1208 | - //if no obj then let's just do cap |
|
1209 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
1210 | - $caps[] = $cap; |
|
1211 | - return $caps; |
|
1212 | - } |
|
1213 | - $is_global = $obj->is_global(); |
|
1214 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1215 | - if ($is_global) { |
|
1216 | - $caps[] = $this->private_cap; |
|
1217 | - } else { |
|
1218 | - $caps[] = $cap; |
|
1219 | - } |
|
1220 | - } else { |
|
1221 | - if ($is_global) { |
|
1222 | - $caps[] = $this->private_cap; |
|
1223 | - } else { |
|
1224 | - $caps[] = $this->others_cap; |
|
1225 | - } |
|
1226 | - } |
|
1227 | - return $caps; |
|
1228 | - } |
|
1185 | + /** |
|
1186 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1187 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1188 | + * |
|
1189 | + * @since 4.5.0 |
|
1190 | + * @see wp-includes/capabilities.php |
|
1191 | + * @param array $caps actual users capabilities |
|
1192 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1193 | + * @param int $user_id The user id |
|
1194 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1195 | + * @return array actual users capabilities |
|
1196 | + */ |
|
1197 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1198 | + { |
|
1199 | + //only process if we're checking our mapped_cap |
|
1200 | + if ($cap !== $this->meta_cap) { |
|
1201 | + return $caps; |
|
1202 | + } |
|
1203 | + |
|
1204 | + //cast $user_id to int for later explicit comparisons |
|
1205 | + $user_id = (int) $user_id; |
|
1206 | + |
|
1207 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1208 | + //if no obj then let's just do cap |
|
1209 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
1210 | + $caps[] = $cap; |
|
1211 | + return $caps; |
|
1212 | + } |
|
1213 | + $is_global = $obj->is_global(); |
|
1214 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1215 | + if ($is_global) { |
|
1216 | + $caps[] = $this->private_cap; |
|
1217 | + } else { |
|
1218 | + $caps[] = $cap; |
|
1219 | + } |
|
1220 | + } else { |
|
1221 | + if ($is_global) { |
|
1222 | + $caps[] = $this->private_cap; |
|
1223 | + } else { |
|
1224 | + $caps[] = $this->others_cap; |
|
1225 | + } |
|
1226 | + } |
|
1227 | + return $caps; |
|
1228 | + } |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | |
@@ -1242,39 +1242,39 @@ discard block |
||
1242 | 1242 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
1243 | 1243 | { |
1244 | 1244 | |
1245 | - /** |
|
1246 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1247 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1248 | - * |
|
1249 | - * @since 4.5.0 |
|
1250 | - * @see wp-includes/capabilities.php |
|
1251 | - * @param array $caps actual users capabilities |
|
1252 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1253 | - * @param int $user_id The user id |
|
1254 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1255 | - * @return array actual users capabilities |
|
1256 | - */ |
|
1257 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1258 | - { |
|
1259 | - //only process if we're checking our mapped_cap |
|
1260 | - if ($cap !== $this->meta_cap) { |
|
1261 | - return $caps; |
|
1262 | - } |
|
1263 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1264 | - //if no obj then let's just do cap |
|
1265 | - if (! $obj instanceof EE_Base_Class) { |
|
1266 | - $caps[] = $cap; |
|
1267 | - return $caps; |
|
1268 | - } |
|
1269 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1270 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1271 | - if ($is_system) { |
|
1272 | - $caps[] = $this->private_cap; |
|
1273 | - } else { |
|
1274 | - $caps[] = $cap; |
|
1275 | - } |
|
1276 | - return $caps; |
|
1277 | - } |
|
1245 | + /** |
|
1246 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1247 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1248 | + * |
|
1249 | + * @since 4.5.0 |
|
1250 | + * @see wp-includes/capabilities.php |
|
1251 | + * @param array $caps actual users capabilities |
|
1252 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1253 | + * @param int $user_id The user id |
|
1254 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1255 | + * @return array actual users capabilities |
|
1256 | + */ |
|
1257 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1258 | + { |
|
1259 | + //only process if we're checking our mapped_cap |
|
1260 | + if ($cap !== $this->meta_cap) { |
|
1261 | + return $caps; |
|
1262 | + } |
|
1263 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1264 | + //if no obj then let's just do cap |
|
1265 | + if (! $obj instanceof EE_Base_Class) { |
|
1266 | + $caps[] = $cap; |
|
1267 | + return $caps; |
|
1268 | + } |
|
1269 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1270 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1271 | + if ($is_system) { |
|
1272 | + $caps[] = $this->private_cap; |
|
1273 | + } else { |
|
1274 | + $caps[] = $cap; |
|
1275 | + } |
|
1276 | + return $caps; |
|
1277 | + } |
|
1278 | 1278 | |
1279 | 1279 | |
1280 | 1280 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public static function instance() |
56 | 56 | { |
57 | 57 | //check if instantiated, and if not do so. |
58 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
58 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
59 | 59 | self::$_instance = new self(); |
60 | 60 | } |
61 | 61 | return self::$_instance; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $this->_meta_caps = $this->_get_default_meta_caps_array(); |
120 | 120 | $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps); |
121 | 121 | //add filter for map_meta_caps but only if models can query. |
122 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
122 | + if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
123 | 123 | add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
124 | 124 | } |
125 | 125 | } |
@@ -275,10 +275,10 @@ discard block |
||
275 | 275 | if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
276 | 276 | //loop through our _meta_caps array |
277 | 277 | foreach ($this->_meta_caps as $meta_map) { |
278 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
278 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
279 | 279 | continue; |
280 | 280 | } |
281 | - if(!empty($args[0])){ |
|
281 | + if ( ! empty($args[0])) { |
|
282 | 282 | $meta_map->ensure_is_model(); |
283 | 283 | } |
284 | 284 | $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
@@ -651,9 +651,9 @@ discard block |
||
651 | 651 | foreach ($caps_map as $role => $caps_for_role) { |
652 | 652 | foreach ($caps_for_role as $cap) { |
653 | 653 | //first check we haven't already added this cap before, or it's a reset |
654 | - if ($reset || ! isset($caps_set_before[ $role ]) || ! in_array($cap, $caps_set_before[ $role ])) { |
|
654 | + if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) { |
|
655 | 655 | if ($this->add_cap_to_role($role, $cap)) { |
656 | - $caps_set_before[ $role ][] = $cap; |
|
656 | + $caps_set_before[$role][] = $cap; |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | } |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | { |
681 | 681 | $role_object = get_role($role); |
682 | 682 | //if the role isn't available then we create it. |
683 | - if (! $role_object instanceof WP_Role) { |
|
683 | + if ( ! $role_object instanceof WP_Role) { |
|
684 | 684 | //if a plugin wants to create a specific role name then they should create the role before |
685 | 685 | //EE_Capabilities does. Otherwise this function will create the role name from the slug: |
686 | 686 | // - removes any `ee_` namespacing from the start of the slug. |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | public function current_user_can($cap, $context, $id = 0) |
734 | 734 | { |
735 | 735 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
736 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
736 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
737 | 737 | $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
738 | 738 | $id); |
739 | 739 | return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap); |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | public function user_can($user, $cap, $context, $id = 0) |
754 | 754 | { |
755 | 755 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
756 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
756 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
757 | 757 | $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
758 | 758 | $id); |
759 | 759 | return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap); |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | : current_user_can($blog_id, $cap); |
783 | 783 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
784 | 784 | $user_can = apply_filters( |
785 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
785 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, |
|
786 | 786 | $user_can, |
787 | 787 | $blog_id, |
788 | 788 | $cap, |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | if (empty($role)) { |
817 | 817 | return $capabilities; |
818 | 818 | } |
819 | - return isset($capabilities[ $role ]) ? $capabilities[ $role ] : array(); |
|
819 | + return isset($capabilities[$role]) ? $capabilities[$role] : array(); |
|
820 | 820 | } |
821 | 821 | } |
822 | 822 | |
@@ -880,16 +880,16 @@ discard block |
||
880 | 880 | 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
881 | 881 | 'event_espresso' |
882 | 882 | ), |
883 | - '<br>' . print_r($map_values, true) |
|
883 | + '<br>'.print_r($map_values, true) |
|
884 | 884 | ) |
885 | 885 | ); |
886 | 886 | } |
887 | 887 | //set properties |
888 | 888 | $this->_model = null; |
889 | 889 | $this->_model_name = $map_values[0]; |
890 | - $this->published_cap = (string)$map_values[1]; |
|
891 | - $this->others_cap = (string)$map_values[2]; |
|
892 | - $this->private_cap = (string)$map_values[3]; |
|
890 | + $this->published_cap = (string) $map_values[1]; |
|
891 | + $this->others_cap = (string) $map_values[2]; |
|
892 | + $this->private_cap = (string) $map_values[3]; |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -915,11 +915,11 @@ discard block |
||
915 | 915 | return; |
916 | 916 | } |
917 | 917 | //ensure model name is string |
918 | - $this->_model_name = (string)$this->_model_name; |
|
918 | + $this->_model_name = (string) $this->_model_name; |
|
919 | 919 | //error proof if the name has EEM in it |
920 | 920 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
921 | 921 | $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
922 | - if (! $this->_model instanceof EEM_Base) { |
|
922 | + if ( ! $this->_model instanceof EEM_Base) { |
|
923 | 923 | throw new EE_Error( |
924 | 924 | sprintf( |
925 | 925 | __( |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | /** @var EE_Base_Class $obj */ |
1003 | 1003 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1004 | 1004 | //if no obj then let's just do cap |
1005 | - if (! $obj instanceof EE_Base_Class) { |
|
1005 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1006 | 1006 | $caps[] = $cap; |
1007 | 1007 | return $caps; |
1008 | 1008 | } |
@@ -1021,12 +1021,12 @@ discard block |
||
1021 | 1021 | } |
1022 | 1022 | } else { |
1023 | 1023 | //the user is trying to edit someone else's obj |
1024 | - if (! empty($this->others_cap)) { |
|
1024 | + if ( ! empty($this->others_cap)) { |
|
1025 | 1025 | $caps[] = $this->others_cap; |
1026 | 1026 | } |
1027 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1027 | + if ( ! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1028 | 1028 | $caps[] = $this->published_cap; |
1029 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1029 | + } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') { |
|
1030 | 1030 | $caps[] = $this->private_cap; |
1031 | 1031 | } |
1032 | 1032 | } |
@@ -1045,7 +1045,7 @@ discard block |
||
1045 | 1045 | if ($has_cap) { |
1046 | 1046 | $caps[] = $cap; |
1047 | 1047 | } else { |
1048 | - if (! empty($this->others_cap)) { |
|
1048 | + if ( ! empty($this->others_cap)) { |
|
1049 | 1049 | $caps[] = $this->others_cap; |
1050 | 1050 | } |
1051 | 1051 | } |
@@ -1123,7 +1123,7 @@ discard block |
||
1123 | 1123 | |
1124 | 1124 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1125 | 1125 | //if no obj then let's just do cap |
1126 | - if (! $obj instanceof EE_Base_Class) { |
|
1126 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1127 | 1127 | $caps[] = $cap; |
1128 | 1128 | return $caps; |
1129 | 1129 | } |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | } elseif ($status_obj->private && ! empty($this->private_cap)) { |
1140 | 1140 | //the user is trying to view someone else's obj |
1141 | 1141 | $caps[] = $this->private_cap; |
1142 | - } elseif (! empty($this->others_cap)) { |
|
1142 | + } elseif ( ! empty($this->others_cap)) { |
|
1143 | 1143 | $caps[] = $this->others_cap; |
1144 | 1144 | } else { |
1145 | 1145 | $caps[] = $cap; |
@@ -1156,9 +1156,9 @@ discard block |
||
1156 | 1156 | } |
1157 | 1157 | if ($has_cap) { |
1158 | 1158 | $caps[] = $cap; |
1159 | - } elseif (! empty($this->private_cap)) { |
|
1159 | + } elseif ( ! empty($this->private_cap)) { |
|
1160 | 1160 | $caps[] = $this->private_cap; |
1161 | - } elseif (! empty($this->others_cap)) { |
|
1161 | + } elseif ( ! empty($this->others_cap)) { |
|
1162 | 1162 | $caps[] = $this->others_cap; |
1163 | 1163 | } else { |
1164 | 1164 | $caps[] = $cap; |
@@ -1206,7 +1206,7 @@ discard block |
||
1206 | 1206 | |
1207 | 1207 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1208 | 1208 | //if no obj then let's just do cap |
1209 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
1209 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
1210 | 1210 | $caps[] = $cap; |
1211 | 1211 | return $caps; |
1212 | 1212 | } |
@@ -1262,7 +1262,7 @@ discard block |
||
1262 | 1262 | } |
1263 | 1263 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1264 | 1264 | //if no obj then let's just do cap |
1265 | - if (! $obj instanceof EE_Base_Class) { |
|
1265 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1266 | 1266 | $caps[] = $cap; |
1267 | 1267 | return $caps; |
1268 | 1268 | } |