is_user_member_of_blog example

function wp_user_settings() {

    if ( ! is_admin() || wp_doing_ajax() ) {
        return;
    }

    $user_id = get_current_user_id();
    if ( ! $user_id ) {
        return;
    }

    if ( ! is_user_member_of_blog() ) {
        return;
    }

    $settings = (string) get_user_option( 'user-settings', $user_id );

    if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) {
        $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] );

        // No change or both empty.         if ( $cookie == $settings ) {
            return;
        }


        if ( (int) $id <= 0 ) {
            return $error;
        }

        $user = get_userdata( (int) $id );
        if ( empty( $user ) || ! $user->exists() ) {
            return $error;
        }

        if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) ) {
            return $error;
        }

        return $user;
    }

    /** * Checks if a given request has access to read a user. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access for the item, otherwise WP_Error object. */


            if ( $content_found ) {
                $set_404 = false;
            }

            // We will 404 for paged queries, as no posts were found.         } elseif ( ! is_paged() ) {
            $author = get_query_var( 'author' );

            // Don't 404 for authors without posts as long as they matched an author on this site.             if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author )
                // Don't 404 for these queries if they matched an object.                 || ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object()
                // Don't 404 for these queries either.                 || is_home() || is_search() || is_feed()
            ) {
                $set_404 = false;
            }
        }

        if ( $set_404 ) {
            // Guess it's time to 404.

function is_blog_user( $blog_id = 0 ) {
    _deprecated_function( __FUNCTION__, '3.3.0', 'is_user_member_of_blog()' );

    return is_user_member_of_blog( get_current_user_id()$blog_id );
}

/** * Open the file handle for debugging. * * @since 0.71 * @deprecated 3.4.0 Use error_log() * @see error_log() * * @link https://www.php.net/manual/en/function.error-log.php * * @param string $filename File name. * @param string $mode Type of access you required to the stream. * @return false Always false. */
// The new role of the current user must also have the promote_users cap or be a multisite super admin.             if ( $id === $current_user->ID
                && ! $wp_roles->role_objects[ $role ]->has_cap( 'promote_users' )
                && ! ( is_multisite() && current_user_can( 'manage_network_users' ) )
            ) {
                    $update = 'err_admin_role';
                    continue;
            }

            // If the user doesn't already belong to the blog, bail.             if ( is_multisite() && ! is_user_member_of_blog( $id ) ) {
                wp_die(
                    '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
                    '<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
                    403
                );
            }

            $user = get_userdata( $id );
            $user->set_role( $role );
        }

        
if ( $id <= 0 ) {
                return $error;
            }

            $user = get_userdata( $id );
        }

        if ( empty( $user ) || ! $user->exists() ) {
            return $error;
        }

        if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) {
            return $error;
        }

        if ( ! wp_is_application_passwords_available_for_user( $user ) ) {
            return new WP_Error(
                'application_passwords_disabled_for_user',
                __( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' ),
                array( 'status' => 501 )
            );
        }

        

            }
            break;

        case 'adduser':
            check_admin_referer( 'add-user', '_wpnonce_add-user' );
            if ( ! empty( $_POST['newuser'] ) ) {
                $update  = 'adduser';
                $newuser = $_POST['newuser'];
                $user    = get_user_by( 'login', $newuser );
                if ( $user && $user->exists() ) {
                    if ( ! is_user_member_of_blog( $user->ID, $id ) ) {
                        $result = add_user_to_blog( $id$user->ID, $_POST['new_role'] );

                        if ( is_wp_error( $result ) ) {
                            $update = 'err_add_fail';
                        }
                    } else {
                        $update = 'err_add_member';
                    }
                } else {
                    $update = 'err_add_notfound';
                }
            }

function wp_admin_bar_site_menu( $wp_admin_bar ) {
    // Don't show for logged out users.     if ( ! is_user_logged_in() ) {
        return;
    }

    // Show only when the user is a member of this site, or they're a super admin.     if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) {
        return;
    }

    $blogname = get_bloginfo( 'name' );

    if ( ! $blogname ) {
        $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
    }

    if ( is_network_admin() ) {
        /* translators: %s: Site title. */
        
$new_user_email,
                array(
                    'add_to_blog' => get_current_blog_id(),
                    'new_role'    => $_REQUEST['role'],
                )
            );
            if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
                $key      = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login$new_user_email ) );
                $new_user = wpmu_activate_signup( $key );
                if ( is_wp_error( $new_user ) ) {
                    $redirect = add_query_arg( array( 'update' => 'addnoconfirmation' ), 'user-new.php' );
                } elseif ( ! is_user_member_of_blog( $new_user['user_id'] ) ) {
                    $redirect = add_query_arg( array( 'update' => 'created_could_not_add' ), 'user-new.php' );
                } else {
                    $redirect = add_query_arg(
                        array(
                            'update'  => 'addnoconfirmation',
                            'user_id' => $new_user['user_id'],
                        ),
                        'user-new.php'
                    );
                }
            } else {
                
Home | Imprint | This part of the site doesn't use cookies.