0

I need to disable a specific plugin for administrators.

I found this piece of code that should do the trick, but it's not working for me. I don't really know much about PHP so I don't know how to fix it.

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 ( current_user_can('administrator') ) {

        // Use the plugin folder and main file name here.
        // is used here as an example
           $plugins_not_needed = array ( 'no-right-click-images-plugin/no-right-click-images-plugin.php' );
            foreach ( $plugins_not_needed as $plugin ) {
                $key = array_search( $plugin, $plugins );
                if ( false !== $key ) {
                    unset( $plugins[ $key ] );
                }
            }
        }

        return $plugins;
    }

As Castiblanco requested, here is my theme's functions.php in pastebin: https://pastebin.com/qZwSzmgh

"code" and "pre" weren't working properly here.

0

1 Answer 1

1

I just tested your code and it works, so it seems one of the two following things.

You are placing the code in the wrong place, make sure you put that code at the bottom of the functions.php file of your theme. Or maybe the functions.php file of your theme is having problems, in which case you could share it with us by posting its content editing your question.


It seems alright, do this:

Open your wp-config.php and add these lines:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );

Let me know what it shows after.

3
  • I just added my functions.php code.
    – leandroprz
    Aug 23, 2018 at 22:32
  • Answer updated, let me know. Aug 23, 2018 at 22:38
  • It shows some notices about the theme: pastebin.com/TJU1J2YF Only when I access the home page, other pages and blog posts show nothing.
    – leandroprz
    Aug 24, 2018 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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