PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.4.5
Easy Elements for Elementor – Addons & Website Templates v1.4.5
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / includes / helper-functions.php

helper-functions.php in Easy Elements for Elementor – Addons & Website Templates 1.4.5, at includes/helper-functions.php

1,090 lines 42.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6
7 if ( ! function_exists( 'easyel_allowed_html' ) ) {
8 /**
9 * Returns allowed HTML tags and attributes for wp_kses.
10 *
11 * Covers all HTML used in the product gallery output including
12 * SVG elements, Swiper markup, form elements, and data attributes.
13 *
14 * @since 1.0.0
15 *
16 * @return array Allowed HTML tags with their attributes.
17 */
18 function easyel_allowed_html() {
19
20 $global_attributes = array(
21 'class' => true,
22 'id' => true,
23 'style' => true,
24 'title' => true,
25 'role' => true,
26 'tabindex' => true,
27 'aria-label' => true,
28 'aria-live' => true,
29 'aria-atomic' => true,
30 'aria-current' => true,
31 'aria-controls' => true,
32 'aria-disabled' => true,
33 'aria-hidden' => true,
34 'aria-expanded' => true,
35 'aria-selected' => true,
36 'aria-describedby' => true,
37 'aria-labelledby' => true,
38 'aria-haspopup' => true,
39 'aria-pressed' => true,
40 'aria-checked' => true,
41 'aria-valuenow' => true,
42 'aria-valuemin' => true,
43 'aria-valuemax' => true,
44 'data-*' => true,
45 );
46
47 $allowed_tags = array(
48
49 // Structural
50 'div' => $global_attributes,
51 'span' => $global_attributes,
52 'section' => $global_attributes,
53 'article' => $global_attributes,
54 'aside' => $global_attributes,
55 'header' => $global_attributes,
56 'footer' => $global_attributes,
57 'main' => $global_attributes,
58 'figure' => $global_attributes,
59 'figcaption' => $global_attributes,
60 'nav' => $global_attributes,
61 'ul' => $global_attributes,
62 'ol' => array_merge( $global_attributes, array(
63 'start' => true,
64 'reversed' => true,
65 'type' => true,
66 )),
67 'li' => array_merge( $global_attributes, array(
68 'value' => true,
69 )),
70
71 // Headings
72 'h1' => $global_attributes,
73 'h2' => $global_attributes,
74 'h3' => $global_attributes,
75 'h4' => $global_attributes,
76 'h5' => $global_attributes,
77 'h6' => $global_attributes,
78
79 // Text / Inline
80 'p' => $global_attributes,
81 'a' => array_merge( $global_attributes, array(
82 'href' => true,
83 'target' => true,
84 'rel' => true,
85 'download' => true,
86 )),
87 'strong' => $global_attributes,
88 'b' => $global_attributes,
89 'em' => $global_attributes,
90 'i' => $global_attributes,
91 'u' => $global_attributes,
92 's' => $global_attributes,
93 'small' => $global_attributes,
94 'sub' => $global_attributes,
95 'sup' => $global_attributes,
96 'br' => $global_attributes,
97 'hr' => $global_attributes,
98 'abbr' => $global_attributes,
99 'cite' => $global_attributes,
100 'code' => $global_attributes,
101 'pre' => $global_attributes,
102 'mark' => $global_attributes,
103 'del' => array_merge( $global_attributes, array(
104 'datetime' => true,
105 )),
106 'ins' => array_merge( $global_attributes, array(
107 'datetime' => true,
108 )),
109 'bdi' => $global_attributes,
110 'bdo' => array_merge( $global_attributes, array(
111 'dir' => true,
112 )),
113 'time' => array_merge( $global_attributes, array(
114 'datetime' => true,
115 )),
116
117 // Images
118 'img' => array_merge( $global_attributes, array(
119 'src' => true,
120 'srcset' => true,
121 'sizes' => true,
122 'alt' => true,
123 'width' => true,
124 'height' => true,
125 'loading' => true,
126 'decoding' => true,
127 'fetchpriority' => true,
128 'crossorigin' => true,
129 'usemap' => true,
130 'ismap' => true,
131 )),
132 'picture' => $global_attributes,
133 'source' => array_merge( $global_attributes, array(
134 'src' => true,
135 'srcset' => true,
136 'sizes' => true,
137 'media' => true,
138 'type' => true,
139 )),
140
141 // Video / Audio
142 'video' => array_merge( $global_attributes, array(
143 'src' => true,
144 'poster' => true,
145 'width' => true,
146 'height' => true,
147 'autoplay' => true,
148 'controls' => true,
149 'loop' => true,
150 'muted' => true,
151 'playsinline' => true,
152 'preload' => true,
153 )),
154 'audio' => array_merge( $global_attributes, array(
155 'src' => true,
156 'autoplay' => true,
157 'controls' => true,
158 'loop' => true,
159 'muted' => true,
160 'preload' => true,
161 )),
162 'iframe' => array_merge( $global_attributes, array(
163 'src' => true,
164 'width' => true,
165 'height' => true,
166 'frameborder' => true,
167 'allow' => true,
168 'allowfullscreen' => true,
169 'loading' => true,
170 'sandbox' => true,
171 'name' => true,
172 )),
173
174 // Form elements
175 'form' => array_merge( $global_attributes, array(
176 'action' => true,
177 'method' => true,
178 'enctype' => true,
179 'name' => true,
180 'target' => true,
181 'novalidate' => true,
182 'autocomplete' => true,
183 )),
184 'input' => array_merge( $global_attributes, array(
185 'type' => true,
186 'name' => true,
187 'value' => true,
188 'placeholder' => true,
189 'min' => true,
190 'max' => true,
191 'step' => true,
192 'checked' => true,
193 'disabled' => true,
194 'readonly' => true,
195 'required' => true,
196 'autofocus' => true,
197 'autocomplete' => true,
198 'inputmode' => true,
199 'pattern' => true,
200 'size' => true,
201 'maxlength' => true,
202 'minlength' => true,
203 'multiple' => true,
204 'accept' => true,
205 'list' => true,
206 'form' => true,
207 )),
208 'button' => array_merge( $global_attributes, array(
209 'type' => true,
210 'name' => true,
211 'value' => true,
212 'disabled' => true,
213 'form' => true,
214 )),
215 'label' => array_merge( $global_attributes, array(
216 'for' => true,
217 )),
218 'select' => array_merge( $global_attributes, array(
219 'name' => true,
220 'multiple' => true,
221 'disabled' => true,
222 'required' => true,
223 'size' => true,
224 'autocomplete' => true,
225 'form' => true,
226 )),
227 'option' => array_merge( $global_attributes, array(
228 'value' => true,
229 'selected' => true,
230 'disabled' => true,
231 'label' => true,
232 )),
233 'optgroup' => array_merge( $global_attributes, array(
234 'label' => true,
235 'disabled' => true,
236 )),
237 'textarea' => array_merge( $global_attributes, array(
238 'name' => true,
239 'rows' => true,
240 'cols' => true,
241 'placeholder' => true,
242 'disabled' => true,
243 'readonly' => true,
244 'required' => true,
245 'maxlength' => true,
246 'minlength' => true,
247 'wrap' => true,
248 'autocomplete' => true,
249 'form' => true,
250 )),
251 'fieldset' => array_merge( $global_attributes, array(
252 'disabled' => true,
253 'form' => true,
254 'name' => true,
255 )),
256 'legend' => $global_attributes,
257
258 // Table
259 'table' => array_merge( $global_attributes, array(
260 'border' => true,
261 'cellpadding' => true,
262 'cellspacing' => true,
263 'width' => true,
264 )),
265 'thead' => $global_attributes,
266 'tbody' => $global_attributes,
267 'tfoot' => $global_attributes,
268 'tr' => $global_attributes,
269 'th' => array_merge( $global_attributes, array(
270 'colspan' => true,
271 'rowspan' => true,
272 'scope' => true,
273 'abbr' => true,
274 'headers' => true,
275 )),
276 'td' => array_merge( $global_attributes, array(
277 'colspan' => true,
278 'rowspan' => true,
279 'headers' => true,
280 )),
281 'caption' => $global_attributes,
282 'colgroup' => array_merge( $global_attributes, array(
283 'span' => true,
284 )),
285 'col' => array_merge( $global_attributes, array(
286 'span' => true,
287 )),
288
289 // SVG
290 'svg' => array_merge( $global_attributes, array(
291 'xmlns' => true,
292 'viewBox' => true,
293 'viewbox' => true,
294 'width' => true,
295 'height' => true,
296 'fill' => true,
297 'stroke' => true,
298 'stroke-width' => true,
299 'stroke-linecap' => true,
300 'stroke-linejoin' => true,
301 'enable-background' => true,
302 'preserveAspectRatio' => true,
303 'x' => true,
304 'y' => true,
305 'opacity' => true,
306 'transform' => true,
307 'clip-path' => true,
308 'clip-rule' => true,
309 'mask' => true,
310 'overflow' => true,
311 'version' => true,
312 'xml:space' => true,
313 'xmlns:xlink' => true,
314 'focusable' => true,
315 )),
316 'path' => array_merge( $global_attributes, array(
317 'd' => true,
318 'fill' => true,
319 'fill-rule' => true,
320 'fill-opacity' => true,
321 'stroke' => true,
322 'stroke-width' => true,
323 'stroke-linecap' => true,
324 'stroke-linejoin' => true,
325 'stroke-dasharray' => true,
326 'stroke-dashoffset' => true,
327 'stroke-opacity' => true,
328 'opacity' => true,
329 'transform' => true,
330 'clip-path' => true,
331 'clip-rule' => true,
332 )),
333 'circle' => array_merge( $global_attributes, array(
334 'cx' => true,
335 'cy' => true,
336 'r' => true,
337 'fill' => true,
338 'fill-opacity' => true,
339 'stroke' => true,
340 'stroke-width' => true,
341 'opacity' => true,
342 'transform' => true,
343 )),
344 'ellipse' => array_merge( $global_attributes, array(
345 'cx' => true,
346 'cy' => true,
347 'rx' => true,
348 'ry' => true,
349 'fill' => true,
350 'fill-opacity' => true,
351 'stroke' => true,
352 'stroke-width' => true,
353 'opacity' => true,
354 'transform' => true,
355 )),
356 'rect' => array_merge( $global_attributes, array(
357 'x' => true,
358 'y' => true,
359 'width' => true,
360 'height' => true,
361 'rx' => true,
362 'ry' => true,
363 'fill' => true,
364 'fill-opacity' => true,
365 'stroke' => true,
366 'stroke-width' => true,
367 'opacity' => true,
368 'transform' => true,
369 )),
370 'line' => array_merge( $global_attributes, array(
371 'x1' => true,
372 'y1' => true,
373 'x2' => true,
374 'y2' => true,
375 'stroke' => true,
376 'stroke-width' => true,
377 'stroke-linecap' => true,
378 'opacity' => true,
379 'transform' => true,
380 )),
381 'polyline' => array_merge( $global_attributes, array(
382 'points' => true,
383 'fill' => true,
384 'stroke' => true,
385 'stroke-width' => true,
386 'stroke-linecap' => true,
387 'stroke-linejoin' => true,
388 'opacity' => true,
389 'transform' => true,
390 )),
391 'polygon' => array_merge( $global_attributes, array(
392 'points' => true,
393 'fill' => true,
394 'fill-rule' => true,
395 'stroke' => true,
396 'stroke-width' => true,
397 'opacity' => true,
398 'transform' => true,
399 )),
400 'g' => array_merge( $global_attributes, array(
401 'fill' => true,
402 'fill-rule' => true,
403 'stroke' => true,
404 'stroke-width' => true,
405 'opacity' => true,
406 'transform' => true,
407 'clip-path' => true,
408 )),
409 'defs' => $global_attributes,
410 'symbol' => array_merge( $global_attributes, array(
411 'viewBox' => true,
412 'viewbox' => true,
413 'width' => true,
414 'height' => true,
415 'fill' => true,
416 'overflow' => true,
417 )),
418 'use' => array_merge( $global_attributes, array(
419 'href' => true,
420 'xlink:href' => true,
421 'x' => true,
422 'y' => true,
423 'width' => true,
424 'height' => true,
425 'fill' => true,
426 'stroke' => true,
427 )),
428 'clipPath' => $global_attributes,
429 'linearGradient' => array_merge( $global_attributes, array(
430 'x1' => true,
431 'y1' => true,
432 'x2' => true,
433 'y2' => true,
434 'gradientUnits' => true,
435 'gradientTransform' => true,
436 )),
437 'radialGradient' => array_merge( $global_attributes, array(
438 'cx' => true,
439 'cy' => true,
440 'r' => true,
441 'fx' => true,
442 'fy' => true,
443 'gradientUnits' => true,
444 'gradientTransform' => true,
445 )),
446 'stop' => array_merge( $global_attributes, array(
447 'offset' => true,
448 'stop-color' => true,
449 'stop-opacity' => true,
450 )),
451 'text' => array_merge( $global_attributes, array(
452 'x' => true,
453 'y' => true,
454 'dx' => true,
455 'dy' => true,
456 'text-anchor' => true,
457 'font-size' => true,
458 'font-family' => true,
459 'font-weight' => true,
460 'fill' => true,
461 'opacity' => true,
462 'transform' => true,
463 )),
464 'tspan' => array_merge( $global_attributes, array(
465 'x' => true,
466 'y' => true,
467 'dx' => true,
468 'dy' => true,
469 'fill' => true,
470 'font-size' => true,
471 'font-family' => true,
472 'font-weight' => true,
473 )),
474 'mask' => array_merge( $global_attributes, array(
475 'x' => true,
476 'y' => true,
477 'width' => true,
478 'height' => true,
479 'maskUnits' => true,
480 'maskContentUnits' => true,
481 )),
482 'title' => $global_attributes,
483 'desc' => $global_attributes,
484 );
485
486 return apply_filters( 'easyel_allowed_html', $allowed_tags );
487 }
488 }
489
490 add_filter( 'elementor/files/allow_unfiltered_files', '__return_false' );
491
492
493 if ( ! function_exists( 'easyel_get_pro_clean_version' ) ) {
494 function easyel_get_pro_clean_version() {
495
496 if ( ! defined( 'EASYELEMENTS_PRO_FILE' ) ) {
497 return null;
498 }
499
500 if ( ! function_exists( 'get_file_data' ) ) {
501 require_once ABSPATH . 'wp-admin/includes/plugin.php';
502 }
503
504 $data = get_file_data(
505 EASYELEMENTS_PRO_FILE,
506 [ 'Version' => 'Version' ]
507 );
508
509 return $data['Version'] ?? null;
510 }
511 }
512
513 if ( ! function_exists( 'easyel_enable_svg_upload' ) ) {
514 function easyel_enable_svg_upload( $mimes ) {
515 $mimes['svg'] = 'image/svg+xml';
516 $mimes['svgz'] = 'image/svg+xml';
517 return $mimes;
518 }
519 add_filter( 'upload_mimes', 'easyel_enable_svg_upload' );
520 }
521
522 if ( ! function_exists( 'easyel_fix_svg_filetype' ) ) {
523 function easyel_fix_svg_filetype( $data, $file, $filename, $mimes ) {
524 $ext = pathinfo( $filename, PATHINFO_EXTENSION );
525 if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) {
526 $data['ext'] = 'svg';
527 $data['type'] = 'image/svg+xml';
528 }
529 return $data;
530 }
531 add_filter( 'wp_check_filetype_and_ext', 'easyel_fix_svg_filetype', 10, 4 );
532 }
533
534 if ( ! function_exists( 'easyel_handle_sideload_svg' ) ) {
535 function easyel_handle_sideload_svg( $file ) {
536 $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
537 if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) {
538 $file['type'] = 'image/svg+xml';
539 }
540 return $file;
541 }
542
543 add_filter( 'wp_handle_sideload_prefilter', 'easyel_handle_sideload_svg' );
544 }
545
546 if ( ! function_exists( 'easyel_get_cf7_forms' ) ) {
547 /**
548 * Get a list of all CF7 forms
549 *
550 * @return array
551 */
552 function easyel_get_cf7_forms() {
553 $forms = get_posts( [
554 'post_type' => 'wpcf7_contact_form',
555 'post_status' => 'publish',
556 'posts_per_page' => -1,
557 'orderby' => 'title',
558 'order' => 'ASC',
559 ] );
560
561 if ( ! empty( $forms ) ) {
562 return wp_list_pluck( $forms, 'post_title', 'ID' );
563 }
564 return [];
565 }
566 }
567
568
569 // Domain Search Code
570 add_action('template_redirect', function(){
571 // phpcs:ignore WordPress.Security.NonceVerification.Missing
572 if (isset($_POST['easyel_domain_redirect'])) {
573 // phpcs:ignore WordPress.Security.NonceVerification.Missing
574 $domain = isset($_POST['domain']) ? sanitize_text_field(wp_unslash($_POST['domain'])) : '';
575 // phpcs:ignore WordPress.Security.NonceVerification.Missing
576 $base_url = isset($_POST['base_url']) ? esc_url_raw( wp_unslash($_POST['base_url'] ) ) : '';
577
578 if ( !empty($domain) && !empty($base_url) && filter_var($base_url, FILTER_VALIDATE_URL) ) {
579 $redirect_url = esc_url_raw($base_url . urlencode($domain));
580 wp_safe_redirect( $redirect_url );
581 exit;
582 }
583 }
584 });
585
586 function easyel_get_extension_fields() {
587 $fields = [
588 'enable_cursor' => [
589 'label' => __('Magic Cursor', 'easy-elements'),
590 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/magic-cursor.svg',
591 'is_pro' => true,
592 'group' => 'GSAP Extensions',
593 'demo_url' => 'https://wpeasyelements.com/docs/magic-cursor/',
594 'docs_url' => 'https://wpeasyelements.com/docs/magic-cursor/',
595 ],
596 'enable_sticky_elements' => [
597 'label' => __('Sticky Elements', 'easy-elements'),
598 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/sticky-elements.svg',
599 'is_pro' => true,
600 'group' => 'General Extensions',
601 'demo_url' => 'https://wpeasyelements.com/extensions/sticky-elements/',
602 'docs_url' => 'https://wpeasyelements.com/docs/sticky-elements/',
603 ],
604 'enable_cursor_hover_effect' => [
605 'label' => __('Cursor Hover Effect', 'easy-elements'),
606 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-hover-effect.svg',
607 'is_pro' => true,
608 'group' => 'GSAP Extensions',
609 'demo_url' => 'https://wpeasyelements.com/extensions/cursor-hover-effect/',
610 'docs_url' => 'https://wpeasyelements.com/docs/cursor-hover-effect/',
611 ],
612 'enable_cursor_move_effect' => [
613 'label' => __('Cursor Move Effect', 'easy-elements'),
614 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-move-effect.svg',
615 'is_pro' => true,
616 'group' => 'GSAP Extensions',
617 'demo_url' => 'https://wpeasyelements.com/extensions/cursor-move-effect/',
618 'docs_url' => 'https://wpeasyelements.com/docs/cursor-move-effect/',
619
620 ],
621 'enable_scroll_trigger' => [
622 'label' => __('ScrollTrigger', 'easy-elements'),
623 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/scrolltrigger.svg',
624 'is_pro' => true,
625 'group' => 'GSAP Extensions',
626 'demo_url' => 'https://wpeasyelements.com/extensions/scroll-trigger/',
627 'docs_url' => 'https://wpeasyelements.com/docs/scrolltrigger/',
628
629 ],
630 'enable_parallax_image' => [
631 'label' => __('Background Parallax', 'easy-elements'),
632 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/background-parallax.svg',
633 'is_pro' => true,
634 'group' => 'GSAP Extensions',
635 'demo_url' => 'https://wpeasyelements.com/extensions/background-parallax/',
636 'docs_url' => 'https://wpeasyelements.com/docs/background-parallax/',
637 ],
638 'enable_drawsvg' => [
639 'label' => __('DrawSVG', 'easy-elements'),
640 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/drawsvg.svg',
641 'is_pro' => true,
642 'upcoming' => true,
643 'group' => 'GSAP Extensions',
644 'demo_url' => '#',
645 'docs_url' => '#',
646 ],
647 'enable_image_3d_effect' => [
648 'label' => __('Image 3D Effect', 'easy-elements'),
649 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
650 'is_pro' => true,
651 'upcoming' => true,
652 'group' => 'GSAP Extensions',
653 'demo_url' => '#',
654 'docs_url' => '#',
655 ],
656 'enable_smooth_scroller' => [
657 'label' => __('Scroll Smoother', 'easy-elements'),
658 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
659 'is_pro' => true,
660 'setting' => true,
661 'group' => 'GSAP Extensions',
662 'demo_url' => 'https://wpeasyelements.com/',
663 'docs_url' => 'https://wpeasyelements.com/docs/scroll-smoother/',
664 ],
665 'enable_bounce_animation' => [
666 'label' => __('Bounce Animation', 'easy-elements'),
667 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
668 'is_pro' => true,
669 'group' => 'GSAP Extensions',
670 'demo_url' => 'https://wpeasyelements.com/extensions/bounce-animation/',
671 'docs_url' => 'https://wpeasyelements.com/docs/bounce-animation/',
672 ],
673 'enable_wrapper_link' => [
674 'label' => __('Wrapper Link', 'easy-elements'),
675 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/wrapper-link.svg',
676 'is_pro' => false,
677 'group' => 'General Extensions',
678 'demo_url' => 'https://wpeasyelements.com/extensions/wrapper-link/',
679 'docs_url' => 'https://wpeasyelements.com/docs/wrapper-link/',
680 ],
681 'enable_post_duplicator' => [
682 'label' => __('Duplicator', 'easy-elements'),
683 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg',
684 'is_pro' => false,
685 'group' => 'General Extensions',
686 'demo_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
687 'docs_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
688 ],
689 'enable_postpage_export' => [
690 'label' => __('Easy Export', 'easy-elements'),
691 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg',
692 'is_pro' => false,
693 'group' => 'General Extensions',
694 'demo_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/',
695 'docs_url' => 'https://wpeasyelements.com/docs/easy-export/',
696 ],
697 'enable_visibility_control' => [
698 'label' => __('Visibility Control', 'easy-elements'),
699 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/visibility-control.svg',
700 'is_pro' => true,
701 'group' => 'General Extensions',
702 'demo_url' => 'https://wpeasyelements.com/extensions/visibility-control/',
703 'docs_url' => 'https://wpeasyelements.com/docs/visibility-control/',
704 ],
705 'enable_dynamic_content' => [
706 'label' => __('Dynamic Content', 'easy-elements'),
707 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/dynamic-content.svg',
708 'is_pro' => true,
709 'group' => 'General Extensions',
710 'demo_url' => 'https://wpeasyelements.com/extensions/dynamic-content/',
711 'docs_url' => 'https://wpeasyelements.com/docs/dynamic-content/',
712 ],
713 'enable_live_copy_paste' => [
714 'label' => __('Live Copy Paste', 'easy-elements'),
715 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/live-copy.svg',
716 'is_pro' => true,
717 'group' => 'General Extensions',
718 'demo_url' => 'https://wpeasyelements.com/extensions/live-copy/',
719 'docs_url' => 'https://wpeasyelements.com/docs/live-copy/',
720 ],
721 'enable_easy_custom_css' => [
722 'label' => __('Custom CSS', 'easy-elements'),
723 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/easy-custom-css.svg',
724 'is_pro' => true,
725 'group' => 'General Extensions',
726 'demo_url' => 'https://wpeasyelements.com/docs/custom-css/',
727 'docs_url' => 'https://wpeasyelements.com/docs/custom-css/',
728 ],
729 'enable_global_badge' => [
730 'label' => __('Global Badge', 'easy-elements'),
731 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/global-badge.svg',
732 'is_pro' => true,
733 'group' => 'General Extensions',
734 'demo_url' => 'https://wpeasyelements.com/extensions/global-badge/',
735 'docs_url' => 'https://wpeasyelements.com/docs/global-badge/',
736 ],
737 'enable_megamenu_builder' => [
738 'label' => __('Megamenu Builder', 'easy-elements'),
739 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/megamenu.svg',
740 'is_pro' => true,
741 'group' => 'General Extensions',
742 'demo_url' => 'https://wpeasyelements.com/megamenu-builder/',
743 'docs_url' => 'https://wpeasyelements.com/docs/megamenu-builder/',
744 ],
745 'enable_reading_progress_bar' => [
746 'label' => __('Reading Progress Bar', 'easy-elements'),
747 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/progressbar.svg',
748 'is_pro' => false,
749 'setting' => true,
750 'group' => 'General Extensions',
751 'demo_url' => 'https://wpeasyelements.com/reading-progress-bar/',
752 'docs_url' => 'https://wpeasyelements.com/docs/reading-progress-bar/',
753 ],
754 'enable_scroll_top' => [
755 'label' => __('Scroll Top', 'easy-elements'),
756 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/arrow-up.svg',
757 'is_pro' => false,
758 'setting' => true,
759 'group' => 'General Extensions',
760 'demo_url' => '',
761 'docs_url' => 'https://wpeasyelements.com/docs/scroll-to-top/',
762 ],
763 'enable_preloader' => [
764 'label' => __( 'Preloader', 'easy-elements' ),
765 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/loader.svg',
766 'is_pro' => false,
767 'setting' => true,
768 'group' => 'General Extensions',
769 'demo_url' => '',
770 'docs_url' => 'https://wpeasyelements.com/docs/preloader/',
771 ],
772 'enable_popup_builder' => [
773 'label' => __('Popup Builder', 'easy-elements'),
774 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/popup-builder.svg',
775 'is_pro' => true,
776 'setting' => true,
777 'group' => 'General Extensions',
778 'demo_url' => 'https://wpeasyelements.com/extensions/popup-builder/',
779 'docs_url' => 'https://wpeasyelements.com/docs/popup-builder/',
780 ],
781 'enable_quick_view' => [
782 'label' => __('Quick View', 'easy-elements'),
783 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/quickview.svg',
784 'is_pro' => true,
785 'setting' => true,
786 'group' => 'WooCommerce Extensions',
787 'demo_url' => 'https://wpeasyelements.com/shop/',
788 'docs_url' => 'https://wpeasyelements.com/docs/quick-view/',
789 ],
790 'enable_easyel_compare' => [
791 'label' => __('Compare', 'easy-elements'),
792 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/compare.svg',
793 'is_pro' => true,
794 'setting' => true,
795 'group' => 'WooCommerce Extensions',
796 'demo_url' => 'https://wpeasyelements.com/shop/',
797 'docs_url' => 'https://wpeasyelements.com/docs/compare/',
798 ],
799 'enable_easyel_wishlist' => [
800 'label' => __('Wishlist', 'easy-elements'),
801 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/wishlist.svg',
802 'is_pro' => true,
803 'setting' => true,
804 'group' => 'WooCommerce Extensions',
805 'demo_url' => 'https://wpeasyelements.com/shop/',
806 'docs_url' => 'https://wpeasyelements.com/docs/wishlist/',
807 ],
808 ];
809
810 return apply_filters('easyel_extension_fields', $fields);
811 }
812
813 function easyel_sanitize_conditions_array( $conditions ) {
814 if ( ! is_array( $conditions ) ) {
815 return [];
816 }
817
818 $sanitized = [];
819 foreach ( $conditions as $cond ) {
820 if ( ! is_array( $cond ) ) continue;
821
822 $sanitized[] = [
823 'include' => isset($cond['include']) ? sanitize_text_field($cond['include']) : 'include',
824 'main' => isset($cond['main']) ? sanitize_text_field($cond['main']) : '',
825 'sub' => isset($cond['sub']) ? sanitize_text_field($cond['sub']) : '',
826 'child_sub' => isset($cond['child_sub']) ? sanitize_text_field($cond['child_sub']) : '',
827 ];
828 }
829
830 return $sanitized;
831 }
832
833 /**
834 * Safely decode JSON or return array as-is
835 */
836 function easyel_safe_json_decode( $data ) {
837 if ( is_string($data) ) {
838 $decoded = json_decode($data, true);
839 if ( json_last_error() === JSON_ERROR_NONE && is_array($decoded) ) {
840 return $decoded;
841 }
842 return [];
843 } elseif ( is_array($data) ) {
844 return $data;
845 } else {
846 return [];
847 }
848 }
849
850 class Easy_Widget_Injection {
851 public static function init() {
852 add_filter( 'elementor/controls/animations/additional_animations', [ __CLASS__, 'inject_easy_animations' ] );
853 }
854
855 public static function inject_easy_animations( $animations ) {
856 $animations['Easy Animations'] = [
857 'scaleIn' => __( 'Scale In', 'easy-elements' ),
858 ];
859 return $animations;
860 }
861 }
862
863 // Initialize the class
864 Easy_Widget_Injection::init();
865
866
867 /**
868 * Check if a specific Easy Element extension setting is enabled.
869 *
870 * @param string $setting_key The key of the setting to check (e.g. 'enable_sticky_elements').
871 * @return bool True if enabled, false otherwise.
872 */
873 function easy_element_is_enabled( $setting_key ) {
874 if ( empty( $setting_key ) ) {
875 return false;
876 }
877
878 $tab_slug = 'extensions';
879 $settings = get_option( 'easy_element_' . $tab_slug, [] );
880
881 // Sanitize and check
882 $value = isset( $settings[ $setting_key ] ) ? (int) $settings[ $setting_key ] : 0;
883
884 return ( $value === 1 );
885 }
886
887
888 function easyel_translate_hfe_template( $template_id ) {
889 if ( function_exists( 'pll_get_post' ) ) {
890 $translated = pll_get_post( $template_id );
891 if ( $translated ) {
892 $template_id = $translated;
893 }
894 }
895 if ( has_filter( 'wpml_object_id' ) ) {
896
897 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
898 $translated = apply_filters( 'wpml_object_id', $template_id, 'ee-elementor-hf', true );
899 if ( $translated ) {
900 $template_id = $translated;
901 }
902 }
903 return $template_id;
904 }
905
906 add_filter( 'easyel_get_settings_type_header', 'easyel_translate_hfe_template' );
907 add_filter( 'easyel_get_settings_type_footer', 'easyel_translate_hfe_template' );
908 add_filter( 'easyel_get_settings_type_easy_topbar', 'easyel_translate_hfe_template' );
909 add_filter( 'easyel_get_settings_type_easy_after__header', 'easyel_translate_hfe_template' );
910 add_filter( 'easyel_get_settings_type_before_footer', 'easyel_translate_hfe_template' );
911
912 if ( ! function_exists( 'easyel_get_valid_archive_post_types' ) ) {
913 function easyel_get_valid_archive_post_types() {
914
915 $post_types = get_post_types(
916 [
917 'public' => true,
918 'show_in_nav_menus' => true,
919 ],
920 'objects'
921 );
922
923 $valid = [];
924
925 foreach ( $post_types as $post_type => $pt ) {
926
927 if ( ! $pt->has_archive || ! get_post_type_archive_link( $post_type ) ) {
928 continue;
929 }
930
931 if ( $post_type === 'page' ) {
932 continue;
933 }
934
935 if (
936 ! empty( $pt->_builtin ) === false &&
937 str_starts_with( $post_type, 'elementor' )
938 ) {
939 continue;
940 }
941
942 if ( ! $pt->publicly_queryable ) {
943 continue;
944 }
945
946 $valid[ $post_type ] = $pt;
947 }
948
949 return $valid;
950 }
951 }
952
953 if ( ! function_exists( 'easyel_get_hierarchical_taxonomies_by_post_type' ) ) {
954 function easyel_get_hierarchical_taxonomies_by_post_type() {
955
956 $map = [];
957 $post_types = easyel_get_valid_archive_post_types();
958
959 foreach ($post_types as $post_type => $pt) {
960 $taxonomies = get_object_taxonomies($post_type, 'objects');
961
962 foreach ($taxonomies as $tax_slug => $tax) {
963 if (!$tax->public) {
964 continue;
965 }
966
967 $map[$tax_slug] = [
968 'post_type' => $post_type,
969 'taxonomy' => $tax_slug,
970 ];
971 }
972 }
973
974 return $map;
975 }
976 }
977
978 if ( ! function_exists('easyel_theme_builder_child_options') ) {
979 /**
980 * Get global condition arrays: needs_child_sub & no_child_sub
981 *
982 * @return array
983 */
984 function easyel_theme_builder_child_options() {
985 // Default needs_child_sub
986 $needs_child_sub = [
987 'author',
988 'category',
989 'child_of_category',
990 'any_child_of_category',
991 'in_category',
992 'in_category_children',
993 'post_tag',
994 'in_post_tag',
995 'child_of',
996 'any_child_of',
997 'product_cat',
998 'product_tag',
999 'product_brand',
1000 'post',
1001 'page',
1002 'page_by_author',
1003 ];
1004
1005 // Default no_child_sub
1006 $no_child_sub = [
1007 "all",
1008 "front_page",
1009 "not_found404",
1010 "index",
1011 "search",
1012 "date",
1013 "post_archive",
1014 "all_product_archive",
1015 "product_search",
1016 "shop_page",
1017 ];
1018
1019 // Get dynamic archive taxonomies
1020 $archive_taxonomies = function_exists('easyel_get_hierarchical_taxonomies_by_post_type')
1021 ? easyel_get_hierarchical_taxonomies_by_post_type()
1022 : [];
1023
1024 if ( is_array($archive_taxonomies) || is_object($archive_taxonomies) ) {
1025 foreach ($archive_taxonomies as $tax_slug => $data) {
1026 $needs_child_sub[] = $tax_slug;
1027 $needs_child_sub[] = 'child_of_' . $tax_slug;
1028 $needs_child_sub[] = 'any_child_of_' . $tax_slug;
1029
1030 $needs_child_sub[] = 'in_' . $tax_slug;
1031 $needs_child_sub[] = 'in_' . $tax_slug . '_children';
1032 $needs_child_sub[] = $data['post_type'] . '_by_author';
1033
1034 if ( ! empty($data['post_type']) ) {
1035 $no_child_sub[] = $data['post_type']."_archive";
1036 $needs_child_sub[] = $data['post_type'];
1037 }
1038 }
1039 }
1040
1041 return [
1042 'needs_child_sub' => $needs_child_sub,
1043 'no_child_sub' => $no_child_sub,
1044 ];
1045 }
1046 }
1047
1048 if ( ! function_exists( 'easyel_get_prepared_post_id' ) ) {
1049 function easyel_get_prepared_post_id() {
1050
1051 if ( is_singular( 'post' ) ) {
1052 return get_the_ID();
1053 }
1054
1055 $cache_key = 'easyel_latest_post_id';
1056 $post_id = wp_cache_get( $cache_key, 'easyel' );
1057
1058 if ( ! $post_id || get_post_status( $post_id ) !== 'publish' ) {
1059
1060 $latest_post = get_posts([
1061 'post_type' => 'post',
1062 'post_status' => 'publish',
1063 'posts_per_page' => 1,
1064 'orderby' => 'date',
1065 'order' => 'DESC',
1066 'fields' => 'ids',
1067 ]);
1068
1069 $post_id = !empty($latest_post) ? $latest_post[0] : 0;
1070
1071 wp_cache_set( $cache_key, $post_id, 'easyel', 12 * HOUR_IN_SECONDS );
1072 }
1073
1074 return $post_id;
1075 }
1076 }
1077
1078 // Sticky Header On
1079 add_action('template_redirect', function() {
1080 ob_start(function ($html) {
1081 if ( isset($GLOBALS['eel_force_sticky_header']) && $GLOBALS['eel_force_sticky_header'] === true ) {
1082 return preg_replace(
1083 '/(class=["\'][^"\']*easy-site-header[^"\']*)/i',
1084 '$1 eel-sticky-header-on',
1085 $html
1086 );
1087 }
1088 return $html;
1089 });
1090 });