---
title: "create_snippet — AI Ability"
description: "Create a Code Glue snippet — Create a Code Glue PHP snippet (inert until assigned to a webhook)."
url: "https://wpwebhooks.org/docs/ability-create-snippet/"
---

[WP Webhooks](/) / [Docs](/docs/) / create\_snippet

AI Ability Pro 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 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

[preview\_snippet](/docs/ability-preview-snippet/)[assign\_snippet](/docs/ability-assign-snippet/)[Code Glue](/docs/code-glue/)[REST API reference](/webhook-wordpress-plugin-api/)

/Ready

## Your next automation is  
one sentence away.

[Install Plugin→](https://wordpress.org/plugins/flowsystems-webhook-actions/) [See the Plugin →](/wordpress-webhook-plugin/)

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

## Structured data

```json
{"@context":"https://schema.org","@type":"TechArticle","name":"create_snippet — AI Ability — Webhook Actions Docs","description":"Create a Code Glue snippet — Create a Code Glue PHP snippet (inert until assigned to a webhook).","url":"https://wpwebhooks.org/docs/ability-create-snippet/","isPartOf":{"@type":"WebSite","name":"WP Webhooks","url":"https://wpwebhooks.org"},"about":{"@type":"SoftwareApplication","name":"Webhook Actions","applicationCategory":"WordPress Plugin"}}
```
