How to prevent users to get to the admin panel?

6.24K viewsCore
0

Hi,

Everything needed is accessible in front-end (profile, post question, post answer, modify these…). By the way this website is not sending me to the admin panel after connexion nor to ask this question.

So I wonder why mine is doing it and if I have done anything wrong in the settings.

Many thanks in advancefor your help (eventually by mp?)

Sincerely,

Thierry

0

OOps,

Found a partial solution, adding this to functions.php:

/**
* Block access to admin panel (to everybody except admin)
*/

add_action( ‘init’, ‘blockusers_init’ );
function blockusers_init() {
if ( is_admin() && ! current_user_can( ‘administrator’ ) &&
! ( defined( ‘DOING_AJAX’ ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}

You are viewing 1 out of 3 answers, click here to view all answers.