is_user_member_of_blog

The timeline below displays how wordpress function is_user_member_of_blog has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Finds out whether a user is a member of a given blog.
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
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;
    }
    $keys = get_user_meta($user_id);
    if (empty($keys)) {
        return false;
    }
    // No underscore before capabilities in $base_capabilities_key.
    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
    if (isset($keys[$base_capabilities_key]) && 1 == $blog_id) {
        return true;
    }
    if (isset($keys[$site_capabilities_key])) {
        return true;
    }
    return false;
}

WordPress Version: 6.1

/**
 * Finds out whether a user is a member of a given blog.
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
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;
    }
    $keys = get_user_meta($user_id);
    if (empty($keys)) {
        return false;
    }
    // No underscore before capabilities in $base_capabilities_key.
    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
    if (isset($keys[$base_capabilities_key]) && 1 == $blog_id) {
        return true;
    }
    if (isset($keys[$site_capabilities_key])) {
        return true;
    }
    return false;
}

WordPress Version: 5.4

/**
 * Find out whether a user is a member of a given blog.
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
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;
    }
    $keys = get_user_meta($user_id);
    if (empty($keys)) {
        return false;
    }
    // No underscore before capabilities in $base_capabilities_key.
    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
    if (isset($keys[$base_capabilities_key]) && 1 == $blog_id) {
        return true;
    }
    if (isset($keys[$site_capabilities_key])) {
        return true;
    }
    return false;
}

WordPress Version: 4.9

/**
 * Find out whether a user is a member of a given blog.
 *
 * @since MU (3.0.0)
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
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;
    }
    $keys = get_user_meta($user_id);
    if (empty($keys)) {
        return false;
    }
    // no underscore before capabilities in $base_capabilities_key
    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
    if (isset($keys[$base_capabilities_key]) && $blog_id == 1) {
        return true;
    }
    if (isset($keys[$site_capabilities_key])) {
        return true;
    }
    return false;
}

WordPress Version: 4.7

/**
 * Find out whether a user is a member of a given blog.
 *
 * @since MU 1.1
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
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;
    }
    $keys = get_user_meta($user_id);
    if (empty($keys)) {
        return false;
    }
    // no underscore before capabilities in $base_capabilities_key
    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
    if (isset($keys[$base_capabilities_key]) && $blog_id == 1) {
        return true;
    }
    if (isset($keys[$site_capabilities_key])) {
        return true;
    }
    return false;
}

WordPress Version: 4.4

/**
 * Find out whether a user is a member of a given blog.
 *
 * @since MU 1.1
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
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_blog_details 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_blog_details($blog_id);
    if (!$blog || !isset($blog->domain) || $blog->archived || $blog->spam || $blog->deleted) {
        return false;
    }
    $keys = get_user_meta($user_id);
    if (empty($keys)) {
        return false;
    }
    // no underscore before capabilities in $base_capabilities_key
    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
    if (isset($keys[$base_capabilities_key]) && $blog_id == 1) {
        return true;
    }
    if (isset($keys[$site_capabilities_key])) {
        return true;
    }
    return false;
}

WordPress Version: 4.1

/**
 * Find out whether a user is a member of a given blog.
 *
 * @since MU 1.1
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
function is_user_member_of_blog($user_id = 0, $blog_id = 0)
{
    $user_id = (int) $user_id;
    $blog_id = (int) $blog_id;
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    if (empty($blog_id)) {
        $blog_id = get_current_blog_id();
    }
    $blogs = get_blogs_of_user($user_id);
    return array_key_exists($blog_id, $blogs);
}

WordPress Version: 3.7

/**
 * Find out whether a user is a member of a given blog.
 *
 * @since MU 1.1
 * @uses get_blogs_of_user()
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
function is_user_member_of_blog($user_id = 0, $blog_id = 0)
{
    $user_id = (int) $user_id;
    $blog_id = (int) $blog_id;
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    if (empty($blog_id)) {
        $blog_id = get_current_blog_id();
    }
    $blogs = get_blogs_of_user($user_id);
    return array_key_exists($blog_id, $blogs);
}