Skip to content

WP-CLI Batch Script Runbook

Origin: Extracted from knowledge/lessons/wordpress/cli-and-deploy.md during knowledge restructure (2026-05-20). The procedure body is preserved verbatim below.

WP-CLI Batch Scripts for Multi-Site Operations

From legacy section: Hostinger / Server

Pattern: Needed to reset passwords, kill sessions, install plugins, rename users, and set options across 38 WordPress sites. Individual SSH commands hit the 1000-char limit. Running a single script timed out at 60s. Rule: For multi-site operations: (1) Write a bash script locally in build/, (2) SCP to ~/scripts/ on server, (3) Run with nohup bash script.sh > output.txt 2>&1 &, (4) Poll with sleep 55 && ps aux | grep script | grep -v grep | wc -l && tail -10 output.txt, (5) Delete script from server after confirmed run. Never put passwords in scripts that get committed — delete before git backup. Date: 2026-04-14


For 5+ WordPress pages of the same change, use WP-CLI eval-file over SSH — not MCP calls

From legacy section: SEO NEO / Workbook

WordPress MCP's create_page / update_page echo the full rendered post content in the tool response. For a typical ~18KB schema/audit page, that's ~25KB of response tokens per call. Across 10 audit publishes + 1 index update, that's ~280KB of repeated content in context. SSH path: build a single PHP script that does all 10 wp_insert_post + 1 wp_update_post calls, scp it to /home/u488157871/scripts/<site>/, run via ssh ... wp ... eval-file. Returns ~20 lines of [OK] page_id -> url. Total token cost ~5KB. Why: Confirmed 2026-05-13 batch publish of 10 light-tier audits. The first 3 went via WP MCP create_page and each burned ~50K tokens (content sent + content echoed back). Switched to PHP+wp-eval-file for the remaining 7 + index update; the whole batch returned in 20 lines of text. Same end state (10 published pages + index updated), 5-10x cheaper in context. How to apply: 1. MCP create/update is fine for ONE page at a time — context cost is acceptable. 2. For 5+ pages of the same site, batch via wp-eval-file — build a single PHP script locally, scp HTML files alongside, run via wp --path=/home/u488157871/domains/<site>/public_html eval-file /home/u488157871/scripts/<site>/publish.php. 3. For mu-plugin schema deploys via _evolve_schema post meta, use wp post meta update <id> _evolve_schema "$(cat <file>.json)" over SSH — one call per page, response is just Success. 4. Pattern works for any bulk WP operation — bulk slug changes, bulk meta updates, bulk schema rolls, bulk redirect-map additions. Date: 2026-05-18


Server path conventions (Evolve standard)

  • Deploy scripts to: /home/u488157871/scripts/<SITENAME>/ (outside web root — never public_html)
  • SCP command: scp -P 65002 build/script.php u488157871@156.67.77.152:/home/u488157871/scripts/<SITENAME>/
  • Run command: wp --path=/home/u488157871/domains/<DOMAIN>/public_html eval-file /home/u488157871/scripts/<SITENAME>/script.php
  • Delete from server after confirmed run — local build/ is the source of truth

See also: ~/.claude/CLAUDE.md → "WordPress Bulk Operations — WP-CLI Batch Scripts" for the standard script safety flags template.