1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Fields
  5. Switcher Field

Switcher Field

Arguments

NameTypeDefaultDescription
idstring A unique ID. This ID will be used to get the value
typestringswitcherType of field
titlestring Title of the field
defaultstring Default value from database, if the option doesn’t exist
subtitlestring Subtitle to display below the title
descstring Description to display after the field
helpstring Text to display on right-corner (as hover/popup) the field
classstring Extra CSS classes (space separated) to append to the field
beforestring Content to display before the field
afterstring Content to display after the field
dependencyarray Define field visibility depending on other field value
attributesarray Extra HTML attributes to append to the field
sanitizestring Callback function for sanitizing value
validatestring Callback function for validating value
EXTRAS   
text_onstringONText to display on the “ON” label
text_offstringOFFText to display on the “OFF” label
text_widthnumber60The width of the switcher
labelstring The text to display along with the switcher

Simple Switcher Field Example

array(
  'id' => 'example-switcher',
  'type' => 'switcher',
  'title' => 'Example Switcher',
),

Switcher Field Example with Label

array(
  'id' => 'example-switcher',
  'type' => 'switcher',
  'title' => 'Example Switcher',
  'label' => 'Do you want to activate the switch?',
  'default' => true,
),

Switcher Field Example with Dependency

array(
  'id' => 'example-switcher',
  'type' => 'switcher',
  'title' => 'Example Switcher',
  'default' => true,
),

//Text field dependent of the above switcher
array(
  'id' => 'example-text',
  'type' => 'text',
  'title' => 'Text',
  'dependency' => array('example-switcher', '==', 'true'),
),

Switcher Field Example with Custom Text

array(
  'id' => 'example-switcher',
  'type' => 'switcher',
  'title' => 'Switcher with Yes/No',
  'text_on' => 'Yes',
  'text_off' => 'No',
),

array(
  'id' => 'example-switcher-2',
  'type' => 'switcher',
  'title' => 'Switcher with Enabled/Disabled',
  'text_on' => 'Enabled',
  'text_off' => 'Disabled',
  'text_width' => 100,
),
Was this article helpful to you? Yes No

How can we help?