Custom Admin Bar Link To User's Site

Hi, I have a multisite setup where users can register their own site. I'm using the Custom Admin Bar of Ultimate Branding plugin and would like to link an entry to the user's own subsite dashboard area when they are already logged in. What do I put in 'This URL:' ?

  • Adam Czajczyk

    Hey @ic1980,

    I hope you're well today and thank you for your question!

    Although our Ultimate Branding plugin includes a feature that allows you to add link to the admin toolbar this link will be "fixed" so there's no "out of the box" way to determine which blog to redirect to.

    You may however try a simple snippet of code:

    <?php
    function wpmu_get_user_dashboard_link()
    {
    	global $user;
        if ($user->ID != 0) {
            $user_info = get_userdata($user->ID);
            if ($user_info->primary_blog) {
                $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin/';
                if ($primary_url) {
                    return $primary_url;
                    die();
                }
            }
        }
    }
    
    function wpmu_admin_bar_dashboard_render() {
    	global $wp_admin_bar;
    	$wpmu_dashboard_link = wpmu_get_user_dashboard_link();
    	$wp_admin_bar->add_menu( array(
    		'parent' => false,
    		'id' => 'wpmu_my_dashboard',
    		'title' => __('My Dashboard'),
    		'href' => $wpmu_dashboard_link,
    		'meta' => false
    	));
    }
    add_action( 'wp_before_admin_bar_render', 'wpmu_admin_bar_dashboard_render' );
    ?>

    To use it, access your WP install via FTP and go to this folder:

    /wp-content/mu-plugins/

    If it doesn't exist then please create it.

    Next step would be to download the attached .zip file, unpack it and upload to this directory. The file includes the very same code as above.

    It should automatically add a "My Dashboard" link to user's site dashboard for every logged in user.

    Let me know if it helped!

    Cheers,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.