Created
July 9, 2025 12:47
-
-
Save bhubbard/fb59abe8c3917390b4ae31d2a5147b76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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