This is where you'll find a lot of the convenience of using the SiteOrigin Widgets Bundle as a framework for creating your own widgets. The widget form fields are a way for you to define the configuration fields you'd like to allow for your widget users. The more form fields you provide, the more customizable your widget becomes.
The form fields options are passed into the SiteOrigin_Widget class constructor as an array and stored in the $form_options instance variable. Each value in the array is a form field descriptor, which is an associative array describing the form field to be rendered by the SiteOrigin_Widget base class, in order to capture configuration values for a widget instance. Each form field descriptor must at least have a type, however a few of the types won't be useful without additional configuration values. Optional base form field descriptor values are listed below:
- label:
stringRender a label for the field with the given value. - default:
mixedThe field will be prepopulated with this default value. - description:
stringRender small italic text below the field to describe the field's purpose. - optional:
boolAppend '(Optional)' to this field's label as a small green superscript. - sanitize:
stringSpecifies sanitization type to be performed on input from this field. Available sanitizations are'email' and 'url'. If the specified sanitization isn't recognized it is assumed to be a custom sanitization and a filter is applied using the pattern'siteorigin_widgets_sanitize_field_' . $sanitize, in case the sanitization is defined elsewhere.
In addition to these, some fields have their own specific configuration values, which are listed in the respective sections below.
You can see all of these in action by installing and activating the SiteOrigin Widget Form Fields Demo plugin which can be found in the so-dev-examples repository.
Renders a text input field.
- placeholder:
stringA string to display before any text has been input. - readonly:
boolIf true, this field will not be editable.
Form options input:
$form_options = array(
'some_text' => array(
'type' => 'text',
'label' => __('Some text goes here', 'widget-form-fields-text-domain'),
'default' => 'Some default text.'
)
);Result:
Renders an input field for entering any URL and a button for convenient selection of content from public posts (except attachments).
- placeholder:
stringA string to display before any text has been input. - readonly:
boolIf true, this field will not be editable.
Form options input:
$form_options = array(
'some_url' => array(
'type' => 'link',
'label' => __('Some URL goes here', 'widget-form-fields-text-domain'),
'default' => 'http://www.example.com'
)
);Result:
Renders a color input field and color picker.
- placeholder:
stringA string to display before any text has been input.
Form options input:
$form_options = array(
'some_color' => array(
'type' => 'color',
'label' => __( 'Choose a color', 'widget-form-fields-text-domain' ),
'default' => '#bada55'
)
);Result:
Renders a text input field for entering a number. This is the same as the text field, except that the input is cast as a float.
- placeholder:
stringA string to display before any text has been input. - readonly:
boolIf true, this field will not be editable.
Form options input:
$form_options = array(
'some_number' => array(
'type' => 'number',
'label' => __( 'Enter a number', 'widget-form-fields-text-domain' ),
'default' => '12654'
)
);Result:
Renders a textarea field.
- rows:
intThe number of visible rows in the textarea. - placeholder:
stringA string to display before any text has been input. - readonly:
boolIf true, this field will not be editable.
Form options input:
$form_options = array(
'some_long_message' => array(
'type' => 'textarea',
'label' => __( 'Type a message', 'widget-form-fields-text-domain' ),
'default' => 'An example of a long message.</br>It is even possible to add a few html tags.</br><a href="siteorigin.com" target="_blank"">Links!</a></br><strong>Strong</strong> and <em>emphasized</em> text.',
'rows' => 10
)
);Result:
Renders a TinyMCE editor field.
- rows:
intThe number of visible rows in the textarea. - default_editor:
stringWhether to display the TinyMCE visual editor or the Quicktags HTML editor initially. Allowed values are'tinymce'( can be abbreviated to'tmce'), and'html'. The default is'tinymce'. - editor_height:
intThe initial height of the editor. Setting this will cause the rows option to be ignored. - button_filters:
arrayAn array of filter callbacks to filter the buttons available on the TinyMCE visual editor and the Quicktags HTML editor. The TinyMCE editor can display up to four rows of buttons and the Quicktags editor displays a single row of buttons. Each row can be filtered by specifying a corresponding callback, as follows:- First row:
'mce_buttons' - Second row:
'mce_buttons_2' - Third row:
'mce_buttons_3' - Fourth row:
'mce_buttons_4' - Quicktags settings:
'quicktags_settings'
- First row:
Form options input:
$form_options = array(
'some_tinymce_editor' => array(
'type' => 'tinymce',
'label' => __( 'Visually edit, richly.', 'widget-form-fields-text-domain' ),
'default' => 'An example of a long message.</br>It is even possible to add a few html tags.</br><a href="siteorigin.com" target="_blank"">Links!</a>',
'rows' => 10,
'default_editor' => 'html',
'button_filters' => array(
'mce_buttons' => array( $this, 'filter_mce_buttons' ),
'mce_buttons_2' => array( $this, 'filter_mce_buttons_2' ),
'mce_buttons_3' => array( $this, 'filter_mce_buttons_3' ),
'mce_buttons_4' => array( $this, 'filter_mce_buttons_5' ),
'quicktags_settings' => array( $this, 'filter_quicktags_settings' ),
),
)
);Result:
Renders a number slider field to allow the choice of a number in a range.
- min:
intThe minimum value of the allowed range. - max:
intThe maximum value of the allowed range.
Form options input:
$form_options = array(
'some_number_in_a_range' => array(
'type' => 'slider',
'label' => __( 'Choose a number', 'widget-form-fields-text-domain' ),
'default' => 24,
'min' => 2,
'max' => 37,
'integer' => true
)
);Result:
Renders a dropdown select field. This field is better for a long list of predefined values. For a short list the radio input field is a better choice.
- prompt:
stringIf present, it is included as a disabled (not selectable) value at the top of the list of options. If there is no default value, it is selected by default. You might even want to leave the label value blank when you use this. - options
arrayThe list of options which may be selected. - multiple
boolDetermines whether this is a single or multiple select field.
Form options input:
$form_options = array(
'some_selection' => array(
'type' => 'select',
'label' => __( 'Choose a thing from a long list of things', 'widget-form-fields-text-domain' ),
'default' => 'the_other_thing',
'options' => array(
'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' ),
)
)
);Result:
Form options input:
$form_options = array(
'another_selection' => array(
'type' => 'select',
'prompt' => __( 'Choose a thing from a long list of things', 'widget-form-fields-text-domain' ),
'options' => array(
'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' ),
)
)
);Result:
Form options input:
$form_options = array(
'another_selection' => array(
'type' => 'select',
'label' => __( 'Choose a thing from a long list of things', 'widget-form-fields-text-domain' ),
'multiple' => true,
'default' => 'the_other_thing',
'options' => array(
'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' ),
)
)
);Result:
Renders a checkbox field.
Form options input:
$form_options = array(
'some_boolean' => array(
'type' => 'checkbox',
'label' => __( 'Allow this thing?', 'widget-form-fields-text-domain' ),
'default' => true
)
);Result:
Renders a radio input field. This field is better for a short list of predefined values. For a long list the dropdown select field is a better choice.
- options
arrayThe list of options which may be selected.
Form options input:
$form_options = array(
'radio_selection' => array(
'type' => 'radio',
'label' => __( 'Choose a thing from a short list of things', 'widget-form-fields-text-domain' ),
'default' => 'that_thing',
'options' => array(
'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' )
)
)
);Result:
Renders a media selector button. When clicked the button opens the WordPress Media Library dialog for the media types specified by the library option.
This field requires at least WordPress 3.5.
- choose:
stringA label for the title of the media selector dialog. - update:
stringA label for the confirmation button of the media selector dialog. - library:
stringSets the media library which to browse and from which media can be selected. Allowed values are'image','audio','video', and'file'. The default is'image'. - fallback:
boolWhether or not to display a URL input field which allows for specification of a fallback URL to be used in case the selected media resource isn't available.
Form options input:
$form_options = array(
'some_media' => array(
'type' => 'media',
'label' => __( 'Choose a media thing', 'widget-form-fields-text-domain' ),
'choose' => __( 'Choose image', 'widget-form-fields-text-domain' ),
'update' => __( 'Set image', 'widget-form-fields-text-domain' ),
'library' => 'image',
'fallback' => true
)
);Result:
Renders a post selector field. This can be used to build custom queries with which to select posts from your database. The field displays a small red indicator which shows the number of posts currently being selected. By default, all posts are selected.
You can find more detail about the use of the post selector field here.
Form options input:
$form_options = array(
'some_posts' => array(
'type' => 'posts',
'label' => __('Some posts query', 'widget-form-fields-text-domain'),
)
);Result:
The section field type provides a convenient way to group and hide related form fields. This is useful when you have a large form which can appear overwhelming.
- hide:
boolWhether or not this section should start out collapsed or expanded. - fields:
arrayThe set of fields to be grouped together. This should contain any combination of other field types, even repeaters and sections.
Form options input:
$form_options = array(
'a_section' => array(
'type' => 'section',
'label' => __( 'A section containing related fields.' , 'widget-form-fields-text-domain' ),
'hide' => true,
'fields' => array(
'grouped_text' => array(
'type' => 'text',
'label' => __( 'A grouped text field', 'widget-form-fields-text-domain' )
),
'grouped_checkbox' => array(
'type' => 'checkbox',
'label' => __( 'A grouped checkbox', 'widget-form-fields-text-domain' )
)
)
)
);Result:
The repeater field type provides a convenient way to repeat a specified set of form fields.
- item_name:
stringA default label for each repeated item. - item_label:
arrayThis associative array describes how the repeater may retrieve the item labels from HTML elements as they are updated. The options are:- selector:
stringA JQuery selector which is used to find an element from which to retrieve the item label. - update_event:
stringThe javascript event on which to bind and update the item label. - value_method:
stringThe javascript function which should be used to retrieve the item label from an element.
- selector:
- fields:
arrayThe set of fields to be repeated together as one item. This should contain any combination of other field types, even repeaters and sections. - scroll_count:
intThe maximum number of repeated items to display before adding a scrollbar to the repeater. - readonly:
boolWhether or not items may be added to or removed from this repeater by user interaction.
Form options input:
$form_options = array(
'a_repeater' => array(
'type' => 'repeater',
'label' => __( 'A repeating repeater.' , 'widget-form-fields-text-domain' ),
'item_name' => __( 'Repeater item', 'siteorigin-widgets' ),
'item_label' => array(
'selector' => "[id*='repeat_text']",
'update_event' => 'change',
'value_method' => 'val'
),
'fields' => array(
'repeat_text' => array(
'type' => 'text',
'label' => __( 'A text field in a repeater item.', 'widget-form-fields-text-domain' )
),
'repeat_checkbox' => array(
'type' => 'checkbox',
'label' => __( 'A checkbox in a repeater item.', 'widget-form-fields-text-domain' )
)
)
)
);Result:
Repeater containing two items (the first item is collapsed and the second item is expanded):

Includes the entire form of an existing widget class.
- class:
stringThe class name of the widget to be included. - hide:
boolWhether or not this widget's form section should start out collapsed or expanded.
Form options input:
$form_options = array(
'some_widget' => array(
'type' => 'widget',
'label' => __( 'Button Widget', 'widget-form-fields-text-domain' ),
'class' => 'SiteOrigin_Widget_Button_Widget',
'hide' => true
)
);Result:
Renders an icon selector field. This allows you to select an icon from a default set of icon families, namely Font Awesome, IcoMoon, Genericons, Typicons, and Elegant Themes' Line Icons. You can include your own icon families with the siteorigin_widgets_icon_families filter.
You can find more detail about using icons here.
Form options input:
$form_options = array(
'some_icon' => array(
'type' => 'icon',
'label' => __('Select an icon', 'widget-form-fields-text-domain'),
)
);Result:
Renders a font selector field. This allows you to select a font from a default set of font families, namely the web safe fonts (Helvetica Neue, Lucida Grande, Georgia, and Courier New ) and a selection of font families from the Google Fonts library. By default this field will use the font specified by the active theme.
You can include your own font families with the siteorigin_widgets_font_families filter. You can find more detail about extending available fonts here.
Form options input:
$form_options = array(
'some_font' => array(
'type' => 'font',
'label' => __('Select a font', 'widget-form-fields-text-domain'),
)
);Result:


















