Skip Navigation

[Resolved] Logged in cookie set, want to redirect from wp-admin based on custom user role

This support ticket is created 6 years, 4 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1124073

I have a custom user role that only has access to one CPT.

When the user logs in, they are redirected to the "All CPT" list.

The user closes the window, then later goes to domain.tld/wp-admin/ where they see "Sorry, you are not allowed to access this page."

I would like them to be redirected to the "All CPT" list as they are when they login.

#1124357

Hello,

There isn't such a built-in feature within Toolset, it needs custom codes, here is my suggestion, when user goes to domain.tld/wp-admin/, you can use wordpress action hook admin_init to trigger a custom PHP function
https://developer.wordpress.org/reference/hooks/admin_init/

In this PHP function, get current user's role
https://wordpress.stackexchange.com/questions/5047/how-to-check-if-a-user-is-in-a-specific-role

Then redirect him to the specific URL:
https://developer.wordpress.org/reference/functions/wp_redirect/