This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use WP_User::has_cap() instead.

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

Temporary implementation of ‘bp_moderate’ cap.

Description

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 WP_User::has_cap().

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. 🙂

See also

Parameters

$caps

(array) (Optional) The caps that WP associates with the given role.

Default value: array()

$cap

(string) (Optional) The caps being tested for in WP_User::has_cap().

Default value: ''

$user_id

(int) (Required) ID of the user being checked against.

$args

(array) (Optional) Miscellaneous arguments passed to the user_has_cap filter.

Default value: array()

Return

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

Source

File: bp-core/bp-core-caps.php

function _bp_enforce_bp_moderate_cap_for_admins( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {

	// Bail if not checking the 'bp_moderate' cap.
	if ( 'bp_moderate' !== $cap ) {
		return $caps;
	}

	// Bail if BuddyPress is not network activated.
	if ( bp_is_network_activated() ) {
		return $caps;
	}

	// Never trust inactive users.
	if ( bp_is_user_inactive( $user_id ) ) {
		return $caps;
	}

	// Only users that can 'manage_options' on this site can 'bp_moderate'.
	return array( 'manage_options' );
}

Changelog

Changelog
Version Description
BuddyPress 1.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.