WordPress.org

Forums

[resolved] How to restrict subscribers to access the dash board? (7 posts)

  1. frostfairs
    Member
    Posted 2 years ago #

    How can i restrict the users to access the dash board who have the role of subscriber?

  2. Rajesh Soni
    Member
    Posted 2 years ago #

  3. frostfairs
    Member
    Posted 2 years ago #

    There is a snippet in codex which restricts all the users else Administrator. Is there any way we could accomplish by tweaking that snippet rather than using Plugin? thanks.

  4. Rajesh Soni
    Member
    Posted 2 years ago #

    Sure you could try this:

    function restrict_admin_with_redirect() {
    	if ( ! current_user_can( 'edit_posts' ) && $_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' ) {
    		wp_redirect( site_url() ); exit;
    	}
    }
    
    add_action( 'admin_init', 'restrict_admin_with_redirect' );
  5. catacaustic
    very awesome
    Posted 2 years ago #

    Yes you can. Just add that code to your theme's functions.php file and it will be used.

  6. frostfairs
    Member
    Posted 2 years ago #

    Thank you so much guys. This works for me. Thanks you all.

  7. Rajesh Soni
    Member
    Posted 2 years ago #

    You're welcome.

    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic