WP Webhooks / Docs / create_snippet
AI Ability since v1.3.0

create_snippet

Create a Code Glue snippet — Create a Code Glue PHP snippet (inert until assigned to a webhook).

$

Create a Code Glue PHP snippet (inert until assigned to a webhook). Write plain PHP without a <?php tag. PRE-dispatch snippets receive $payload — the payload AFTER the field mapping has run — and MUST end with return $payload;, returning the FULL modified array (a non-array return leaves the payload unchanged). $args is just $payload["args"], so it is an empty array unless the mapping kept an "args" key (with includeUnmapped:false it does not, and $args[0] is silently missing) — read mapped target names instead, or map the source field through first. POST-dispatch snippets receive $payload (as sent), $originalPayload (pre-mapping), $responseCode and $responseBody, and run for side effects only (return value ignored). The shorthand {{ $args.0.total }} expands to $args[0]["total"] and is only safe when "args" survives the mapping. Always test with preview_snippet (it feeds the real mapped payload) before assign_snippet. Registered as the WordPress Ability flowsystems-webhook-actions/create-snippet, so external AI tools (Claude Code, Cursor) can call it over MCP, or over the Abilities REST route with a scoped API token.

/ Plan step shape

{ "ability": "create_snippet", "input": { "name": …, "code": …, "tags": … } }

/ Scope & confirmation

Minimum API-token scope for external (MCP/REST) callers: full. Runs without a confirmation pause (the overall plan is still user-approved before execution starts).

/ Input fields

NameInTypeReqDescription
nameparamstringyesShort descriptive name.
codeparamstringyesPHP code, no <?php tag.
tagsparamarray—

/ Examples

Plan step as Build with AI proposes it

{
  "id": "step_1",
  "ability": "create_snippet",
  "summary": "…",
  "input": {
    "name": "Add order total tag",
    "code": "$payload[\"tag\"] = {{ $args.0.total }} > 100 ? \"vip\" : \"standard\";\nreturn $payload;",
    "tags": [
      "orders"
    ]
  }
}

/ Related

Ready

Your next automation is
one sentence away.

$ wp plugin install flowsystems-webhook-actions --activate