Role Redirection

This topic contains 7 replies, has 3 voices, and was last updated by  Alex Rollin 1 year, 5 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #8044

    gowrann
    Free User
    Post count: 39

    HI,

    I have UsersWP and GeoDirectory – I have the default ‘subscriber’ role redirect to the profile page on login as configured in UsersWP settings.

    I have another role ‘parent’ which I want to redirect to another URL on the site.

    I have tried code…

    	
    
    add_filter( 'login_redirect', 'tr_parent_login_redirect', 1, 3 );
    	/**
    	 * 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 tr_parent_login_redirect( $redirect_to, $request, $user ){
    
    		//is there a user to check?
    
    		if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    
    			//check for admins
    			if ( in_array( 'parent', $user->roles ) ) {
    
    				$redirect_to = '/tutors/'; // Your redirect URL
    			}
    		}
    

    And also tried the Peters Redirect Plugin but both fail and the ‘parent’ role is redirected to the same as the ‘subscriber’ role profile page.

    How can I get around this?

    #8049

    Alex Rollin
    Moderator
    Post count: 27815

    Sorry, we don’t have per-role redirects at this time, but I will take this up as a feature for the developers to consider for future versions.

    I will ask the developers to take a look at your code to see if there is a quick fix.

    #8051

    gowrann
    Free User
    Post count: 39

    Thanks Alex – appreciate that – please let me know if they have a work around

    #8069

    Patrik
    Moderator
    Post count: 1971

    Hi,

    Can you try following code?

    add_filter('uwp_login_redirect', 'uwp_login_redirect_cb', 10, 4);
    function uwp_login_redirect_cb($redirect_to, $redirect_page_id, $data, $user){
    	if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    
    		//check for admins
    		if ( in_array( 'administrator', $user->roles ) ) {
    
    			$redirect_to = admin_url(); // Your redirect URL
    		}
    	}
        return $redirect_to;
    }

    Regards,
    Patrik

    #8070

    gowrann
    Free User
    Post count: 39

    Hi Patrick,

    Thanks that filter works perfect – my only remaining question is how to register a user with a different user role via UsersWP for use in GEODirectory https://wpgeodirectory.com/support/topic/fundamental-workflow-issue/

    Can you give me any ideas?

    #8072

    Patrik
    Moderator
    Post count: 1971

    Hi,

    This needs customization and also we are planning for the membership addon which will include this. What you can do is using a similar code for the hook ‘uwp_after_process_register’ using wp_redirect().

    Regards,
    Patrik

    #8077

    gowrann
    Free User
    Post count: 39

    Hi Patrick, can you elaborate a bit more on that with the hook, uwp_after_process_register

    So I have a 2nd role that requires basic registration to view listings.

    The first role is already set up in UsersWP with some custom fields and works fine, it’s the 2nd role I need a registration option.

    Thanks

    #8085

    Alex Rollin
    Moderator
    Post count: 27815

    Hello,

    we are working on an addon for this and many other features.

    For now what you are asking for requires your own customization.

    If you need hands on help you will need to hire a developer.

    You can find help here: https://geodirectoryexperts.com/experts/

Viewing 8 posts - 1 through 8 (of 8 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket