Class Name:
MP_CORE_Shortcode_Insert
Purpose:
This class is used to easily create “shortcode-builders” which assemble the pieces of a shortcode for the user and insert it into the content area.
Overview:
Using an associative array passed to the MP_CORE_Shortcode_Insert class, a custom “shortcode-builder” can be built for any shortcode.
Usage:
new MP_CORE_Shortcode_Insert($args);
Parameters:
$args (array)
Sample Code:
/** * Show "Insert Shortcode" above posts */ function my_shortcode(){ $args = array( 'shortcode_id' => 'my_shortcode', 'shortcode_title' => __('My Shortcode', 'textdomain'), 'shortcode_description' => __( 'Shortcode Description', 'textdomain' ), 'shortcode_options' => array( array( 'option_id' => 'first_shortcode_var', 'option_title' => 'My Dropdown', 'option_description' => 'Choose something:', 'option_type' => 'select', 'option_value' => array( 'value1' => "Option 1", 'value2' => "Option 2" ), ), array( 'option_id' => 'second_shortcode_var', 'option_title' => 'My Checkbox', 'option_description' => 'Do you want to check this?', 'option_type' => 'checkbox', 'option_value' => NULL, ), ) ); new MP_CORE_Shortcode_Insert($args); } add_action('init', 'my_shortcode');
This will create a form which the user fills out and then click “Insert”.
The resulting shortcode from the above example would be:
[my_shortcode first_shortcode_var=value1 second_shortcode_var=true]
Shortcode Field Types:
These are the types of fields that are available for the “option_type” setting:
- basictext
- textbox
- password
- checkbox
- url
- date
- number
- textarea
- select* – Select fields require the ‘option_value’ parameter in the array as seen in the example code above. It stores an array of options:
'option_value' => array( 'value1' => "Option 1", 'value2' => "Option 2" ),
- colorpicker
- mediaupload