You can simply check if the user has an specific role, and redirect them to homepage if they try to access the admin panel.
function redirect_to_front(){
// Check if we are on the admin panel, and the user is not an admin
if( is_admin() && !current_user_can( 'administrator' ) ){
// Redirect them back to front
wp_safe_redirect( site_url() );
exit();
}
}
add_action('init', 'redirect_to_front');
This is just an example. You should alter the code, and change the capabilities to fit your purpose. The current_user_can()
function accepts both capability and roles.
Related Posts:
- How to keep track of user logins?
- My custom page template with is_user_logged_in() does not detect that I’m logged in
- Replacing the WordPress password validation
- WordPress auto login after registration not working
- Allow up to 5 Concurrent Login Sessions
- Why does is_user_logged_in() return false after redirect from another site?
- Pre-populate Username Field
- Get user info outside WordPress
- How can I secure a WordPress blog using OpenID from a single provider?
- Is it possible to get a user with just the password field?
- Redirect after login based on user role (custom login page)
- Check for user meta data at Login
- Redirect User to Homepage if no other redirect is specified
- Use phpbb user database for WordPress
- WordPress to use Drupal users’ credentials
- Best way to have an per-user customized private section
- Share user table from WP with Drupal
- How can I allow password reset based on logins containing the @ character?
- A way to count logged in users and display count?
- stop login if user_status equal zero
- Redirect user to login before viewing custom post
- Change the user_login at registration
- Max no of simultaneous active sessions for a single user
- When I try to login in wordpress it is showing “USER Doesn’t Exists”
- Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
- Redirect subscribers to last viewed page after log-in
- wordpress disable login for unverified user
- Reset Password policy
- Rewrite Rules and Login Issue
- Is possible to allow user to login with different role?
- Use WordPress Login for a non-wordpress site
- WordPress Login Customization for External Authentication
- Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
- Is there any action /filter hook I can use to disable login for some user role?
- How to check User Role and redirect to specific page according to Role when login in WordPress?
- Display video on homepage for users who have not logged in
- How do you manage your pages or functions that require logged-in users?
- How can i login with user’s password in WordPress being an admin?
- Delete a user from frontend
- Check if user is logged in via JS? [duplicate]
- Use members from 1 site on another one
- Can I edit the database to change a login?
- how redirect users to custom login page when “login to reply” is clicked? [duplicate]
- User(s) already exists show error please provide a valid username
- wp_generate_password sets password but can’t login using created password
- add class to element if user is not logged in [closed]
- Is there a way to call via javascript if a user is logged-in on a static html file?
- Restricting wordpress login sessions for a web app
- How to connect wordpress user with my own APP user?
- How to change default username field after login
- The same session information for peer users on two different WordPress servers
- WP users cant reset password
- Check for empty username or password on login
- $user_login is not working if author has only 1 post
- Specific Content on pages based on user
- user and usermeta table not found
- custom login form, guide me
- Front end login and page restriction
- Changing user_login ends current session
- Current User Seeing Another Logged In User Info
- Privacy in WordPress
- Redirect based on log-in status per JavaScript
- Securely log in a user without a password using a link?
- Integrating Facebook Registration (and Login) on a WordPress page
- WordPress – Security Question at Login from User’s Meta Data
- determine active user browser at the same time
- How to track all users logged into a site?
- Cant edit profile from frontend
- How to authenticate/verify login credentials & check for user meta without logging in?
- How to get WordPress Username in Array format
- Display user registration date
- How to assign capabilities to user NOT to User Role
- Redirect after User Activation [closed]
- Changing default Buddypress avatar affects all site avatars (because gravatar)
- How to make user accept license agreement before download
- Add user data to table when user is created?
- Detecting all admins that are logged in
- Why wordpress showe “admin is editing…” whoever edits?
- Restricted registrations or removing the ability to edit your password/email
- Remove admin menu links for multiple users by email
- Use wp_update_user to update custom column in wp_users table
- How to filter users by last_name?
- Custom Query for count_user_posts function
- How to pull all the contributer users records and order by Designation (which is users meta data)?
- cannot get user_registered date from get_user_meta
- Confirm Deletion not found
- Need to exclude users with no posts from my contributors page
- link variable to user
- How to get image path from id using SQL
- Update user role for expired membership
- wp_insert_user error
- Create users by importing from CSV, with User ID assigned from CSV
- Moving users from joomla to wordpress
- Auto approve new users if their username is included in a predefined list
- How to use url formatter with integer
- add a Custom Columns to user
- Access level seems to have gone from admin to editor
- MySQL query to list users who never signed in
- Send email to user if their role is changed to Author
- Can’t retrieve user email address with REST API