_bp_enforce_bp_moderate_cap_for_admins

Temporary implementation of 'bp_moderate' cap.

Description

(array) _bp_enforce_bp_moderate_cap_for_admins( (array) $caps = array(), (string) $cap = '', (int) $user_id = 0, (array) $args = array() ); 

In BuddyPress 1.6, the bp_moderate cap was introduced. In order to enforce that bp_current_user_can( bp_moderate ) always returns true for Administrators, we must manually add the bp_moderate cap to the list of user caps for Admins.

Note that this level of enforcement is only necessary in the case of non-Multisite. This is because WordPress automatically assigns every capability - and thus bp_moderate - to Super Admins on a Multisite installation. See .

This implementation of bp_moderate is temporary, until BuddyPress properly matches caps to roles and stores them in the database.

Plugin authors: Please do not use this function; thank you. :)

Returns (array)

$allcaps The user's cap list, with 'bp_moderate' appended, if relevant.

Parameters (4)

0. $caps — Optional. (array) => array()
The caps that WP associates with the given role.
1. $cap — Optional. (string) => ''
The caps being tested for in WP_User::has_cap().
2. $user_id — Optional. (int)
ID of the user being checked against.
3. $args — Optional. (array) => array()
Miscellaneous arguments passed to the user_has_cap filter.

Usage

  1. if ( !function_exists( '_bp_enforce_bp_moderate_cap_for_admins' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-caps.php'; 
  3.  
  4. // The caps that WP associates with the given role. 
  5. $caps = array(); 
  6.  
  7. // The caps being tested for in WP_User::has_cap(). 
  8. $cap = ''; 
  9.  
  10. // ID of the user being checked against. 
  11. $user_id = -1; 
  12.  
  13. // Miscellaneous arguments passed to the user_has_cap filter. 
  14. $args = array(); 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = _bp_enforce_bp_moderate_cap_for_admins($caps, $cap, $user_id, $args); 
  18.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-caps.php  
  1. function _bp_enforce_bp_moderate_cap_for_admins( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 
  2.  
  3. // Bail if not checking the 'bp_moderate' cap. 
  4. if ( 'bp_moderate' !== $cap ) { 
  5. return $caps; 
  6.  
  7. // Bail if BuddyPress is not network activated. 
  8. return $caps; 
  9.  
  10. // Never trust inactive users. 
  11. if ( bp_is_user_inactive( $user_id ) ) { 
  12. return $caps; 
  13.  
  14. // Only users that can 'manage_options' on this site can 'bp_moderate'. 
  15. return array( 'manage_options' );