Options: Adding shortcode or widget options - dotherightthing/wpdtrt-plugin-boilerplate GitHub Wiki
Summary
DTRT WordPress Plugin Boilerplate supports user-configurable shortcodes and widgets.
Status
- Stable @ 1.6.9
- Needs further documentation and testing re passing values to template, and overriding templates
Usage
Register an option
The option array describes an input field which will be used to set a value within a widget in WordPress admin, or when authoring a shortcode in the WordPress editor / in a PHP file.
Input field types are self-documented in ./views/form-element-*.php.
The default
value is used if the option is not included in the shortcode, e.g.:
// with option.
[wpdtrt_map_shortcode enlargement_link_text="View bigger map"]
// without option.
[wpdtrt_map_shortcode]
Example from ./wpdtrt-map.php
$instance_options = array(
...
'enlargement_link_text' => array(
'type' => 'text',
'size' => 30,
'label' => __('Enlargement link text', 'wpdtrt-map'),
'tip' => __('e.g. View larger map', 'wpdtrt-map'),
'default' => __('View on Google Maps', 'wpdtrt-map'),
)
);
Make the option available within a shortcode
The relevant $instance_options
must be selected by using the $selected_instance_options
array.
Example from ./wpdtrt-map.php
function wpdtrt_map_shortcode_init() {
global $wpdtrt_map_plugin;
$wpdtrt_map_shortcode = new DoTheRightThing\WPPlugin\Shortcode(
array(
...
'selected_instance_options' => array(
...
'enlargement_link_text',
...
)
)
);
}
Make the option available within a widget
TODO