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

536 lines 19.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_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 ],
111 'enable_sticky_elements' => [
112 'label' => __('Sticky Elements', 'easy-elements'),
113 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/sticky-elements.svg',
114 'is_pro' => true,
115 'group' => 'General Extensions',
116 'demo_url' => 'https://wpeasyelements.com/extensions/sticky-elements/',
117 ],
118 'enable_cursor_hover_effect' => [
119 'label' => __('Cursor Hover Effect', 'easy-elements'),
120 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-hover-effect.svg',
121 'is_pro' => true,
122 'group' => 'GSAP Extensions',
123 'demo_url' => 'https://wpeasyelements.com/extensions/cursor-hover-effect/',
124 ],
125 'enable_cursor_move_effect' => [
126 'label' => __('Cursor Move Effect', 'easy-elements'),
127 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-move-effect.svg',
128 'is_pro' => true,
129 'group' => 'GSAP Extensions',
130 'demo_url' => 'https://wpeasyelements.com/extensions/cursor-move-effect/',
131 ],
132 'enable_scroll_trigger' => [
133 'label' => __('ScrollTrigger', 'easy-elements'),
134 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/scrolltrigger.svg',
135 'is_pro' => true,
136 'group' => 'GSAP Extensions',
137 'demo_url' => 'https://wpeasyelements.com/extensions/scroll-trigger/',
138 ],
139 'enable_parallax_image' => [
140 'label' => __('Background Parallax', 'easy-elements'),
141 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/background-parallax.svg',
142 'is_pro' => true,
143 'group' => 'GSAP Extensions',
144 'demo_url' => 'https://wpeasyelements.com/extensions/background-parallax/',
145 ],
146 'enable_drawsvg' => [
147 'label' => __('DrawSVG', 'easy-elements'),
148 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/drawsvg.svg',
149 'is_pro' => true,
150 'upcoming' => true,
151 'group' => 'GSAP Extensions',
152 'demo_url' => '#',
153 ],
154 'enable_image_3d_effect' => [
155 'label' => __('Image 3D Effect', 'easy-elements'),
156 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
157 'is_pro' => true,
158 'upcoming' => true,
159 'group' => 'GSAP Extensions',
160 'demo_url' => '#',
161 ],
162 'enable_smooth_scroller' => [
163 'label' => __('Scroll Smoother', 'easy-elements'),
164 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
165 'is_pro' => true,
166 'setting' => true,
167 'group' => 'GSAP Extensions',
168 'demo_url' => 'https://wpeasyelements.com/extensions/scroll-smoother/',
169 'docx_url' => 'https://wpeasyelements.com/extensions/docs/scroll-smoother/',
170 ],
171 'enable_bounce_animation' => [
172 'label' => __('Bounce Animation', 'easy-elements'),
173 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg',
174 'is_pro' => true,
175 'group' => 'GSAP Extensions',
176 'demo_url' => 'https://wpeasyelements.com/extensions/bounce-animation/',
177 'docx_url' => 'https://wpeasyelements.com/extensions/docs/bounce-animation/',
178 ],
179 'enable_wrapper_link' => [
180 'label' => __('Wrapper Link', 'easy-elements'),
181 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/wrapper-link.svg',
182 'is_pro' => false,
183 'group' => 'General Extensions',
184 'demo_url' => 'https://wpeasyelements.com/extensions/wrapper-link/',
185 'docx_url' => 'https://wpeasyelements.com/extensions/wrapper-link/',
186 ],
187 'enable_post_duplicator' => [
188 'label' => __('Duplicator', 'easy-elements'),
189 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg',
190 'is_pro' => false,
191 'group' => 'General Extensions',
192 'demo_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
193 'docx_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
194 ],
195 'enable_postpage_export' => [
196 'label' => __('Easy Export', 'easy-elements'),
197 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg',
198 'is_pro' => false,
199 'group' => 'General Extensions',
200 'demo_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/',
201 'docx_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/',
202 ],
203 'enable_visibility_control' => [
204 'label' => __('Visibility Control', 'easy-elements'),
205 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/visibility-control.svg',
206 'is_pro' => true,
207 'group' => 'General Extensions',
208 'demo_url' => 'https://wpeasyelements.com/extensions/visibility-control/',
209 ],
210 'enable_dynamic_content' => [
211 'label' => __('Dynamic Content', 'easy-elements'),
212 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/dynamic-content.svg',
213 'is_pro' => true,
214 'group' => 'General Extensions',
215 'demo_url' => 'https://wpeasyelements.com/extensions/dynamic-content/',
216 ],
217 'enable_live_copy_paste' => [
218 'label' => __('Live Copy Paste', 'easy-elements'),
219 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/live-copy.svg',
220 'is_pro' => true,
221 'group' => 'General Extensions',
222 'demo_url' => 'https://wpeasyelements.com/extensions/live-copy/',
223 ],
224 'enable_easy_custom_css' => [
225 'label' => __('Custom CSS', 'easy-elements'),
226 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/easy-custom-css.svg',
227 'is_pro' => true,
228 'group' => 'General Extensions',
229 'demo_url' => 'https://wpeasyelements.com/docs/custom-css/',
230 ],
231 'enable_global_badge' => [
232 'label' => __('Global Badge', 'easy-elements'),
233 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/live-copy.svg',
234 'is_pro' => true,
235 'group' => 'General Extensions',
236 'demo_url' => 'https://wpeasyelements.com/extensions/global-badge/',
237 'docx_url' => 'https://wpeasyelements.com/extensions/docs/lobal-badge/',
238 ],
239 'enable_megamenu_builder' => [
240 'label' => __('Megamenu Builder', 'easy-elements'),
241 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/live-copy.svg',
242 'is_pro' => true,
243 'group' => 'General Extensions',
244 'demo_url' => 'https://wpeasyelements.com/megamenu-builder/',
245 'docx_url' => 'https://wpeasyelements.com/docs/megamenu-builder/',
246 ],
247 'enable_reading_progress_bar' => [
248 'label' => __('Reading Progress Bar', 'easy-elements'),
249 'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/progess.svg',
250 'is_pro' => false,
251 'setting' => true,
252 'group' => 'General Extensions',
253 'demo_url' => 'https://wpeasyelements.com/reading-progress-bar/',
254 'docx_url' => '#',
255 ],
256 ];
257
258 return apply_filters('easyel_extension_fields', $fields);
259 }
260
261 function sanitize_conditions_array( $conditions ) {
262 if ( ! is_array( $conditions ) ) {
263 return [];
264 }
265
266 $sanitized = [];
267 foreach ( $conditions as $cond ) {
268 if ( ! is_array( $cond ) ) continue;
269
270 $sanitized[] = [
271 'include' => isset($cond['include']) ? sanitize_text_field($cond['include']) : 'include',
272 'main' => isset($cond['main']) ? sanitize_text_field($cond['main']) : '',
273 'sub' => isset($cond['sub']) ? sanitize_text_field($cond['sub']) : '',
274 'child_sub' => isset($cond['child_sub']) ? sanitize_text_field($cond['child_sub']) : '',
275 ];
276 }
277
278 return $sanitized;
279 }
280
281 /**
282 * Safely decode JSON or return array as-is
283 */
284 function safe_json_decode( $data ) {
285 if ( is_string($data) ) {
286 $decoded = json_decode($data, true);
287 if ( json_last_error() === JSON_ERROR_NONE && is_array($decoded) ) {
288 return $decoded;
289 }
290 return [];
291 } elseif ( is_array($data) ) {
292 return $data;
293 } else {
294 return [];
295 }
296 }
297
298 class Easy_Widget_Injection {
299 public static function init() {
300 add_filter( 'elementor/controls/animations/additional_animations', [ __CLASS__, 'inject_easy_animations' ] );
301 }
302
303 public static function inject_easy_animations( $animations ) {
304 $animations['Easy Animations'] = [
305 'scaleIn' => __( 'Scale In', 'easy-elements' ),
306 ];
307 return $animations;
308 }
309 }
310
311 // Initialize the class
312 Easy_Widget_Injection::init();
313
314
315 /**
316 * Check if a specific Easy Element extension setting is enabled.
317 *
318 * @param string $setting_key The key of the setting to check (e.g. 'enable_sticky_elements').
319 * @return bool True if enabled, false otherwise.
320 */
321 function easy_element_is_enabled( $setting_key ) {
322 if ( empty( $setting_key ) ) {
323 return false;
324 }
325
326 $tab_slug = 'extensions';
327 $settings = get_option( 'easy_element_' . $tab_slug, [] );
328
329 // Sanitize and check
330 $value = isset( $settings[ $setting_key ] ) ? (int) $settings[ $setting_key ] : 0;
331
332 return ( $value === 1 );
333 }
334
335
336 function easyel_translate_hfe_template( $template_id ) {
337 if ( function_exists( 'pll_get_post' ) ) {
338 $translated = pll_get_post( $template_id );
339 if ( $translated ) {
340 $template_id = $translated;
341 }
342 }
343 if ( has_filter( 'wpml_object_id' ) ) {
344 $translated = apply_filters( 'wpml_object_id', $template_id, 'ee-elementor-hf', true );
345 if ( $translated ) {
346 $template_id = $translated;
347 }
348 }
349 return $template_id;
350 }
351
352 add_filter( 'easyel_get_settings_type_header', 'easyel_translate_hfe_template' );
353 add_filter( 'easyel_get_settings_type_footer', 'easyel_translate_hfe_template' );
354 add_filter( 'easyel_get_settings_type_easy_topbar', 'easyel_translate_hfe_template' );
355 add_filter( 'easyel_get_settings_type_easy_after__header', 'easyel_translate_hfe_template' );
356 add_filter( 'easyel_get_settings_type_before_footer', 'easyel_translate_hfe_template' );
357
358 if ( ! function_exists( 'easyel_get_valid_archive_post_types' ) ) {
359 function easyel_get_valid_archive_post_types() {
360
361 $post_types = get_post_types(
362 [
363 'public' => true,
364 'show_in_nav_menus' => true,
365 ],
366 'objects'
367 );
368
369 $valid = [];
370
371 foreach ( $post_types as $post_type => $pt ) {
372
373 if ( ! $pt->has_archive || ! get_post_type_archive_link( $post_type ) ) {
374 continue;
375 }
376
377 if ( $post_type === 'page' ) {
378 continue;
379 }
380
381 if (
382 ! empty( $pt->_builtin ) === false &&
383 str_starts_with( $post_type, 'elementor' )
384 ) {
385 continue;
386 }
387
388 if ( ! $pt->publicly_queryable ) {
389 continue;
390 }
391
392 $valid[ $post_type ] = $pt;
393 }
394
395 return $valid;
396 }
397 }
398
399 if ( ! function_exists( 'easyel_get_hierarchical_taxonomies_by_post_type' ) ) {
400 function easyel_get_hierarchical_taxonomies_by_post_type() {
401
402 $map = [];
403 $post_types = easyel_get_valid_archive_post_types();
404
405 foreach ($post_types as $post_type => $pt) {
406 $taxonomies = get_object_taxonomies($post_type, 'objects');
407
408 foreach ($taxonomies as $tax_slug => $tax) {
409 if (!$tax->public) {
410 continue;
411 }
412
413 $map[$tax_slug] = [
414 'post_type' => $post_type,
415 'taxonomy' => $tax_slug,
416 ];
417 }
418 }
419
420 return $map;
421 }
422 }
423
424 if ( ! function_exists('easyel_theme_builder_child_options') ) {
425 /**
426 * Get global condition arrays: needs_child_sub & no_child_sub
427 *
428 * @return array
429 */
430 function easyel_theme_builder_child_options() {
431 // Default needs_child_sub
432 $needs_child_sub = [
433 'author',
434 'category',
435 'child_of_category',
436 'any_child_of_category',
437 'in_category',
438 'in_category_children',
439 'post_tag',
440 'in_post_tag',
441 'child_of',
442 'any_child_of',
443 'product_cat',
444 'product_tag',
445 'product_brand',
446 'post',
447 'page',
448 'page_by_author',
449 ];
450
451 // Default no_child_sub
452 $no_child_sub = [
453 "all",
454 "front_page",
455 "not_found404",
456 "index",
457 "search",
458 "date",
459 "post_archive",
460 "all_product_archive",
461 "product_search",
462 "shop_page",
463 ];
464
465 // Get dynamic archive taxonomies
466 $archive_taxonomies = function_exists('easyel_get_hierarchical_taxonomies_by_post_type')
467 ? easyel_get_hierarchical_taxonomies_by_post_type()
468 : [];
469
470 if ( is_array($archive_taxonomies) || is_object($archive_taxonomies) ) {
471 foreach ($archive_taxonomies as $tax_slug => $data) {
472 $needs_child_sub[] = $tax_slug;
473 $needs_child_sub[] = 'child_of_' . $tax_slug;
474 $needs_child_sub[] = 'any_child_of_' . $tax_slug;
475
476 $needs_child_sub[] = 'in_' . $tax_slug;
477 $needs_child_sub[] = 'in_' . $tax_slug . '_children';
478 $needs_child_sub[] = $data['post_type'] . '_by_author';
479
480 if ( ! empty($data['post_type']) ) {
481 $no_child_sub[] = $data['post_type']."_archive";
482 $needs_child_sub[] = $data['post_type'];
483 }
484 }
485 }
486
487 return [
488 'needs_child_sub' => $needs_child_sub,
489 'no_child_sub' => $no_child_sub,
490 ];
491 }
492 }
493
494 if ( ! function_exists( 'easyel_get_prepared_post_id' ) ) {
495 function easyel_get_prepared_post_id() {
496
497 if ( is_singular( 'post' ) ) {
498 return get_the_ID();
499 }
500
501 $cache_key = 'easyel_latest_post_id';
502 $post_id = wp_cache_get( $cache_key, 'easyel' );
503
504 if ( ! $post_id || get_post_status( $post_id ) !== 'publish' ) {
505
506 $latest_post = get_posts([
507 'post_type' => 'post',
508 'post_status' => 'publish',
509 'posts_per_page' => 1,
510 'orderby' => 'date',
511 'order' => 'DESC',
512 'fields' => 'ids',
513 ]);
514
515 $post_id = !empty($latest_post) ? $latest_post[0] : 0;
516
517 wp_cache_set( $cache_key, $post_id, 'easyel', 12 * HOUR_IN_SECONDS );
518 }
519
520 return $post_id;
521 }
522 }
523
524 // Sticky Header On
525 add_action('template_redirect', function() {
526 ob_start(function ($html) {
527 if ( isset($GLOBALS['eel_force_sticky_header']) && $GLOBALS['eel_force_sticky_header'] === true ) {
528 return preg_replace(
529 '/(class=["\'][^"\']*easy-site-header[^"\']*)/i',
530 '$1 eel-sticky-header-on',
531 $html
532 );
533 }
534 return $html;
535 });
536 });