šŸ¤– Automating WordPress Admin Tasks with ChatGPT & WP-CLI

automating admin tasks with chatGPT featured image

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *