The WordPress Studio Framework (WPSF) can also be used to create settings fields in the WordPress Customizer.
Customizer Options Arguments
Name | Type | Default | Description of Arguments |
---|---|---|---|
database | string | option | Data type for database (option | theme_mod) |
transport | string | refresh | This 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. |
capability | string | manage_options | Capability required for this menu to be displayed to a user |
save_defaults | bool | true | Flag to save to default values of the framework |
enqueue_webfont | bool | true | Flag to load web fonts of the framework |
async_webfont | bool | false | Flag to load google fonts with async method of the framework |
output_css | bool | true | Flag to load output css of the framework |
defaults | array | Sets all default values from an external array (optional) | |
assign | string | 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',
),
)
));
}