I'm using this function to prevent users apart from admin from getting to the backend of wordpress. (Note, that addition to allow ajax requests too):
add_action( 'init', 'my_block_users' );
function my_block_users() {
$isAjax = (defined('DOING_AJAX') && true === DOING_AJAX) ? true : false;
if(!$isAjax) {
if ( is_admin() && ! current_user_can( 'administrator' ) ) {
wp_redirect( home_url() );
exit;
}
}
}
Trouble is, it causes an http error when uploading images etc. Does anyone know a work around for this? Thanks!