Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Visual Composer Info Boxes
- Plugin URI: http://milardovich.com.ar
- Description: Home-made info boxes for Visual Composer
- Version: 0.1
- Author: Sergio Milardovich
- Author URI: http://milardovich.com.ar
- 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 VCInfoBoxAddonClass {
- 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( 'vc_infoboxes', array( $this, 'renderInfoBoxes' ) );
- // 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" => __("Simple Info Box", 'vc_extend'),
- "description" => __("A simple info box", 'vc_extend'),
- "base" => "vc_infoboxes",
- "class" => "",
- "controls" => "full",
- "icon" => plugins_url('assets/icons/info.png', __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" => "colorpicker",
- "holder" => "div",
- "class" => "",
- "heading" => __("Wrapper Background", 'vc_extend'),
- "param_name" => "wrapper_background",
- "value" => '#D0A9A9',
- "description" => __("Choose wrapper background", 'vc_extend')
- ),
- array(
- "type" => "colorpicker",
- "holder" => "div",
- "class" => "",
- "heading" => __("Title Color", 'vc_extend'),
- "param_name" => "title_color",
- "value" => '#ffffff',
- "description" => __("Choose title color", 'vc_extend')
- ),
- array(
- "type" => "textfield",
- "holder" => "div",
- "class" => "",
- "heading" => __("Title", 'vc_extend'),
- "param_name" => "title",
- "value" => __("Default Title", 'vc_extend'),
- "description" => __("Box title", 'vc_extend')
- ),
- array(
- "type" => "colorpicker",
- "holder" => "div",
- "class" => "",
- "heading" => __("Text Color", 'vc_extend'),
- "param_name" => "text_color",
- "value" => '#ffffff',
- "description" => __("Choose text color", 'vc_extend')
- ),
- array(
- "type" => "textarea_html",
- "holder" => "div",
- "class" => "",
- "heading" => __("Box text", 'vc_extend'),
- "param_name" => "text",
- "value" => __("Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.", 'vc_extend'),
- "description" => __("Enter your content.", 'vc_extend')
- ),
- array(
- "type" => "colorpicker",
- "holder" => "div",
- "class" => "",
- "heading" => __("Button Background", 'vc_extend'),
- "param_name" => "button_background",
- "value" => '#B23535',
- "description" => __("Choose button background", 'vc_extend')
- ),
- array(
- "type" => "colorpicker",
- "holder" => "div",
- "class" => "",
- "heading" => __("Button Border", 'vc_extend'),
- "param_name" => "button_border",
- "value" => '#B23535',
- "description" => __("Choose button border color", 'vc_extend')
- ),
- array(
- "type" => "iconpicker",
- "holder" => "div",
- "class" => "",
- "heading" => __("Button Icon", 'vc_extend'),
- "param_name" => "button_icon",
- "value" => 'fa-bell',
- "description" => __("Choose button icon", 'vc_extend')
- ),
- array(
- "type" => "textfield",
- "holder" => "div",
- "class" => "",
- "heading" => __("Button Text", 'vc_extend'),
- "param_name" => "button_text",
- "value" => __("View More", 'vc_extend'),
- "description" => __("Button text", 'vc_extend')
- ),
- )
- ) );
- }
- /*
- Shortcode logic how it should be rendered
- */
- public function renderInfoBoxes( $atts, $content = null ) {
- extract( shortcode_atts( array(
- 'wrapper_background' => '#D0A9A9',
- 'title_color' => '#ffffff',
- 'text_color' => '#ffffff',
- 'text' => 'Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.',
- 'title' => 'Advanced Business Solution',
- 'button_icon' => 'fa-bell',
- 'button_text' => 'View More',
- 'button_background' => '#B23535',
- 'button_border' => '#B23535',
- 'button_color' => '#ffffff',
- 'button_link' => '#'
- ), $atts ) );
- $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
- $output = '
- <div style="background:'.$wrapper_background.';padding:5px;margin-bottom:5px;margin-top:5px;">
- <div style="margin-top: 17px;margin-bottom: 0px;" class="separator transparent center "></div>
- <div class="wpb_text_column wpb_content_element ">
- <div class="wpb_wrapper">
- <h3 style="text-align:center;color:'.$title_color.';">'.$title.'</h3>
- </div>
- </div>
- <div style="margin-top: 10px;margin-bottom: 0px;" class="separator transparent center "></div>
- <div class="wpb_text_column wpb_content_element ">
- <div class="wpb_wrapper" style="color:'.$text_color.';padding:5px;">
- '.$text.'
- </div>
- </div>
- <div style="margin-top: 12px;margin-bottom: 0px;" class="separator transparent center "></div>
- <center><a style="border-radius:0;background:'.$button_background.';border:'.$button_border.' 1px;color:'.$button_color.';" class="qbutton " target="_self" href="'.$button_link.'"><i class="fa '.$button_icon.'"></i> '.$button_text.'</a></center>
- </div>';
- 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 VCInfoBoxAddonClass();
- class VCPostsAddonClass {
- 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( 'vc_postlists', array( $this, 'renderPosts' ) );
- // 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" => __("Show Posts", 'vc_extend'),
- "description" => __("Show posts list", 'vc_extend'),
- "base" => "vc_postlists",
- "class" => "",
- "controls" => "full",
- "icon" => plugins_url('assets/icons/info.png', __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" => "textfield",
- "holder" => "div",
- "class" => "",
- "heading" => __("Category", 'vc_extend'),
- "param_name" => "category",
- "value" => '1',
- "description" => __("Category", 'vc_extend')
- ),
- array(
- "type" => "textfield",
- "holder" => "div",
- "class" => "",
- "heading" => __("Count", 'vc_extend'),
- "param_name" => "count",
- "value" => __("3", 'vc_extend'),
- "description" => __("Posts", 'vc_extend')
- ),
- array(
- "type" => "textfield",
- "holder" => "div",
- "class" => "",
- "heading" => __("Offset", 'vc_extend'),
- "param_name" => "offset",
- "value" => __("0", 'vc_extend'),
- "description" => __("Offsets", 'vc_extend')
- )
- )
- ) );
- }
- /*
- Shortcode logic how it should be rendered
- */
- public function renderPosts( $atts, $content = null ) {
- extract( shortcode_atts( array(
- 'category' => '1',
- 'limit' => '3',
- 'offset' => '0'
- ), $atts ) );
- $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
- $args = array(
- 'posts_per_page' => $limit,
- 'offset' => $offset,
- 'category' => $category
- );
- $posts = get_posts($args);
- $output = '';
- foreach($posts as $post){
- setup_postdata( $post );
- $output .= '<a href="'.get_the_permalink().'">'.get_the_title().'</a> - <span class="post-date">'.get_the_date().'</span><br/>'.get_the_excerpt().'<hr/>';
- }
- 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 VCPostsAddonClass();
Advertisement
Add Comment
Please, Sign In to add comment