//

Eitan Adler

Almost every WordPress site ends up with custom code. A filter that changes a Gravity Forms notification, a few lines of CSS that fix a theme quirk, a tracking script in the footer. Snippet plugins exist so that code doesn’t end up in functions.php, where a theme update can wipe it out.

Running a snippet is the easy part. The hard part comes later: you have thirty snippets and can’t remember which one does what, you reuse one on another site and have to re-edit its form IDs, someone changes a snippet and nobody notices, or you delete one and it leaves options and scheduled tasks behind.

GravityOps Code Snippet Manager (GOCSM) handles every kind of snippet in one place: PHP, JavaScript, CSS, and HTML for the head, body or footer, or placed with a shortcode or block. Where it stands out is in two areas: managing snippets over their whole life, and letting you manage them through an AI assistant.

Built to manage snippets, not just run them

Configure: one codebase, different settings on every site

Most snippets have a few values that differ from site to site: a form ID, a field ID, an email address, a message. Normally those live inside the code, so reusing a snippet means editing the code, and updating it means editing it again.

GOCSM separates them. A snippet declares its settings in a config block:

// === BEGIN CONFIG ===
/** @config int The Gravity Forms form ID to listen on */
$form_id = 5;

/** @config email Address to receive notification emails */
const NOTIFY_EMAIL = 'admin@example.com';
// === END CONFIG ===

GOCSM turns that block into a settings panel on the snippet’s edit screen. Each site stores its own values, separately from the code. When the code is updated, the values stay.

Values that hold secrets, such as an API key, can be marked private, either in the panel or with an @private tag in the config block. Private values are never returned to the API or to AI assistants.

Maintain: treat snippets as a library, not as loose code

If you use the same snippets on several sites, you can keep them in a GitHub repository, public or private, and add that repository to each site as a collection.

  • You choose what to install. A collection lists its snippets, and each site installs only the ones it needs. If a site already has a snippet with the same code, GOCSM takes it over instead of installing a duplicate.
  • Updates come to you for review. When the repository changes, the site shows what changed in the code and in the config before anything is applied. You can let updates without warnings apply automatically.
  • Your settings survive. Updates replace the code and keep each site’s config values.
  • You can see what happened. Every sync produces a summary of what changed and whether it was applied, and the Sync Log keeps the full history.

A collection doesn’t have to be yours. You can add any repository you trust and get its updates the same way, reviewed before they apply. Our own Gravity Forms snippet library works as a collection; you can browse it in our snippet directory first.

Every snippet, whether from a collection or written on the site, also keeps a revision history. You can compare any earlier version with the current one and restore it, config values included.

Oversee: know when something changes

Snippets run code on your site, so changes to them matter. GOCSM can send a signed webhook whenever a snippet is created, its code changes, or its cleanup runs. You can leave out your own changes, and you can have the webhook include the snippet’s code and a diff of what changed. On multisite, one setting covers every site on the network.

A webhook can go anywhere, so you can build whatever review process fits your team. Here is the one we use:

  1. A snippet is changed on one of our sites, and GOCSM sends the webhook.
  2. A small receiver (itself a GOCSM snippet) turns it into a Gravity Forms entry.
  3. Gravity Flow routes the entry for review, and our Asana add-on for Gravity Forms opens an Asana task with the diff attached.
  4. When the reviewer marks the entry approved, the Asana task closes.

If the same snippet changes again before review, the change is added to the open review instead of starting a new one.

Errors are covered too. When a snippet causes an error, GOCSM switches it off and sends an alert: an email to the site admin by default, other recipients or a signed webhook if you add them. An admin notice stays up until the snippet is fixed.

Organize: find any snippet quickly

  • Folders, also reachable from a dashboard widget and the admin toolbar. Snippets from a collection go into the collection’s folder.
  • Tags for anything that cuts across folders.
  • Visible IDs. Every snippet shows its ID, and search accepts an ID, #ID, or a list of IDs.

Retire cleanly: nothing left behind

Snippets often create things: an option in the database, a scheduled task, sometimes a table. Deleting the snippet usually leaves all of that behind.

In GOCSM, a snippet can declare its cleanup: the options and scheduled tasks to remove, plus PHP that runs when it is deactivated or deleted. Before you confirm, GOCSM shows you exactly what will be removed. Snippets meant to run once can delete themselves when they finish.

Running safely

On every save, GOCSM checks the syntax and scans for risky code and hard-coded credentials. A snippet that causes an error is switched off automatically, and if a snippet ever breaks your admin, safe mode stops PHP snippets from running for your login so you can get back in and fix it. PHP snippets also show how long they take to load.

Run it all from your AI assistant

On WordPress 6.9 and later, GOCSM registers its operations with WordPress’s Abilities API. Through that API, an AI assistant connected to your site can do almost everything the admin screens do:

  • list, read, create, edit, activate and deactivate snippets
  • add GitHub collections, sync them, install or remove their snippets, and review and apply pending updates
  • manage folders and tags, compare and restore revisions
  • read and change settings, read the Sync Log, import and export
  • report the site’s status: which snippets are in error and which updates are waiting

Because this is WordPress’s own API, you are not tied to one assistant. Any assistant that supports MCP can connect, and scripts can use the same operations over REST. Every call requires the same permission as the Code Snippet Manager screens.

In practice, that means you can ask things like:

  • “Which snippets are erroring, and why?”
  • “Move every checkout snippet into a Checkout folder.”
  • “Show me what the pending update to snippet #42 changes, then apply it.”
  • “Set the form ID on the donation receipt snippet to 7.”

Safe to hand to an AI

Letting an AI assistant manage code on your site is only reasonable if there are limits. GOCSM has them built in:

  • Writing new code is off by default. Over the API, creating a snippet or changing its code is refused unless you add a constant to wp-config.php. A setting would not be enough, because a tool that can change settings could turn it on. With the constant off, neither an assistant nor a stolen application password can put new PHP on your site, and everything else still works.
  • Config values stay hidden unless asked for, and private values never leave the site.
  • No silent overwrites. An assistant can pass the version it read, and if the snippet changed since then, the change is refused.
  • Deleting a collection, or removing its snippets, needs explicit confirmation.
  • Code from a GitHub collection can’t be edited over the API. It changes only through the repository.
  • An update is applied only if it is still exactly what was reviewed.

We manage the snippets on our own sites this way, every day.

To connect your assistant, see Connecting an AI assistant to your site.

Try it

Snippets are easy to add and hard to keep track of. GOCSM is built for the part that comes after: settings that survive updates, a library you can review, changes you hear about, and cleanup that actually cleans up, all of which you can also manage by asking your AI assistant.

Get GravityOps Code Snippet Manager

Discuss this post

Questions, corrections or your own approach? Reply in the community thread.

Leave a Comment