A schema widgetβs entire UI comes from its fields array. This guide covers picking controls, grouping them, conditional visibility, and the two repeater shapes.
Choosing a control#
| Need | Control | Stored value |
|---|---|---|
| Short text | text | string |
| Long text or a newline-separated list | textarea | string |
| A number | number | numeric string |
| A bounded number the user should feel | slider | numeric string |
| On / off | toggle | boolean |
| One of several | select | option key |
| One of a few, shown as pills | buttongroup | option key β identical storage to select |
| A colour | color | colour string |
| A link | url | URL string |
| An image from the media library | image | attachment URL |
| Any icon | icon | IconValue object |
| Several from a visual grid | multiicon | comma-separated keys |
| Four-sided spacing or radius | dimensions4 | CSS shorthand string |
| An ordered list of known options | repeater | comma-separated keys (+ optional colour map) |
| An ordered list of objects | itemsRepeater | JSON string |
Notice that every control stores a string (or a boolean, or one object for icon). That is deliberate: PHP never has to learn a new data type when a richer control is added.
Grouping and tabs#
{ key: 'iconSize', label: 'Size', control: 'slider',
min: 6, max: 120, step: 1, unit: 'px', placeholder: '18',
group: 'Icon', tab: 'style' }groupputs the field inside a named PropGroup accordion. Fields sharing a group name are collected together in declaration order.tab: 'style'moves the field out of the Content tab and intoGenericStyleExtrasat the top of the Style tab. Default is'content'.
Use this to keep the Content tab about what the widget says and the Style tab about how it looks β the same split users already expect from the bespoke widgets.
Conditional visibility#
{ key: 'iconColorMode', label: 'Color', control: 'select',
options: [{ value: 'official', label: 'Official Color' }, { value: 'custom', label: 'Custom' }] },
{ key: 'iconColor', label: 'Custom Color', control: 'color',
showIf: { key: 'iconColorMode', equals: 'custom' } },showIf takes { key, equals? | notEquals? | truthy? }. It only hides the control β the value stays in content if it was set before, so toggling back restores it.
The two repeaters#
repeater β an ordered list of known option keys, stored as a comma string. An optional colorKey names a companion content key holding a key:color,key:color map, so per-item colours can be added without changing the primary fieldβs shape. Absent entries fall back to the optionβs own colour, which is why existing content keeps rendering identically.
itemsRepeater β an ordered list of objects, each with its own sub-fields. Stored as a JSON string in the fieldβs key, so the sanitizerβs default text path leaves it intact and a dedicated renderer decodes it.
{
key: 'items', label: 'Social Icons', control: 'itemsRepeater',
addLabel: 'Add Item', itemTitleKey: 'link', addWithIconPicker: true,
itemFields: [
{ key: 'icon', label: 'Icon', control: 'icon' },
{ key: 'link', label: 'Link', control: 'url', placeholder: 'Type or paste your URL' },
{ key: 'color', label: 'Color', control: 'color' },
],
}addWithIconPicker: true makes β+ Add Itemβ open the icon library first and store the result in the new itemβs icon sub-field. It requires an icon sub-field to exist.
The PHP side of a control#
Each control type maps to an escaper in sanitize_generic_content(). The field-type strings you write in widgets-schema.php are what select it:
| Schema field type | Escaping |
|---|---|
text | sanitize_text_field() |
textarea | sanitize_textarea_field() |
number | Numeric coercion |
toggle | Boolean cast |
select | Text field β the renderer re-validates against its own allow-list |
color | Jalpi_Sanitizer::sanitize_color() |
url | Jalpi_Sanitizer::sanitize_url() |
icon | Jalpi_Sanitizer::sanitize_icon_value() |
social-items | JSON list of {icon, link, color}, each member validated |
Because select is stored as free text and re-validated at render time, the render branch must always call enum() (or an equivalent) rather than trusting the stored value directly.
Source
Files
admin/editor/src/widgets/registry.ts includes/widgets-schema.php includes/class-jalpi-sanitizer.php admin/editor/src/widgets/GenericContent.tsx includes/elements/class-jalpi-element-generic.php
Classes
Jalpi_Sanitizer Jalpi_Element_Generic
Functions
sanitize_generic_content render_template enum
Last updated: November 2026