0

Iuse this code for restrict access to wordpress admin. But now i must allow access to author too. Only for this roles. Is possible with this code? Really thanks

add_action( 'init', 'blockusers_init' );
function blockusers_init() {
 if ( is_admin() && !current_user_can( 'author' ) && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
 wp_redirect( home_url() );exit;
 }
}
1
  • One thing I noticed is that you are using the role in a check meant for capabilities. The codex specifically says not to do this. Change 'author' to 'publish_posts' before continuing?
    – SkyShab
    Commented Nov 24, 2014 at 16:40

1 Answer 1

1

Following plugin can help you better and quick :

https://wordpress.org/plugins/user-role-editor/
4
  • thanks for your answer but i want do it without plugin if possible. Commented Nov 24, 2014 at 12:59
  • I check this plugin and don't work with i want Commented Nov 24, 2014 at 13:02
  • As far as I know , plugin allows all type of restriction setup. Commented Nov 24, 2014 at 13:05
  • But i want that user can't go to admin page. Not change capatibilities. And this plugin don´t work with this. This code work, but only with one role. I need use this with two roles. Commented Nov 24, 2014 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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