I've built a Wordpress plugin, and now I want to add support for Visual Composer but I can't get it to work. I've read a lot of articles about how to use vc_map, found pages on github with examples, and it seems like I do everything like described in these articles. However my shortcodes still don't show up in the VC editor.
My shortcode (it works perfectly as a shortcode, [mappy id="123"]
will show the map with the ID of 123)
add_shortcode('mappy', 'mappy_shortcode');
function mappy_shortcode($atts) {
// Attribute defaults
extract(shortcode_atts(array(
'id' => null,
), $atts));
// Check if id is set, and the given post is a mappy_map
if(!isset($atts['id'])) {
return '';
}
$post = get_post(intval($atts['id']));
if(!isset($post)) {
return;
}
if($post->post_type != 'mappy_map') {
return;
}
return $post->post_content;
}
And the code I've tried:
/**
* Visual Composer Support
*/
if(defined('WPB_VC_VERSION')) {
add_action('vc_before_init', 'mappy_vc_support');
}
function mappy_vc_support() {
vc_map(
array(
'base' => 'mappy',
'description' => __('Display a Mappy map.', 'mappy'),
'category' => 'Mappy',
'icon' => plugin_dir_url(__FILE__) . 'img/vc_map_32.png',
'class' => '',
'weight' => 100,
'params' => array(
array(
'type' => 'dropdown',
'class' => '',
'heading' => __('Térkép', 'mappy'),
'param_name' => 'id',
'value' => mappy_map_list(),
'description' => __('Térkép', 'mappy'),
'holder' => 'div'
)
)
)
);
}
/**
* Helper function to get all mappy_map posts
*/
function mappy_map_list() {
$list = array();
$posts = get_posts(array('post_type' => 'mappy_map'));
foreach($posts as $post) {
$list[$post->post_title] = $post->ID;
}
return $list;
}
I've also tried to hook mappy_vc_support
into init
and admin_init
, with no luck.
Also note that the function vc_map
itself is being called, and returns 1
.
What could be the problem here?