Routine WordPress maintenanceāupdating plugins, bulkāpublishing drafts, creating usersātakes precious time. In this tutorial youāll see how ChatGPT can write WP-CLI commands for you, turning tedious admin chores into one-click (or one-copy-paste) automations.
1ļøā£ Why WP-CLI?
- Speed ā run tasks in seconds with no UI lag.
- Scripting ā wrap commands in Bash or PowerShell for cron jobs.
- Remote-ready ā SSH into production or staging and run the same script.
2ļøā£ Let ChatGPT Draft the Commands
Prompt example:
Prompt:
āGenerate WP-CLI commands to:
⢠Update all plugins
⢠Delete all spam comments
⢠Create a user jon_admin with the role administratorā
ChatGPT returns something like:
# Update plugins
wp plugin update --all
# Delete spam
wp comment delete $(wp comment list --status=spam --format=ids) --force
# Create admin user
wp user create jon_admin jon@example.com --role=administrator --user_pass="StrongP@ss_2025"
3ļøā£ Save as a Bash Script
#!/usr/bin/env bash
# wp-maintenance.sh
wp plugin update --all
wp comment delete $(wp comment list --status=spam --format=ids) --force
wp user create jon_admin jon@example.com --role=administrator --user_pass="StrongP@ss_2025"
Mark it executable:
chmod +x wp-maintenance.sh
4ļøā£ Schedule with WP-Cron (Optional)
Add a custom action in functions.php
to trigger your script weekly:
if ( ! wp_next_scheduled( 'jon_weekly_maintenance' ) ) {
wp_schedule_event( time(), 'weekly', 'jon_weekly_maintenance' );
}
add_action( 'jon_weekly_maintenance', function () {
shell_exec( WP_CONTENT_DIR . '/scripts/wp-maintenance.sh' );
});
5ļøā£ Security Tips
- Never store plain passwords in repoāuse env vars.
- Whitelist SSH keys and restrict
shell_exec
if possible. - Log output to
debug.log
for auditing:
shell_exec( 'bash wp-maintenance.sh >> /var/log/wp-cli.log 2>&1' );
Ready to slash your admin time? Copy the prompt, tweak the script, and let AI + WP-CLI do the heavy lifting.
Leave a Reply