Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to restrict user's(subscribers only) from dashboard ?


  • Shahzaib Sabir
    Participant

    @shahzaib147

    I found a snippet from wordpress codex to restrict user’s from dash board. This block access to the admin panel for users that do not have the Administrator Role. Is there any way that we may tweak the snippet to block access for the users that are subscribers only?

    Because the above snippet restricted the access to all the users(Author, Editor, etc) but i want to restrict this for the subscribers only.

Viewing 4 replies - 1 through 4 (of 4 total)

  • bp-help
    Participant

    @bphelp


    Unsal Korkmaz
    Participant

    @unsalkorkmaz

    function restrict_admin(){
    	//if Subscriber or low, kill WordPress execution and provide a message
    	if ( ! current_user_can( 'edit_posts' ) ) {
    		wp_die( __('You are not allowed to access this part of the site') );
    	}
    }
    add_action( 'admin_init', 'restrict_admin', 1 );

    Is this ok for you?


    Shahzaib Sabir
    Participant

    @shahzaib147

    @unsalkorkmaz This really works. thank you so much but can we add a redirect element in this code? plz.


    Shahzaib Sabir
    Participant

    @shahzaib147

    oopss the user(subscriber) could not post anything, even could not update his status by applying this code. Is there any alternative solution? i do not want to try plugins. plz.

    `function restrict_admin(){
    //if Subscriber or low, kill WordPress execution and provide a message
    if ( ! current_user_can( ‘edit_posts’ ) ) {
    wp_die( __(‘You are not allowed to access this part of the site’) );
    }
    }
    add_action( ‘admin_init’, ‘restrict_admin’, 1 );`

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to restrict user's(subscribers only) from dashboard ?’ is closed to new replies.
Skip to toolbar