register( new FieldDefinition( type: 'text', label: __( 'Text', 'subtleforms' ), category: 'basic', icon: 'dashicons-text', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', 'maxLength' => null, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'maxLength', 'label' => __( 'Max Length', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // Email Field - with RFC validation toggle $registry->register( new FieldDefinition( type: 'email', label: __( 'Email', 'subtleforms' ), category: 'basic', icon: 'dashicons-email', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', 'rfcValidation' => true, 'allowMultiple' => false, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'checkbox', 'name' => 'rfcValidation', 'label' => __( 'RFC Validation', 'subtleforms' ), 'help' => __( 'Use strict RFC 5322 email validation', 'subtleforms' ), ), array( 'type' => 'checkbox', 'name' => 'allowMultiple', 'label' => __( 'Allow Multiple', 'subtleforms' ), 'help' => __( 'Allow comma-separated email addresses', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // Textarea Field - with rows and maxLength $registry->register( new FieldDefinition( type: 'textarea', label: __( 'Textarea', 'subtleforms' ), category: 'basic', icon: 'dashicons-text-page', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', 'rows' => 4, 'maxLength' => null, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'rows', 'label' => __( 'Rows', 'subtleforms' ), 'min' => 2, 'max' => 20, ), array( 'type' => 'number', 'name' => 'maxLength', 'label' => __( 'Max Length', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // Number Field - with min/max/step $registry->register( new FieldDefinition( type: 'number', label: __( 'Number', 'subtleforms' ), category: 'basic', icon: 'dashicons-calculator', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', 'min' => null, 'max' => null, 'step' => 1, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'min', 'label' => __( 'Minimum Value', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'max', 'label' => __( 'Maximum Value', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'step', 'label' => __( 'Step size', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // Phone Field $registry->register( new FieldDefinition( type: 'phone', label: __( 'Phone', 'subtleforms' ), category: 'basic', icon: 'dashicons-phone', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', 'format' => 'international', 'enableCountryCode' => false, 'defaultCountry' => 'US', 'showFlags' => false, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'checkbox', 'name' => 'enableCountryCode', 'label' => __( 'Country code', 'subtleforms' ), 'help' => __( 'Add a searchable country list with dial codes in front of the number.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'text', 'name' => 'defaultCountry', 'label' => __( 'Default country', 'subtleforms' ), 'placeholder' => 'US', 'help' => __( 'Two-letter country code used when the country picker is on, for example US, GB or PK.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'checkbox', 'name' => 'showFlags', 'label' => __( 'Show country flags', 'subtleforms' ), 'help' => __( 'Shows a small flag next to the country code. Loads a flag image only for forms that use it.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'select', 'name' => 'format', 'label' => __( 'Format', 'subtleforms' ), 'options' => array( array( 'value' => 'international', 'label' => __( 'International', 'subtleforms' ), ), array( 'value' => 'us', 'label' => __( 'US', 'subtleforms' ), ), array( 'value' => 'custom', 'label' => __( 'Custom', 'subtleforms' ), ), ), ), ), meta: array( 'category' => 'regular' ), ) ); // URL Field $registry->register( new FieldDefinition( type: 'url', label: __( 'URL', 'subtleforms' ), category: 'basic', icon: 'dashicons-admin-links', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // Password Field - with strength meter and confirmation $registry->register( new FieldDefinition( type: 'password', label: __( 'Password', 'subtleforms' ), category: 'basic', icon: 'dashicons-lock', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', 'minLength' => 8, 'strengthMeter' => true, 'requireConfirmation' => false, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'minLength', 'label' => __( 'Minimum Length', 'subtleforms' ), ), array( 'type' => 'checkbox', 'name' => 'strengthMeter', 'label' => __( 'Show Strength Meter', 'subtleforms' ), ), array( 'type' => 'checkbox', 'name' => 'requireConfirmation', 'label' => __( 'Require Confirmation', 'subtleforms' ), ), array( 'type' => 'checkbox', 'name' => 'storeHash', 'label' => __( 'Store a hash', 'subtleforms' ), 'help' => __( 'Passwords are never stored as typed. By default the entry only records that a password was provided. Turn this on to keep a one-way hash instead. Passwords are never included in emails or exports.', 'subtleforms' ), 'section' => 'advanced', ), ), meta: array( 'category' => 'regular' ), ) ); // ===== Choice Fields ===== $registry->register( new FieldDefinition( type: 'checkbox', label: __( 'Checkbox', 'subtleforms' ), category: 'choices', icon: 'dashicons-yes', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( // A checkbox is a single consent-style checkbox (NOT a // multi-option list, that is `multiple_choice`). The label // next to the box is the consent statement, so canvas, preview, // settings and frontend all read the same `checkboxLabel`. 'checkboxLabel' => __( 'I agree', 'subtleforms' ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'checkboxLabel', 'label' => __( 'Checkbox label', 'subtleforms' ), 'help' => __( 'Text shown next to the checkbox.', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // Consent / GDPR field, a single checkbox with a rich label that can // link to the Privacy Policy, required by default, and recorded as a // consent + timestamp on submission. Distinct from `checkbox` so legal // consent is explicit and auditable. $registry->register( new FieldDefinition( type: 'consent', label: __( 'Consent', 'subtleforms' ), category: 'choices', icon: 'dashicons-privacy', kind: 'input', baseAttributes: array( 'required' => true, ), fieldSpecificAttributes: array( 'checkboxLabel' => __( 'I agree to the Privacy Policy.', 'subtleforms' ), 'privacyPolicyUrl' => self::default_privacy_policy_url(), 'linkText' => __( 'Privacy Policy', 'subtleforms' ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'textarea', 'name' => 'checkboxLabel', 'label' => __( 'Consent statement', 'subtleforms' ), 'help' => __( 'Text shown next to the checkbox. Add the link placeholder below to insert a Privacy Policy link.', 'subtleforms' ), 'rows' => 2, ), array( 'type' => 'text', 'name' => 'privacyPolicyUrl', 'label' => __( 'Privacy Policy URL', 'subtleforms' ), 'help' => __( 'Link target for the consent statement. Defaults to the site Privacy Policy page.', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'linkText', 'label' => __( 'Link text', 'subtleforms' ), 'help' => __( 'Text of the Privacy Policy link inside the consent statement.', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'radio', label: __( 'Radio', 'subtleforms' ), category: 'choices', icon: 'dashicons-marker', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'options' => array( array( 'label' => __( 'First choice', 'subtleforms' ), 'value' => 'first', ), array( 'label' => __( 'Second choice', 'subtleforms' ), 'value' => 'second', ), array( 'label' => __( 'Third choice', 'subtleforms' ), 'value' => 'third', ), ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'multiple_choice', label: __( 'Multiple Choice', 'subtleforms' ), category: 'choices', icon: 'dashicons-list-view', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'options' => array( array( 'label' => __( 'First choice', 'subtleforms' ), 'value' => 'first', ), array( 'label' => __( 'Second choice', 'subtleforms' ), 'value' => 'second', ), array( 'label' => __( 'Third choice', 'subtleforms' ), 'value' => 'third', ), ), 'allowMultiple' => true, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'checkbox', 'name' => 'allowMultiple', 'label' => __( 'Allow Multiple', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'dropdown', label: __( 'Dropdown', 'subtleforms' ), category: 'choices', icon: 'dashicons-arrow-down-alt2', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => 'Select an option', 'options' => array( array( 'label' => __( 'First choice', 'subtleforms' ), 'value' => 'first', ), array( 'label' => __( 'Second choice', 'subtleforms' ), 'value' => 'second', ), array( 'label' => __( 'Third choice', 'subtleforms' ), 'value' => 'third', ), ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // 'select' is the canonical type used by templates (alias of dropdown). // Registers inspector controls so the panel shows label/placeholder settings. $registry->register( new FieldDefinition( type: 'select', label: __( 'Select', 'subtleforms' ), category: 'choices', icon: 'dashicons-arrow-down-alt2', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => 'Select an option', 'options' => array( array( 'label' => __( 'First choice', 'subtleforms' ), 'value' => 'first', ), array( 'label' => __( 'Second choice', 'subtleforms' ), 'value' => 'second', ), array( 'label' => __( 'Third choice', 'subtleforms' ), 'value' => 'third', ), ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // 'tel' is the HTML5 input type name for phone fields, used by templates. // Registers inspector controls identical to 'phone'. $registry->register( new FieldDefinition( type: 'tel', label: __( 'Phone', 'subtleforms' ), category: 'basic', icon: 'dashicons-phone', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => '', 'format' => 'international', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'select', 'name' => 'format', 'label' => __( 'Format', 'subtleforms' ), 'options' => array( array( 'value' => 'international', 'label' => __( 'International', 'subtleforms' ), ), array( 'value' => 'us', 'label' => __( 'US', 'subtleforms' ), ), array( 'value' => 'custom', 'label' => __( 'Custom', 'subtleforms' ), ), ), ), ), meta: array( 'category' => 'regular' ), ) ); // Country Field - with full ISO-3166 country list $registry->register( new FieldDefinition( type: 'country', label: __( 'Country', 'subtleforms' ), category: 'choices', icon: 'dashicons-admin-site', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'placeholder' => 'Select a country', 'default_country' => '', 'preferred_countries' => array(), // ISO codes for countries to show at top 'searchable' => true, 'output_format' => 'code', // 'code' or 'name' 'showFlags' => false, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), ), array( 'type' => 'select', 'name' => 'default_country', 'label' => __( 'Default country', 'subtleforms' ), 'section' => 'appearance', 'options' => self::countryControlOptions(), ), array( 'type' => 'lines', 'name' => 'preferred_countries', 'label' => __( 'Preferred countries', 'subtleforms' ), 'help' => __( 'ISO codes shown first, one per line. Example: US', 'subtleforms' ), 'section' => 'appearance', ), array( 'type' => 'checkbox', 'name' => 'showFlags', 'label' => __( 'Show country flags', 'subtleforms' ), 'help' => __( 'Shows a small flag next to the country code. Loads a flag image only for forms that use it.', 'subtleforms' ), 'section' => 'appearance', ), array( 'type' => 'select', 'name' => 'output_format', 'label' => __( 'Output Format', 'subtleforms' ), 'options' => array( array( 'value' => 'code', 'label' => __( 'ISO Code (US, GB)', 'subtleforms' ) ), array( 'value' => 'name', 'label' => __( 'Country Name', 'subtleforms' ) ), ), ), array( 'type' => 'checkbox', 'name' => 'searchable', 'label' => __( 'Enable Search', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'chained_select', label: __( 'Chained Select', 'subtleforms' ), category: 'choices', icon: 'dashicons-networking', kind: 'dynamic', baseAttributes: array(), fieldSpecificAttributes: array( 'source' => 'manual', 'levels' => array(), // dropdowns, buttons, or columns. The public field reads this. 'presentation' => 'dropdowns', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'chained_levels', 'name' => 'levels', 'label' => __( 'Dropdowns', 'subtleforms' ), 'section' => 'choices', 'help' => __( 'Each dropdown appears after the one above it. A choice in a later dropdown is only offered when the visitor picks its parent.', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // ===== Date & Time Fields ===== $registry->register( new FieldDefinition( type: 'date', label: __( 'Date', 'subtleforms' ), category: 'advanced', icon: 'dashicons-calendar-alt', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'format' => 'site', 'customFormat' => '', 'firstDay' => 'site', 'minDate' => null, 'maxDate' => null, 'disablePast' => false, 'disabledWeekdays' => array(), 'defaultMode' => 'none', ), inspectorControls: array_merge( self::dateTimeLabelControls(), array( array( 'type' => 'select', 'name' => 'format', 'label' => __( 'Date format', 'subtleforms' ), 'help' => __( 'How the date reads in the field. The saved value is always the same.', 'subtleforms' ), 'section' => 'appearance', 'options' => self::dateFormatOptions(), ), array( 'type' => 'text', 'name' => 'customFormat', 'label' => __( 'Custom format', 'subtleforms' ), 'help' => __( 'PHP date format letters, for example d/m/Y.', 'subtleforms' ), 'section' => 'appearance', 'showWhen' => array( 'format' => array( 'custom' ) ), ), array( 'type' => 'select', 'name' => 'firstDay', 'label' => __( 'First day of the week', 'subtleforms' ), 'help' => __( 'Which day the calendar starts its weeks on.', 'subtleforms' ), 'section' => 'appearance', 'options' => self::firstDayOptions(), ), ), self::dateLimitControls(), array( array( 'type' => 'select', 'name' => 'defaultMode', 'label' => __( 'Default value', 'subtleforms' ), 'help' => __( 'Today fills the field when the form opens with no value.', 'subtleforms' ), 'section' => 'general', 'options' => array( array( 'value' => 'none', 'label' => __( 'None', 'subtleforms' ), ), array( 'value' => 'today', 'label' => __( 'Today', 'subtleforms' ), ), ), ), ) ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'time', label: __( 'Time', 'subtleforms' ), category: 'advanced', icon: 'dashicons-clock', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'format' => 'H:i', 'customFormat' => '', 'minuteStep' => 15, 'minTime' => null, 'maxTime' => null, 'defaultMode' => 'none', ), inspectorControls: array_merge( self::dateTimeLabelControls(), array( array( 'type' => 'select', 'name' => 'format', 'label' => __( 'Time format', 'subtleforms' ), 'help' => __( 'How the time reads in the field. The saved value is always 24-hour, like 14:30.', 'subtleforms' ), 'section' => 'appearance', 'options' => self::timeFormatOptions(), ), array( 'type' => 'text', 'name' => 'customFormat', 'label' => __( 'Custom format', 'subtleforms' ), 'help' => __( 'PHP date format letters, for example H:i.', 'subtleforms' ), 'section' => 'appearance', 'showWhen' => array( 'format' => array( 'custom' ) ), ), ), self::timeLimitControls(), array( array( 'type' => 'select', 'name' => 'defaultMode', 'label' => __( 'Default value', 'subtleforms' ), 'help' => __( 'Now fills the field with the current time, rounded up to the minute step.', 'subtleforms' ), 'section' => 'general', 'options' => array( array( 'value' => 'none', 'label' => __( 'None', 'subtleforms' ), ), array( 'value' => 'now', 'label' => __( 'Now', 'subtleforms' ), ), ), ), ) ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'datetime', label: __( 'Date & Time', 'subtleforms' ), category: 'advanced', icon: 'dashicons-calendar', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'format' => 'site', 'customFormat' => '', 'firstDay' => 'site', 'minDate' => null, 'maxDate' => null, 'disablePast' => false, 'disabledWeekdays' => array(), 'minuteStep' => 15, 'minTime' => null, 'maxTime' => null, 'defaultMode' => 'none', ), inspectorControls: array_merge( self::dateTimeLabelControls(), array( array( 'type' => 'select', 'name' => 'format', 'label' => __( 'Date and time format', 'subtleforms' ), 'help' => __( 'How the date and time read in the field. The saved value is always like 2025-03-31T14:30.', 'subtleforms' ), 'section' => 'appearance', 'options' => self::dateTimeFormatOptions(), ), array( 'type' => 'text', 'name' => 'customFormat', 'label' => __( 'Custom format', 'subtleforms' ), 'help' => __( 'PHP date format letters, for example d/m/Y H:i.', 'subtleforms' ), 'section' => 'appearance', 'showWhen' => array( 'format' => array( 'custom' ) ), ), array( 'type' => 'select', 'name' => 'firstDay', 'label' => __( 'First day of the week', 'subtleforms' ), 'help' => __( 'Which day the calendar starts its weeks on.', 'subtleforms' ), 'section' => 'appearance', 'options' => self::firstDayOptions(), ), ), self::dateLimitControls(), self::timeLimitControls(), array( array( 'type' => 'select', 'name' => 'defaultMode', 'label' => __( 'Default value', 'subtleforms' ), 'help' => __( 'Now fills the field with today and the current time, rounded up to the minute step.', 'subtleforms' ), 'section' => 'general', 'options' => array( array( 'value' => 'none', 'label' => __( 'None', 'subtleforms' ), ), array( 'value' => 'now', 'label' => __( 'Now', 'subtleforms' ), ), ), ), ) ), meta: array( 'category' => 'regular' ), ) ); // ===== Media Fields ===== $registry->register( new FieldDefinition( type: 'image_upload', label: __( 'Image Upload', 'subtleforms' ), category: 'media', icon: 'dashicons-format-image', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'maxSize' => 5242880, // 5MB 'allowedTypes' => array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp' ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'maxSize', 'label' => __( 'Max Size (bytes)', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'file_upload', label: __( 'File Upload', 'subtleforms' ), category: 'media', icon: 'dashicons-media-document', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'maxSize' => 10485760, // 10MB 'allowedTypes' => array( 'application/pdf', 'application/msword', 'text/plain' ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'maxSize', 'label' => __( 'Max Size (bytes)', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); // ===== Advanced Fields ===== $registry->register( new FieldDefinition( type: 'rating', label: __( 'Rating', 'subtleforms' ), category: 'advanced', icon: 'dashicons-star-filled', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'max' => 5, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'max', 'label' => __( 'Max Rating', 'subtleforms' ), 'min' => 1, 'max' => 10, ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'range_slider', label: __( 'Range Slider', 'subtleforms' ), category: 'advanced', icon: 'dashicons-leftright', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'min' => 0, 'max' => 100, 'step' => 1, ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'min', 'label' => __( 'Minimum', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'max', 'label' => __( 'Maximum', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'step', 'label' => __( 'Step size', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'color_picker', label: __( 'Color Picker', 'subtleforms' ), category: 'advanced', icon: 'dashicons-color-picker', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'default' => '#000000', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'default', 'label' => __( 'Default Color', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'rich_text', label: __( 'Rich Text Input', 'subtleforms' ), category: 'advanced', icon: 'dashicons-editor-bold', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array(), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'net_promoter_score', label: __( 'Net Promoter Score', 'subtleforms' ), category: 'advanced', icon: 'dashicons-chart-bar', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array(), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'checkbox_grid', label: __( 'Checkbox Grid', 'subtleforms' ), category: 'advanced', icon: 'dashicons-grid-view', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( // Ships ready to answer, like the builder preview (2.2.1, bug 8). 'rows' => array( __( 'Row 1', 'subtleforms' ), __( 'Row 2', 'subtleforms' ) ), 'columns' => array( __( 'Column 1', 'subtleforms' ), __( 'Column 2', 'subtleforms' ), __( 'Column 3', 'subtleforms' ) ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'dynamic_field', label: __( 'Dynamic Field', 'subtleforms' ), category: 'advanced', icon: 'dashicons-database', kind: 'dynamic', baseAttributes: array(), fieldSpecificAttributes: array( 'source' => '', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'source', 'label' => __( 'Data Source', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'post_selection', label: __( 'Post Selection', 'subtleforms' ), category: 'advanced', icon: 'dashicons-admin-post', kind: 'dynamic', baseAttributes: array(), fieldSpecificAttributes: array( 'post_type' => 'post', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'post_type', 'label' => __( 'Post Type', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'html', label: __( 'HTML', 'subtleforms' ), category: 'advanced', icon: 'dashicons-editor-code', kind: 'structure', baseAttributes: array(), fieldSpecificAttributes: array( 'content' => '', ), inspectorControls: array( array( 'type' => 'textarea', 'name' => 'content', 'label' => __( 'HTML Content', 'subtleforms' ), ), ), meta: array( 'category' => 'regular' ), ) ); $registry->register( new FieldDefinition( type: 'hidden', label: __( 'Hidden', 'subtleforms' ), category: 'advanced', icon: 'dashicons-hidden', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'value' => '', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'value', 'label' => __( 'Value', 'subtleforms' ), 'help' => __( 'Sent with the entry to notifications and integrations. Visitors never see it. Supports {user_email}, {user_name}, {date} and {get:param}.', 'subtleforms' ), 'section' => 'general', ), ), meta: array( 'category' => 'system' ), ) ); // ===== Composite Fields ===== // Legacy field removed: replaced by address_group // ===== Structural Fields ===== $registry->register( new FieldDefinition( type: 'disclaimer', label: __( 'Disclaimer', 'subtleforms' ), category: 'layout', icon: 'dashicons-info', kind: 'structure', baseAttributes: array(), fieldSpecificAttributes: array( 'content' => '', 'variant' => 'info', ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'textarea', 'name' => 'content', 'label' => __( 'Disclaimer Text', 'subtleforms' ), ), array( 'type' => 'select', 'name' => 'variant', 'label' => __( 'Style', 'subtleforms' ), 'options' => array( array( 'label' => __( 'Info', 'subtleforms' ), 'value' => 'info', ), array( 'label' => __( 'Warning', 'subtleforms' ), 'value' => 'warning', ), array( 'label' => __( 'Success', 'subtleforms' ), 'value' => 'success', ), array( 'label' => __( 'Neutral', 'subtleforms' ), 'value' => 'neutral', ), ), ), ), ) ); $registry->register( new FieldDefinition( type: 'section_break', label: __( 'Section Break', 'subtleforms' ), category: 'layout', icon: 'dashicons-minus', kind: 'structure', baseAttributes: array(), fieldSpecificAttributes: array( 'title' => '', 'description' => '', ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'text', 'name' => 'title', 'label' => __( 'Title', 'subtleforms' ), ), array( 'type' => 'textarea', 'name' => 'description', 'label' => __( 'Description', 'subtleforms' ), ), ), ) ); $registry->register( new FieldDefinition( type: 'form_step', label: __( 'Form Step', 'subtleforms' ), category: 'layout', icon: 'dashicons-arrow-right-alt2', kind: 'structure', baseAttributes: array(), fieldSpecificAttributes: array( 'title' => '', ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'text', 'name' => 'title', 'label' => __( 'Title', 'subtleforms' ), ), ), ) ); $registry->register( new FieldDefinition( type: 'repeat_field', label: __( 'Repeat Field', 'subtleforms' ), category: 'layout', icon: 'dashicons-controls-repeat', kind: 'structure', baseAttributes: array(), fieldSpecificAttributes: array( 'max' => 5, ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'max', 'label' => __( 'Max Items', 'subtleforms' ), ), ), ) ); // ===== Layout Containers ===== // Helper function to create column containers $createColumnContainer = function ( $columns ) use ( $registry ) { $registry->register( new FieldDefinition( type: "{$columns}_column_container", label: _n( 'Column', 'Columns', $columns, 'subtleforms' ), category: 'layout', icon: 'columns', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'columns' => $columns, 'spacing' => 16, ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'number', 'name' => 'spacing', 'label' => __( 'Spacing (px)', 'subtleforms' ), ), ), ) ); }; // Register all column containers (1-6) foreach ( array( 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5, 'six' => 6, ) as $name => $num ) { $createColumnContainer( $name ); } $registry->register( new FieldDefinition( type: 'repeat_container', label: __( 'Repeat Container', 'subtleforms' ), category: 'layout', icon: 'controls-repeat', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'min' => 1, 'max' => 5, 'buttonLabel' => __( 'Add New', 'subtleforms' ), 'spacing' => 16, ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'number', 'name' => 'min', 'label' => __( 'Min Repeats', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'max', 'label' => __( 'Max Repeats', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'buttonLabel', 'label' => __( 'Button Label', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'spacing', 'label' => __( 'Spacing (px)', 'subtleforms' ), ), ), ) ); $registry->register( new FieldDefinition( type: 'group_container', label: __( 'Group', 'subtleforms' ), category: 'layout', icon: 'category', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'label' => __( 'Group', 'subtleforms' ), 'spacing' => 16, ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'number', 'name' => 'spacing', 'label' => __( 'Spacing (px)', 'subtleforms' ), ), ), ) ); // Tabs and Accordion (2.9.0): a container holds panels, each panel holds // fields. Panels are created by their container and hidden from the // field library. All four are layout only: nothing is answered at them. $registry->register( new FieldDefinition( type: 'tabs_container', label: __( 'Tabs', 'subtleforms' ), category: 'layout', icon: 'index-card', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'label' => __( 'Tabs', 'subtleforms' ), 'position' => 'top', 'collapse_mobile' => true, 'active' => 0, ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), 'help' => __( 'Names the tabs in the builder and for screen readers. Visitors do not see it.', 'subtleforms' ), ), array( 'type' => 'select', 'name' => 'position', 'section' => 'general', 'label' => __( 'Tab position', 'subtleforms' ), 'options' => array( array( 'value' => 'top', 'label' => __( 'Top', 'subtleforms' ), ), array( 'value' => 'left', 'label' => __( 'Left', 'subtleforms' ), ), ), ), array( 'type' => 'toggle', 'name' => 'collapse_mobile', 'section' => 'general', 'label' => __( 'On narrow screens, show as accordion', 'subtleforms' ), ), array( 'type' => 'panel_select', 'name' => 'active', 'section' => 'general', 'label' => __( 'Tab shown first', 'subtleforms' ), ), ), ) ); $registry->register( new FieldDefinition( type: 'accordion_container', label: __( 'Accordion', 'subtleforms' ), category: 'layout', icon: 'editor-justify', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'label' => __( 'Accordion', 'subtleforms' ), 'multiple' => false, 'open' => 'first', 'icon' => 'chevron', ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), 'help' => __( 'Names the accordion in the builder. Visitors do not see it.', 'subtleforms' ), ), array( 'type' => 'toggle', 'name' => 'multiple', 'section' => 'general', 'label' => __( 'Let several sections open at once', 'subtleforms' ), ), array( 'type' => 'select', 'name' => 'open', 'section' => 'general', 'label' => __( 'Open at start', 'subtleforms' ), 'options' => array( array( 'value' => 'first', 'label' => __( 'First section', 'subtleforms' ), ), array( 'value' => 'none', 'label' => __( 'None', 'subtleforms' ), ), array( 'value' => 'all', 'label' => __( 'All', 'subtleforms' ), ), ), ), array( 'type' => 'select', 'name' => 'icon', 'section' => 'general', 'label' => __( 'Icon', 'subtleforms' ), 'options' => array( array( 'value' => 'chevron', 'label' => __( 'Chevron', 'subtleforms' ), ), array( 'value' => 'plus', 'label' => __( 'Plus and minus', 'subtleforms' ), ), ), ), ), ) ); $registry->register( new FieldDefinition( type: 'tab_panel', label: __( 'Tab', 'subtleforms' ), category: 'layout', icon: 'index-card', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'label' => __( 'Tab', 'subtleforms' ) ), inspectorControls: array(), meta: array( 'category' => 'layout', 'internal' => true, ), paletteHidden: true, layoutControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Title', 'subtleforms' ), ), ), ) ); $registry->register( new FieldDefinition( type: 'accordion_panel', label: __( 'Section', 'subtleforms' ), category: 'layout', icon: 'editor-justify', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'label' => __( 'Section', 'subtleforms' ) ), inspectorControls: array(), meta: array( 'category' => 'layout', 'internal' => true, ), paletteHidden: true, layoutControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Title', 'subtleforms' ), ), ), ) ); // ===== Step/Page Container ===== $registry->register( new FieldDefinition( type: 'step', label: __( 'Step', 'subtleforms' ), category: 'structure', icon: 'dashicons-media-document', kind: 'structure', acceptsChildren: true, baseAttributes: array(), fieldSpecificAttributes: array( 'title' => __( 'Step', 'subtleforms' ), 'description' => '', ), inspectorControls: array(), meta: array( 'category' => 'layout' ), layoutControls: array( array( 'type' => 'text', 'name' => 'title', 'label' => __( 'Title', 'subtleforms' ), ), array( 'type' => 'textarea', 'name' => 'description', 'label' => __( 'Description', 'subtleforms' ), ), ), ) ); // ===== Special Fields ===== // Name Group Field $registry->register( new FieldDefinition( type: 'name_group', label: __( 'Name', 'subtleforms' ), category: 'special', icon: 'dashicons-admin-users', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'fields' => array( 'first_name' => array( 'enabled' => true, 'label' => 'First Name', 'placeholder' => '' ), 'last_name' => array( 'enabled' => true, 'label' => 'Last Name', 'placeholder' => '' ), 'middle_name' => array( 'enabled' => false, 'label' => 'Middle Name', 'placeholder' => '' ), 'suffix' => array( 'enabled' => false, 'label' => 'Suffix', 'placeholder' => '' ), ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'subfield', 'name' => 'fields', 'subfields' => array( array( 'key' => 'first_name', 'label' => __( 'First Name', 'subtleforms' ), 'toggleable' => false ), array( 'key' => 'last_name', 'label' => __( 'Last Name', 'subtleforms' ), 'toggleable' => false ), array( 'key' => 'middle_name', 'label' => __( 'Middle Name', 'subtleforms' ), 'toggleable' => true ), array( 'key' => 'suffix', 'label' => __( 'Suffix', 'subtleforms' ), 'toggleable' => true ), ), ), ), meta: array( 'category' => 'composite' ), ) ); // Address Group Field $registry->register( new FieldDefinition( type: 'address_group', label: __( 'Address', 'subtleforms' ), category: 'special', icon: 'dashicons-location', kind: 'input', baseAttributes: array(), fieldSpecificAttributes: array( 'fields' => array( 'street' => array( 'enabled' => true, 'label' => 'Street Address', 'placeholder' => '' ), 'street2' => array( 'enabled' => false, 'label' => 'Street Address Line 2', 'placeholder' => 'Apt, Suite, etc.' ), 'city' => array( 'enabled' => true, 'label' => 'City', 'placeholder' => '' ), 'state' => array( 'enabled' => true, 'label' => 'State / Province', 'placeholder' => '' ), 'postal' => array( 'enabled' => true, 'label' => 'Postal Code', 'placeholder' => '' ), 'country' => array( 'enabled' => true, 'label' => 'Country', 'placeholder' => '' ), ), ), inspectorControls: array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), ), array( 'type' => 'subfield', 'name' => 'fields', 'subfields' => array( array( 'key' => 'street', 'label' => __( 'Street Address', 'subtleforms' ), 'toggleable' => false ), array( 'key' => 'street2', 'label' => __( 'Street Address Line 2', 'subtleforms' ), 'toggleable' => true ), array( 'key' => 'city', 'label' => __( 'City', 'subtleforms' ), 'toggleable' => false ), array( 'key' => 'state', 'label' => __( 'State / Province', 'subtleforms' ), 'toggleable' => true ), array( 'key' => 'postal', 'label' => __( 'Postal Code', 'subtleforms' ), 'toggleable' => true ), array( 'key' => 'country', 'label' => __( 'Country', 'subtleforms' ), 'toggleable' => true ), ), ), ), meta: array( 'category' => 'composite' ), ) ); // ===== System Fields ===== $registry->register( new FieldDefinition( type: 'recaptcha', label: __( 'reCaptcha', 'subtleforms' ), category: 'system', icon: 'dashicons-shield', kind: 'system', baseAttributes: array(), fieldSpecificAttributes: array( 'site_key' => '', 'secret_key' => '', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'site_key', 'label' => __( 'Site Key', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'secret_key', 'label' => __( 'Secret key', 'subtleforms' ), 'help' => __( 'Used to check the answer. Leave blank to use the key saved in Settings for this provider.', 'subtleforms' ), ), ), meta: array( 'category' => 'system' ), ) ); $registry->register( new FieldDefinition( type: 'hcaptcha', label: __( 'hCaptcha', 'subtleforms' ), category: 'system', icon: 'dashicons-shield-alt', kind: 'system', baseAttributes: array(), fieldSpecificAttributes: array( 'site_key' => '', 'secret_key' => '', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'site_key', 'label' => __( 'Site Key', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'secret_key', 'label' => __( 'Secret key', 'subtleforms' ), 'help' => __( 'Used to check the answer. Leave blank to use the key saved in Settings for this provider.', 'subtleforms' ), ), ), meta: array( 'category' => 'system' ), ) ); $registry->register( new FieldDefinition( type: 'turnstile', label: __( 'Turnstile', 'subtleforms' ), category: 'system', icon: 'dashicons-lock', kind: 'system', baseAttributes: array(), fieldSpecificAttributes: array( 'site_key' => '', 'secret_key' => '', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'site_key', 'label' => __( 'Site Key', 'subtleforms' ), ), array( 'type' => 'text', 'name' => 'secret_key', 'label' => __( 'Secret key', 'subtleforms' ), 'help' => __( 'Used to check the answer. Leave blank to use the key saved in Settings for this provider.', 'subtleforms' ), ), ), meta: array( 'category' => 'system' ), ) ); $registry->register( new FieldDefinition( type: 'action_hook', label: __( 'Action Hook', 'subtleforms' ), category: 'system', icon: 'dashicons-admin-plugins', kind: 'system', baseAttributes: array(), fieldSpecificAttributes: array( 'hook_name' => '', ), inspectorControls: array( array( 'type' => 'text', 'name' => 'hook_name', 'label' => __( 'Hook Name', 'subtleforms' ), ), ), meta: array( 'category' => 'system' ), paletteHidden: true, ) ); $registry->register( new FieldDefinition( type: 'save_resume', label: __( 'Save & Resume', 'subtleforms' ), category: 'system', icon: 'dashicons-saved', kind: 'system', baseAttributes: array(), fieldSpecificAttributes: array( 'enabled' => true, ), inspectorControls: array( array( 'type' => 'checkbox', 'name' => 'enabled', 'label' => __( 'Enabled', 'subtleforms' ), ), ), meta: array( 'category' => 'system' ), ) ); // Allow extensions to register additional fields do_action( 'subtleforms/fields/register', $registry ); } /** * Options for the country field's default-country select. * * @return array */ private static function countryControlOptions(): array { $options = array( array( 'value' => '', 'label' => __( 'No default', 'subtleforms' ), ), ); foreach ( CountryList::getAll() as $code => $name ) { $options[] = array( 'value' => $code, 'label' => $name, ); } return $options; } /** * Resolve the site's Privacy Policy page URL, if one is set. * * WordPress exposes the Privacy Policy page via the `wp_page_for_privacy_policy` * option. We surface it as the default for the Consent field's link so admins * get a sensible value without configuration; empty when no page is set. * * @return string Privacy Policy URL, or '' if none configured. */ private static function default_privacy_policy_url(): string { $page_id = (int) get_option( 'wp_page_for_privacy_policy', 0 ); if ( $page_id <= 0 ) { return ''; } $permalink = get_permalink( $page_id ); return is_string( $permalink ) ? $permalink : ''; } /** * Label and placeholder controls shared by the date and time fields. * Help text is added to every input by FieldSettings. * * @return array> */ private static function dateTimeLabelControls(): array { return array( array( 'type' => 'text', 'name' => 'label', 'label' => __( 'Label', 'subtleforms' ), 'help' => __( 'The question shown above the field.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'text', 'name' => 'placeholder', 'label' => __( 'Placeholder', 'subtleforms' ), 'help' => __( 'Shown while the field is empty. Leave it blank to show an example of the format.', 'subtleforms' ), 'section' => 'appearance', ), ); } /** * Earliest and latest date, no past dates and disabled weekdays. * * @return array> */ private static function dateLimitControls(): array { return array( array( 'type' => 'date', 'name' => 'minDate', 'label' => __( 'Earliest date', 'subtleforms' ), 'help' => __( 'A date, or a relative date such as today or +7 days.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'date', 'name' => 'maxDate', 'label' => __( 'Latest date', 'subtleforms' ), 'help' => __( 'A date, or a relative date such as +1 year.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'toggle', 'name' => 'disablePast', 'label' => __( 'No past dates', 'subtleforms' ), 'help' => __( 'Days before today cannot be picked.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'weekdays', 'name' => 'disabledWeekdays', 'label' => __( 'Unavailable weekdays', 'subtleforms' ), 'help' => __( 'Turn on the days of the week that cannot be picked.', 'subtleforms' ), 'section' => 'general', ), ); } /** * Minute step, earliest and latest time. * * @return array> */ private static function timeLimitControls(): array { $steps = array(); foreach ( array( 1, 5, 10, 15, 30, 60 ) as $minutes ) { $steps[] = array( 'value' => (string) $minutes, /* translators: %d: number of minutes. */ 'label' => sprintf( _n( '%d minute', '%d minutes', $minutes, 'subtleforms' ), $minutes ), ); } return array( array( 'type' => 'select', 'name' => 'minuteStep', 'label' => __( 'Minute step', 'subtleforms' ), 'help' => __( 'The minutes offered in the time list.', 'subtleforms' ), 'section' => 'general', 'options' => $steps, ), array( 'type' => 'time', 'name' => 'minTime', 'label' => __( 'Earliest time', 'subtleforms' ), 'help' => __( 'Times before this cannot be picked.', 'subtleforms' ), 'section' => 'general', ), array( 'type' => 'time', 'name' => 'maxTime', 'label' => __( 'Latest time', 'subtleforms' ), 'help' => __( 'Times after this cannot be picked.', 'subtleforms' ), 'section' => 'general', ), ); } /** * One format choice with a live example built from the site clock. * * @param string $format PHP date format. * @return array{value: string, label: string} */ private static function formatChoice( string $format ): array { $stamp = 1743415800; // 2025-03-31 10:30 UTC, a Monday. $text = function_exists( 'wp_date' ) ? wp_date( $format, $stamp ) : gmdate( $format, $stamp ); return array( 'value' => $format, 'label' => sprintf( '%1$s (%2$s)', $format, (string) $text ), ); } /** * The "site" and "custom" choices that end every format list. * * @param string $siteLabel Label of the site choice. * @return array */ private static function formatTail( string $siteLabel ): array { return array( array( 'value' => 'site', 'label' => $siteLabel, ), array( 'value' => 'custom', 'label' => __( 'Custom', 'subtleforms' ), ), ); } /** * Date format presets. * * @return array */ private static function dateFormatOptions(): array { $options = array_map( array( self::class, 'formatChoice' ), array( 'Y-m-d', 'd/m/Y', 'm/d/Y', 'd.m.Y', 'j F Y', 'D, j M Y' ) ); $site = (string) get_option( 'date_format', 'F j, Y' ); return array_merge( $options, self::formatTail( /* translators: %s: the site date format with an example. */ sprintf( __( 'Site setting (%s)', 'subtleforms' ), self::formatChoice( $site )['label'] ) ) ); } /** * Time format presets. * * @return array */ private static function timeFormatOptions(): array { $options = array_map( array( self::class, 'formatChoice' ), array( 'H:i', 'g:i A' ) ); $site = (string) get_option( 'time_format', 'g:i a' ); return array_merge( $options, self::formatTail( /* translators: %s: the site time format with an example. */ sprintf( __( 'Site setting (%s)', 'subtleforms' ), self::formatChoice( $site )['label'] ) ) ); } /** * Date and time format presets. * * @return array */ private static function dateTimeFormatOptions(): array { $options = array_map( array( self::class, 'formatChoice' ), array( 'Y-m-d H:i', 'd/m/Y H:i', 'm/d/Y g:i A', 'j F Y, g:i A' ) ); $site = (string) get_option( 'date_format', 'F j, Y' ) . ', ' . (string) get_option( 'time_format', 'g:i a' ); return array_merge( $options, self::formatTail( /* translators: %s: the site date and time format with an example. */ sprintf( __( 'Site setting (%s)', 'subtleforms' ), self::formatChoice( $site )['label'] ) ) ); } /** * First day of the week choices. * * @return array */ private static function firstDayOptions(): array { return array( array( 'value' => 'site', 'label' => __( 'Site setting', 'subtleforms' ), ), array( 'value' => '0', 'label' => __( 'Sunday', 'subtleforms' ), ), array( 'value' => '1', 'label' => __( 'Monday', 'subtleforms' ), ), array( 'value' => '6', 'label' => __( 'Saturday', 'subtleforms' ), ), ); } }