Using WP-CLI bash Scripting to Find WP-CLI Plugin Conflicts or Errors

WP-CLI is invaluable to me so when it doesn’t work on a WooCommerce or WordPress site it’s a top priority to get it fixed and working properly! I was getting this weird error for a site where WP-CLI wouldn’t show me any information, simple commands like wp option get weren’t returning any output and simply didn’t work. WP-CLI was just showing nothing, a blank result.

Other times WP-CLI commands have returned PHP code errors instead of the expected output because of some PHP error like a warning or fatal error. This will help you find the culprit by identifying the plugin reason why WP-CLI isn’t showing you the output you are expecting.

On large WordPress and WooCommerce sites with many plugins you won’t have to manually activate and deactivate each one thanks to the automated bash script below.

Using WP-CLI and bash Scripting to Find WP-CLI Plugin Conflicts

Usually this simple WP-CLI option get command will return the domain of the site you are working on.

wp option get siteurl

I had to skip all of the plugins being loaded with --skip-plugins flag

wp option get siteurl --skip-plugins --allow-root

There we go, but I can’t do many useful tests like using wp profile if I have to skip all of the plugins just for WP-CLI to work!

https://test.wp-bullet.com

So I listed all of the site’s WordPress plugins by just their name and active status

wp plugin list --field=name --status=active --skip-plugins --allow-root

I got this incredibly long plugin list, I really don’t want to manually deactivate and reactivate each of these one by one!

advanced-css-editor
akismet
appointments
dynamic-pricing-and-discounts-for-woocommerce-basic-version
easy-facebook-likebox
erident-custom-login-and-dashboard
export-user-data
pirate-forms
sz-google
heartbeat-control
hello
hide-this
if-menu
jquery-website-tour
lifterlms
lifterlms-customizations-master
lifterlms-labs
lifterlms-integration-woocommerce
magee-shortcodes
magee-shortcodes-pro
mageewp-page-layout
mageewp-page-layout-pro
migrate-guru
mycred
order-import-export-for-woocommerce
checkout-fees-for-woocommerce
per-page-add-to
popup-surveys
query-monitor
really-simple-ssl
redirection
regenerate-thumbnails
restrict-widgets
shortcode-redirect
spreadshop
top-bar
user-role-editor
user-shortcodes
view-admin-as
wc-speed-drain-repair
widgets-on-pages
woocommerce
woocommerce-autocomplete-order
woocommerce-checkout-manager
woocommerce-extra-charges-to-payment-gateways
woocommerce-gateway-paypal-express-checkout
woocommerce-time-based-pricing
woocommerce-role-by-amount-spent
woo-discount-rules
woo-display-price
inspector-wp
wp-customer-reviews
wpdatatables
sp-faq
wp-fastest-cache
wp-file-manager
wpfront-notification-bar
wp-live-chat-support
wp-live-chat-support-pro
wp-smushit
youtube-embed-plus
zerif-lite-transition-master

To quickly count all the installed and active WordPress plugins with WP-CLI, you can pipe the output of the plugin list command with | to wc -l which will count the number of lines in the output.

wp plugin list --field=name --status=active --skip-plugins --allow-root | wc -l

Even if you are a fast typer, it will still take a while to test all 62 plugins manually

62

Here is a bash script utilizing WP-CLI that will cycle through all of the active plugins and simulates deactivating them one-by-one without actually deactivating them. This is especially useful since sometimes widgets or options can disappear when some plugins are deactivated.

This script will also provide you with a list of all the active WordPress plugins and place it in the file /tmp/plugin-list.txt which can be handy.

# Purpose: Find plugin conflicts with WP-CLI
# Author: Mike from wp-bullet.com

# create list of plugins
wp plugin list --status=active --skip-plugins --field=name ${WPFLAGS} --allow-root > /tmp/plugin-list.txt

# loop through the plugins
while read -r PLUGIN
do
    echo "--------------------------------------------------------------"
    echo "Deactivating-$PLUGIN"
    wp option get siteurl --skip-plugins="$PLUGIN" --allow-root
done < /tmp/plugin-list.txt

The script generates this easy-to-read output. We can see that I could finally get the siteurl option from the database when WooCommerce or the woocommerce-role-by-amount plugin were deactivated so that tells us the conflict lies there.

--------------------------------------------------------------
Deactivating-advanced-css-editor
--------------------------------------------------------------
Deactivating-appointments
--------------------------------------------------------------
Deactivating-easy-facebook-likebox
--------------------------------------------------------------
Deactivating-export-user-data
--------------------------------------------------------------
Deactivating-pirate-forms
--------------------------------------------------------------
Deactivating-sz-google
--------------------------------------------------------------
Deactivating-heartbeat-control
--------------------------------------------------------------
Deactivating-hide-this
--------------------------------------------------------------
Deactivating-if-menu
--------------------------------------------------------------
Deactivating-lifterlms
--------------------------------------------------------------
Deactivating-lifterlms-customizations-master
--------------------------------------------------------------
Deactivating-lifterlms-labs
--------------------------------------------------------------
Deactivating-lifterlms-integration-woocommerce
--------------------------------------------------------------
Deactivating-magee-shortcodes-pro
--------------------------------------------------------------
Deactivating-mageewp-page-layout
--------------------------------------------------------------
Deactivating-mageewp-page-layout-pro
--------------------------------------------------------------
Deactivating-migrate-guru
--------------------------------------------------------------
Deactivating-mycred
--------------------------------------------------------------
Deactivating-order-import-export-for-woocommerce
--------------------------------------------------------------
Deactivating-checkout-fees-for-woocommerce
--------------------------------------------------------------
Deactivating-per-page-add-to
--------------------------------------------------------------
Deactivating-popup-surveys
--------------------------------------------------------------
Deactivating-query-monitor
--------------------------------------------------------------
Deactivating-really-simple-ssl
--------------------------------------------------------------
Deactivating-redirection
--------------------------------------------------------------
Deactivating-restrict-widgets
--------------------------------------------------------------
Deactivating-shortcode-redirect
--------------------------------------------------------------
Deactivating-spreadshop
--------------------------------------------------------------
Deactivating-user-role-editor
--------------------------------------------------------------
Deactivating-user-shortcodes
--------------------------------------------------------------
Deactivating-widgets-on-pages
--------------------------------------------------------------
Deactivating-woocommerce
http://test.wp-bullet.com
--------------------------------------------------------------
Deactivating-woocommerce-autocomplete-order
--------------------------------------------------------------
Deactivating-woocommerce-checkout-manager
--------------------------------------------------------------
Deactivating-woocommerce-extra-charges-to-payment-gateways
--------------------------------------------------------------
Deactivating-woocommerce-gateway-paypal-express-checkout
--------------------------------------------------------------
Deactivating-woocommerce-time-based-pricing
--------------------------------------------------------------
Deactivating-woocommerce-role-by-amount-spent
https://test.wp-bullet.com
--------------------------------------------------------------
Deactivating-woo-display-price
--------------------------------------------------------------
Deactivating-inspector-wp
--------------------------------------------------------------
Deactivating-wp-customer-reviews
--------------------------------------------------------------
Deactivating-wpdatatables
--------------------------------------------------------------
Deactivating-sp-faq
--------------------------------------------------------------
Deactivating-wp-file-manager
--------------------------------------------------------------
Deactivating-wp-live-chat-support
--------------------------------------------------------------
Deactivating-wp-live-chat-support-pro
--------------------------------------------------------------
Deactivating-youtube-embed-plus

Now I can easily deactivate that plugin to make my troubleshooting with WP-CLI easier!

wp plugin deactivate woocommerce-role-by-amount-spent --skip-plugins --allow-root

I hope this script helps save you some time in diagnosing issues with the expected output of WP-CLI 🙂