Created
          November 1, 2017 01:15 
        
      - 
      
- 
        Save ricardobrg/9f0f1c053640c9725b39dbc1970d523d to your computer and use it in GitHub Desktop. 
    WP block wp-admin based in user role
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| add_action( 'init', 'blockusers_init' ); | |
| function blockusers_init() { | |
| //check if user is administrator | |
| if (! current_user_can( 'administrator' ) ){ | |
| //check if it's wp-admin and not ajax calls | |
| if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { | |
| //redirect to home | |
| wp_redirect( home_url() ); | |
| //exit after redirect is required | |
| exit; | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment