Support » Plugins » Restricting non admin to Dashboard

  • There is a situation here. I’ve tried the following code to prevent the non admins to access the dashboard.

    add_action('admin_init', 'no_mo_dashboard');
    function no_mo_dashboard() {
      if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
      wp_redirect(home_url()); exit;

    and this as well..

    function baw_no_admin_access()
    if( !current_user_can( 'administrator' ) )
    wp_redirect( home_url() );
    add_action( 'admin_init', 'baw_no_admin_access', 1 );

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Both codes are doing what they are supposed to. But one unusual behavior I noticed that the non admins are not able to post anything. Neither any posts nor any comments of non admins are posted. What’s wrong ?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Restricting non admin to Dashboard’ is closed to new replies.