Skip to content

Deactivate Plugins 1by1 Faster!

  • by

If you are experiencing issues in your WordPress this can be a result of a Plugin conflict. In some cases the only way to isolate the conflict is to disable plugins 1 by 1 to determine the issue. This can be very time consuming to try to complete via the GUI in the WordPress Dashboard. Below is a script you can run from a Shell session which will automate this process making it much faster:

{
for pluginname in $(wp plugin list --skip-{plugins,themes} | awk '{print $1}'| grep -v ^name$); do 
    if [ $(wp plugin get "$pluginname" --skip-{plugins,themes} | grep status | awk '{print $2}') == 'active' ]; then  
        echo "Disabling Plugin: $pluginname"
        wp plugin deactivate "$pluginname" --skip-{plugins,themes}
        echo "Does the site work now? (Y/N)"
        read -r yn 
        if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then 
            echo "$pluginname was breaking the site"'!' 
            break 
        else 
            wp plugin activate "$pluginname" --skip-{plugins,themes} 
            continue 
        fi
    else
        echo "Plugin $pluginname already inactive, skipping"'!'
        continue
    fi
done
}

Here is an example of the output once you run this script:

Disabling Plugin: akismet
Plugin 'akismet' deactivated.
Success: Deactivated 1 of 1 plugins.
Does the site work now? (Y/N)
n
Plugin 'akismet' activated.
Success: Activated 1 of 1 plugins.
Disabling Plugin: heartbeat-control
Plugin 'heartbeat-control' deactivated.
Success: Deactivated 1 of 1 plugins.
Does the site work now? (Y/N)
n
Plugin 'heartbeat-control' activated.
Success: Activated 1 of 1 plugins.
Disabling Plugin: hello
Plugin 'hello' deactivated.
Success: Deactivated 1 of 1 plugins.
Does the site work now? (Y/N)
y
hello was breaking the site\!

Leave a Reply

Your email address will not be published. Required fields are marked *