<?php
class VCExtendAddonClass_2{
function __construct() {
// We safely integrate with VC with this hook
add_action( 'init', array( $this, 'integrateWithVC' ) );
// Use this when creating a shortcode addon
add_shortcode( 'demoShortcode', array( $this, 'renderDemoFunction' ) );
// Register CSS and JS
add_action( 'wp_enqueue_scripts', array( $this, 'loadCssAndJs' ) );
}
public function integrateWithVC() {
// Check if Visual Composer is installed
if ( ! defined( 'WPB_VC_VERSION' ) ) {
// Display notice that Visual Compser is required
add_action('admin_notices', array( $this, 'showVcVersionNotice' ));
return;
}
//call the field array.
vc_map( array(
"name" => __("HeyCodeTech - demo field", 'vc_extend'),
"description" => __("Listing of all the demo fields.", 'vc_extend'),
"base" => "demoShortcode",
"class" => "class",
"controls" => "full",
//"icon" => plugins_url('assets/asterisk_yellow.png', __FILE__), // or css class name which you can reffer in your css file later. Example: "vc_extend_my_class"
"category" => __('Content', 'js_composer'),
"params" => array(
array(
"type" => "textarea_html",
"holder" => "div",
"class" => "",
"heading" => __("Text", 'vc_extend'),
"param_name" => "textfieldname1",
"value" => __("demo Value", 'vc_extend'),
"description" => __("Title", 'vc_extend')
),
array(
"type" => "checkbox",
"heading" => __("Select category"),
"param_name" => "selectboxname",
"admin_label" => true,
"value" => array(
'First Option'=>'first',
'Second Option'=>'second',
'Third Option'=>'third',
'Fourth Option'=>'fourth'
), //value
"std" => " ",
"description" => __("display all the posts.")
),
)
) );
}
/*
Shortcode logic how it should be rendered
*/
public function renderDemoFunction( $atts, $content = null ) {
extract( shortcode_atts( array(
'textfieldname1'=> '',
'selectnoxname'=>''
), $atts ) );
//print_r($atts);
$textfield = $atts['textfieldname1'];
$selectboxfield = $atts['selectboxname'];
// ob_get_clean();
//create buffer string
ob_start();
?>
<div class="heycodetech-container container">
<div class="list-value">
<p>TextField Value = <?php echo $textfield; ?></p>
<p>Selected checkbox = <?php echo $selectboxfield; ?></p>
</div>
</div>
<?php
$output = ob_get_contents();
ob_get_clean();
return $output;
}
/*
Load plugin css and javascript files which you may need on front end of your site
*/
public function loadCssAndJs() {
wp_register_style( 'vc_extend_style', plugins_url('assets/vc_extend.css', __FILE__) ); wp_enqueue_style( 'vc_extend_style' );
// If you need any javascript files on front end, here is how you can load them.
wp_enqueue_script( 'vc_extend_js', plugins_url('assets/vc_extend.js', __FILE__), array('jquery') );
}
/*
Show notice if your plugin is activated but Visual Composer is not
*/
public function showVcVersionNotice() {
$plugin_data = get_plugin_data(__FILE__);
echo '
<div class="updated">
<p>'.sprintf(__('Notice of visual composer', 'vc_extend'), $plugin_data['Name']).'</p>
</div>';
}
}
// Finally initialize code
new VCExtendAddonClass_2();
?>