MarketPress - Wordpress user roles - shopper vs store owner

Running Multisite with Marketpress and Gridmarket
I’m making great progress with my new marketplace, but I’ve run into what I think is a simple problem I can’t solve. When a new person chooses to register for my marketplace of stores, they are given two options. Either “I want to set up a store” OR “I just want to browse.” See lines at about 253 - 276 in custom-wpsignup.php (I modified the language a bit).
When they choose set up a store, all works well. When then choose “just browse” they get login credentials as they should. But this login takes them to an empty WP dashboard. They should never see a WP dashboard. Instead they should go directly to my global Marketplace site. I believe this has to do with their WP user role. I believe Marketpress assigns subscriber to the shopper and administrator to a store (subsite) owner. Please correct me if I’m wrong.
I do have the User Role Editor plugin installed but have not network activated or configured it yet. I plan to go to Pro version of URE to restrict capabilities of store owners. However, I first need to make sure subscribers (shoppers) are taken directly to my marketplace of stores when they log in and not to an empty WP dashboard .
Thanks for your help!

  • Andy
    • Design Lord, Child of Thor

    Thanks for the quick reply Vaughn. I checked info on the first suggestion. But won't this redirect all logins, including store owners? When they log in they should be taken to their own store dashboard.

  • Andy
    • Design Lord, Child of Thor

    Have tried Peter's Login Redirect but no joy. Ignored my setting to send Subscribers to my Marketplace URL instead of the WP dashboard. Discovered the plug-in is not multisite compatible - network activated doesn't work so each subset needs to activate individually (from support site for the plugin).

    I'm considering a different approach. Don't show the non-store owners a WP login. I removed the link in the new user account setup email by simply changing the content in the welcome user email in Network Admin > Settings > Network Settings. I can add a link to my Marketplace there.
    Now I believe I could modify line 121 of wp-activate.php to eliminate the login link that shows up on the resulting "Your account is now active!" webpage. However, this is a WP core file so any changes will be overwritten in the next WP upgrade, plus I know we should not play with the core. I read that "anything you want to change in the login workflow can be done with hooks and filters" but I'm hoping there is something simpler. Suggestions?

  • Andy
    • Design Lord, Child of Thor

    Reference - http://wpscholar.com/blog/wordpress-user-login-redirect/
    If administrator go to login screen, if not go to Marketplace home page.
    I'm no code expert but would it be possible to employ a function such as this one (which when added to functions.php causes a blank screen):

    function my_login_redirect( $url, $request, $user ){
    if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
    if( $user->has_cap( 'administrator' ) ) {
    $url = network_site_url();
    } else {
    $url = network_home_url();
    }
    }
    return $url;
    }

    add_filter('login_redirect', 'my_login_redirect', 10, 3 );

  • Vaughan
    • Support/SLS MockingJay

    Hi tony,

    This function works fine as is on multisite, you need to add it to a mu-plugin functions.php

    create a file called functions.php

    Place this code in the file

    <?php
    function my_login_redirect( $url, $request, $user ){
        if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
            if( $user->has_cap( 'administrator' ) ) {
                $url = network_site_url();
            } else {
                $url = network_home_url();
            }
        }
        return $url;
    }
    
    add_filter('login_redirect', 'my_login_redirect', 10, 3 );

    make sure <?php is on the very first line with no spaces in front of it.

    Then upload this file to /wp-content/mu-plugins/

    If /mu-plugins does not exist, create it.

    Hope this helps

  • Vaughan
    • Support/SLS MockingJay

    Hi,

    This one should do the trick for you.

    /**
     * Redirect user after successful login.
     *
     * @param string $redirect_to URL to redirect to.
     * @param string $request URL the user is coming from.
     * @param object $user Logged user's data.
     * @return string
     */
    function my_login_redirect( $redirect_to, $request, $user ) {
    	//is there a user to check?
    	global $user;
    	if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    		//check for admins
            if ($user->has_cap('manage_network')) {
                return network_admin_url();
            }
    		if ( in_array( 'administrator', $user->roles ) ) {
    			// redirect them to the default place
    			return $redirect_to;
    		} else {
    			return network_home_url();
    		}
    	} else {
    		return $redirect_to;
    	}
    }
    
    add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

    Super-admins will be redirected to the network http://domain.com/wp-admin/network

    Administrators will be redirected to the default page (usually the one they were viewing before logging in)

    Users should be redirected to the main network home URL or the main site.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.