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 mapped payload array) and $args ($payload["args"]) and MUST end with return $payload; — return the FULL modified array (a non-array return leaves the payload unchanged). POST-dispatch snippets receive $payload (as sent), $originalPayload, $responseCode and $responseBody, and run for side effects only (return value ignored). The shorthand {{ $args.0.total }} expands to $args[0]["total"]. Always test with preview_snippet 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 REST 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
| Name | In | Type | Req | Description |
|---|---|---|---|---|
| name | param | string | yes | Short descriptive name. |
| code | param | string | yes | PHP code, no <?php tag. |
| tags | param | array | — |
/ Examples
Plan step as the AI Builder 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