Skip to main content

Option Types

Option types are the building blocks of Unyson+ settings, meta boxes, and shortcode options. The framework ships with many — text, textarea, select, switch, color, typography, image/upload, gallery, spacing, gradient, box-shadow, and more.

Every option has type as a required parameter. Its value should be an existing registered option type.

Defining options

Options are declared as a PHP array:

<?php
$options = array(
'heading' => array(
'type' => 'text',
'label' => __( 'Heading', 'fw' ),
'value' => 'Hello world',
),
'accent' => array(
'type' => 'color-picker',
'label' => __( 'Accent color', 'fw' ),
'value' => '#ffcc00',
),
);

Reading saved values

<?php
// Theme settings
$accent = fw_get_db_settings_option( 'accent' );

// Post meta (e.g. from a Custom Fields group or a meta box)
$heading = fw_get_field( 'heading' );

Adding a new option type

New option types live in framework/includes/option-types/. Each registers a class extending FW_Option_Type. For a complete worked example (the PHP class, the prefixed CSS, and the fw:options:init JS), see Create an option type. The conventions below are the rules that example follows.

HTML

All option types must have a .fw-option-type-{type} class on the main/wrapper html element.

CSS

If the option type has css, all rules must be prefixed with the .fw-option-type-{type} class:

/* correct */
.fw-option-type-demo .some-class {
color: blue;
}

/* wrong */
.some-class {
color: blue;
}
tip

This is done to prevent css conflicts.

JavaScript

All javascript must stick to the .fw-option-type-{type} class and work only within the main/wrapper element (no events attached to the body). If the option type has custom javascript events, those events must be triggered on the main element.

$someInnerElement.closest('.fw-option-type-demo')
.trigger('fw:option-type:demo:custom-event', {some: 'data'});

If it's specified in the documentation that an option type has custom events, it means that you can attach event listeners on the elements with the .fw-option-type-{type} class (not on body or fwEvents). Some events send data that can be accessed this way:

jQuery('.fw-option-type-demo#fw-option-demo')
.on('fw:option-type:demo:custom-event', function(event, data){
console.log(data);
});
danger

Do not confuse .fw-option-type-{type} with the .fw-backend-option-type-{type} class which is used internally by the framework and should not be used in option type scripts.

Built-in option types

All 54 built-in types, grouped by what they're for. Click any type for its reference and a copy-pasteable example.

Text & rich input

TypeFor
textA single-line text input
short-textA narrow text input
medium-textA mid-width text input
textareaMulti-line plain text
passwordA masked text input
numberA numeric input with min / max / step
unit-inputA number paired with a unit selector (px / rem / em / %)
code-editorA syntax-highlighted code editor
wp-editorThe WordPress rich-text (TinyMCE) editor
htmlRender arbitrary HTML in the form (no stored value)
hiddenA stored value with no visible control

Choice

TypeFor
selectA single-choice dropdown
short-selectA narrow dropdown
select-multipleA multi-choice dropdown
multi-selectA tag-style multi-select (posts, terms, users, …)
radioA single choice as radio buttons
radio-textRadio buttons rendered as a segmented control
checkboxA single on/off checkbox
checkboxesMultiple checkboxes
switchAn on/off toggle
image-pickerChoose one option by clicking an image swatch

Color

TypeFor
color-pickerA single solid color
rgba-color-pickerA color with alpha / opacity
predefined-colorsPick from a fixed palette
predefined-colors-color-pickerA palette preset or a custom color
predefined-colors-color-picker-compactThe compact preset-or-custom picker
gradientA two-stop gradient
gradient-v2A multi-stop gradient with angle and type

Media & icons

TypeFor
uploadUpload or select one file from the Media Library
multi-uploadSelect multiple files / a gallery
background-imageAn image with position / repeat / size
background-proFull background: color + gradient + image + video layers
oembedEmbed by URL (YouTube, Vimeo, …)
iconPick an icon (Font Awesome)
icon-v2Pick an icon from multiple packs, or upload a custom SVG
mapA location picker returning coordinates + address

Typography, spacing & effects

TypeFor
typographyFont family / size / weight / style / line-height / color
typography-v2The modern typography control (+ Google Fonts)
spacingMargin / padding per side, with per-device overrides
box-shadowA box-shadow builder

Sliders & ranges

TypeFor
sliderA single-value slider
range-sliderA min / max range slider

Date & time

TypeFor
date-pickerPick a date
datetime-pickerPick a date and time
datetime-rangePick a start / end date-time range

Presets & pickers

TypeFor
button-presetsManage reusable button-style presets
button-style-pickerPick a button preset with a live preview
image-style-pickerPick an Image Style preset with a live swatch preview

Composite & repeatable

TypeFor
multiGroup several options into one stored value
multi-pickerReveal different sub-options based on a picker choice
responsiveWrap any control to make it per-device (Phone / Tablet / Desktop)
popupEdit a set of options inside a modal
popoverEdit options inside an inline popover panel
addable-optionA repeatable single option (add / remove rows)
addable-boxA repeatable group of options (add / remove boxes)
addable-popupRepeatable items, each edited in a popup