AI Snippets Engine

Creating, validating and safely running AI-generated PHP, JavaScript, CSS and HTML snippets in WordPress with Aimogen Pro, including the safety model and kill switch.

The AI Snippets Engine lets you describe a small piece of functionality in words and have the AI write, validate and store the code — with conditions deciding where it runs and several layers of protection against it breaking your site.

Added in 2.7.1. Advanced Tools › AI Snippets

Stop Editing functions.php - Build Smart WordPress Features with Aimogen Pro AI SnippetsCreating and managing snippets.Watch on YouTube

Snippet types#

TypeHow it runs
PHPExecuted on template_redirect, front end only, inside a sandboxed closure with runtime fatal-error detection
JavaScriptInjected inline in the footer via wp_add_inline_script()
CSSInjected inline via wp_add_inline_style()
HTMLStatic markup, sanitised on output

AI mode and manual mode#

AI mode. You describe what you want; the selected model or assistant writes it. Output is normalised, validated and stored inactive by default — you review before enabling.

Manual mode. You paste code directly. The same validation and safety checks apply.

Conditions#

Conditions decide where a snippet runs. Rules are grouped: groups combine with OR, rules within a group combine with AND.

Available subjects:

SubjectValues
Site AreaGlobal, Frontend, Admin
Current QueryHome, Front Page, Single, Page, Archive, Search, 404, Post Type Archive
Visitor LanguageLocale
Current ThemeActive theme
Active PluginA plugin being active
Debug EnabledWP_DEBUG state
Post, Page, Post Type, Tag, Category, Author, Post StatusSpecific content targeting
Post ParentHierarchical targeting
Post Published Date, Post Modified DateDate comparisons

Conditions can also be generated by AI from a description, using the condition generator on the snippet screen.

Aimogen Pro > Advanced Tools > AI Snippets

The safety model#

This is the part worth reading before you use the feature.

ProtectionWhat it does
Front-end restrictionSnippets without conditions never run in wp-admin
Token-based PHP validationThe code is parsed and unsafe function calls are blocked before storage
$wpdb blockedDirect database access is not permitted
Dangerous functions blockedeval, exec, system and similar are rejected
Strict activation checkPHP snippets are validated again before being enabled
Runtime fatal-error detectionA shutdown handler catches fatal errors
Automatic deactivationA snippet that causes a fatal error is deactivated automatically
Error storageThe error message is stored against the snippet
LoggingThe issue is logged when logging is enabled
HTML sanitisationHTML output is sanitised

The automatic-deactivation behaviour is what makes this usable: a snippet that would white-screen your site takes itself out of service and records why.

The kill switch#

If something does go wrong and you cannot reach wp-admin:

php
// wp-config.php
define( 'AIMOGEN_DISABLE_SNIPPETS', true );

This prevents PHP execution and front-end injection without deleting anything. Remove the constant to re-enable.

There is also an official emergency plugin, aimogen-emergency-disable-snippets, which you can drop in over FTP if editing wp-config.php is not convenient.

Caching#

Active snippets are cached per blog ID for 60 seconds in the WordPress object cache, in the aimogen cache group. The cache is flushed automatically when snippets are created, updated, deleted or toggled.

Storage#

Snippets live in the {prefix}aimogen_snippets table:

ColumnHolds
id, title, typeIdentity
codeThe snippet body
conditionsJSON condition rules
ai_model, assistant_idWhat generated it
priorityExecution order
activeEnabled state
has_error, last_errorFailure state
created_atTimestamp

See Data model.

Honest guidance#

This does not make you a developer. AI-generated PHP can be subtly wrong in ways that pass validation: inefficient queries, missing capability checks, incorrect escaping. The validator blocks dangerous functions; it does not review logic.

Read the code before activating it. Every time. The AI-mode default of storing inactive exists for this reason.

Test on staging first, for anything non-trivial.

Prefer a proper plugin for real functionality. Snippets suit small, self-contained tweaks — conditionally hiding an element, adding a body class, injecting a tracking tag. Anything larger belongs in version-controlled code.

Access is administrative. Rendering the snippets screen requires manage_options. Anyone who reaches it can execute PHP on your site.

Common problems#

A snippet was rejected on save. The validator blocked something. The error explains what.

A snippet deactivated itself. It caused a fatal error. last_error holds the message.

A snippet does not run. It is inactive, the conditions do not match, or it has no conditions and you expected it in wp-admin.

Changes do not take effect. The 60-second cache. Toggling the snippet flushes it.

The site is broken and wp-admin is unreachable. Use the kill switch above.

Still stuck? Open a support ticket and include the diagnostics from Aimogen Pro › System & Logs › System Info.