PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.4.0
Easy Elements for Elementor – Addons & Website Templates v1.4.0
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.0, at includes/helper-functions.php

570 lines 21.7 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 add_filter( 'elementor/files/allow_unfiltered_files', '__return_false' );
7
8
9 if ( ! function_exists( 'easyel_get_pro_clean_version' ) ) {
10 function easyel_get_pro_clean_version() {
11
12 if ( ! defined( 'EASYELEMENTS_PRO_FILE' ) ) {
13 return null;
14 }
15
16 if ( ! function_exists( 'get_file_data' ) ) {
17 require_once ABSPATH . 'wp-admin/includes/plugin.php';
18 }
19
20 $data = get_file_data(
21 EASYELEMENTS_PRO_FILE,
22 [ 'Version' => 'Version' ]
23 );
24
25 return $data['Version'] ?? null;
26 }
27 }
28
29 if ( ! function_exists( 'easyel_enable_svg_upload' ) ) {
30 function easyel_enable_svg_upload( $mimes ) {
31 $mimes['svg'] = 'image/svg+xml';
32 $mimes['svgz'] = 'image/svg+xml';
33 return $mimes;
34 }
35 add_filter( 'upload_mimes', 'easyel_enable_svg_upload' );
36 }
37
38 if ( ! function_exists( 'easyel_fix_svg_filetype' ) ) {
39 function easyel_fix_svg_filetype( $data, $file, $filename, $mimes ) {
40 $ext = pathinfo( $filename, PATHINFO_EXTENSION );
41 if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) {
42 $data['ext'] = 'svg';
43 $data['type'] = 'image/svg+xml';
44 }
45 return $data;
46 }
47 add_filter( 'wp_check_filetype_and_ext', 'easyel_fix_svg_filetype', 10, 4 );
48 }
49
50 if ( ! function_exists( 'easyel_handle_sideload_svg' ) ) {
51 function easyel_handle_sideload_svg( $file ) {
52 $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
53 if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) {
54 $file['type'] = 'image/svg+xml';
55 }
56 return $file;
57 }
58
59 add_filter( 'wp_handle_sideload_prefilter', 'easyel_handle_sideload_svg' );
60 }
61
62 if ( ! function_exists( 'easyel_get_cf7_forms' ) ) {
63 /**
64 * Get a list of all CF7 forms
65 *
66 * @return array
67 */
68 function easyel_get_cf7_forms() {
69 $forms = get_posts( [
70 'post_type' => 'wpcf7_contact_form',
71 'post_status' => 'publish',
72 'posts_per_page' => -1,
73 'orderby' => 'title',
74 'order' => 'ASC',
75 ] );
76
77 if ( ! empty( $forms ) ) {
78 return wp_list_pluck( $forms, 'post_title', 'ID' );
79 }
80 return [];
81 }
82 }
83
84
85 // Domain Search Code
86 add_action('template_redirect', function(){
87 // phpcs:ignore WordPress.Security.NonceVerification.Missing
88 if (isset($_POST['easyel_domain_redirect'])) {
89 // phpcs:ignore WordPress.Security.NonceVerification.Missing
90 $domain = isset($_POST['domain']) ? sanitize_text_field(wp_unslash($_POST['domain'])) : '';
91 // phpcs:ignore WordPress.Security.NonceVerification.Missing
92 $base_url = isset($_POST['base_url']) ? esc_url_raw( wp_unslash($_POST['base_url'] ) ) : '';
93
94 if ( !empty($domain) && !empty($base_url) && filter_var($base_url, FILTER_VALIDATE_URL) ) {
95 $redirect_url = esc_url_raw($base_url . urlencode($domain));
96 wp_safe_redirect( $redirect_url );
97 exit;
98 }
99 }
100 });
101
102 function easyel_get_extension_fields() {
103 $fields = [
104 'enable_cursor' => [
105 'label' => __('Magic Cursor', 'easy-elements'),
106 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/magic-cursor.svg',
107 'is_pro' => true,
108 'group' => 'GSAP Extensions',
109 'demo_url' => 'https://wpeasyelements.com/docs/magic-cursor/',
110 'docs_url' => 'https://wpeasyelements.com/docs/magic-cursor/',
111 ],
112 'enable_sticky_elements' => [
113 'label' => __('Sticky Elements', 'easy-elements'),
114 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/sticky-elements.svg',
115 'is_pro' => true,
116 'group' => 'General Extensions',
117 'demo_url' => 'https://wpeasyelements.com/extensions/sticky-elements/',
118 'docs_url' => 'https://wpeasyelements.com/docs/sticky-elements/',
119 ],
120 'enable_cursor_hover_effect' => [
121 'label' => __('Cursor Hover Effect', 'easy-elements'),
122 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-hover-effect.svg',
123 'is_pro' => true,
124 'group' => 'GSAP Extensions',
125 'demo_url' => 'https://wpeasyelements.com/extensions/cursor-hover-effect/',
126 'docs_url' => 'https://wpeasyelements.com/docs/cursor-hover-effect/',
127 ],
128 'enable_cursor_move_effect' => [
129 'label' => __('Cursor Move Effect', 'easy-elements'),
130 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-move-effect.svg',
131 'is_pro' => true,
132 'group' => 'GSAP Extensions',
133 'demo_url' => 'https://wpeasyelements.com/extensions/cursor-move-effect/',
134 'docs_url' => 'https://wpeasyelements.com/docs/cursor-move-effect/',
135
136 ],
137 'enable_scroll_trigger' => [
138 'label' => __('ScrollTrigger', 'easy-elements'),
139 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/scrolltrigger.svg',
140 'is_pro' => true,
141 'group' => 'GSAP Extensions',
142 'demo_url' => 'https://wpeasyelements.com/extensions/scroll-trigger/',
143 'docs_url' => 'https://wpeasyelements.com/docs/scrolltrigger/',
144
145 ],
146 'enable_parallax_image' => [
147 'label' => __('Background Parallax', 'easy-elements'),
148 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/background-parallax.svg',
149 'is_pro' => true,
150 'group' => 'GSAP Extensions',
151 'demo_url' => 'https://wpeasyelements.com/extensions/background-parallax/',
152 'docs_url' => 'https://wpeasyelements.com/docs/background-parallax/',
153 ],
154 'enable_drawsvg' => [
155 'label' => __('DrawSVG', 'easy-elements'),
156 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/drawsvg.svg',
157 'is_pro' => true,
158 'upcoming' => true,
159 'group' => 'GSAP Extensions',
160 'demo_url' => '#',
161 'docs_url' => '#',
162 ],
163 'enable_image_3d_effect' => [
164 'label' => __('Image 3D Effect', 'easy-elements'),
165 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
166 'is_pro' => true,
167 'upcoming' => true,
168 'group' => 'GSAP Extensions',
169 'demo_url' => '#',
170 'docs_url' => '#',
171 ],
172 'enable_smooth_scroller' => [
173 'label' => __('Scroll Smoother', 'easy-elements'),
174 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
175 'is_pro' => true,
176 'setting' => true,
177 'group' => 'GSAP Extensions',
178 'demo_url' => 'https://wpeasyelements.com/extensions/scroll-smoother/',
179 'docs_url' => 'https://wpeasyelements.com/extensions/docs/scroll-smoother/',
180 ],
181 'enable_bounce_animation' => [
182 'label' => __('Bounce Animation', 'easy-elements'),
183 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
184 'is_pro' => true,
185 'group' => 'GSAP Extensions',
186 'demo_url' => 'https://wpeasyelements.com/extensions/bounce-animation/',
187 'docs_url' => 'https://wpeasyelements.com/extensions/docs/bounce-animation/',
188 ],
189 'enable_wrapper_link' => [
190 'label' => __('Wrapper Link', 'easy-elements'),
191 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/wrapper-link.svg',
192 'is_pro' => false,
193 'group' => 'General Extensions',
194 'demo_url' => 'https://wpeasyelements.com/extensions/wrapper-link/',
195 'docs_url' => 'https://wpeasyelements.com/docs/wrapper-link/',
196 ],
197 'enable_post_duplicator' => [
198 'label' => __('Duplicator', 'easy-elements'),
199 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg',
200 'is_pro' => false,
201 'group' => 'General Extensions',
202 'demo_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
203 'docs_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
204 ],
205 'enable_postpage_export' => [
206 'label' => __('Easy Export', 'easy-elements'),
207 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg',
208 'is_pro' => false,
209 'group' => 'General Extensions',
210 'demo_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/',
211 'docs_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/',
212 ],
213 'enable_visibility_control' => [
214 'label' => __('Visibility Control', 'easy-elements'),
215 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/visibility-control.svg',
216 'is_pro' => true,
217 'group' => 'General Extensions',
218 'demo_url' => 'https://wpeasyelements.com/extensions/visibility-control/',
219 'docs_url' => 'https://wpeasyelements.com/docs/visibility-control/',
220 ],
221 'enable_dynamic_content' => [
222 'label' => __('Dynamic Content', 'easy-elements'),
223 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/dynamic-content.svg',
224 'is_pro' => true,
225 'group' => 'General Extensions',
226 'demo_url' => 'https://wpeasyelements.com/extensions/dynamic-content/',
227 'docs_url' => 'https://wpeasyelements.com/docs/dynamic-content/',
228 ],
229 'enable_live_copy_paste' => [
230 'label' => __('Live Copy Paste', 'easy-elements'),
231 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/live-copy.svg',
232 'is_pro' => true,
233 'group' => 'General Extensions',
234 'demo_url' => 'https://wpeasyelements.com/extensions/live-copy/',
235 'docs_url' => 'https://wpeasyelements.com/docs/live-copy/',
236 ],
237 'enable_easy_custom_css' => [
238 'label' => __('Custom CSS', 'easy-elements'),
239 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/easy-custom-css.svg',
240 'is_pro' => true,
241 'group' => 'General Extensions',
242 'demo_url' => 'https://wpeasyelements.com/docs/custom-css/',
243 'docs_url' => '#',
244 ],
245 'enable_global_badge' => [
246 'label' => __('Global Badge', 'easy-elements'),
247 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/global-badge.svg',
248 'is_pro' => true,
249 'group' => 'General Extensions',
250 'demo_url' => 'https://wpeasyelements.com/extensions/global-badge/',
251 'docs_url' => 'https://wpeasyelements.com/extensions/docs/global-badge/',
252 ],
253 'enable_megamenu_builder' => [
254 'label' => __('Megamenu Builder', 'easy-elements'),
255 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/megamenu.svg',
256 'is_pro' => true,
257 'group' => 'General Extensions',
258 'demo_url' => 'https://wpeasyelements.com/megamenu-builder/',
259 'docs_url' => 'https://wpeasyelements.com/docs/megamenu-builder/',
260 ],
261 'enable_reading_progress_bar' => [
262 'label' => __('Reading Progress Bar', 'easy-elements'),
263 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/progressbar.svg',
264 'is_pro' => false,
265 'setting' => true,
266 'group' => 'General Extensions',
267 'demo_url' => 'https://wpeasyelements.com/reading-progress-bar/',
268 'docs_url' => 'https://wpeasyelements.com/docs/reading-progress-bar/',
269 ],
270 'enable_popup_builder' => [
271 'label' => __('Popup Builder', 'easy-elements'),
272 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/popup-builder.svg',
273 'is_pro' => true,
274 'setting' => true,
275 'group' => 'General Extensions',
276 'demo_url' => 'https://wpeasyelements.com/extensions/popup-builder/',
277 'docs_url' => 'https://wpeasyelements.com/docs/popup-builder/',
278 ],
279 // 'enable_quick_view' => [
280 // 'label' => __('Quick View', 'easy-elements'),
281 // 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/progess.svg',
282 // 'is_pro' => true,
283 // 'setting' => true,
284 // 'group' => 'WooCommerce Extensions',
285 // 'demo_url' => 'https://wpeasyelements.com/extensions/quick-view/',
286 // 'docs_url' => 'https://wpeasyelements.com/docs/quick-view/',
287 // ],
288 ];
289
290 return apply_filters('easyel_extension_fields', $fields);
291 }
292
293 function easyel_sanitize_conditions_array( $conditions ) {
294 if ( ! is_array( $conditions ) ) {
295 return [];
296 }
297
298 $sanitized = [];
299 foreach ( $conditions as $cond ) {
300 if ( ! is_array( $cond ) ) continue;
301
302 $sanitized[] = [
303 'include' => isset($cond['include']) ? sanitize_text_field($cond['include']) : 'include',
304 'main' => isset($cond['main']) ? sanitize_text_field($cond['main']) : '',
305 'sub' => isset($cond['sub']) ? sanitize_text_field($cond['sub']) : '',
306 'child_sub' => isset($cond['child_sub']) ? sanitize_text_field($cond['child_sub']) : '',
307 ];
308 }
309
310 return $sanitized;
311 }
312
313 /**
314 * Safely decode JSON or return array as-is
315 */
316 function easyel_safe_json_decode( $data ) {
317 if ( is_string($data) ) {
318 $decoded = json_decode($data, true);
319 if ( json_last_error() === JSON_ERROR_NONE && is_array($decoded) ) {
320 return $decoded;
321 }
322 return [];
323 } elseif ( is_array($data) ) {
324 return $data;
325 } else {
326 return [];
327 }
328 }
329
330 class Easy_Widget_Injection {
331 public static function init() {
332 add_filter( 'elementor/controls/animations/additional_animations', [ __CLASS__, 'inject_easy_animations' ] );
333 }
334
335 public static function inject_easy_animations( $animations ) {
336 $animations['Easy Animations'] = [
337 'scaleIn' => __( 'Scale In', 'easy-elements' ),
338 ];
339 return $animations;
340 }
341 }
342
343 // Initialize the class
344 Easy_Widget_Injection::init();
345
346
347 /**
348 * Check if a specific Easy Element extension setting is enabled.
349 *
350 * @param string $setting_key The key of the setting to check (e.g. 'enable_sticky_elements').
351 * @return bool True if enabled, false otherwise.
352 */
353 function easy_element_is_enabled( $setting_key ) {
354 if ( empty( $setting_key ) ) {
355 return false;
356 }
357
358 $tab_slug = 'extensions';
359 $settings = get_option( 'easy_element_' . $tab_slug, [] );
360
361 // Sanitize and check
362 $value = isset( $settings[ $setting_key ] ) ? (int) $settings[ $setting_key ] : 0;
363
364 return ( $value === 1 );
365 }
366
367
368 function easyel_translate_hfe_template( $template_id ) {
369 if ( function_exists( 'pll_get_post' ) ) {
370 $translated = pll_get_post( $template_id );
371 if ( $translated ) {
372 $template_id = $translated;
373 }
374 }
375 if ( has_filter( 'wpml_object_id' ) ) {
376
377 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
378 $translated = apply_filters( 'wpml_object_id', $template_id, 'ee-elementor-hf', true );
379 if ( $translated ) {
380 $template_id = $translated;
381 }
382 }
383 return $template_id;
384 }
385
386 add_filter( 'easyel_get_settings_type_header', 'easyel_translate_hfe_template' );
387 add_filter( 'easyel_get_settings_type_footer', 'easyel_translate_hfe_template' );
388 add_filter( 'easyel_get_settings_type_easy_topbar', 'easyel_translate_hfe_template' );
389 add_filter( 'easyel_get_settings_type_easy_after__header', 'easyel_translate_hfe_template' );
390 add_filter( 'easyel_get_settings_type_before_footer', 'easyel_translate_hfe_template' );
391
392 if ( ! function_exists( 'easyel_get_valid_archive_post_types' ) ) {
393 function easyel_get_valid_archive_post_types() {
394
395 $post_types = get_post_types(
396 [
397 'public' => true,
398 'show_in_nav_menus' => true,
399 ],
400 'objects'
401 );
402
403 $valid = [];
404
405 foreach ( $post_types as $post_type => $pt ) {
406
407 if ( ! $pt->has_archive || ! get_post_type_archive_link( $post_type ) ) {
408 continue;
409 }
410
411 if ( $post_type === 'page' ) {
412 continue;
413 }
414
415 if (
416 ! empty( $pt->_builtin ) === false &&
417 str_starts_with( $post_type, 'elementor' )
418 ) {
419 continue;
420 }
421
422 if ( ! $pt->publicly_queryable ) {
423 continue;
424 }
425
426 $valid[ $post_type ] = $pt;
427 }
428
429 return $valid;
430 }
431 }
432
433 if ( ! function_exists( 'easyel_get_hierarchical_taxonomies_by_post_type' ) ) {
434 function easyel_get_hierarchical_taxonomies_by_post_type() {
435
436 $map = [];
437 $post_types = easyel_get_valid_archive_post_types();
438
439 foreach ($post_types as $post_type => $pt) {
440 $taxonomies = get_object_taxonomies($post_type, 'objects');
441
442 foreach ($taxonomies as $tax_slug => $tax) {
443 if (!$tax->public) {
444 continue;
445 }
446
447 $map[$tax_slug] = [
448 'post_type' => $post_type,
449 'taxonomy' => $tax_slug,
450 ];
451 }
452 }
453
454 return $map;
455 }
456 }
457
458 if ( ! function_exists('easyel_theme_builder_child_options') ) {
459 /**
460 * Get global condition arrays: needs_child_sub & no_child_sub
461 *
462 * @return array
463 */
464 function easyel_theme_builder_child_options() {
465 // Default needs_child_sub
466 $needs_child_sub = [
467 'author',
468 'category',
469 'child_of_category',
470 'any_child_of_category',
471 'in_category',
472 'in_category_children',
473 'post_tag',
474 'in_post_tag',
475 'child_of',
476 'any_child_of',
477 'product_cat',
478 'product_tag',
479 'product_brand',
480 'post',
481 'page',
482 'page_by_author',
483 ];
484
485 // Default no_child_sub
486 $no_child_sub = [
487 "all",
488 "front_page",
489 "not_found404",
490 "index",
491 "search",
492 "date",
493 "post_archive",
494 "all_product_archive",
495 "product_search",
496 "shop_page",
497 ];
498
499 // Get dynamic archive taxonomies
500 $archive_taxonomies = function_exists('easyel_get_hierarchical_taxonomies_by_post_type')
501 ? easyel_get_hierarchical_taxonomies_by_post_type()
502 : [];
503
504 if ( is_array($archive_taxonomies) || is_object($archive_taxonomies) ) {
505 foreach ($archive_taxonomies as $tax_slug => $data) {
506 $needs_child_sub[] = $tax_slug;
507 $needs_child_sub[] = 'child_of_' . $tax_slug;
508 $needs_child_sub[] = 'any_child_of_' . $tax_slug;
509
510 $needs_child_sub[] = 'in_' . $tax_slug;
511 $needs_child_sub[] = 'in_' . $tax_slug . '_children';
512 $needs_child_sub[] = $data['post_type'] . '_by_author';
513
514 if ( ! empty($data['post_type']) ) {
515 $no_child_sub[] = $data['post_type']."_archive";
516 $needs_child_sub[] = $data['post_type'];
517 }
518 }
519 }
520
521 return [
522 'needs_child_sub' => $needs_child_sub,
523 'no_child_sub' => $no_child_sub,
524 ];
525 }
526 }
527
528 if ( ! function_exists( 'easyel_get_prepared_post_id' ) ) {
529 function easyel_get_prepared_post_id() {
530
531 if ( is_singular( 'post' ) ) {
532 return get_the_ID();
533 }
534
535 $cache_key = 'easyel_latest_post_id';
536 $post_id = wp_cache_get( $cache_key, 'easyel' );
537
538 if ( ! $post_id || get_post_status( $post_id ) !== 'publish' ) {
539
540 $latest_post = get_posts([
541 'post_type' => 'post',
542 'post_status' => 'publish',
543 'posts_per_page' => 1,
544 'orderby' => 'date',
545 'order' => 'DESC',
546 'fields' => 'ids',
547 ]);
548
549 $post_id = !empty($latest_post) ? $latest_post[0] : 0;
550
551 wp_cache_set( $cache_key, $post_id, 'easyel', 12 * HOUR_IN_SECONDS );
552 }
553
554 return $post_id;
555 }
556 }
557
558 // Sticky Header On
559 add_action('template_redirect', function() {
560 ob_start(function ($html) {
561 if ( isset($GLOBALS['eel_force_sticky_header']) && $GLOBALS['eel_force_sticky_header'] === true ) {
562 return preg_replace(
563 '/(class=["\'][^"\']*easy-site-header[^"\']*)/i',
564 '$1 eel-sticky-header-on',
565 $html
566 );
567 }
568 return $html;
569 });
570 });