@@ -25,6 +25,7 @@ wherever the screen happens to be.
2525* Group fields into tabs or collapsible sections
2626* Sit two short fields on one line with ` 'width' => 'half' `
2727* Take an amount with its currency symbol inside the control
28+ * Fill a select from a named preset — roles, timezones, countries — with one string
2829* Fold a repeater's rows away, each titled by one of its own fields
2930* Reorder a repeater by dragging its handle, or from the keyboard
3031* Refuse a value that fails a rule — required, email, url, your own callable — and say why
@@ -107,7 +108,7 @@ Date, time and colour
107108: ` date ` ` time ` ` datetime ` ` color ` ` gradient ` ` date_range ` ` time_range `
108109
109110Choice
110- : ` select ` ` enhanced_select ` ` select_multiple ` ` checkbox ` ` toggle ` ` radio ` ` checkbox_group ` ` button_group ` ` card_choice `
111+ : ` select ` ` enhanced_select ` ` select_multiple ` ` checkbox ` ` toggle ` ` radio ` ` checkbox_group ` ` button_group ` ` card_choice ` ` country ` ` currency `
111112
112113Relational — one search endpoint behind all of them
113114: ` post ` ` page ` ` user ` ` taxonomy ` ` ajax ` ` tags `
@@ -124,6 +125,38 @@ Layout and display
124125Purpose-built
125126: ` license ` ` email_editor ` ` action_button `
126127
128+ ## Options from a preset
129+
130+ The lists every settings screen ends up needing — the site's roles, its
131+ timezones, its page templates — are presets, and a select asks for one by
132+ name rather than building it again:
133+
134+ ``` php
135+ use ArrayPress\FieldKit\FieldSet;
136+ use ArrayPress\FieldKit\Context\OptionContext;
137+
138+ $set = new FieldSet(
139+ [
140+ 'notify_role' => [ 'type' => 'select', 'label' => __( 'Notify', 'my-plugin' ), 'options' => 'roles' ],
141+ 'timezone' => [ 'type' => 'select', 'label' => __( 'Timezone', 'my-plugin' ), 'options' => 'timezones' ],
142+ 'country' => [ 'type' => 'country', 'label' => __( 'Country', 'my-plugin' ), 'continents' => true ],
143+ 'currency' => [ 'type' => 'currency', 'label' => __( 'Currency', 'my-plugin' ) ],
144+ ],
145+ new OptionContext( 'my_plugin' ),
146+ 'my_plugin'
147+ );
148+ ```
149+
150+ The built-ins are ` roles ` , ` post_types ` , ` taxonomies ` , ` pages ` , ` timezones ` ,
151+ ` image_sizes ` , ` page_templates ` , ` cron_schedules ` , ` countries ` and
152+ ` currencies ` . The last two draw on ` arraypress/wp-countries ` and
153+ ` arraypress/wp-money ` ; the ` country ` and ` currency ` types use them by default.
154+
155+ A preset is resolved when the field renders, not when it is declared, and its
156+ options pass through the ` field_kit_preset_options ` filter. Register your own
157+ with ` Presets::register( 'products', fn() => $options ) ` and any field can say
158+ ` 'options' => 'products' ` .
159+
127160## Requirements
128161
129162* PHP 8.3 or later
0 commit comments