| 1 |
<?php |
| 2 |
/** |
| 3 |
* Facet Reset widget. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace King_Addons; |
| 9 |
|
| 10 |
use Elementor\Controls_Manager; |
| 11 |
use Elementor\Widget_Base; |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Reset filters widget. |
| 19 |
*/ |
| 20 |
class Facet_Reset extends Widget_Base |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Widget slug. |
| 24 |
* |
| 25 |
* @return string |
| 26 |
*/ |
| 27 |
public function get_name(): string |
| 28 |
{ |
| 29 |
return 'king-addons-facet-reset'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Widget title. |
| 34 |
* |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public function get_title(): string |
| 38 |
{ |
| 39 |
return esc_html__('Reset Filters', 'king-addons'); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Keywords. |
| 44 |
* |
| 45 |
* @return array<int, string> |
| 46 |
*/ |
| 47 |
public function get_keywords(): array |
| 48 |
{ |
| 49 |
return ['shop', 'product', 'filter', 'filters', 'ajax', 'woocommerce', 'reset', 'clear', 'faceted', 'smart filters']; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Widget icon. |
| 54 |
* |
| 55 |
* @return string |
| 56 |
*/ |
| 57 |
public function get_icon(): string |
| 58 |
{ |
| 59 |
return 'king-addons-icon king-addons-facet-reset'; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Categories. |
| 64 |
* |
| 65 |
* @return array<int, string> |
| 66 |
*/ |
| 67 |
public function get_categories(): array |
| 68 |
{ |
| 69 |
return ['king-addons']; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Style dependencies. |
| 74 |
* |
| 75 |
* @return array<int, string> |
| 76 |
*/ |
| 77 |
public function get_style_depends(): array |
| 78 |
{ |
| 79 |
return [ |
| 80 |
KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-reset-style', |
| 81 |
]; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Script dependencies. |
| 86 |
* |
| 87 |
* @return array<int, string> |
| 88 |
*/ |
| 89 |
public function get_script_depends(): array |
| 90 |
{ |
| 91 |
return [ |
| 92 |
KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-reset-script', |
| 93 |
]; |
| 94 |
} |
| 95 |
|
| 96 |
public function get_custom_help_url() |
| 97 |
{ |
| 98 |
return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue'; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Register controls. |
| 103 |
* |
| 104 |
* @return void |
| 105 |
*/ |
| 106 |
public function register_controls(): void |
| 107 |
{ |
| 108 |
$this->start_controls_section( |
| 109 |
'kng_facet_reset_section', |
| 110 |
[ |
| 111 |
'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Reset Filters', 'king-addons'), |
| 112 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 113 |
] |
| 114 |
); |
| 115 |
|
| 116 |
$this->add_control( |
| 117 |
'kng_filters_query_id', |
| 118 |
[ |
| 119 |
'label' => esc_html__('Shop Filters ID', 'king-addons'), |
| 120 |
'type' => Controls_Manager::TEXT, |
| 121 |
'placeholder' => esc_html__('shop_grid_1', 'king-addons'), |
| 122 |
'description' => esc_html__('Must match the Shop Filters ID on the product grid.', 'king-addons'), |
| 123 |
] |
| 124 |
); |
| 125 |
|
| 126 |
$this->add_control( |
| 127 |
'kng_label', |
| 128 |
[ |
| 129 |
'label' => esc_html__('Button Label', 'king-addons'), |
| 130 |
'type' => Controls_Manager::TEXT, |
| 131 |
'default' => esc_html__('Reset filters', 'king-addons'), |
| 132 |
] |
| 133 |
); |
| 134 |
|
| 135 |
$this->end_controls_section(); |
| 136 |
|
| 137 |
require_once KING_ADDONS_PATH . 'includes/helpers/Faceted/Style_Controls.php'; |
| 138 |
Facet_Style_Controls::button($this); |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Render widget output. |
| 143 |
* |
| 144 |
* @return void |
| 145 |
*/ |
| 146 |
public function render(): void |
| 147 |
{ |
| 148 |
$settings = $this->get_settings_for_display(); |
| 149 |
$query_id = sanitize_title($settings['kng_filters_query_id'] ?? ''); |
| 150 |
$label = $settings['kng_label'] ?? esc_html__('Reset filters', 'king-addons'); |
| 151 |
|
| 152 |
if ('' === $query_id) { |
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
?> |
| 157 |
<div class="king-addons-facet king-addons-facet--reset"> |
| 158 |
<button |
| 159 |
type="button" |
| 160 |
class="king-addons-facet__button" |
| 161 |
data-ka-filter-type="reset" |
| 162 |
data-ka-filters-query-id="<?php echo esc_attr($query_id); ?>" |
| 163 |
> |
| 164 |
<?php echo esc_html($label); ?> |
| 165 |
</button> |
| 166 |
</div> |
| 167 |
<?php |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|