PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.0.8
Easy Elements for Elementor – Addons & Website Templates v1.0.8
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 / inc / helper.php

helper.php in Easy Elements for Elementor – Addons & Website Templates 1.0.8, at inc/helper.php

325 lines 11.8 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 if ( ! function_exists( 'easyel_enable_svg_upload' ) ) {
7 function easyel_enable_svg_upload( $mimes ) {
8 $mimes['svg'] = 'image/svg+xml';
9 $mimes['svgz'] = 'image/svg+xml';
10 return $mimes;
11 }
12 add_filter( 'upload_mimes', 'easyel_enable_svg_upload' );
13 }
14
15 if ( ! function_exists( 'easyel_fix_svg_filetype' ) ) {
16 function easyel_fix_svg_filetype( $data, $file, $filename, $mimes ) {
17 $ext = pathinfo( $filename, PATHINFO_EXTENSION );
18 if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) {
19 $data['ext'] = 'svg';
20 $data['type'] = 'image/svg+xml';
21 }
22 return $data;
23 }
24 add_filter( 'wp_check_filetype_and_ext', 'easyel_fix_svg_filetype', 10, 4 );
25 }
26
27 if ( ! function_exists( 'easyel_handle_sideload_svg' ) ) {
28 function easyel_handle_sideload_svg( $file ) {
29 $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
30 if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) {
31 $file['type'] = 'image/svg+xml';
32 }
33 return $file;
34 }
35
36 add_filter( 'wp_handle_sideload_prefilter', 'easyel_handle_sideload_svg' );
37 }
38
39 if ( ! function_exists( 'easyel_get_cf7_forms' ) ) {
40 /**
41 * Get a list of all CF7 forms
42 *
43 * @return array
44 */
45 function easyel_get_cf7_forms() {
46 $forms = get_posts( [
47 'post_type' => 'wpcf7_contact_form',
48 'post_status' => 'publish',
49 'posts_per_page' => -1,
50 'orderby' => 'title',
51 'order' => 'ASC',
52 ] );
53
54 if ( ! empty( $forms ) ) {
55 return wp_list_pluck( $forms, 'post_title', 'ID' );
56 }
57 return [];
58 }
59 }
60
61
62 // Domain Search Code
63 add_action('template_redirect', function(){
64 // phpcs:ignore WordPress.Security.NonceVerification.Missing
65 if (isset($_POST['easyel_domain_redirect'])) {
66 // phpcs:ignore WordPress.Security.NonceVerification.Missing
67 $domain = isset($_POST['domain']) ? sanitize_text_field(wp_unslash($_POST['domain'])) : '';
68 // phpcs:ignore WordPress.Security.NonceVerification.Missing
69 $base_url = isset($_POST['base_url']) ? esc_url_raw( wp_unslash($_POST['base_url'] ) ) : '';
70
71 if ( !empty($domain) && !empty($base_url) && filter_var($base_url, FILTER_VALIDATE_URL) ) {
72 $redirect_url = esc_url_raw($base_url . urlencode($domain));
73 wp_redirect($redirect_url);
74 exit;
75 }
76 }
77 });
78
79 function easyel_get_extension_fields() {
80 $fields = [
81 'enable_cursor' => [
82 'label' => __('Magic Cursor', 'easy-elements'),
83 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/magic-cursor.svg',
84 'is_pro' => true,
85 'group' => 'GSAP Extensions',
86 'demo_url' => 'https://wpeasyelements.com/',
87 ],
88 'enable_sticky_elements' => [
89 'label' => __('Sticky Elements', 'easy-elements'),
90 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/sticky-elements.svg',
91 'is_pro' => true,
92 'group' => 'GSAP Extensions',
93 'demo_url' => 'https://wpeasyelements.com/',
94 ],
95 'enable_cursor_hover_effect' => [
96 'label' => __('Cursor Hover Effect', 'easy-elements'),
97 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/cursor-hover-effect.svg',
98 'is_pro' => true,
99 'group' => 'GSAP Extensions',
100 'demo_url' => 'https://wpeasyelements.com/',
101 ],
102 'enable_cursor_move_effect' => [
103 'label' => __('Cursor Move Effect', 'easy-elements'),
104 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/cursor-move-effect.svg',
105 'is_pro' => true,
106 'group' => 'GSAP Extensions',
107 'demo_url' => 'https://wpeasyelements.com/',
108 ],
109 'enable_scroll_trigger' => [
110 'label' => __('ScrollTrigger', 'easy-elements'),
111 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/scrolltrigger.svg',
112 'is_pro' => true,
113 'group' => 'GSAP Extensions',
114 'demo_url' => 'https://wpeasyelements.com/',
115 ],
116 'enable_parallax_image' => [
117 'label' => __('Background Parallax', 'easy-elements'),
118 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/background-parallax.svg',
119 'is_pro' => true,
120 'group' => 'GSAP Extensions',
121 'demo_url' => 'https://wpeasyelements.com/',
122 ],
123 'enable_drawsvg' => [
124 'label' => __('DrawSVG', 'easy-elements'),
125 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/drawsvg.svg',
126 'is_pro' => true,
127 'upcoming' => true,
128 'group' => 'GSAP Extensions',
129 'demo_url' => 'https://wpeasyelements.com/',
130 ],
131 'enable_image_3d_effect' => [
132 'label' => __('Image 3D Effect', 'easy-elements'),
133 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/image-3d-effect.svg',
134 'is_pro' => true,
135 'upcoming' => true,
136 'group' => 'GSAP Extensions',
137 'demo_url' => 'https://wpeasyelements.com/',
138 ],
139
140 'enable_wrapper_link' => [
141 'label' => __('Wrapper Link', 'easy-elements'),
142 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/wrapper-link.svg',
143 'is_pro' => false,
144 'group' => 'General Extensions',
145 'demo_url' => 'https://wpeasyelements.com/extensions/wrapper-link/',
146 'docx_url' => 'https://wpeasyelements.com/extensions/wrapper-link/',
147 ],
148
149 'enable_post_duplicator' => [
150 'label' => __('Duplicator', 'easy-elements'),
151 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/duplicator.svg',
152 'is_pro' => false,
153 'group' => 'General Extensions',
154 'demo_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
155 'docx_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/',
156 ],
157
158 'enable_postpage_export' => [
159 'label' => __('Easy Export', 'easy-elements'),
160 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/duplicator.svg',
161 'is_pro' => false,
162 'group' => 'General Extensions',
163 'demo_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/',
164 'docx_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/',
165 ],
166
167 'enable_visibility_control' => [
168 'label' => __('Visibility Control', 'easy-elements'),
169 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/visibility-control.svg',
170 'is_pro' => true,
171 'group' => 'General Extensions',
172 'demo_url' => 'https://wpeasyelements.com/',
173 ],
174 'enable_dynamic_content' => [
175 'label' => __('Dynamic Content', 'easy-elements'),
176 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/dynamic-content.svg',
177 'is_pro' => true,
178 'group' => 'General Extensions',
179 'demo_url' => 'https://wpeasyelements.com/',
180 ],
181 'enable_live_copy_paste' => [
182 'label' => __('Live Copy Paste', 'easy-elements'),
183 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/live-copy.svg',
184 'is_pro' => true,
185 'group' => 'General Extensions',
186 'demo_url' => 'https://wpeasyelements.com/',
187 ],
188 'enable_easy_custom_css' => [
189 'label' => __('Custom CSS', 'easy-elements'),
190 'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/easy-custom-css.svg',
191 'is_pro' => true,
192 'group' => 'General Extensions',
193 'demo_url' => 'https://wpeasyelements.com/',
194 ],
195
196 ];
197
198 return apply_filters('easyel_extension_fields', $fields);
199 }
200
201 add_action('deactivated_plugin', function($plugin) {
202
203 if ($plugin !== 'easy-elements-pro/easy-elements-pro.php') {
204 return;
205 }
206
207 if ($plugin === 'easy-elements-pro/easy-elements-pro.php') {
208 $available_elements = Easyel_Elements::get_instance()->easyel_elements_get_available_widgets();
209
210 foreach ($available_elements as $key => $widget) {
211 if (isset($widget['is_pro']) && $widget['is_pro']) {
212 update_option('easy_element_widget_' . $key, '0');
213 }
214 }
215 }
216
217 $extensions_settings = get_option('easy_element_extensions', []);
218 $fields = easyel_get_extension_fields();
219
220 foreach ($fields as $ext_key => $data) {
221 if (!empty($data['is_pro']) && $data['is_pro']) {
222 $extensions_settings[$ext_key] = 0;
223 }
224 }
225
226 update_option('easy_element_extensions', $extensions_settings);
227
228 });
229
230
231 function sanitize_conditions_array( $conditions ) {
232 if ( ! is_array( $conditions ) ) {
233 return [];
234 }
235
236 $sanitized = [];
237 foreach ( $conditions as $cond ) {
238 if ( ! is_array( $cond ) ) continue;
239
240 $sanitized[] = [
241 'include' => isset($cond['include']) ? sanitize_text_field($cond['include']) : 'include',
242 'main' => isset($cond['main']) ? sanitize_text_field($cond['main']) : '',
243 'sub' => isset($cond['sub']) ? sanitize_text_field($cond['sub']) : '',
244 ];
245 }
246
247 return $sanitized;
248 }
249
250 /**
251 * Safely decode JSON or return array as-is
252 */
253 function safe_json_decode( $data ) {
254 if ( is_string($data) ) {
255 $decoded = json_decode($data, true);
256 if ( json_last_error() === JSON_ERROR_NONE && is_array($decoded) ) {
257 return $decoded;
258 }
259 return [];
260 } elseif ( is_array($data) ) {
261 return $data;
262 } else {
263 return [];
264 }
265 }
266
267 class Easy_Widget_Injection {
268 public static function init() {
269 add_filter( 'elementor/controls/animations/additional_animations', [ __CLASS__, 'inject_easy_animations' ] );
270 }
271
272 public static function inject_easy_animations( $animations ) {
273 $animations['Easy Animations'] = [
274 'scaleIn' => __( 'Scale In', 'easy-elements' ),
275 ];
276 return $animations;
277 }
278 }
279
280 // Initialize the class
281 Easy_Widget_Injection::init();
282
283
284 /**
285 * Check if a specific Easy Element extension setting is enabled.
286 *
287 * @param string $setting_key The key of the setting to check (e.g. 'enable_sticky_elements').
288 * @return bool True if enabled, false otherwise.
289 */
290 function easy_element_is_enabled( $setting_key ) {
291 if ( empty( $setting_key ) ) {
292 return false;
293 }
294
295 $tab_slug = 'extensions';
296 $settings = get_option( 'easy_element_' . $tab_slug, [] );
297
298 // Sanitize and check
299 $value = isset( $settings[ $setting_key ] ) ? (int) $settings[ $setting_key ] : 0;
300
301 return ( $value === 1 );
302 }
303
304
305 function easyel_translate_hfe_template( $template_id ) {
306 if ( function_exists( 'pll_get_post' ) ) {
307 $translated = pll_get_post( $template_id );
308 if ( $translated ) {
309 $template_id = $translated;
310 }
311 }
312 if ( has_filter( 'wpml_object_id' ) ) {
313 $translated = apply_filters( 'wpml_object_id', $template_id, 'ee-elementor-hf', true );
314 if ( $translated ) {
315 $template_id = $translated;
316 }
317 }
318 return $template_id;
319 }
320
321 add_filter( 'easyel_get_settings_type_header', 'easyel_translate_hfe_template' );
322 add_filter( 'easyel_get_settings_type_footer', 'easyel_translate_hfe_template' );
323 add_filter( 'easyel_get_settings_type_easy_topbar', 'easyel_translate_hfe_template' );
324 add_filter( 'easyel_get_settings_type_easy_after__header', 'easyel_translate_hfe_template' );
325 add_filter( 'easyel_get_settings_type_before_footer', 'easyel_translate_hfe_template' );