Off the top of my head, you should be able to do something like this:
$role = get_role( 'client' );
if ( $role && $role->has_cap( 'install_plugins' ) ) {
// Role not updated yet, so update it.
$role->remove_cap( 'install_plugins' );
}
get_role()
returns a WP_Role
object on success and WP_Role::remove_cap()
calls WP_Roles::remove_cap()
, which directly updates the option in the database. The $role->has_cap()
check ensures that the code isn’t run twice.
Running this in a function hooked to init
should suffice.
Ideally you’d have a database version option for your plugin which you could use to run some code exactly once per plugin update. Otherwise your code is executed again every time someone manually adds the install_plugins
capability to your role again. That’s not necessarily bad, but it could be prevented 🙂
Code reference:
Related Posts:
- How can I modify the Capability needed to access a plugin’s options?
- WordPress Capabilities: edit_user vs edit_users
- Allowing Custom Capability to Manage Plugin Options
- Remove specific administrator’s capability
- How To Create A File Archive in WordPress?
- How to hide plugin options for editors via functions.php
- Adding plugin editing capability for Author
- See which user role / capability is needed to use a plugin
- Remove dashboard links from wordpress
- Why user profile update creates Additional Capabilities
- Run only on plug-in activation instead of wp_head
- Want to add post to user dashboard
- Sync roles across several plugins
- How to disable plugin capability : “create new category”
- edit slider plugin capability for custom_role
- How to prevent a post from being deleted?
- Deactivate plugin for a specific user group
- Publish author posts only with editor approval?
- Limit access to posts/pages by user roles
- Disable plugins for a specific user role
- User profiles and object associations
- How to assign user a role if none is present when logging in
- Can’t use /wp-json/wp/v2/plugins API endpoint even as administrator
- Specific post user permissions
- How can I let users to access plugin functions based on roles?
- Dynamic homepage according to user role
- Restricting users to a specific front end page [closed]
- Remove Adminstrator Hyperlink from a user having role to add and see users
- Enable comments for post with comments meta box removed
- Restrict backend but allow to use post.php?action=delete&post=POSTID from front-end
- How can I change plugin to give access to editor user role?
- WordPress roles – Protect administrator role
- wordpress custom login successful redirect hook
- Keep user’s privileges on accessing contents in JSON response
- Advanced Custom Fields/User Role Editor – how to hide ACF for certain users?
- How create a role with admin capability less 1 or 2?
- Set user ID at time of wp_create_user
- Getting user roles in plugin files
- How to achieve certain page (url) accessible to certain users
- How to make a customize role and view a specific plugins base on that role?
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- Hook to plugins admin settings
- Disable plugin per user role
- how to give a user a role?
- Making a plugin only available on the front-end for the logged in super admin
- Filter custom posts based on the user role of author
- Redirection of users away from wp-admin (but not administrators)
- Custom post type – no layout section of Document tab, and no author choice
- How to allow an editor to edit all WordPress blog posts but have the last say as administrator?
- WooCommerce specifc variations for specific user role [closed]
- How to create restrict content to users (by user, not by role)
- How to set add question capability for author role in wp pro quiz plugin
- How to create user that has permission to create new sites on WordPress with multisite option enabled?
- Unable to delete custom post types, confusion around capabilities
- Can I allow certain people to add/edit pages within a parent?
- can i limit editing specific custom fields to certain roles?
- Add user role to generated plugin
- Is there any way to make myself an admin?
- Understanding State in WordPress Multisites
- Allow only Admin role to access plugin settings/options page
- How to allow Contributors to publish articles after approval
- Custom shortcode for displaying user based on a role parameter
- How I can change the required capability for an admin menu without editing the plugin file?
- Add User Role: Pre-saved in User-Meta [SOLVED]
- Multiple authors and readers restricted by role [closed]
- Custom Login page with custom redirects for each user?
- Show WordPress Plugin Menu(Admin) To Editor
- Mutliple users editing single document in wordspress
- Show media-uploads to all users
- same user role or copy the user role to be same as the other role
- Plugin permissions for Editor role
- Completely remove ability to create users?
- Role based permission edit for plugins
- Require Capability to View Woocommerce Product
- WordPress Membership Plugin Advice [closed]
- Plugin privelages for “editors”
- Plugin access and Roles
- Plugin Hook When New Author Added
- Show an admin menu item in Editor role
- implement custom roles in custom plugin
- Allow a particular user to access a particular plugin?
- how to create user profile pages and display them based on users roles
- Allow editor user to full permission to access plugin settings
- Allow a page to be edited by a specific custom role
- How to create different views for different user roles?
- Public WP website with one area just for members
- Multiple useres editing specified content
- How can I disable access to plugin settings in wp admin for other roles
- How to show private pages based on a user’s role?
- User / membership Plugin [closed]
- Overwrite user role
- Allow non-admin users to access plug-in
- Defined user role to access plugin’s pages
- Different email notifications (about pending posts) to different users
- Allow a role to edit one specific plugin
- WordPress Role Capability Restriction
- How to give different user access to different people?
- registration plugin [closed]
- How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
- How to have certain products show for only certain users (Not roles)