Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to turn off admin panel for authors and subscribers.

Is there any secure way to keep them away from admin panel?

share|improve this question
Hi, welcome to WPSE! Please, take a look at the following apps so you can easily follow your questions and answers in all StackExchange sites: stackapps.com :) – brasofilo May 31 '12 at 1:27

1 Answer

Notice: I am not security expert, so cannot say any of this methods are secure.

Use this if you want to completely block the access to the Admin panel:
(copy the code to your functions.php theme file)

 /*
 * Hide the admin bar in the front end 
*/
add_filter('show_admin_bar', '__return_false');

 /*
 * Redirects Authors and Subscribers to the site front page using: get_home_url()
*/
add_action('admin_init','wpse_53675_block_users');
function wpse_53675_block_users()
{
    if( !current_user_can( 'delete_pages' ) ) // blocks authors, contributors and subscribers
    {   
        wp_redirect( get_home_url(), 301 ); 
        exit;
    }
}


Or use this other one if you want the users to have access only to their profile page:

  /*
  * Redirect Authors and Subscribers to the site front page
 * Except if viewing the Profile page
*/
add_action('admin_init','wpse_53675_block_users');
function wpse_53675_block_users()
{
    global $pagenow;
    if( 'profile.php' == $pagenow ) return;

    if( !current_user_can('delete_pages') ) 
    {   
        wp_redirect( get_home_url(), 301 ); 
        exit;
    }
}

  /*
  * Hide all menus from the Admin panel
 * Except the profile item
*/
add_action('admin_menu', 'wpse_53675_remove_admin_menus', 999);
function wpse_53675_remove_admin_menus() {
    if( !current_user_can('delete_pages') ) 
    {
        remove_menu_page('index.php');
        remove_menu_page('edit.php');
        remove_menu_page('upload.php');
        remove_menu_page('link-manager.php');
        remove_menu_page('edit.php?post_type=page');
        remove_menu_page('edit-comments.php');
        remove_menu_page('tools.php');
    }
}

Plugins of interest

Maybe a more secure way would be manipulating roles and capabilities.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.