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;
 }
}
  • 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 Nov 24 '14 at 16:40
1

Following plugin can help you better and quick :

https://wordpress.org/plugins/user-role-editor/
  • thanks for your answer but i want do it without plugin if possible. – Vektor Unbreakable Nov 24 '14 at 12:59
  • I check this plugin and don't work with i want – Vektor Unbreakable Nov 24 '14 at 13:02
  • As far as I know , plugin allows all type of restriction setup. – Helping Hands Nov 24 '14 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. – Vektor Unbreakable Nov 24 '14 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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