This is what i am using;
add_action('init', 'blockusers_init');
function blockusers_init() {
if (is_admin() && !current_user_can('administrator') &&
!(defined('DOING_AJAX') && DOING_AJAX)) {
wp_redirect(home_url());
exit;
}
}
It’s possible the best one.
EDIT : You need a custom login page for reach wp-admin
. This code redirect to homepage if you enter directly to wp-admin
.
Related Posts:
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- Customize Admin Users Screen based on Role
- Make certain pages uneditable by editors?
- Shared account / dual blogging in WordPress
- Redirect admin 403 “Cheatin uh?” admin pages
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- How should I setup the “Users” area to hand over to a client?
- Different role for free and pro users in wordpress without using bbpress
- How do I remove dashboard access from specific user roles?
- Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
- Can an admin check passwords of registered users?
- How to obtain the user ID of the current profile being edited in WP-Admin?
- Prevent author from changing their posts if admin has modified
- Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
- How to remove administrator role in settings -> general -> New User Default Role?
- Create un-removeable user
- Custom CSS In Admin Only For Certain Roles
- Remove ability to access certain admin menus
- Remove admin AND editor from the “change role to” menu in user listing
- Hide update messages from non-admin users?
- Customize the upload screen
- Add extra field when admin create user
- Add a custom column in users list page
- Blocking Administrative Access to Authors and Subcribers?
- wp-admin: Sort users by surname
- Add User meta fields, which only admin can edit
- How to display only logged in user’s post comments in comments area
- Add Admin User via SQL
- Can you have the users list pre sorted by specific column?
- How to remove Gravatar from Username column
- How do I enable new account notification emails (to the administrator)?
- Restrict dashboard access for specific user roles to specific actions
- In administration, how do I display comments of a certain user?
- New users must comment when requesting username
- user-new.php less detailed after WP3.1; how to revert?
- WordPress stripping html and script tags from some admin users on save
- How can I restore admin capabilities?
- $user_id vs. is_user_logged_in()
- Get current logged in user under 3.1, re: remove “Howdy”
- Hide everything on site for visitors except specific page IDs
- What determines whether admin toolbar is shown to a logged-in user?
- Manage users custom column add class “num”
- Can user #1 (the initial user) be deleted without ill effect?
- How to restrict the editors from viewing/editing pages created by admin?
- Hide one admin from another admin
- How do you set up a WordPress blog with multiple authors to allow something like StackExchange’s “community wiki” feature?
- Displaying different in-page content to cliente/admin
- Admin role not really admin
- WordPress Remove Submenus
- How can I make the user names of commentors clickable links to the user’s profile from the admin comment screen?
- Keep Logged in Users out of Admin Panel
- Only Admin can Edit, Delete or Update
- add_cap for editor but no admin role
- Bind custom role to admin page
- remove menus for a specific role?
- I’m a super admin and I want to give an admin the ability to add new users…?
- Allow admins to login as other users
- current_user_can(‘administrator’) not working in custom login
- Show global Message in User Profiles with admin only Input field in WordPress Backend
- How to make sure your admin doesn’t hi-jack you site?
- Remove specific administrator’s capability
- Plugin permissions for Editor role
- solution to prevent specific admins from altering site contents
- Admin user roles/permissions
- How to show a custom notification to a specific user?
- Posts in sidebar only by admin
- Want to know who is login Admin/User
- Control Users listed in Users List on dashboard
- How should I change the username of or delete the admin user?
- Prevent Registration Where Role is None?
- Extending the user profile [closed]
- Newly created user role not displaying on users screen
- Redirect non-admin after login, and in url – /admin
- When admin approves a registered user, I don’t want to send a notification email to users
- How can I create multiple different admin roles with their own capabilities
- Is it possible to create a custom admin page for users?
- Custom redirection when managing users in admin
- Defined user role to access plugin’s pages
- Front end login and page restriction
- Assign a category by user and customize the edit-tags.php?taxonomy=category page
- Forbid certain users to access a specific page
- You do not have permission to access this document on form submit
- Different customer login form than administrator login form?
- Add a user to edit the layout of a site
- If the current user is an administrator or editor
- How to check if a user is in a specific role?
- What are the standard admin CSS id/class tags?
- Getting a List of Currently Available Roles on a WordPress Site?
- Editor can create any new user except administrator
- Admin Ajax is returning 0
- Add custom column to Users admin panel
- wp_verify_nonce vs check_admin_referer
- Add a Separator to the Admin Menu?
- How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?
- how to know if admin is in edit page or post [duplicate]
- Modal window from within WordPress admin
- Where in WP can I check history or log of updates of plugins etc?
- Admin Page Redirect
- How to allow an user role to create a new user under a role which lower than his level only?
- Adding a custom admin page