WP-CLI Command for Cleanly Removing Unused Plugins

My testing WP-Admin ends up being bloated with unused plugins/themes every now and then.

Going through each one and clicking uninstall is not very efficient so I wrote this little bash script that works with WP-CLI.

Dry Run:

wp plugin list --format=csv --fields=name,status | grep 'inactive$' | cut -d ',' -f 1 | echo

Final wipe

wp plugin list --format=csv --fields=name,status | grep 'inactive$' | cut -d ',' -f 1 | xargs wp plugin uninstall


# List all plugins and their statuses
wp plugin list --format=csv --fields=name,status  \

# Select strings that end with inactive
| grep 'inactive$' \

# Select the first column from a comma delimited string
| cut -d ',' -f 1 \

# Combine lines into a single line of arguments for following command
| xargs \

# Properly uninstall (calling all the hooks) and delete plugins
wp plugin uninstall