• Resolved willcowd

    (@willcowd)


    Hi all

    I hope you can help
    I have a multisite with a custom login which takes users to the root wp-admin by default which gives this error for those who do not have the correct permission.

    You attempted to access the “WordPress” dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the “WordPress” dashboard, please contact your network administrator.

    I would like them to be redirected to the primary blog like this example.

    https://www.ads-software.com/support/topic/automatic-redirection-to-child-site-from-main?replies=15

    However, my custom plugin does not contain $current_user and none of the functions to get the current user work.
    The other functions I have built work no problem, so I know there is nothing wrong with the file getting included.

    Any help would be much appreciated.
    Thanks
    Mark

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter willcowd

    (@willcowd)

    Hi all

    I’m very sorry to bump this, but I could really so with some help.

    Thanks
    Mark

    Thread Starter willcowd

    (@willcowd)

    Hi All

    I’ve added in

    require_once( ABSPATH . ‘wp-blog-header.php’);

    but as I thought it gives a fatal error

    Fatal error: Call to a member function main() on a non-object in /home/willcowd/public_html/wp-includes/functions.php on line 798

    Any ideas would be great.

    Thread Starter willcowd

    (@willcowd)

    Hi All

    I managed to get there in the end. This is the code, just in case it helps someone.

    function check_if_user_needs_redirecting(){
    		$active_blog = get_active_blog_for_user(get_current_user_id());
    		$blogid = get_current_blog_id();
    		if ($blogid != $active_blog->blog_id){
    			header('Location: '.$active_blog->siteurl.'/wp-admin/');
    			exit;
    		}
    	}
    	add_action( 'init', 'check_if_user_needs_redirecting' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘MU-Plugin get user info’ is closed to new replies.