WP_User::for_site() WordPress Method

The WP_User::for_site() method is used to retrieve a user object by ID or login name for a specific site. This is useful if you need to retrieve a user object from a site other than the current one. For example, if you need to retrieve a user object from a multisite network.

WP_User::for_site( int $site_id = '' ) #

Sets the site to operate on. Defaults to the current site.


Parameters

$site_id

(int)(Optional)Site ID to initialize user capabilities for. Default is the current site.

Default value: ''


Top ↑

Source

File: wp-includes/class-wp-user.php

	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();
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.