PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
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.78, at includes/widgets/Promo_Bar/Promo_Bar.php

494 lines 14.5 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 public function get_custom_help_url()
100 {
101 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
102 }
103
104 /**
105 * Register controls.
106 *
107 * @return void
108 */
109 public function register_controls(): void
110 {
111 $this->register_content_controls();
112 $this->register_layout_controls();
113 $this->register_style_controls();
114 $this->register_pro_notice_controls();
115 }
116
117 /**
118 * Render widget.
119 *
120 * @return void
121 */
122 public function render(): void
123 {
124 $settings = $this->get_settings_for_display();
125 $attrs = $this->get_wrapper_attributes($settings);
126
127 $button_url = $settings['kng_button_url'] ?? [];
128 $href = is_array($button_url) ? ($button_url['url'] ?? '') : '';
129 $is_external = is_array($button_url) && !empty($button_url['is_external']);
130 $nofollow = is_array($button_url) && !empty($button_url['nofollow']);
131 $rels = [];
132 if ($is_external) {
133 $rels[] = 'noopener';
134 $rels[] = 'noreferrer';
135 }
136 if ($nofollow) {
137 $rels[] = 'nofollow';
138 }
139 $rel_attr = !empty($rels) ? ' rel="' . esc_attr(implode(' ', array_unique($rels))) . '"' : '';
140 $target_attr = $is_external ? ' target="_blank"' : '';
141
142 ?>
143 <div class="king-addons-promo-bar" <?php echo $attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
144 <div class="king-addons-promo-bar__inner">
145 <div class="king-addons-promo-bar__content">
146 <?php if (!empty($settings['kng_badge_text'])) : ?>
147 <span class="king-addons-promo-bar__badge">
148 <?php echo esc_html($settings['kng_badge_text']); ?>
149 </span>
150 <?php endif; ?>
151 <?php if (!empty($settings['kng_title'])) : ?>
152 <span class="king-addons-promo-bar__title"><?php echo esc_html($settings['kng_title']); ?></span>
153 <?php endif; ?>
154 <?php if (!empty($settings['kng_description'])) : ?>
155 <span class="king-addons-promo-bar__description"><?php echo esc_html($settings['kng_description']); ?></span>
156 <?php endif; ?>
157 </div>
158
159 <div class="king-addons-promo-bar__actions">
160 <?php if (!empty($settings['kng_button_text']) && !empty($href)) : ?>
161 <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 ?>>
162 <?php echo esc_html($settings['kng_button_text']); ?>
163 </a>
164 <?php endif; ?>
165 <?php if (($settings['kng_show_close'] ?? 'yes') === 'yes') : ?>
166 <button class="king-addons-promo-bar__close" type="button" aria-label="<?php echo esc_attr__('Close', 'king-addons'); ?>">
167 <span aria-hidden="true">&times;</span>
168 </button>
169 <?php endif; ?>
170 </div>
171 </div>
172 </div>
173 <?php
174 }
175
176 /**
177 * Content controls.
178 *
179 * @return void
180 */
181 protected function register_content_controls(): void
182 {
183 $this->start_controls_section(
184 'kng_content_section',
185 [
186 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
187 'tab' => Controls_Manager::TAB_CONTENT,
188 ]
189 );
190
191 $this->add_control(
192 'kng_badge_text',
193 [
194 'label' => esc_html__('Badge Text', 'king-addons'),
195 'type' => Controls_Manager::TEXT,
196 'placeholder' => esc_html__('New', 'king-addons'),
197 ]
198 );
199
200 $this->add_control(
201 'kng_title',
202 [
203 'label' => esc_html__('Title', 'king-addons'),
204 'type' => Controls_Manager::TEXT,
205 'default' => esc_html__('Limited-time offer', 'king-addons'),
206 ]
207 );
208
209 $this->add_control(
210 'kng_description',
211 [
212 'label' => esc_html__('Description', 'king-addons'),
213 'type' => Controls_Manager::TEXT,
214 'default' => esc_html__('Save 20% today only.', 'king-addons'),
215 ]
216 );
217
218 $this->add_control(
219 'kng_button_text',
220 [
221 'label' => esc_html__('Button Text', 'king-addons'),
222 'type' => Controls_Manager::TEXT,
223 'default' => esc_html__('Shop now', 'king-addons'),
224 ]
225 );
226
227 $this->add_control(
228 'kng_button_url',
229 [
230 'label' => esc_html__('Button Link', 'king-addons'),
231 'type' => Controls_Manager::URL,
232 'placeholder' => esc_html__('https://', 'king-addons'),
233 ]
234 );
235
236 $this->add_control(
237 'kng_show_close',
238 [
239 'label' => esc_html__('Show Close Button', 'king-addons'),
240 'type' => Controls_Manager::SWITCHER,
241 'return_value' => 'yes',
242 'default' => 'yes',
243 ]
244 );
245
246 $this->end_controls_section();
247 }
248
249 /**
250 * Layout controls.
251 *
252 * @return void
253 */
254 protected function register_layout_controls(): void
255 {
256 $this->start_controls_section(
257 'kng_layout_section',
258 [
259 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Layout', 'king-addons'),
260 'tab' => Controls_Manager::TAB_CONTENT,
261 ]
262 );
263
264 $this->add_control(
265 'kng_position',
266 [
267 'label' => esc_html__('Position', 'king-addons'),
268 'type' => Controls_Manager::SELECT,
269 'default' => 'top',
270 'options' => [
271 'top' => esc_html__('Top', 'king-addons'),
272 'bottom' => esc_html__('Bottom', 'king-addons'),
273 ],
274 ]
275 );
276
277 $this->add_control(
278 'kng_sticky',
279 [
280 'label' => esc_html__('Sticky on Scroll', 'king-addons'),
281 'type' => Controls_Manager::SWITCHER,
282 'return_value' => 'yes',
283 'default' => 'yes',
284 ]
285 );
286
287 $this->add_responsive_control(
288 'kng_padding',
289 [
290 'label' => esc_html__('Padding', 'king-addons'),
291 'type' => Controls_Manager::DIMENSIONS,
292 'size_units' => ['px', 'em'],
293 'selectors' => [
294 '{{WRAPPER}} .king-addons-promo-bar__inner' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
295 ],
296 ]
297 );
298
299 $this->end_controls_section();
300 }
301
302 /**
303 * Style controls.
304 *
305 * @return void
306 */
307 protected function register_style_controls(): void
308 {
309 $this->start_controls_section(
310 'kng_style_section',
311 [
312 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Styles', 'king-addons'),
313 'tab' => Controls_Manager::TAB_STYLE,
314 ]
315 );
316
317 $this->add_control(
318 'kng_bg_color',
319 [
320 'label' => esc_html__('Background', 'king-addons'),
321 'type' => Controls_Manager::COLOR,
322 'selectors' => [
323 '{{WRAPPER}} .king-addons-promo-bar' => 'background-color: {{VALUE}};',
324 ],
325 ]
326 );
327
328 $this->add_group_control(
329 Group_Control_Border::get_type(),
330 [
331 'name' => 'kng_border',
332 'selector' => '{{WRAPPER}} .king-addons-promo-bar',
333 ]
334 );
335
336 $this->add_group_control(
337 Group_Control_Box_Shadow::get_type(),
338 [
339 'name' => 'kng_shadow',
340 'selector' => '{{WRAPPER}} .king-addons-promo-bar',
341 ]
342 );
343
344 $this->add_group_control(
345 Group_Control_Typography::get_type(),
346 [
347 'name' => 'kng_text_typography',
348 'selector' => '{{WRAPPER}} .king-addons-promo-bar__content',
349 ]
350 );
351
352 $this->add_control(
353 'kng_text_color',
354 [
355 'label' => esc_html__('Text Color', 'king-addons'),
356 'type' => Controls_Manager::COLOR,
357 'selectors' => [
358 '{{WRAPPER}} .king-addons-promo-bar__title' => 'color: {{VALUE}};',
359 '{{WRAPPER}} .king-addons-promo-bar__description' => 'color: {{VALUE}};',
360 ],
361 ]
362 );
363
364 $this->add_group_control(
365 Group_Control_Typography::get_type(),
366 [
367 'name' => 'kng_badge_typography',
368 'selector' => '{{WRAPPER}} .king-addons-promo-bar__badge',
369 ]
370 );
371
372 $this->add_control(
373 'kng_badge_color',
374 [
375 'label' => esc_html__('Badge Text Color', 'king-addons'),
376 'type' => Controls_Manager::COLOR,
377 'selectors' => [
378 '{{WRAPPER}} .king-addons-promo-bar__badge' => 'color: {{VALUE}};',
379 ],
380 ]
381 );
382
383 $this->add_control(
384 'kng_badge_bg',
385 [
386 'label' => esc_html__('Badge Background', 'king-addons'),
387 'type' => Controls_Manager::COLOR,
388 'selectors' => [
389 '{{WRAPPER}} .king-addons-promo-bar__badge' => 'background-color: {{VALUE}};',
390 ],
391 ]
392 );
393
394 $this->add_group_control(
395 Group_Control_Typography::get_type(),
396 [
397 'name' => 'kng_button_typography',
398 'selector' => '{{WRAPPER}} .king-addons-promo-bar__button',
399 ]
400 );
401
402 $this->add_control(
403 'kng_button_color',
404 [
405 'label' => esc_html__('Button Text Color', 'king-addons'),
406 'type' => Controls_Manager::COLOR,
407 'selectors' => [
408 '{{WRAPPER}} .king-addons-promo-bar__button' => 'color: {{VALUE}};',
409 ],
410 ]
411 );
412
413 $this->add_control(
414 'kng_button_bg',
415 [
416 'label' => esc_html__('Button Background', 'king-addons'),
417 'type' => Controls_Manager::COLOR,
418 'selectors' => [
419 '{{WRAPPER}} .king-addons-promo-bar__button' => 'background-color: {{VALUE}};',
420 ],
421 ]
422 );
423
424 $this->add_control(
425 'kng_button_radius',
426 [
427 'label' => esc_html__('Button Radius', 'king-addons'),
428 'type' => Controls_Manager::SLIDER,
429 'size_units' => ['px', '%'],
430 'range' => [
431 'px' => ['min' => 0, 'max' => 40],
432 '%' => ['min' => 0, 'max' => 100],
433 ],
434 'selectors' => [
435 '{{WRAPPER}} .king-addons-promo-bar__button' => 'border-radius: {{SIZE}}{{UNIT}};',
436 ],
437 ]
438 );
439
440 $this->end_controls_section();
441 }
442
443 /**
444 * Render pro notice.
445 *
446 * @return void
447 */
448 public function register_pro_notice_controls(): void
449 {
450 if (!king_addons_can_use_pro()) {
451 Core::renderProFeaturesSection($this, '', Controls_Manager::RAW_HTML, 'promo-bar', [
452 'Display conditions (page, UTM, schedule)',
453 'Persistent close and countdown timer',
454 'Device targeting and button icons',
455 'Bottom sheet style and animations',
456 ]);
457 }
458 }
459
460 /**
461 * Build wrapper attributes.
462 *
463 * @param array<string, mixed> $settings Settings.
464 *
465 * @return string
466 */
467 protected function get_wrapper_attributes(array $settings): string
468 {
469 $position = $settings['kng_position'] ?? 'top';
470 $position = in_array($position, ['top', 'bottom'], true) ? $position : 'top';
471
472 $attrs = [
473 'data-position' => $position,
474 'data-sticky' => (($settings['kng_sticky'] ?? 'yes') === 'yes') ? 'yes' : 'no',
475 'data-close-persist' => 'no',
476 'data-conditions' => '',
477 ];
478
479 $compiled = [];
480 foreach ($attrs as $key => $value) {
481 $compiled[] = esc_attr($key) . '="' . esc_attr($value) . '"';
482 }
483
484 return implode(' ', $compiled);
485 }
486 }
487
488
489
490
491
492
493
494