WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_User::set_role() public WP 2.0.0

Set the role of the user.

This will remove the previous roles of the user and assign the user the new one. You can set the role to an empty string and it will remove all of the roles from the user.

Это метод класса: WP_User{}

Хуки из метода
Возвращает

Null. Ничего.

Использование

$WP_User = new WP_User();
$WP_User->set_role( $role );
$role(строка) (обязательный)
Role name.

Список изменений

С версии 2.0.0 Введена.

Код WP_User::set_role() WP 5.5.1

wp-includes/class-wp-user.php
<?php
public function set_role( $role ) {
	if ( 1 === count( $this->roles ) && current( $this->roles ) == $role ) {
		return;
	}

	foreach ( (array) $this->roles as $oldrole ) {
		unset( $this->caps[ $oldrole ] );
	}

	$old_roles = $this->roles;
	if ( ! empty( $role ) ) {
		$this->caps[ $role ] = true;
		$this->roles         = array( $role => true );
	} else {
		$this->roles = false;
	}
	update_user_meta( $this->ID, $this->cap_key, $this->caps );
	$this->get_role_caps();
	$this->update_user_level_from_caps();

	/**
	 * Fires after the user's role has changed.
	 *
	 * @since 2.9.0
	 * @since 3.6.0 Added $old_roles to include an array of the user's previous roles.
	 *
	 * @param int      $user_id   The user ID.
	 * @param string   $role      The new role.
	 * @param string[] $old_roles An array of the user's previous roles.
	 */
	do_action( 'set_user_role', $this->ID, $role, $old_roles );
}