0

I want to remove a plugin for a contributor role or just make it unaccessible. I have a code for kinda similar situation:

add_filter( 'option_active_plugins', 'disable_logged_in_plugin' );
function disable_logged_in_plugin( $plugins ) {
    // The 'option_active_plugins' hook occurs before any user information get generated,
    // so we need to require this file early to be able to check for logged in status
    require (ABSPATH . WPINC . '/pluggable.php');
    // If we are logged in, and NOT an admin...
    if ( current_user_can('contributor') & !is_admin() ) {
        // Use the plugin folder and main file name here.
        // is used here as an example
           $plugins_not_needed = array ('/metabox/meta-box.php');
            foreach ( $plugins_not_needed as $plugin ) {
                $key = array_search( $plugin, $plugins );
                if ( false !== $key ) {
                    unset( $plugins[ $key ] );
                }
            }
       PHP            return $plugins;
    }

I don't have any experience with php, but how I understand the problem, because they are inside admin area? ( I allow them to Sign up and post, but they aren't admins ).

How can I turn off specific plugin for contributors if they are inside admin area?

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.