SidebarGroupButtonControl.php (2444B)
1 <?php 2 3 namespace Materialis; 4 5 6 class SidebarGroupButtonControl extends \Kirki_Customize_Control 7 { 8 9 public $type = "sidebar-button-group"; 10 public $popupId = ''; 11 public $in_row_with = array(); 12 public $always_active = false; 13 14 public function __construct($manager, $id, $args = array()) 15 { 16 $this->popupId = uniqid('cp-sidebar-button-group-'); 17 $this->in_row_with = isset($args['in_row_with']) ? $args['in_row_with'] : array(); 18 $this->always_active = isset($args['always_active']) ? $args['always_active'] : false; 19 parent::__construct($manager, $id, $args); 20 } 21 22 public function enqueue() 23 { 24 $jsRoot = get_template_directory_uri() . "/customizer/js"; 25 wp_enqueue_script('materialis-sb-group-button-control', $jsRoot . "/sb-group-button-control.js"); 26 27 } 28 29 public function json() 30 { 31 $fields = \Kirki::$fields; 32 $grouped = array(); 33 foreach ($fields as $field) { 34 if (isset($field['group']) && $field['group'] == $this->setting->id) { 35 $grouped[] = $field["settings"]; 36 } 37 } 38 if ( ! count($grouped)) { 39 $grouped = $this->choices; 40 } 41 42 $grouped = apply_filters($this->setting->id . "_filter", (array)$this->choices + $grouped); 43 44 if (count($grouped)) { 45 $this->choices = $grouped; 46 } 47 48 $json = parent::json(); 49 $json['popup'] = $this->popupId; 50 $json['in_row_with'] = $this->in_row_with; 51 $json['always_active'] = $this->always_active; 52 53 return $json; 54 } 55 56 protected function content_template() 57 { 58 ?> 59 60 <label> 61 62 <# if ( data.description ) { #> 63 <span class="title customize-control-title" style="visibility: hidden;">{{{ data.description }}}</span> 64 <# } #> 65 66 <button type="button" class="button" data-sidebar-container="{{ data.popup }}" id="group_customize-button-{{ data.popup }}"> 67 {{{ data.label }}} 68 </button> 69 </label> 70 71 <div id="{{ data.popup }}-popup" class="customizer-right-section"> 72 <span data-close-right-sidebar="true" title="<?php esc_attr_e("Close Panel", 'materialis'); ?>" class="close-panel"></span> 73 <ul class="section-settings-container accordion-section-content no-border"></ul> 74 </div> 75 <?php 76 77 } 78 }