Yes it can be good practice to check if a user is capable of doing something before doing something related in code.
For example, don’t save a custom post type if the user doesn’t have the capabilities needed to do it, or don’t show certain things to users who don’t have the manage_options
capability ( super admins and admins normally ).
Bad practice in this case would be assuming the user has the necessary role to do these things and doing them anyway. This doesn’t mean you should fill your code with checks for current_user_can
everywhere though, in many places ( such as registering admin menus ), the check is performed by WP Core itself
Related Posts:
- Editor can create any new user except administrator
- Remove Ability for Other Users to View Administrator in User List?
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- What’s the difference between the capability remove_users and delete_users?
- How to let contributors to create a new revision(draft) editing their published posts
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- How to update user role without logout
- How to check user role without using current_user_can()
- Do not allow users to create new posts and pages
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- How to enable the theme editor cap for an editor role?
- How to assign capabilities to user NOT to User Role
- How-to Delay The Capability To Publish Posts?
- Is there a simple way to manage capabilities per user?
- Prevent Admin user to edit/see super admin from users list
- Get User Role by ID not working
- Getting users by specific capability, not role
- Restricted registrations or removing the ability to edit your password/email
- Are User Levels Still Currently Used?
- Does an AJAX call on the Admin Side Automatically include the User Data/Capabilities?
- Remove Capabilities from WP admin for specific user role
- Add a role and give admin priviledges
- Where are $current_user->allcaps set?
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- What’s the correct way to add capabilites to user roles?
- Can I Create a Second Admin Level User Role?
- Custom capability for a single user
- Privilege to recover trashed posts
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- how do I add role and capability after I create a new user
- current_user_can() causing critical error
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- Author Error “Sorry, you are not allowed to access this page.”
- fine-grained capabilities for user related capabilities
- Disabling user capability to edit_posts or delete_posts in the front-end
- Groups roles & capabilities
- Subscriber role – blank page
- No one can edit post/pages by Administrator
- current_user_can() returning true for capability when the user and role do not have the capability
- If the current user is an administrator or editor
- Getting a List of Currently Available Roles on a WordPress Site?
- How do I add a field on the Users profile? For example, country, age etc
- How do I display logged-in username IF logged-in?
- How to allow an user role to create a new user under a role which lower than his level only?
- user_login vs. user_nicename
- How to programatically change username (user_login)?
- Change the Author Slug from Username to Nickname
- Difference between update_user_meta and update_user_option
- Make display name unique
- Make WooCommerce pages accessible for logged in users only
- Find out if logged in user is not subscriber
- WordPress usermeta scaling for thousands of users
- How to get WordPress Username in Array format
- Display user registration date
- Get multiple roles with get_users
- get_user_meta() doesn’t include user email?
- Confirmation required on email change
- How to Merge Two Authors Into One?
- Whats the best way to share user data across multiple WordPress websites?
- get_current_user_id() returns 0?
- How to get userid at wp_logout action hook?
- Is there a way to merge two users?
- List users by last name in WP_User_Query
- How to restrict access to uploaded files?
- Automatically delete inactive users after 2 months
- How to change user_login with wp-cli?
- Delete all subscribers from wp_users and wp_usermeta a few thousand at a time
- Email user when password is reset by admin
- Replacing the WordPress password validation
- Ban a user and end their session
- Allowing users to edit only their page and nobody else’s
- How can 2 blogs share the same users
- alphabetically order role drop-down selection in dashboard
- WordPress auto login after registration not working
- Change the author slug from nickname to ID
- Execute a function when admin changes the user role
- how to use joomla password format in wordpress?
- How to do get_users() with multiple meta_keys
- What the user_status column?
- How to limit users to one comment per post
- Different back-end language for different users?
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- Hide Admin Menu for Specific User ID who has administrator Role
- Migrating WordPress users into Disqus
- Problem with Hebrew characters in username
- Is there an upper limit for users in WP?
- How to display the status of users (online – offline) in archive.php
- Remove email verification when new user register
- How to change user`s avatar?
- How to set up User email verification after Signup?
- Allow up to 5 Concurrent Login Sessions
- 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?
- How to work around “that email address has already been used” error?
- Get the name of user who updated post
- Disable delete user