get_blogs_of_user example


        do_action( 'xmlrpc_call', 'wp.getUsersBlogs', $args$this );

        $blogs           = (array) get_blogs_of_user( $user->ID );
        $struct          = array();
        $primary_blog_id = 0;
        $active_blog     = get_active_blog_for_user( $user->ID );
        if ( $active_blog ) {
            $primary_blog_id = (int) $active_blog->blog_id;
        }

        foreach ( $blogs as $blog ) {
            // Don't include blogs that aren't hosted at this site.             if ( get_current_network_id() != $blog->site_id ) {
                continue;
            }
/** * Fires before a user is deleted from the network. * * @since MU (3.0.0) * @since 5.5.0 Added the `$user` parameter. * * @param int $id ID of the user about to be deleted from the network. * @param WP_User $user WP_User object of the user about to be deleted from the network. */
    do_action( 'wpmu_delete_user', $id$user );

    $blogs = get_blogs_of_user( $id );

    if ( ! empty( $blogs ) ) {
        foreach ( $blogs as $blog ) {
            switch_to_blog( $blog->userblog_id );
            remove_user_from_blog( $id$blog->userblog_id );

            $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
            foreach ( (array) $post_ids as $post_id ) {
                wp_delete_post( $post_id );
            }

            
if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore.             $post = get_default_post_to_edit( 'post', true );
            update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.         } else {
            $post->post_title = ''; // Remove the auto draft title.         }
    } else {
        $post    = get_default_post_to_edit( 'post', true );
        $user_id = get_current_user_id();

        // Don't create an option if this is a super admin who does not belong to this site.         if ( in_array( get_current_blog_id()array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
            update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.         }
    }

    $post_ID = (int) $post->ID;
    ?> <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js"> <?php if ( $error_msg ) : ?> <div class="error"><?php echo $error_msg; ?></div>
<p> <?php         printf(
            /* translators: %s: Current user's display name. */
            __( 'Welcome back, %s. By filling out the form below, you can <strong>add another site to your account</strong>. There is no limit to the number of sites you can have, so create to your heart&#8217;s content, but write responsibly!' ),
            $current_user->display_name
        );
        ?> </p> <?php     $blogs = get_blogs_of_user( $current_user->ID );
    if ( ! empty( $blogs ) ) {
        ?> <p><?php _e( 'Sites you are already a member of:' ); ?></p> <ul> <?php                 foreach ( $blogs as $blog ) {
                    $home_url = get_home_url( $blog->userblog_id );
                    echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>';
                }
                ?>
if ( is_super_admin( $user->ID ) ) {
                                    wp_die(
                                        sprintf(
                                            /* translators: %s: User login. */
                                            __( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
                                            esc_html( $user->user_login )
                                        )
                                    );
                                }

                                $userfunction = 'all_spam';
                                $blogs        = get_blogs_of_user( $user_id, true );

                                foreach ( (array) $blogs as $details ) {
                                    if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!                                         update_blog_status( $details->userblog_id, 'spam', '1' );
                                    }
                                }

                                $user_data         = $user->to_array();
                                $user_data['spam'] = '1';

                                wp_update_user( $user_data );
                                
__( 'Would you like to give the application identifying itself as %s access to your account? You should only do this if you trust the application in question.' ),
                    '<strong>' . esc_html( $app_name ) . '</strong>'
                );
                ?> </p> <?php else : ?> <p><?php _e( 'Would you like to give this application access to your account? You should only do this if you trust the application in question.' ); ?></p> <?php endif; ?> <?php         if ( is_multisite() ) {
            $blogs       = get_blogs_of_user( $user->ID, true );
            $blogs_count = count( $blogs );

            if ( $blogs_count > 1 ) {
                ?> <p> <?php                     /* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
                    $message = _n(
                        'This will grant access to <a href="%1$s">the %2$s site in this installation that you have permissions on</a>.',
                        'This will grant access to <a href="%1$s">all %2$s sites in this installation that you have permissions on</a>.',
                        $blogs_count
                    );
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
            '<p>' . __( 'Sorry, you are not allowed to add users to this network.' ) . '</p>',
            403
        );
    }

    // Adding an existing user to this blog.     $new_user_email = array();
    $redirect       = 'user-new.php';
    $username       = $user_details->user_login;
    $user_id        = $user_details->ID;
    if ( null != $username && array_key_exists( $blog_idget_blogs_of_user( $user_id ) ) ) {
        $redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' );
    } else {
        if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
            $result = add_existing_user_to_blog(
                array(
                    'user_id' => $user_id,
                    'role'    => $_REQUEST['role'],
                )
            );

            if ( ! is_wp_error( $result ) ) {
                
if ( ! is_multisite() ) {
    wp_die( __( 'Multisite support is not enabled.' ) );
}

if ( ! current_user_can( 'read' ) ) {
    wp_die( __( 'Sorry, you are not allowed to access this page.' ) );
}

$action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';

$blogs = get_blogs_of_user( $current_user->ID );

$updated = false;
if ( 'updateblogsettings' === $action && isset( $_POST['primary_blog'] ) ) {
    check_admin_referer( 'update-my-sites' );

    $blog = get_site( (int) $_POST['primary_blog'] );
    if ( $blog && isset( $blog->domain ) ) {
        update_user_meta( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'] );
        $updated = true;
    } else {
        wp_die( __( 'The primary site you chose does not exist.' ) );
    }
echo '</td>';
    }

    /** * Handles the sites column output. * * @since 4.3.0 * * @param WP_User $user The current WP_User object. */
    public function column_blogs( $user ) {
        $blogs = get_blogs_of_user( $user->ID, true );
        if ( ! is_array( $blogs ) ) {
            return;
        }

        foreach ( $blogs as $site ) {
            if ( ! can_edit_network( $site->site_id ) ) {
                continue;
            }

            $path         = ( '/' === $site->path ) ? '' : $site->path;
            $site_classes = array( 'site-' . $site->site_id );
            

function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
    $user_id = $user_id ? (int) $user_id : get_current_user_id();

    $blogs = get_blogs_of_user( $user_id );

    if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
        $url = user_admin_url( $path$scheme );
    } elseif ( ! is_multisite() ) {
        $url = admin_url( $path$scheme );
    } else {
        $current_blog = get_current_blog_id();

        if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blogarray_keys( $blogs ), true ) ) ) {
            $url = admin_url( $path$scheme );
        } else {
            

function get_active_blog_for_user( $user_id ) {
    $blogs = get_blogs_of_user( $user_id );
    if ( empty( $blogs ) ) {
        return;
    }

    if ( ! is_multisite() ) {
        return $blogs[ get_current_blog_id() ];
    }

    $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
    $first_blog   = current( $blogs );
    if ( false !== $primary_blog ) {
        
/** * Initializes the admin bar. * * @since 3.1.0 */
    public function initialize() {
        $this->user = new stdClass();

        if ( is_user_logged_in() ) {
            /* Populate settings we need for the menu based on the current user. */
            $this->user->blogs = get_blogs_of_user( get_current_user_id() );
            if ( is_multisite() ) {
                $this->user->active_blog    = get_active_blog_for_user( get_current_user_id() );
                $this->user->domain         = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) );
                $this->user->account_domain = $this->user->domain;
            } else {
                $this->user->active_blog    = $this->user->blogs[ get_current_blog_id() ];
                $this->user->domain         = trailingslashit( home_url() );
                $this->user->account_domain = $this->user->domain;
            }
        }

        
<?php endif; ?> </table> <?php if ( wp_is_application_passwords_available_for_user( $user_id ) || ! wp_is_application_passwords_supported() ) : ?> <div class="application-passwords hide-if-no-js" id="application-passwords-section"> <h2><?php _e( 'Application Passwords' ); ?></h2> <p><?php _e( 'Application passwords allow authentication via non-interactive systems, such as XML-RPC or the REST API, without providing your actual password. Application passwords can be easily revoked. They cannot be used for traditional logins to your website.' ); ?></p> <?php if ( wp_is_application_passwords_available_for_user( $user_id ) ) : ?> <?php                                 if ( is_multisite() ) :
                                    $blogs       = get_blogs_of_user( $user_id, true );
                                    $blogs_count = count( $blogs );

                                    if ( $blogs_count > 1 ) :
                                        ?> <p> <?php                                             /* translators: 1: URL to my-sites.php, 2: Number of sites the user has. */
                                            $message = _n(
                                                'Application passwords grant access to <a href="%1$s">the %2$s site in this installation that you have permissions on</a>.',
                                                'Application passwords grant access to <a href="%1$s">all %2$s sites in this installation that you have permissions on</a>.',
                                                $blogs_count
                                            );
Home | Imprint | This part of the site doesn't use cookies.