Restrict Multisite Users from accessing wp-admin pages even outside ClassiPress
I have a Multisite installation where each of the sub-sites uses the ClassiPress theme, but the main site does not.
I wanted to restrict users that were logged in on the network, from accessing anything within the
wp-admin/ directory of the main site. By default, even if they signed "up" through a ClassiPress site, they can access a user dashboard via
wp-admin/ on the main site.
ClassiPress's "Restrict Back-office Access" setting can be used to prevent users from accessing
wp-admin/ within a ClassiPress site, but that particular setting doesn't have any effect on my main site.
Here is how I accomplished it. Note: this code was written by someone else (not me), and I found it here:
http://pento.net/2011/06/19/preventi...sing-wp-admin/
I added this to my main blog's functions.php file:
PHP Code:
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) ) {
wp_redirect( home_url() );
exit;
}
}
Once I added that code, users who tried to access
wp-admin/ directory on my main site were forwarded to the main site's homepage instead.