[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/users/ -> capabilities.php (source)

   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              // Default to the current cap.
  63              } else {
  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                  // If user is a per-forum moderator, make sure they can spectate.
 107                  if ( bbp_is_user_forum_moderator( $user_id, $forum_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 string
 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 users 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          // Users role is different than the new role
 170          } else {
 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   * Add the default role to the current user if needed
 311   *
 312   * This function will bail if the forum is not global in a multisite
 313   * installation of WordPress, or if the user is marked as spam or deleted.
 314   *
 315   * @since 2.0.0 bbPress (r3380)
 316   *
 317   * @return If not multisite, not global, or user is deleted/spammed
 318   */
 319  function bbp_set_current_user_default_role() {
 320  
 321      /** Sanity ****************************************************************/
 322  
 323      // Bail if deactivating bbPress
 324      if ( bbp_is_deactivation() ) {
 325          return;
 326      }
 327  
 328      // Catch all, to prevent premature user initialization
 329      if ( ! did_action( 'set_current_user' ) ) {
 330          return;
 331      }
 332  
 333      // Bail if not logged in or already a member of this site
 334      if ( ! is_user_logged_in() ) {
 335          return;
 336      }
 337  
 338      // Get the current user ID
 339      $user_id = bbp_get_current_user_id();
 340  
 341      // Bail if user already has a forums role
 342      if ( bbp_get_user_role( $user_id ) ) {
 343          return;
 344      }
 345  
 346      // Bail if user is marked as spam or is deleted
 347      if ( bbp_is_user_inactive( $user_id ) ) {
 348          return;
 349      }
 350  
 351      /** Ready *****************************************************************/
 352  
 353      // Load up bbPress once
 354      $bbp         = bbpress();
 355  
 356      // Get whether or not to add a role to the user account
 357      $add_to_site = bbp_allow_global_access();
 358  
 359      // Get the current user's WordPress role. Set to empty string if none found.
 360      $user_role   = bbp_get_user_blog_role( $user_id );
 361  
 362      // Get the role map
 363      $role_map    = bbp_get_user_role_map();
 364  
 365      /** Forum Role ************************************************************/
 366  
 367      // Use a mapped role or default role
 368      $new_role = empty( $user_role ) || ! isset( $role_map[ $user_role ] )
 369          ? bbp_get_default_role()
 370          : $role_map[ $user_role ];
 371  
 372      /** Add or Map ************************************************************/
 373  
 374      // Add the user to the site
 375      if ( true === $add_to_site ) {
 376          bbp_set_user_role( $user_id, $new_role );
 377  
 378      // Don't add the user, but still give them the correct caps dynamically
 379      } else {
 380          $bbp->current_user->caps[ $new_role ] = true;
 381          $bbp->current_user->get_role_caps();
 382      }
 383  }
 384  
 385  /**
 386   * Return a map of WordPress roles to bbPress roles. Used to automatically grant
 387   * appropriate bbPress roles to WordPress users that wouldn't already have a
 388   * role in the forums. Also guarantees WordPress admins get the Keymaster role.
 389   *
 390   * @since 2.2.0 bbPress (r4334)
 391   *
 392   * @return array Filtered array of WordPress roles to bbPress roles
 393   */
 394  function bbp_get_user_role_map() {
 395  
 396      // Get the default role once here
 397      $default_role = bbp_get_default_role();
 398  
 399      // Filter & return
 400      return (array) apply_filters( 'bbp_get_user_role_map', array(
 401          'administrator' => bbp_get_keymaster_role(),
 402          'editor'        => $default_role,
 403          'author'        => $default_role,
 404          'contributor'   => $default_role,
 405          'subscriber'    => $default_role
 406      ) );
 407  }
 408  
 409  /** User Status ***************************************************************/
 410  
 411  /**
 412   * Checks if the user has been marked as a spammer.
 413   *
 414   * @since 2.0.0 bbPress (r3355)
 415   *
 416   * @param int $user_id int The ID for the user.
 417   * @return bool True if spammer, False if not.
 418   */
 419  function bbp_is_user_spammer( $user_id = 0 ) {
 420  
 421      // Default to current user
 422      if ( empty( $user_id ) && is_user_logged_in() ) {
 423          $user_id = bbp_get_current_user_id();
 424      }
 425  
 426      // No user to check
 427      if ( empty( $user_id ) ) {
 428          return false;
 429      }
 430  
 431      // Assume user is not spam
 432      $is_spammer = false;
 433  
 434      // Get user data
 435      $user = get_userdata( $user_id );
 436  
 437      // No user found
 438      if ( empty( $user ) ) {
 439          $is_spammer = false;
 440  
 441      // Check if spam
 442      } elseif ( ! empty( $user->spam ) ) {
 443          $is_spammer = true;
 444      }
 445  
 446      // Filter & return
 447      return (bool) apply_filters( 'bbp_core_is_user_spammer', $is_spammer );
 448  }
 449  
 450  /**
 451   * Mark a users topics and replies as spam when the user is marked as spam
 452   *
 453   * @since 2.0.0 bbPress (r3405)
 454   *
 455   * @param int $user_id Optional. User ID to spam. Defaults to displayed user.
 456   *
 457   * @return bool If no user ID passed.
 458   */
 459  function bbp_make_spam_user( $user_id = 0 ) {
 460  
 461      // Use displayed user if it's not yourself
 462      if ( empty( $user_id ) && bbp_is_single_user() && ! bbp_is_user_home() ) {
 463          $user_id = bbp_get_displayed_user_id();
 464      }
 465  
 466      // Bail if no user ID
 467      if ( empty( $user_id ) ) {
 468          return false;
 469      }
 470  
 471      // Bail if user ID is keymaster
 472      if ( bbp_is_user_keymaster( $user_id ) ) {
 473          return false;
 474      }
 475  
 476      // Arm the torpedos
 477      $bbp_db = bbp_db();
 478  
 479      // Get the blog IDs of the user to mark as spam
 480      $blogs = get_blogs_of_user( $user_id, true );
 481  
 482      // If user has no blogs, they are a guest on this site
 483      if ( empty( $blogs ) ) {
 484          $blogs[ $bbp_db->blogid ] = array();
 485      }
 486  
 487      // Make array of post types to mark as spam
 488      $post_types  = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
 489      $post_types  = "'" . implode( "', '", $post_types ) . "'";
 490  
 491      // Loop through blogs and remove their posts
 492      foreach ( (array) array_keys( $blogs ) as $blog_id ) {
 493  
 494          // Switch to the site ID
 495          bbp_switch_to_site( $blog_id );
 496  
 497          // Get topics and replies
 498          $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = %s AND post_type IN ( {$post_types} )", $user_id, bbp_get_public_status_id() );
 499          $posts = $bbp_db->get_col( $query );
 500  
 501          // Loop through posts and spam them
 502          if ( ! empty( $posts ) ) {
 503              foreach ( $posts as $post_id ) {
 504  
 505                  // The routines for topics ang replies are different, so use the
 506                  // correct one based on the post type
 507                  switch ( get_post_type( $post_id ) ) {
 508  
 509                      case bbp_get_topic_post_type() :
 510                          bbp_spam_topic( $post_id );
 511                          break;
 512  
 513                      case bbp_get_reply_post_type() :
 514                          bbp_spam_reply( $post_id );
 515                          break;
 516                  }
 517              }
 518          }
 519  
 520          // Switch back to current site
 521          bbp_restore_current_site();
 522      }
 523  
 524      // Success
 525      return true;
 526  }
 527  
 528  /**
 529   * Mark a users topics and replies as spam when the user is marked as spam
 530   *
 531   * @since 2.0.0 bbPress (r3405)
 532   *
 533   * @param int $user_id Optional. User ID to unspam. Defaults to displayed user.
 534   *
 535   * @return bool If no user ID passed.
 536   */
 537  function bbp_make_ham_user( $user_id = 0 ) {
 538  
 539      // Use displayed user if it's not yourself
 540      if ( empty( $user_id ) && bbp_is_single_user() && ! bbp_is_user_home() ) {
 541          $user_id = bbp_get_displayed_user_id();
 542      }
 543  
 544      // Bail if no user ID
 545      if ( empty( $user_id ) ) {
 546          return false;
 547      }
 548  
 549      // Bail if user ID is keymaster
 550      if ( bbp_is_user_keymaster( $user_id ) ) {
 551          return false;
 552      }
 553  
 554      // Arm the torpedos
 555      $bbp_db = bbp_db();
 556  
 557      // Get the blog IDs of the user to mark as spam
 558      $blogs = get_blogs_of_user( $user_id, true );
 559  
 560      // If user has no blogs, they are a guest on this site
 561      if ( empty( $blogs ) ) {
 562          $blogs[ $bbp_db->blogid ] = array();
 563      }
 564  
 565      // Make array of post types to mark as spam
 566      $post_types = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
 567      $post_types = "'" . implode( "', '", $post_types ) . "'";
 568  
 569      // Loop through blogs and remove their posts
 570      foreach ( (array) array_keys( $blogs ) as $blog_id ) {
 571  
 572          // Switch to the site ID
 573          bbp_switch_to_site( $blog_id );
 574  
 575          // Get topics and replies
 576          $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = %s AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id() );
 577          $posts = $bbp_db->get_col( $query );
 578  
 579          // Loop through posts and spam them
 580          if ( ! empty( $posts ) ) {
 581              foreach ( $posts as $post_id ) {
 582  
 583                  // The routines for topics ang replies are different, so use the
 584                  // correct one based on the post type
 585                  switch ( get_post_type( $post_id ) ) {
 586  
 587                      case bbp_get_topic_post_type() :
 588                          bbp_unspam_topic( $post_id );
 589                          break;
 590  
 591                      case bbp_get_reply_post_type() :
 592                          bbp_unspam_reply( $post_id );
 593                          break;
 594                  }
 595              }
 596          }
 597  
 598          // Switch back to current site
 599          bbp_restore_current_site();
 600      }
 601  
 602      // Success
 603      return true;
 604  }
 605  
 606  /**
 607   * Checks if the user has been marked as deleted.
 608   *
 609   * @since 2.0.0 bbPress (r3355)
 610   *
 611   * @param int $user_id int The ID for the user.
 612   * @return bool True if deleted, False if not.
 613   */
 614  function bbp_is_user_deleted( $user_id = 0 ) {
 615  
 616      // Default to current user
 617      if ( empty( $user_id ) && is_user_logged_in() ) {
 618          $user_id = bbp_get_current_user_id();
 619      }
 620  
 621      // No user to check
 622      if ( empty( $user_id ) ) {
 623          return false;
 624      }
 625  
 626      // Assume user is not deleted
 627      $is_deleted = false;
 628  
 629      // Get user data
 630      $user = get_userdata( $user_id );
 631  
 632      // No user found
 633      if ( empty( $user ) ) {
 634          $is_deleted = true;
 635  
 636      // Check if deleted
 637      } elseif ( ! empty( $user->deleted ) ) {
 638          $is_deleted = true;
 639      }
 640  
 641      // Filter & return
 642      return (bool) apply_filters( 'bbp_core_is_user_deleted', $is_deleted );
 643  }
 644  
 645  /**
 646   * Checks if user is active
 647   *
 648   * @since 2.0.0 bbPress (r3502)
 649   *
 650   * @param int $user_id The user ID to check
 651   * @return bool True if public, false if not
 652   */
 653  function bbp_is_user_active( $user_id = 0 ) {
 654  
 655      // No user to check
 656      $user_id = bbp_get_user_id( $user_id, false, true );
 657      if ( empty( $user_id ) ) {
 658          return false;
 659      }
 660  
 661      // Check spam
 662      if ( bbp_is_user_spammer( $user_id ) ) {
 663          return false;
 664      }
 665  
 666      // Check deleted
 667      if ( bbp_is_user_deleted( $user_id ) ) {
 668          return false;
 669      }
 670  
 671      // Assume true if not spam or deleted
 672      return true;
 673  }
 674  
 675  /**
 676   * Checks if user is not active.
 677   *
 678   * @since 2.0.0 bbPress (r3502)
 679   *
 680   * @param int $user_id The user ID to check. Defaults to current user ID
 681   * @return bool True if inactive, false if active
 682   */
 683  function bbp_is_user_inactive( $user_id = 0 ) {
 684      return ! bbp_is_user_active( $user_id );
 685  }
 686  
 687  /**
 688   * Checks if user is a keymaster
 689   *
 690   * @since 2.3.0 bbPress (r4783)
 691   *
 692   * @param int $user_id
 693   * @return bool True if keymaster, false if not
 694   */
 695  function bbp_is_user_keymaster( $user_id = 0 ) {
 696      $_user_id = bbp_get_user_id( $user_id, false, true );
 697      $retval   = user_can( $_user_id, 'keep_gate' );
 698  
 699      // Filter & return
 700      return (bool) apply_filters( 'bbp_is_user_keymaster', $retval, $_user_id, $user_id );
 701  }
 702  
 703  /**
 704   * Does a user have a profile for the current site
 705   *
 706   * @since 2.2.0 bbPress (r4362)
 707   *
 708   * @param int $user_id User ID to check
 709   *
 710   * @return bool Whether or not the user has a profile on this blog_id.
 711   */
 712  function bbp_user_has_profile( $user_id = 0 ) {
 713  
 714      // Assume every user has a profile
 715      $retval  = true;
 716  
 717      // Validate user ID, default to displayed or current user
 718      $user_id = bbp_get_user_id( $user_id, true, true );
 719  
 720      // Try to get this user's data
 721      $user    = get_userdata( $user_id );
 722  
 723      // No user found, return false
 724      if ( empty( $user ) ) {
 725          $retval = false;
 726  
 727      // User is inactive, and current user is not a keymaster
 728      } elseif ( ! bbp_is_user_keymaster() && bbp_is_user_inactive( $user->ID ) ) {
 729          $retval = false;
 730      }
 731  
 732      // Filter & return
 733      return (bool) apply_filters( 'bbp_show_user_profile', $retval, $user_id );
 734  }
 735  
 736  /** Moderators ****************************************************************/
 737  
 738  /**
 739   * Add a moderator to an object
 740   *
 741   * @since 2.6.0 bbPress (r6056)
 742   *
 743   * @param int    $object_id   Traditionally a post ID
 744   * @param int    $user_id     User ID
 745   * @param string $object_type Type of meta (post,term,user,comment)
 746   *
 747   * @return bool
 748   */
 749  function bbp_add_moderator( $object_id = 0, $user_id = 0, $object_type = 'post' ) {
 750      return bbp_add_user_to_object( $object_id, $user_id, '_bbp_moderator_id', $object_type );
 751  }
 752  
 753  /**
 754   * Remove a moderator user ID from an object
 755   *
 756   * @since 2.6.0 bbPress (r6056)
 757   *
 758   * @param int    $object_id   Traditionally a post ID
 759   * @param int    $user_id     User ID
 760   * @param string $object_type Type of meta (post,term,user,comment)
 761   *
 762   * @return bool
 763   */
 764  function bbp_remove_moderator( $object_id = 0, $user_id = 0, $object_type = 'post' ) {
 765      return bbp_remove_user_from_object( $object_id, $user_id, '_bbp_moderator_id', $object_type );
 766  }
 767  
 768  /**
 769   * Get user IDs of moderators for an object
 770   *
 771   * @since 2.6.0 bbPress (r6056)
 772   *
 773   * @param int    $object_id   Traditionally a post ID
 774   * @param string $object_type Type of meta (post,term,user,comment)
 775   *
 776   * @return array
 777   */
 778  function bbp_get_moderator_ids( $object_id = 0, $object_type = 'post' ) {
 779      return bbp_get_users_for_object( $object_id, '_bbp_moderator_id', $object_type );
 780  }
 781  
 782  /**
 783   * Get moderators for a specific object ID. Will return global moderators when
 784   * object ID is empty.
 785   *
 786   * @since 2.6.0 bbPress (r6056)
 787   *
 788   * @param int    $object_id   Traditionally a post ID
 789   * @param string $object_type Type of meta (post,term,user,comment)
 790   *
 791   * @return array
 792   */
 793  function bbp_get_moderators( $object_id = 0, $object_type = 'post' ) {
 794  
 795      // Get global moderators
 796      if ( empty( $object_id ) ) {
 797          $users = get_users( array(
 798              'role__in' => bbp_get_moderator_role(),
 799          ) );
 800  
 801      // Get object moderators
 802      } else {
 803          $users = get_users( array(
 804              'include' => bbp_get_moderator_ids( $object_id, $object_type ),
 805          ) );
 806      }
 807  
 808      // Filter & return
 809      return (array) apply_filters( 'bbp_get_moderators', $users, $object_id, $object_type );
 810  }


Generated: Mon Jul 22 01:01:32 2019 Cross-referenced by PHPXref 0.7.1