Advertisement
arie_cristianD

only allowing admin and editor to access admin dashboard

Jul 2nd, 2025
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.34 KB | None | 0 0
  1. add_action(
  2.     'admin_init',
  3.     function () {
  4.         if ( ! current_user_can( 'edit_others_posts' ) && ! defined( 'DOING_AJAX' ) ) {
  5.             wp_redirect( home_url() );
  6.             exit;
  7.         }
  8.     }
  9. );
  10.  
  11.  
  12. add_filter(
  13.     'show_admin_bar',
  14.     function ( $show ) {
  15.         if ( ! current_user_can( 'edit_others_posts' ) ) {
  16.             return false;
  17.         }
  18.         return $show;
  19.     }
  20. );
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement