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 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
- Editor can create any new user except administrator
- How do I programmatically set default role for new users?
- Display user registration date
- How to set up User email verification after Signup?
- Show admin bar only for some USERS roles
- How to check user role without using current_user_can()
- How to assign capabilities to user NOT to User Role
- How to stop a user from updating the post date
- How do i auto approve new user?
- BuddyPress | Check if user is in current group [closed]
- Customize Admin Users Screen based on Role
- WordPress edit_user_profile_update update secondary role
- How to display only logged in user’s post comments in comments area
- How to get the Role Name of the current user? (WordPress)
- set_role has no effect
- WP_User->add_role producing unexpected results
- WPMU – new users are automatically subscribed to the main blog – how to prevent that?
- WordPress to use Drupal users’ credentials
- How do I list in the backend all users that were assigned to a custom role?
- How to add local users to wordpress without email password?
- Upgrade Nightmare – No Posts, Permissions Issues and Can’t Create a new post
- Are User Levels Still Currently Used?
- Error: How to allow the “contributor” to upload media in wordpress
- Restrict access of admin uploads to certain logged-in users?
- Fix permissions for users role
- Are there mutiple ways to get usernames (as a hacker)
- How change user type from contributor to author
- Menu page with list of users
- Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
- How to hide user profile fields based on the role of the viewed user?
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Custom registration and pending approval
- Make new users automatically approved
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- One Click Access To Users Account In WordPress?
- Get Authors Role
- Edit text of WordPress “Register” button
- Editor role can only create/edit/delete users who have one of two roles
- set automatically email address for WordPress users
- WordPress 5.8 – Hide or Remove personal fields from admin Profile page
- Perform multiple actions after wp_insert_user()
- Find count of WordPress users by role and search string for user name
- Hook into add_user_role and update based on new and removed roles
- Auto approve new users if their username is included in a predefined list
- fine-grained capabilities for user related capabilities
- Updated user role inncorrect when using wp_get_current_user()
- Hide top admin panel for non admin and non editors
- How to use url formatter with integer
- Custom registration fields not appearing in user info
- How to restrict Admin from creating new users from Add new user screen in dashboard to only of one domain?
- Show user details only
- A different role for each site in a multisite
- Access level seems to have gone from admin to editor
- post acces for guests / unregistered users only
- Front end login and page restriction
- i need to let a user to add a role from a frontend form
- Integrating Facebook Registration (and Login) on a WordPress page
- You do not have permission to access this document on form submit
- How to give different user access to different people?
- Redirect user based on role when they try access a particular page
- determine active user browser at the same time
- Send email to user if their role is changed to Author
- Remove My Account Menu items in Woocommerce based on user roles