You are going to want to look at a few things. First, the WP_user object which will enable you to check if the user is even logged in. But you can also check capabilities with the has_cap
method.
You can even define your own capabilities and apply them to users.
Then you would do something along these lines:
<?php
$user = wp_get_current_user();
if($user->exists()){
// logged in user
if( $user->has_cap('edit_users') ){
// user can edit users
}else{
// this user cannot do that
}
}else{
// anon user
}
Related Posts:
- How to customize wp_signon()
- Allow admins to login as other users
- How to add default folders to Every registered User when registered in WordPress site?
- How to allow an user role to create a new user under a role which lower than his level only?
- Allowing users to edit only their page and nobody else’s
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Hide Admin Menu for Specific User ID who has administrator Role
- Copy a user from one WordPress site to another
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- Can I create users that have access to *some* other users posts instead of all other users posts?
- Set default page for user account in admin
- Hide everything on site for visitors except specific page IDs
- Managing Users and Creating Groups [closed]
- How to disable a specific page for a specific user
- wordpress user roles are not working
- Problem with automatic role change through cron job
- How can I allow an User to publish only 5 posts per month?
- Where are $current_user->allcaps set?
- Can I Create a Second Admin Level User Role?
- Customising “user ids” and add to ‘user’ panel in the admin area
- How to hide some users to unlogged users [closed]
- Redirect admin 403 “Cheatin uh?” admin pages
- Unique password to access a section site
- WordPress user role with create user capability?
- Update user role for expired membership
- Custom User Role: Can Edit Own Page, Cannot Create New
- WordPress install checking permissions of user id 0
- Allowing users to edit only their page and nobody else’s
- How to bulk change user role to “No role for this site”
- Restrict Access to the User Profile
- view and update form only for registered users
- Control Category of each user can post
- Limit user access to installing/configuring a plugin?
- file upload user profile
- MySQL query to list users who never signed in
- Wordpres password as plain text in email
- WordPress password as plain text in email
- How to remove/limit Editor accounts privileges, to prevent them from deleting media and pages created by Admin
- Condionally/limited emails from system (cantact-form, registration, passwd reset)With
- If the current user is an administrator or editor
- Editor can create any new user except administrator
- How to programatically change username (user_login)?
- Remove Ability for Other Users to View Administrator in User List?
- Find out if logged in user is not subscriber
- How do I programmatically set default role for new users?
- Display user registration date
- Whats the best way to share user data across multiple WordPress websites?
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- How to restrict access to uploaded files?
- alphabetically order role drop-down selection in dashboard
- Can an admin check passwords of registered users?
- WordPress auto login after registration not working
- Execute a function when admin changes the user role
- How to let contributors to create a new revision(draft) editing their published posts
- Problem with Hebrew characters in username
- Remove email verification when new user register
- How to set up User email verification after Signup?
- How to let user set password on registration
- How to hide media uploads by other users in the Media menu?
- Show admin bar only for some USERS roles
- How to display custom user meta from registration in backend?
- Allowing an email as the username?
- Grouping users under parent user
- Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
- How to remove administrator role in settings -> general -> New User Default Role?
- Check if specific username is logged in
- How to update user role without logout
- How to check user role without using current_user_can()
- Post list based on the user that is logged in
- Multi-steps WordPress registration : in 4 steps how to?
- Basic auth WordPress REST API dilemma
- Do not allow users to create new posts and pages
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- Force users to complete their profile after they register? How to
- How to enable the theme editor cap for an editor role?
- Forbid certain users to access a specific page
- You do not have permission to access this document on form submit
- One folder to be accessible by one user
- Is it possible to tell if a user is logged into WordPress from looking at the cookies which are set?
- New User Registration email
- How to give different user access to different people?
- how can i inform other users about new user registration? [closed]
- Increase by one the user counter on specific role
- current_user_can() returning true for capability when the user and role do not have the capability
- Show only users with the same role in Dashboard user list
- Add custom input field in new user page
- Redirect user based on role when they try access a particular page
- determine active user browser at the same time
- How to create a specific role to manage users
- Send email to user if their role is changed to Author
- Remove My Account Menu items in Woocommerce based on user roles
- WordPress: New user role which is ONLY allowed to manage media
- (How) does WordPress protect direct access of user data?
- How to allow users in wordpress to switch between two assigned roles e.g. Candidate & Employer
- Administrator user cannot access dashboard after localwp import
- WordPress change role from administrator to author by itself (automatically)
- Redirect Login Based on User Role
- Importing users from Single WordPress site to a Multisite