Skip to content

Instantly share code, notes, and snippets.

@smileBeda
Created December 9, 2020 12:46
Show Gist options
  • Save smileBeda/883529d0f7a6be8993826f17db974d97 to your computer and use it in GitHub Desktop.
Save smileBeda/883529d0f7a6be8993826f17db974d97 to your computer and use it in GitHub Desktop.
add_action('init','safe_remove_backend_admin_access_for_role');
function safe_remove_backend_admin_access_for_role(){
if( current_user_can('editor') || current_user_can('administrator') )//Your roles
return;
if( is_admin() && !defined('DOING_AJAX') ){//IMPORTANT! Front end AJAX events are excluded...
if(isset( $_GET[ 'action'] ) && 'trash' == $_GET[ 'action'])//Perhaps you have a call to some WP Admin Operation that needs whitelisting...
return;
wp_redirect( home_url() );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment