Bloquer l’accès à l’administration

Une fonc­tion à rajou­ter dans le fichier functions.php de votre thème pour empê­cher les non-admin d’ac­cé­der à la partie admi­nis­tra­tion. Vous pouvez modi­fier le rôle pour adap­ter aux non-auteurs, non-éditeurs etc… !current_user_can('edit_posts')
Trou­vé sur WPChan­nel.

Code

/* Bloquer accès aux non-admins */
function wpc_block_dashboard() {
  $file = basename($_SERVER['PHP_SELF']);
  if (is_user_logged_in() && is_admin() && !current_user_can('edit_posts') && $file != 'admin-ajax.php') {
    wp_redirect( home_url() );
    exit();
  }
}
add_action('init', 'wpc_block_dashboard');

If you have found a spel­ling error, please, noti­fy us by selec­ting that text and pres­sing Ctrl+Enter.

Ce site embarque des cookies pour vous offrir la meilleur expérience possible

Spelling error report

The following text will be sent to our editors: