Admin.php
3 years ago
Ajax_Handler.php
2 years ago
Controls.php
2 years ago
Core.php
3 years ago
Elements.php
2 years ago
Enqueue.php
3 years ago
Facebook_Feed.php
3 years ago
Helper.php
2 years ago
Library.php
3 years ago
Login_Registration.php
2 years ago
Shared.php
5 years ago
Template_Query.php
4 years ago
Twitter_Feed.php
2 years ago
Woo_Product_Comparable.php
3 years ago
index.php
3 years ago
Ajax_Handler.php
1103 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class trait Ajax_Handler file |
| 4 | * |
| 5 | * @package Essential-addons-for-elementor-lite\Traits |
| 6 | */ |
| 7 | |
| 8 | namespace Essential_Addons_Elementor\Traits; |
| 9 | |
| 10 | use Essential_Addons_Elementor\Classes\Helper as HelperClass; |
| 11 | use Essential_Addons_Elementor\Template\Woocommerce\Checkout\Woo_Checkout_Helper; |
| 12 | use Essential_Addons_Elementor\Traits\Template_Query; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // Exit if accessed directly |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Essential Addons ajax request handler |
| 20 | * |
| 21 | * Manage all ajax request for EA |
| 22 | * |
| 23 | * @class Ajax_Handler |
| 24 | * @since 5.0.9 |
| 25 | * @package Essential-addons-for-elementor-lite\Traits |
| 26 | */ |
| 27 | trait Ajax_Handler { |
| 28 | //use Template_Query; |
| 29 | /** |
| 30 | * init_ajax_hooks |
| 31 | */ |
| 32 | public function init_ajax_hooks() { |
| 33 | |
| 34 | add_action( 'wp_ajax_load_more', array( $this, 'ajax_load_more' ) ); |
| 35 | add_action( 'wp_ajax_nopriv_load_more', array( $this, 'ajax_load_more' ) ); |
| 36 | |
| 37 | add_action( 'wp_ajax_woo_product_pagination_product', array( $this, 'eael_woo_pagination_product_ajax' ) ); |
| 38 | add_action( 'wp_ajax_nopriv_woo_product_pagination_product', array( $this, 'eael_woo_pagination_product_ajax' ) ); |
| 39 | |
| 40 | add_action( 'wp_ajax_woo_product_pagination', array( $this, 'eael_woo_pagination_ajax' ) ); |
| 41 | add_action( 'wp_ajax_nopriv_woo_product_pagination', array( $this, 'eael_woo_pagination_ajax' ) ); |
| 42 | |
| 43 | add_action( 'wp_ajax_eael_product_add_to_cart', array( $this, 'eael_product_add_to_cart' ) ); |
| 44 | add_action( 'wp_ajax_nopriv_eael_product_add_to_cart', array( $this, 'eael_product_add_to_cart' ) ); |
| 45 | |
| 46 | add_action( 'wp_ajax_woo_checkout_update_order_review', [ $this, 'woo_checkout_update_order_review' ] ); |
| 47 | add_action( 'wp_ajax_nopriv_woo_checkout_update_order_review', [ $this, 'woo_checkout_update_order_review' ] ); |
| 48 | |
| 49 | add_action( 'wp_ajax_nopriv_eael_product_quickview_popup', [ $this, 'eael_product_quickview_popup' ] ); |
| 50 | add_action( 'wp_ajax_eael_product_quickview_popup', [ $this, 'eael_product_quickview_popup' ] ); |
| 51 | |
| 52 | add_action( 'wp_ajax_nopriv_eael_product_gallery', [ $this, 'ajax_eael_product_gallery' ] ); |
| 53 | add_action( 'wp_ajax_eael_product_gallery', [ $this, 'ajax_eael_product_gallery' ] ); |
| 54 | |
| 55 | add_action( 'wp_ajax_eael_select2_search_post', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); |
| 56 | add_action( 'wp_ajax_nopriv_eael_select2_search_post', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); |
| 57 | |
| 58 | add_action( 'wp_ajax_eael_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); |
| 59 | add_action( 'wp_ajax_nopriv_eael_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); |
| 60 | |
| 61 | if ( is_admin() ) { |
| 62 | add_action( 'wp_ajax_save_settings_with_ajax', array( $this, 'save_settings' ) ); |
| 63 | add_action( 'wp_ajax_clear_cache_files_with_ajax', array( $this, 'clear_cache_files' ) ); |
| 64 | add_action( 'wp_ajax_eael_admin_promotion', array( $this, 'eael_admin_promotion' ) ); |
| 65 | } |
| 66 | |
| 67 | add_action( 'wp_ajax_eael_get_token', [ $this, 'eael_get_token' ] ); |
| 68 | add_action( 'wp_ajax_nopriv_eael_get_token', [ $this, 'eael_get_token' ] ); |
| 69 | |
| 70 | add_action( 'eael_before_woo_pagination_product_ajax_start', [ $this, 'eael_yith_wcwl_ajax_disable' ] ); |
| 71 | add_action( 'eael_before_ajax_load_more', [ $this, 'eael_yith_wcwl_ajax_disable' ] ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Ajax Load More |
| 76 | * This function is responsible for get the post data. |
| 77 | * It will return HTML markup with AJAX call and with normal call. |
| 78 | * |
| 79 | * @access public |
| 80 | * @return false|void of a html markup with AJAX call. |
| 81 | * @return array of content and found posts count without AJAX call. |
| 82 | * @since 3.1.0 |
| 83 | */ |
| 84 | public function ajax_load_more() { |
| 85 | $ajax = wp_doing_ajax(); |
| 86 | |
| 87 | do_action( 'eael_before_ajax_load_more', $_REQUEST ); |
| 88 | |
| 89 | wp_parse_str( $_POST['args'], $args ); |
| 90 | |
| 91 | if ( isset( $args['date_query']['relation'] ) ) { |
| 92 | $args['date_query']['relation'] = HelperClass::eael_sanitize_relation( $args['date_query']['relation'] ); |
| 93 | } |
| 94 | |
| 95 | if ( empty( $_POST['nonce'] ) ) { |
| 96 | $err_msg = __( 'Insecure form submitted without security token', 'essential-addons-for-elementor-lite' ); |
| 97 | if ( $ajax ) { |
| 98 | wp_send_json_error( $err_msg ); |
| 99 | } |
| 100 | |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | if ( ! wp_verify_nonce( $_POST['nonce'], 'load_more' ) && ! wp_verify_nonce( $_POST['nonce'], 'essential-addons-elementor' ) ) { |
| 105 | $err_msg = __( 'Security token did not match', 'essential-addons-for-elementor-lite' ); |
| 106 | if ( $ajax ) { |
| 107 | wp_send_json_error( $err_msg ); |
| 108 | } |
| 109 | |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | if ( ! empty( $_POST['page_id'] ) ) { |
| 114 | $page_id = intval( $_POST['page_id'], 10 ); |
| 115 | } else { |
| 116 | $err_msg = __( 'Page ID is missing', 'essential-addons-for-elementor-lite' ); |
| 117 | if ( $ajax ) { |
| 118 | wp_send_json_error( $err_msg ); |
| 119 | } |
| 120 | |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | if ( ! empty( $_POST['widget_id'] ) ) { |
| 125 | $widget_id = sanitize_text_field( $_POST['widget_id'] ); |
| 126 | } else { |
| 127 | $err_msg = __( 'Widget ID is missing', 'essential-addons-for-elementor-lite' ); |
| 128 | if ( $ajax ) { |
| 129 | wp_send_json_error( $err_msg ); |
| 130 | } |
| 131 | |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | $settings = HelperClass::eael_get_widget_settings( $page_id, $widget_id ); |
| 136 | |
| 137 | if ( empty( $settings ) ) { |
| 138 | wp_send_json_error( [ 'message' => __( 'Widget settings are not found. Did you save the widget before using load more??', 'essential-addons-for-elementor-lite' ) ] ); |
| 139 | } |
| 140 | |
| 141 | $settings['eael_widget_id'] = $widget_id; |
| 142 | $settings['eael_page_id'] = $page_id; |
| 143 | $html = ''; |
| 144 | $class = '\\' . str_replace( '\\\\', '\\', $_REQUEST['class'] ); |
| 145 | $args['offset'] = (int) $args['offset'] + ( ( (int) $_REQUEST['page'] - 1 ) * (int) $args['posts_per_page'] ); |
| 146 | |
| 147 | if ( isset( $_REQUEST['taxonomy'] ) && isset( $_REQUEST['taxonomy']['taxonomy'] ) && $_REQUEST['taxonomy']['taxonomy'] != 'all' ) { |
| 148 | $args['tax_query'] = [ |
| 149 | $this->sanitize_taxonomy_data( $_REQUEST['taxonomy'] ), |
| 150 | ]; |
| 151 | |
| 152 | $args['tax_query'] = $this->eael_terms_query_multiple( $args['tax_query'] ); |
| 153 | } |
| 154 | |
| 155 | if ( $class == '\Essential_Addons_Elementor\Elements\Post_Grid' ) { |
| 156 | $settings['read_more_button_text'] = get_transient( 'eael_post_grid_read_more_button_text_' . $widget_id ); |
| 157 | $settings['excerpt_expanison_indicator'] = get_transient( 'eael_post_grid_excerpt_expanison_indicator_' . $widget_id ); |
| 158 | |
| 159 | if ( $settings['orderby'] === 'rand' ) { |
| 160 | $args['post__not_in'] = array_map( 'intval', array_unique( $_REQUEST['post__not_in'] ) ); |
| 161 | unset( $args['offset'] ); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // ensure control name compatibility to old code if it is post block |
| 166 | if ( $class === '\Essential_Addons_Elementor\Pro\Elements\Post_Block' ) { |
| 167 | $settings ['post_block_hover_animation'] = $settings['eael_post_block_hover_animation']; |
| 168 | $settings ['show_read_more_button'] = $settings['eael_show_read_more_button']; |
| 169 | $settings ['eael_post_block_bg_hover_icon'] = ( isset( $settings['__fa4_migrated']['eael_post_block_bg_hover_icon_new'] ) || empty( $settings['eael_post_block_bg_hover_icon'] ) ) ? $settings['eael_post_block_bg_hover_icon_new']['value'] : $settings['eael_post_block_bg_hover_icon']; |
| 170 | $settings ['expanison_indicator'] = $settings['excerpt_expanison_indicator']; |
| 171 | } |
| 172 | if ( $class === '\Essential_Addons_Elementor\Elements\Post_Timeline' ) { |
| 173 | $settings ['expanison_indicator'] = $settings['excerpt_expanison_indicator']; |
| 174 | } |
| 175 | if ( $class === '\Essential_Addons_Elementor\Pro\Elements\Dynamic_Filterable_Gallery' ) { |
| 176 | $settings['eael_section_fg_zoom_icon'] = ( isset( $settings['__fa4_migrated']['eael_section_fg_zoom_icon_new'] ) || empty( $settings['eael_section_fg_zoom_icon'] ) ? $settings['eael_section_fg_zoom_icon_new']['value'] : $settings['eael_section_fg_zoom_icon'] ); |
| 177 | $settings['eael_section_fg_link_icon'] = ( isset( $settings['__fa4_migrated']['eael_section_fg_link_icon_new'] ) || empty( $settings['eael_section_fg_link_icon'] ) ? $settings['eael_section_fg_link_icon_new']['value'] : $settings['eael_section_fg_link_icon'] ); |
| 178 | $settings['show_load_more_text'] = $settings['eael_fg_loadmore_btn_text']; |
| 179 | $settings['layout_mode'] = isset( $settings['layout_mode'] ) ? $settings['layout_mode'] : 'masonry'; |
| 180 | |
| 181 | $exclude_ids = json_decode( html_entity_decode( stripslashes ( $_POST['exclude_ids'] ) ) ); |
| 182 | $args['post__not_in'] = ( !empty( $_POST['exclude_ids'] ) ) ? array_map( 'intval', array_unique($exclude_ids) ) : array(); |
| 183 | $active_term_id = ( !empty( $_POST['active_term_id'] ) ) ? intval( $_POST['active_term_id'] ) : 0; |
| 184 | $active_taxonomy = ( !empty( $_POST['active_taxonomy'] ) ) ? sanitize_text_field( $_POST['active_taxonomy'] ) : ''; |
| 185 | |
| 186 | if( 0 < $active_term_id && |
| 187 | !empty( $active_taxonomy ) && |
| 188 | !empty($args['tax_query']) |
| 189 | ) { |
| 190 | foreach ($args['tax_query'] as $key => $taxonomy) { |
| 191 | if (isset($taxonomy['taxonomy']) && $taxonomy['taxonomy'] === $active_taxonomy) { |
| 192 | $args['tax_query'][$key]['terms'] = [$active_term_id]; |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | $link_settings = [ |
| 199 | 'image_link_nofollow' => ! empty( $settings['image_link_nofollow'] ) ? 'rel="nofollow"' : '', |
| 200 | 'image_link_target_blank' => ! empty( $settings['image_link_target_blank'] ) ? 'target="_blank"' : '', |
| 201 | 'title_link_nofollow' => ! empty( $settings['title_link_nofollow'] ) ? 'rel="nofollow"' : '', |
| 202 | 'title_link_target_blank' => ! empty( $settings['title_link_target_blank'] ) ? 'target="_blank"' : '', |
| 203 | 'read_more_link_nofollow' => ! empty( $settings['read_more_link_nofollow'] ) ? 'rel="nofollow"' : '', |
| 204 | 'read_more_link_target_blank' => ! empty( $settings['read_more_link_target_blank'] ) ? 'target="_blank"' : '', |
| 205 | ]; |
| 206 | |
| 207 | $template_info = $this->eael_sanitize_template_param( $_REQUEST['template_info'] ); |
| 208 | |
| 209 | if ( $template_info ) { |
| 210 | |
| 211 | if ( $template_info['dir'] === 'theme' ) { |
| 212 | $dir_path = $this->retrive_theme_path(); |
| 213 | } else if ( $template_info['dir'] === 'pro' ) { |
| 214 | $dir_path = sprintf( "%sincludes", EAEL_PRO_PLUGIN_PATH ); |
| 215 | } else { |
| 216 | $dir_path = sprintf( "%sincludes", EAEL_PLUGIN_PATH ); |
| 217 | } |
| 218 | |
| 219 | $file_path = realpath( sprintf( |
| 220 | '%s/Template/%s/%s', |
| 221 | $dir_path, |
| 222 | $template_info['name'], |
| 223 | $template_info['file_name'] |
| 224 | ) ); |
| 225 | |
| 226 | if ( ! $file_path || 0 !== strpos( $file_path, realpath( $dir_path ) ) ) { |
| 227 | wp_send_json_error( 'Invalid template', 'invalid_template', 400 ); |
| 228 | } |
| 229 | |
| 230 | if ( $file_path ) { |
| 231 | $query = new \WP_Query( $args ); |
| 232 | $found_posts = $query->found_posts; |
| 233 | $iterator = 0; |
| 234 | |
| 235 | if ( $query->have_posts() ) { |
| 236 | if ( $class === '\Essential_Addons_Elementor\Elements\Product_Grid' && boolval( $settings['show_add_to_cart_custom_text'] ) ) { |
| 237 | |
| 238 | $add_to_cart_text = [ |
| 239 | 'add_to_cart_simple_product_button_text' => $settings['add_to_cart_simple_product_button_text'], |
| 240 | 'add_to_cart_variable_product_button_text' => $settings['add_to_cart_variable_product_button_text'], |
| 241 | 'add_to_cart_grouped_product_button_text' => $settings['add_to_cart_grouped_product_button_text'], |
| 242 | 'add_to_cart_external_product_button_text' => $settings['add_to_cart_external_product_button_text'], |
| 243 | 'add_to_cart_default_product_button_text' => $settings['add_to_cart_default_product_button_text'], |
| 244 | ]; |
| 245 | $this->change_add_woo_checkout_update_order_reviewto_cart_text( $add_to_cart_text ); |
| 246 | } |
| 247 | |
| 248 | if ( $class === '\Essential_Addons_Elementor\Pro\Elements\Dynamic_Filterable_Gallery' ) { |
| 249 | $html .= "<div class='found_posts' style='display: none;'>{$found_posts}</div>"; |
| 250 | } |
| 251 | |
| 252 | while ( $query->have_posts() ) { |
| 253 | $query->the_post(); |
| 254 | |
| 255 | $html .= HelperClass::include_with_variable( $file_path, [ |
| 256 | 'settings' => $settings, |
| 257 | 'link_settings' => $link_settings, |
| 258 | 'iterator' => $iterator |
| 259 | ] ); |
| 260 | $iterator ++; |
| 261 | } |
| 262 | } else { |
| 263 | $html .= __( '<p class="no-posts-found">No posts found!</p>', 'essential-addons-for-elementor-lite' ); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | |
| 269 | while ( ob_get_status() ) { |
| 270 | ob_end_clean(); |
| 271 | } |
| 272 | if ( function_exists( 'gzencode' ) ) { |
| 273 | $response = gzencode( wp_json_encode( $html ) ); |
| 274 | |
| 275 | header( 'Content-Type: application/json; charset=utf-8' ); |
| 276 | header( 'Content-Encoding: gzip' ); |
| 277 | header( 'Content-Length: ' . strlen( $response ) ); |
| 278 | |
| 279 | printf( '%1$s', $response ); |
| 280 | } else { |
| 281 | echo wp_kses_post( $html ); |
| 282 | } |
| 283 | wp_die(); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Woo Pagination Product Ajax |
| 288 | * get product list when pagination number/dot click by ajax |
| 289 | * |
| 290 | * @access public |
| 291 | * @return void of a html markup with AJAX call. |
| 292 | * @since 3.1.0 |
| 293 | */ |
| 294 | public function eael_woo_pagination_product_ajax() { |
| 295 | |
| 296 | check_ajax_referer( 'essential-addons-elementor', 'security' ); |
| 297 | |
| 298 | do_action( 'eael_before_woo_pagination_product_ajax_start', $_REQUEST ); |
| 299 | |
| 300 | if ( ! empty( $_POST['page_id'] ) ) { |
| 301 | $page_id = intval( $_POST['page_id'], 10 ); |
| 302 | } else { |
| 303 | $err_msg = __( 'Page ID is missing', 'essential-addons-for-elementor-lite' ); |
| 304 | wp_send_json_error( $err_msg ); |
| 305 | } |
| 306 | |
| 307 | if ( ! empty( $_POST['widget_id'] ) ) { |
| 308 | $widget_id = sanitize_text_field( $_POST['widget_id'] ); |
| 309 | } else { |
| 310 | $err_msg = __( 'Widget ID is missing', 'essential-addons-for-elementor-lite' ); |
| 311 | wp_send_json_error( $err_msg ); |
| 312 | } |
| 313 | |
| 314 | $settings = HelperClass::eael_get_widget_settings( $page_id, $widget_id ); |
| 315 | if ( empty( $settings ) ) { |
| 316 | wp_send_json_error( [ 'message' => __( 'Widget settings are not found. Did you save the widget before using load more??', 'essential-addons-for-elementor-lite' ) ] ); |
| 317 | } |
| 318 | $settings['eael_page_id'] = $page_id; |
| 319 | $settings['eael_widget_id'] = $widget_id; |
| 320 | wp_parse_str( $_REQUEST['args'], $args ); |
| 321 | |
| 322 | if ( isset( $args['date_query']['relation'] ) ) { |
| 323 | $args['date_query']['relation'] = HelperClass::eael_sanitize_relation( $args['date_query']['relation'] ); |
| 324 | } |
| 325 | |
| 326 | $paginationNumber = absint( $_POST['number'] ); |
| 327 | $paginationLimit = absint( $_POST['limit'] ); |
| 328 | |
| 329 | $args['posts_per_page'] = $paginationLimit; |
| 330 | |
| 331 | if ( $paginationNumber == "1" ) { |
| 332 | $paginationOffsetValue = "0"; |
| 333 | } else { |
| 334 | $paginationOffsetValue = ( $paginationNumber - 1 ) * $paginationLimit; |
| 335 | $args['offset'] = $paginationOffsetValue; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | $template_info = $this->eael_sanitize_template_param( $_REQUEST['templateInfo'] ); |
| 340 | |
| 341 | $this->set_widget_name( $template_info['name'] ); |
| 342 | $template = realpath( $this->get_template( $template_info['file_name'] ) ); |
| 343 | |
| 344 | ob_start(); |
| 345 | $query = new \WP_Query( $args ); |
| 346 | if ( $query->have_posts() ) { |
| 347 | while ( $query->have_posts() ) { |
| 348 | $query->the_post(); |
| 349 | include( $template ); |
| 350 | } |
| 351 | wp_reset_postdata(); |
| 352 | } |
| 353 | echo ob_get_clean(); |
| 354 | wp_die(); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Woo Pagination Ajax |
| 359 | * Return pagination list for product post type while used Product_Grid widget |
| 360 | * |
| 361 | * @access public |
| 362 | * @return void of a html markup with AJAX call. |
| 363 | * @since unknown |
| 364 | */ |
| 365 | public function eael_woo_pagination_ajax() { |
| 366 | |
| 367 | check_ajax_referer( 'essential-addons-elementor', 'security' ); |
| 368 | |
| 369 | if ( ! empty( $_POST['page_id'] ) ) { |
| 370 | $page_id = intval( $_POST['page_id'], 10 ); |
| 371 | } else { |
| 372 | $err_msg = __( 'Page ID is missing', 'essential-addons-for-elementor-lite' ); |
| 373 | wp_send_json_error( $err_msg ); |
| 374 | } |
| 375 | |
| 376 | if ( ! empty( $_POST['widget_id'] ) ) { |
| 377 | $widget_id = sanitize_text_field( $_POST['widget_id'] ); |
| 378 | } else { |
| 379 | $err_msg = __( 'Widget ID is missing', 'essential-addons-for-elementor-lite' ); |
| 380 | wp_send_json_error( $err_msg ); |
| 381 | } |
| 382 | |
| 383 | $settings = HelperClass::eael_get_widget_settings( $page_id, $widget_id ); |
| 384 | |
| 385 | if ( empty( $settings ) ) { |
| 386 | wp_send_json_error( [ 'message' => __( 'Widget settings are not found. Did you save the widget before using load more??', 'essential-addons-for-elementor-lite' ) ] ); |
| 387 | } |
| 388 | |
| 389 | $settings['eael_page_id'] = $page_id; |
| 390 | wp_parse_str( $_REQUEST['args'], $args ); |
| 391 | |
| 392 | if ( isset( $args['date_query']['relation'] ) ) { |
| 393 | $args['date_query']['relation'] = HelperClass::eael_sanitize_relation( $args['date_query']['relation'] ); |
| 394 | } |
| 395 | |
| 396 | $paginationNumber = absint( $_POST['number'] ); |
| 397 | $paginationLimit = absint( $_POST['limit'] ); |
| 398 | $pagination_Count = intval( $args['total_post'] ); |
| 399 | $pagination_Paginationlist = ceil( $pagination_Count / $paginationLimit ); |
| 400 | $last = ceil( $pagination_Paginationlist ); |
| 401 | $paginationprev = $paginationNumber - 1; |
| 402 | $paginationnext = $paginationNumber + 1; |
| 403 | |
| 404 | if ( $paginationNumber > 1 ) { |
| 405 | $paginationprev; |
| 406 | } |
| 407 | if ( $paginationNumber < $last ) { |
| 408 | $paginationnext; |
| 409 | } |
| 410 | |
| 411 | $adjacents = "2"; |
| 412 | $next_label = sanitize_text_field( $settings['pagination_next_label'] ); |
| 413 | $prev_label = sanitize_text_field( $settings['pagination_prev_label'] ); |
| 414 | $settings['eael_widget_name'] = realpath( sanitize_file_name( $_REQUEST['template_name'] ) ); |
| 415 | $setPagination = ""; |
| 416 | |
| 417 | if ( $pagination_Paginationlist > 0 ) { |
| 418 | |
| 419 | $setPagination .= "<ul class='page-numbers'>"; |
| 420 | |
| 421 | if ( 1 < $paginationNumber ) { |
| 422 | $setPagination .= "<li class='pagitext'><a href='javascript:void(0);' class='page-numbers' data-pnumber='$paginationprev' >$prev_label</a></li>"; |
| 423 | } |
| 424 | |
| 425 | if ( $pagination_Paginationlist < 7 + ( $adjacents * 2 ) ) { |
| 426 | |
| 427 | for ( $pagination = 1; $pagination <= $pagination_Paginationlist; $pagination ++ ) { |
| 428 | $active = ( $paginationNumber == $pagination ) ? 'current' : ''; |
| 429 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, $pagination ); |
| 430 | } |
| 431 | |
| 432 | } else if ( $pagination_Paginationlist > 5 + ( $adjacents * 2 ) ) { |
| 433 | |
| 434 | if ( $paginationNumber < 1 + ( $adjacents * 2 ) ) { |
| 435 | for ( $pagination = 1; $pagination <= 4 + ( $adjacents * 2 ); $pagination ++ ) { |
| 436 | |
| 437 | $active = ( $paginationNumber == $pagination ) ? 'current' : ''; |
| 438 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, $pagination ); |
| 439 | } |
| 440 | $setPagination .= "<li class='pagitext dots'>...</li>"; |
| 441 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, $pagination ); |
| 442 | |
| 443 | } elseif ( $pagination_Paginationlist - ( $adjacents * 2 ) > $paginationNumber && $paginationNumber > ( $adjacents * 2 ) ) { |
| 444 | $active = ''; |
| 445 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, 1 ); |
| 446 | $setPagination .= "<li class='pagitext dots'>...</li>"; |
| 447 | for ( $pagination = $paginationNumber - $adjacents; $pagination <= $paginationNumber + $adjacents; $pagination ++ ) { |
| 448 | $active = ( $paginationNumber == $pagination ) ? 'current' : ''; |
| 449 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, $pagination ); |
| 450 | } |
| 451 | |
| 452 | $setPagination .= "<li class='pagitext dots'>...</li>"; |
| 453 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, $last ); |
| 454 | |
| 455 | } else { |
| 456 | $active = ''; |
| 457 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, 1 ); |
| 458 | $setPagination .= "<li class='pagitext dots'>...</li>"; |
| 459 | for ( $pagination = $last - ( 2 + ( $adjacents * 2 ) ); $pagination <= $last; $pagination ++ ) { |
| 460 | $active = ( $paginationNumber == $pagination ) ? 'current' : ''; |
| 461 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, $pagination ); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | } else { |
| 466 | for ( $pagination = 1; $pagination <= $pagination_Paginationlist; $pagination ++ ) { |
| 467 | $active = ( $paginationNumber == $pagination ) ? 'current' : ''; |
| 468 | $setPagination .= sprintf( "<li><a href='javascript:void(0);' id='post' class='page-numbers %s' data-pnumber='%2\$d'>%2\$d</a></li>", $active, $pagination ); |
| 469 | } |
| 470 | |
| 471 | } |
| 472 | |
| 473 | if ( $paginationNumber < $pagination_Paginationlist ) { |
| 474 | $setPagination .= "<li class='pagitext'><a href='javascript:void(0);' class='page-numbers' data-pnumber='$paginationnext' >$next_label</a></li>"; |
| 475 | } |
| 476 | |
| 477 | $setPagination .= "</ul>"; |
| 478 | } |
| 479 | |
| 480 | printf( '%1$s', $setPagination ); |
| 481 | wp_die(); |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Product Add to Cart |
| 486 | * added product in cart through ajax |
| 487 | * |
| 488 | * @access public |
| 489 | * @return void of a html markup with AJAX call. |
| 490 | * @since unknown |
| 491 | */ |
| 492 | public function eael_product_add_to_cart() { |
| 493 | |
| 494 | $ajax = wp_doing_ajax(); |
| 495 | $cart_items = isset( $_POST['cart_item_data'] ) ? $_POST['cart_item_data'] : []; |
| 496 | $variation = []; |
| 497 | if ( ! empty( $cart_items ) ) { |
| 498 | foreach ( $cart_items as $key => $value ) { |
| 499 | if ( preg_match( "/^attribute*/", $value['name'] ) ) { |
| 500 | $variation[ $value['name'] ] = sanitize_text_field( $value['value'] ); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | if ( isset( $_POST['product_data'] ) ) { |
| 506 | foreach ( $_POST['product_data'] as $item ) { |
| 507 | $product_id = isset( $item['product_id'] ) ? sanitize_text_field( $item['product_id'] ) : 0; |
| 508 | $variation_id = isset( $item['variation_id'] ) ? sanitize_text_field( $item['variation_id'] ) : 0; |
| 509 | $quantity = isset( $item['quantity'] ) ? sanitize_text_field( $item['quantity'] ) : 0; |
| 510 | |
| 511 | if ( $variation_id ) { |
| 512 | WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variation ); |
| 513 | } else { |
| 514 | WC()->cart->add_to_cart( $product_id, $quantity ); |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | wp_send_json_success(); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Woo Checkout Update Order Review |
| 523 | * return order review data |
| 524 | * |
| 525 | * @access public |
| 526 | * @return void |
| 527 | * @since 4.0.0 |
| 528 | */ |
| 529 | public function woo_checkout_update_order_review() { |
| 530 | $setting = $_POST['orderReviewData']; |
| 531 | ob_start(); |
| 532 | Woo_Checkout_Helper::checkout_order_review_default( $setting ); |
| 533 | $woo_checkout_update_order_review = ob_get_clean(); |
| 534 | |
| 535 | wp_send_json( |
| 536 | array( |
| 537 | 'order_review' => $woo_checkout_update_order_review, |
| 538 | ) |
| 539 | ); |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * Eael Product Quick View Popup |
| 544 | * Retrieve product quick view data |
| 545 | * |
| 546 | * @access public |
| 547 | * @return void |
| 548 | * @since 4.0.0 |
| 549 | */ |
| 550 | public function eael_product_quickview_popup() { |
| 551 | //check nonce |
| 552 | check_ajax_referer( 'essential-addons-elementor', 'security' ); |
| 553 | $widget_id = sanitize_key( $_POST['widget_id'] ); |
| 554 | $product_id = absint( $_POST['product_id'] ); |
| 555 | $page_id = absint( $_POST['page_id'] ); |
| 556 | |
| 557 | if ( $widget_id == '' && $product_id == '' && $page_id == '' ) { |
| 558 | wp_send_json_error(); |
| 559 | } |
| 560 | |
| 561 | global $post, $product; |
| 562 | $product = wc_get_product( $product_id ); |
| 563 | $post = get_post( $product_id ); |
| 564 | setup_postdata( $post ); |
| 565 | |
| 566 | $settings = $this->eael_get_widget_settings( $page_id, $widget_id ); |
| 567 | ob_start(); |
| 568 | HelperClass::eael_product_quick_view( $product, $settings, $widget_id ); |
| 569 | $data = ob_get_clean(); |
| 570 | wp_reset_postdata(); |
| 571 | |
| 572 | wp_send_json_success( $data ); |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Ajax Eael Product Gallery |
| 577 | * Retrieve product quick view data |
| 578 | * |
| 579 | * @access public |
| 580 | * @return false|void |
| 581 | * @since 4.0.0 |
| 582 | */ |
| 583 | public function ajax_eael_product_gallery() { |
| 584 | |
| 585 | $ajax = wp_doing_ajax(); |
| 586 | |
| 587 | wp_parse_str( $_POST['args'], $args ); |
| 588 | |
| 589 | if ( isset( $args['date_query']['relation'] ) ) { |
| 590 | $args['date_query']['relation'] = HelperClass::eael_sanitize_relation( $args['date_query']['relation'] ); |
| 591 | } |
| 592 | |
| 593 | if ( empty( $_POST['nonce'] ) ) { |
| 594 | $err_msg = __( 'Insecure form submitted without security token', 'essential-addons-for-elementor-lite' ); |
| 595 | if ( $ajax ) { |
| 596 | wp_send_json_error( $err_msg ); |
| 597 | } |
| 598 | |
| 599 | return false; |
| 600 | } |
| 601 | |
| 602 | if ( ! wp_verify_nonce( $_POST['nonce'], 'eael_product_gallery' ) ) { |
| 603 | $err_msg = __( 'Security token did not match', 'essential-addons-for-elementor-lite' ); |
| 604 | if ( $ajax ) { |
| 605 | wp_send_json_error( $err_msg ); |
| 606 | } |
| 607 | |
| 608 | return false; |
| 609 | } |
| 610 | |
| 611 | if ( ! empty( $_POST['page_id'] ) ) { |
| 612 | $page_id = intval( $_POST['page_id'], 10 ); |
| 613 | } else { |
| 614 | $err_msg = __( 'Page ID is missing', 'essential-addons-for-elementor-lite' ); |
| 615 | if ( $ajax ) { |
| 616 | wp_send_json_error( $err_msg ); |
| 617 | } |
| 618 | |
| 619 | return false; |
| 620 | } |
| 621 | |
| 622 | if ( ! empty( $_POST['widget_id'] ) ) { |
| 623 | $widget_id = sanitize_text_field( $_POST['widget_id'] ); |
| 624 | } else { |
| 625 | $err_msg = __( 'Widget ID is missing', 'essential-addons-for-elementor-lite' ); |
| 626 | if ( $ajax ) { |
| 627 | wp_send_json_error( $err_msg ); |
| 628 | } |
| 629 | |
| 630 | return false; |
| 631 | } |
| 632 | |
| 633 | $settings = HelperClass::eael_get_widget_settings( $page_id, $widget_id ); |
| 634 | if ( empty( $settings ) ) { |
| 635 | wp_send_json_error( [ 'message' => __( 'Widget settings are not found. Did you save the widget before using load more??', 'essential-addons-for-elementor-lite' ) ] ); |
| 636 | } |
| 637 | |
| 638 | if ( $widget_id == '' && $page_id == '' ) { |
| 639 | wp_send_json_error(); |
| 640 | } |
| 641 | |
| 642 | $settings['eael_widget_id'] = $widget_id; |
| 643 | $settings['eael_page_id'] = $page_id; |
| 644 | $args['offset'] = (int) $args['offset'] + ( ( (int) $_REQUEST['page'] - 1 ) * (int) $args['posts_per_page'] ); |
| 645 | |
| 646 | if ( isset( $_REQUEST['taxonomy'] ) && isset( $_REQUEST['taxonomy']['taxonomy'] ) && $_REQUEST['taxonomy']['taxonomy'] != 'all' ) { |
| 647 | $args['tax_query'] = [ |
| 648 | $this->sanitize_taxonomy_data( $_REQUEST['taxonomy'] ), |
| 649 | ]; |
| 650 | |
| 651 | $args['tax_query'] = $this->eael_terms_query_multiple( $args['tax_query'] ); |
| 652 | |
| 653 | if ( $settings[ 'eael_product_gallery_product_filter' ] == 'featured-products' ) { |
| 654 | $args[ 'tax_query' ][] = [ |
| 655 | 'relation' => 'AND', |
| 656 | [ |
| 657 | 'taxonomy' => 'product_visibility', |
| 658 | 'field' => 'name', |
| 659 | 'terms' => 'featured', |
| 660 | ], |
| 661 | [ |
| 662 | 'taxonomy' => 'product_visibility', |
| 663 | 'field' => 'name', |
| 664 | 'terms' => [ 'exclude-from-search', 'exclude-from-catalog' ], |
| 665 | 'operator' => 'NOT IN', |
| 666 | ], |
| 667 | ]; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | } |
| 672 | |
| 673 | $template_info = $this->eael_sanitize_template_param( $_REQUEST['template_info'] ); |
| 674 | |
| 675 | if ( $template_info ) { |
| 676 | |
| 677 | if ( $template_info['dir'] === 'theme' ) { |
| 678 | $dir_path = $this->retrive_theme_path(); |
| 679 | } else if ( $template_info['dir'] === 'pro' ) { |
| 680 | $dir_path = sprintf( "%sincludes", EAEL_PRO_PLUGIN_PATH ); |
| 681 | } else { |
| 682 | $dir_path = sprintf( "%sincludes", EAEL_PLUGIN_PATH ); |
| 683 | } |
| 684 | |
| 685 | $file_path = realpath( sprintf( |
| 686 | '%s/Template/%s/%s', |
| 687 | $dir_path, |
| 688 | $template_info['name'], |
| 689 | $template_info['file_name'] |
| 690 | ) ); |
| 691 | |
| 692 | if ( ! $file_path || 0 !== strpos( $file_path, realpath( $dir_path ) ) ) { |
| 693 | wp_send_json_error( 'Invalid template', 'invalid_template', 400 ); |
| 694 | } |
| 695 | |
| 696 | $html = ''; |
| 697 | if ( $file_path ) { |
| 698 | $query = new \WP_Query( $args ); |
| 699 | |
| 700 | if ( $query->have_posts() ) { |
| 701 | |
| 702 | while ( $query->have_posts() ) { |
| 703 | $query->the_post(); |
| 704 | $html .= HelperClass::include_with_variable( $file_path, [ 'settings' => $settings ] ); |
| 705 | } |
| 706 | $html .= '<div class="eael-max-page" style="display:none;">'. ceil($query->found_posts / absint( $args['posts_per_page'] ) ) . '</div>'; |
| 707 | printf( '%1$s', $html ); |
| 708 | wp_reset_postdata(); |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | wp_die(); |
| 713 | } |
| 714 | |
| 715 | public function eael_terms_query_multiple( $args_tax_query = [] ){ |
| 716 | if ( strpos($args_tax_query[0]['taxonomy'], '|') !== false ) { |
| 717 | $args_tax_query_item = $args_tax_query[0]; |
| 718 | |
| 719 | //Query for category and tag |
| 720 | $args_multiple['tax_query'] = []; |
| 721 | |
| 722 | if( isset( $args_tax_query_item['terms'] ) ){ |
| 723 | $args_multiple['tax_query'][] = [ |
| 724 | 'taxonomy' => 'product_cat', |
| 725 | 'field' => 'term_id', |
| 726 | 'terms' => $args_tax_query_item['terms'], |
| 727 | ]; |
| 728 | } |
| 729 | |
| 730 | if( isset( $args_tax_query_item['terms_tag'] ) ){ |
| 731 | $args_multiple['tax_query'][] = [ |
| 732 | 'taxonomy' => 'product_tag', |
| 733 | 'field' => 'term_id', |
| 734 | 'terms' => $args_tax_query_item['terms_tag'], |
| 735 | ]; |
| 736 | } |
| 737 | |
| 738 | |
| 739 | if ( count( $args_multiple['tax_query'] ) ) { |
| 740 | $args_multiple['tax_query']['relation'] = 'OR'; |
| 741 | } |
| 742 | |
| 743 | $args_tax_query = $args_multiple['tax_query']; |
| 744 | } |
| 745 | |
| 746 | if( isset( $args_tax_query[0]['terms_tag'] ) ){ |
| 747 | if( 'product_tag' === $args_tax_query[0]['taxonomy'] ){ |
| 748 | $args_tax_query[0]['terms'] = $args_tax_query[0]['terms_tag']; |
| 749 | } |
| 750 | unset($args_tax_query[0]['terms_tag']); |
| 751 | } |
| 752 | |
| 753 | return $args_tax_query; |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Select2 Ajax Posts Filter Autocomplete |
| 758 | * Fetch post/taxonomy data and render in Elementor control select2 ajax search box |
| 759 | * |
| 760 | * @access public |
| 761 | * @return void |
| 762 | * @since 4.0.0 |
| 763 | */ |
| 764 | public function select2_ajax_posts_filter_autocomplete() { |
| 765 | $post_type = 'post'; |
| 766 | $source_name = 'post_type'; |
| 767 | |
| 768 | if ( ! empty( $_POST['post_type'] ) ) { |
| 769 | $post_type = sanitize_text_field( $_POST['post_type'] ); |
| 770 | } |
| 771 | |
| 772 | if ( ! empty( $_POST['source_name'] ) ) { |
| 773 | $source_name = sanitize_text_field( $_POST['source_name'] ); |
| 774 | } |
| 775 | |
| 776 | $search = ! empty( $_POST['term'] ) ? sanitize_text_field( $_POST['term'] ) : ''; |
| 777 | $results = $post_list = []; |
| 778 | switch ( $source_name ) { |
| 779 | case 'taxonomy': |
| 780 | $args = [ |
| 781 | 'hide_empty' => false, |
| 782 | 'orderby' => 'name', |
| 783 | 'order' => 'ASC', |
| 784 | 'search' => $search, |
| 785 | 'number' => '5', |
| 786 | ]; |
| 787 | |
| 788 | if ( $post_type !== 'all' ) { |
| 789 | $args['taxonomy'] = $post_type; |
| 790 | } |
| 791 | |
| 792 | $post_list = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| 793 | break; |
| 794 | case 'user': |
| 795 | $users = []; |
| 796 | |
| 797 | foreach ( get_users( [ 'search' => "*{$search}*" ] ) as $user ) { |
| 798 | $user_id = $user->ID; |
| 799 | $user_name = $user->display_name; |
| 800 | $users[ $user_id ] = $user_name; |
| 801 | } |
| 802 | |
| 803 | $post_list = $users; |
| 804 | break; |
| 805 | default: |
| 806 | $post_list = HelperClass::get_query_post_list( $post_type, 10, $search ); |
| 807 | } |
| 808 | |
| 809 | if ( ! empty( $post_list ) ) { |
| 810 | foreach ( $post_list as $key => $item ) { |
| 811 | $results[] = [ 'text' => $item, 'id' => $key ]; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | wp_send_json( [ 'results' => $results ] ); |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Select2 Ajax Get Posts Value Titles |
| 820 | * get selected value to show elementor editor panel in select2 ajax search box |
| 821 | * |
| 822 | * @access public |
| 823 | * @return void |
| 824 | * @since 4.0.0 |
| 825 | */ |
| 826 | public function select2_ajax_get_posts_value_titles() { |
| 827 | |
| 828 | if ( empty( $_POST['id'] ) ) { |
| 829 | wp_send_json_error( [] ); |
| 830 | } |
| 831 | |
| 832 | if ( empty( array_filter( $_POST['id'] ) ) ) { |
| 833 | wp_send_json_error( [] ); |
| 834 | } |
| 835 | $ids = array_map( 'intval', $_POST['id'] ); |
| 836 | $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; |
| 837 | |
| 838 | switch ( $source_name ) { |
| 839 | case 'taxonomy': |
| 840 | $args = [ |
| 841 | 'hide_empty' => false, |
| 842 | 'orderby' => 'name', |
| 843 | 'order' => 'ASC', |
| 844 | 'include' => implode( ',', $ids ), |
| 845 | ]; |
| 846 | |
| 847 | if ( $_POST['post_type'] !== 'all' ) { |
| 848 | $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] ); |
| 849 | } |
| 850 | |
| 851 | $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| 852 | break; |
| 853 | case 'user': |
| 854 | $users = []; |
| 855 | |
| 856 | foreach ( get_users( [ 'include' => $ids ] ) as $user ) { |
| 857 | $user_id = $user->ID; |
| 858 | $user_name = $user->display_name; |
| 859 | $users[ $user_id ] = $user_name; |
| 860 | } |
| 861 | |
| 862 | $response = $users; |
| 863 | break; |
| 864 | default: |
| 865 | $post_info = get_posts( [ |
| 866 | 'post_type' => sanitize_text_field( $_POST['post_type'] ), |
| 867 | 'include' => implode( ',', $ids ) |
| 868 | ] ); |
| 869 | $response = wp_list_pluck( $post_info, 'post_title', 'ID' ); |
| 870 | } |
| 871 | |
| 872 | if ( ! empty( $response ) ) { |
| 873 | wp_send_json_success( [ 'results' => $response ] ); |
| 874 | } else { |
| 875 | wp_send_json_error( [] ); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Save Settings |
| 881 | * Save EA settings data through ajax request |
| 882 | * |
| 883 | * @access public |
| 884 | * @return void |
| 885 | * @since 1.1.2 |
| 886 | */ |
| 887 | public function save_settings() { |
| 888 | check_ajax_referer( 'essential-addons-elementor', 'security' ); |
| 889 | |
| 890 | if ( ! current_user_can( 'manage_options' ) ) { |
| 891 | wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) ); |
| 892 | } |
| 893 | |
| 894 | if ( ! isset( $_POST['fields'] ) ) { |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | wp_parse_str( $_POST['fields'], $settings ); |
| 899 | |
| 900 | if ( ! empty( $_POST['is_login_register'] ) ) { |
| 901 | // Saving Login | Register Related Data |
| 902 | if ( isset( $settings['recaptchaSiteKey'] ) ) { |
| 903 | update_option( 'eael_recaptcha_sitekey', sanitize_text_field( $settings['recaptchaSiteKey'] ) ); |
| 904 | } |
| 905 | if ( isset( $settings['recaptchaSiteSecret'] ) ) { |
| 906 | update_option( 'eael_recaptcha_secret', sanitize_text_field( $settings['recaptchaSiteSecret'] ) ); |
| 907 | } |
| 908 | if ( isset( $settings['recaptchaLanguage'] ) ) { |
| 909 | update_option( 'eael_recaptcha_language', sanitize_text_field( $settings['recaptchaLanguage'] ) ); |
| 910 | } |
| 911 | |
| 912 | //reCAPTCHA V3 |
| 913 | if ( isset( $settings['recaptchaSiteKeyV3'] ) ) { |
| 914 | update_option( 'eael_recaptcha_sitekey_v3', sanitize_text_field( $settings['recaptchaSiteKeyV3'] ) ); |
| 915 | } |
| 916 | if ( isset( $settings['recaptchaSiteSecretV3'] ) ) { |
| 917 | update_option( 'eael_recaptcha_secret_v3', sanitize_text_field( $settings['recaptchaSiteSecretV3'] ) ); |
| 918 | } |
| 919 | if ( isset( $settings['recaptchaLanguageV3'] ) ) { |
| 920 | update_option( 'eael_recaptcha_language_v3', sanitize_text_field( $settings['recaptchaLanguageV3'] ) ); |
| 921 | } |
| 922 | |
| 923 | //pro settings |
| 924 | if ( isset( $settings['gClientId'] ) ) { |
| 925 | update_option( 'eael_g_client_id', sanitize_text_field( $settings['gClientId'] ) ); |
| 926 | } |
| 927 | if ( isset( $settings['fbAppId'] ) ) { |
| 928 | update_option( 'eael_fb_app_id', sanitize_text_field( $settings['fbAppId'] ) ); |
| 929 | } |
| 930 | if ( isset( $settings['fbAppSecret'] ) ) { |
| 931 | update_option( 'eael_fb_app_secret', sanitize_text_field( $settings['fbAppSecret'] ) ); |
| 932 | } |
| 933 | |
| 934 | wp_send_json_success( [ 'message' => __( 'Login | Register Settings updated', 'essential-addons-for-elementor-lite' ) ] ); |
| 935 | } |
| 936 | |
| 937 | //Login-register data |
| 938 | if ( isset( $settings['lr_recaptcha_sitekey'] ) ) { |
| 939 | update_option( 'eael_recaptcha_sitekey', sanitize_text_field( $settings['lr_recaptcha_sitekey'] ) ); |
| 940 | } |
| 941 | if ( isset( $settings['lr_recaptcha_secret'] ) ) { |
| 942 | update_option( 'eael_recaptcha_secret', sanitize_text_field( $settings['lr_recaptcha_secret'] ) ); |
| 943 | } |
| 944 | if ( isset( $settings['lr_recaptcha_language'] ) ) { |
| 945 | update_option( 'eael_recaptcha_language', sanitize_text_field( $settings['lr_recaptcha_language'] ) ); |
| 946 | } |
| 947 | //reCAPTCHA v3 |
| 948 | if ( isset( $settings['lr_recaptcha_sitekey_v3'] ) ) { |
| 949 | update_option( 'eael_recaptcha_sitekey_v3', sanitize_text_field( $settings['lr_recaptcha_sitekey_v3'] ) ); |
| 950 | } |
| 951 | if ( isset( $settings['lr_recaptcha_secret_v3'] ) ) { |
| 952 | update_option( 'eael_recaptcha_secret_v3', sanitize_text_field( $settings['lr_recaptcha_secret_v3'] ) ); |
| 953 | } |
| 954 | if ( isset( $settings['lr_recaptcha_language_v3'] ) ) { |
| 955 | update_option( 'eael_recaptcha_language_v3', sanitize_text_field( $settings['lr_recaptcha_language_v3'] ) ); |
| 956 | } |
| 957 | |
| 958 | if ( isset( $settings['lr_custom_profile_fields'] ) ) { |
| 959 | update_option( 'eael_custom_profile_fields', sanitize_text_field( $settings['lr_custom_profile_fields'] ) ); |
| 960 | } else { |
| 961 | update_option( 'eael_custom_profile_fields', '' ); |
| 962 | } |
| 963 | |
| 964 | if ( isset( $settings['lr_custom_profile_fields_text'] ) ) { |
| 965 | update_option( 'eael_custom_profile_fields_text', sanitize_text_field( $settings['lr_custom_profile_fields_text'] ) ); |
| 966 | } else { |
| 967 | update_option( 'eael_custom_profile_fields_text', '' ); |
| 968 | } |
| 969 | |
| 970 | if ( isset( $settings['lr_custom_profile_fields_img'] ) ) { |
| 971 | update_option( 'eael_custom_profile_fields_img', sanitize_text_field( $settings['lr_custom_profile_fields_img'] ) ); |
| 972 | } else { |
| 973 | update_option( 'eael_custom_profile_fields_img', '' ); |
| 974 | } |
| 975 | |
| 976 | //pro settings |
| 977 | if ( isset( $settings['lr_g_client_id'] ) ) { |
| 978 | update_option( 'eael_g_client_id', sanitize_text_field( $settings['lr_g_client_id'] ) ); |
| 979 | } |
| 980 | if ( isset( $settings['lr_fb_app_id'] ) ) { |
| 981 | update_option( 'eael_fb_app_id', sanitize_text_field( $settings['lr_fb_app_id'] ) ); |
| 982 | } |
| 983 | if ( isset( $settings['lr_fb_app_secret'] ) ) { |
| 984 | update_option( 'eael_fb_app_secret', sanitize_text_field( $settings['lr_fb_app_secret'] ) ); |
| 985 | } |
| 986 | |
| 987 | // Business Reviews : Saving Google Place Api Key |
| 988 | if ( isset( $settings['br_google_place_api_key'] ) ) { |
| 989 | update_option( 'eael_br_google_place_api_key', sanitize_text_field( $settings['br_google_place_api_key'] ) ); |
| 990 | } |
| 991 | |
| 992 | // Saving Google Map Api Key |
| 993 | if ( isset( $settings['google-map-api'] ) ) { |
| 994 | update_option( 'eael_save_google_map_api', sanitize_text_field( $settings['google-map-api'] ) ); |
| 995 | } |
| 996 | |
| 997 | // Saving Mailchimp Api Key |
| 998 | if ( isset( $settings['mailchimp-api'] ) ) { |
| 999 | update_option( 'eael_save_mailchimp_api', sanitize_text_field( $settings['mailchimp-api'] ) ); |
| 1000 | } |
| 1001 | |
| 1002 | // Saving Mailchimp Api Key for EA Login | Register Form |
| 1003 | if ( isset( $settings['lr_mailchimp_api_key'] ) ) { |
| 1004 | update_option( 'eael_lr_mailchimp_api_key', sanitize_text_field( $settings['lr_mailchimp_api_key'] ) ); |
| 1005 | } |
| 1006 | |
| 1007 | // Saving TYpeForm token |
| 1008 | if ( isset( $settings['typeform-personal-token'] ) ) { |
| 1009 | update_option( 'eael_save_typeform_personal_token', sanitize_text_field( $settings['typeform-personal-token'] ) ); |
| 1010 | } |
| 1011 | |
| 1012 | // Saving Duplicator Settings |
| 1013 | if ( isset( $settings['post-duplicator-post-type'] ) ) { |
| 1014 | update_option( 'eael_save_post_duplicator_post_type', sanitize_text_field( $settings['post-duplicator-post-type'] ) ); |
| 1015 | } |
| 1016 | |
| 1017 | // save js print method |
| 1018 | if ( isset( $settings['eael-js-print-method'] ) ) { |
| 1019 | update_option( 'eael_js_print_method', sanitize_text_field( $settings['eael-js-print-method'] ) ); |
| 1020 | } |
| 1021 | |
| 1022 | $settings = array_map( 'sanitize_text_field', $settings ); |
| 1023 | $defaults = array_fill_keys( array_keys( array_merge( $this->registered_elements, $this->registered_extensions ) ), false ); |
| 1024 | $elements = array_merge( $defaults, array_fill_keys( array_keys( array_intersect_key( $settings, $defaults ) ), true ) ); |
| 1025 | |
| 1026 | // update new settings |
| 1027 | $updated = update_option( 'eael_save_settings', $elements ); |
| 1028 | |
| 1029 | // clear assets files |
| 1030 | $this->empty_dir( EAEL_ASSET_PATH ); |
| 1031 | |
| 1032 | wp_send_json( $updated ); |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * Clear Cache Files |
| 1037 | * Clear cache files from uploads/essential-addons-elementor |
| 1038 | * |
| 1039 | * @access public |
| 1040 | * @return void |
| 1041 | * @since 3.0.0 |
| 1042 | */ |
| 1043 | public function clear_cache_files() { |
| 1044 | check_ajax_referer( 'essential-addons-elementor', 'security' ); |
| 1045 | |
| 1046 | if ( ! current_user_can( 'manage_options' ) ) { |
| 1047 | wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) ); |
| 1048 | } |
| 1049 | |
| 1050 | if ( isset( $_REQUEST['posts'] ) ) { |
| 1051 | if ( ! empty( $_POST['posts'] ) ) { |
| 1052 | foreach ( json_decode( $_POST['posts'] ) as $post ) { |
| 1053 | $this->remove_files( 'post-' . $post ); |
| 1054 | } |
| 1055 | } |
| 1056 | } else { |
| 1057 | // clear cache files |
| 1058 | $this->empty_dir( EAEL_ASSET_PATH ); |
| 1059 | if ( $this->is_activate_elementor() ) { |
| 1060 | \Elementor\Plugin::$instance->files_manager->clear_cache(); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | // Purge All LS Cache |
| 1065 | do_action( 'litespeed_purge_all', '3rd Essential Addons for Elementor' ); |
| 1066 | |
| 1067 | // After clear the cache hook |
| 1068 | do_action( 'eael_after_clear_cache_files' ); |
| 1069 | |
| 1070 | wp_send_json( true ); |
| 1071 | } |
| 1072 | |
| 1073 | public function eael_admin_promotion(){ |
| 1074 | check_ajax_referer( 'essential-addons-elementor', 'security' ); |
| 1075 | |
| 1076 | if ( ! current_user_can( 'manage_options' ) ) { |
| 1077 | wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) ); |
| 1078 | } |
| 1079 | |
| 1080 | update_option( 'eael_admin_promotion', self::EAEL_PROMOTION_FLAG ); |
| 1081 | } |
| 1082 | |
| 1083 | /** |
| 1084 | * Get nonce token through ajax request |
| 1085 | * |
| 1086 | * @since 5.1.13 |
| 1087 | * @return void |
| 1088 | */ |
| 1089 | public function eael_get_token() { |
| 1090 | $nonce = wp_create_nonce( 'essential-addons-elementor' ); |
| 1091 | if ( $nonce ) { |
| 1092 | wp_send_json_success( [ 'nonce' => $nonce ] ); |
| 1093 | } |
| 1094 | wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) ); |
| 1095 | } |
| 1096 | |
| 1097 | public function eael_yith_wcwl_ajax_disable( $request ) { |
| 1098 | add_filter( 'option_yith_wcwl_ajax_enable', function ( $data ) { |
| 1099 | return 'no'; |
| 1100 | } ); |
| 1101 | } |
| 1102 | } |
| 1103 |