wp_switch_roles_and_user()WP 4.9.0

Switches the initialized roles and current user capabilities to another site.

Хуков нет.

Возвращает

null. Ничего (null).

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

wp_switch_roles_and_user( $new_site_id, $old_site_id );
$new_site_id(int) (обязательный)
New site ID.
$old_site_id(int) (обязательный)
Old site ID.

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

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

Код wp_switch_roles_and_user() WP 6.5.2

function wp_switch_roles_and_user( $new_site_id, $old_site_id ) {
	if ( $new_site_id == $old_site_id ) {
		return;
	}

	if ( ! did_action( 'init' ) ) {
		return;
	}

	wp_roles()->for_site( $new_site_id );
	wp_get_current_user()->for_site( $new_site_id );
}