bbp_profile_update_role( int $user_id )

Helper function hooked to ‘bbp_profile_update’ action to save or update user roles and capabilities.

Description

Parameters

$user_id

(int) (Required)

Source

File: bp-forums/users/capabilities.php

function bbp_profile_update_role( $user_id = 0 ) {

	// Bail if no user ID was passed
	if ( empty( $user_id ) )
		return;

	// Bail if no role
	if ( ! isset( $_POST['bbp-forums-role'] ) )
		return;

	// Fromus role we want the user to have
	$new_role    = sanitize_text_field( $_POST['bbp-forums-role'] );
	$forums_role = bbp_get_user_role( $user_id );

	// Bail if no role change
	if ( $new_role === $forums_role )
		return;

	// Bail if trying to set their own role
	if ( bbp_is_user_home_edit() )
		return;
	
	// Bail if current user cannot promote the passing user
	if ( ! current_user_can( 'promote_user', $user_id ) )
		return;

	// Set the new forums role
	bbp_set_user_role( $user_id, $new_role );
}

Changelog

Changelog
Version Description
bbPress (r4235) 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.