Created
August 9, 2017 07:17
-
-
Save rajendra89/50359da4662562dec9bab30b84d6623c to your computer and use it in GitHub Desktop.
replace your my-first-custom-element.php with code below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
replace your my-first-custom-element.php with code below. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Element Description: VC Info Box | |
*/ | |
// Element Class | |
class vcInfoBox extends WPBakeryShortCode { | |
//Element Init | |
function __construct(){ | |
add_action( 'init', array( $this, 'vc_infobox_mapping' ) ); | |
add_shortcode( 'vc_infobox', array( $this, 'vc_infobox_html' ) ); | |
} | |
//Element Mapping | |
public function vc_infobox_mapping(){ | |
//stop all if VC is not enabled | |
if ( !defined( 'WPB_VC_VERSION' ) ){ | |
return; | |
} | |
// Map the block of VC_map | |
vc_map( | |
array( | |
'name' => __('VC_INFOBOX', 'text-domain'), | |
'base' => 'vc_infobox', | |
'description' => __('Infobox custom element', 'textdomain'), | |
'category' => __('Custom Element', 'text-domain'), //to create custom tab "Custom element" | |
//'icon' => get_template_directory().'/vc-extend/puzzle.png', | |
'icon' => 'Textbox', | |
'params' => array( | |
array( | |
'type'=>'textfield', | |
'holder' => 'h3', | |
'class' => 'title-class', | |
'heading' => __('Title', 'text-domain'), | |
'param_name' => 'title', | |
'value' => __( 'Default value', 'text-domain'), | |
'description' => __('Box Title', 'text-domain'), | |
'admin_level' => false, | |
'weight' => 0, | |
'group' => 'custom group', | |
), | |
array( | |
'type' => 'textarea', | |
'holder'=> 'div', | |
'class' => 'text-class', | |
'heading' => __('Text', 'text-domain'), | |
'param_name' => 'text', | |
'value' => __( 'Default Value', 'text-domain'), | |
'description' => __('Box Text', 'text-domain'), | |
'admin_level' => false, | |
'wight' => 0, | |
'group' => 'custom group', | |
), | |
array( | |
'type' => 'attach_image', | |
'holder'=> 'div', | |
'class' => '', | |
'heading' => __('Thumbnail', 'text-domain'), | |
'param_name' => 'image', | |
'value' => __( 'Default Value', 'text-domain'), | |
'description' => __('Box Image', 'text-domain'), | |
'admin_level' => false, | |
'wight' => 0, | |
'group' => 'custom group', | |
), | |
array( | |
'type' => 'vc_link', | |
'holder'=> 'div', | |
'class' => '', | |
'heading' => __('Link', 'text-domain'), | |
'param_name' => 'link', | |
'value' => __( 'Default Value', 'text-domain'), | |
'description' => __('Box Link', 'text-domain'), | |
'admin_level' => false, | |
'wight' => 0, | |
'group' => 'custom group', | |
), | |
array( | |
'type' => 'dropdown', | |
'holder'=> 'div', | |
'class' => '', | |
'heading' => __('Dropdown', 'text-domain'), | |
'param_name' => 'dropdown', | |
'value' => array( | |
__( 'Ram', "my-text-domain" ) => 'option1value', | |
__( 'Shyam', "my-text-domain" ) => 'option2value', | |
__( 'Gita', "my-text-domain" ) => 'option3value', | |
), | |
'description' => __('Box Dropdown', 'text-domain'), | |
'admin_level' => false, | |
'wight' => 0, | |
'group' => 'custom group', | |
), | |
) | |
) | |
); | |
} | |
//Element HTML | |
public function vc_infobox_html($atts){ | |
//params extraction | |
extract( | |
shortcode_atts( | |
array( | |
'title' => '', | |
'text' => '', | |
'image' => '', | |
'link' => '', | |
'dropdown' => '', | |
), | |
$atts | |
) | |
); | |
//Fill $html var with data | |
$html=' | |
<div class="vc-infobox-wrap"> | |
<h2 class="vc-infobox-title">' . $title . '</h2> | |
<div class="vc-infobox-text">' . $text . '</div> | |
<div class="vc-infobox-link">' . $link . '</div> | |
</div> | |
' | |
; | |
return $html; | |
} | |
}//End element class | |
new vcInfoBox(); | |
?> | |
<div><img src=""> </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment