Building blocks
Validation
Per-field validation (user input)
Every control supports a validation block that the meta-box and (in
future) the block Inspector enforce client-side, with a server-side mirror
that forces the post to draft on save if invalid:
{
"type": "text",
"attributeKey": "subtitle",
"label": "Subtitle",
"validation": {
"required": true,
"requiredMessage": "Subtitle is required.",
"minLength": 3,
"maxLength": 80,
"min": 0,
"max": 100,
"pattern": "^[A-Z]",
"patternMessage": "Must start with a capital letter."
}
}requiredcan be a boolean OR{ "message": "..." }.requiredMessageis a top-level shorthand for a custom required text.minLength/maxLengthapply to string values.min/maxapply to numbers (and numeric strings).patternis a bare regex (no delimiters); supplypatternMessageto override the generic "does not match" error.
Hidden by conditional logic = skipped. If a required field is hidden
by its conditionalLogic, it is excluded from validation entirely — it
can't block save because the user can't see it.
Server-side authority. GCBLite\PostFields\Validator mirrors the JS
rules. If a post is saved with invalid required fields, status is forced
to draft and an admin notice lists each error. Add new rules to BOTH
src/validation.js and includes/PostFields/Validator.php — the JS-only
client check is just nice UX.
Config validation (registration-time)
The plugin validates gcb configs at registration. With WP_DEBUG on, invalid blocks emit warnings naming the exact field. The scaffold CLI rejects invalid specs before writing anything.
Before reporting a block as done:
block.jsonparses and hasapiVersion: 3,name: "gcb/{slug}".- Every non-group control in
block.fields.jsonhasattributeKey. EveryparentPanelIdmatches a group'sid. - If using
render.php:php -l render.phppasses, and every attribute referenced has a matching control inblock.fields.json. - If rendering via your Next.js frontend: a route at
/wordpress/render/{slug}on that frontend returns the component wrapped in<wp-block-wrapper data-block-name="{slug}">.
Validator messages
Reference, generated from the plugin source
The messages GCBLite\Validation\BlockGcbValidator gives when a block.fields.json is wrong, read from the code. Each names the path of the control it is about (for example controls[2].attributeKey).
- block.fields.json must be an object.
controlsmust be an array.allowed_blocksmust benullor an array of block names.- Each entry must be a string.
- Control must be an object.
{required}is required and must be a non-empty string.- Duplicate control id
{id}. attributeKeyis required for non-group controls.attributeKeymust start with a letter and contain only letters, digits, and underscores.attributeTypemust be one of:parentPanelIdreferences unknown control{control}. Must match a structural control'sid(group / panel / tools-panel).decimalsbelongs to a number or range control: it is how many decimals the number prints with.decimalsmust be a whole number of zero or more: the count of decimals the field prints with ("5.0" is 1, "4.95" is 2, "14,395" is 0).optionsmust be an array.- Each option must be
{label, value}.
Unknown types are refused, with the nearest real type suggested: "Unknown control type x. Did you mean y? Use a built-in type or register your own with gcblite_register_control_type()."