On this page
WP_User::for_site( int $site_id = '' )
Sets the site to operate on. Defaults to the current site.
Parameters
$site_idint Optional-
Site ID to initialize user capabilities for. Default is the current site.
Default:
''
Source
File: wp-includes/class-wp-user.php. View all references
public function for_site( $site_id = '' ) {
global $wpdb;
if ( ! empty( $site_id ) ) {
$this->site_id = absint( $site_id );
} else {
$this->site_id = get_current_blog_id();
}
$this->cap_key = $wpdb->get_blog_prefix( $this->site_id ) . 'capabilities';
$this->caps = $this->get_caps_data();
$this->get_role_caps();
}
Related
Uses
| Uses | Description |
|---|---|
| WP_User::get_caps_data() wp-includes/class-wp-user.php | Gets the available user capabilities data. |
| WP_User::get_role_caps() wp-includes/class-wp-user.php | Retrieves all of the capabilities of the user’s roles, and merges them with individual user capabilities. |
| 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_User::for_blog() wp-includes/class-wp-user.php | Sets the site to operate on. Defaults to the current site. |
| WP_User::init() wp-includes/class-wp-user.php | Sets up object properties, including capabilities. |
Changelog
| Version | Description |
|---|---|
| 4.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_user/for_site