Skip Navigation

[Resolved] Prevent user access to WordPress dashboard

This support ticket is created 4 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by michaelR-26 4 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1670173

I have a custom role named Exhibitor and have set up front end forms for them to use to access their account details, create new Exhibitor pages etc...

You can see that here hidden link
login: service@zeeweb.com
pass: %MxB(HkW%B3VQjv4AK@THR$#

It all seems to work well, but this same user can access the WordPress dashboard here hidden link.

How can I prevent this user role from accessing the dashboard?

Probably something simple I just overlooked!

Your help is appreciated...:-)

#1671771

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to add the following hook to your theme's functions.php file
or
You can add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

 function func_no_admin_access() {
    $redirect = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : home_url( '/' );
    global $current_user;
    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    if($user_role === 'exhibitor'){
        exit( wp_redirect( $redirect ) );
    }
 }
add_action( 'admin_init', 'func_no_admin_access', 100 );

Where please adjust the role slug exhibitor if required.

#1672411

My issue is resolved now. Thank you!