Preventing Users From Accessing wp-admin

Posted by Gary Pendergast on Oracle Blogs See other posts from Oracle Blogs or by Gary Pendergast
Published on Sat, 18 Jun 2011 22:58:45 -0700 Indexed on 2011/06/20 16:32 UTC
Read the original article Hit count: 449

Filed under:
|

If you have a WordPress site that you allow people to sign up for, you often don’t want them to be able to access wp-admin. It’s not that there are any security issues, you just want to ensure that your users are accessing your site in a predictable manner.

To block non-admin users from getting into wp-admin, you just need to add the following code to your functions.php, or somewhere similar:

add_action( 'init', 'blockusers_init' );
 
function blockusers_init() {
	if ( is_admin() && ! current_user_can( 'administrator' ) ) {
		wp_redirect( home_url() );
		exit;
	}
}

Ta-da! Now, only administrator users can access wp-admin, everyone else will be re-directed to the homepage.

© Oracle Blogs or respective owner

Related posts about Wordpress

Related posts about hack