On this page
wp_switch_roles_and_user( int $new_site_id, int $old_site_id )
Switches the initialized roles and current user capabilities to another site.
Parameters
$new_site_idint Required-
New site ID.
$old_site_idint Required-
Old site ID.
Source
File: wp-includes/ms-blogs.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Roles::for_site() wp-includes/class-wp-roles.php | Sets the site to operate on. Defaults to the current site. |
| wp_roles() wp-includes/capabilities.php | Retrieves the global WP_Roles instance and instantiates it if necessary. |
| wp_get_current_user() wp-includes/pluggable.php | Retrieves the current user object. |
| did_action() wp-includes/plugin.php | Retrieves the number of times an action has been fired during the current request. |
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_switch_roles_and_user