Skip to content

Instantly share code, notes, and snippets.

@sudipto-me
Last active December 3, 2018 11:48
Show Gist options
  • Save sudipto-me/6a470857b5049cd5b32c84ff5d871e14 to your computer and use it in GitHub Desktop.
Save sudipto-me/6a470857b5049cd5b32c84ff5d871e14 to your computer and use it in GitHub Desktop.
/*
* At first retreive the sidebar list and return it in a array
*/
add_action('admin_init','treeservice_select_sidebar');
function treeservice_select_sidebar() {
$sidebar_list = array();
foreach($GLOBALS['wp_registered_sidebars'] as $sidebar) {
$sidebar_list[$sidebar['id']] = $sidebar['id'];
}
return $sidebar_list;
}
/*
*Shortcode for visual composer component
*/
function display_dynamic_sidebar_shortcode_callback($atts,$content=NULL) {
extract(shortcode_atts( array('select_sidebar'=>'general-sidebar'), $atts));
ob_start();
if(is_active_sidebar( $select_sidebar )) {
dynamic_sidebar($select_sidebar);
}
return ob_get_clean();
}
add_shortcode('display_dynamic_sidebar','display_dynamic_sidebar_shortcode_callback');
/*
*Visual Composer Component
*/
add_action('vc_before_init', 'select_sidebar_component');
function select_sidebar_component() {
$sidebar_list = treeservice_select_sidebar();
vc_map(array(
'name' => __('Select Sidebar'),
'base' => 'display_dynamic_sidebar',
'category' => __('BTS','tree-service'),
'params' => array(
array(
'type' => 'dropdown',
'heading' => __('Select Sidebar'),
'param_name' => 'select_sidebar',
'admin_label' => true,
'value' => $sidebar_list,
'std' => 'general-sidebar',
)),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment