Skip Navigation

[Resolved] WP-Cred login form: redirects based on different member roles

This support ticket is created 7 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Tia 7 years, 7 months ago.

Assisted by: Tia.

Author
Posts
#431714

Hi there,

We're testing with the wp-views login forms.

We want to reach the next thing:
We have 3 types of user roles: admin / client / user

We want to redirect after login based on this role:
admin => .../wp-admin
client => .../my-account
user => .../my-profile

Is this possible and how can we reach this?
Thanks.

Paul

#431983

Tia

Thank you for contacting Toolset Support. I am happy to help you with this.

There is no direct way to do this with a conditional but I suggest creating a custom filter with WordPress native functions:
https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

/**
 * 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?
	if ( isset( $user->roles ) && is_array( $user->roles ) ) {
		//check for admins
		if ( in_array( 'administrator', $user->roles ) ) {
			// redirect them to the default place
			return $redirect_to;
		} else {
			return home_url();
		}
	} else {
		return $redirect_to;
	}
}

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

Please let me know if this resolves your question or if it needs more investigation.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.