Your current code disables plugins for logged in users with contributor
capabilities on non-admin pages. The is_admin()
function checks if the current page is “/wp-admin” page, to disable plugins just on the admin pages change this condition to:
if ( current_user_can( 'contributor' ) && is_admin() ) {
But to make this code work you need to have it in Must-Use plugin, to load it earlier than all the plugins. In short, create new PHP file directly inside /wp-content/mu-plugins
directory, add required header information and add your code with the change I mentioned above.
Alternatively, you can use a plugin like Adminimize and disable certain parts of the dashboard to specified users group.
Related Posts:
- Checking for user role in a custom plugin
- Error shown for Trying to get property ‘roles’ of non-object in WordPress After Content for User Roles
- Redirection of users away from wp-admin (but not administrators)
- WooCommerce specifc variations for specific user role [closed]
- Custom shortcode for displaying user based on a role parameter
- Add User Role: Pre-saved in User-Meta [SOLVED]
- implement custom roles in custom plugin
- Allow a particular user to access a particular plugin?
- Should all plugins be encapsulated in a Class?
- Preserve custom URL parameter on more pages
- PHP code on Visual Composer Plugin
- if plugin is active? check if plugin is enabled or not?
- WordPress Capabilities: edit_user vs edit_users
- Making plugin unique to not conflict with plugins with the same name
- How to find out if option exists but is empty?
- How to store ACF custom fields data in a custom table
- How to assign user a role if none is present when logging in
- Trying to disable plugins doens’t work
- Thumb rating for wordpress – top user
- Errors while using ajax from external wordpress page
- Have Plugin Handle Specific URLs
- Setting up widgets in wordpress with a unique ID for the after_title argument
- allow arabic letters when register new account
- How to get all events from ‘All in one Events calender’ plugin in JSON format?
- How do you remove plugin edit option?
- Make specific products accessible only to a user role in WooCommerce
- Where should I save an API key of my user when installing my plugin?
- How to make a customize role and view a specific plugins base on that role?
- Accessing post’s meta data based on user’s click of a post
- Custom form action to handle data inside a plugin
- WP Post Template – Templates in own folder
- How to add equivalent of php include to one page (as plugin?)
- Override Plugin Script Fucnction in WordPress
- Image upload and download from front-end
- Shrink down register_settings on Settings API
- Parse error: syntax error, unexpected ‘new’ (T_NEW) in /misc/41/000/204/381/9/user/web/ragami.net/wp-settings.php on line 219
- How to call WordPress function other files
- Removing an action from wp_footer called in a class that’s inside a bigger class
- Ajax call returning 0
- How to create restrict content to users (by user, not by role)
- How to create user that has permission to create new sites on WordPress with multisite option enabled?
- Some code in shortcode function being ignored
- Subdomains with almost the same content
- Using window.onload with Ubermenu
- What is @Action in WordPress?
- PHP Error When a plugin is active
- Inserting custom PHP script on homepage
- Add bcc to contact from on wordpress
- Getting taxonomy images to display on single-post with their terms
- How I can change the required capability for an admin menu without editing the plugin file?
- wp_enqueue_scripts
- WordPress Console Application (ability to excecute a custom function via crontab only)
- Get all the URLs of the pages that uses a specific shortcode
- Wp Debug Enabled True Notices and Warning
- Pagination shows Same posts
- Theme Functions run a function upon activation or preview
- WP Subtitle Plugin Problem
- Custom Plugin scripts from admin working in frontend
- WooComerce Deposit: set specific shipping method and quantity based deposit amount
- Unexpected add action function in WP plugin
- How to get brand children with woocommerce brands
- Prevent WordPress from sending set-cookie http header
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- How to add a prefix to a WordPress post preview url?
- i can not access the post in custom template of my wordpress plugin
- location lock wordpress website
- Use AJAX to fetch Current Post Thumbnail for WordPress when Uploaded throughMedia Uploader Frontend
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- How much PHP and MySQL or MariaDB knowledge should I know to start writing WordPress themes and plug-ins and whatever else a beginner can edit?
- post id or permalink auto-incrementing number and reset everyday
- How To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially
- WordPress logout appends cache/all/index.php to the site_url()
- Reverse count page view and show on other page
- Change (replace) word in metabox
- Caching of combined CSS and JS fails because of losing MIME types through combining by PHP
- Change pricing in Woocommerce based on Category and Product [closed]
- User / membership Plugin [closed]
- Passing ajax variable to more than one wordpress plugin function
- Add class as plugin for other plugins
- Social sharing plugin directing to blank page after post sharing
- Displaying friend’s posts only
- using href when creating wordpress plugin calls empty page instead of php file
- Saving custom form fields
- How to add php stylesheet to admin section instead of admin_head hook
- Template from scratch: Sidebars not showing widget
- Contact Form 7: custom validation [closed]
- Enforce conditions only for draft posts using WyPiekacz, ignore pending and published posts
- How to add homepage Widget?
- What can I do to customize a widget provided with this plugin? from where have I to start?
- WordPress create permalink structure for custom post type with userid
- Shortcode inside a redirect [closed]
- Attachement title in wpallimport
- Block registration with viewScript
- Warning: Undefined variable $admin
- How to change all the urls of the WordPress site?
- How do I remove the filter from the orders and add custom status in Dokan?
- How to make a Template page to show the information of different things Shop and Product page?
- Split Million WordPress Post’s Into Multiple Database Server
- I want to allow certain file types on dokan upload files
- How to create different woocommerce single_product.php pages for each product? [closed]