milardovich

Untitled

Sep 10th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.05 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Visual Composer Info Boxes
  4. Plugin URI: http://milardovich.com.ar
  5. Description: Home-made info boxes for Visual Composer
  6. Version: 0.1
  7. Author: Sergio Milardovich
  8. Author URI: http://milardovich.com.ar
  9. License: GPLv2 or later
  10. */
  11.  
  12. /*
  13. This example/starter plugin can be used to speed up Visual Composer plugins creation process.
  14. More information can be found here: http://kb.wpbakery.com/index.php?title=Category:Visual_Composer
  15. */
  16.  
  17. // don't load directly
  18. if (!defined('ABSPATH')) die('-1');
  19.  
  20. class VCInfoBoxAddonClass {
  21.     function __construct() {
  22.         // We safely integrate with VC with this hook
  23.         add_action( 'init', array( $this, 'integrateWithVC' ) );
  24.  
  25.         // Use this when creating a shortcode addon
  26.         add_shortcode( 'vc_infoboxes', array( $this, 'renderInfoBoxes' ) );
  27.  
  28.         // Register CSS and JS
  29.         add_action( 'wp_enqueue_scripts', array( $this, 'loadCssAndJs' ) );
  30.     }
  31.  
  32.     public function integrateWithVC() {
  33.         // Check if Visual Composer is installed
  34.         if ( ! defined( 'WPB_VC_VERSION' ) ) {
  35.             // Display notice that Visual Compser is required
  36.             add_action('admin_notices', array( $this, 'showVcVersionNotice' ));
  37.             return;
  38.         }
  39.  
  40.         /*
  41.         Add your Visual Composer logic here.
  42.         Lets call vc_map function to "register" our custom shortcode within Visual Composer interface.
  43.  
  44.         More info: http://kb.wpbakery.com/index.php?title=Vc_map
  45.         */
  46.         vc_map( array(
  47.             "name" => __("Simple Info Box", 'vc_extend'),
  48.             "description" => __("A simple info box", 'vc_extend'),
  49.             "base" => "vc_infoboxes",
  50.             "class" => "",
  51.             "controls" => "full",
  52.             "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"
  53.             "category" => __('Content', 'js_composer'),
  54.             //'admin_enqueue_js' => array(plugins_url('assets/vc_extend.js', __FILE__)), // This will load js file in the VC backend editor
  55.             //'admin_enqueue_css' => array(plugins_url('assets/vc_extend_admin.css', __FILE__)), // This will load css file in the VC backend editor
  56.             "params" => array(
  57.                 array(
  58.                     "type" => "colorpicker",
  59.                     "holder" => "div",
  60.                     "class" => "",
  61.                     "heading" => __("Wrapper Background", 'vc_extend'),
  62.                     "param_name" => "wrapper_background",
  63.                     "value" => '#D0A9A9',
  64.                     "description" => __("Choose wrapper background", 'vc_extend')
  65.                 ),
  66.                 array(
  67.                     "type" => "colorpicker",
  68.                     "holder" => "div",
  69.                     "class" => "",
  70.                     "heading" => __("Title Color", 'vc_extend'),
  71.                     "param_name" => "title_color",
  72.                     "value" => '#ffffff',
  73.                     "description" => __("Choose title color", 'vc_extend')
  74.                 ),
  75.                 array(
  76.                     "type" => "textfield",
  77.                     "holder" => "div",
  78.                     "class" => "",
  79.                     "heading" => __("Title", 'vc_extend'),
  80.                     "param_name" => "title",
  81.                     "value" => __("Default Title", 'vc_extend'),
  82.                     "description" => __("Box title", 'vc_extend')
  83.                 ),
  84.                 array(
  85.                     "type" => "colorpicker",
  86.                     "holder" => "div",
  87.                     "class" => "",
  88.                     "heading" => __("Text Color", 'vc_extend'),
  89.                     "param_name" => "text_color",
  90.                     "value" => '#ffffff',
  91.                     "description" => __("Choose text color", 'vc_extend')
  92.                 ),
  93.                 array(
  94.                     "type" => "textarea_html",
  95.                     "holder" => "div",
  96.                     "class" => "",
  97.                     "heading" => __("Box text", 'vc_extend'),
  98.                     "param_name" => "text",
  99.                     "value" => __("Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.", 'vc_extend'),
  100.                     "description" => __("Enter your content.", 'vc_extend')
  101.                 ),
  102.                 array(
  103.                     "type" => "colorpicker",
  104.                     "holder" => "div",
  105.                     "class" => "",
  106.                     "heading" => __("Button Background", 'vc_extend'),
  107.                     "param_name" => "button_background",
  108.                     "value" => '#B23535',
  109.                     "description" => __("Choose button background", 'vc_extend')
  110.                 ),
  111.                 array(
  112.                     "type" => "colorpicker",
  113.                     "holder" => "div",
  114.                     "class" => "",
  115.                     "heading" => __("Button Border", 'vc_extend'),
  116.                     "param_name" => "button_border",
  117.                     "value" => '#B23535',
  118.                     "description" => __("Choose button border color", 'vc_extend')
  119.                 ),
  120.                 array(
  121.                     "type" => "iconpicker",
  122.                     "holder" => "div",
  123.                     "class" => "",
  124.                     "heading" => __("Button Icon", 'vc_extend'),
  125.                     "param_name" => "button_icon",
  126.                     "value" => 'fa-bell',
  127.                     "description" => __("Choose button icon", 'vc_extend')
  128.                 ),
  129.                 array(
  130.                     "type" => "textfield",
  131.                     "holder" => "div",
  132.                     "class" => "",
  133.                     "heading" => __("Button Text", 'vc_extend'),
  134.                     "param_name" => "button_text",
  135.                     "value" => __("View More", 'vc_extend'),
  136.                     "description" => __("Button text", 'vc_extend')
  137.                 ),
  138.  
  139.  
  140.  
  141.  
  142.             )
  143.         ) );
  144.     }
  145.  
  146.     /*
  147.     Shortcode logic how it should be rendered
  148.     */
  149.     public function renderInfoBoxes( $atts, $content = null ) {
  150.         extract( shortcode_atts( array(
  151.             'wrapper_background' => '#D0A9A9',
  152.             'title_color' => '#ffffff',
  153.             'text_color' => '#ffffff',
  154.             'text' => 'Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.',
  155.             'title' => 'Advanced Business Solution',
  156.             'button_icon' => 'fa-bell',
  157.             'button_text' => 'View More',
  158.             'button_background' => '#B23535',
  159.             'button_border' => '#B23535',
  160.             'button_color' => '#ffffff',
  161.             'button_link' => '#'
  162.         ), $atts ) );
  163.         $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
  164.         $output = '
  165.                <div style="background:'.$wrapper_background.';padding:5px;margin-bottom:5px;margin-top:5px;">
  166.                    <div style="margin-top: 17px;margin-bottom: 0px;" class="separator  transparent center  "></div>
  167.                    <div class="wpb_text_column wpb_content_element ">
  168.                        <div class="wpb_wrapper">
  169.                            <h3 style="text-align:center;color:'.$title_color.';">'.$title.'</h3>
  170.                        </div>
  171.                    </div>
  172.                    <div style="margin-top: 10px;margin-bottom: 0px;" class="separator  transparent center  "></div>
  173.                    <div class="wpb_text_column wpb_content_element ">
  174.                        <div class="wpb_wrapper" style="color:'.$text_color.';padding:5px;">
  175.                            '.$text.'
  176.                        </div>
  177.                    </div>
  178.                    <div style="margin-top: 12px;margin-bottom: 0px;" class="separator  transparent center  "></div>
  179.                    <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>
  180.                </div>';
  181.         return $output;
  182.     }
  183.  
  184.     /*
  185.     Load plugin css and javascript files which you may need on front end of your site
  186.     */
  187.     public function loadCssAndJs() {
  188.         wp_register_style( 'vc_extend_style', plugins_url('assets/vc_extend.css', __FILE__) );
  189.         wp_enqueue_style( 'vc_extend_style' );
  190.  
  191.         // If you need any javascript files on front end, here is how you can load them.
  192.         //wp_enqueue_script( 'vc_extend_js', plugins_url('assets/vc_extend.js', __FILE__), array('jquery') );
  193.     }
  194.  
  195.     /*
  196.     Show notice if your plugin is activated but Visual Composer is not
  197.     */
  198.     public function showVcVersionNotice() {
  199.         $plugin_data = get_plugin_data(__FILE__);
  200.         echo '
  201.        <div class="updated">
  202.          <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>
  203.        </div>';
  204.     }
  205. }
  206. // Finally initialize code
  207. new VCInfoBoxAddonClass();
  208. class VCPostsAddonClass {
  209.     function __construct() {
  210.         // We safely integrate with VC with this hook
  211.         add_action( 'init', array( $this, 'integrateWithVC' ) );
  212.  
  213.         // Use this when creating a shortcode addon
  214.         add_shortcode( 'vc_postlists', array( $this, 'renderPosts' ) );
  215.  
  216.         // Register CSS and JS
  217.         add_action( 'wp_enqueue_scripts', array( $this, 'loadCssAndJs' ) );
  218.     }
  219.  
  220.     public function integrateWithVC() {
  221.         // Check if Visual Composer is installed
  222.         if ( ! defined( 'WPB_VC_VERSION' ) ) {
  223.             // Display notice that Visual Compser is required
  224.             add_action('admin_notices', array( $this, 'showVcVersionNotice' ));
  225.             return;
  226.         }
  227.  
  228.         /*
  229.         Add your Visual Composer logic here.
  230.         Lets call vc_map function to "register" our custom shortcode within Visual Composer interface.
  231.  
  232.         More info: http://kb.wpbakery.com/index.php?title=Vc_map
  233.         */
  234.         vc_map( array(
  235.             "name" => __("Show Posts", 'vc_extend'),
  236.             "description" => __("Show posts list", 'vc_extend'),
  237.             "base" => "vc_postlists",
  238.             "class" => "",
  239.             "controls" => "full",
  240.             "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"
  241.             "category" => __('Content', 'js_composer'),
  242.             //'admin_enqueue_js' => array(plugins_url('assets/vc_extend.js', __FILE__)), // This will load js file in the VC backend editor
  243.             //'admin_enqueue_css' => array(plugins_url('assets/vc_extend_admin.css', __FILE__)), // This will load css file in the VC backend editor
  244.             "params" => array(
  245.                 array(
  246.                     "type" => "textfield",
  247.                     "holder" => "div",
  248.                     "class" => "",
  249.                     "heading" => __("Category", 'vc_extend'),
  250.                     "param_name" => "category",
  251.                     "value" => '1',
  252.                     "description" => __("Category", 'vc_extend')
  253.                 ),
  254.                 array(
  255.                     "type" => "textfield",
  256.                     "holder" => "div",
  257.                     "class" => "",
  258.                     "heading" => __("Count", 'vc_extend'),
  259.                     "param_name" => "count",
  260.                     "value" => __("3", 'vc_extend'),
  261.                     "description" => __("Posts", 'vc_extend')
  262.                 ),
  263.                 array(
  264.                     "type" => "textfield",
  265.                     "holder" => "div",
  266.                     "class" => "",
  267.                     "heading" => __("Offset", 'vc_extend'),
  268.                     "param_name" => "offset",
  269.                     "value" => __("0", 'vc_extend'),
  270.                     "description" => __("Offsets", 'vc_extend')
  271.                 )
  272.  
  273.  
  274.  
  275.  
  276.             )
  277.         ) );
  278.     }
  279.  
  280.     /*
  281.     Shortcode logic how it should be rendered
  282.     */
  283.     public function renderPosts( $atts, $content = null ) {
  284.         extract( shortcode_atts( array(
  285.             'category' => '1',
  286.             'limit' => '3',
  287.             'offset' => '0'
  288.         ), $atts ) );
  289.         $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
  290.         $args = array(
  291.             'posts_per_page'   => $limit,
  292.             'offset'           => $offset,
  293.             'category'         => $category
  294.         );
  295.         $posts = get_posts($args);
  296.         $output = '';
  297.         foreach($posts as $post){
  298.             setup_postdata( $post );
  299.             $output .= '<a href="'.get_the_permalink().'">'.get_the_title().'</a> - <span class="post-date">'.get_the_date().'</span><br/>'.get_the_excerpt().'<hr/>';
  300.         }
  301.         return $output;
  302.     }
  303.  
  304.     /*
  305.     Load plugin css and javascript files which you may need on front end of your site
  306.     */
  307.     public function loadCssAndJs() {
  308.         wp_register_style( 'vc_extend_style', plugins_url('assets/vc_extend.css', __FILE__) );
  309.         wp_enqueue_style( 'vc_extend_style' );
  310.  
  311.         // If you need any javascript files on front end, here is how you can load them.
  312.         //wp_enqueue_script( 'vc_extend_js', plugins_url('assets/vc_extend.js', __FILE__), array('jquery') );
  313.     }
  314.  
  315.     /*
  316.     Show notice if your plugin is activated but Visual Composer is not
  317.     */
  318.     public function showVcVersionNotice() {
  319.         $plugin_data = get_plugin_data(__FILE__);
  320.         echo '
  321.        <div class="updated">
  322.          <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>
  323.        </div>';
  324.     }
  325. }
  326. // Finally initialize code
  327. new VCPostsAddonClass();
Advertisement
Add Comment
Please, Sign In to add comment