When logging in how to redirect users to their store

Thank you for your quick reply.
The users should be redirected to their store when they log in.
Right now, they are being redirected to:
http://www.creativechinese.com/sarah/ - which looks like the Dashboard for a user - Sarah, and not their store.
Any ideas of what I am doing wrong?
Thank you,
Shaz
http://www.creativechinese.com

  • Michael Bissett
    • Recruit

    Hey @Shaz, hope you're doing well today! :slight_smile:

    I tried registering for an account on your site, and logging in, but I wasn't sent to that page, though I did notice that you had a different one specified inside of the settings for the plugin.

    However, I should note that you've got the plugin network activated at present, which isn't going to give you the results you're looking for, since that should send users off to the main site.

    Have you tried enabling the plugin on each subsite, and seeing if the redirect works properly when the redirect is configured for each site?

    Please advise,
    Michael

  • Shaz
    • WPMU DEV Initiate

    Hello,
    Thanks for getting back to me.
    Unfortunately, I am not sure how to do what you suggested - the redirection once logged in.
    This is the first time I have used multi sites.
    Sorry to bother you, but can you give me the exact URL all users should be directed to once logged in?
    http://www.creativechinese.com
    I appreciate any help you can give.
    Thanks,
    Shaz

  • Ash
    • WordPress Hacker

    Hello @Shaz

    I hope you are well today. Would you please try the following code?

    function go_to_primary_blog($redirect_to, $request, $user){
    	$user_info = get_userdata($user->ID);
    	return get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin';
    }
    add_filter("login_redirect", "go_to_primary_blog", 10, 3);

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • Shaz
    • WPMU DEV Initiate

    Please let me know how to get my site up. Thanks.

    This is what the functions.php looks like:
    <?php
    add_action( 'after_setup_theme', 'gridmarket_setup', 10 );
    function gridmarket_setup() {

    global $content_width;
    if ( ! isset( $content_width ) ) {
    $content_width = 720;
    }
    function framemarket_enqueue_styles(){
    $version = '1.4';

    global $bp_existed;

    if ( (!is_admin())&& ($bp_existed == 'true') ) {
    wp_enqueue_style( 'buddypress-default', get_template_directory_uri() . '/buddypress/bp-default.css', array( 'framemarket' ), $version);
    }

    if ( !is_admin() ) {
    wp_enqueue_style( 'framemarket', get_template_directory_uri() . '/css/framemarket.css', array(), $version);

    wp_enqueue_style( 'gridmarket', get_stylesheet_directory_uri() . '/css/grid.css', array( 'framemarket' ), $version);

    $themename = wp_get_theme();
    $themeinput = $themename . '_styleinput';

    $options = get_option('framemarket_theme_options');
    $stylesheet = isset($options[$themeinput]) ? $options[$themeinput] : '';

    if ($stylesheet != ""){
    wp_enqueue_style( 'gridmarket_style', get_stylesheet_directory_uri() . '/styles/' . $stylesheet . '.css', array( 'framemarket' ), $version);

    }
    else{
    wp_enqueue_style( 'gridmarket_orange', get_stylesheet_directory_uri() . '/styles/darkorange.css', array( 'framemarket' ), $version);
    }

    wp_enqueue_style( 'gridmarket_custom', get_stylesheet_directory_uri() . '/css/custom.css', array( 'framemarket' ), $version);
    }

    }

    function gridmarket_widgets_init() {
    register_sidebar(
    array(
    'name' => __( 'Footer one', 'framemarket' ),
    'id' => 'footer-one',
    'description' => 'Footer one',
    'before_widget' => '<div id="%1$s" class="footer-widget side widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
    )
    );
    register_sidebar(
    array(
    'name' => __( 'Footer two', 'framemarket' ),
    'id' => 'footer-two',
    'description' => 'Footer two',
    'before_widget' => '<div id="%1$s" class="footer-widget side widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
    )
    );
    register_sidebar(
    array(
    'name' => __( 'Footer three', 'framemarket' ),
    'id' => 'footer-three',
    'description' => 'Footer three',
    'before_widget' => '<div id="%1$s" class="footer-widget side widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
    )
    );
    register_sidebar(
    array(
    'name' => __( 'Footer four', 'framemarket' ),
    'id' => 'footer-four',
    'description' => 'Footer four',
    'before_widget' => '<div id="%1$s" class="footer-widget side widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
    )
    );
    register_sidebar(
    array(
    'name' => __( 'Footer five', 'framemarket' ),
    'id' => 'footer-five',
    'description' => 'Footer five',
    'before_widget' => '<div id="%1$s" class="footer-widget side widget %2$s end">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
    )
    );
    }

    function go_to_primary_blog($redirect_to, $request, $user){
    $user_info = get_userdata($user->ID);
    return get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin';
    }
    add_filter("login_redirect", "go_to_primary_blog", 10, 3);
    ?>

  • Ash
    • WordPress Hacker

    As you are in multisite, please use the following code as mu-plugin:

    <?php
    function go_to_primary_blog($redirect_to, $request, $user){
    	$user_info = get_userdata($user->ID);
    	return get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin';
    }
    add_filter("login_redirect", "go_to_primary_blog", 10, 3);

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Would you please send me your admin login and ftp details to me?

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash
    Details: Send all required details (admin info and ftp details) with a link of this thread, so that I can track.
    Also post a note here once you send the info.

    I will be happy to take a look :slight_smile:

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Your site is back now and I have the code in mu-plugins. Would you please check the redirect issue for subsite user?

    Please delete all caches before testing.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.