Guide

Field Schema

This schema is provided by AbilityFieldAdapterTrait and is shared by all field-bearing abilities: save-post-meta-fields, save-term-meta-fields, save-user-meta-fields, and save-options-page-fields.

Schema

{
  "type": "object",
  "required": ["fieldType", "name", "fieldLabel"],
  "properties": {
    "fieldType":         { "type": "string" },
    "name":              { "type": "string" },
    "fieldLabel":        { "type": "string" },
    "default":           { "type": "string" },
    "required":          { "type": "boolean", "default": false },
    "disabled":          { "type": "boolean", "default": false },
    "field_custom_info": { "type": "object" }
  }
}

Properties

PropertyRequiredTypeDescription
fieldTypeYesstringField type. See supported values below.
nameYesstringUnique meta key slug (sanitize_key is applied)
fieldLabelYesstringLabel shown in the admin interface
defaultNostringDefault field value
requiredNobooleanMakes the field mandatory (default: false)
disabledNobooleanDisables the field (default: false)
field_custom_infoNoobjectType-specific options (see below)

Supported Field Types (fieldType)

TypeDescription
textSingle-line text input
textareaMulti-line text input
inputHTML input (type can be specified)
numberNumeric input
rangeRange slider
selectDropdown list
radioRadio buttons
checkboxCheckbox
toggleOn/off toggle switch
toggle_groupGroup of toggle buttons
comboboxSearchable select box
token_fieldTag/token input
date_pickerDate picker
date_time_pickerDate and time picker
time_pickerTime picker
file_uploadFile upload
media_libraryWordPress media library picker
color_pickerColor picker
color_paletteColor palette picker
font_sizeFont size input
unitUnit input
repeaterRepeatable field group*
groupField group*
sectionSection heading

* Nested fields inside repeater and group cannot be defined via ability.

field_custom_info Options

select, radio, combobox, token_field, toggle_group

{
  "options": "Label:value, Label2:value2",
  "multiple": false
}

input

{
  "type": "text|email|url|number|date|datetime-local|password",
  "placeholder": "...",
  "min": 0,
  "max": 100,
  "step": 1
}

textarea

{
  "placeholder": "...",
  "rows": 4
}

text

{
  "placeholder": "..."
}

number, range

{
  "min": 0,
  "max": 100,
  "step": 1
}

Example Field Definition

{
  "fieldType": "select",
  "name": "color_choice",
  "fieldLabel": "Color Choice",
  "default": "blue",
  "required": true,
  "field_custom_info": {
    "options": "Red:red, Blue:blue, Green:green"
  }
}

Was this helpful?