WordPress at a glance
function is not described

WP_User::add_role() public WP 2.0.0

Add role to user.

Updates the user's meta data option with capabilities and roles.

This is a method of the class: WP_User{}

Hooks from the method

Null. Nothing.


$WP_User = new WP_User();
\$WP_User->add_role( $role );
$role(string) (required)
Role name.


Since 2.0.0 Introduced.

Code of WP User::add role: wp-includes/class-wp-user.php WP 5.4.2

public function add_role( $role ) {
	if ( empty( $role ) ) {

	$this->caps[ $role ] = true;
	update_user_meta( $this->ID, $this->cap_key, $this->caps );

	 * Fires immediately after the user has been given a new role.
	 * @since 4.3.0
	 * @param int    $user_id The user ID.
	 * @param string $role    The new role.
	do_action( 'add_user_role', $this->ID, $role );