I working with nested elements wp bakery . i am trying uses classes and public function .
But could not get it working . its not registering . I think its may be an issue because i used class . please find whats wrong with . i dont need a work around . i know how to work it with out member functions. but i need to do it using member functions
<?php
/*
* Element Description: Featured Block
*/
//featured block container
if ( class_exists( 'WPBakeryShortCodesContainer' ) ) {
class protechsaasFeaturedBlock extends WPBakeryShortCodesContainer {
// Element Init
function __construct() {
add_action( 'init', array( $this, 'protechsaas_featured_block_mapping' ) );
add_shortcode( 'feature_container', array( $this, 'protechsaas_featured_block_html' ) );
}
// Element Mapping
public function protechsaas_featured_block_mapping() {
// Stop all if VC is not enabled
if ( !defined( 'WPB_VC_VERSION' ) ) {
return;
}
//Register "container" content element. It will hold all your inner (child) content elements
vc_map( array(
"name" => __("Feature Block", "protechsaas"),
"base" => "feature_container",
"as_parent" => array('only' => 'feature'), // Use only|except attributes to limit child shortcodes (separate multiple values with comma)
"content_element" => true,
"show_settings_on_create" => false,
"is_container" => true,
"params" => array(
// add params same as with any other content element
array(
"type" => "textfield",
"heading" => __("Block Title", "protechsaas"),
'holder' => 'h2',
'class' => 'sub-title-class',
"param_name" => "subtitle",
"description" => __("add the title for your features block", "protechsaas")
),
array(
"type" => "textfield",
"heading" => __("Title", "protechsaas"),
'holder' => 'h2',
'class' => 'title-class',
"param_name" => "title",
"description" => __("add the main title for your features block", "protechsaas")
),
array(
"type" => "textarea",
"heading" => __("Content", "protechsaas"),
'holder' => 'p',
'class' => 'content-class',
"param_name" => "content",
"description" => __("add the main content for your features block", "protechsaas")
),
array(
'type' => 'dropdown',
'holder' => 'div',
'class' => 'style-class',
'heading' => __( 'Block Style', 'protechsaas' ),
'param_name' => 'blockstyle',
'value' => array(
'1' => 'Feature white bg ',
'2' => 'Feature grey bg',
'3' => 'Feature icon bg none ',
),
'description' => __( 'choose you features block style', 'protechsaas' ),
'admin_label' => true,
'weight' => 0,
),
),
"js_view" => 'VcColumnView'
) );
}
// Element HTML
public function protechsaas_featured_block_html( $atts ,$features = null ) {
// Params extraction
extract(
shortcode_atts(
array(
'subtitle' => '',
'title' => '',
'content' => '',
'blockstyle' => '',
),
$atts
)
);
switch ($blockstyle) {
case '1':
$html = '
<section class="client-speak our-features padding-lg">
<div class="container">
<div class="row justify-content-center head-block">
<div class="col-md-10"> <span>'.$subtitle.'</span>
<h2>'.$title.'</h2>
<p class="hidden-xs">'.$content.'</p>
</div>
</div>
<ul class="row features-listing">
'.do_shortcode($features).'
</ul>
</div>
</section>';
break;
case '2':
$html = '
<section class="client-speak our-features padding-lg bg-white">
<div class="container">
<div class="row justify-content-center head-block">
<div class="col-md-10"> <span>'.$subtitle.'</span>
<h2>'.$title.'</h2>
<p class="hidden-xs">'.$content.'</p>
</div>
</div>
<ul class="row features-listing ico-bg">
'.do_shortcode($features).'
</ul>
</div>
</section>';
break;
case '3':
$html = '
<section class="client-speak our-features padding-lg">
<div class="container">
<div class="row justify-content-center head-block">
<div class="col-md-10"> <span>'.$subtitle.'</span>
<h2>'.$title.'</h2>
<p class="hidden-xs">'.$content.'</p>
</div>
</div>
<ul class="row features-listing bg-none">
'.do_shortcode($features).'
</ul>
</div>
</section> ';
break;
default:
$html = '
<section class="client-speak our-features padding-lg">
<div class="container">
<div class="row justify-content-center head-block">
<div class="col-md-10"> <span>'.$subtitle.'</span>
<h2>'.$title.'</h2>
<p class="hidden-xs">'.$content.'</p>
</div>
</div>
<ul class="row features-listing">
'.do_shortcode($features).'
</ul>
</div>
</section>';
break;
}
return $html;
}
}
}
//feature element
if ( class_exists( 'WPBakeryShortCode' ) ) {
class protechsaasFeature extends WPBakeryShortCode {
// Element Init
function __construct() {
add_action( 'init', array( $this, 'protechsaas_feature_mapping' ) );
add_shortcode( 'protechsaas_feature', array( $this, 'protechsaas_feature_html' ) );
}
// Element Mapping
public function protechsaas_feature_mapping() {
// Stop all if VC is not enabled
if ( !defined( 'WPB_VC_VERSION' ) ) {
return;
}
vc_map( array(
"name" => __("Feature", "protechsaas"),
"base" => "feature",
"content_element" => true,
"as_child" => array('only' => 'feature_container'), // Use only|except attributes to limit parent (separate multiple values with comma)
"params" => array(
// add params same as with any other content element
array(
"type" => "textfield",
"heading" => __("title", "protechsaas"),
"param_name" => "title",
"description" => __("add the title for your feature.", "protechsaas")
),
array(
"type" => "textarea",
"heading" => __("Content", "protechsaas"),
'holder' => 'p',
'class' => 'content-class',
"param_name" => "content",
"description" => __("add the content for your feature", "protechsaas")
),
array(
'type' => 'attach_image',
'holder'=> 'div',
'class' => '',
'heading' => __('Icon image', 'protechsaas'),
'param_name' => 'iconimage',
'description' => __('Choose an image for icon if ypu want use your own icons else keep it blank and choose icon from next field', 'protechsaas'),
),
array(
'type' => 'dropdown',
'holder' => 'div',
'class' => 'style-class',
'heading' => __( 'Saas Icons', 'protechsaas' ),
'param_name' => 'icon',
'value' => array(
'icon-analytics' => 'analytics ',
'icon-responsive' => 'responsive',
'icon-support' => 'support',
'icon-settings' => 'settings',
'icon-file' => 'file',
'icon-graphic' => 'graphic',
),
'description' => __( 'choose you features block style', 'protechsaas' ),
'admin_label' => true,
'weight' => 0,
),
)
) );
}
// Element HTML
public function protechsaas_feature_html( $atts ) {
// Params extraction
extract(
shortcode_atts(
array(
'iconimage' => '',
'title' => '',
'content' => '',
'icon' => '',
),
$atts
)
);
if($iconimage != null){
$bg=wp_get_attachment_image_src($iconimage,'full');
$iconcontent = '<img src="'.$bg[0].'" alt="icon" class="img-fluid"/>';
}
else {
$iconcontent ='<span class="'.$icon.'"></span>';
}
$html='
<li class="col-md-4">
<div class="inner"> <span class="icon">'.$iconcontent.'</span>
<h3>'.$title.'</h3>
<p>'.$content.'</p>
</div>
</li>
';
return $html;
}
}
}
// Element Class Init
new protechsaasFeaturedBlock();
new protechsaasFeature();
?>