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 / TB_Archive_Description / TB_Archive_Description.php

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

316 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Builder Archive Description widget (Free).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Widget_Base;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Displays archive description or author bio.
20 */
21 class TB_Archive_Description extends Widget_Base
22 {
23 /**
24 * Widget slug.
25 *
26 * @return string
27 */
28 public function get_name(): string
29 {
30 return 'king-addons-tb-archive-description';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Archive Description', 'king-addons');
41 }
42
43 /**
44 * Widget icon.
45 *
46 * @return string
47 */
48 public function get_icon(): string
49 {
50 return 'eicon-archive-description';
51 }
52
53 /**
54 * Style dependencies.
55 *
56 * @return array<int, string>
57 */
58 public function get_style_depends(): array
59 {
60 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-archive-description-style'];
61 }
62
63 /**
64 * Script dependencies.
65 *
66 * @return array<int, string>
67 */
68 public function get_script_depends(): array
69 {
70 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-archive-description-script'];
71 }
72
73 /**
74 * Categories.
75 *
76 * @return array<int, string>
77 */
78 public function get_categories(): array
79 {
80 return ['king-addons'];
81 }
82
83 /**
84 * Keywords.
85 *
86 * @return array<int, string>
87 */
88 public function get_keywords(): array
89 {
90 return ['archive', 'description', 'bio', 'taxonomy', 'king-addons'];
91 }
92
93 /**
94 * Register controls.
95 *
96 * @return void
97 */
98 public function register_controls(): void
99 {
100 $this->register_content_controls(false);
101 $this->register_style_controls(false);
102 $this->register_pro_notice_controls();
103 }
104
105 /**
106 * Render output.
107 *
108 * @return void
109 */
110 public function render(): void
111 {
112 $settings = $this->get_settings_for_display();
113 $this->render_output($settings, false);
114 }
115
116 /**
117 * Content controls.
118 *
119 * @param bool $is_pro Whether Pro controls are enabled.
120 *
121 * @return void
122 */
123 protected function register_content_controls(bool $is_pro): void
124 {
125 $this->start_controls_section(
126 'kng_content_section',
127 [
128 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
129 'tab' => Controls_Manager::TAB_CONTENT,
130 ]
131 );
132
133 $this->add_control(
134 'kng_trim_words',
135 [
136 'label' => $is_pro ?
137 esc_html__('Trim Length (words)', 'king-addons') :
138 sprintf(__('Trim Length (words) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
139 'type' => Controls_Manager::NUMBER,
140 'min' => 0,
141 'default' => 0,
142 'classes' => $is_pro ? '' : 'king-addons-pro-control',
143 ]
144 );
145
146 $this->add_control(
147 'kng_strip_html',
148 [
149 'label' => esc_html__('Strip HTML', 'king-addons'),
150 'type' => Controls_Manager::SWITCHER,
151 'return_value' => 'yes',
152 'default' => 'yes',
153 ]
154 );
155
156 $this->add_control(
157 'kng_empty_behavior',
158 [
159 'label' => esc_html__('Empty Behavior', 'king-addons'),
160 'type' => Controls_Manager::SELECT,
161 'default' => 'hide',
162 'options' => [
163 'hide' => esc_html__('Hide Widget', 'king-addons'),
164 'placeholder' => $is_pro ?
165 esc_html__('Show Placeholder', 'king-addons') :
166 sprintf(__('Show Placeholder %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
167 ],
168 ]
169 );
170
171 $this->add_control(
172 'kng_placeholder_text',
173 [
174 'label' => esc_html__('Placeholder Text', 'king-addons'),
175 'type' => Controls_Manager::TEXT,
176 'default' => esc_html__('No description available.', 'king-addons'),
177 'condition' => [
178 'kng_empty_behavior' => 'placeholder',
179 ],
180 'classes' => $is_pro ? '' : 'king-addons-pro-control',
181 ]
182 );
183
184 $this->end_controls_section();
185 }
186
187 /**
188 * Style controls.
189 *
190 * @param bool $is_pro Whether Pro controls are enabled.
191 *
192 * @return void
193 */
194 protected function register_style_controls(bool $is_pro): void
195 {
196 $this->start_controls_section(
197 'kng_style_section',
198 [
199 'label' => esc_html__('Style', 'king-addons'),
200 'tab' => Controls_Manager::TAB_STYLE,
201 ]
202 );
203
204 $this->add_group_control(
205 Group_Control_Typography::get_type(),
206 [
207 'name' => 'kng_typography',
208 'selector' => '{{WRAPPER}} .king-addons-tb-archive-description',
209 ]
210 );
211
212 $this->add_control(
213 'kng_color',
214 [
215 'label' => esc_html__('Color', 'king-addons'),
216 'type' => Controls_Manager::COLOR,
217 'selectors' => [
218 '{{WRAPPER}} .king-addons-tb-archive-description' => 'color: {{VALUE}};',
219 ],
220 ]
221 );
222
223 $this->add_responsive_control(
224 'kng_alignment',
225 [
226 'label' => esc_html__('Alignment', 'king-addons'),
227 'type' => Controls_Manager::CHOOSE,
228 'options' => [
229 'left' => [
230 'title' => esc_html__('Left', 'king-addons'),
231 'icon' => 'eicon-text-align-left',
232 ],
233 'center' => [
234 'title' => esc_html__('Center', 'king-addons'),
235 'icon' => 'eicon-text-align-center',
236 ],
237 'right' => [
238 'title' => esc_html__('Right', 'king-addons'),
239 'icon' => 'eicon-text-align-right',
240 ],
241 ],
242 'selectors' => [
243 '{{WRAPPER}} .king-addons-tb-archive-description' => 'text-align: {{VALUE}};',
244 ],
245 ]
246 );
247
248 $this->add_responsive_control(
249 'kng_margin',
250 [
251 'label' => esc_html__('Margin', 'king-addons'),
252 'type' => Controls_Manager::DIMENSIONS,
253 'size_units' => ['px', 'em', '%'],
254 'selectors' => [
255 '{{WRAPPER}} .king-addons-tb-archive-description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
256 ],
257 ]
258 );
259
260 $this->end_controls_section();
261 }
262
263 /**
264 * Pro upsell.
265 *
266 * @return void
267 */
268 protected function register_pro_notice_controls(): void
269 {
270 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
271 return;
272 }
273
274 Core::renderProFeaturesSection(
275 $this,
276 '',
277 Controls_Manager::RAW_HTML,
278 'tb-archive-description',
279 [
280 'Trim length and placeholder handling',
281 'Advanced formatting and typography',
282 ]
283 );
284 }
285
286 /**
287 * Render output helper.
288 *
289 * @param array<string, mixed> $settings Settings.
290 * @param bool $is_pro Pro flag.
291 *
292 * @return void
293 */
294 protected function render_output(array $settings, bool $is_pro): void
295 {
296 $description = get_the_archive_description();
297 if ($settings['kng_strip_html'] ?? 'yes') {
298 $description = wp_strip_all_tags((string) $description, true);
299 }
300
301 if ($is_pro && !empty($settings['kng_trim_words'])) {
302 $description = wp_trim_words($description, (int) $settings['kng_trim_words'], '');
303 }
304
305 if (empty($description)) {
306 if ('placeholder' === ($settings['kng_empty_behavior'] ?? 'hide') && $is_pro && !empty($settings['kng_placeholder_text'])) {
307 $description = $settings['kng_placeholder_text'];
308 } else {
309 return;
310 }
311 }
312
313 echo '<div class="king-addons-tb-archive-description">' . wp_kses_post($description) . '</div>';
314 }
315 }
316