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

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

489 lines 14.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Announcement / Promo Bar Widget (Free).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Border;
12 use Elementor\Group_Control_Box_Shadow;
13 use Elementor\Group_Control_Typography;
14 use Elementor\Widget_Base;
15
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 /**
21 * Renders a sticky announcement bar.
22 */
23 class Promo_Bar extends Widget_Base
24 {
25 /**
26 * Widget slug.
27 *
28 * @return string
29 */
30 public function get_name(): string
31 {
32 return 'king-addons-promo-bar';
33 }
34
35 /**
36 * Widget title.
37 *
38 * @return string
39 */
40 public function get_title(): string
41 {
42 return esc_html__('Announcement / Promo Bar', 'king-addons');
43 }
44
45 /**
46 * Widget icon.
47 *
48 * @return string
49 */
50 public function get_icon(): string
51 {
52 return 'king-addons-icon king-addons-promo-bar';
53 }
54
55 /**
56 * Style dependencies.
57 *
58 * @return array<int, string>
59 */
60 public function get_style_depends(): array
61 {
62 return [
63 KING_ADDONS_ASSETS_UNIQUE_KEY . '-promo-bar-style',
64 ];
65 }
66
67 /**
68 * Script dependencies.
69 *
70 * @return array<int, string>
71 */
72 public function get_script_depends(): array
73 {
74 return [
75 KING_ADDONS_ASSETS_UNIQUE_KEY . '-promo-bar-script',
76 ];
77 }
78
79 /**
80 * Categories.
81 *
82 * @return array<int, string>
83 */
84 public function get_categories(): array
85 {
86 return ['king-addons'];
87 }
88
89 /**
90 * Keywords.
91 *
92 * @return array<int, string>
93 */
94 public function get_keywords(): array
95 {
96 return ['announcement', 'promo', 'bar', 'notification'];
97 }
98
99 /**
100 * Register controls.
101 *
102 * @return void
103 */
104 public function register_controls(): void
105 {
106 $this->register_content_controls();
107 $this->register_layout_controls();
108 $this->register_style_controls();
109 $this->register_pro_notice_controls();
110 }
111
112 /**
113 * Render widget.
114 *
115 * @return void
116 */
117 public function render(): void
118 {
119 $settings = $this->get_settings_for_display();
120 $attrs = $this->get_wrapper_attributes($settings);
121
122 $button_url = $settings['kng_button_url'] ?? [];
123 $href = is_array($button_url) ? ($button_url['url'] ?? '') : '';
124 $is_external = is_array($button_url) && !empty($button_url['is_external']);
125 $nofollow = is_array($button_url) && !empty($button_url['nofollow']);
126 $rels = [];
127 if ($is_external) {
128 $rels[] = 'noopener';
129 $rels[] = 'noreferrer';
130 }
131 if ($nofollow) {
132 $rels[] = 'nofollow';
133 }
134 $rel_attr = !empty($rels) ? ' rel="' . esc_attr(implode(' ', array_unique($rels))) . '"' : '';
135 $target_attr = $is_external ? ' target="_blank"' : '';
136
137 ?>
138 <div class="king-addons-promo-bar" <?php echo $attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
139 <div class="king-addons-promo-bar__inner">
140 <div class="king-addons-promo-bar__content">
141 <?php if (!empty($settings['kng_badge_text'])) : ?>
142 <span class="king-addons-promo-bar__badge">
143 <?php echo esc_html($settings['kng_badge_text']); ?>
144 </span>
145 <?php endif; ?>
146 <?php if (!empty($settings['kng_title'])) : ?>
147 <span class="king-addons-promo-bar__title"><?php echo esc_html($settings['kng_title']); ?></span>
148 <?php endif; ?>
149 <?php if (!empty($settings['kng_description'])) : ?>
150 <span class="king-addons-promo-bar__description"><?php echo esc_html($settings['kng_description']); ?></span>
151 <?php endif; ?>
152 </div>
153
154 <div class="king-addons-promo-bar__actions">
155 <?php if (!empty($settings['kng_button_text']) && !empty($href)) : ?>
156 <a class="king-addons-promo-bar__button" href="<?php echo esc_url($href); ?>"<?php echo $target_attr . $rel_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
157 <?php echo esc_html($settings['kng_button_text']); ?>
158 </a>
159 <?php endif; ?>
160 <?php if (($settings['kng_show_close'] ?? 'yes') === 'yes') : ?>
161 <button class="king-addons-promo-bar__close" type="button" aria-label="<?php echo esc_attr__('Close', 'king-addons'); ?>">
162 <span aria-hidden="true">&times;</span>
163 </button>
164 <?php endif; ?>
165 </div>
166 </div>
167 </div>
168 <?php
169 }
170
171 /**
172 * Content controls.
173 *
174 * @return void
175 */
176 protected function register_content_controls(): void
177 {
178 $this->start_controls_section(
179 'kng_content_section',
180 [
181 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
182 'tab' => Controls_Manager::TAB_CONTENT,
183 ]
184 );
185
186 $this->add_control(
187 'kng_badge_text',
188 [
189 'label' => esc_html__('Badge Text', 'king-addons'),
190 'type' => Controls_Manager::TEXT,
191 'placeholder' => esc_html__('New', 'king-addons'),
192 ]
193 );
194
195 $this->add_control(
196 'kng_title',
197 [
198 'label' => esc_html__('Title', 'king-addons'),
199 'type' => Controls_Manager::TEXT,
200 'default' => esc_html__('Limited-time offer', 'king-addons'),
201 ]
202 );
203
204 $this->add_control(
205 'kng_description',
206 [
207 'label' => esc_html__('Description', 'king-addons'),
208 'type' => Controls_Manager::TEXT,
209 'default' => esc_html__('Save 20% today only.', 'king-addons'),
210 ]
211 );
212
213 $this->add_control(
214 'kng_button_text',
215 [
216 'label' => esc_html__('Button Text', 'king-addons'),
217 'type' => Controls_Manager::TEXT,
218 'default' => esc_html__('Shop now', 'king-addons'),
219 ]
220 );
221
222 $this->add_control(
223 'kng_button_url',
224 [
225 'label' => esc_html__('Button Link', 'king-addons'),
226 'type' => Controls_Manager::URL,
227 'placeholder' => esc_html__('https://', 'king-addons'),
228 ]
229 );
230
231 $this->add_control(
232 'kng_show_close',
233 [
234 'label' => esc_html__('Show Close Button', 'king-addons'),
235 'type' => Controls_Manager::SWITCHER,
236 'return_value' => 'yes',
237 'default' => 'yes',
238 ]
239 );
240
241 $this->end_controls_section();
242 }
243
244 /**
245 * Layout controls.
246 *
247 * @return void
248 */
249 protected function register_layout_controls(): void
250 {
251 $this->start_controls_section(
252 'kng_layout_section',
253 [
254 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Layout', 'king-addons'),
255 'tab' => Controls_Manager::TAB_CONTENT,
256 ]
257 );
258
259 $this->add_control(
260 'kng_position',
261 [
262 'label' => esc_html__('Position', 'king-addons'),
263 'type' => Controls_Manager::SELECT,
264 'default' => 'top',
265 'options' => [
266 'top' => esc_html__('Top', 'king-addons'),
267 'bottom' => esc_html__('Bottom', 'king-addons'),
268 ],
269 ]
270 );
271
272 $this->add_control(
273 'kng_sticky',
274 [
275 'label' => esc_html__('Sticky on Scroll', 'king-addons'),
276 'type' => Controls_Manager::SWITCHER,
277 'return_value' => 'yes',
278 'default' => 'yes',
279 ]
280 );
281
282 $this->add_responsive_control(
283 'kng_padding',
284 [
285 'label' => esc_html__('Padding', 'king-addons'),
286 'type' => Controls_Manager::DIMENSIONS,
287 'size_units' => ['px', 'em'],
288 'selectors' => [
289 '{{WRAPPER}} .king-addons-promo-bar__inner' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
290 ],
291 ]
292 );
293
294 $this->end_controls_section();
295 }
296
297 /**
298 * Style controls.
299 *
300 * @return void
301 */
302 protected function register_style_controls(): void
303 {
304 $this->start_controls_section(
305 'kng_style_section',
306 [
307 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Styles', 'king-addons'),
308 'tab' => Controls_Manager::TAB_STYLE,
309 ]
310 );
311
312 $this->add_control(
313 'kng_bg_color',
314 [
315 'label' => esc_html__('Background', 'king-addons'),
316 'type' => Controls_Manager::COLOR,
317 'selectors' => [
318 '{{WRAPPER}} .king-addons-promo-bar' => 'background-color: {{VALUE}};',
319 ],
320 ]
321 );
322
323 $this->add_group_control(
324 Group_Control_Border::get_type(),
325 [
326 'name' => 'kng_border',
327 'selector' => '{{WRAPPER}} .king-addons-promo-bar',
328 ]
329 );
330
331 $this->add_group_control(
332 Group_Control_Box_Shadow::get_type(),
333 [
334 'name' => 'kng_shadow',
335 'selector' => '{{WRAPPER}} .king-addons-promo-bar',
336 ]
337 );
338
339 $this->add_group_control(
340 Group_Control_Typography::get_type(),
341 [
342 'name' => 'kng_text_typography',
343 'selector' => '{{WRAPPER}} .king-addons-promo-bar__content',
344 ]
345 );
346
347 $this->add_control(
348 'kng_text_color',
349 [
350 'label' => esc_html__('Text Color', 'king-addons'),
351 'type' => Controls_Manager::COLOR,
352 'selectors' => [
353 '{{WRAPPER}} .king-addons-promo-bar__title' => 'color: {{VALUE}};',
354 '{{WRAPPER}} .king-addons-promo-bar__description' => 'color: {{VALUE}};',
355 ],
356 ]
357 );
358
359 $this->add_group_control(
360 Group_Control_Typography::get_type(),
361 [
362 'name' => 'kng_badge_typography',
363 'selector' => '{{WRAPPER}} .king-addons-promo-bar__badge',
364 ]
365 );
366
367 $this->add_control(
368 'kng_badge_color',
369 [
370 'label' => esc_html__('Badge Text Color', 'king-addons'),
371 'type' => Controls_Manager::COLOR,
372 'selectors' => [
373 '{{WRAPPER}} .king-addons-promo-bar__badge' => 'color: {{VALUE}};',
374 ],
375 ]
376 );
377
378 $this->add_control(
379 'kng_badge_bg',
380 [
381 'label' => esc_html__('Badge Background', 'king-addons'),
382 'type' => Controls_Manager::COLOR,
383 'selectors' => [
384 '{{WRAPPER}} .king-addons-promo-bar__badge' => 'background-color: {{VALUE}};',
385 ],
386 ]
387 );
388
389 $this->add_group_control(
390 Group_Control_Typography::get_type(),
391 [
392 'name' => 'kng_button_typography',
393 'selector' => '{{WRAPPER}} .king-addons-promo-bar__button',
394 ]
395 );
396
397 $this->add_control(
398 'kng_button_color',
399 [
400 'label' => esc_html__('Button Text Color', 'king-addons'),
401 'type' => Controls_Manager::COLOR,
402 'selectors' => [
403 '{{WRAPPER}} .king-addons-promo-bar__button' => 'color: {{VALUE}};',
404 ],
405 ]
406 );
407
408 $this->add_control(
409 'kng_button_bg',
410 [
411 'label' => esc_html__('Button Background', 'king-addons'),
412 'type' => Controls_Manager::COLOR,
413 'selectors' => [
414 '{{WRAPPER}} .king-addons-promo-bar__button' => 'background-color: {{VALUE}};',
415 ],
416 ]
417 );
418
419 $this->add_control(
420 'kng_button_radius',
421 [
422 'label' => esc_html__('Button Radius', 'king-addons'),
423 'type' => Controls_Manager::SLIDER,
424 'size_units' => ['px', '%'],
425 'range' => [
426 'px' => ['min' => 0, 'max' => 40],
427 '%' => ['min' => 0, 'max' => 100],
428 ],
429 'selectors' => [
430 '{{WRAPPER}} .king-addons-promo-bar__button' => 'border-radius: {{SIZE}}{{UNIT}};',
431 ],
432 ]
433 );
434
435 $this->end_controls_section();
436 }
437
438 /**
439 * Render pro notice.
440 *
441 * @return void
442 */
443 public function register_pro_notice_controls(): void
444 {
445 if (!king_addons_can_use_pro()) {
446 Core::renderProFeaturesSection($this, '', Controls_Manager::RAW_HTML, 'promo-bar', [
447 'Display conditions (page, UTM, schedule)',
448 'Persistent close and countdown timer',
449 'Device targeting and button icons',
450 'Bottom sheet style and animations',
451 ]);
452 }
453 }
454
455 /**
456 * Build wrapper attributes.
457 *
458 * @param array<string, mixed> $settings Settings.
459 *
460 * @return string
461 */
462 protected function get_wrapper_attributes(array $settings): string
463 {
464 $position = $settings['kng_position'] ?? 'top';
465 $position = in_array($position, ['top', 'bottom'], true) ? $position : 'top';
466
467 $attrs = [
468 'data-position' => $position,
469 'data-sticky' => (($settings['kng_sticky'] ?? 'yes') === 'yes') ? 'yes' : 'no',
470 'data-close-persist' => 'no',
471 'data-conditions' => '',
472 ];
473
474 $compiled = [];
475 foreach ($attrs as $key => $value) {
476 $compiled[] = esc_attr($key) . '="' . esc_attr($value) . '"';
477 }
478
479 return implode(' ', $compiled);
480 }
481 }
482
483
484
485
486
487
488
489