This little handler will also prevent access to profile and dashboard unless you are an admin.
It is handy if you're not using WordPress to handle your users.
1.
function
prevent_admin_access() {
2.
if
(
strpos
(
strtolower
(
$_SERVER
[
'REQUEST_URI'
]),
'/wp-admin'
) !== false && !current_user_can(
'administrator'
)) {
3.
wp_redirect(get_option(
'siteurl'
));
4.
}
5.
}
6.
7.
add_action(
'init'
,
'prevent_admin_access'
, 0);
Great little snippet. Just paste it into your themes functions.php file and away you go!
[ Source ]