30 days free. No credit card. Full access from the moment you connect your site.

Start free trial

Create Code Snippet

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

Abilitysnippets/create-snippet
ToolsetWPCode — toolset/wpcode
GroupWPCode › Snippets
RequiresWPCode, active on the site
Capabilitymanage_options
SafetyWrites data
RepeatableNot idempotent — each call changes the row set, so re-running is not a no-op
Ships inAcrossAI 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

NameTypeRequiredWhat it is
code_typestringYesOne of php, js, css, html, text or universal.
titlestringYesSnippet title.
codestringYesThe snippet body. For the php type, leave the opening PHP tag off; for html and universal you may include it.
notestringNoInternal note. Never output anywhere on the site.
priorityintegerNo — defaults to 10Execution order; lower runs earlier.
custom_shortcodestringNoA custom shortcode tag for rendering this snippet manually.
tagsarrayNoTags, as a list of strings.
confirmbooleanYes — must be trueThe irreversibility gate. Without it the call is refused before anything is touched.

What comes back

NameTypeWhat it is
snippetobjectThe created snippet.
in_cachebooleanWhether WPCode’s loader cache holds the snippet. This, not the post status, is what decides whether it actually runs.
safe_modebooleanWhether safe mode is active. When it is, no snippet runs regardless of everything else.
successbooleanWhether the call completed.
messagestringA one-line summary of what happened, suitable for showing a human.
error_codestringPresent 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 php and universal only.

Related abilities


Get the plugins:
AcrossAI Abilities Manager · AcrossAI MCP Manager

Browse the rest: Every ability, by category


Keep reading