WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. frostfairs
    Member
    Posted 1 year ago #

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

  2. Rajesh Soni
    Member
    Posted 1 year ago #

  3. frostfairs
    Member
    Posted 1 year 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 1 year 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
    Member
    Posted 1 year ago #

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

  6. frostfairs
    Member
    Posted 1 year ago #

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

  7. Rajesh Soni
    Member
    Posted 1 year ago #

    You're welcome.

    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic