Sauter la navigation

[Résolu] Prevent user access to WordPress dashboard

This support ticket is created Il y a 4 années et 11 mois. 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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par michaelR-26 Il y a 4 années et 10 mois.

Assisté par: Minesh.

Auteur
Publications
#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 lien caché
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 lien caché.

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

Probably something simple I just overlooked!

Your help is appreciated...:-)

#1671771

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: 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!