Skip to content
Advertisement

wordpress redirect users to the same URL they request appending parameters according to role

I am working on a WordPress website with multiple roles. My target is to redirect user with a specific role when they request pages like orders in the admin area to go to a filtered URL having their id.

example: User requests: www.site.com/wp-admin/edit.php?post_type=shop_order

JavaScript

This Applies only to the role “tester”

My Approach was:

JavaScript

Rewriting the code now gave me error, Although when I was testing it it just worked but the problem was that user receives error: Too many redirects.

I really need help with this, So any suggestions would be appreciated. Thanks in advance.

Advertisement

Answer

The problem is with user_has_cap filter in which user capabilities are required to return. In your code, you are redirecting the tester user without passing capabilities so instead, you should use admin_init action in order to redirect the user.

JavaScript

The above code is tested and working fine!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement