=== ZeeMee Snippets ===
Contributors: zeemeemedia
Tags: code snippets, php, version control, mcp, ai
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Snippet manager for PHP, JS, CSS and HTML with version history, rollback, safe mode, error isolation and rights-controlled MCP access for AI clients.

== Description ==

ZeeMee Snippets lets you add PHP, JavaScript, CSS and HTML to your site without touching theme files — and without the fear that one typo takes the site down.

**Snippets**

* PHP, JavaScript, CSS and HTML snippets with a code editor (syntax highlighting, line numbers).
* Locations: run PHP everywhere, frontend only, wp-admin only or on a specific hook with your own priority; print JS/CSS/HTML in the head or footer of the frontend, wp-admin or the login page, before/after the post content, or only via the `[zmsn id="123"]` shortcode.
* Conditions: audience (everyone, logged in, logged out, selected roles), page type, post IDs, URL rules and an optional schedule.
* Priority ordering, folders, descriptions, duplicate, search and filters.

**Version history**

* Every save that changes code or settings becomes a version (50 per snippet).
* Compare any version with the current code — or any two versions — side by side.
* Restore with one click; the restore is itself a new version, so it can be undone.
* Activity log of who created, changed, activated, deactivated, restored, duplicated, deleted and imported what.

**Safety net**

* PHP is syntax-checked before it is saved as active.
* Activation is refused when the code declares functions or classes that already exist (for example because the same code still runs in another plugin).
* A fatal error or uncaught exception deactivates the snippet automatically and shows the message and line number — the site recovers on the next request.
* Safe mode: `?zmsn_safe=1` as an administrator (one hour, cookie) or `define( 'ZMSN_SAFE_MODE', true );` in wp-config.php stops every snippet.
* `define( 'ZMSN_LOCK', true );` makes the editor read-only in production.

**MCP access for AI clients**

* Built-in MCP server (Streamable HTTP, JSON-RPC 2.0) so Claude, ChatGPT, Gemini, Copilot, Mistral or your own agents can manage snippets.
* One connection per client, each with its own token and its own rights: view, contribute, edit, delete — switch any client off alone, or everything with the master switch.
* Optional folder sandbox and per-connection rate limit; every change is logged under the connection's name and stored as a version.
* Token works both as `Authorization: Bearer` / `X-API-Key` header and as a per-connection URL for clients without a header field. `search` and `fetch` tools included for ChatGPT.

**Tools**

* Export all or single snippets as JSON (optionally with version history) and import them on another site.

The admin interface is in English and Danish.

== Installation ==

1. Upload the `zeemee-snippets` folder to `/wp-content/plugins/` or install the zip via Plugins → Add New.
2. Activate the plugin.
3. Go to **ZeeMee Plugins → Snippets** and create your first snippet.

Snippets are compiled to files in `wp-content/uploads/zeemee-snippets/` (protected by `.htaccess`), so the uploads folder must be writable.

== Frequently Asked Questions ==

= A snippet broke my site. What now? =

The snippet that caused a fatal error is deactivated automatically; reload the page. If the site is still down, add `?zmsn_safe=1` to any URL while logged in as an administrator, or add `define( 'ZMSN_SAFE_MODE', true );` to wp-config.php. Then fix or deactivate the snippet under ZeeMee Plugins → Snippets.

= Why is activation refused with "these already exist"? =

The code declares a function or class that is already defined — usually because the same code is still active in another plugin or snippet. Deactivate it there first.

= Do page conditions work for PHP snippets? =

Only for PHP that runs on a hook after WordPress has parsed the request (`wp`, `template_redirect` or later) and for shortcodes. PHP that runs at startup (everywhere / frontend / admin) runs before the page is known.

= Where is the code stored? =

In the database (`wp_zmsn_snippets`, with versions in `wp_zmsn_versions` and the log in `wp_zmsn_log`). Compiled copies are written to `uploads/zeemee-snippets` so PHP reports real line numbers and opcache works; they are rebuilt from the database if they go missing.

= Does the plugin phone home? =

No. There are no external requests. Fonts for the admin interface are bundled. The MCP endpoint only answers requests that AI clients send to your site; the plugin never calls any AI service.

= Is the MCP endpoint safe? =

It is off until you create the first connection, and every request needs a connection token (48 random characters, stored hashed). Each connection has only the rights you tick, can be limited to one folder and a number of requests per minute, and can be switched off or given a new token at any time. New snippets created by a client are always inactive, PHP is syntax- and conflict-checked before activation, and a crashing snippet is deactivated automatically. `ZMSN_LOCK` blocks all changes through MCP too.

== Screenshots ==

1. Snippet overview with status panel and filters.
2. Editor with code, location, audience and page conditions.
3. Version comparison and restore.
4. Tools: import, export, safe mode.

== Changelog ==

= 1.1.0 =
* New: MCP access tab — create connections for AI clients with separate view / contribute / edit / delete rights, folder sandbox, rate limit, master switch, token rotation.
* New: MCP server at `/wp-json/zmsn/v1/mcp` (Streamable HTTP) with tools for listing, reading, creating, updating, activating, restoring and deleting snippets, plus ChatGPT-compatible `search`/`fetch`.
* New: versions and activity log record which connection made a change.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.1.0 =
Adds rights-controlled MCP access for AI clients. The database is upgraded automatically.
