snippets/create-snippet creates a WPCode snippet of any supported type: PHP, JS, CSS, HTML, text or universal.
It is always created inactive. Activating is a separate, deliberate call.
At a glance
| Ability | snippets/create-snippet |
| Toolset | WPCode — toolset/wpcode |
| Group | WPCode › Snippets |
| Requires | WPCode, active on the site |
| Capability | manage_options |
| Safety | Writes data |
| Repeatable | Not idempotent — each call changes the row set, so re-running is not a no-op |
| Ships in | AcrossAI Abilities Manager 0.0.34 and later |
Why PHP and universal need confirmation
PHP and universal snippets execute on this site. Code arriving through an assistant is code somebody described rather than wrote, and the gap between the description and what the code does is exactly where this goes wrong. The confirmation is there to make that a deliberate step rather than a consequence of a sentence. The snippet is created inactive either way, so nothing runs until snippets/activate-snippet is called separately.
Why it does not insert the post directly
A WPCode snippet is a custom post type, so inserting one looks trivial. It is not: the code type is a taxonomy term, the error state is meta the loader reads, and the loader cache has to be rebuilt for any of it to take effect.
WPCode does not read the snippets table on every request. It builds a loader cache and runs from that, which is why a snippet can be published in the database and still be completely inert — and why writing the snippet post type directly through the content or database abilities produces a row that looks right and does nothing.
Going through WPCode’s own save routine keeps all three in step — the term is set, the error state is initialised, the cache is rebuilt — and the response reports whether the snippet made it into the cache.
Creating inactive is not a safety gesture so much as the only sensible default. A snippet created by an assistant is code nobody has read yet, and the gap between creating and activating is where reading happens.
Input
| Name | Type | Required | What it is |
|---|---|---|---|
code_type | string | Yes | One of php, js, css, html, text or universal. |
title | string | Yes | Snippet title. |
code | string | Yes | The snippet body. For the php type, leave the opening PHP tag off; for html and universal you may include it. |
note | string | No | Internal note. Never output anywhere on the site. |
priority | integer | No — defaults to 10 | Execution order; lower runs earlier. |
custom_shortcode | string | No | A custom shortcode tag for rendering this snippet manually. |
tags | array | No | Tags, as a list of strings. |
confirm | boolean | Yes — must be true | The irreversibility gate. Without it the call is refused before anything is touched. |
What comes back
| Name | Type | What it is |
|---|---|---|
snippet | object | The created snippet. |
in_cache | boolean | Whether WPCode’s loader cache holds the snippet. This, not the post status, is what decides whether it actually runs. |
safe_mode | boolean | Whether safe mode is active. When it is, no snippet runs regardless of everything else. |
success | boolean | Whether the call completed. |
message | string | A one-line summary of what happened, suitable for showing a human. |
error_code | string | Present only on failure — a stable machine-readable reason, such as a missing field, a wrong field type or an unmet confirmation. |
Example
Ask your assistant:
Add a CSS snippet that hides the admin bar for subscribers.
It resolves to one call:
{
"ability": "snippets/create-snippet",
"parameters": {
"code_type": "css",
"title": "Hide admin bar for subscribers",
"code": ".role-subscriber #wpadminbar { display: none; }",
"priority": 10
}
}Worth knowing
- Always created inactive. Activate separately once you have read the code.
- PHP snippets take no opening tag. Including one is the most common creation error.
- Not idempotent — two calls make two snippets.
- Confirmation is required for
phpanduniversalonly.
Related abilities
- Activate Code Snippet — switch it on once reviewed
- Set Snippet Location — decide where it is inserted
- Update Code Snippet — change it before activating
Get the plugins:
AcrossAI Abilities Manager · AcrossAI MCP Manager
Browse the rest: Every ability, by category