PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
bbpress / includes / users / capabilities.php

capabilities.php in bbPress 2.6.6, at includes/users/capabilities.php

861 lines 20.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress User Capabilites
5 *
6 * Used to map user capabilities to WordPress's existing capabilities.
7 *
8 * @package bbPress
9 * @subpackage Capabilities
10 */
11
12 /**
13 * Maps primary capabilities
14 *
15 * @since 2.2.0 bbPress (r4242)
16 *
17 * @param array $caps Capabilities for meta capability.
18 * @param string $cap Capability name.
19 * @param int $user_id User id.
20 * @param array $args Arguments.
21 *
22 * @return array Actual capabilities for meta capability
23 */
24 function bbp_map_primary_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
25
26 // What capability is being checked?
27 switch ( $cap ) {
28 case 'spectate' :
29
30 // Do not allow inactive users.
31 if ( bbp_is_user_inactive( $user_id ) ) {
32 $caps = array( 'do_not_allow' );
33
34 // Default to the current cap.
35 } else {
36 $caps = array( $cap );
37 }
38 break;
39
40 case 'participate' :
41
42 // Do not allow inactive users.
43 if ( bbp_is_user_inactive( $user_id ) ) {
44 $caps = array( 'do_not_allow' );
45
46 // Default to the current cap.
47 } else {
48 $caps = array( $cap );
49 }
50 break;
51
52 case 'moderate' :
53
54 // Do not allow inactive users.
55 if ( bbp_is_user_inactive( $user_id ) ) {
56 $caps = array( 'do_not_allow' );
57
58 // Keymasters can always moderate.
59 } elseif ( bbp_is_user_keymaster( $user_id ) ) {
60 $caps = array( 'spectate' );
61
62 // Check if user can moderate forum.
63 } elseif ( bbp_allow_forum_mods() ) {
64 $caps = array( $cap );
65
66 // Bail if no post to check.
67 if ( empty( $args[0] ) ) {
68 break;
69 }
70
71 // Get the post.
72 $_post = get_post( $args[0] );
73 if ( empty( $_post ) ) {
74 break;
75 }
76
77 // Get forum ID for specific type of post.
78 switch ( $_post->post_type ) {
79
80 // Forum.
81 case bbp_get_forum_post_type() :
82 $forum_id = bbp_get_forum_id( $_post->ID );
83 break;
84
85 // Topic.
86 case bbp_get_topic_post_type() :
87 $forum_id = bbp_get_topic_forum_id( $_post->ID );
88 break;
89
90 // Reply.
91 case bbp_get_reply_post_type() :
92 $forum_id = bbp_get_reply_forum_id( $_post->ID );
93 break;
94
95 // Any other post type defaults to 0.
96 default :
97 $forum_id = 0;
98 break;
99 }
100
101 // Bail if no forum ID.
102 if ( empty( $forum_id ) ) {
103 break;
104 }
105
106 // User is mod of this forum
107 if ( bbp_is_object_of_user( $forum_id, $user_id, '_bbp_moderator_id' ) ) {
108 $caps = array( 'spectate' );
109 }
110 }
111
112 break;
113
114 /** Super Moderators **************************************************/
115
116 case 'edit_user' :
117 case 'edit_users' :
118
119 // Moderators can edit users if super moderators is enabled
120 if ( bbp_allow_super_mods() ) {
121
122 // Get the user ID
123 $_user_id = ! empty( $args[0] )
124 ? (int) $args[0]
125 : bbp_get_displayed_user_id();
126
127 // Users can always edit themselves, so only map for others
128 if ( ! empty( $_user_id ) && ( $_user_id !== $user_id ) ) {
129
130 // Super moderators cannot edit keymasters
131 if ( ! bbp_is_user_keymaster( $_user_id ) ) {
132 $caps = array( 'moderate' );
133 }
134 }
135 }
136
137 break;
138 }
139
140 // Filter & return
141 return (array) apply_filters( 'bbp_map_primary_meta_caps', $caps, $cap, $user_id, $args );
142 }
143
144 /**
145 * Set a user's role in the forums
146 *
147 * @since 2.1.0 bbPress (r3860)
148 *
149 * @param int $user_id
150 *
151 * @return mixed False if no change. String of new role if changed.
152 */
153 function bbp_set_user_role( $user_id = 0, $new_role = '' ) {
154
155 // Validate user id
156 $user_id = bbp_get_user_id( $user_id, false, false );
157 $user = get_userdata( $user_id );
158
159 // User exists
160 if ( ! empty( $user ) ) {
161
162 // Get user forum role
163 $role = bbp_get_user_role( $user_id );
164
165 // User already has this role so no new role is set
166 if ( $new_role === $role ) {
167 $new_role = false;
168
169 // User role is different than the new (valid) role
170 } elseif ( bbp_is_valid_role( $new_role ) ) {
171
172 // Remove the old role
173 if ( ! empty( $role ) ) {
174 $user->remove_role( $role );
175 }
176
177 // Add the new role
178 if ( ! empty( $new_role ) ) {
179 $user->add_role( $new_role );
180 }
181 }
182
183 // User does don exist so return false
184 } else {
185 $new_role = false;
186 }
187
188 // Filter & return
189 return apply_filters( 'bbp_set_user_role', $new_role, $user_id, $user );
190 }
191
192 /**
193 * Return a user's forums role
194 *
195 * @since 2.1.0 bbPress (r3860)
196 *
197 * @param int $user_id
198 *
199 * @return string
200 */
201 function bbp_get_user_role( $user_id = 0 ) {
202
203 // Validate user id
204 $user_id = bbp_get_user_id( $user_id );
205 $user = get_userdata( $user_id );
206 $role = false;
207
208 // User has roles so look for a bbPress one
209 if ( ! empty( $user->roles ) ) {
210
211 // Look for a bbPress role
212 $roles = array_intersect(
213 array_values( $user->roles ),
214 array_keys( bbp_get_dynamic_roles() )
215 );
216
217 // If there's a role in the array, use the first one. This isn't very
218 // smart, but since roles aren't exactly hierarchical, and bbPress
219 // does not yet have a UI for multiple user roles, it's fine for now.
220 if ( ! empty( $roles ) ) {
221 $role = array_shift( $roles );
222 }
223 }
224
225 // Filter & return
226 return apply_filters( 'bbp_get_user_role', $role, $user_id, $user );
227 }
228
229 /**
230 * Return a user's blog role
231 *
232 * @since 2.3.0 bbPress (r4446)
233 *
234 * @param int $user_id
235 *
236 * @return string
237 */
238 function bbp_get_user_blog_role( $user_id = 0 ) {
239
240 // Validate user id
241 $user_id = bbp_get_user_id( $user_id );
242 $user = get_userdata( $user_id );
243 $role = false;
244
245 // User has roles so lets
246 if ( ! empty( $user->roles ) ) {
247
248 // Look for a non bbPress role
249 $roles = array_intersect(
250 array_values( $user->roles ),
251 array_keys( bbp_get_blog_roles() )
252 );
253
254 // If there's a role in the array, use the first one. This isn't very
255 // smart, but since roles aren't exactly hierarchical, and WordPress
256 // does not yet have a UI for multiple user roles, it's fine for now.
257 if ( ! empty( $roles ) ) {
258 $role = array_shift( $roles );
259 }
260 }
261
262 // Filter & return
263 return apply_filters( 'bbp_get_user_blog_role', $role, $user_id, $user );
264 }
265
266 /**
267 * Helper function hooked to 'bbp_profile_update' action to save or
268 * update user roles and capabilities.
269 *
270 * @since 2.2.0 bbPress (r4235)
271 *
272 * @param int $user_id
273 */
274 function bbp_profile_update_role( $user_id = 0 ) {
275
276 // Bail if no user ID was passed
277 if ( empty( $user_id ) ) {
278 return;
279 }
280
281 // Bail if no role
282 if ( ! isset( $_POST['bbp-forums-role'] ) ) {
283 return;
284 }
285
286 // Forums role we want the user to have
287 $new_role = sanitize_key( $_POST['bbp-forums-role'] );
288 $forums_role = bbp_get_user_role( $user_id );
289
290 // Bail if no role change
291 if ( $new_role === $forums_role ) {
292 return;
293 }
294
295 // Bail if trying to set their own role
296 if ( bbp_is_user_home_edit() ) {
297 return;
298 }
299
300 // Bail if current user cannot promote the passing user
301 if ( ! current_user_can( 'promote_user', $user_id ) ) {
302 return;
303 }
304
305 // Set the new forums role
306 bbp_set_user_role( $user_id, $new_role );
307 }
308
309 /**
310 * Check if a role string is valid
311 *
312 * @since 2.6.5
313 *
314 * @param string $role
315 *
316 * @return bool True if role is valid. False if role is not valid.
317 */
318 function bbp_is_valid_role( $role = '' ) {
319
320 // Default return value
321 $retval = false;
322
323 // Skip if no role to check
324 if ( ! empty( $role ) && is_string( $role ) ) {
325
326 // Get the dynamic role IDs
327 $roles = array_keys( bbp_get_dynamic_roles() );
328
329 // Skip if no known role IDs
330 if ( ! empty( $roles ) ) {
331
332 // Is role in dynamic roles array?
333 $retval = in_array( $role, $roles, true );
334 }
335 }
336
337 // Filter & return
338 return (bool) apply_filters( 'bbp_is_valid_role', $retval, $role );
339 }
340
341 /**
342 * Add the default role to the current user if needed
343 *
344 * This function will bail if the forum is not global in a multisite
345 * installation of WordPress, or if the user is marked as spam or deleted.
346 *
347 * @since 2.0.0 bbPress (r3380)
348 *
349 * @return If not multisite, not global, or user is deleted/spammed
350 */
351 function bbp_set_current_user_default_role() {
352
353 /** Sanity ****************************************************************/
354
355 // Bail if deactivating bbPress
356 if ( bbp_is_deactivation() ) {
357 return;
358 }
359
360 // Catch all, to prevent premature user initialization
361 if ( ! did_action( 'set_current_user' ) ) {
362 return;
363 }
364
365 // Bail if not logged in or already a member of this site
366 if ( ! is_user_logged_in() ) {
367 return;
368 }
369
370 // Get the current user ID
371 $user_id = bbp_get_current_user_id();
372
373 // Bail if user already has a forums role
374 if ( bbp_get_user_role( $user_id ) ) {
375 return;
376 }
377
378 // Bail if user is marked as spam or is deleted
379 if ( bbp_is_user_inactive( $user_id ) ) {
380 return;
381 }
382
383 /** Ready *****************************************************************/
384
385 // Load up bbPress once
386 $bbp = bbpress();
387
388 // Get whether or not to add a role to the user account
389 $add_to_site = bbp_allow_global_access();
390
391 // Get the current user's WordPress role. Set to empty string if none found.
392 $user_role = bbp_get_user_blog_role( $user_id );
393
394 // Get the role map
395 $role_map = bbp_get_user_role_map();
396
397 /** Forum Role ************************************************************/
398
399 // Use a mapped role or default role
400 $new_role = empty( $user_role ) || ! isset( $role_map[ $user_role ] )
401 ? bbp_get_default_role()
402 : $role_map[ $user_role ];
403
404 /** Add or Map ************************************************************/
405
406 // Add the user to the site
407 if ( true === $add_to_site ) {
408 bbp_set_user_role( $user_id, $new_role );
409
410 // Don't add the user, but still give them the correct caps dynamically
411 } else {
412 $bbp->current_user->caps[ $new_role ] = true;
413 $bbp->current_user->get_role_caps();
414 }
415 }
416
417 /**
418 * Return a map of WordPress roles to bbPress roles. Used to automatically grant
419 * appropriate bbPress roles to WordPress users that wouldn't already have a
420 * role in the forums. Also guarantees WordPress admins get the Keymaster role.
421 *
422 * @since 2.2.0 bbPress (r4334)
423 *
424 * @return array Filtered array of WordPress roles to bbPress roles
425 */
426 function bbp_get_user_role_map() {
427
428 // Get the default role once here
429 $default_role = bbp_get_default_role();
430
431 // Filter & return
432 return (array) apply_filters( 'bbp_get_user_role_map', array(
433 'administrator' => bbp_get_keymaster_role(),
434 'editor' => $default_role,
435 'author' => $default_role,
436 'contributor' => $default_role,
437 'subscriber' => $default_role
438 ) );
439 }
440
441 /** User Status ***************************************************************/
442
443 /**
444 * Checks if the user has been marked as a spammer.
445 *
446 * @since 2.0.0 bbPress (r3355)
447 *
448 * @param int $user_id int The ID for the user.
449 * @return bool True if spammer, False if not.
450 */
451 function bbp_is_user_spammer( $user_id = 0 ) {
452
453 // Default to current user
454 if ( empty( $user_id ) && is_user_logged_in() ) {
455 $user_id = bbp_get_current_user_id();
456 }
457
458 // No user to check
459 if ( empty( $user_id ) ) {
460 return false;
461 }
462
463 // Assume user is not spam
464 $is_spammer = false;
465
466 // Get user data
467 $user = get_userdata( $user_id );
468
469 // No user found
470 if ( empty( $user ) ) {
471 $is_spammer = false;
472
473 // Check if spam
474 } elseif ( ! empty( $user->spam ) ) {
475 $is_spammer = true;
476 }
477
478 // Filter & return
479 return (bool) apply_filters( 'bbp_core_is_user_spammer', $is_spammer );
480 }
481
482 /**
483 * Mark a users topics and replies as spam when the user is marked as spam
484 *
485 * @since 2.0.0 bbPress (r3405)
486 *
487 * @param int $user_id Optional. User ID to spam. Defaults to displayed user.
488 *
489 * @return bool If no user ID passed.
490 */
491 function bbp_make_spam_user( $user_id = 0 ) {
492
493 // Use displayed user if it's not yourself
494 if ( empty( $user_id ) && bbp_is_single_user() && ! bbp_is_user_home() ) {
495 $user_id = bbp_get_displayed_user_id();
496 }
497
498 // Bail if no user ID
499 if ( empty( $user_id ) ) {
500 return false;
501 }
502
503 // Bail if user ID is keymaster
504 if ( bbp_is_user_keymaster( $user_id ) ) {
505 return false;
506 }
507
508 // Arm the torpedos
509 $bbp_db = bbp_db();
510
511 // Get the blog IDs of the user to mark as spam
512 $blogs = get_blogs_of_user( $user_id, true );
513
514 // If user has no blogs, they are a guest on this site
515 if ( empty( $blogs ) ) {
516 $blogs[ $bbp_db->blogid ] = array();
517 }
518
519 // Get array of post types to mark as spam
520 $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
521 $post_types = "'" . implode( "', '", $post_types ) . "'";
522
523 // Get array of statuses to mark as spam
524 $post_statuses = bbp_get_public_topic_statuses();
525 $post_statuses = "'" . implode( "', '", $post_statuses ) . "'";
526
527 // Loop through blogs and remove their posts
528 foreach ( (array) array_keys( $blogs ) as $blog_id ) {
529
530 // Switch to the site ID
531 bbp_switch_to_site( $blog_id );
532
533 // Get topics and replies
534 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status IN ( {$post_statuses} ) AND post_type IN ( {$post_types} )", $user_id );
535 $posts = $bbp_db->get_col( $query );
536
537 // Loop through posts and spam them
538 if ( ! empty( $posts ) ) {
539 foreach ( $posts as $post_id ) {
540
541 // The routines for topics ang replies are different, so use the
542 // correct one based on the post type
543 switch ( get_post_type( $post_id ) ) {
544
545 case bbp_get_topic_post_type() :
546 bbp_spam_topic( $post_id );
547 break;
548
549 case bbp_get_reply_post_type() :
550 bbp_spam_reply( $post_id );
551 break;
552 }
553 }
554 }
555
556 // Switch back to current site
557 bbp_restore_current_site();
558 }
559
560 // Delete user options
561 bbp_delete_user_options( $user_id );
562
563 // Success
564 return true;
565 }
566
567 /**
568 * Mark a users topics and replies as spam when the user is marked as spam
569 *
570 * @since 2.0.0 bbPress (r3405)
571 *
572 * @param int $user_id Optional. User ID to unspam. Defaults to displayed user.
573 *
574 * @return bool If no user ID passed.
575 */
576 function bbp_make_ham_user( $user_id = 0 ) {
577
578 // Use displayed user if it's not yourself
579 if ( empty( $user_id ) && bbp_is_single_user() && ! bbp_is_user_home() ) {
580 $user_id = bbp_get_displayed_user_id();
581 }
582
583 // Bail if no user ID
584 if ( empty( $user_id ) ) {
585 return false;
586 }
587
588 // Bail if user ID is keymaster
589 if ( bbp_is_user_keymaster( $user_id ) ) {
590 return false;
591 }
592
593 // Arm the torpedos
594 $bbp_db = bbp_db();
595
596 // Get the blog IDs of the user to mark as spam
597 $blogs = get_blogs_of_user( $user_id, true );
598
599 // If user has no blogs, they are a guest on this site
600 if ( empty( $blogs ) ) {
601 $blogs[ $bbp_db->blogid ] = array();
602 }
603
604 // Get array of post types to mark as spam
605 $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
606 $post_types = "'" . implode( "', '", $post_types ) . "'";
607
608 // Get array of statuses to unmark as spam
609 $post_statuses = array( bbp_get_spam_status_id() );
610 $post_statuses = "'" . implode( "', '", $post_statuses ) . "'";
611
612 // Loop through blogs and remove their posts
613 foreach ( (array) array_keys( $blogs ) as $blog_id ) {
614
615 // Switch to the site ID
616 bbp_switch_to_site( $blog_id );
617
618 // Get topics and replies
619 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status IN ( {$post_statuses} ) AND post_type IN ( {$post_types} )", $user_id );
620 $posts = $bbp_db->get_col( $query );
621
622 // Loop through posts and spam them
623 if ( ! empty( $posts ) ) {
624 foreach ( $posts as $post_id ) {
625
626 // The routines for topics ang replies are different, so use the
627 // correct one based on the post type
628 switch ( get_post_type( $post_id ) ) {
629
630 case bbp_get_topic_post_type() :
631 bbp_unspam_topic( $post_id );
632 break;
633
634 case bbp_get_reply_post_type() :
635 bbp_unspam_reply( $post_id );
636 break;
637 }
638 }
639 }
640
641 // Switch back to current site
642 bbp_restore_current_site();
643 }
644
645 // Update topic & reply counts
646 bbp_update_user_topic_count( $user_id, bbp_get_user_topic_count_raw( $user_id ) );
647 bbp_update_user_reply_count( $user_id, bbp_get_user_reply_count_raw( $user_id ) );
648
649 // Update last posted (to now)
650 bbp_update_user_last_posted( $user_id );
651
652 // Success
653 return true;
654 }
655
656 /**
657 * Checks if the user has been marked as deleted.
658 *
659 * @since 2.0.0 bbPress (r3355)
660 *
661 * @param int $user_id int The ID for the user.
662 * @return bool True if deleted, False if not.
663 */
664 function bbp_is_user_deleted( $user_id = 0 ) {
665
666 // Default to current user
667 if ( empty( $user_id ) && is_user_logged_in() ) {
668 $user_id = bbp_get_current_user_id();
669 }
670
671 // No user to check
672 if ( empty( $user_id ) ) {
673 return false;
674 }
675
676 // Assume user is not deleted
677 $is_deleted = false;
678
679 // Get user data
680 $user = get_userdata( $user_id );
681
682 // No user found
683 if ( empty( $user ) ) {
684 $is_deleted = true;
685
686 // Check if deleted
687 } elseif ( ! empty( $user->deleted ) ) {
688 $is_deleted = true;
689 }
690
691 // Filter & return
692 return (bool) apply_filters( 'bbp_core_is_user_deleted', $is_deleted );
693 }
694
695 /**
696 * Checks if user is active
697 *
698 * @since 2.0.0 bbPress (r3502)
699 *
700 * @param int $user_id The user ID to check
701 * @return bool True if public, false if not
702 */
703 function bbp_is_user_active( $user_id = 0 ) {
704
705 // No user to check
706 $user_id = bbp_get_user_id( $user_id, false, true );
707 if ( empty( $user_id ) ) {
708 return false;
709 }
710
711 // Check spam
712 if ( bbp_is_user_spammer( $user_id ) ) {
713 return false;
714 }
715
716 // Check deleted
717 if ( bbp_is_user_deleted( $user_id ) ) {
718 return false;
719 }
720
721 // Assume true if not spam or deleted
722 return true;
723 }
724
725 /**
726 * Checks if user is not active.
727 *
728 * @since 2.0.0 bbPress (r3502)
729 *
730 * @param int $user_id The user ID to check. Defaults to current user ID
731 * @return bool True if inactive, false if active
732 */
733 function bbp_is_user_inactive( $user_id = 0 ) {
734 return ! bbp_is_user_active( $user_id );
735 }
736
737 /**
738 * Checks if user is a keymaster
739 *
740 * @since 2.3.0 bbPress (r4783)
741 *
742 * @param int $user_id
743 * @return bool True if keymaster, false if not
744 */
745 function bbp_is_user_keymaster( $user_id = 0 ) {
746 $_user_id = bbp_get_user_id( $user_id, false, true );
747 $retval = user_can( $_user_id, 'keep_gate' );
748
749 // Filter & return
750 return (bool) apply_filters( 'bbp_is_user_keymaster', $retval, $_user_id, $user_id );
751 }
752
753 /**
754 * Does a user have a profile for the current site
755 *
756 * @since 2.2.0 bbPress (r4362)
757 *
758 * @param int $user_id User ID to check
759 *
760 * @return bool Whether or not the user has a profile on this blog_id.
761 */
762 function bbp_user_has_profile( $user_id = 0 ) {
763
764 // Assume every user has a profile
765 $retval = true;
766
767 // Validate user ID, default to displayed or current user
768 $user_id = bbp_get_user_id( $user_id, true, true );
769
770 // Try to get this user's data
771 $user = get_userdata( $user_id );
772
773 // No user found, return false
774 if ( empty( $user ) ) {
775 $retval = false;
776
777 // User is inactive, and current user is not a keymaster
778 } elseif ( ! bbp_is_user_keymaster() && bbp_is_user_inactive( $user->ID ) ) {
779 $retval = false;
780 }
781
782 // Filter & return
783 return (bool) apply_filters( 'bbp_show_user_profile', $retval, $user_id );
784 }
785
786 /** Moderators ****************************************************************/
787
788 /**
789 * Add a moderator to an object
790 *
791 * @since 2.6.0 bbPress (r6056)
792 *
793 * @param int $object_id Traditionally a post ID
794 * @param int $user_id User ID
795 * @param string $object_type Type of meta (post,term,user,comment)
796 *
797 * @return bool
798 */
799 function bbp_add_moderator( $object_id = 0, $user_id = 0, $object_type = 'post' ) {
800 return bbp_add_user_to_object( $object_id, $user_id, '_bbp_moderator_id', $object_type );
801 }
802
803 /**
804 * Remove a moderator user ID from an object
805 *
806 * @since 2.6.0 bbPress (r6056)
807 *
808 * @param int $object_id Traditionally a post ID
809 * @param int $user_id User ID
810 * @param string $object_type Type of meta (post,term,user,comment)
811 *
812 * @return bool
813 */
814 function bbp_remove_moderator( $object_id = 0, $user_id = 0, $object_type = 'post' ) {
815 return bbp_remove_user_from_object( $object_id, $user_id, '_bbp_moderator_id', $object_type );
816 }
817
818 /**
819 * Get user IDs of moderators for an object
820 *
821 * @since 2.6.0 bbPress (r6056)
822 *
823 * @param int $object_id Traditionally a post ID
824 * @param string $object_type Type of meta (post,term,user,comment)
825 *
826 * @return array
827 */
828 function bbp_get_moderator_ids( $object_id = 0, $object_type = 'post' ) {
829 return bbp_get_users_for_object( $object_id, '_bbp_moderator_id', $object_type );
830 }
831
832 /**
833 * Get moderators for a specific object ID. Will return global moderators when
834 * object ID is empty.
835 *
836 * @since 2.6.0 bbPress (r6056)
837 *
838 * @param int $object_id Traditionally a post ID
839 * @param string $object_type Type of meta (post,term,user,comment)
840 *
841 * @return array
842 */
843 function bbp_get_moderators( $object_id = 0, $object_type = 'post' ) {
844
845 // Get global moderators
846 if ( empty( $object_id ) ) {
847 $users = get_users( array(
848 'role__in' => bbp_get_moderator_role(),
849 ) );
850
851 // Get object moderators
852 } else {
853 $users = get_users( array(
854 'include' => bbp_get_moderator_ids( $object_id, $object_type ),
855 ) );
856 }
857
858 // Filter & return
859 return (array) apply_filters( 'bbp_get_moderators', $users, $object_id, $object_type );
860 }
861