I think is a better strategy, that you add on the activation a new capability and add this capability to the Administrator role. This makes possible for installations with much different roles to the WP default to add this capability to other roles or for the requirement of a installation to add the view to another role.
Add Cap to a Role
add_action( 'admin_init', 'fb_add_capabilities' );
function fb_add_capabilities() {
`$GLOBALS['wp_roles']->add_cap( 'administrator', '_your_custom_cap' );`
}
Check for Cap
Inside your source can you check for this capabilty:
if ( ! current_user_can( '_debug_objects' ) )
return;
Remove Cap
On the deactivation (Hook register_deactivation_hook
) and uninstall (Hook register_uninstall_hook
) of the plugin is it necessary, that you remove the cap.
remove_cap()
Example
A example in the wild can you finde in this plugin, file.
Related Posts:
- what’s the meaning of the field wp_capabilities in table wp_usermeta
- Send user activation email when programmatically creating user
- Change default admin page for specific role(s)
- Add Custom User Capabilities Before or After the Custom User Role has Been Added?
- How to Change the Entire WordPress Admin panel Look and Feel?
- How to Structure a New Role/Capability Scheme?
- How to add more than 1 user role to sub-menu pages
- How to allow Unfiltered HTML in a wordpress multisite install
- How to restrict plugin’s sub-menu pages to admin/subscribers?
- How to not let a user with a new role edit users that have administrator role?
- Execute plugin for specific user role(s) only
- query users by role
- get_posts() not working when accessing with a custom user role
- Limit role to one plugin [duplicate]
- Logout users upon login, based on caps/role?
- Set different custom menu items for different user roles
- Prevent third party plugin’s admin page access based on user type
- wp_dropdown_roles() to replace option value = code
- Hide custom post type by user roles
- Check user’s role and store in variable
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- How can I change my assigned user role in WordPress 3.5.1?
- How to determine which capability to use?
- Allow contributor user role to perform copy operation PHP
- Enable a role named ‘backend_user’ to access my plugin pages
- Add custom parameter for custom user role
- Buddy Press restrict the capability to edit users
- How I can give access to my custom plugin for editor roles user?
- Remove all capabilities in separate method fails versus included in method
- Remove from a div by class name from post page if post author role is not administrator
- Adding admin for specific users
- What is more secure checking capabilities of user or checking role of user in WordPress plugin development
- New Users are saved with no role selected
- WordPress User Management Departmental Managers
- Remove default wordpress roles
- Adding more options to the instance of an image. (Attachment Display Settings)
- Plugin – create a page without it appearing in the side menu
- Using wp_filesystem in Plugins
- How to write testable classes in WordPress
- WordPress REST API call generates nonce twice on every call
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- How to trap “Publish” button to check for meta box validation?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- wp_mail not recognizing cc and bcc headers
- How can I call “preview post” from wp_remote_get with authentication?
- When is it too late to call the action wp_enqueue_scripts?
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- Adding extra pages to plugin that shouldn’t appear in the sidebar
- Finding posts containing matching array elements in a meta field usign WP_Query
- how to use hook deleted_user into custom function to delete user from custom table
- Namespaced action and filter tags
- Adding Dropbox dropin js using wp_enqueue_script
- Single sanitization callback for multiple fields
- How to filter users list on user_status field with get_users()
- Where did the ability to edit a plugin go?
- How to add custom fields to the all users page
- Can Page Templates be Applied to Archive and Post Templates?
- WooCommerce Admin Reports : Get custom product report based on date range
- Auto gallery from folder contents
- Is there a plugin that will allow a tag cloud to be created from any mysql field?
- Custom login doesn’t work properly
- Translate slug in WPMU with PO files
- Allow users to add / remove settings in plugin
- Update problem with update_option() in combination with register_setting()
- Why does my widget break other widgets?
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- Is it possible to enable and disable wp debug from functions.php?
- Default settings aren’t used
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Getting a WordPress Debug Strategy
- Best way to include and use Zoho SDK in a wordpress plugin
- How to change WooCommerce loop product title HTML output in single product page and archive page
- How remove trashed WooCommerce orders from wc_get_orders() result?
- How to use nonce
- Does WordPress default CSS have Grids?
- Unexpected T_FUNCTION
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- Plugin can’t be activated [closed]
- Is there an action_filter hook to add content before the post title?
- CSS not being applied using wp_enqueue_style
- Count products with custom metadata field in an order
- Hide / show settings field based on other field’s value
- $_SESSION inside php function executed by AJAX
- Two same AJAX calls – one is working, other doesn’t
- Adding and handling custom settings tab to fusion element
- WordPress Reset password Strength set to medium
- How to get option values without requiring wp-load?
- Problem with baseurl and interaction with plugin
- Why setcookie function redirecting to home page in wordpress?
- Should all roles be allowed CRUD operation on the database?
- Associating special meaning with user id 0
- Filter get_user_by instead of replace function
- Downloading Generated XML File
- How to create a custom search form and handler?
- How to use permalink query to go to specific tabs in posts
- Conditional query tags do not work before the query is run. Before then, they always return false
- Method to retrieve category names and IDs only as an array?
- Send Webhook when post-status is publish or trash
- Using “add_image_size” to register custom image sizes inside plugins not working
- How do I access the contents of WordPress Classic editor in admin area with JavaScript?