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

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