1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Locations
  5. Customizer Options

Customizer Options

The WordPress Studio Framework (WPSF) can also be used to create settings fields in the WordPress Customizer.

Customizer Options Arguments

NameTypeDefaultDescription of Arguments
databasestringoptionData type for database (option | theme_mod)
transportstringrefreshThis can be either ‘refresh’ (default) or ‘postMessage’. Only set this to ‘postMessage’ if you are writing custom Javascript to control the Theme Customizer’s live preview.
capabilitystringmanage_optionsCapability required for this menu to be displayed to a user
save_defaultsbooltrueFlag to save to default values of the framework
enqueue_webfontbooltrueFlag to load web fonts of the framework
async_webfontboolfalseFlag to load google fonts with async method of the framework
output_cssbooltrueFlag to load output css of the framework
defaultsarray Sets all default values from an external array (optional)
assignstring Assigns the field to an already established Customizer section

Simple Customizer Options Example

//Check to see if the WordPress Studio Framework is loaded
if ( class_exists( 'WPSF' ) ){
  $prefix = 'customizer_options';
  
  //Create customizer options
  WPSF::createCustomizeOptions( $prefix );
  
  //Create a section
  WPSF::createSection( $prefix, array(
    'title' => 'Section Tab One',
    'fields' => array(
      array(
        'id' => 'example-text',
        'type' => 'text',
        'title' => 'Example Text Field',
      ),
    )
  ));
  WPSF::createSection( $prefix, array(
    'assign' => 'title_tagline',
    'fields' => array(
      array(
        'id' => 'tagline-example',
        'type' => 'text',
        'title' => 'Set Site Tagline',
      ),
    )
  ));
  WPSF::createSection( $prefix, array(
    'assign' => 'static_front_page',
    'fields' => array(
      array(
        'id' => 'front-page-example',
        'type' => 'text',
        'title' => 'Example Front Page Text',
      ),
    )
  ));
}

Customizer Options with Tabs Example

if ( class_exists( 'WPSF' ) ){
  $prefix = 'customizer_tabs';
  WPSF::createCustomizeOptions($prefix);
  WPSF::createSection( $prefix, array(
    'id' => 'primary_tab',
    'title' => 'Primary Tab',
  ));
  WPSF::createSection( $prefix, array(
    'parent' => 'primary_tab',
    'title' => 'Sub Tab One',
    'fields' => array(
      array(
        'id' => 'example-text',
        'type' => 'text',
        'title' => 'Example Text Field',
      ),
     )
  ));
  WPSF::createSection( $prefix, array(
    'parent' => 'primary_tab',
    'title' => 'Sub Tab Two',
    'fields' => array(
      array(
        'id' => 'example-textarea',
        'type' => 'textarea',
        'title' => 'Example Textarea',
      ),
    )
  ));
  WPSF::createSection( $prefix, array(
    'id' => 'secondary_tab',
    'title' => 'Secondary Tab',
  ));
  WPSF::createSection( $prefix, array(
    'parent' => 'secondary_tab',
    'title' => 'Sub Tab One',
    'fields' => array(
      array(
        'id' => 'example-switcher',
        'type' => 'switcher',
        'title' => 'Example Switcher',
      ),
    )
  ));
}

Customizer Options Framework with all arguments

if ( class_exists( 'WPSF' ) ){
  $prefix = 'customizer-full';
  WPSF::createCustomizeOptions( $prefix, array(
    'database' => 'option',
    'transport' => 'refresh',
    'capability' => 'manage_options',
    'save_defaults' => true,
    'enqueue_webfont' => true,
    'async_webfont' => false,
    'output_css' => true,
  ));
  WPSF::createSection( $prefix, array(
    'title' => 'Tab Title One',
    'fields' => array(
      array(
        'id' => 'example-text',
        'type' => 'text',
        'title' => 'Example Text',
      ),
    )
  ));
  WPSF::createSection( $prefix, array(
    'title' => 'Tab Title Two',
    'fields' => array(
      array(
        'id' => 'example-textarea',
        'type' => 'textarea',
        'title' => 'Example Textarea',
      ),
    )
  ));
}
Was this article helpful to you? Yes No

How can we help?