Skip to content

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.

  1. The agent calls list-control-types to learn the spec shape and supported controls.
  2. It builds a spec: sections of controls (text, color, select, dimensions, typography group, repeater, …) plus an html_template that references those controls.
  3. validate-widget-spec dry-runs the generator and returns any errors without persisting.
  4. create-custom-widget generates the Widget_Base PHP, writes it to the sandbox, and auto-activates it. The widget shows up under a “Custom (EMCP)” category in the Elementor panel.
  5. 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.

  • 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.

ToolPurpose
emcp-tools/list-control-typesList supported control types + the spec shape
emcp-tools/validate-widget-specSchema + generator dry-run; returns errors, persists nothing
emcp-tools/create-custom-widgetGenerate + register a widget from a spec (auto-activates)
emcp-tools/update-custom-widgetReplace a widget’s spec, regenerate, re-validate
emcp-tools/get-custom-widgetReturn a widget’s spec + generated PHP + status
emcp-tools/list-custom-widgetsList generated widgets (id, title, name, status)
emcp-tools/set-widget-statusActivate or deactivate a widget
emcp-tools/delete-custom-widgetDelete a widget (CPT record + sandbox files)

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.