Using WP-CLI to Troubleshoot Frontend WordPress Plugin and Theme Conflicts

The potential time savings for troubleshooting WordPress with WP-CLI can be incredible. Many of us have had to go through the plugin deactivation dance to isolate a conflict with a plugin and/or theme in WooCommerce or WordPress. This is an incredibly tedious task if you only use the wp-admin dashboard to deactivate each plugin one by one. If you have WP-CLI you can go through this monotonus process much more efficiently.

Picture this: you have your SSH terminal window open running a script that will deactivate each plugin serially (one by one) as you press Enter, in a browser window you can refresh the page display errors or having issues after each plugin deactivation. Can you see how much time this would save? I have shared a script for doing this below that I hope makes you feel like a WordPress troubleshooting ninja!

Please note this is for frontend troubleshooting, if you want to troubleshoot command line errors see this post

Like many of my posts, this was inspired by a Codeable client whose site had over 80 plugins active. There was an issue with jQuery not being defined which caused all JavaScript files depending on it to not function. I definitely didn’t want to delete all 80 of those plugins one by one!

Using WP-CLI to Troubleshoot Frontend WordPress Plugin and Theme Conflicts

First, we deactivated all plugins using the command below. The jQuery problem went away so we wanted to find out why.

wp plugin deactivate --all --allow-root

I needed to list all of the inactive plugins with WP-CLI

wp plugin list --status=inactive --field=name --allow-root

Now we can redirect the output of the above command to a file so we can use it to loop through the list of inactive plugins

wp plugin list --status=inactive --field=name --allow-root > pluginlist

Here is the bash loop that will activate each plugin one by one after you click Enter to step through each one

while read -r PLUGIN; do
    echo "Activating ${PLUGIN}"
    wp plugin activate ${PLUGIN}
    read -p "Press Enter to continue" </dev/tty
done < pluginlist

You will see output like this for each plugin that is reactivated

Activating tiny-compress-images
Plugin 'tiny-compress-images' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue

When you get through the whole list you’ll see a long output similar to this, by the end you should have found the plugin culprit causing the conflict!

Eventually every single one of the plugins will be re-activated as the script progresses.

Activating tiny-compress-images
Plugin 'tiny-compress-images' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating contact-form-7
Plugin 'contact-form-7' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating creative-clans-embed-script
Plugin 'creative-clans-embed-script' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating nova-currency-converter
Plugin 'nova-currency-converter' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating disable-comments
Plugin 'disable-comments' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating duplicate-post
Plugin 'duplicate-post' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating google-rich-snippets-plugin
Plugin 'google-rich-snippets-plugin' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating hc-custom-wp-admin-url
Plugin 'hc-custom-wp-admin-url' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating header-footer
Plugin 'header-footer' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating imagify
Plugin 'imagify' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating effect-inline-content
Plugin 'effect-inline-content' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating kraken-image-optimizer
Plugin 'kraken-image-optimizer' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating list-category-posts
Plugin 'list-category-posts' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating mainwp-child
Plugin 'mainwp-child' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating media-file-renamer
Plugin 'media-file-renamer' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating media-library-assistant
Plugin 'media-library-assistant' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating mindvalley-include-content
Plugin 'mindvalley-include-content' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating ml-raw-html
Plugin 'ml-raw-html' activated.
Success: Activated 1 of 1 plugins.
Press Enter to continue
Activating nxs-snap-pro-upgrade
Plugin 'nxs-snap-pro-upgrade' activated.
Success: Activated 1 of 1 plugins.

Hopefully you feel like a boss executing this!

Sources

Pausing bash Scripts in a while loop

3 thoughts on “Using WP-CLI to Troubleshoot Frontend WordPress Plugin and Theme Conflicts”

Comments are closed.