Debugging Empty WP-CLI Output: Finding the Problematic Plugin

When WP-CLI commands mysteriously return no output, it’s often due to a misbehaving plugin. Here’s a quick script that helped me identify the culprit:

bash
for plugin in $(wp plugin list --field=name --skip-plugins); do
    echo -e "\033[1;34m-----------------------------------------\033[0m"
    echo -e "\033[1;33mTesting with --skip-plugins=$plugin...\033[0m"
    
    output=$(wp eval 'echo "test";' --skip-plugins="$plugin")
    
    if [ ! -z "$output" ]; then
        echo -e "\033[1;32mSuccess! Output: $output\033[0m"
        echo -e "\033[1;31mProblem likely caused by: $plugin\033[0m"
        echo -e "\033[1;34m-----------------------------------------\033[0m"
        break
    else
        echo -e "\033[1;31mNo output. Moving to the next plugin.\033[0m"
    fi
done

This script iterates through each plugin, disabling them one at a time until WP-CLI output is restored. When output appears, you’ve found your problematic plugin.

The script uses color coding for better visibility:

  • Blue: Separators
  • Yellow: Current test
  • Green: Success
  • Red: Issues/problematic plugin

Save this as debug-wpcli.sh and run it from your WordPress root directory.

Happy debugging!

Comments

Leave a Reply

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

To respond on your own website, enter the URL of your response which should contain a link to this post’s permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post’s URL again. (Find out more about Webmentions.)