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

561 lines 21.2 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/live-copy.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/live-copy.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/progess.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/progess.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 ];
280
281 return apply_filters('easyel_extension_fields', $fields);
282 }
283
284 function easyel_sanitize_conditions_array( $conditions ) {
285 if ( ! is_array( $conditions ) ) {
286 return [];
287 }
288
289 $sanitized = [];
290 foreach ( $conditions as $cond ) {
291 if ( ! is_array( $cond ) ) continue;
292
293 $sanitized[] = [
294 'include' => isset($cond['include']) ? sanitize_text_field($cond['include']) : 'include',
295 'main' => isset($cond['main']) ? sanitize_text_field($cond['main']) : '',
296 'sub' => isset($cond['sub']) ? sanitize_text_field($cond['sub']) : '',
297 'child_sub' => isset($cond['child_sub']) ? sanitize_text_field($cond['child_sub']) : '',
298 ];
299 }
300
301 return $sanitized;
302 }
303
304 /**
305 * Safely decode JSON or return array as-is
306 */
307 function easyel_safe_json_decode( $data ) {
308 if ( is_string($data) ) {
309 $decoded = json_decode($data, true);
310 if ( json_last_error() === JSON_ERROR_NONE && is_array($decoded) ) {
311 return $decoded;
312 }
313 return [];
314 } elseif ( is_array($data) ) {
315 return $data;
316 } else {
317 return [];
318 }
319 }
320
321 class Easy_Widget_Injection {
322 public static function init() {
323 add_filter( 'elementor/controls/animations/additional_animations', [ __CLASS__, 'inject_easy_animations' ] );
324 }
325
326 public static function inject_easy_animations( $animations ) {
327 $animations['Easy Animations'] = [
328 'scaleIn' => __( 'Scale In', 'easy-elements' ),
329 ];
330 return $animations;
331 }
332 }
333
334 // Initialize the class
335 Easy_Widget_Injection::init();
336
337
338 /**
339 * Check if a specific Easy Element extension setting is enabled.
340 *
341 * @param string $setting_key The key of the setting to check (e.g. 'enable_sticky_elements').
342 * @return bool True if enabled, false otherwise.
343 */
344 function easy_element_is_enabled( $setting_key ) {
345 if ( empty( $setting_key ) ) {
346 return false;
347 }
348
349 $tab_slug = 'extensions';
350 $settings = get_option( 'easy_element_' . $tab_slug, [] );
351
352 // Sanitize and check
353 $value = isset( $settings[ $setting_key ] ) ? (int) $settings[ $setting_key ] : 0;
354
355 return ( $value === 1 );
356 }
357
358
359 function easyel_translate_hfe_template( $template_id ) {
360 if ( function_exists( 'pll_get_post' ) ) {
361 $translated = pll_get_post( $template_id );
362 if ( $translated ) {
363 $template_id = $translated;
364 }
365 }
366 if ( has_filter( 'wpml_object_id' ) ) {
367
368 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
369 $translated = apply_filters( 'wpml_object_id', $template_id, 'ee-elementor-hf', true );
370 if ( $translated ) {
371 $template_id = $translated;
372 }
373 }
374 return $template_id;
375 }
376
377 add_filter( 'easyel_get_settings_type_header', 'easyel_translate_hfe_template' );
378 add_filter( 'easyel_get_settings_type_footer', 'easyel_translate_hfe_template' );
379 add_filter( 'easyel_get_settings_type_easy_topbar', 'easyel_translate_hfe_template' );
380 add_filter( 'easyel_get_settings_type_easy_after__header', 'easyel_translate_hfe_template' );
381 add_filter( 'easyel_get_settings_type_before_footer', 'easyel_translate_hfe_template' );
382
383 if ( ! function_exists( 'easyel_get_valid_archive_post_types' ) ) {
384 function easyel_get_valid_archive_post_types() {
385
386 $post_types = get_post_types(
387 [
388 'public' => true,
389 'show_in_nav_menus' => true,
390 ],
391 'objects'
392 );
393
394 $valid = [];
395
396 foreach ( $post_types as $post_type => $pt ) {
397
398 if ( ! $pt->has_archive || ! get_post_type_archive_link( $post_type ) ) {
399 continue;
400 }
401
402 if ( $post_type === 'page' ) {
403 continue;
404 }
405
406 if (
407 ! empty( $pt->_builtin ) === false &&
408 str_starts_with( $post_type, 'elementor' )
409 ) {
410 continue;
411 }
412
413 if ( ! $pt->publicly_queryable ) {
414 continue;
415 }
416
417 $valid[ $post_type ] = $pt;
418 }
419
420 return $valid;
421 }
422 }
423
424 if ( ! function_exists( 'easyel_get_hierarchical_taxonomies_by_post_type' ) ) {
425 function easyel_get_hierarchical_taxonomies_by_post_type() {
426
427 $map = [];
428 $post_types = easyel_get_valid_archive_post_types();
429
430 foreach ($post_types as $post_type => $pt) {
431 $taxonomies = get_object_taxonomies($post_type, 'objects');
432
433 foreach ($taxonomies as $tax_slug => $tax) {
434 if (!$tax->public) {
435 continue;
436 }
437
438 $map[$tax_slug] = [
439 'post_type' => $post_type,
440 'taxonomy' => $tax_slug,
441 ];
442 }
443 }
444
445 return $map;
446 }
447 }
448
449 if ( ! function_exists('easyel_theme_builder_child_options') ) {
450 /**
451 * Get global condition arrays: needs_child_sub & no_child_sub
452 *
453 * @return array
454 */
455 function easyel_theme_builder_child_options() {
456 // Default needs_child_sub
457 $needs_child_sub = [
458 'author',
459 'category',
460 'child_of_category',
461 'any_child_of_category',
462 'in_category',
463 'in_category_children',
464 'post_tag',
465 'in_post_tag',
466 'child_of',
467 'any_child_of',
468 'product_cat',
469 'product_tag',
470 'product_brand',
471 'post',
472 'page',
473 'page_by_author',
474 ];
475
476 // Default no_child_sub
477 $no_child_sub = [
478 "all",
479 "front_page",
480 "not_found404",
481 "index",
482 "search",
483 "date",
484 "post_archive",
485 "all_product_archive",
486 "product_search",
487 "shop_page",
488 ];
489
490 // Get dynamic archive taxonomies
491 $archive_taxonomies = function_exists('easyel_get_hierarchical_taxonomies_by_post_type')
492 ? easyel_get_hierarchical_taxonomies_by_post_type()
493 : [];
494
495 if ( is_array($archive_taxonomies) || is_object($archive_taxonomies) ) {
496 foreach ($archive_taxonomies as $tax_slug => $data) {
497 $needs_child_sub[] = $tax_slug;
498 $needs_child_sub[] = 'child_of_' . $tax_slug;
499 $needs_child_sub[] = 'any_child_of_' . $tax_slug;
500
501 $needs_child_sub[] = 'in_' . $tax_slug;
502 $needs_child_sub[] = 'in_' . $tax_slug . '_children';
503 $needs_child_sub[] = $data['post_type'] . '_by_author';
504
505 if ( ! empty($data['post_type']) ) {
506 $no_child_sub[] = $data['post_type']."_archive";
507 $needs_child_sub[] = $data['post_type'];
508 }
509 }
510 }
511
512 return [
513 'needs_child_sub' => $needs_child_sub,
514 'no_child_sub' => $no_child_sub,
515 ];
516 }
517 }
518
519 if ( ! function_exists( 'easyel_get_prepared_post_id' ) ) {
520 function easyel_get_prepared_post_id() {
521
522 if ( is_singular( 'post' ) ) {
523 return get_the_ID();
524 }
525
526 $cache_key = 'easyel_latest_post_id';
527 $post_id = wp_cache_get( $cache_key, 'easyel' );
528
529 if ( ! $post_id || get_post_status( $post_id ) !== 'publish' ) {
530
531 $latest_post = get_posts([
532 'post_type' => 'post',
533 'post_status' => 'publish',
534 'posts_per_page' => 1,
535 'orderby' => 'date',
536 'order' => 'DESC',
537 'fields' => 'ids',
538 ]);
539
540 $post_id = !empty($latest_post) ? $latest_post[0] : 0;
541
542 wp_cache_set( $cache_key, $post_id, 'easyel', 12 * HOUR_IN_SECONDS );
543 }
544
545 return $post_id;
546 }
547 }
548
549 // Sticky Header On
550 add_action('template_redirect', function() {
551 ob_start(function ($html) {
552 if ( isset($GLOBALS['eel_force_sticky_header']) && $GLOBALS['eel_force_sticky_header'] === true ) {
553 return preg_replace(
554 '/(class=["\'][^"\']*easy-site-header[^"\']*)/i',
555 '$1 eel-sticky-header-on',
556 $html
557 );
558 }
559 return $html;
560 });
561 });