PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.49
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.49
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Facet_Meta / Facet_Meta.php

Facet_Meta.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.49, at includes/widgets/Facet_Meta/Facet_Meta.php

142 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Facet Meta/ACF filter widget (placeholder).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Widget_Base;
12 use King_Addons\Woo_Builder\Context as Woo_Context;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Renders meta/ACF filter controls for faceted filters.
20 */
21 class Facet_Meta extends Widget_Base
22 {
23 public function get_name(): string
24 {
25 return 'facet_meta';
26 }
27
28 public function get_title(): string
29 {
30 return esc_html__('Facet Meta/ACF', 'king-addons');
31 }
32
33 public function get_icon(): string
34 {
35 return 'eicon-filter';
36 }
37
38 public function get_categories(): array
39 {
40 return ['king-addons'];
41 }
42
43 public function get_script_depends(): array
44 {
45 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-meta-script'];
46 }
47
48 public function get_style_depends(): array
49 {
50 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-facet-meta-style'];
51 }
52
53 protected function register_controls(): void
54 {
55 $this->start_controls_section(
56 'section_content',
57 [
58 'label' => esc_html__('Content', 'king-addons'),
59 'tab' => Controls_Manager::TAB_CONTENT,
60 ]
61 );
62
63 $this->add_control(
64 'query_id',
65 [
66 'label' => esc_html__('Query ID', 'king-addons'),
67 'type' => Controls_Manager::TEXT,
68 'description' => esc_html__('Must match the grid Query ID.', 'king-addons'),
69 ]
70 );
71
72 $this->add_control(
73 'meta_key',
74 [
75 'label' => esc_html__('Meta/ACF key', 'king-addons'),
76 'type' => Controls_Manager::TEXT,
77 'placeholder' => 'custom_field',
78 ]
79 );
80
81 $this->add_control(
82 'control_type',
83 [
84 'label' => esc_html__('Control type', 'king-addons'),
85 'type' => Controls_Manager::SELECT,
86 'options' => [
87 'text' => esc_html__('Text', 'king-addons'),
88 'select' => esc_html__('Select', 'king-addons'),
89 'range' => esc_html__('Range', 'king-addons'),
90 ],
91 'default' => 'text',
92 ]
93 );
94
95 $this->add_control(
96 'placeholder',
97 [
98 'label' => esc_html__('Placeholder', 'king-addons'),
99 'type' => Controls_Manager::TEXT,
100 ]
101 );
102
103 $this->end_controls_section();
104 }
105
106 protected function render(): void
107 {
108 $settings = $this->get_settings_for_display();
109 $query_id = $settings['query_id'] ?? '';
110 $meta_key = $settings['meta_key'] ?? '';
111 if (empty($query_id) || empty($meta_key)) {
112 if (class_exists(Woo_Context::class) && Woo_Context::is_editor()) {
113 echo '<div class="king-addons-woo-builder-notice">' . esc_html__('Set Query ID and Meta key.', 'king-addons') . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
114 }
115 return;
116 }
117
118 $type = $settings['control_type'] ?? 'text';
119 $placeholder = $settings['placeholder'] ?? '';
120 $data = ' data-ka-filters-query-id="' . esc_attr($query_id) . '" data-ka-filter-type="meta" data-ka-meta-key="' . esc_attr($meta_key) . '"';
121
122 echo '<div class="ka-facet-meta" ' . $data . '>';
123 if ('text' === $type) {
124 echo '<input type="text" class="ka-facet-meta__input" placeholder="' . esc_attr($placeholder) . '" />';
125 } elseif ('select' === $type) {
126 $ph = $placeholder ?: __('Any', 'king-addons');
127 echo '<select class="ka-facet-meta__select" data-placeholder="' . esc_attr($ph) . '" data-ka-meta-key="' . esc_attr($meta_key) . '" data-ka-filters-query-id="' . esc_attr($query_id) . '"><option value="">' . esc_html($ph) . '</option></select>';
128 } elseif ('range' === $type) {
129 echo '<div class="ka-facet-meta__range">';
130 echo '<input type="number" class="ka-facet-meta__range-min" placeholder="' . esc_attr__('Min', 'king-addons') . '" />';
131 echo '<input type="number" class="ka-facet-meta__range-max" placeholder="' . esc_attr__('Max', 'king-addons') . '" />';
132 echo '</div>';
133 }
134 echo '</div>';
135 }
136 }
137
138
139
140
141
142