A WordPress team ships every Friday. Code reviews catch obvious problems. The thing that ships and breaks production is almost never the code under review — it’s a plugin update that bundled a different vendored library, a wp_options autoload row that doubled in size because someone shipped a new “premium plugin license server” call, or a composer.json change that pulled in an abandoned WordPress.org plugin. The fix is not “be more careful.” It is to run WP-CLI against an ephemeral instance of the site on every PR and fail the build on real signals: plugin vulnerabilities, autoload bloat, broken activations, security misconfigurations. The runbook below is what we install when a team’s “we test in staging” model finally fails them.
What’s happening
WP-CLI is the WordPress command-line tool. It does roughly four things that matter for CI:
- Boot a WordPress instance (
wp core download,wp config create,wp db create,wp core install) — entirely from the shell, no browser needed. - Inspect runtime state (
wp plugin list,wp option get autoload,wp user list,wp post list,wp eval) — query the live state of the install. - Run command packages that extend it (
wp doctor,wp profile,wp scaffold,wp package install) — these add diagnostics, profiling, and code-generation surfaces. - Run arbitrary PHP in the WordPress context (
wp eval,wp shell,wp eval-file) — equivalent to a one-off plugin executing in the bootstrapped runtime.
The CI pattern is straightforward in principle: on every PR, spin up a clean WordPress with the PR’s composer.json (or wp-content/ snapshot), activate all production plugins, run a set of WP-CLI checks, and fail the build if any check trips. In practice, it gets non-obvious in three places: speed (a clean install + plugin activation per PR is slow), state (some checks need representative data, not an empty DB), and reproducibility (a vulnerability scan needs a current advisory feed at the moment of the build, not a stale one).
The fast pattern uses a base Docker image with WordPress, MariaDB, and a known-good baseline already initialized. The PR’s changes get layered on top — plugins activated, theme symlinked, composer dependencies updated — and the WP-CLI checks run against the layered state. Build time stays under three minutes for a typical PR.
How to verify
Before designing the CI, audit what WP-CLI commands actually catch the regressions you’ve seen. On a staging install that mirrors production:
# what does wp doctor find?
wp doctor check --all
# what's the autoload size right now?
wp option list --autoload=yes --fields=option_name,size_bytes \
| sort -k2 -n -r | head -20
# any plugin with a known CVE? (wp-cli/profile-command + wpscan or wpvulnerability package)
wp package install wp-cli/doctor-command:@stable
wp doctor check core-update plugin-update
# any plugin that fails to activate cleanly?
for p in $(wp plugin list --status=inactive --field=name); do
wp plugin activate "$p" --network 2>&1 | tee -a /tmp/activation-log
wp plugin deactivate "$p" --network --quiet
done
grep -i "error\|fatal" /tmp/activation-log
Tabulate what you find. The CI should run the checks that map to real regressions in your codebase’s history — not a generic “run every WP-CLI command” pattern that takes 20 minutes and the team starts ignoring.
The fix
Below is a GitHub Actions workflow that runs the core WP-CLI quality gates on every PR. The same pattern translates to GitLab CI, Buildkite, or Drone with minor changes.
# .github/workflows/wp-ci.yml
name: WordPress CI
on:
pull_request:
paths:
- 'wp-content/**'
- 'composer.json'
- 'composer.lock'
- 'wp-config.php'
jobs:
wp-cli-checks:
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:11.4
env:
MARIADB_ROOT_PASSWORD: root
MARIADB_DATABASE: wp_test
ports:
- 3306:3306
options: >-
--health-cmd="mariadb-admin ping -uroot -proot"
--health-interval=10s --health-timeout=5s --health-retries=5
steps:
- uses: actions/checkout@v4
- name: Set up PHP 8.2 with WP-CLI
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mysqli, mbstring, xml, intl, zip, gd, curl
coverage: none
tools: wp-cli, composer:v2
- name: Cache composer
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
- name: Install composer dependencies
run: composer install --no-progress --no-interaction --no-dev
- name: Download WordPress core
run: |
mkdir -p /tmp/wp
wp core download --path=/tmp/wp --version=$(cat .wp-version 2>/dev/null || echo "latest")
- name: Symlink wp-content + config
run: |
rm -rf /tmp/wp/wp-content
ln -s "$GITHUB_WORKSPACE/wp-content" /tmp/wp/wp-content
cp "$GITHUB_WORKSPACE/wp-config-ci.php" /tmp/wp/wp-config.php
- name: Install WordPress
run: |
wp core install \
--path=/tmp/wp \
--url=http://localhost:8080 \
--title="CI Test" \
--admin_user=ciadmin \
--admin_password=$(openssl rand -hex 12) \
--admin_email=ci@example.com \
--skip-email
- name: Activate production plugins
run: |
# plugin list comes from a checked-in manifest, not the filesystem
while IFS= read -r plugin; do
[ -z "$plugin" ] || [[ "$plugin" =~ ^# ]] && continue
wp plugin activate "$plugin" --path=/tmp/wp
done < .ci-plugin-manifest
- name: Doctor — fatal-on-error checks
run: |
wp doctor check --all --path=/tmp/wp --format=json > /tmp/doctor.json
# fail the build on any 'error' status (warnings logged but don't block)
if jq -e '.[] | select(.status == "error")' /tmp/doctor.json > /dev/null; then
echo "::error::WP Doctor reported errors:"
jq -r '.[] | select(.status == "error") | " - \(.name): \(.message)"' /tmp/doctor.json
exit 1
fi
- name: Autoload bloat threshold
run: |
BLOAT=$(wp option list --autoload=yes --format=json --path=/tmp/wp | jq '[.[].size_bytes // 0] | add')
echo "Total autoload size: $BLOAT bytes"
if [ "$BLOAT" -gt 1048576 ]; then
echo "::error::Autoload size $BLOAT bytes exceeds 1 MB threshold"
wp option list --autoload=yes --format=table --fields=option_name,size_bytes --path=/tmp/wp \
| sort -k2 -n -r | head -10
exit 1
fi
- name: Plugin vulnerability scan
run: |
wp package install wp-cli/wpvulnerability-command:@stable --quiet || true
wp wpvulnerability --path=/tmp/wp --format=json > /tmp/vulns.json || true
# fail on any critical or high severity
CRIT=$(jq '[.[] | select(.severity == "critical" or .severity == "high")] | length' /tmp/vulns.json)
if [ "$CRIT" -gt 0 ]; then
echo "::error::Critical or high-severity plugin vulnerabilities found:"
jq -r '.[] | select(.severity == "critical" or .severity == "high") | " - \(.plugin): \(.title) (\(.severity))"' /tmp/vulns.json
exit 1
fi
- name: Security misconfig checks
run: |
# file edit must be disabled
wp eval 'if (!defined("DISALLOW_FILE_EDIT") || !DISALLOW_FILE_EDIT) { echo "DISALLOW_FILE_EDIT not set\n"; exit(1); }' --path=/tmp/wp
# debug logging must not go to display in production config
wp eval 'if (defined("WP_DEBUG_DISPLAY") && WP_DEBUG_DISPLAY) { echo "WP_DEBUG_DISPLAY is on\n"; exit(1); }' --path=/tmp/wp
# admin user must not be named "admin"
if wp user get admin --path=/tmp/wp 2>/dev/null; then
echo "::error::User 'admin' exists — rename or remove"
exit 1
fi
- name: Cron health
run: |
# any cron entries for past-due jobs?
OVERDUE=$(wp cron event list --due-now --format=count --path=/tmp/wp)
if [ "$OVERDUE" -gt 0 ]; then
wp cron event list --due-now --format=table --path=/tmp/wp
# informational, not blocking — but log it
echo "::warning::$OVERDUE cron events overdue at install time"
fi
- name: REST API smoke
run: |
# boot PHP server in background, hit /wp-json
php -S 127.0.0.1:8080 -t /tmp/wp >/tmp/php-server.log 2>&1 &
SERVER_PID=$!
sleep 2
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/wp-json/)
kill $SERVER_PID
if [ "$STATUS" != "200" ]; then
echo "::error::REST API returned $STATUS at /wp-json/"
cat /tmp/php-server.log
exit 1
fi
- name: Profile baseline
run: |
wp package install wp-cli/profile-command:@stable --quiet || true
wp profile stage bootstrap --orderby=time --order=desc --path=/tmp/wp | head -20
A few patterns worth calling out:
The plugin manifest is checked into the repo. A file like .ci-plugin-manifest lists exactly which plugins should be active in production. CI fails if a plugin in wp-content/plugins/ is not in the manifest, or vice versa. This catches the “someone uploaded a plugin to production via FTP” class of drift.
The doctor checks split into blocking vs. warning. core-update and plugin-update-major are warnings (you’ll update on a cadence, not on every PR). core-verify-checksums, plugin-active-count, and cron-count are blocking.
Vulnerability scan results are cached on a daily cadence, not per-build. The wpvulnerability package hits an advisory feed; rate-limiting that with a daily cache keeps build times down and the feed unangered. Production-critical advisories override the cache and fail the build immediately.
State for representative checks. If a check needs real data (e.g., “does this query return in under 100ms with 50k posts?”), seed the CI database from a sanitized production dump, not from an empty install. The seed file is built nightly by a separate job and stored in CI artifact storage.
For nightly deeper checks that don’t fit in a PR timeline (full security scan, full plugin compatibility matrix), use a separate workflow on a schedule. Keep the PR pipeline under three minutes.
Stack Harbor designs and operates the CI pipeline for WordPress under the Deployment Management service — including the WP-CLI gate, the plugin manifest discipline, and the vulnerability advisory feed. If your team is shipping WP changes without a CLI gate on every PR, we can scope and install the pipeline.
Stack Harbor operates production WordPress at scale — see enterprise WordPress operations for the managed model, or book a WordPress consult for a written read of your current shape.