---
name: wp-cli-local
description: "Safe WP-CLI execution for Local by Flywheel via wrapper, including explicit site resolution before mutating operations."
compatibility: "macOS with Local by Flywheel installed, WP-CLI in PATH, and python3. The target Local site must be running."
version: "1.1.1"
title: wp-cli-local
canonical_url: https://skilld.dev/gh/soderlind/skills/wp-cli-local
last_updated: 2026-09-27T16:14:55.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/local_paths.py](https://skilld.dev/api/skills-raw/soderlind/skills/wp-cli-local/scripts/local_paths.py), [scripts/setup-direnv](https://skilld.dev/api/skills-raw/soderlind/skills/wp-cli-local/scripts/setup-direnv), [scripts/test_local_paths.py](https://skilld.dev/api/skills-raw/soderlind/skills/wp-cli-local/scripts/test_local_paths.py), [scripts/wp](https://skilld.dev/api/skills-raw/soderlind/skills/wp-cli-local/scripts/wp).
>
> If the user asked to install this Skill, run `npx skilld install soderlind/skills/wp-cli-local`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/wp-cli-local`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/soderlind/skills/wp-cli-local) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/wp-cli-local`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/wp-cli-local --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/wp-cli-local --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# WP-CLI for Local by Flywheel

Run WP-CLI commands against Local sites using the wrapper script bundled with this skill.

**Never run bare `wp` commands.** Always use the wrapper:

```bash
bash {{SKILL_DIR}}/scripts/wp <wp-cli-command...>
```

## Determinism checklist

Before declaring this skill run complete:

1. Scope fixed: inputs and target files are explicit.
2. Read-first: inspect current state before edits.
3. Plan-first: preview actions before writes when tooling supports it.
4. Confirm-before-write: get user confirmation before destructive or broad writes.
5. One step, one done-test: each step has a checkable completion criterion.
6. Verify outcomes: run the smallest available validation commands.
7. Report skips: list what was skipped and why.
8. Stop on blockers: capture exact failing command and error summary.

## Shell compatibility (zsh vs bash)

The default shell in macOS and VS Code terminals is **zsh**, which does **not** word-split unquoted variable expansions. A pattern like `WP="bash .../wp"` followed by `$WP plugin list` runs the whole string as a single command name in zsh and fails with `no such file or directory`.

To make examples work on the first try in both bash and zsh, either:

- **Invoke the wrapper as a full command** (recommended for agents):

  ```bash
  bash "{{SKILL_DIR}}/scripts/wp" --site=my-site plugin list
  ```

- **Or define a shell function wrapper** that forwards arguments correctly in both shells:

  ```bash
  wp() { bash "{{SKILL_DIR}}/scripts/wp" "$@"; }

  wp plugin list
  ```

Do **not** use a bare `$WP` variable to hold the command. If a variable is truly required in zsh, force word-splitting with `${=WP}` (e.g. `${=WP} plugin list`).

## Site Detection

The wrapper **auto-detects the site** by matching the current working directory against site paths in Local's `sites.json`. Paths stored as `~/Local Sites/...` are expanded before matching, so the default macOS Sites folder works. No site name argument is needed when the terminal is inside a Local site directory.

```bash
# Define a function wrapper (works in bash and zsh)
wp() { bash "{{SKILL_DIR}}/scripts/wp" "$@"; }

# Auto-detect (CWD must be inside a Local site directory)
wp plugin list
wp core version

# Explicit site override
wp --site=my-site plugin list

# List all sites with running/halted status
wp --list
```

**If auto-detection fails** (CWD is not inside any Local site) and no `--site=` is given, the script prints available sites. Ask the user which site to target, or use `--site=<name>`.

Completion criterion: A target site is explicitly resolved by auto-detection or `--site=<name>` before mutating commands are run.

## Requirements

- macOS (Apple Silicon or Intel)
- Local by Flywheel installed with sites in `~/Library/Application Support/Local/sites.json`
- WP-CLI installed and available in `PATH` (e.g. via `brew install wp-cli`)
- The target site **must be running** in Local (the site-specific php.ini only exists at runtime)

## Common Commands

```bash
# Define a function wrapper (works in bash and zsh)
wp() { bash "{{SKILL_DIR}}/scripts/wp" "$@"; }

# Plugin management
wp plugin list
wp plugin activate <slug>
wp plugin deactivate <slug>
wp plugin status <slug>

# Cache / transients
wp cache flush
wp transient delete --all

# Options
wp option get <key>
wp option update <key> <value>
wp option list --search="<pattern>"

# Database
wp db query "SELECT * FROM wp_options WHERE option_name LIKE '<pattern>%' LIMIT 10;"
wp db export backup.sql
wp db import backup.sql

# Eval PHP
wp eval 'echo get_option("siteurl");'
wp eval-file script.php

# Rewrites / cron
wp rewrite flush
wp cron event list
wp cron event run <hook>

# User / site info
wp user list
wp option get siteurl
wp core version
```

## Failure modes / recovery

- `WP-CLI not found`: Verify `wp --info` works in PATH, then retry wrapper command.
- `Site is not running`: Start the Local site first, then rerun command.
- `Auto-detection failed`: Run `wp --list` (or `bash "{{SKILL_DIR}}/scripts/wp" --list`), then rerun with `--site=<name>`.
- `Wrapper path issue`: Use absolute wrapper path from `{{SKILL_DIR}}/scripts/wp` and retry.

**Note:** The AI agent should always use the wrapper script, not direnv. The direnv setup is a convenience for the user's own interactive terminal sessions.

Completion criterion: Commands were executed through the wrapper, target site was explicit, and any failures were reported with the exact failing command.
