Skip to content

Instantly share code, notes, and snippets.

@bhubbard
Created July 9, 2025 12:47
Show Gist options
  • Select an option

  • Save bhubbard/fb59abe8c3917390b4ae31d2a5147b76 to your computer and use it in GitHub Desktop.

Select an option

Save bhubbard/fb59abe8c3917390b4ae31d2a5147b76 to your computer and use it in GitHub Desktop.
#!/bin/bash
# A WP-CLI script to install, run, and uninstall the WP-Sweep plugin.
# This automates the process of cleaning the WordPress database.
# --- Configuration ---
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Script Start ---
echo "πŸš€ Starting the automated WordPress database sweep..."
echo "----------------------------------------------------"
# Check if WP-CLI is installed and available
if ! command -v wp &> /dev/null
then
echo "❌ Error: WP-CLI could not be found. Please install it and make sure it's in your PATH."
exit 1
fi
# 1. Check for the WP-Sweep plugin
echo "πŸ”Ž Checking for the 'wp-sweep' plugin..."
if wp plugin is-installed wp-sweep; then
echo "βœ… 'wp-sweep' is already installed. Ensuring it's active..."
wp plugin activate wp-sweep
else
echo "πŸ”Œ 'wp-sweep' not found. Installing and activating now..."
# Install and activate the plugin from the WordPress repository
wp plugin install wp-sweep --activate
echo "πŸ‘ 'wp-sweep' has been successfully installed and activated."
fi
echo "" # Add a blank line for readability
# 2. Run all the cleaning tasks
echo "🧹 Running all sweep operations. This might take a moment..."
# The --all flag runs every available sweep task.
wp sweep --all
echo "" # Add a blank line for readability
# 3. Uninstall and deactivate the plugin
echo "πŸ—‘οΈ Cleaning up: Uninstalling the 'wp-sweep' plugin..."
wp plugin uninstall wp-sweep --deactivate
echo "----------------------------------------------------"
echo "βœ… Success! The database has been swept and the plugin has been removed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment