get_active_blog_for_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;
            }

            $blog_id = $blog->userblog_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 {
            $active = get_active_blog_for_user( $user_id );
            if ( $active ) {
                $url = get_admin_url( $active->blog_id, $path$scheme );
            } else {
                $url = user_admin_url( $path$scheme );
            }
        }
    }

    /** * Filters the dashboard URL for a user. * * @since 3.1.0 * * @param string $url The complete URL including scheme and path. * @param int $user_id The user ID. * @param string $path Path relative to the URL. Blank string if no path is specified. * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */

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

        add_action( 'wp_head', 'wp_admin_bar_header' );

        
array(
                            'action'  => 'confirm_admin_email',
                            'wp_lang' => get_user_locale( $user ),
                        ),
                        wp_login_url( $redirect_to )
                    );
                }
            }

            if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) {
                // If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.                 if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) {
                    $redirect_to = user_admin_url();
                } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) {
                    $redirect_to = get_dashboard_url( $user->ID );
                } elseif ( ! $user->has_cap( 'edit_posts' ) ) {
                    $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
                }

                wp_redirect( $redirect_to );
                exit;
            }

            
Home | Imprint | This part of the site doesn't use cookies.