Guest User

Untitled

a guest
Aug 30th, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. <?php
  2. /*
  3. Widget Name: Accordion
  4.  */
  5.  
  6. if (!class_exists('SiteOrigin_Widget_Base_Slider')) {
  7.     include_once plugin_dir_path(SOW_BUNDLE_BASE_FILE) . '/base/inc/widgets/base-slider.class.php';
  8. }
  9.  
  10. class Custom_SOW_Accordion extends SiteOrigin_Widget_Base_Slider
  11. {
  12.     public function __construct()
  13.     {
  14.  
  15.         parent::__construct(
  16.             'accordion-own',
  17.             __('Accordion', 'custom_so_widgets'),
  18.             array(
  19.                 'description' => __('Custom Accordion', 'custom_so_widgets'),
  20.             ),
  21.             array(),
  22.             array(
  23.                 'frames' => array(
  24.                     'type' => 'repeater',
  25.                     'label' => __('Items', 'custom_so_widgets'),
  26.                     'item_label' => array(
  27.                         'selector' => "[id*='title']",
  28.                     ),
  29.                     'fields' => array(
  30.                         'title' => array(
  31.                             'type' => 'text',
  32.                             'label' => __('Title', 'custom_so_widgets'),
  33.                         ),
  34.                         'content' => array(
  35.                             'type' => 'builder',
  36.                             'label' => __('Content', 'custom_so_widgets'),
  37.                         ),
  38.                     ),
  39.                 ),
  40.                 'countable' => array(
  41.                     'type' => 'checkbox',
  42.                     'label' => __('Countable', 'custom_so_widgets'),
  43.                 ),
  44.             ),
  45.             plugin_dir_path(__FILE__)
  46.         );
  47.     }
  48.  
  49.     public function render_template($controls, $i, $frame)
  50.     {
  51.         $this->render_frame($i, $frame, $controls);
  52.     }
  53.  
  54.     public function render_frame_contents($i, $frame)
  55.     {
  56.         echo $this->process_content($frame['content'], $frame);
  57.     }
  58.  
  59.     public function process_content($content, $frame)
  60.     {
  61.         if (function_exists('siteorigin_panels_render')) {
  62.             $content_builder_id = substr(md5(json_encode($content)), 0, 8);
  63.             echo siteorigin_panels_render('w' . $content_builder_id, true, $content);
  64.         } else {
  65.             echo __('This widget requires Page Builder.', 'custom_so_widgets');
  66.         }
  67.     }
  68.  
  69.     public function render_frame($i, $frame, $controls)
  70.     {
  71.         $this->render_frame_contents($i, $frame);
  72.     }
  73.  
  74.     public function get_template_variables($instance, $args)
  75.     {
  76.         if (empty($instance)) {
  77.             return array();
  78.         }
  79.  
  80.         $items = empty($instance['frames']) ? array() : $instance['frames'];
  81.         $countable = !empty($instance['countable']) ? true : false;
  82.  
  83.         return array(
  84.             'items' => $items,
  85.             'countable' => $countable,
  86.         );
  87.     }
  88. }
  89.  
  90. siteorigin_widget_register('accordion-own', __FILE__, 'Custom_SOW_Accordion');
Advertisement
Add Comment
Please, Sign In to add comment