The WordPress Studio Framework (WPSF) can also be used to create widgets that can be used in a WordPress site.
Widget Options Arguments
Name | Type | Default | Description |
---|---|---|---|
title | string | Title of the widget in the backend | |
description | string | Description of widget in the backend | |
classname | string | CSS classes (space separated) to append to the front-end widget display. | |
width | number | 250 | Width of the fully expanded control form |
defaults | array | Sets all default values from an external array (optional) | |
class | string | Extra CSS classes (space separated) to append to the main framework. |
Widget Options Framework Example
// Check to see if the WPSF class is loaded
if ( class_exists( 'WPSF' ) ){
//Create a Widget
WPSF::createWidget( 'custom_widget_example', array(
'title' => 'Example Widget',
'classname' => 'custom-widget-classname',
'description' => 'A description for the Example Widget',
'fields' => array(
array(
'id' => 'title',
'type' => 'text',
'title' => 'Title',
),
array(
'id' => 'example-text',
'type' => 'text',
'title' => 'Example Text',
'default' => 'Default Text in the Field',
),
array(
'id' => 'example-switcher',
'type' => 'switcher',
'title' => 'Example Switcher',
),
array(
'id' => 'example-textarea',
'type' => 'textarea',
'title' => 'Example Textarea',
'help' => 'The help text of the field.',
),
)
));
// Frontend display of the example widget
if ( ! function_exists( 'custom_widget_example' ) ){
function custom_widget_example( $args, $instance ){
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ){
echo $args['before_title'] . apply_filters('widget_title', $instance['title'] ) . $args['after_title'];
}
//var_dump($args); // Widget Arguments
//var_dump($instance); // Saved values from database
echo $instance['title'];
echo $instance['example-text'];
echo $instance['example-switcher'];
echo $instance['example-textarea'];
echo $args['after_widget'];
}
}
}