Alert: 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.

_bp_roles_init( WP_Roles $wp_roles )

Adds the bp_moderate cap to Roles having the manage_options cap when BuddyPress is not active on the network.


Parameters Parameters

$wp_roles

(WP_Roles) (Required) The WordPress roles object.


Source Source

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

function _bp_roles_init( WP_Roles $wp_roles ) {
	$roles_list = array();
	$caps_list  = wp_list_pluck( $wp_roles->role_objects, 'capabilities' );

	// Look for roles having the `manage_options` capability set to true.
	$filtered_list = wp_list_filter( $caps_list, array( 'manage_options' => true ) );

	if ( $filtered_list ) {
		$roles_list = array_keys( $filtered_list );

		// Loop into roles list to add the `bp_moderate` capability.
		foreach ( $roles_list as $role ) {
			if ( isset( $wp_roles->roles[ $role ] ) ) {
				$wp_roles->roles[ $role ]['capabilities']['bp_moderate'] = true;
			}

			if ( isset( $wp_roles->role_objects[ $role ] ) ) {
				$wp_roles->role_objects[ $role ]->capabilities['bp_moderate'] = true;
			}
		}
	}

	// Make sure to remove the `bp_moderate` capability from roles when BuddyPress is network activated.
	if ( bp_is_network_activated() ) {
		foreach ( $roles_list as $role ) {
			unset( $wp_roles->roles[ $role ]['capabilities']['bp_moderate'], $wp_roles->role_objects[ $role ]->capabilities['bp_moderate'] );
		}
	}
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.