Widget Builder
The Widget Builder lets an AI agent design a custom Elementor widget (a pricing card, a stat counter, a testimonial block) from a structured spec. The plugin compiles that spec into a real Elementor widget that appears in the editor panel, ready to drop onto any page.
Crucially, the AI never writes PHP. It submits a JSON spec plus an HTML template with {{control}} placeholders. A plugin-owned generator compiles that into a Widget_Base class, escaping every value by its declared control type. The generated code lives in an isolated sandbox under wp-content/uploads/emcp-widgets/. It never touches WordPress core, your theme, or any other plugin.
How it works
Section titled “How it works”- The agent calls
list-control-typesto learn the spec shape and supported controls. - It builds a spec: sections of controls (text, color, select, dimensions, typography group, repeater, …) plus an
html_templatethat references those controls. validate-widget-specdry-runs the generator and returns any errors without persisting.create-custom-widgetgenerates theWidget_BasePHP, writes it to the sandbox, and auto-activates it. The widget shows up under a “Custom (EMCP)” category in the Elementor panel.- The agent (or you) places it on a page like any other widget.
A runtime safety net validates each widget on create/update and isolates compile failures, so a malformed widget is demoted to draft with a recorded error rather than breaking the editor.
Spec essentials
Section titled “Spec essentials”- 35 control types, including group controls (typography, border, box-shadow, background), repeaters, responsive controls, and conditional visibility.
- Template syntax:
{{control_name}}for values,{{#if control}}…{{/if}}for conditionals,{{#each repeater}}…{{/each}}for loops. Every value is escaped by its control type. - Optional per-widget CSS/JS: registered and enqueued only when the widget renders on a page.
Connected agents that load the bundled widget-builder Agent Skill already know the full spec format and control catalog.
| Tool | Purpose |
|---|---|
emcp-tools/list-control-types | List supported control types + the spec shape |
emcp-tools/validate-widget-spec | Schema + generator dry-run; returns errors, persists nothing |
emcp-tools/create-custom-widget | Generate + register a widget from a spec (auto-activates) |
emcp-tools/update-custom-widget | Replace a widget’s spec, regenerate, re-validate |
emcp-tools/get-custom-widget | Return a widget’s spec + generated PHP + status |
emcp-tools/list-custom-widgets | List generated widgets (id, title, name, status) |
emcp-tools/set-widget-status | Activate or deactivate a widget |
emcp-tools/delete-custom-widget | Delete a widget (CPT record + sandbox files) |
Permissions
Section titled “Permissions”Creating, updating, activating, and deleting widgets require manage_options plus unfiltered_html, the same bar as site-wide custom code. Read tools (get-, list-, list-control-types, validate-) require edit_posts.