-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvc_extend.php
156 lines (137 loc) · 5.99 KB
/
vc_extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/*
Plugin Name: VC Text Block Plus
Plugin URI: http://wpbakery.com/vc
Description: Extend Visual Composer with your own set of shortcodes.
Version: 0.1.1
Author: WPBakery
Author URI: http://wpbakery.com
License: GPLv2 or later
*/
/*
This example/starter plugin can be used to speed up Visual Composer plugins creation process.
More information can be found here: http://kb.wpbakery.com/index.php?title=Category:Visual_Composer
*/
// don't load directly
if (!defined('ABSPATH')) die('-1');
class VCExtendAddonClass {
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( 'text_plus', array( $this, 'renderMyBartag' ) );
// 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;
}
/*
Add your Visual Composer logic here.
Lets call vc_map function to "register" our custom shortcode within Visual Composer interface.
More info: http://kb.wpbakery.com/index.php?title=Vc_map
*/
vc_map( array(
"name" => __("Text Block Plus", 'vc_extend'),
"description" => __("", 'vc_extend'),
"base" => "text_plus",
"class" => "",
"controls" => "full",
"icon" => plugins_url('assets/plus.jpg', __FILE__), // or css class name which you can reffer in your css file later. Example: "vc_extend_my_class"
"category" => __('Content', 'js_composer'),
//'admin_enqueue_js' => array(plugins_url('assets/vc_extend.js', __FILE__)), // This will load js file in the VC backend editor
'admin_enqueue_css' => array(plugins_url('assets/vc_extend_admin.css', __FILE__)), // This will load css file in the VC backend editor
"params" => array(
array(
"type" => "textarea_html",
"holder" => "div",
"class" => "",
"heading" => __("Content", 'vc_extend'),
"param_name" => "content",
"value" => __("<p>I am test text block. Click edit button to change this text.</p>", 'vc_extend'),
"description" => __("Enter your content.", 'vc_extend')
),
/* array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Text", 'vc_extend'),
"param_name" => "foo",
"value" => __("Default params value", 'vc_extend'),
"description" => __("Description for foo param.", 'vc_extend')
),
*
*
*/
array(
"type" => "colorpicker",
"holder" => "div",
"class" => "",
"heading" => __("Text color", 'vc_extend'),
"param_name" => "color",
"value" => '#FF0000', //Default Red color
"description" => __("Choose text color", 'vc_extend')
),
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Font Size", 'vc_extend'),
"param_name" => "fsize",
"value" => '24px',
"description" => __("eg. 24px, 2em", 'vc_extend')
),
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Line Height", 'vc_extend'),
"param_name" => "lheight",
"value" => '1',
"description" => __("eg. 2, 20px", 'vc_extend')
),
)
) );
}
/*
Shortcode logic how it should be rendered
*/
public function renderMyBartag( $atts, $content = null ) {
extract( shortcode_atts( array(
'foo' => 'something',
'color' => '#FF0000',
'fsize' => '24px',
'lheight' => '1'
), $atts ) );
$content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
$content = strip_tags($content, "<p><a><span><b><i>");
$output = "<div class='text_plus_wrap' style='color:{$color}; font-size:{$fsize}; line-height:{$lheight}' data-foo='${foo}'>{$content}</div>";
/* $output .= "<style>.text_plus_wrap p{ color:inherit; font-size:inherit; line-height:inherit }</style>"; */
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(__('<strong>%s</strong> requires <strong><a href="http://bit.ly/vcomposer" target="_blank">Visual Composer</a></strong> plugin to be installed and activated on your site.', 'vc_extend'), $plugin_data['Name']).'</p>
</div>';
}
}
// Finally initialize code
new VCExtendAddonClass();