Code Snippets
These abilities register when Code Snippets is detected on the site and a Pro licence is active. If either is missing the module stays absent rather than failing at call time.
At a glance
Code Snippets registers 11 abilities: 6 that only read, 3 that write, and 2 marked destructive. That split is the practical answer to how much of this module can run unattended. Reads cost nothing and are safe to repeat, so discovery is the part to be generous with; the writes are where review belongs, and the destructive calls stop for an explicit confirmation every single time regardless of which profile is active.
What this module is for
List, inspect, validate, create, edit, enable, disable, and delete Code Snippets with type and condition schema discovery.
Before you rely on it: Code execution is privileged: use staging, backups, review, and a recovery path before enabling any generated snippet.
Typical workflows
- Validate a disabled snippet before enabling it
- Inspect condition schemas before scoping execution
- Disable a problematic snippet while preserving its source for review
The Code Snippets integration page covers the same module from the workflow side, with the capability map and the questions worth asking before a first write.
Availability on your site
The Code Snippets module needs three things at once: WPPilot Free as the MCP foundation, an active Pro licence, and the companion plugin detected on the site. Miss any one and the module does not register, which is deliberate: an ability that appears in the tool list but fails at call time is worse than an ability that was never offered. What the connected agent can actually call is then narrowed twice more: by the safety profile active on the site, and by the WordPress capabilities of the user behind the credential. A read that succeeds for an administrator can be absent entirely for an editor.
Every write these abilities perform is recorded in the change ledger, and destructive calls can be routed through the approval queue so a person signs off before anything is applied. A successful tool result means the operation returned, not that the front end, the cache, and every dependent template are correct: that still needs a look.
Reads
Available in every safety profile, including Read Only. Inspection costs nothing and is not rate limited.
| Ability | What it does |
|---|---|
wppilot/code-snippets-check-setupCheck Code Snippets Setup | Returns a snapshot of the Code Snippets install: which variant is active (free or Pro), version, whether the minimum supported release is satisfied, the list of snippet types available on this install (free = php/html; Pro adds css/js/cond), and counts of total / active snippets. Call this once at the start of any session that will read or write snippets. |
wppilot/code-snippets-get-conditions-schemaGet Conditions Schema | Pro-only reference for the Code Snippets conditions feature. A condition is itself a snippet of type=cond + scope=condition whose code field stores a JSON tree of rules; other snippets attach to a condition via their condition_id. This ability returns the catalog of supported subjects (siteArea, currentQuery, postType, userRole, currentDate, …), their operators (equals is implicit; date subjects also support before / after / between), and a worked JSON example so an agent can compose valid conditions without reading the plugin source. Returns available: false on a free install since conditions are Pro-only. |
wppilot/code-snippets-get-snippetGet Code Snippet | Reads a single snippet by id, including the executable code body and all metadata (name, desc, type, scope, tags, priority, active flag, modified timestamp, revision, condition_id, plus a shortcode field when type=html scope=content). Returns WP_Error cs_not_found when the id does not exist. |
wppilot/code-snippets-get-types-schemaGet Code Snippets Types Schema | Returns the type / scope reference for Code Snippets: which type accepts which scope values, what each scope means in terms of when the snippet runs, and which types require Code Snippets Pro. Pass type (e.g. "php") to receive only that type entry — useful when an agent already knows the family and wants to keep the response small. Otherwise the full matrix is returned. Call this once before authoring a snippet so create / edit send the right type+scope pair on the first try. |
wppilot/code-snippets-list-snippetsList Code Snippets | Lists snippets with optional filters. Response is a compact summary per snippet — id, name, type, scope, tags, priority, active, network, modified — WITHOUT the code field so listings stay small. Call code-snippets-get-snippet with a specific id to read the executable code. Filters: type (php|html|css|js|cond), scope, active (bool), tag (substring match against the snippet's tag list), search (case-insensitive substring match against name, desc, and code). Pagination: limit (default 100, max 500 — values above the cap are REJECTED with ability_invalid_input, not silently clamped), offset (default 0, must be ≥0). total in the response always reflects the unpaginated match count so the agent knows whether to keep paging. |
wppilot/code-snippets-validate-snippetValidate Code Snippet | Lints a PHP snippet body for syntax errors WITHOUT saving or executing it. The check runs token_get_all($source, TOKEN_PARSE) over the prefixed source so PHP's parser walks every token (catching both ParseError and CompileError, which is what some PHP 8.4 constructs throw) but never invokes the runtime. Use this as a pre-flight step before code-snippets-enable-snippet. For non-PHP types (html / css / js / cond) the call returns valid: true, skipped: true immediately — cond bodies are JSON, not PHP, so running the parser on them would produce false negatives. To lint a snippet you have NOT saved yet, pass code directly; to lint an existing snippet, pass id. |
Writes
Gated by the active profile and your WordPress capabilities. Rate limited to 120 per minute per credential.
| Ability | What it does |
|---|---|
wppilot/code-snippets-disable-snippetDisable Code Snippet | Deactivates a snippet by id. The snippet body stays in the database (unchanged) but stops executing on the next request. Reversible by code-snippets-enable-snippet. Calling disable on an already-inactive snippet is a no-op. |
wppilot/code-snippets-edit-snippetEdit Code Snippet | Merges new field values into an existing snippet identified by id. Only the keys you pass are changed — omitted keys keep their current value. To change type and scope together, pass both (changing one without the other often produces an invalid pair). The active flag is NOT touched here — use code-snippets-enable-snippet / code-snippets-disable-snippet for toggling execution. Code Snippets re-validates the PHP code on save and deactivates the snippet if the code errors; the result then includes deactivated_on_save and code_error. |
wppilot/code-snippets-enable-snippetEnable Code Snippet | Activates a snippet by id. From this point on, the snippet code runs on every matching request (based on its scope) — for PHP that means it can hook into actions / filters, for HTML it becomes a shortcode or head/footer markup, for CSS / JS it gets enqueued. ALWAYS call code-snippets-validate-snippet first on PHP bodies — the plugin only catches a narrow set of activation-time problems (duplicate function names, missing class identifiers) and surfaces those under error_line; a plain PHP syntax error slips past activation and fatals on the next render. Calling enable on an already-active snippet is a safe no-op (returns success: true without re-firing activation hooks). |
Destructive
Marked destructive in the source, so each call needs an explicit confirmation flag, every time.
| Ability | What it does |
|---|---|
wppilot/code-snippets-create-snippetCreate Code Snippet | Creates a new snippet. Required: name, code, type (php|html|css|js|cond), scope. Optional: desc, tags[], priority. SAFETY: the new snippet is always created INACTIVE — it is saved to the database but does NOT run on the site until you call code-snippets-enable-snippet (or pass activate: true to opt into immediate activation, in which case the agent takes responsibility for the safety review). The css / js / cond types require Code Snippets Pro on this install; the response surfaces a clear error when an unavailable type is requested. Note: Code Snippets does NOT enforce unique name — multiple snippets may share the same name; identify rows by the id returned in snippet.id. Note: operates on the per-site wp_snippets table only; network-shared snippets in wp_ms_snippets are out of scope. |
wppilot/code-snippets-delete-snippetDelete Code Snippet | Permanently removes a snippet by id. There is no soft-delete — once deleted the snippet cannot be recovered via the abilities. The plugin auto-deactivates active snippets before delete so the code stops executing immediately. IMPORTANT: delete only removes the snippet row — it does NOT undo durable side effects the snippet body created during prior executions (scheduled WP-Cron events via wp_schedule_event survive the delete and continue firing forever as silent no-ops; dbDelta-created tables remain; persisted options remain). For snippets that wired durable side effects, prefer code-snippets-disable-snippet first, then have the user run a cleanup snippet to reverse those effects, then delete. |