Skip to:
Content

BuddyPress.org

Changeset 6844


Ignore:
Timestamp:
03/09/2013 08:43:38 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Fix bug in _bp_enforce_bp_moderate_cap_for_admins() causing it not to appear when BuddyPress is activated on a single site in a network. Switch it to use 'map_meta_cap' instead. Add @access phpdoc tag.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-caps.php

    r6306 r6844  
    210210 * @since BuddyPress (1.6)
    211211 * @see WP_User::has_cap()
     212 * @access private
    212213 *
    213214 * @param array $allcaps The caps that WP associates with the given role
     
    216217 * @return array $allcaps The user's cap list, with 'bp_moderate' appended, if relevant
    217218 */
    218 function _bp_enforce_bp_moderate_cap_for_admins( $allcaps, $caps, $args ) {
    219     if ( in_array( 'bp_moderate', $caps ) &&   // We only care if checking for bp_moderate
    220          !in_array( 'do_not_allow', $caps ) && // 'do_not_allow' overrides everything else
    221          !is_multisite() &&                    // Check not necessary on Multisite
    222          isset( $allcaps['delete_users'] ) )   // Mimicking WP's check for Administrator status
    223     {
    224         $allcaps['bp_moderate'] = true;
    225     }
    226 
    227     return $allcaps;
    228 }
    229 add_filter( 'user_has_cap', '_bp_enforce_bp_moderate_cap_for_admins', 10, 3 );
     219function _bp_enforce_bp_moderate_cap_for_admins( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
     220
     221    // Bail if not checking the 'bp_moderate' cap
     222    if ( 'bp_moderate' !== $cap )
     223        return $caps;
     224
     225    // Bail if BuddyPress is not network activated
     226    if ( bp_is_network_activated() )
     227        return $caps;
     228
     229    // Never trust inactive users
     230    if ( bp_is_user_inactive( $user_id ) )
     231        return $caps;
     232
     233    // Only users that can 'manage_options' on this site can 'bp_moderate'
     234    return array( 'manage_options' );
     235}
     236add_filter( 'map_meta_cap', '_bp_enforce_bp_moderate_cap_for_admins', 10, 4 );
    230237
    231238/** Deprecated ****************************************************************/
Note: See TracChangeset for help on using the changeset viewer.