| 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' => 'General 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_smooth_scroller' => [ |
| 141 |
'label' => __('Scroll Smoother', 'easy-elements'), |
| 142 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/image-3d-effect.svg', |
| 143 |
'is_pro' => true, |
| 144 |
'setting' => true, |
| 145 |
'group' => 'GSAP Extensions', |
| 146 |
'demo_url' => 'https://wpeasyelements.com/extensions/scroll-smoother/', |
| 147 |
'docx_url' => 'https://wpeasyelements.com/extensions/docs/scroll-smoother/', |
| 148 |
], |
| 149 |
|
| 150 |
'enable_wrapper_link' => [ |
| 151 |
'label' => __('Wrapper Link', 'easy-elements'), |
| 152 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/wrapper-link.svg', |
| 153 |
'is_pro' => false, |
| 154 |
'group' => 'General Extensions', |
| 155 |
'demo_url' => 'https://wpeasyelements.com/extensions/wrapper-link/', |
| 156 |
'docx_url' => 'https://wpeasyelements.com/extensions/wrapper-link/', |
| 157 |
], |
| 158 |
|
| 159 |
'enable_post_duplicator' => [ |
| 160 |
'label' => __('Duplicator', 'easy-elements'), |
| 161 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/duplicator.svg', |
| 162 |
'is_pro' => false, |
| 163 |
'group' => 'General Extensions', |
| 164 |
'demo_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/', |
| 165 |
'docx_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/', |
| 166 |
], |
| 167 |
|
| 168 |
'enable_postpage_export' => [ |
| 169 |
'label' => __('Easy Export', 'easy-elements'), |
| 170 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/duplicator.svg', |
| 171 |
'is_pro' => false, |
| 172 |
'group' => 'General Extensions', |
| 173 |
'demo_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/', |
| 174 |
'docx_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/', |
| 175 |
], |
| 176 |
|
| 177 |
'enable_visibility_control' => [ |
| 178 |
'label' => __('Visibility Control', 'easy-elements'), |
| 179 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/visibility-control.svg', |
| 180 |
'is_pro' => true, |
| 181 |
'group' => 'General Extensions', |
| 182 |
'demo_url' => 'https://wpeasyelements.com/', |
| 183 |
], |
| 184 |
'enable_dynamic_content' => [ |
| 185 |
'label' => __('Dynamic Content', 'easy-elements'), |
| 186 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/dynamic-content.svg', |
| 187 |
'is_pro' => true, |
| 188 |
'group' => 'General Extensions', |
| 189 |
'demo_url' => 'https://wpeasyelements.com/', |
| 190 |
], |
| 191 |
'enable_live_copy_paste' => [ |
| 192 |
'label' => __('Live Copy Paste', 'easy-elements'), |
| 193 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/live-copy.svg', |
| 194 |
'is_pro' => true, |
| 195 |
'group' => 'General Extensions', |
| 196 |
'demo_url' => 'https://wpeasyelements.com/', |
| 197 |
], |
| 198 |
'enable_easy_custom_css' => [ |
| 199 |
'label' => __('Custom CSS', 'easy-elements'), |
| 200 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/easy-custom-css.svg', |
| 201 |
'is_pro' => true, |
| 202 |
'group' => 'General Extensions', |
| 203 |
'demo_url' => 'https://wpeasyelements.com/', |
| 204 |
], |
| 205 |
'enable_global_badge' => [ |
| 206 |
'label' => __('Global Badge', 'easy-elements'), |
| 207 |
'icon' => EASYELEMENTS_DIR_URL . 'admin/icons/extension/live-copy.svg', |
| 208 |
'is_pro' => true, |
| 209 |
'group' => 'General Extensions', |
| 210 |
'demo_url' => 'https://wpeasyelements.com/extensions/docs/global-badge/', |
| 211 |
'docx_url' => 'https://wpeasyelements.com/extensions/docs/lobal-badge/', |
| 212 |
], |
| 213 |
|
| 214 |
]; |
| 215 |
|
| 216 |
return apply_filters('easyel_extension_fields', $fields); |
| 217 |
} |
| 218 |
|
| 219 |
function sanitize_conditions_array( $conditions ) { |
| 220 |
if ( ! is_array( $conditions ) ) { |
| 221 |
return []; |
| 222 |
} |
| 223 |
|
| 224 |
$sanitized = []; |
| 225 |
foreach ( $conditions as $cond ) { |
| 226 |
if ( ! is_array( $cond ) ) continue; |
| 227 |
|
| 228 |
$sanitized[] = [ |
| 229 |
'include' => isset($cond['include']) ? sanitize_text_field($cond['include']) : 'include', |
| 230 |
'main' => isset($cond['main']) ? sanitize_text_field($cond['main']) : '', |
| 231 |
'sub' => isset($cond['sub']) ? sanitize_text_field($cond['sub']) : '', |
| 232 |
]; |
| 233 |
} |
| 234 |
|
| 235 |
return $sanitized; |
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Safely decode JSON or return array as-is |
| 240 |
*/ |
| 241 |
function safe_json_decode( $data ) { |
| 242 |
if ( is_string($data) ) { |
| 243 |
$decoded = json_decode($data, true); |
| 244 |
if ( json_last_error() === JSON_ERROR_NONE && is_array($decoded) ) { |
| 245 |
return $decoded; |
| 246 |
} |
| 247 |
return []; |
| 248 |
} elseif ( is_array($data) ) { |
| 249 |
return $data; |
| 250 |
} else { |
| 251 |
return []; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
class Easy_Widget_Injection { |
| 256 |
public static function init() { |
| 257 |
add_filter( 'elementor/controls/animations/additional_animations', [ __CLASS__, 'inject_easy_animations' ] ); |
| 258 |
} |
| 259 |
|
| 260 |
public static function inject_easy_animations( $animations ) { |
| 261 |
$animations['Easy Animations'] = [ |
| 262 |
'scaleIn' => __( 'Scale In', 'easy-elements' ), |
| 263 |
]; |
| 264 |
return $animations; |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
// Initialize the class |
| 269 |
Easy_Widget_Injection::init(); |
| 270 |
|
| 271 |
|
| 272 |
/** |
| 273 |
* Check if a specific Easy Element extension setting is enabled. |
| 274 |
* |
| 275 |
* @param string $setting_key The key of the setting to check (e.g. 'enable_sticky_elements'). |
| 276 |
* @return bool True if enabled, false otherwise. |
| 277 |
*/ |
| 278 |
function easy_element_is_enabled( $setting_key ) { |
| 279 |
if ( empty( $setting_key ) ) { |
| 280 |
return false; |
| 281 |
} |
| 282 |
|
| 283 |
$tab_slug = 'extensions'; |
| 284 |
$settings = get_option( 'easy_element_' . $tab_slug, [] ); |
| 285 |
|
| 286 |
// Sanitize and check |
| 287 |
$value = isset( $settings[ $setting_key ] ) ? (int) $settings[ $setting_key ] : 0; |
| 288 |
|
| 289 |
return ( $value === 1 ); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
function easyel_translate_hfe_template( $template_id ) { |
| 294 |
if ( function_exists( 'pll_get_post' ) ) { |
| 295 |
$translated = pll_get_post( $template_id ); |
| 296 |
if ( $translated ) { |
| 297 |
$template_id = $translated; |
| 298 |
} |
| 299 |
} |
| 300 |
if ( has_filter( 'wpml_object_id' ) ) { |
| 301 |
$translated = apply_filters( 'wpml_object_id', $template_id, 'ee-elementor-hf', true ); |
| 302 |
if ( $translated ) { |
| 303 |
$template_id = $translated; |
| 304 |
} |
| 305 |
} |
| 306 |
return $template_id; |
| 307 |
} |
| 308 |
|
| 309 |
add_filter( 'easyel_get_settings_type_header', 'easyel_translate_hfe_template' ); |
| 310 |
add_filter( 'easyel_get_settings_type_footer', 'easyel_translate_hfe_template' ); |
| 311 |
add_filter( 'easyel_get_settings_type_easy_topbar', 'easyel_translate_hfe_template' ); |
| 312 |
add_filter( 'easyel_get_settings_type_easy_after__header', 'easyel_translate_hfe_template' ); |
| 313 |
add_filter( 'easyel_get_settings_type_before_footer', 'easyel_translate_hfe_template' ); |