forked from jo-snips/vc-content-block
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vc_content_block.php
157 lines (144 loc) · 5.75 KB
/
vc_content_block.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
157
<?php
/*
Plugin Name: Content Blocks For Visual Composer
Plugin URI: http://wpbakery.com/vc
Description: Use Content Blocks in The Visual Composer
Version: 1.0
Author: Jonah Coyote Design
Author URI: http://jonahcoyote.com
License: GPLv2 or later
*/
// don't load directly
if (!defined('ABSPATH')) die('-1');
class VCContentBlockAddonClass {
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( 'custom_content_block', array( $this, 'render_content_block' ) );
}
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
*/
$blocks = get_posts( 'post_type="content_block"&numberposts=-1' );
$blocks_array = array();
if ( $blocks ) {
foreach ($blocks as $block) {
$blocks_array[$block->post_title] = $block->ID;
}
} else {
$blocks_array["No content blocks found"] = 0;
}
vc_map(array(
"name" => __("Content Block", "mk_framework"),
"base" => "custom_content_block",
'icon' => 'icon-mk-content-box vc_mk_element-icon',
"category" => __('Custom', 'mk_framework'),
"params" => array(
array(
"type" => "dropdown",
"heading" => __("Content Block", "mk_framework"),
"param_name" => "id",
'save_always' => true,
"admin_label" => true,
"value" => $blocks_array,
"description" => __("Choose previously created Content Blocks from the drop down list.", "mk_framework")
),
array(
"type" => "range",
"heading" => __("Padding Top", "mk_framework") ,
"param_name" => "margin_top",
"value" => "0",
"min" => "0",
"max" => "500",
"step" => "1",
"unit" => 'px',
"description" => __("", "mk_framework")
) ,
array(
"type" => "range",
"heading" => __("Padding Bottom", "mk_framework") ,
"param_name" => "margin_bottom",
"value" => "20",
"min" => "0",
"max" => "500",
"step" => "1",
"unit" => 'px',
"description" => __("", "mk_framework")
),
array(
"type" => "textfield",
"heading" => __("Extra class name", "mk_framework"),
"param_name" => "el_class",
"value" => "",
"description" => __("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in Custom CSS Shortcode or Masterkey Custom CSS option.", "mk_framework")
),
array(
"type" => "hidden_input",
"param_name" => "cb_class",
"value" => "",
"description" => __("", "mk_framework")
)
)
));
}
/*
Shortcode logic how it should be rendered
*/
public function render_content_block( $atts ) {
extract( shortcode_atts( array(
'title' => '',
'id' => '',
'margin_top' => '0',
'margin_bottom' => '20',
'cb_class' => '',
'el_class' => ''
), $atts ) );
//echo $id;
$post = get_post($id);
$cb_class = $post->post_name;
$styles = '
<style>
#custom_post_widget-'.$id.' {
padding-top:'.$margin_top.'px;
padding-bottom:'.$margin_bottom.'px;
}
</style>
';
$output = '';
$output .= $styles;
$output .= wpb_widget_title( array('title' => $title, 'extraclass' => 'wpb_content_block_heading') );
$output .= apply_filters( 'vc_content_block_shortcode', do_shortcode( '[content_block id=' . $id . ' class="content_block ' . $el_class . ' ' . $cb_class .'"]' ) );
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_content-block.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 VCContentBlockAddonClass();