How do I access vc_map() internal values to create custom markup for WPBakery interface?
A similar question has been asked here, without any viable responses: Visual Composer custom markup for custom shortcode (vc_map)
and here: Visual Composer custom shortcode template - custom_markup display user input
I am trying to create custom markup within the WPBakery interface.
I can add custom markup no problem by doing:
$markup = 'test';
vc_map( array(
"name" => __("MyShortcode"),
"base" => "myshortcode",
"category" => __('Content'),
"custom_markup" => $markup, // @TODO how do we access shortcode's attributes here to display in bakery grid
"params" => $params
) );
This will output "test" in the WPBakery grid which is good, but how do I access vc_map() internal values to display?
For instance I have "post types" as a field for this shortcode. If someone selects "page" post type for example, I would like to display those posts within the WPBakery grid. What I cannot figure out is how to get the values that the user selected to display.
Any help would be greatly appreciated. I've searched endlessly on this one.
Solutions
I found a solution. By extending the class WPBakeryShortCode, you could change the contentAdmin output :
// Extend Class WPBakeryShortCodesContainer
if (class_exists('WPBakeryShortCode')) {
class WPBakeryShortCode_Custom_Element extends WPBakeryShortCode {
/**
* @param $atts
* @param $content
*
* @return string
* @throws \Exception
*/
public function contentAdmin( $atts, $content = null ) {
$output = $custom_markup = $width = $el_position = '';
if ( null !== $content ) {
$content = wpautop( stripslashes( $content ) );
}
$shortcode_attributes = array( 'width' => '1/1' );
$atts = vc_map_get_attributes( $this->getShortcode(), $atts ) + $shortcode_attributes;
$this->atts = $atts;
$elem = $this->getElementHolder( $width );
if ( isset( $this->settings['custom_markup'] ) && '' !== $this->settings['custom_markup'] ) {
$markup = $this->settings['custom_markup'];
$elem = str_ireplace( '%wpb_element_content%', $this->customMarkup( $markup, $content ), $elem );
$output .= $elem;
} else {
$inner = $this->outputTitle( $this->settings['name'] );
$inner .= $this->paramsHtmlHolders( $atts );
$elem = str_ireplace( '%wpb_element_content%', $inner, $elem );
$output .= $elem;
}
return $output;
}
}
}
I follow this Git example to create my custom elements : https://gist.github.com/Webcreations907/ff0b068c5c364f63e45d