Advertisement
raselahmed7

SliderWidget - Elementor Class 4

Feb 26th, 2019
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.68 KB | None | 0 0
  1. <?php
  2.  
  3. class RRFCommerce_Slider_Widget extends \Elementor\Widget_Base {
  4.  
  5.  
  6.     public function get_name() {
  7.         return 'rrfcommerce-slider';
  8.     }
  9.  
  10.     public function get_title() {
  11.         return __( 'RRFCommerce Slider', 'plugin-name' );
  12.     }
  13.  
  14.     public function get_icon() {
  15.         return 'fa fa-code';
  16.     }
  17.  
  18.     public function get_categories() {
  19.         return [ 'general' ];
  20.     }
  21.  
  22.     protected function _register_controls() {
  23.  
  24.         $this->start_controls_section(
  25.             'content_section',
  26.             [
  27.                 'label' => __( 'Content', 'plugin-name' ),
  28.                 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  29.             ]
  30.         );
  31.  
  32.         $repeater = new \Elementor\Repeater();
  33.  
  34.         $repeater->add_control(
  35.             'slide_title', [
  36.                 'label' => __( 'Title', 'plugin-domain' ),
  37.                 'type' => \Elementor\Controls_Manager::TEXT,
  38.                 'default' => __( 'Slide title' , 'plugin-domain' ),
  39.                 'label_block' => true,
  40.             ]
  41.         );
  42.  
  43.         $repeater->add_control(
  44.             'slide_content', [
  45.                 'label' => __( 'Content', 'plugin-domain' ),
  46.                 'type' => \Elementor\Controls_Manager::WYSIWYG,
  47.                 'default' => __( 'Slide Content' , 'plugin-domain' ),
  48.                 'show_label' => true,
  49.             ]
  50.         );
  51.  
  52.         $repeater->add_control(
  53.             'slide_desc',
  54.             [
  55.                 'label' => __( 'Slide description', 'plugin-domain' ),
  56.                 'type' => \Elementor\Controls_Manager::TEXT,
  57.                 'show_label' => true,
  58.             ]
  59.         );
  60.  
  61.         $repeater->add_control(
  62.             'slide_image',
  63.             [
  64.                 'label' => __( 'Slide image', 'plugin-domain' ),
  65.                 'type' => \Elementor\Controls_Manager::MEDIA,
  66.                 'show_label' => true,
  67.             ]
  68.         );
  69.  
  70.         $this->add_control(
  71.             'slides',
  72.             [
  73.                 'label' => __( 'Slides', 'plugin-domain' ),
  74.                 'type' => \Elementor\Controls_Manager::REPEATER,
  75.                 'fields' => $repeater->get_controls(),
  76.                 'default' => [
  77.                     [
  78.                         'list_title' => __( 'Slide #1', 'plugin-domain' ),
  79.                         'list_content' => __( 'Slide content', 'plugin-domain' ),
  80.                     ],
  81.                 ]
  82.             ]
  83.         );
  84.         $this->end_controls_section();
  85.  
  86.         $this->start_controls_section(
  87.             'setting_section',
  88.             [
  89.                 'label' => __( 'Slider Settings', 'plugin-name' ),
  90.                 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  91.             ]
  92.         );
  93.  
  94.         $this->add_control(
  95.             'fade',
  96.             [
  97.                 'label' => __( 'Fade effecct?', 'plugin-domain' ),
  98.                 'type' => \Elementor\Controls_Manager::SWITCHER,
  99.                 'label_on' => __( 'Yes', 'your-plugin' ),
  100.                 'label_off' => __( 'No', 'your-plugin' ),
  101.                 'return_value' => 'yes',
  102.                 'default' => 'no',
  103.             ]
  104.         );
  105.         $this->add_control(
  106.             'loop',
  107.             [
  108.                 'label' => __( 'Loop?', 'plugin-domain' ),
  109.                 'type' => \Elementor\Controls_Manager::SWITCHER,
  110.                 'label_on' => __( 'Yes', 'your-plugin' ),
  111.                 'label_off' => __( 'No', 'your-plugin' ),
  112.                 'return_value' => 'yes',
  113.                 'default' => 'yes',
  114.             ]
  115.         );
  116.         $this->add_control(
  117.             'arrows',
  118.             [
  119.                 'label' => __( 'Show arrows?', 'plugin-domain' ),
  120.                 'type' => \Elementor\Controls_Manager::SWITCHER,
  121.                 'label_on' => __( 'Show', 'your-plugin' ),
  122.                 'label_off' => __( 'Hide', 'your-plugin' ),
  123.                 'return_value' => 'yes',
  124.                 'default' => 'yes',
  125.             ]
  126.         );
  127.  
  128.         $this->add_control(
  129.             'dots',
  130.             [
  131.                 'label' => __( 'Show dots?', 'plugin-domain' ),
  132.                 'type' => \Elementor\Controls_Manager::SWITCHER,
  133.                 'label_on' => __( 'Show', 'your-plugin' ),
  134.                 'label_off' => __( 'Hide', 'your-plugin' ),
  135.                 'return_value' => 'yes',
  136.                 'default' => 'yes',
  137.             ]
  138.         );
  139.  
  140.         $this->add_control(
  141.             'autoplay',
  142.             [
  143.                 'label' => __( 'Autoplay?', 'plugin-domain' ),
  144.                 'type' => \Elementor\Controls_Manager::SWITCHER,
  145.                 'label_on' => __( 'Yes', 'your-plugin' ),
  146.                 'label_off' => __( 'No', 'your-plugin' ),
  147.                 'return_value' => 'yes',
  148.                 'default' => 'yes',
  149.             ]
  150.         );
  151.  
  152.         $this->add_control(
  153.             'autoplay_time',
  154.             [
  155.                 'label' => __( 'Autoplay Time', 'plugin-domain' ),
  156.                 'type' => \Elementor\Controls_Manager::TEXT,
  157.                 'default' => '5000',
  158.                 'condition' => [
  159.                     'autoplay' => 'yes',
  160.                 ],
  161.             ]
  162.         );
  163.  
  164.         $this->end_controls_section();
  165.  
  166.     }
  167.  
  168.     protected function render() {
  169.  
  170.         $settings = $this->get_settings_for_display();
  171.  
  172.         if($settings['slides']) {
  173.             $dynamic_id = rand(78676, 967698);
  174.             if(count($settings['slides']) > 1) {
  175.                 if($settings['fade'] == 'yes') {
  176.                     $fade = 'true';
  177.                 } else {
  178.                     $fade = 'false';
  179.                 }
  180.                 if($settings['arrows'] == 'yes') {
  181.                     $arrows = 'true';
  182.                 } else {
  183.                     $arrows = 'false';
  184.                 }
  185.                 if($settings['dots'] == 'yes') {
  186.                     $dots = 'true';
  187.                 } else {
  188.                     $dots = 'false';
  189.                 }
  190.                 if($settings['autoplay'] == 'yes') {
  191.                     $autoplay = 'true';
  192.                 } else {
  193.                     $autoplay = 'false';
  194.                 }
  195.                 if($settings['loop'] == 'yes') {
  196.                     $loop = 'true';
  197.                 } else {
  198.                     $loop = 'false';
  199.                 }
  200.                 echo '<script>
  201.                     jQuery(document).ready(function($) {
  202.                         $("#slides-'.$dynamic_id.'").slick({
  203.                             arrows: '.$arrows.',
  204.                             prevArrow: "<i class=\'fa fa-angle-left\'></i>",
  205.                             nextArrow: "<i class=\'fa fa-angle-right\'></i>",
  206.                             dots: '.$dots.',
  207.                             fade: '.$fade.',
  208.                             autoplay: '.$autoplay.',
  209.                             loop: '.$loop.',';
  210.  
  211.                             if($autoplay == 'true') {
  212.                                 echo 'autoplaySpeed: '.$settings['autoplay_time'].'';
  213.                             }
  214.                            
  215.  
  216.                             echo '
  217.                         });
  218.                     });
  219.                 </script>';
  220.             }
  221.             echo '<div id="slides-'.$dynamic_id.'" class="slides">';
  222.             foreach($settings['slides'] as $slide) {
  223.                 echo '<div class="single-slide-item" style="background-image:url('.wp_get_attachment_image_url($slide['slide_image']['id'], 'large').')">
  224.                     <div class="row">
  225.                         <div class="col my-auto">
  226.                             '.wpautop($slide['slide_content']).'
  227.                         </div>
  228.                     </div>
  229.                     <div class="slide-info">
  230.                         <h4>'.$slide['slide_title'].'</h4>
  231.                         '.$slide['slide_desc'].'
  232.                     </div>
  233.                 </div>';
  234.             }
  235.             echo '</div>';
  236.         }
  237.        
  238.  
  239.     }
  240.  
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement