snippet_save
Create or update PHP, CSS, JS, or HTML snippets on a WordPress site, control where they run and whether they are active, and record purpose and impact.
Instructions
Create or update a code snippet that runs on the site — like WPCode/Code Snippets. Types: php (runs in WordPress; NO <?php tags; use add_action/add_filter/functions), css, js, html. Location controls where it runs: everywhere, admin_only, frontend_only, header (wp_head), footer (wp_footer), before_content, after_content, shortcode (use [keelhob_snippet id=N]), or page_template (serve raw PHP/HTML as a whole page for target_id — the pixel-perfect custom-coded page mode). ALWAYS fill name, tags, purpose and impact: the site owner reads them on the Keelhob > Snippets admin page and that is their only way to judge what you installed. Updates MERGE — send only the fields you are changing and everything else, including code, is preserved. PHP is parse-checked first; code that does not parse is still saved but forced inactive with the error attached. A PHP snippet that fatals at runtime is auto-deactivated so the site stays up. Set active=true to turn it on. WARNING — the auto-deactivate guard only catches FATAL ERRORS. A snippet that runs perfectly can still take the site down, and the two ways that happens are: (1) sending a 4xx/5xx status from the front end — hosts poll the home page for liveness and read a 503 there as "server dead", then stop routing to the site entirely, including wp-admin and this MCP endpoint, so you lose the ability to undo it; serve coming-soon and maintenance pages with status 200 plus a noindex meta tag instead. (2) gating the front end without letting wp-login.php, /wp-admin, /wp-json, wp-cron.php and xmlrpc.php through, which locks the owner out of their own site. After activating anything that changes what a logged-out visitor sees, fetch the home page with no cookies and confirm it returns 200 before reporting done. If a snippet does break the site, the owner recovers by adding define('KEELHOB_SNIPPETS_OFF', true); to wp-config.php, which disables every snippet without needing a working site or a database client.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "snippet_save"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | Omit to create; include to update. | |
| uid | No | Portable identity. Omit on new snippets — one is generated. | |
| code | Yes | The snippet code. For php, do NOT include <?php tags (except page_template, where inline HTML with <?php islands is allowed). | |
| name | No | ||
| tags | No | Short lowercase labels the owner filters by, e.g. ["seo","header"]. Max 10. | |
| active | No | ||
| impact | No | What it changes on the site, and what breaks if it is switched off. | |
| purpose | No | Why this snippet exists, in plain English for the site owner. | |
| location | No | css, js and html only run from header, footer, before_content, after_content or shortcode — everywhere/admin_only/frontend_only/page_template only execute php, so a css/js/html snippet saved there is refused. | everywhere |
| priority | No | ||
| target_id | No | For page_template: the page/post ID this template serves. | |
| conditions | No | Optional load rules. {enabled:true, relation:"AND"|"OR", rules:[{type,operator,value}]}. type is one of user_status, user_role, page_type, post_type, post_id, url_path, device. operator is "is"/"is_not" (or "contains"/"equals"/"starts_with" for url_path). value may be an array, meaning "any of these". Example: {"enabled":true,"relation":"AND","rules":[{"type":"user_status","operator":"is","value":"logged_out"},{"type":"page_type","operator":"is","value":"front_page"}]}. The older flat shape {logged_in, front_page, post_types, post_ids} is still accepted and is converted on read, so existing snippets keep working. | |
| origin_uid | No | When copying from another site: the source snippet's uid. Re-copying with the same origin_uid UPDATES the existing copy instead of duplicating it — which also overwrites any edit the owner made here. | |
| description | No | ||
| origin_site | No | When copying from another site: that site's label. | |
| snippet_type | No | php |