The method
Use this prompt in ChatGPT to generate shell scripts that leverage WP-CLI for automating WordPress tasks. Provide context about your desired workflow, database access, file paths, and any external dependencies. Refine the prompt iteratively for optimal results.
The prompts
Prompt 1
I need a shell script that automates the process of backing up my WordPress database using WP-CLI. The script should: 1. Create a directory named 'wp-backups' in the /var/www/html/ directory if it doesn't exist. 2. Export the WordPress database to a file named 'wp_backup_[date].sql' in the 'wp-backups' directory, where [date] is the current date in YYYYMMDD format. 3. Compress the SQL file using gzip. 4. Output a message indicating the backup was successful, including the filename and location of the backup. Ensure the script handles cases where WP-CLI is not installed or the database credentials are incorrect. Also add error handling and logging to a file called backup.log in the same directory.
Prompt 2
Create a shell script using WP-CLI that automates plugin updates for a WordPress site. The script should: 1. Check for available plugin updates. 2. Update all plugins if updates are available. 3. Output a list of plugins that were updated, or a message indicating that no updates were available. 4. Implement a rollback mechanism: before updating plugins, create a database backup using WP-CLI. If any plugin update fails, restore the database from the backup. The script must log all actions, including plugin updates and rollback attempts, to a file named 'plugin_updates.log'. This script will run on a Ubuntu 20.04 server with WP-CLI pre-installed.