'text', 'name' => 'placeholder', 'label' => 'Placeholder'], * ['type' => 'number', 'name' => 'min', 'label' => 'Minimum Value'], * ] * Any key is passed to the browser. The inspector reads these besides * type, name, label and help: * - default: shown as the value while the setting has never been saved * (only an undefined value counts as never saved). It is display only * and is not written into the field until the user changes the control. * A toggle with 'default' => true shows on until it is saved off. * - placeholder: hint text of a text, textarea or number control. * - disabled: true draws the control unusable, for a setting that cannot * be used yet. The help text stays available to explain why. */ public $inspectorControls; /** * Capability keys an add-on attaches to its own field type. Kept for the * add-on to read; this plugin does not read them. * * @var array */ public $requiredCapabilities; /** * @var array Field meta information, routing and categorisation * ['category' => 'regular|composite|layout|system'] */ public $meta; /** * @var array Inspector controls for layout/container fields. * Uses the same control schema as inspectorControls. * Rendered instead of inspectorControls when meta.category === 'layout'. */ public $layoutControls; /** * @var bool Whether this field is hidden from the builder field palette. * Set to true for internal/system-only fields that should not be user-addable. */ public $paletteHidden; /** * @param string $type Unique field type identifier * @param string $label Human-readable label * @param string $category Field category (basic, choices, media, advanced) * @param string $icon Icon slug or dashicon key * @param string $kind Field kind (input, structure, system, dynamic) * @param bool $acceptsChildren Whether this field can accept children * @param array $baseAttributes Common attributes for all fields * @param array $fieldSpecificAttributes Field-type specific config * @param array $inspectorControls Inspector UI controls configuration * @param array $requiredCapabilities Capability keys for the add-on's own use (not read here) * @param array $meta Field meta (category: regular|composite|layout|system) * @param array $layoutControls Inspector controls for layout/container fields * @param bool $paletteHidden Whether to hide this field from the builder palette */ public function __construct( $type, $label, $category, $icon, $kind = 'input', $acceptsChildren = false, $baseAttributes = array(), $fieldSpecificAttributes = array(), $inspectorControls = array(), $requiredCapabilities = array(), $meta = array(), $layoutControls = array(), $paletteHidden = false ) { $this->type = $type; $this->label = $label; $this->category = $category; $this->icon = $icon; $this->kind = $kind; $this->acceptsChildren = $acceptsChildren; // Merge with default base attributes $this->baseAttributes = array_merge( array( 'id' => null, // Generated at runtime 'key' => null, // Generated at runtime 'type' => $type, 'label' => '', 'required' => false, 'defaultValue' => null, 'visibility' => null, 'validation' => array(), ), $baseAttributes ); $this->fieldSpecificAttributes = $fieldSpecificAttributes; $this->inspectorControls = $inspectorControls; $this->requiredCapabilities = $requiredCapabilities; $this->meta = array_merge( array( 'category' => 'regular' ), $meta ); $this->layoutControls = $layoutControls; $this->paletteHidden = $paletteHidden; } /** * Convert to array representation. * * @return array */ public function toArray(): array { return array( 'type' => $this->type, 'label' => $this->label, 'category' => $this->category, 'icon' => $this->icon, 'kind' => $this->kind, 'acceptsChildren' => $this->acceptsChildren, 'baseAttributes' => $this->baseAttributes, 'fieldSpecificAttributes' => $this->fieldSpecificAttributes, 'inspectorControls' => $this->inspectorControls, 'meta' => $this->meta, 'layoutControls' => $this->layoutControls, 'paletteHidden' => $this->paletteHidden, ); } /** * Get default configuration for field instance creation. * Merges base attributes with field-specific defaults. * * @return array */ public function getDefaultConfig(): array { return array_merge( $this->baseAttributes, $this->fieldSpecificAttributes ); } }