On this page
WP_Roles::for_site( int $site_id = null )
Sets the site to operate on. Defaults to the current site.
Parameters
$site_idint Optional-
Site ID to initialize roles for. Default is the current site.
Default:
null
Source
File: wp-includes/class-wp-roles.php. View all references
public function for_site( $site_id = null ) {
global $wpdb;
if ( ! empty( $site_id ) ) {
$this->site_id = absint( $site_id );
} else {
$this->site_id = get_current_blog_id();
}
$this->role_key = $wpdb->get_blog_prefix( $this->site_id ) . 'user_roles';
if ( ! empty( $this->roles ) && ! $this->use_db ) {
return;
}
$this->roles = $this->get_roles_data();
$this->init_roles();
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Roles::get_roles_data() wp-includes/class-wp-roles.php | Gets the available roles data. |
| WP_Roles::init_roles() wp-includes/class-wp-roles.php | Initializes all of the available roles. |
| wpdb::get_blog_prefix() wp-includes/class-wpdb.php | Gets blog prefix. |
| get_current_blog_id() wp-includes/load.php | Retrieve the current site ID. |
| absint() wp-includes/functions.php | Converts a value to non-negative integer. |
Used By
| Used By | Description |
|---|---|
| wp_switch_roles_and_user() wp-includes/ms-blogs.php | Switches the initialized roles and current user capabilities to another site. |
| WP_Roles::__construct() wp-includes/class-wp-roles.php | Constructor. |
| WP_Roles::_init() wp-includes/class-wp-roles.php | Sets up the object properties. |
| WP_Roles::reinit() wp-includes/class-wp-roles.php | Reinitializes the object. |
| WP_User_Query::prepare_query() wp-includes/class-wp-user-query.php | Prepares the query variables. |
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_roles/for_site