wppaste
WordPress

is_user_member_of_blog( int $user_id = 0, int $blog_id = 0 ): bool

Since
MU (3.0.0), 7.1.0
Source
wp-includes/user.php:1163
Finds out whether a user is a member of a given blog.

Parameters

$user_idintoptional
The unique ID of the user. Defaults to the current user.Default: 0
$blog_idintoptional
ID of the blog to check. Defaults to the current site.Default: 0

Return

bool

Hooks fired · 1

One hook fires while is_user_member_of_blog() runs, in this order:

  1. apply_filters( is_user_member_of_blog )filterline 1222 (+59 into the body)

    Filters whether the user is a member of a given blog.

Uses · 7

Used by · 7

Source

function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) {	global $wpdb; 	$user_id = (int) $user_id;	$blog_id = (int) $blog_id; 	if ( empty( $user_id ) ) {		$user_id = get_current_user_id();	} 	/*	 * Technically not needed, but does save calls to get_site() and get_user_meta()	 * in the event that the function is called when a user isn't logged in.	 */	if ( empty( $user_id ) ) {		return false;	} else {		$user = get_userdata( $user_id );		if ( ! $user instanceof WP_User ) {			return false;		}	} 	if ( ! is_multisite() ) {		return true;	} 	if ( empty( $blog_id ) ) {		$blog_id = get_current_blog_id();	} 	$blog = get_site( $blog_id ); 	if ( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted ) {		return false;	} 	if ( 1 === $blog_id ) {		$capabilities_key = $wpdb->base_prefix . 'capabilities';	} else {		$capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';	} 	$has_cap   = get_user_meta( $user_id, $capabilities_key, true );	$is_member = is_array( $has_cap ); 	/**	 * Filters whether the user is a member of a given blog.	 *	 * This filter only runs when the user and blog have both been resolved	 * to valid records on a multisite installation; it is not invoked for	 * logged-out requests, unknown users, or archived/spammed/deleted sites.	 *	 * @since 7.1.0	 *	 * @param bool $is_member Whether the user is a member of the blog.	 * @param int  $user_id   The user ID being checked.	 * @param int  $blog_id   The blog ID being checked.	 */	return (bool) apply_filters( 'is_user_member_of_blog', $is_member, $user_id, $blog_id );}

History

Introduced in 7.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Introduced the 'is_user_member_of_blog' filter.from the docblock
MU (3.0.0)
MU (3.0.0)from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.