PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.3.1
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.3.1
2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 All 128 releases
wdesignkit / includes / admin / class-api.php

class-api.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 2.3.1, at includes/admin/class-api.php

5,073 lines 155.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * @link https://posimyth.com/
6 * @since 1.0.0
7 *
8 * @package Wdesignkit
9 * @subpackage Wdesignkit/includes
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 use wdkit\Wdkit_Wdesignkit;
17 use wdkit\WdKit_enqueue\Wdkit_Enqueue;
18 use wdkit\wdkit_datahooks\Wdkit_Data_Hooks;
19
20 if ( ! class_exists( 'Wdkit_Api_Call' ) ) {
21
22 /**
23 * Main classs call for all api
24 *
25 * @link https://posimyth.com/
26 * @since 1.0.0
27 */
28 class Wdkit_Api_Call {
29
30 /**
31 * Member Variable
32 *
33 * @var instance
34 */
35 private static $instance;
36
37 /**
38 * Member Variable
39 *
40 * @var staring widgets_with_post_category
41 */
42 public $widgets_with_post_category = array(
43 'post_category', 'include_products',
44 );
45
46 /**
47 * Member Variable
48 *
49 * @var staring $wdkit_api
50 */
51 public $wdkit_api = WDKIT_SERVER_API_URL . 'api/wp/';
52
53 /**
54 * Member Variable
55 *
56 * @var staring $wdkit_api_v2
57 */
58 public $wdkit_api_v2 = WDKIT_SERVER_API_URL . 'api/v2/wp/';
59
60 /**
61 * Member Variable
62 *
63 * @var staring $widget_folder_u_r_l
64 */
65 public $widget_folder_u_r_l = '';
66
67 /**
68 * Member Variable
69 *
70 * @var staring $e_msg_login
71 */
72 public $e_msg_login = 'Login Error: Check your details and try again.';
73
74 /**
75 * Member Variable
76 *
77 * @var staring $e_desc_login
78 */
79 public $e_desc_login = 'Invalid Login Details';
80
81 /**
82 * Member Variable
83 *
84 * @var staring wdkit_onbording_api
85 */
86 public $wdkit_onbording_api = 'https://api.posimyth.com/wp-json/wdkit/v2/wdkit_store_user_data';
87
88 /**
89 * Member Variable
90 *
91 * @var staring wdkit_onbording_end
92 */
93 public $wdkit_onbording_end = 'wkit_onbording_end';
94
95 /**
96 * Initiator
97 */
98 public static function get_instance() {
99 if ( ! isset( self::$instance ) ) {
100 self::$instance = new self();
101 }
102
103 return self::$instance;
104 }
105
106 /**
107 * Define the core functionality of the plugin.
108 */
109 public function __construct() {
110 add_action( 'wp_ajax_get_wdesignkit', array( $this, 'wdkit_api_call' ) );
111 }
112
113 /**
114 * Error JSON message
115 *
116 * @param array $data give array.
117 * @param string $status api code number.
118 *
119 * @since 1.0.0
120 * */
121 public function wdkit_error_msg( $data = null, $status = null ) {
122 wp_send_json_error( $data );
123 wp_die();
124 }
125
126 /**
127 * Success JSON message
128 *
129 * @param array $data give array.
130 * @param string $status api code number.
131 *
132 * @since 1.0.0
133 * */
134 public function wdkit_success_msg( $data = null, $status = null ) {
135 wp_send_json_success( $data, $status );
136 wp_die();
137 }
138
139 /**
140 * Get Wdkit Api Call Ajax.
141 */
142 public function wdkit_api_call() {
143
144 check_ajax_referer( 'wdkit_nonce', 'kit_nonce' );
145
146 if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
147 wp_send_json_error( array( 'content' => __( 'Insufficient permissions.', 'wdesignkit' ) ) );
148 }
149
150 $type = isset( $_POST['type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['type'] ) ) ) : false;
151 if ( ! $type ) {
152 $this->wdkit_error_msg( __( 'Something went wrong.', 'wdesignkit' ) );
153 }
154
155 switch ( $type ) {
156 case 'onboarding_handler':
157 $data = $this->wdkit_onboarding_handler();
158 break;
159 case 'wkit_login':
160 $data = apply_filters( 'wp_wdkit_login_ajax', 'wkit_login' );
161 break;
162 case 'api_login':
163 $data = apply_filters( 'wp_wdkit_login_ajax', 'api_login' );
164 break;
165 case 'social_login':
166 $data = apply_filters( 'wp_wdkit_login_ajax', 'social_login' );
167 break;
168 case 'forgot_password':
169 $data = apply_filters( 'wp_wdkit_login_ajax', 'forgot_password' );
170 break;
171 case 'wdkit_user_signup':
172 $data = apply_filters( 'wp_wdkit_login_ajax', 'wdkit_user_signup' );
173 break;
174 case 'wkit_meta_data':
175 $data = $this->wdkit_meta_data();
176 break;
177 case 'get_user_info':
178 $data = $this->wdkit_get_user_info();
179 break;
180 case 'browse_page':
181 $data = $this->wdkit_browse_page();
182 break;
183 case 'kit_template':
184 $data = $this->wdkit_template();
185 break;
186 case 'wkit_preset_template':
187 $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_template' );
188 break;
189 case 'wdkit_preset_dwnld_template':
190 $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_dwnld_template' );
191 break;
192 case 'template_remove':
193 $data = $this->wdkit_template_remove();
194 break;
195 case 'save_template':
196 $data = $this->wdkit_put_save_template();
197 break;
198 case 'update_save_temp_image':
199 $data = $this->wdkit_update_save_temp_image();
200 break;
201 case 'get_global_val':
202 $data = $this->wdkit_get_global_val();
203 break;
204 case 'update_global_val':
205 $data = $this->wdkit_update_global_val();
206 break;
207 case 'wdkit_get_site_setting':
208 $data = $this->wdkit_get_site_setting();
209 break;
210 case 'wdkit_update_site_setting':
211 $data = $this->wdkit_update_site_setting();
212 break;
213 case 'update_preset_setting':
214 $data = $this->wdkit_update_preset();
215 break;
216 case 'find_template':
217 $data = $this->wdkit_find_existing_template();
218 break;
219 case 'update_template':
220 $data = $this->wdkit_update_template();
221 break;
222 case 'manage_favorite':
223 $data = $this->wdkit_manage_favorite();
224 break;
225 case 'check_plugins_depends':
226 $data = $this->wdkit_check_plugins_depends();
227 break;
228 case 'install_plugins_depends':
229 $data = $this->wdkit_install_plugins_depends();
230 break;
231 case 'generate_site_logo':
232 $data = $this->wkit_generate_site_logo();
233 break;
234 case 'generate_ai_content':
235 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'generate_ai_content' );
236 break;
237 case 'reset_site':
238 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'reset_site' );
239 break;
240 case 'wdkit_nxt_thembuilder_reset':
241 $data = $this->wdkit_nxt_thembuilder_reset();
242 break;
243 case 'wdkit_check_user_credit':
244 $data = $this->wdkit_check_user_credit();
245 break;
246 case 'wdkit_remove_header_footer':
247 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wdkit_remove_header_footer' );
248 break;
249 case 'check_post_count':
250 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'check_post_count' );
251 break;
252 case 'wkit_check_product_count':
253 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_check_product_count' );
254 break;
255 case 'select_team_img':
256 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'select_team_img' );
257 break;
258 case 'wkit_ai_desc_keyword':
259 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_ai_desc_keyword' );
260 break;
261 case 'wkit_ai_credit_update':
262 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_ai_credit_update' );
263 break;
264 case 'wkit_generate_post_data':
265 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_generate_post_data' );
266 break;
267 case 'wkit_generate_product_data':
268 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_generate_product_data' );
269 break;
270 case 'wkit_cteate_product':
271 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_cteate_product' );
272 break;
273 case 'wkit_remove_dummy_post':
274 $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_remove_dummy_post' );
275 break;
276 case 'update_latest_plugin':
277 $data = $this->wdkit_update_latest_plugin();
278 break;
279 case 'activate_container':
280 $data = $this->wdkit_activate_container();
281 break;
282 case 'import_taxonomy':
283 $data = $this->wdkit_import_taxonomy();
284 break;
285 case 'import_template':
286 $data = $this->wdkit_import_template();
287 break;
288 case 'import_multi_template':
289 $data = $this->wdkit_import_multi_template();
290 break;
291 case 'import_page_section':
292 $data = $this->import_page_section_content();
293 break;
294 case 'wkit_update_elementor_template':
295 $data = $this->wkit_update_elementor_template();
296 break;
297 case 'update_plugin_setting':
298 $data = $this->update_plugin_setting();
299 break;
300 case 'update_theme_setting':
301 $data = $this->update_theme_setting();
302 break;
303 case 'update_site_setting':
304 $data = $this->update_site_setting();
305 break;
306 case 'import_kit_template':
307 $data = $this->wdkit_import_kit_template();
308 break;
309 case 'enable_template_widgets':
310 $data = $this->wdkit_enable_template_widgets();
311 break;
312 case 'scan_nexter_widgets':
313 if ( ! empty( $_POST['blockNames'] ) && has_filter( 'nexter_block_list_merge' ) ) {
314
315 $posted_blocks = json_decode( stripslashes( $_POST['blockNames'] ), true );
316
317 if ( is_array( $posted_blocks ) ) {
318 $blockList = array_map( 'sanitize_text_field', $posted_blocks );
319
320 // �
321 filter call करो
322 $result = apply_filters( 'nexter_block_list_merge', $blockList );
323
324 wp_send_json( $result );
325 wp_die();
326 }
327 }
328
329 wp_send_json(
330 array(
331 'success' => false,
332 'message' => 'No block names received or filter not found.',
333 'description' => 'Ensure blockNames are posted and the filter is attached.',
334 )
335 );
336 wp_die();
337 $data = '';
338 break;
339 case 'shared_with_me':
340 $data = $this->wdkit_shared_with_me();
341 break;
342 case 'manage_workspace':
343 $data = $this->wdkit_manage_workspace();
344 break;
345 case 'widget_browse_page':
346 $data = apply_filters( 'wp_wdkit_widget_ajax', 'widget_browse_page' );
347 break;
348 case 'wkit_create_widget':
349 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_create_widget' );
350 break;
351 case 'wkit_import_widget':
352 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_import_widget' );
353 break;
354 case 'wkit_export_widget':
355 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_export_widget' );
356 break;
357 case 'wkit_delete_widget':
358 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_delete_widget' );
359 break;
360 case 'wkit_widget_preview':
361 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_widget_preview' );
362 break;
363 case 'wkit_check_widget_versions':
364 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_check_widget_versions' );
365 break;
366 case 'wkit_manage_widget_workspace':
367 $data = $this->wdkit_manage_widget_workspace();
368 break;
369 case 'wkit_activate_key':
370 $data = $this->wdkit_activate_key();
371 break;
372 case 'wkit_manage_widget_category':
373 $data = $this->wdkit_manage_widget_category();
374 break;
375 case 'wkit_widget_json':
376 $data = $this->wkit_widget_json();
377 break;
378 case 'wkit_download_widget':
379 $data = $this->wdkit_download_widget();
380 break;
381 case 'wkit_public_download_widget':
382 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_public_download_widget' );
383 break;
384 case 'wkit_add_widget':
385 $data = $this->wdkit_add_widget();
386 break;
387 case 'wkit_favourite_widget':
388 $data = $this->wdkit_favourite_widget();
389 break;
390 case 'wkit_setting_panel':
391 $data = $this->wdkit_setting_panel();
392 break;
393 case 'media_import':
394 $data = $this->wdkit_media_import();
395 break;
396 case 'active_licence':
397 $data = $this->wdkit_activate_licence();
398 break;
399 case 'delete_licence':
400 $data = $this->wdkit_delete_licence_key();
401 break;
402 case 'sync_licence':
403 $data = $this->wdkit_sync_licence_key();
404 break;
405 case 'get_wkit_version':
406 $data = $this->wdkit_prev_version();
407 break;
408 case 'rollback_wdkit':
409 $data = $this->wdkit_rollback_check();
410 break;
411 case 'wkit_logout':
412 $data = $this->wdkit_logout();
413 break;
414 case 'wkit_white_label':
415 $this->wkit_white_label();
416 break;
417 case 'wkit_reset_wl':
418 $data = $this->wkit_reset_wl();
419 break;
420 case 'wdkit_dark_mode':
421 $data = $this->wdkit_dark_mode();
422 break;
423 case 'wdkit_get_workspace_data':
424 $data = $this->wdkit_get_workspace_data();
425 break;
426 }
427
428 $this->wdkit_success_msg( $data );
429 // wp_die();
430 }
431
432 /**
433 *
434 * This Function is used for API call
435 *
436 * @since 1.0.0
437 *
438 * @param array $data give array.
439 * @param array $name store data.
440 */
441 protected function wkit_api_call( $data, $name ) {
442 $u_r_l = $this->wdkit_api;
443
444 if ( empty( $u_r_l ) ) {
445 return array(
446 'massage' => esc_html__( 'API Not Found', 'wdesignkit' ),
447 'success' => false,
448 );
449 }
450
451 $args = array(
452 'method' => 'POST',
453 'body' => $data,
454 'timeout' => 100,
455 );
456 $response = wp_remote_post( $u_r_l . $name, $args );
457
458 if ( is_wp_error( $response ) ) {
459 $error_message = $response->get_error_message();
460
461 /* Translators: %s is a placeholder for the error message */
462 $error_message = printf( esc_html__( 'API request error: %s', 'wdesignkit' ), esc_html( $error_message ) );
463
464 return array(
465 'massage' => $error_message,
466 'success' => false,
467 );
468 }
469
470 $status_code = wp_remote_retrieve_response_code( $response );
471 if ( 200 === $status_code ) {
472
473 return array(
474 'data' => json_decode( wp_remote_retrieve_body( $response ) ),
475 'massage' => esc_html__( 'Success', 'wdesignkit' ),
476 'status' => $status_code,
477 'success' => true,
478 );
479 }
480
481 $error_message = printf( 'Server error: %d', esc_html( $status_code ) );
482
483 if ( isset( $error_data->message ) ) {
484 $error_message .= ' (' . $error_data->message . ')';
485 }
486
487 return array(
488 'massage' => $error_message,
489 'status' => $status_code,
490 'success' => false,
491 );
492 }
493
494 /**
495 *
496 * It is Use for handle onboarding data.
497 *
498 * @since 1.0.9
499 */
500 public function wdkit_onboarding_handler() {
501 $page_template = isset( $_POST['page_template'] ) ? json_decode( wp_unslash( $_POST['page_template'] ), true ) : '';
502 $page_builder = isset( $_POST['page_builder'] ) ? json_decode( wp_unslash( $_POST['page_builder'] ), true ) : '';
503
504 $elementor_plugin = isset( $_POST['elementor_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['elementor_plugin'] ) ) : 0;
505 $tpag_plugin = isset( $_POST['tpag_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['tpag_plugin'] ) ) : 0;
506 $bricks_theme = isset( $_POST['bricks_theme'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['bricks_theme'] ) ) : 0;
507 $site_info = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : false;
508
509 $server_software = ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
510
511 $web_server = $server_software;
512 $memory_limit = ini_get( 'memory_limit' );
513 $max_execution_time = ini_get( 'max_execution_time' );
514 $php_version = phpversion();
515 $wp_version = get_bloginfo( 'version' );
516 $email = get_option( 'admin_email' );
517 $siteurl = get_option( 'siteurl' );
518 $language = get_bloginfo( 'language' );
519
520 // Active Plugin Name.
521 $act_plugin = array();
522 $actplu = get_option( 'active_plugins' );
523 if ( ! function_exists( 'get_plugins' ) ) {
524 require_once ABSPATH . 'wp-admin/includes/plugin.php';
525 }
526
527 $plugins = get_plugins();
528 foreach ( $actplu as $p ) {
529 if ( isset( $plugins[ $p ] ) ) {
530 $act_plugin[] = $plugins[ $p ]['Name'];
531 }
532 }
533
534 $plugin = wp_json_encode( $act_plugin );
535
536 $theme = '';
537 $acthemeobj = wp_get_theme();
538 if ( $acthemeobj->get( 'Name' ) !== null && ! empty( $acthemeobj->get( 'Name' ) ) ) {
539 $theme = $acthemeobj->get( 'Name' );
540 }
541
542 $basic_requirements = array(
543 'elementor_install' => $elementor_plugin,
544 'tpag_install' => $tpag_plugin,
545 'bricks_install' => $bricks_theme,
546 );
547
548 if ( ! empty( $site_info ) ) {
549 $final = array(
550 'web_server' => $web_server,
551 'memory_limit' => $memory_limit,
552 'max_execution_time' => $max_execution_time,
553 'php_version' => $php_version,
554 'wp_version' => $wp_version,
555 'email' => $email,
556 'site_url' => $siteurl,
557 'site_language' => $language,
558 'theme' => $theme,
559 'plugins' => $act_plugin,
560 'basic_requirements' => $basic_requirements,
561 'page_template' => $page_template,
562 'page_builder' => $page_builder,
563 );
564 } else {
565 $final = array();
566 }
567
568 $response = wp_remote_post(
569 $this->wdkit_onbording_api,
570 array(
571 'method' => 'POST',
572 'body' => wp_json_encode( $final ),
573 )
574 );
575
576 $existing_value = get_option( $this->wdkit_onbording_end );
577 if ( false === $existing_value ) {
578 add_option( $this->wdkit_onbording_end, true );
579 }
580
581 if ( is_wp_error( $response ) ) {
582 $result = array(
583 'success' => false,
584 'messages' => 'Oops',
585 'description' => 'Description',
586 );
587
588 wp_send_json( $result );
589 } else {
590 $status_one = wp_remote_retrieve_response_code( $response );
591
592 if ( 200 === $status_one ) {
593 $get_data_one = wp_remote_retrieve_body( $response );
594
595 $get_res = json_decode( json_decode( $get_data_one, true ), true );
596
597 $result = array(
598 'success' => ! empty( $get_res['success'] ) ? $get_res['success'] : false,
599 'messages' => ! empty( $get_res['messages'] ) ? $get_res['messages'] : 'success',
600 'description' => ! empty( $get_res['description'] ) ? $get_res['description'] : 'Description',
601 );
602
603 wp_send_json( $result );
604 } else {
605
606 $result = array(
607 'success' => false,
608 'messages' => 'Oops',
609 'description' => 'description',
610 );
611
612 wp_send_json( $result );
613 }
614 }
615
616 wp_die();
617 }
618
619 /**
620 *
621 * It is Use for get meta data for non login user
622 *
623 * @since 1.0.0
624 */
625 protected function wdkit_meta_data() {
626 $type = isset( $_POST['meta_type'] ) ? sanitize_text_field( wp_unslash( $_POST['meta_type'] ) ) : '';
627 $data = array( 'type' => $type );
628
629 $response = $this->wkit_api_call( $data, 'meta' );
630 $success = ! empty( $response['success'] ) ? $response['success'] : false;
631 $status = ! empty( $response['status'] ) ? (int) $response['status'] : 400;
632
633 if ( empty( $success ) ) {
634 $result = array(
635 'plugin' => array(),
636 'builder' => array(),
637 'category' => array(),
638 'widgetscategory' => array(),
639 'tags' => array(),
640 'widgetbuilder' => array(),
641
642 'message' => esc_html__( 'Server Error', 'wdesignkit' ),
643 'description' => esc_html__( 'Server Error, Data Not Found', 'wdesignkit' ),
644 'success' => false,
645 );
646
647 wp_send_json( $result );
648 wp_die();
649 }
650
651 $get_data_one = ! empty( $response['data'] ) ? $response['data'] : array();
652 $statuscode = array( 'HTTP_CODE' => $status );
653
654 $final = json_decode( wp_json_encode( $get_data_one ), true );
655
656 $final['Setting'] = self::wkit_get_settings_panel();
657 $final['widget_list'] = $this->wkit_manage_widget_sequence( array() );
658
659 $final = array(
660 'data' => $final,
661 );
662
663 wp_send_json( $final );
664 wp_die();
665 }
666
667 /**
668 *
669 * It is Use for get activate license key data from tpae and nexter blocks.
670 *
671 * @since 1.1.6
672 */
673 protected function wkit_manage_license_data() {
674 $manage_licence = array();
675 $theplus_active_check = is_plugin_active( 'the-plus-addons-for-elementor-page-builder/theplus_elementor_addon.php' );
676 $nexter_active_check = is_plugin_active( 'the-plus-addons-for-block-editor/the-plus-addons-for-block-editor.php' );
677
678 $theplus_licence = get_option( 'tpaep_licence_data', array() );
679
680 if ( ! empty( $theplus_active_check ) && ! empty( $theplus_licence ) ) {
681 $manage_licence['tpae'] = $theplus_licence;
682 }
683
684 $nexter_licence = get_option( 'tpgb_activate', array() );
685
686 if ( ! empty( $nexter_active_check ) && ! empty( $nexter_licence ) && ! empty( $nexter_licence['tpgb_activate_key'] ) ) {
687 $tpgb_license_status = get_option( 'tpgbp_license_status', array() );
688 $tpgb_license_status['license_key'] = $nexter_licence['tpgb_activate_key'];
689 $manage_licence['tpag'] = $tpgb_license_status;
690 }
691
692 return $manage_licence;
693 }
694
695 /**
696 *
697 * It is Use for get all info of user.
698 *
699 * @since 1.0.0
700 */
701 protected function wdkit_get_user_info() {
702 $token = isset( $_POST['token'] ) ? wp_unslash( $_POST['token'] ) : false;
703 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
704 $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['builder'] ) ) ) : '';
705
706 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
707
708 $response = array();
709
710 if ( empty( $token ) ) {
711 $response = array(
712 'success' => false,
713 'message' => $this->e_msg_login,
714 'description' => $this->e_desc_login,
715 );
716
717 wp_send_json( $response );
718 wp_die();
719 }
720
721 // $token = $this->wdkit_login_user_token( $email );
722 $args = array(
723 'token' => $token,
724 'builder' => $builder,
725 'site_url' => $site_url,
726 );
727
728 $response = WDesignKit_Data_Query::get_data( 'get_user_info', $args );
729 $status = ( ! empty( $response['status'] ) ) ? sanitize_text_field( $response['status'] ) : 'error';
730 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
731
732 /**Condtion user for user logout & expire token*/
733 if ( 'Token is Expired' === $status || 'Authorization Token not found' === $status ) {
734 delete_transient( 'wdkit_auth_' . $email );
735 // Clear stored license data when token expires so banner shows again
736 delete_option( 'wdkit_licence_data' );
737 }
738
739 if ( empty( $response ) ) {
740 $response['login_reset'] = 'yes';
741 }
742
743 // Store WDesignKit license data locally if present in response
744 if ( ! empty( $response['credits']['wdkit_licence'] ) && is_array( $response['credits']['wdkit_licence'] ) ) {
745 $wdkit_licence = $response['credits']['wdkit_licence'];
746 // Handle serialized data
747 if ( is_string( $wdkit_licence ) && is_serialized( $wdkit_licence ) ) {
748 $wdkit_licence = unserialize( $wdkit_licence );
749 }
750 if ( ! empty( $wdkit_licence ) && is_array( $wdkit_licence ) ) {
751 update_option( 'wdkit_licence_data', $wdkit_licence );
752 }
753 }
754
755 $response['Setting'] = $this->wkit_get_settings_panel();
756 $response['widget_list'] = $this->wkit_manage_widget_sequence( $response );
757 $response['manage_licence'] = $this->wkit_manage_license_data();
758
759 $response = array(
760 'data' => $response,
761 'success' => true,
762 );
763
764 wp_send_json( $response );
765 wp_die();
766 }
767
768 /**
769 *
770 * It is Use for get all widgets local and server.
771 *
772 * @since 1.0.19
773 * @param string $response userinfo store.
774 */
775 protected function wkit_manage_widget_sequence( $response = array() ) {
776
777 $credits = ! empty( $response['credits']['widget_limit']['meta_value'] ) ? $response['credits']['widget_limit']['meta_value'] : 10;
778 $server_list = ! empty( $response['widgettemplate'] ) ? $response['widgettemplate'] : array();
779 $db_builder_list = ! empty( $response['widgetbuilder'] ) ? $response['widgetbuilder'] : array();
780
781 $placeholderimg = WDKIT_URL . 'assets/images/placeholder.jpg';
782
783 $local_list = $this->wdkit_get_local_widgets();
784
785 $server_w_unique = array_column( $server_list, 'w_unique' );
786
787 $idx_builder = array();
788 foreach ( $db_builder_list as $index => $value ) {
789 $builder_name = ! empty( $value['builder_name'] ) ? $value['builder_name'] : '';
790 $w_id = ! empty( $value['w_id'] ) ? $value['w_id'] : '';
791
792 if ( ! empty( $builder_name ) ) {
793 $idx_builder[ $w_id ] = strtolower( str_replace( ' ', '_', trim( $builder_name ) ) );
794 }
795 }
796
797 foreach ( $server_list as $index => $value ) {
798 $get_id = $server_list[ $index ]['builder'] ? $server_list[ $index ]['builder'] : '';
799
800 $server_list[ $index ]['type'] = 'server';
801 $server_list[ $index ]['builder'] = ! empty( $idx_builder[ $get_id ] ) ? $idx_builder[ $get_id ] : '';
802 }
803
804 $count = 0;
805
806 foreach ( $local_list as $key => $value ) {
807 $widget_id = ! empty( $value['widgetdata']['widget_id'] ) ? $value['widgetdata']['widget_id'] : '';
808 $allow_push = isset( $value['widgetdata']['allow_push'] ) ? $value['widgetdata']['allow_push'] : true;
809
810 if ( in_array( $widget_id, $server_w_unique ) ) {
811
812 $index = array_search( $widget_id, $server_w_unique );
813
814 $server_list[ $index ]['title'] = $local_list[ $key ]['widgetdata']['name'];
815 $server_list[ $index ]['w_version'] = $local_list[ $key ]['widgetdata']['widget_version'];
816 $server_list[ $index ]['allow_push'] = $allow_push;
817 $server_list[ $index ]['builder'] = $local_list[ $key ]['widgetdata']['type'];
818 $server_list[ $index ]['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id'];
819 $server_list[ $index ]['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg;
820
821 $local_list[ $key ] = $server_list[ $index ];
822
823 $local_list[ $key ]['type'] = 'done';
824
825 unset( $server_list[ $index ] );
826 } else {
827 $local_list[ $key ]['widgetdata']['builder'] = $local_list[ $key ]['widgetdata']['type'];
828 $local_list[ $key ]['widgetdata']['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id'];
829 $local_list[ $key ]['widgetdata']['allow_push'] = $allow_push;
830 $local_list[ $key ]['widgetdata']['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg;
831 $local_list[ $key ]['widgetdata']['is_activated'] = 'active';
832
833 $local_list[ $key ]['widgetdata']['type'] = 'plugin';
834
835 $local_list[ $key ]['widgetdata']['title'] = $local_list[ $key ]['widgetdata']['name'];
836 unset( $local_list[ $key ]['widgetdata']['name'] );
837 unset( $local_list[ $key ]['widgetdata']['widget_id'] );
838
839 $local_list[ $key ] = $local_list[ $key ]['widgetdata'];
840 }
841 }
842
843 $final = array_merge( $local_list, $server_list );
844
845 $db_widget = array();
846
847 foreach ( $final as $key => $self ) {
848 $is_activated = ! empty( $final[ $key ]['is_activated'] ) ? $final[ $key ]['is_activated'] : 'active';
849
850 if ( 'active' === $is_activated ) {
851 ++$count;
852 }
853
854 if ( ( $count > $credits ) && ( 'unlimited' !== $credits ) ) {
855 $final[ $key ]['is_activated'] = 'deactive';
856 }
857
858 if ( ! empty( $self['is_activated'] ) && 'active' !== $self['is_activated'] ) {
859 $db_widget[] = array(
860 'w_unique' => $self['w_unique'],
861 'builder' => $self['builder'],
862 'title' => $self['title'],
863 'is_activated' => $self['is_activated'],
864 );
865 }
866 }
867
868 $get_db_widget = get_option( 'wkit_deactivate_widgets', array() );
869 if ( empty( $get_db_widget ) ) {
870 add_option( 'wkit_deactivate_widgets', $db_widget, '', 'yes' );
871 } else {
872 update_option( 'wkit_deactivate_widgets', $db_widget );
873 }
874
875 return $final;
876 }
877
878 /**
879 * Browse Page Filter
880 *
881 * @since 1.0.0
882 */
883 protected function wdkit_browse_page() {
884 $args = $this->wdkit_parse_args( $_POST );
885
886 $response = WDesignKit_Data_Query::get_data( 'browse_page', $args );
887
888 $manage_licence = array();
889 $manage_licence['theplus_elementor_addon'] = ! empty( defined( 'THEPLUS_VERSION' ) ) ? true : false;
890 $manage_licence['tpag'] = ! empty( defined( 'TPGBP_VERSION' ) ) ? true : false;
891 $manage_licence['elementor-pro'] = ! empty( defined( 'ELEMENTOR_PRO_VERSION' ) ) ? true : false;
892 $response['manage_licence'] = $manage_licence;
893
894 wp_send_json( $response );
895 wp_die();
896 }
897
898 /**
899 *
900 * It is Use for get template from kit.
901 *
902 * @since 1.0.0
903 */
904 protected function wdkit_template() {
905 $args = $this->wdkit_parse_args( $_POST );
906
907 $response = WDesignKit_Data_Query::get_data( 'kit_template', $args );
908
909 wp_send_json( $response );
910 wp_die();
911 }
912
913 /**
914 *
915 * It is Use for remove or delete template.
916 *
917 * @since 1.0.0
918 */
919 protected function wdkit_template_remove() {
920 $args = $this->wdkit_parse_args( $_POST );
921
922 $user_email = strtolower( sanitize_email( $args['email'] ) );
923 $response = '';
924
925 if ( empty( $user_email ) || empty( $args['template_id'] ) ) {
926 $response = response()->json(
927 array(
928 'message' => $this->e_msg_login,
929 'description' => $this->e_desc_login,
930 'success' => true,
931 )
932 );
933
934 wp_send_json( $response );
935 wp_die();
936 }
937
938 $args['token'] = $this->wdkit_login_user_token( $user_email );
939
940 unset( $user_email );
941 $response = WDesignKit_Data_Query::get_data( 'template_remove', $args );
942
943 wp_send_json( $response );
944 wp_die();
945 }
946
947 /**
948 *
949 * It is Use for save template from page builder.
950 *
951 * @since 1.0.0
952 */
953 protected function wdkit_put_save_template() {
954 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
955 $post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '';
956 $builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '';
957
958 $response = '';
959
960 if ( empty( $email ) ) {
961 $response = array(
962 'id' => 0,
963 'editpage' => '',
964 'message' => $this->e_msg_login,
965 'description' => $this->e_desc_login,
966 'success' => false,
967 );
968
969 wp_send_json( $response );
970 wp_die();
971 }
972
973 $args = $this->wdkit_parse_args( $_POST );
974 $args['token'] = $this->wdkit_login_user_token( $email );
975 unset( $args['email'] );
976
977 if( 'elementor' === $builder ){
978 $args['data'] = base64_decode( $args['data'] );
979 } else if ( 'gutenberg' === $builder ) {
980 $args['data'] = base64_decode( $args['data'] );
981 }
982
983 global $post;
984
985 $custom_fields = array();
986 if ( ! empty( $post_id ) ) {
987 $meta_fields = get_post_custom( $post_id );
988
989 foreach ( $meta_fields as $key => $value ) {
990 if ( str_contains( $key, 'nxt-' ) ) {
991 $custom_fields[ $key ] = $value;
992 }
993 }
994
995 if ( ! empty( $custom_fields ) ) {
996 $data = json_decode( $args['data'], true );
997 $data['custom_meta'] = $custom_fields;
998 $args['data'] = wp_json_encode( $data );
999 }
1000 }
1001
1002 $response = WDesignKit_Data_Query::get_data( 'save_template', $args );
1003
1004 wp_send_json( $response );
1005 wp_die();
1006 }
1007
1008 /**
1009 *
1010 * It is Use for update save template image.
1011 *
1012 * @since 2.0.6
1013 */
1014 protected function wdkit_update_save_temp_image() {
1015 $temp_content = isset( $_POST['temp_content'] ) ? esc_url_raw( $_POST['temp_content'] ) : '';
1016 $content_name = isset( $_POST['content_name'] ) ? sanitize_text_field( $_POST['content_name'] ) : '';
1017 $token = isset( $_POST['token'] ) ? sanitize_text_field( $_POST['token'] ) : '';
1018 $user_type = isset( $_POST['user_type'] ) ? sanitize_text_field( $_POST['user_type'] ) : '';
1019 $type = isset( $_POST['content_type'] ) ? sanitize_text_field( $_POST['content_type'] ) : '';
1020 $id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : '';
1021 if ( empty( $temp_content ) || empty( $user_type ) || empty( $id ) || empty( $token ) ) {
1022 $response = array(
1023 'message' => __( 'Data not found', 'wdesignkit' ),
1024 'description' => __( 'Data not found', 'wdesignkit' ),
1025 'success' => false,
1026 );
1027 } else {
1028 $temp_content = str_replace( '\\', '', $temp_content );
1029 $temp_content = wp_remote_get( $temp_content )['body'];
1030 $temp_content = base64_encode( $temp_content );
1031
1032 $args = array(
1033 'token' => $token,
1034 'template_id' => $id,
1035 'name' => $content_name,
1036 'content' => $temp_content,
1037 'type' => $type,
1038 );
1039
1040 $response = $this->wkit_api_call( $args, 'save_images' );
1041 $success = ! empty( $response['success'] ) ? $response['success'] : false;
1042
1043 if ( $success ) {
1044 $response = array(
1045 'data' => $response['data'],
1046 'success' => true,
1047 );
1048 } else {
1049 $response = array(
1050 'message' => __( 'API Error', 'wdesignkit' ),
1051 'description' => __( 'API Error', 'wdesignkit' ),
1052 'data' => $response['data'],
1053 'success' => false,
1054 );
1055 }
1056 }
1057
1058 wp_send_json( $response );
1059 wp_die();
1060 }
1061
1062 /**
1063 *
1064 * Get Elementor Global color and Typography.
1065 *
1066 * @since 1.1.16
1067 */
1068 protected function wdkit_get_global_val() {
1069
1070 $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( $_POST['builder'] ) ) : '';
1071
1072 if ( 'elementor' === $builder ) {
1073 $kit_id = get_option( 'elementor_active_kit' );
1074 if ( empty( $kit_id ) ) {
1075 $response = array(
1076 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
1077 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
1078 'success' => false,
1079 );
1080
1081 wp_send_json( $response );
1082 wp_die();
1083 }
1084
1085 $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
1086 if ( empty( $kit_meta['system_colors'] ) ) {
1087 $static_meta = array(
1088 'system_colors' => array(
1089 0 => array(
1090 '_id' => 'primary',
1091 'title' => 'Primary',
1092 'color' => '#6EC1E4',
1093 ),
1094 1 => array(
1095 '_id' => 'secondary',
1096 'title' => 'Secondary',
1097 'color' => '#54595F',
1098 ),
1099 2 => array(
1100 '_id' => 'text',
1101 'title' => 'Text',
1102 'color' => '#7A7A7A',
1103 ),
1104 3 => array(
1105 '_id' => 'accent',
1106 'title' => 'Accent',
1107 'color' => '#61CE70',
1108 ),
1109 ),
1110 'custom_colors' => array(),
1111 'system_typography' => array(
1112 0 => array(
1113 '_id' => 'primary',
1114 'title' => 'Primary',
1115 'typography_typography' => 'custom',
1116 'typography_font_family' => 'Roboto',
1117 'typography_font_weight' => '600',
1118 ),
1119 1 => array(
1120 '_id' => 'secondary',
1121 'title' => 'Secondary',
1122 'typography_typography' => 'custom',
1123 'typography_font_family' => 'Roboto Slab',
1124 'typography_font_weight' => '400',
1125 ),
1126 2 => array(
1127 '_id' => 'text',
1128 'title' => 'Text',
1129 'typography_typography' => 'custom',
1130 'typography_font_family' => 'Roboto',
1131 'typography_font_weight' => '400',
1132 ),
1133 3 => array(
1134 '_id' => 'accent',
1135 'title' => 'Accent',
1136 'typography_typography' => 'custom',
1137 'typography_font_family' => 'Roboto',
1138 'typography_font_weight' => '500',
1139 ),
1140 ),
1141 'custom_typography' => array(),
1142 'default_generic_fonts' => 'Sans-serif',
1143 'site_name' => ! empty( get_bloginfo( 'name' ) ) ? get_bloginfo( 'name' ) : '',
1144 'page_title_selector' => 'h1.entry-title',
1145 'activeItemIndex' => 1,
1146 'viewport_md' => 768,
1147 'viewport_lg' => 1025,
1148 );
1149
1150 $kit_meta = $static_meta;
1151 update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta );
1152 }
1153
1154 $system_colors = ! empty( $kit_meta['system_colors'] ) ? $kit_meta['system_colors'] : array();
1155 $custom_colors = ! empty( $kit_meta['custom_colors'] ) ? $kit_meta['custom_colors'] : array();
1156 $system_typography = ! empty( $kit_meta['system_typography'] ) ? $kit_meta['system_typography'] : array();
1157 $custom_typography = ! empty( $kit_meta['custom_typography'] ) ? $kit_meta['custom_typography'] : array();
1158
1159 $color_array = array_merge( $system_colors, $custom_colors );
1160 $typo_array = array_merge( $system_typography, $custom_typography );
1161
1162 $global_data = array(
1163 'color' => $color_array,
1164 'typography' => $typo_array,
1165 );
1166
1167 $response = array(
1168 'message' => __( 'Global data Found', 'wdesignkit' ),
1169 'description' => __( 'Global Color and Typography found', 'wdesignkit' ),
1170 'data' => $global_data,
1171 'success' => true,
1172 );
1173
1174 } elseif ( 'gutenberg' === $builder ) {
1175
1176 $plus_settings = get_option( 'tpgb_global_options', false );
1177 $plus_settings = ! empty( $plus_settings ) ? json_decode( $plus_settings, true ) : json_decode( '[]' );
1178
1179 if ( empty( $plus_settings ) ) {
1180
1181 $static_meta = array(
1182 'active' => 'preset1',
1183 'darkMode' => 'none',
1184 'presets' => array(
1185 'preset1' => array(
1186 'name' => 'Preset 1',
1187 'key' => 'preset1',
1188 'colors' => array(
1189 array(
1190 'label' => 'Primary',
1191 'value' => '#8072FC',
1192 ),
1193 array(
1194 'label' => 'Secondary',
1195 'value' => '#6FC784',
1196 ),
1197 array(
1198 'label' => 'Tertiary',
1199 'value' => '#FF5A6E',
1200 ),
1201 array(
1202 'label' => 'Accent',
1203 'value' => '#F3F3F3',
1204 ),
1205 array(
1206 'label' => 'Background',
1207 'value' => '#888888',
1208 ),
1209 ),
1210 'gradient' => array(
1211 array(
1212 'label' => 'Primary',
1213 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1214 ),
1215
1216 array(
1217 'label' => 'Secondary',
1218 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1219 ),
1220
1221 array(
1222 'label' => 'Tertiary',
1223 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1224 ),
1225
1226 array(
1227 'label' => 'Accent',
1228 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1229 ),
1230
1231 array(
1232 'label' => 'Background',
1233 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1234 ),
1235 ),
1236 'spacing' => array(
1237 array(
1238 'label' => 'Large',
1239 'value' => array(
1240 'md' => 70,
1241 'unit' => 'px',
1242 ),
1243 ),
1244 array(
1245 'label' => 'Medium',
1246 'value' => array(
1247 'md' => 40,
1248 'unit' => 'px',
1249 ),
1250 ),
1251 array(
1252 'label' => 'Small',
1253 'value' => array(
1254 'md' => 20,
1255 'unit' => 'px',
1256 ),
1257
1258 ),
1259 ),
1260 'typography' => array(
1261 array(
1262 'label' => 'Display Text',
1263 'value' => array(
1264 'openTypography' => 1,
1265 'size' => array(
1266 'md' => 65,
1267 'unit' => 'px',
1268 ),
1269 'height' => array(
1270 'md' => 75,
1271 'unit' => 'px',
1272 ),
1273 'fontFamily' => array(
1274 'family' => 'Roboto',
1275 'type' => 'sans-serif',
1276 'fontWeight' => 700,
1277 ),
1278 'spacing' => array(
1279 'md' => 0,
1280 'unit' => 'px',
1281 ),
1282 ),
1283 ),
1284 array(
1285 'label' => 'Headline',
1286 'value' => array(
1287 'openTypography' => 1,
1288 'size' => array(
1289 'md' => 45,
1290 'unit' => 'px',
1291 ),
1292 'height' => array(
1293 'md' => 60,
1294 'unit' => 'px',
1295 ),
1296 'fontFamily' => array(
1297 'family' => 'Roboto',
1298 'type' => 'sans-serif',
1299 'fontWeight' => 700,
1300 ),
1301 'spacing' => array(
1302 'md' => 0,
1303 'unit' => 'px',
1304 ),
1305 ),
1306 ),
1307 array(
1308 'label' => 'Sub Headline',
1309 'value' => array(
1310 'openTypography' => 1,
1311 'size' => array(
1312 'md' => 38,
1313 'unit' => 'px',
1314 ),
1315 'height' => array(
1316 'md' => 45,
1317 'unit' => 'px',
1318 ),
1319 'fontFamily' => array(
1320 'family' => 'Roboto',
1321 'type' => 'sans-serif',
1322 'fontWeight' => 500,
1323 ),
1324 'spacing' => array(
1325 'md' => 0,
1326 'unit' => 'px',
1327 ),
1328 ),
1329 ),
1330 array(
1331 'label' => 'Title 1',
1332 'value' => array(
1333 'openTypography' => 1,
1334 'size' => array(
1335 'md' => 30,
1336 'unit' => 'px',
1337 ),
1338 'height' => array(
1339 'md' => 40,
1340 'unit' => 'px',
1341 ),
1342 'fontFamily' => array(
1343 'family' => 'Roboto',
1344 'type' => 'sans-serif',
1345 'fontWeight' => 500,
1346 ),
1347 'spacing' => array(
1348 'md' => 0,
1349 'unit' => 'px',
1350 ),
1351 ),
1352 ),
1353 array(
1354 'label' => 'Title 2',
1355 'value' => array(
1356 'openTypography' => 1,
1357 'size' => array(
1358 'md' => 25,
1359 'unit' => 'px',
1360 ),
1361 'height' => array(
1362 'md' => 30,
1363 'unit' => 'px',
1364 ),
1365 'fontFamily' => array(
1366 'family' => 'Roboto',
1367 'type' => 'sans-serif',
1368 'fontWeight' => 400,
1369 ),
1370 'spacing' => array(
1371 'md' => 0,
1372 'unit' => 'px',
1373 ),
1374 ),
1375 ),
1376 array(
1377 'label' => 'Body',
1378 'value' => array(
1379 'openTypography' => 1,
1380 'size' => array(
1381 'md' => 17,
1382 'unit' => 'px',
1383 ),
1384 'height' => array(
1385 'md' => 22,
1386 'unit' => 'px',
1387 ),
1388 'fontFamily' => array(
1389 'family' => 'Roboto',
1390 'type' => 'sans-serif',
1391 'fontWeight' => 400,
1392 ),
1393 'spacing' => array(
1394 'md' => 0,
1395 'unit' => 'px',
1396 ),
1397 ),
1398 ),
1399 array(
1400 'label' => 'Captions',
1401 'value' => array(
1402 'openTypography' => 1,
1403 'size' => array(
1404 'md' => 13,
1405 'unit' => 'px',
1406 ),
1407 'height' => array(
1408 'md' => 16,
1409 'unit' => 'px',
1410 ),
1411 'fontFamily' => array(
1412 'family' => 'Roboto',
1413 'type' => 'sans-serif',
1414 'fontWeight' => 400,
1415 ),
1416 'spacing' => array(
1417 'md' => 0,
1418 'unit' => 'px',
1419 ),
1420 ),
1421 ),
1422 ),
1423 'boxshadow' => array(
1424 array(
1425 'label' => 'Normal Shadow',
1426 'value' => array(
1427 'openShadow' => 1,
1428 'inset' => 0,
1429 'horizontal' => 2,
1430 'vertical' => 6,
1431 'blur' => 10,
1432 'spread' => 0,
1433 'color' => 'rgba(0,0,0,0.15)',
1434 ),
1435 ),
1436 array(
1437 'label' => 'Hover Shadow',
1438 'value' => array(
1439 'openShadow' => 1,
1440 'inset' => 0,
1441 'horizontal' => 2,
1442 'vertical' => 5,
1443 'blur' => 14,
1444 'spread' => 3,
1445 'color' => 'rgba(0,0,0,0.2)',
1446 ),
1447 ),
1448 ),
1449 ),
1450 'preset2' => array(
1451 'name' => 'Preset 2',
1452 'key' => 'preset2',
1453 'colors' => array(
1454 array(
1455 'label' => 'Primary',
1456 'value' => '#8072FC',
1457 ),
1458 array(
1459 'label' => 'Secondary',
1460 'value' => '#6FC784',
1461 ),
1462 array(
1463 'label' => 'Tertiary',
1464 'value' => '#FF5A6E',
1465 ),
1466 array(
1467 'label' => 'Accent',
1468 'value' => '#F3F3F3',
1469 ),
1470 array(
1471 'label' => 'Background',
1472 'value' => '#888888',
1473 ),
1474 ),
1475 'gradient' => array(
1476 array(
1477 'label' => 'Primary',
1478 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1479 ),
1480
1481 array(
1482 'label' => 'Secondary',
1483 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1484 ),
1485
1486 array(
1487 'label' => 'Tertiary',
1488 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1489 ),
1490
1491 array(
1492 'label' => 'Accent',
1493 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1494 ),
1495
1496 array(
1497 'label' => 'Background',
1498 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1499 ),
1500 ),
1501 'spacing' => array(
1502 array(
1503 'label' => 'Large',
1504 'value' => array(
1505 'md' => 70,
1506 'unit' => 'px',
1507 ),
1508 ),
1509 array(
1510 'label' => 'Medium',
1511 'value' => array(
1512 'md' => 40,
1513 'unit' => 'px',
1514 ),
1515 ),
1516 array(
1517 'label' => 'Small',
1518 'value' => array(
1519 'md' => 20,
1520 'unit' => 'px',
1521 ),
1522
1523 ),
1524 ),
1525 'typography' => array(
1526 array(
1527 'label' => 'Display Text',
1528 'value' => array(
1529 'openTypography' => 1,
1530 'size' => array(
1531 'md' => 65,
1532 'unit' => 'px',
1533 ),
1534 'height' => array(
1535 'md' => 75,
1536 'unit' => 'px',
1537 ),
1538 'fontFamily' => array(
1539 'family' => 'Roboto',
1540 'type' => 'sans-serif',
1541 'fontWeight' => 700,
1542 ),
1543 'spacing' => array(
1544 'md' => 0,
1545 'unit' => 'px',
1546 ),
1547 ),
1548 ),
1549 array(
1550 'label' => 'Headline',
1551 'value' => array(
1552 'openTypography' => 1,
1553 'size' => array(
1554 'md' => 45,
1555 'unit' => 'px',
1556 ),
1557 'height' => array(
1558 'md' => 60,
1559 'unit' => 'px',
1560 ),
1561 'fontFamily' => array(
1562 'family' => 'Roboto',
1563 'type' => 'sans-serif',
1564 'fontWeight' => 700,
1565 ),
1566 'spacing' => array(
1567 'md' => 0,
1568 'unit' => 'px',
1569 ),
1570 ),
1571 ),
1572 array(
1573 'label' => 'Sub Headline',
1574 'value' => array(
1575 'openTypography' => 1,
1576 'size' => array(
1577 'md' => 38,
1578 'unit' => 'px',
1579 ),
1580 'height' => array(
1581 'md' => 45,
1582 'unit' => 'px',
1583 ),
1584 'fontFamily' => array(
1585 'family' => 'Roboto',
1586 'type' => 'sans-serif',
1587 'fontWeight' => 500,
1588 ),
1589 'spacing' => array(
1590 'md' => 0,
1591 'unit' => 'px',
1592 ),
1593 ),
1594 ),
1595 array(
1596 'label' => 'Title 1',
1597 'value' => array(
1598 'openTypography' => 1,
1599 'size' => array(
1600 'md' => 30,
1601 'unit' => 'px',
1602 ),
1603 'height' => array(
1604 'md' => 40,
1605 'unit' => 'px',
1606 ),
1607 'fontFamily' => array(
1608 'family' => 'Roboto',
1609 'type' => 'sans-serif',
1610 'fontWeight' => 500,
1611 ),
1612 'spacing' => array(
1613 'md' => 0,
1614 'unit' => 'px',
1615 ),
1616 ),
1617 ),
1618 array(
1619 'label' => 'Title 2',
1620 'value' => array(
1621 'openTypography' => 1,
1622 'size' => array(
1623 'md' => 25,
1624 'unit' => 'px',
1625 ),
1626 'height' => array(
1627 'md' => 30,
1628 'unit' => 'px',
1629 ),
1630 'fontFamily' => array(
1631 'family' => 'Roboto',
1632 'type' => 'sans-serif',
1633 'fontWeight' => 400,
1634 ),
1635 'spacing' => array(
1636 'md' => 0,
1637 'unit' => 'px',
1638 ),
1639 ),
1640 ),
1641 array(
1642 'label' => 'Body',
1643 'value' => array(
1644 'openTypography' => 1,
1645 'size' => array(
1646 'md' => 17,
1647 'unit' => 'px',
1648 ),
1649 'height' => array(
1650 'md' => 22,
1651 'unit' => 'px',
1652 ),
1653 'fontFamily' => array(
1654 'family' => 'Roboto',
1655 'type' => 'sans-serif',
1656 'fontWeight' => 400,
1657 ),
1658 'spacing' => array(
1659 'md' => 0,
1660 'unit' => 'px',
1661 ),
1662 ),
1663 ),
1664 array(
1665 'label' => 'Captions',
1666 'value' => array(
1667 'openTypography' => 1,
1668 'size' => array(
1669 'md' => 13,
1670 'unit' => 'px',
1671 ),
1672 'height' => array(
1673 'md' => 16,
1674 'unit' => 'px',
1675 ),
1676 'fontFamily' => array(
1677 'family' => 'Roboto',
1678 'type' => 'sans-serif',
1679 'fontWeight' => 400,
1680 ),
1681 'spacing' => array(
1682 'md' => 0,
1683 'unit' => 'px',
1684 ),
1685 ),
1686 ),
1687 ),
1688 'boxshadow' => array(
1689 array(
1690 'label' => 'Normal Shadow',
1691 'value' => array(
1692 'openShadow' => 1,
1693 'inset' => 0,
1694 'horizontal' => 2,
1695 'vertical' => 6,
1696 'blur' => 10,
1697 'spread' => 0,
1698 'color' => 'rgba(0,0,0,0.15)',
1699 ),
1700 ),
1701 array(
1702 'label' => 'Hover Shadow',
1703 'value' => array(
1704 'openShadow' => 1,
1705 'inset' => 0,
1706 'horizontal' => 2,
1707 'vertical' => 5,
1708 'blur' => 14,
1709 'spread' => 3,
1710 'color' => 'rgba(0,0,0,0.2)',
1711 ),
1712 ),
1713 ),
1714 ),
1715 ),
1716 'globalContainer' => array(
1717 'md' => '',
1718 'unit' => 'px',
1719 ),
1720 );
1721
1722 update_option( 'tpgb_global_options', json_encode( $static_meta ) );
1723 $plus_settings = $static_meta;
1724 }
1725
1726 $active_id = ! empty( $plus_settings['active'] ) ? $plus_settings['active'] : '';
1727 $preset_array = ! empty( $plus_settings['presets'] ) ? $plus_settings['presets'] : array();
1728 $act_preset = ! empty( $plus_settings['presets'][ $active_id ] ) ? $plus_settings['presets'][ $active_id ] : array();
1729
1730 foreach ( $act_preset['colors'] as $index => &$item ) {
1731 $item['id'] = $index + 1;
1732 }
1733 unset( $item );
1734
1735 foreach ( $act_preset['typography'] as $index => &$item ) {
1736 $item['id'] = $index + 1;
1737 }
1738 unset( $item );
1739
1740 $act_preset['color'] = $act_preset['colors'];
1741 unset( $act_preset['colors'] );
1742
1743 $response = array(
1744 'message' => __( 'Global data Found', 'wdesignkit' ),
1745 'description' => __( 'Global Color and Typography found', 'wdesignkit' ),
1746 'data' => $act_preset,
1747 'success' => true,
1748 );
1749 }
1750
1751 wp_send_json( $response );
1752 wp_die();
1753 }
1754
1755 /**
1756 *
1757 * Get site settings.
1758 *
1759 * @since 2.1.3
1760 */
1761 protected function wdkit_get_site_setting() {
1762
1763 $kit_id = get_option( 'elementor_active_kit' );
1764 if ( empty( $kit_id ) ) {
1765 $response = array(
1766 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
1767 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
1768 'success' => false,
1769 );
1770
1771 wp_send_json( $response );
1772 wp_die();
1773 }
1774
1775 $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
1776
1777 $container_width = ! empty( $kit_meta['container_width'] ) ? $kit_meta['container_width'] : array();
1778 $globals = ! empty( $kit_meta['__globals__'] ) ? $kit_meta['__globals__'] : array();
1779 $body_background_color = ! empty( $kit_meta['body_background_color'] ) ? $kit_meta['body_background_color'] : array();
1780
1781 $site_globals = array(
1782 'body_background_color' => $body_background_color,
1783 'container_width' => $container_width,
1784 'globals' => $globals,
1785 );
1786
1787 $response = array(
1788 'message' => __( 'Global data Found', 'wdesignkit' ),
1789 'description' => __( 'Global Color and Typography found', 'wdesignkit' ),
1790 'data' => $site_globals,
1791 'success' => true,
1792 );
1793
1794 wp_send_json( $response );
1795 wp_die();
1796 }
1797
1798 /**
1799 *
1800 * update site settings.
1801 *
1802 * @since 2.1.3
1803 */
1804 protected function wdkit_update_site_setting() {
1805
1806 $builder = ! empty( $_POST['builder'] ) ? sanitize_text_field( $_POST['builder'] ) : '';
1807 $site_data = ! empty( $_POST['site_data'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['site_data'] ) ), true ) : array();
1808
1809 if ( 'elementor' == $builder ) {
1810 $kit_id = get_option( 'elementor_active_kit' );
1811 if ( ! $kit_id ) {
1812 $response = array(
1813 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
1814 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
1815 'success' => false,
1816 );
1817
1818 wp_send_json( $response );
1819 wp_die();
1820 }
1821
1822 $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
1823 if ( empty( $kit_meta ) ) {
1824 $response = array(
1825 'message' => __( 'Data Not Found', 'wdesignkit' ),
1826 'description' => __( 'No site data found in kit', 'wdesignkit' ),
1827 'success' => false,
1828 );
1829
1830 wp_send_json( $response );
1831 wp_die();
1832 }
1833
1834 $kit_meta['container_width'] = ! empty( $site_data['container_width'] ) ? $site_data['container_width'] : array();
1835 $kit_meta['__globals__'] = ! empty( $site_data['globals'] ) ? $site_data['globals'] : array();
1836 $kit_meta['body_background_color'] = ! empty( $site_data['body_background_color'] ) ? $site_data['body_background_color'] : array();
1837
1838 update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta );
1839
1840 $response = array(
1841 'message' => __( 'Site data Updated', 'wdesignkit' ),
1842 'description' => __( 'Site Globals Updated', 'wdesignkit' ),
1843 'success' => true,
1844 );
1845
1846 } elseif ( 'gutenberg' == $builder ) {
1847 $plus_settings = get_option( 'tpgb_global_options' );
1848
1849 $site_preset = json_decode( $plus_settings, true );
1850 $site_preset['globalContainer'] = $site_data;
1851
1852 update_option( 'tpgb_global_options', json_encode( $site_preset ) );
1853
1854 $response = array(
1855 'message' => __( 'Site data Updated', 'wdesignkit' ),
1856 'description' => __( 'Site Globals Updated', 'wdesignkit' ),
1857 'success' => true,
1858 );
1859
1860 } else {
1861 $response = array(
1862 'message' => __( 'Builder Not Found !', 'wdesignkit' ),
1863 'description' => __( 'Template Builder not Found', 'wdesignkit' ),
1864 'success' => true,
1865 );
1866 }
1867
1868 wp_send_json( $response );
1869 wp_die();
1870 }
1871
1872 /**
1873 *
1874 * Update Elementor Global color and Typography.
1875 *
1876 * @since 1.1.20
1877 */
1878 protected function wdkit_update_global_val() {
1879
1880 $builder = ! empty( $_POST['builder'] ) ? sanitize_text_field( $_POST['builder'] ) : '';
1881
1882 if ( 'elementor' == $builder ) {
1883
1884 $g_color = ! empty( $_POST['g_color'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_color'] ) ), true ) : array();
1885 $g_typo = ! empty( $_POST['g_typography'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_typography'] ) ), true ) : array();
1886
1887 // Get colors from Elementor Site Kit
1888 $kit_id = get_option( 'elementor_active_kit' );
1889 if ( ! $kit_id ) {
1890 $response = array(
1891 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
1892 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
1893 'success' => false,
1894 );
1895
1896 wp_send_json( $response );
1897 wp_die();
1898 }
1899
1900 $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
1901 if ( empty( $kit_meta ) ) {
1902 $response = array(
1903 'message' => __( 'Data Not Found', 'wdesignkit' ),
1904 'description' => __( 'No meta data found in kit', 'wdesignkit' ),
1905 'success' => false,
1906 );
1907
1908 wp_send_json( $response );
1909 wp_die();
1910 }
1911
1912 $kit_meta['custom_colors'] = array_merge( $g_color, $kit_meta['custom_colors'] );
1913 $kit_meta['custom_typography'] = array_merge( $g_typo, $kit_meta['custom_typography'] );
1914
1915 update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta );
1916
1917 $response = array(
1918 'message' => __( 'Global data Updated', 'wdesignkit' ),
1919 'description' => __( 'Global Color and Typography Updated', 'wdesignkit' ),
1920 'success' => true,
1921 );
1922
1923 } elseif ( 'gutenberg' == $builder ) {
1924 $new_preset = ! empty( $_POST['new_preset'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['new_preset'] ) ), true ) : array();
1925 $new_preset_id = ! empty( $new_preset['key'] ) ? $new_preset['key'] : '';
1926 $plus_settings = get_option( 'tpgb_global_options' );
1927 $site_preset = json_decode( $plus_settings, true );
1928
1929 $site_preset['presets'][ $new_preset_id ] = $new_preset;
1930 $site_preset['active'] = $new_preset_id;
1931
1932 update_option( 'tpgb_global_options', json_encode( $site_preset ) );
1933
1934 $response = array(
1935 'message' => __( 'Global data Updated', 'wdesignkit' ),
1936 'description' => __( 'Global Color and Typography Updated', 'wdesignkit' ),
1937 'success' => true,
1938 );
1939
1940 } else {
1941 $response = array(
1942 'message' => __( 'Builder Not Found !', 'wdesignkit' ),
1943 'description' => __( 'Template Builder not Found', 'wdesignkit' ),
1944 'success' => true,
1945 );
1946 }
1947
1948 wp_send_json( $response );
1949 wp_die();
1950 }
1951
1952 /**
1953 *
1954 * Create Gutenberg page and save for re-generate css file.
1955 *
1956 * @since 1.2.3
1957 */
1958 protected function wdkit_update_preset() {
1959
1960 $act_type = ! empty( $_POST['act_type'] ) ? sanitize_text_field( $_POST['act_type'] ) : '';
1961 $post_id = ! empty( $_POST['post_id'] ) ? sanitize_text_field( $_POST['post_id'] ) : '';
1962
1963 if ( 'create' == $act_type ) {
1964
1965 $page_id = wp_insert_post(
1966 array(
1967 'post_title' => 'WDesignKit Gutenberg',
1968 'post_status' => 'publish',
1969 'post_type' => 'post',
1970 'post_name' => sanitize_title( 'wdesignkit' ),
1971 'post_content' => '<!-- wp:heading --><h2 class="wp-block-heading">Add Your Heading Text Here<h2><!-- /wp:heading -->',
1972 'meta_input' => array(
1973 'gutenberg_preview' => true,
1974 '_wp_page_template' => 'default',
1975 ),
1976 )
1977 );
1978
1979 if ( is_wp_error( $page_id ) || ! $page_id ) {
1980 $response = array(
1981 'success' => true,
1982 'message' => esc_html__( 'Page Not Found!', 'wdesignkit' ),
1983 'description' => esc_html__( 'Page Not Found!', 'wdesignkit' ),
1984 );
1985
1986 wp_send_json( $response );
1987 wp_die();
1988 }
1989
1990 update_post_meta( $page_id, '_edit_lock', time() . ':1' );
1991 update_post_meta( $page_id, '_edit_last', get_current_user_id() );
1992
1993 $preview_url = admin_url( 'post.php?post=' . $page_id . '&action=edit' );
1994
1995 $response = array(
1996 'success' => true,
1997 'post_id' => $page_id,
1998 'preview_url' => $preview_url,
1999 'message' => esc_html__( 'Page Created', 'wdesignkit' ),
2000 'description' => esc_html__( 'Page Created', 'wdesignkit' ),
2001 );
2002
2003 wp_send_json( $response );
2004 wp_die();
2005
2006 }
2007
2008 if ( ! empty( $post_id ) && ( $act_type == 'remove' ) ) {
2009
2010 wp_delete_post( $post_id, true );
2011
2012 $response = array(
2013 'success' => true,
2014 'message' => esc_html__( 'post deleted', 'wdesignkit' ),
2015 'description' => esc_html__( 'post deleted', 'wdesignkit' ),
2016 );
2017
2018 wp_send_json( $response );
2019 wp_die();
2020 }
2021 }
2022
2023 /**
2024 *
2025 * It is For Find User Existing template List.
2026 *
2027 * @since 1.0.6
2028 */
2029 protected function wdkit_find_existing_template() {
2030 $array_data = array(
2031 'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '',
2032 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
2033 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
2034 'u_id' => isset( $_POST['u_id'] ) ? sanitize_text_field( wp_unslash( $_POST['u_id'] ) ) : '',
2035 'builder' => isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '',
2036 'parpage' => isset( $_POST['parpage'] ) ? sanitize_text_field( wp_unslash( $_POST['parpage'] ) ) : 12,
2037 );
2038
2039 $response = $this->wkit_api_call( $array_data, 'existing_template' );
2040
2041 wp_send_json( $response );
2042 wp_die();
2043 }
2044
2045 /**
2046 *
2047 * It is For Update User Existing template List.
2048 *
2049 * @since 1.0.6
2050 */
2051 protected function wdkit_update_template() {
2052 $array_data = array(
2053 'data' => isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '',
2054 'post_id' => isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '',
2055 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
2056 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
2057 'id' => isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '',
2058 'global_data' => isset( $_POST['global_data'] ) ? wp_unslash( $_POST['global_data'] ) : array(),
2059 // 'global_font_family' => isset( $_POST['global_font_family'] ) ? wp_unslash( $_POST['global_font_family'] ) : array(),
2060 // 'global_color' => isset( $_POST['global_color'] ) ? wp_unslash( $_POST['global_color'] ) : array(),
2061 );
2062
2063 if ( ! empty( $array_data['post_id'] ) ) {
2064 $custom_fields = array();
2065 $post_id = $array_data['post_id'];
2066
2067 $meta_fields = get_post_custom( $post_id );
2068
2069 foreach ( $meta_fields as $key => $value ) {
2070 if ( str_contains( $key, 'nxt-' ) ) {
2071 $custom_fields[ $key ] = $value;
2072 }
2073 }
2074
2075 if ( ! empty( $custom_fields ) ) {
2076 $data = json_decode( $array_data['data'], true );
2077 $data['custom_meta'] = $custom_fields;
2078 $array_data['data'] = wp_json_encode( $data );
2079 }
2080 }
2081
2082 $array_data['remove'] = 'yes';
2083 $response = $this->wkit_api_call( $array_data, 'existing_template' );
2084 wp_send_json( $response );
2085 wp_die();
2086 }
2087
2088 /**
2089 *
2090 * It is Use for manage favourite template.
2091 *
2092 * @since 1.0.0
2093 */
2094 protected function wdkit_manage_favorite() {
2095 $template_id = isset( $_POST['template_id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['template_id'] ) ) ) : 0;
2096 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
2097
2098 if ( empty( $email ) || empty( $template_id ) ) {
2099 $response = array(
2100 'message' => $this->e_msg_login,
2101 'description' => $this->e_desc_login,
2102 'success' => false,
2103 );
2104
2105 wp_send_json( $response );
2106 wp_die();
2107 }
2108
2109 $args = $this->wdkit_parse_args( $_POST );
2110 $args['token'] = $this->wdkit_login_user_token( $email );
2111
2112 unset( $args['email'] );
2113 $response = WDesignKit_Data_Query::get_data( 'manage_favorite', $args );
2114
2115 wp_send_json( $response );
2116 wp_die();
2117 }
2118
2119 /**
2120 *
2121 * It is Use for Check Plugin Dependency of template.
2122 *
2123 * @since 1.0.0
2124 * @version 1.0.9
2125 */
2126 protected function wdkit_check_plugins_depends() {
2127 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ) ) : array();
2128 $update_plugin = array();
2129 $update_theme = array();
2130
2131 if ( empty( $plugins ) || ! is_array( $plugins ) ) {
2132 $this->wdkit_error_msg( array( 'plugins' => 'No Plugins' ) );
2133 }
2134
2135 $all_plugins = $this->get_plugins();
2136 foreach ( $plugins as $plugin ) {
2137 $pluginslug = ! empty( $plugin->plugin_slug ) ? sanitize_text_field( wp_unslash( $plugin->plugin_slug ) ) : '';
2138 $free_pro = ! empty( $plugin->freepro ) ? sanitize_text_field( wp_unslash( $plugin->freepro ) ) : '0';
2139 $type = ! empty( $plugin->type ) ? sanitize_text_field( wp_unslash( $plugin->type ) ) : 'plugin';
2140
2141 if ( is_null( $pluginslug ) ) {
2142 $plugin->status = 'warning';
2143 $update_plugin[] = $plugin;
2144 $update_theme[] = $plugin;
2145
2146 continue;
2147 }
2148
2149 if ( 'plugin' === $type ) {
2150 if ( ! is_plugin_active( $pluginslug ) ) {
2151 if ( ! isset( $all_plugins[ $pluginslug ] ) ) {
2152 if ( isset( $free_pro ) && '1' === $free_pro ) {
2153 $plugin->status = 'manually';
2154 } else {
2155 $plugin->status = 'unavailable';
2156 }
2157 } else {
2158 $plugin->status = 'inactive';
2159 }
2160
2161 $update_plugin[] = $plugin;
2162 } elseif ( is_plugin_active( $pluginslug ) ) {
2163 $plugin->status = 'active';
2164 $update_plugin[] = $plugin;
2165 }
2166 } elseif ( 'theme' === $type ) {
2167 $theme_array = array_keys( wp_get_themes() );
2168 $theme_slug = get_stylesheet();
2169 $parent_theme_slug = get_template();
2170
2171 if ( $theme_slug === $plugin->original_slug || $parent_theme_slug === $plugin->original_slug ) {
2172
2173 $plugin->status = 'active';
2174 } else {
2175 $theme_name = $plugin->original_slug;
2176 if ( ! in_array( $theme_name, $theme_array ) ) {
2177 if ( isset( $free_pro ) && '1' === $free_pro ) {
2178 $plugin->status = 'manually';
2179 } else {
2180 $plugin->status = 'unavailable';
2181 }
2182 } else {
2183 $plugin->status = 'inactive';
2184 }
2185 }
2186
2187 $update_theme[] = $plugin;
2188 }
2189 }
2190
2191 $response = array(
2192 'plugins' => $update_plugin,
2193 'theme' => $update_theme,
2194 'ele_container' => get_option( 'elementor_experiment-container', false ),
2195 );
2196
2197 $this->wdkit_success_msg( $response );
2198 }
2199
2200 /**
2201 *
2202 * It is Use for Install dependent plugin.
2203 *
2204 * @since 1.0.0
2205 * @version 1.0.9
2206 */
2207 protected function wdkit_install_plugins_depends() {
2208 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ), true ) : array();
2209 $type = ! empty( $plugins['type'] ) ? $plugins['type'] : 'plugin';
2210 $p_id = ! empty( $plugins['p_id'] ) ? $plugins['p_id'] : 'plugin';
2211
2212 $responce = '';
2213 if ( 'plugin' === $type ) {
2214 $responce = Wdkit_Depends_Installer::get_instance()->wdkit_install_plugin( $plugins );
2215 } elseif ( 'theme' === $type ) {
2216 $theme_name = ! empty( $plugins['original_slug'] ) ? $plugins['original_slug'] : '';
2217 if ( ! empty( $theme_name ) ) {
2218
2219 $theme_array = array_keys( wp_get_themes() );
2220 $theme_slug = get_stylesheet();
2221
2222 if ( in_array( $theme_name, $theme_array ) ) {
2223 $activate_result = switch_theme( $theme_name );
2224
2225 if ( ! is_wp_error( $activate_result ) ) {
2226 $responce = array(
2227 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ),
2228 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ),
2229 'slug' => 'nexter',
2230 'p_id' => $p_id,
2231 'status' => 'active',
2232 'success' => true,
2233 );
2234 } else {
2235 $responce = array(
2236 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ),
2237 'description' => $activate_result->get_error_message(),
2238 'status' => 'inactive',
2239 'p_id' => $p_id,
2240 'success' => false,
2241 );
2242 }
2243 } else {
2244 $result = $this->wdkit_install_theme_depends( $theme_name );
2245
2246 $message = ! empty( $result['message'] ) ? $result['message'] : esc_html__( 'Somthing Wrong', 'wdesignkit' );
2247 $description = ! empty( $result['description'] ) ? $result['description'] : esc_html__( 'Error Somthing Wrong', 'wdesignkit' );
2248 $status = ! empty( $result['status'] ) ? $result['status'] : esc_html__( 'inactive', 'wdesignkit' );
2249 $success = ! empty( $result['success'] ) ? $result['success'] : false;
2250
2251 $responce = array(
2252 'message' => $message,
2253 'description' => $description,
2254 'p_id' => $p_id,
2255 'status' => $status,
2256 'success' => $success,
2257 );
2258 }
2259 } else {
2260 $responce = array(
2261 'message' => esc_html__( 'Theme Name not Found', 'wdesignkit' ),
2262 'description' => esc_html__( 'Can Not Found Theme Name you Enterd.', 'wdesignkit' ),
2263 'success' => false,
2264 );
2265 }
2266 }
2267
2268 wp_send_json( $responce );
2269 wp_die();
2270 }
2271
2272 protected function wdkit_install_theme_depends( $name = 'nexter' ) {
2273
2274 if ( ! current_user_can( 'install_themes' ) ) {
2275 $response = $this->tpae_set_response( false, 'Invalid nonce.', 'The security check failed. Please refresh the page and try again.' );
2276 return $response;
2277 }
2278
2279 $theme_slug = $name;
2280 $theme_api_url = 'https://api.wordpress.org/themes/info/1.0/';
2281
2282 // Parameters for the request
2283 $args = array(
2284 'body' => array(
2285 'action' => 'theme_information',
2286 'request' => serialize(
2287 (object) array(
2288 'slug' => $name,
2289 'fields' => array(
2290 'description' => false,
2291 'sections' => false,
2292 'rating' => true,
2293 'ratings' => false,
2294 'downloaded' => true,
2295 'download_link' => true,
2296 'last_updated' => true,
2297 'homepage' => true,
2298 'tags' => true,
2299 'template' => true,
2300 'active_installs' => false,
2301 'parent' => false,
2302 'versions' => false,
2303 'screenshot_url' => true,
2304 'active_installs' => false,
2305 ),
2306 )
2307 ),
2308 ),
2309 );
2310
2311 // Make the request
2312 $response = wp_remote_post( $theme_api_url, $args );
2313 // Check for errors
2314 if ( is_wp_error( $response ) ) {
2315 $error_message = $response->get_error_message();
2316
2317 $result = $this->tpae_set_response( false, 'oops', 'oops', '' );
2318 } else {
2319 $theme_info = unserialize( $response['body'] );
2320 $theme_name = $theme_info->name;
2321 $theme_zip_url = $theme_info->download_link;
2322
2323 global $wp_filesystem;
2324 // Install the theme
2325 $theme = wp_remote_get( $theme_zip_url, array( 'timeout' => 30 ) );
2326
2327 if ( ! function_exists( 'WP_Filesystem' ) ) {
2328 require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' );
2329 }
2330
2331 WP_Filesystem();
2332
2333 $active_theme = wp_get_theme();
2334 $theme_name = $active_theme->get( 'Name' );
2335
2336 $wp_filesystem->put_contents( WP_CONTENT_DIR . '/themes/' . $theme_slug . '.zip', $theme['body'] );
2337 $zip = new ZipArchive();
2338 if ( $zip->open( WP_CONTENT_DIR . '/themes/' . $theme_slug . '.zip' ) === true ) {
2339 $zip->extractTo( WP_CONTENT_DIR . '/themes/' );
2340 $zip->close();
2341 }
2342
2343 $wp_filesystem->delete( WP_CONTENT_DIR . '/themes/' . $theme_slug . '.zip' );
2344
2345 $activate_result = switch_theme( $name );
2346
2347 if ( ! is_wp_error( $activate_result ) ) {
2348 $response = array(
2349 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ),
2350 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ),
2351 'status' => 'active',
2352 'success' => true,
2353 );
2354 } else {
2355 $response = array(
2356 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ),
2357 'description' => $activate_result->get_error_message(),
2358 'status' => 'inactive',
2359 'success' => false,
2360 );
2361 }
2362 }
2363
2364 return $response;
2365 }
2366
2367 /**
2368 *
2369 * It is Use Update WDesignKit plugin latest version.
2370 *
2371 * @since 1.0.17
2372 */
2373 protected function wdkit_update_latest_plugin() {
2374
2375 return Wdkit_Depends_Installer::get_instance()->wdkit_update_plugin();
2376 }
2377
2378 /**
2379 *
2380 * It is Use for get plugin list.
2381 *
2382 * @since 1.0.0
2383 */
2384 private function get_plugins() {
2385 if ( ! function_exists( 'get_plugins' ) ) {
2386 require_once \ABSPATH . 'wp-admin/includes/plugin.php';
2387 }
2388
2389 return get_plugins();
2390 }
2391
2392 /**
2393 * Get Download Template Content
2394 *
2395 * @since 1.0.0
2396 */
2397 protected function wdkit_activate_container() {
2398
2399 $option_value = get_option( 'elementor_experiment-container', false );
2400
2401 if ( $option_value === false ) {
2402 add_option( 'elementor_experiment-container', 'active' );
2403 } else {
2404 update_option( 'elementor_experiment-container', 'active' );
2405 }
2406
2407 $result = array(
2408 'message' => esc_html__( 'Container Activated Successfully', 'wdesignkit' ),
2409 'description' => esc_html__( 'Elementor Container Activated Successfully.', 'wdesignkit' ),
2410 'success' => true,
2411 );
2412
2413 wp_send_json( $response );
2414 wp_die();
2415 }
2416
2417 /**
2418 * import category and tags for post
2419 *
2420 * @since 2.0.0
2421 */
2422 protected function wdkit_import_taxonomy() {
2423 $category = isset( $_POST['category'] ) ? json_decode( wp_unslash( $_POST['category'] ) ) : array();
2424 $tags = isset( $_POST['tags'] ) ? json_decode( wp_unslash( $_POST['tags'] ) ) : array();
2425
2426 $response = array(
2427 'success' => false,
2428 'categories' => array(),
2429 'tags' => array(),
2430 );
2431
2432 if ( ! empty( $category ) && count( $category ) > 0 ) {
2433 foreach ( $category as $category_name ) {
2434 $category_name = sanitize_text_field( $category_name );
2435
2436 $term_exists = term_exists( $category_name, 'category' );
2437 if ( ! $term_exists ) {
2438 $result = wp_insert_term( $category_name, 'category' );
2439 if ( ! is_wp_error( $result ) ) {
2440 $response['categories'][] = array(
2441 'name' => $category_name,
2442 'term_id' => $result['term_id'],
2443 );
2444 } else {
2445 $response['categories'][] = array(
2446 'name' => $category_name,
2447 'error' => $result->get_error_message(),
2448 );
2449 }
2450 } else {
2451 $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
2452 $response['categories'][] = array(
2453 'name' => $category_name,
2454 'term_id' => $term_id,
2455 );
2456 }
2457 }
2458
2459 $response['success'] = true;
2460 }
2461
2462 if ( ! empty( $tags ) && count( $tags ) > 0 ) {
2463 foreach ( $tags as $tags_name ) {
2464 $tags_name = sanitize_text_field( $tags_name );
2465
2466 $term_exists = term_exists( $tags_name, 'post_tag' );
2467 if ( ! $term_exists ) {
2468 $result = wp_insert_term( $tags_name, 'post_tag' );
2469 if ( ! is_wp_error( $result ) ) {
2470 $response['tags'][] = array(
2471 'name' => $tags_name,
2472 'term_id' => $result['term_id'],
2473 );
2474 } else {
2475 $response['tags'][] = array(
2476 'name' => $tags_name,
2477 'error' => $result->get_error_message(),
2478 );
2479 }
2480 } else {
2481 $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
2482 $response['tags'][] = array(
2483 'name' => $tags_name,
2484 'term_id' => $term_id,
2485 );
2486 }
2487 }
2488
2489 $response['success'] = true;
2490 }
2491
2492 wp_send_json( $response );
2493 wp_die();
2494 }
2495
2496 /**
2497 * Get Download Template Content
2498 *
2499 * @since 1.0.0
2500 */
2501 protected function wdkit_import_template() {
2502 $args = $this->wdkit_parse_args( $_POST );
2503 $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
2504
2505 $response = '';
2506 if ( empty( $args['template_id'] ) ) {
2507 $result = array(
2508 'content' => '',
2509 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
2510 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
2511 'success' => false,
2512 );
2513
2514 wp_send_json( $response );
2515 wp_die();
2516 }
2517
2518 $args['token'] = $this->wdkit_login_user_token( $args['email'] );
2519
2520 unset( $args['email'] );
2521 $args['unique_id'] = get_option( 'wdkit_unique_id' ) ?? '';
2522 $response = WDesignKit_Data_Query::get_data( $api_type, $args );
2523 $custom_meta = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
2524
2525 /** Custom meta Field */
2526 if ( ! empty( $custom_meta ) && 'true' === $custom_meta && ! empty( $response ) && ! empty( $response['content'] ) ) {
2527
2528 $res_content = json_decode( $response['content'], true );
2529 if ( isset( $res_content['custom_meta'] ) && ! empty( $res_content['custom_meta'] ) ) {
2530 $meta_data = $res_content['custom_meta'];
2531
2532 if ( ! empty( $meta_data ) ) {
2533 foreach ( $meta_data as $meta_key => $meta_val ) {
2534 if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
2535 $meta_val[0] = maybe_unserialize( $meta_val[0] );
2536 }
2537
2538 if ( get_post_meta( get_the_ID(), $meta_key, true ) === '' ) {
2539 add_post_meta( get_the_ID(), $meta_key, $meta_val[0] );
2540 } else {
2541 update_post_meta( get_the_ID(), $meta_key, $meta_val[0] );
2542 }
2543 }
2544 }
2545 }
2546 }
2547
2548 wp_send_json( $response );
2549 wp_die();
2550 }
2551
2552 /**
2553 * This Function is Use For Media Import
2554 *
2555 * @since 1.0.0
2556 *
2557 * @param array $content store media content.
2558 * @param string $editor it is check editor.
2559 */
2560 public function wdkit_media_import( $content = array(), $editor = '' ) {
2561
2562 if ( empty( $content ) && empty( $editor ) ) {
2563 $args = $this->wdkit_parse_args( $_POST );
2564 $content = ! empty( $args['content'] ) ? json_decode( $args['content'], true ) : array();
2565 } else {
2566 $args = array(
2567 'content' => $content,
2568 'editor' => $editor,
2569 );
2570 $content = ! empty( $args['content'] ) ? $args['content'] : array();
2571
2572 if ( 'elementor' === $args['editor'] ) {
2573 $content = json_decode( $content, true );
2574 }
2575 }
2576
2577 if ( ! class_exists( 'Wdkit_Import_Images' ) ) {
2578 require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php';
2579 }
2580
2581 if ( ! empty( $args['editor'] ) && 'gutenberg' === $args['editor'] && ! empty( $content ) ) {
2582 $media_import = array( $content );
2583 $media_import = self::blocks_import_media_copy_content( $media_import );
2584 $content = $media_import[0];
2585 } elseif ( ! empty( $args['editor'] ) && 'elementor' === $args['editor'] && ! empty( $content ) ) {
2586 $media_import = array( $content );
2587 $media_import = self::widgets_elements_id_change( $media_import );
2588 $media_import = self::widgets_import_media_copy_content( $media_import );
2589 $content = $media_import[0];
2590 }
2591
2592 return $content;
2593 }
2594
2595 /**
2596 * Widgets elements data
2597 *
2598 * @since 1.0.0
2599 * @param string $media_import it is store media data.
2600 */
2601 protected static function widgets_elements_id_change( $media_import ) {
2602 if ( did_action( 'elementor/loaded' ) ) {
2603 return \Elementor\Plugin::instance()->db->iterate_data(
2604 $media_import,
2605 function ( $element ) {
2606 $element['id'] = \Elementor\Utils::generate_random_string();
2607 return $element;
2608 }
2609 );
2610 } else {
2611 return $media_import;
2612 }
2613 }
2614
2615 /**
2616 * Widgets Media import copy content.
2617 *
2618 * @since 1.0.0
2619 *
2620 * @param string $media_import it is store media data.
2621 */
2622 protected static function widgets_import_media_copy_content( $media_import ) {
2623 if ( did_action( 'elementor/loaded' ) ) {
2624
2625 return \Elementor\Plugin::instance()->db->iterate_data(
2626 $media_import,
2627 function ( $element_data ) {
2628 $elements = \Elementor\Plugin::instance()->elements_manager->create_element_instance( $element_data );
2629
2630 if ( ! $elements ) {
2631 return null;
2632 }
2633
2634 return self::widgets_element_import_start( $elements );
2635 }
2636 );
2637 } else {
2638 return $media_import;
2639 }
2640 }
2641
2642 /**
2643 * Start element copy content for media import.
2644 *
2645 * @since 1.0.0
2646 *
2647 * @param string \Elementor\Controls_Stack $element it is store elementor data.
2648 */
2649 protected static function widgets_element_import_start( \Elementor\Controls_Stack $element ) {
2650 $get_element_instance = $element->get_data();
2651 $tp_mi_on_fun = 'on_import';
2652
2653 if ( method_exists( $element, $tp_mi_on_fun ) ) {
2654 $get_element_instance = $element->{$tp_mi_on_fun}( $get_element_instance );
2655 }
2656
2657 foreach ( $element->get_controls() as $get_control ) {
2658 $control_type = \Elementor\Plugin::instance()->controls_manager->get_control( $get_control['type'] );
2659 $control_name = $get_control['name'];
2660
2661 if ( ! $control_type ) {
2662 return $get_element_instance;
2663 }
2664
2665 if ( method_exists( $control_type, $tp_mi_on_fun ) ) {
2666 $get_element_instance['settings'][ $control_name ] = $control_type->{$tp_mi_on_fun}( $element->get_settings( $control_name ), $get_control );
2667 }
2668 }
2669
2670 return $get_element_instance;
2671 }
2672
2673 /**
2674 * Blocks Recursively data
2675 *
2676 * @param string $data_import gutenber data import.
2677 */
2678 public static function blocks_import_media_copy_content( $data_import ) {
2679 if ( ! empty( $data_import ) ) {
2680 foreach ( $data_import[0] as $key => $val ) {
2681 if ( array_key_exists( 'blockName', $val ) && ( empty( $val['blockName'] ) || null === $val['blockName'] || empty( $val['blockName'] ) || ' ' === $val['blockName'] ) ) {
2682 unset( $data_import[0][ $key ] );
2683 }
2684 }
2685 }
2686
2687 return self::blocks_array_recursively_data(
2688 $data_import,
2689 function ( $block_data ) {
2690 $elements = self::blocks_data_instance( $block_data );
2691 return $elements;
2692 }
2693 );
2694 }
2695
2696 /**
2697 * Blocks Recursively data
2698 *
2699 * @param array $data store data.
2700 * @param string $callback store data.
2701 * @param string $args store data.
2702 */
2703 public static function blocks_array_recursively_data( $data, $callback, $args = array() ) {
2704 if ( ( isset( $data['name'] ) && ! empty( $data['name'] ) ) || ( isset( $data['blockName'] ) && ! empty( $data['blockName'] ) ) ) {
2705 if ( ! empty( $data['innerBlocks'] ) ) {
2706 $data['innerBlocks'] = self::blocks_array_recursively_data( $data['innerBlocks'], $callback, $args );
2707 }
2708
2709 return call_user_func( $callback, $data, $args );
2710 }
2711
2712 if ( ! empty( $data ) ) {
2713 $data = (array) $data;
2714 foreach ( $data as $block_key => $block_value ) {
2715 $block_data = self::blocks_array_recursively_data( $data[ $block_key ], $callback, $args );
2716
2717 if ( null === $block_data ) {
2718 continue;
2719 }
2720
2721 $data[ $block_key ] = $block_data;
2722 }
2723 }
2724
2725 return $data;
2726 }
2727
2728 /**
2729 * Check Blocks data media Url
2730 *
2731 * @param array $block_data store data.
2732 * @param array $args store data.
2733 * @param array $block_args store data.
2734 */
2735 public static function blocks_data_instance( array $block_data, array $args = array(), $block_args = null ) {
2736
2737 if ( ( isset( $block_data['name'] ) && isset( $block_data['clientId'] ) && isset( $block_data['attributes'] ) ) || ( isset( $block_data['blockName'] ) && isset( $block_data['attrs'] ) && ! empty( $block_data['attrs'] ) ) ) {
2738 $blocks_attr = isset( $block_data['attributes'] ) ? $block_data['attributes'] : ( isset( $block_data['attrs'] ) ? $block_data['attrs'] : array() );
2739 foreach ( $blocks_attr as $block_key => $block_val ) {
2740 if ( isset( $block_val['url'] ) && isset( $block_val['id'] ) && ! empty( $block_val['url'] ) ) {
2741 $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
2742 $blocks_attr[ $block_key ] = $new_media;
2743 } elseif ( isset( $block_val['url'] ) && ! empty( $block_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $block_val['url'] ) ) {
2744 $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
2745 $blocks_attr[ $block_key ] = $new_media;
2746 } elseif ( is_array( $block_val ) && ! empty( $block_val ) ) {
2747 if ( ! array_key_exists( 'md', $block_val ) && ! array_key_exists( 'openTypography', $block_val ) && ! array_key_exists( 'openBorder', $block_val ) && ! array_key_exists( 'openShadow', $block_val ) && ! array_key_exists( 'openFilter', $block_val ) ) {
2748 foreach ( $block_val as $key => $val ) {
2749 if ( is_array( $val ) && ! empty( $val ) ) {
2750
2751 if ( isset( $val['url'] ) && ( isset( $val['Id'] ) || isset( $val['id'] ) ) && ! empty( $val['url'] ) ) {
2752 $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
2753 $blocks_attr[ $block_key ][ $key ] = $new_media;
2754 } elseif ( isset( $val['url'] ) && ! empty( $val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $val['url'] ) ) {
2755 $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
2756 $blocks_attr[ $block_key ][ $key ] = $new_media;
2757 } else {
2758 foreach ( $val as $sub_key => $sub_val ) {
2759 if ( isset( $sub_val['url'] ) && ( isset( $sub_val['Id'] ) || isset( $sub_val['id'] ) ) && ! empty( $sub_val['url'] ) ) {
2760 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
2761
2762 if ( is_array( $sub_val ) && is_array( $new_media ) ) {
2763 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = array_merge( $sub_val, $new_media );
2764 } else {
2765 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
2766 }
2767 } elseif ( isset( $sub_val['url'] ) && ! empty( $sub_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val['url'] ) ) {
2768 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
2769 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
2770 } elseif ( is_array( $sub_val ) && ! empty( $sub_val ) ) {
2771 foreach ( $sub_val as $sub_key1 => $sub_val1 ) {
2772 if ( isset( $sub_val1['url'] ) && ( isset( $sub_val1['Id'] ) || isset( $sub_val1['id'] ) ) && ! empty( $sub_val1['url'] ) ) {
2773 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
2774
2775 if ( is_array( $sub_val1 ) && is_array( $new_media ) ) {
2776 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = array_merge( $sub_val1, $new_media );
2777 } else {
2778 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media;
2779 }
2780 } elseif ( isset( $sub_val1['url'] ) && ! empty( $sub_val1['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val1['url'] ) ) {
2781 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
2782 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media;
2783 }
2784 }
2785 }
2786 }
2787 }
2788 }
2789 }
2790 }
2791 }
2792 }
2793 if ( isset( $block_data['attributes'] ) ) {
2794 $block_data['attributes'] = $blocks_attr;
2795 } elseif ( isset( $block_data['attrs'] ) ) {
2796 $block_data['attrs'] = $blocks_attr;
2797 }
2798 }
2799
2800 return $block_data;
2801 }
2802
2803 /**
2804 * Kit Template Import Pages/Sections
2805 *
2806 * @since 1.0.0
2807 * */
2808 protected function wdkit_import_kit_template() {
2809
2810 if ( ! current_user_can( 'manage_options' ) ) {
2811 return false;
2812 }
2813
2814 $builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '';
2815
2816 $page_section = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : '';
2817
2818 if ( isset( $page_section ) ) {
2819 $args['page_section'] = ! empty( $page_section ) ? sanitize_text_field( wp_unslash( $page_section ) ) : '';
2820 }
2821
2822 $template_ids = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array();
2823 $email = ! empty( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : '';
2824 $editor = isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : '';
2825 $website_kit = isset( $_POST['website_kit'] ) ? sanitize_text_field( wp_unslash( $_POST['website_kit'] ) ) : '';
2826 $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
2827 $ai_compitible = isset( $_POST['ai_compitible'] ) ? sanitize_text_field( wp_unslash( $_POST['ai_compitible'] ) ) : false;
2828
2829 if ( empty( $template_ids ) ) {
2830 $output = array(
2831 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
2832 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
2833 'success' => false,
2834 );
2835
2836 wp_send_json( $output );
2837 wp_die();
2838 }
2839
2840 /**Not Usefull*/
2841 if ( isset( $_POST['select'] ) ) {
2842 $args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : '';
2843 }
2844
2845 $args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
2846 $args['editor'] = $editor;
2847
2848 $token = $this->wdkit_login_user_token( $email );
2849
2850 $temp_args = array(
2851 'token' => $token,
2852 'template_id' => $template_ids['id'],
2853 'editor' => $editor,
2854 'website_kit' => $website_kit,
2855 'unique_id' => get_option( 'wdkit_unique_id' ) ?? '',
2856 );
2857
2858 $response = WDesignKit_Data_Query::get_data( $api_type, $temp_args );
2859 $output = array();
2860
2861 if ( is_wp_error( $response ) ) {
2862
2863 wp_send_json( $response );
2864 wp_die();
2865 }
2866
2867 if ( isset( $response['content'] ) && 'error' === $response['content'] ) {
2868 wp_send_json( $response );
2869 wp_die();
2870 }
2871
2872 $result = array(
2873 'response' => $response,
2874 'args' => $args,
2875 'id' => $template_ids['id'],
2876 'temp_data' => $template_ids,
2877 );
2878
2879 $output['message'] = $response['message'];
2880 $output['description'] = $response['description'];
2881 $output['data'] = $result;
2882 $output['success'] = $response['success'];
2883
2884 wp_send_json( $output );
2885 wp_die();
2886 }
2887
2888 public function wdkit_enable_template_widgets() {
2889 $widget_list = ! empty( $_POST['widget_list'] ) ? json_decode( wp_unslash( $_POST['widget_list'] ), true ) : array();
2890 $extensions_list = ! empty( $_POST['extensions_list'] ) ? json_decode( wp_unslash( $_POST['extensions_list'] ), true ) : array();
2891
2892 if ( empty( $widget_list ) && empty( $extensions_list ) ) {
2893 $res = array(
2894 'massage' => __( 'Widget array not found', 'wdesignkit' ),
2895 'description' => __( 'Widget array not found', 'wdesignkit' ),
2896 'success' => false,
2897 );
2898 wp_send_json( $res );
2899 wp_die();
2900 }
2901
2902 if ( ! has_filter( 'tpae_enable_selected_widgets' ) ) {
2903 $res = array(
2904 'massage' => __( 'Relevant Plugin not Activated', 'wdesignkit' ),
2905 'description' => __( 'Relevant Plugin not Installed / Activated', 'wdesignkit' ),
2906 'success' => false,
2907 );
2908 wp_send_json( $res );
2909 wp_die();
2910 }
2911
2912 $w_list = array(
2913 'widgets' => $widget_list,
2914 'extensions' => $extensions_list,
2915 );
2916
2917 $result = apply_filters( 'tpae_enable_selected_widgets', $w_list );
2918
2919 if ( ! empty( $result['success'] ) ) {
2920 $res = array(
2921 'massage' => __( 'Enabled widgets successfully', 'wdesignkit' ),
2922 'description' => __( 'Used widgets have been enabled successfully', 'wdesignkit' ),
2923 'success' => true,
2924 );
2925 } else {
2926
2927 $message = isset( $result['message'] ) ? $result['message'] : __( 'Failed to enable widgets', 'wdesignkit' );
2928 $description = isset( $result['description'] ) ? $result['description'] : __( 'Failed to enable widgets', 'wdesignkit' );
2929
2930 $res = array(
2931 'massage' => $message,
2932 'description' => $description,
2933 'success' => false,
2934 );
2935 }
2936
2937 wp_send_json( $res );
2938 wp_die();
2939 }
2940
2941 /**
2942 * Import single template and section from plugin only
2943 * */
2944 protected function wdkit_import_multi_template() {
2945 $args = $this->wdkit_parse_args( $_POST );
2946 $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
2947
2948 if ( ! current_user_can( 'manage_options' ) ) {
2949 return false;
2950 }
2951
2952 if ( empty( $_POST['template_ids'] ) ) {
2953 $output = array(
2954 'data' => array(),
2955 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
2956 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
2957 'success' => false,
2958 );
2959
2960 wp_send_json( $output );
2961 wp_die();
2962 }
2963
2964 if ( isset( $_POST['template_ids'] ) ) {
2965 $args['template_ids'] = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array();
2966 }
2967
2968 if ( isset( $_POST['page_section'] ) ) {
2969 $args['page_section'] = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : '';
2970 }
2971
2972 if ( isset( $_POST['select'] ) ) {
2973 $args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : '';
2974 }
2975
2976 $args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
2977
2978 if ( ! empty( $args['template_ids'] ) && ! empty( $args['page_section'] ) ) {
2979 $output = array();
2980 if ( ! empty( $args['template_ids']['id'] ) ) {
2981 $token = $this->wdkit_login_user_token( $args['email'] );
2982
2983 $temp_args = array(
2984 'token' => $token,
2985 'template_id' => $args['template_ids']['id'],
2986 'editor' => $args['editor'],
2987 'unique_id' => get_option( 'wdkit_unique_id' ) ?? '',
2988 );
2989
2990 $response = WDesignKit_Data_Query::get_data( $api_type, $temp_args );
2991
2992 if ( 'error' === $response['content'] ) {
2993 wp_send_json( $response );
2994 wp_die();
2995 }
2996
2997 $result = array(
2998 'response' => $response,
2999 'args' => $args,
3000 'id' => $args['template_ids'],
3001 'value' => $args['template_ids'],
3002 );
3003
3004 $output['message'] = $response['message'];
3005 $output['description'] = $response['description'];
3006 $output['data'] = $result;
3007 $output['success'] = true;
3008
3009 }
3010
3011 wp_send_json( $output );
3012 wp_die();
3013 }
3014 }
3015
3016 /**
3017 * It is Use for remove selected category from content.
3018 *
3019 * @since 2.0.5
3020 */
3021 public function wdkit_content_remover( &$data ) {
3022
3023 if ( is_array( $data ) ) {
3024
3025 foreach ( $data as $key => &$value ) {
3026 if ( $key === 'post_category' ) {
3027 $data[ $key ] = array();
3028 } else if ($key === 'include_products'){
3029 $data[ $key ] = "";
3030 } else {
3031 $this->wdkit_content_remover( $value );
3032 }
3033 }
3034 } elseif ( is_object( $data ) ) {
3035
3036 foreach ( $data as $key => &$value ) {
3037 if ( $key === 'post_category' ) {
3038 $data->$key = array();
3039 } else if ($key === 'include_products'){
3040 $data->$key = "";
3041 } else {
3042 $this->wdkit_content_remover( $value );
3043 }
3044 }
3045 }
3046
3047 return $data;
3048 }
3049
3050 protected function wkit_update_elementor_template(){
3051
3052 if ( isset( $_POST['data'] ) ) {
3053 $content = ! empty( $_POST['data'] ) ? json_decode( wp_unslash( $_POST['data'] ), true ) : '';
3054 }
3055
3056 if ( isset( $_POST['template_id'] ) ) {
3057 $template_id = ! empty( $_POST['template_id'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_id'] ), true ) ) : '';
3058 }
3059
3060 $document = \Elementor\Plugin::$instance->documents->get($template_id);
3061
3062 $document->save([
3063 'elements' => $content
3064 ]);
3065 }
3066
3067 /**
3068 * Import single template and section from plugin only
3069 *
3070 * @param array $args store data.
3071 * @param array $template_id store data.
3072 * @param array $data store data.
3073 * @param array $temp_data store data.
3074 * */
3075 protected function import_page_section_content() {
3076
3077 if ( isset( $_POST['args'] ) ) {
3078 $args = ! empty( $_POST['args'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['args'] ) ), true ) : array();
3079 }
3080
3081 if ( isset( $_POST['temp_data'] ) ) {
3082 $temp_data = ! empty( $_POST['temp_data'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['temp_data'] ) ), true ) : array();
3083 }
3084
3085 if ( isset( $_POST['category_list'] ) ) {
3086 $category_list = ! empty( $_POST['category_list'] ) ? json_decode( wp_unslash( $_POST['category_list'] ), true ) : '';
3087 }
3088
3089 if ( isset( $_POST['tag_list'] ) ) {
3090 $tag_list = ! empty( $_POST['tag_list'] ) ? json_decode( wp_unslash( $_POST['tag_list'] ), true ) : '';
3091 }
3092
3093 if ( isset( $_POST['thumb_image'] ) ) {
3094 $thumb_image = ! empty( $_POST['thumb_image'] ) ? esc_url_raw( $_POST['thumb_image'] ) : '';
3095 }
3096
3097 if ( isset( $_POST['template_id'] ) ) {
3098 $template_id = ! empty( $_POST['template_id'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_id'] ), true ) ) : '';
3099 }
3100
3101 if ( isset( $_POST['temp_type'] ) ) {
3102 $temp_type = isset( $_POST['temp_type'] ) ? sanitize_text_field( wp_unslash( $_POST['temp_type'] ) ) : 'normal';
3103 }
3104
3105 if ( isset( $_POST['data'] ) ) {
3106 $data = ! empty( $_POST['data'] ) ? json_decode( wp_unslash( $_POST['data'] ) ) : '';
3107 }
3108
3109 $enqueue_instance = new Wdkit_Enqueue();
3110 $get_post_type = $enqueue_instance->wdkit_get_post_type_list();
3111
3112 $post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page';
3113
3114 if ( 'section' === $post_type ) {
3115 $post_type = $temp_data['wp_post_type'];
3116 } else {
3117 $post_type = $temp_data['wp_post_type'];
3118 }
3119
3120 if ( ! array_key_exists( $post_type, $get_post_type ) ) {
3121 $post_type = 'page';
3122 }
3123
3124 if ( ! empty( $data ) && ! empty( $template_id ) && ! empty( $post_type ) && current_user_can( 'manage_options' ) ) {
3125 $post_content = $data;
3126 $post_title = isset( $post_content->title ) ? sanitize_text_field( $post_content->title ) : '';
3127 $post_slug = isset( $post_content->slug ) ? sanitize_text_field( $post_content->slug ) : '';
3128 $file_type = isset( $post_content->file_type ) ? sanitize_text_field( $post_content->file_type ) : '';
3129 $content = isset( $post_content->content ) ? wp_slash( $post_content->content ) : '';
3130 $temp_con = '';
3131
3132 if ( 'gutenberg' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'wp_block' === $file_type ) ) {
3133 if ( empty( $content ) ) {
3134 wp_send_json(
3135 array(
3136 'template_id' => $template_id,
3137 'message' => 'Content is Empty.',
3138 )
3139 );
3140 wp_die();
3141 } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'wp_block' === $file_type ) {
3142
3143 $editor = ( 'wdkit' === $args['editor'] ) ? 'gutenberg' : $args['editor'];
3144 $blocks = parse_blocks( stripslashes( $content ) );
3145
3146 $blocks = $this->wdkit_media_import( $blocks, $editor );
3147
3148 $processor = new WDKIT_Nexter_Block_Processor();
3149 $blocks = $processor->run( $blocks );
3150 $content = serialize_blocks( $blocks );
3151
3152 $content = $this->replace_unicode_glitch( serialize_blocks( $blocks ) );
3153
3154 if ( ! empty( $category_list ) && is_array( $category_list ) ) {
3155 $category_ids = array_map( 'intval', $category_list );
3156 wp_set_post_terms( $inserted_id, $category_ids, 'category' );
3157 }
3158
3159 if ( ! empty( $tag_list ) && is_array( $tag_list ) ) {
3160 $tag_ids = array_map( 'intval', $tag_list );
3161 wp_set_post_terms( $inserted_id, $tag_ids, 'post_tag' );
3162 }
3163
3164 $inserted_post = wp_insert_post(
3165 array(
3166 'post_status' => 'publish',
3167 'post_type' => $post_type,
3168 'post_title' => $post_title,
3169 'post_name' => $post_slug,
3170 'post_content' => $content,
3171 )
3172 );
3173
3174 if ( is_wp_error( $inserted_post ) ) {
3175 wp_send_json(
3176 array(
3177 'import_failed' => $inserted_post->get_error_message(),
3178 'code' => $inserted_post->get_error_code(),
3179 )
3180 );
3181 wp_die();
3182 }
3183
3184 if ( ! empty( $thumb_image ) ) {
3185 // $featured_image_url = esc_url_raw( $thumb_image );
3186 $tmp = download_url( $thumb_image );
3187 if ( is_wp_error( $tmp ) ) {
3188 error_log( 'Image download failed: ' . esc_html( $tmp->get_error_message() ) );
3189 } else {
3190 $file_array = array(
3191 'name' => wp_basename( $thumb_image ),
3192 'tmp_name' => $tmp,
3193 );
3194
3195 $image_id = media_handle_sideload( $file_array, $inserted_post );
3196
3197 if ( is_wp_error( $image_id ) ) {
3198 error_log( 'Image sideload failed: ' . esc_html( $image_id->get_error_message() ) );
3199 } else {
3200 set_post_thumbnail( $inserted_post, $image_id );
3201 }
3202
3203 @unlink( $tmp );
3204 }
3205 }
3206
3207 if ( ! empty( $category_list ) && is_array( $category_list ) ) {
3208 $category_ids = array_map( 'intval', $category_list );
3209 wp_set_post_terms( $inserted_post, $category_ids, 'category' );
3210 }
3211
3212 if ( ! empty( $tag_list ) && is_array( $tag_list ) ) {
3213 $tag_ids = array_map( 'intval', $tag_list );
3214 wp_set_post_terms( $inserted_post, $tag_ids, 'post_tag' );
3215 }
3216
3217 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
3218 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
3219 if ( ! empty( $custom_meta ) ) {
3220 foreach ( $custom_meta as $meta_key => $meta_val ) {
3221 if ( isset( $meta_val[0] ) && ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
3222 $meta_val[0] = maybe_unserialize( $meta_val[0] );
3223 }
3224
3225 if ( '' === get_post_meta( $inserted_post, $meta_key, true ) && isset( $meta_val[0] ) ) {
3226 add_post_meta( $inserted_post, $meta_key, $meta_val[0] );
3227 }
3228 }
3229 }
3230 }
3231
3232 $temp_detail = array(
3233 'title' => get_the_title( $inserted_post ),
3234 'edit_link' => get_edit_post_link( $inserted_post, 'internal' ),
3235 'view' => get_permalink( $inserted_post ),
3236 'id' => $inserted_post,
3237 );
3238
3239 if ( ! empty( $template_id->id ) ) {
3240 $temp_id = $template_id->id;
3241 } elseif ( ! empty( $template_id ) ) {
3242 $temp_id = $template_id;
3243 } else {
3244 $temp_id = '';
3245 }
3246
3247 wp_update_post([
3248 'ID' => $inserted_post,
3249 ]);
3250
3251 if (class_exists('Tpgb_Library') && method_exists('Tpgb_Library', 'remove_backend_dir_files')) {
3252 Tpgb_Library()->remove_backend_dir_files();
3253 }
3254
3255 clean_post_cache( $inserted_post );
3256 wp_send_json(
3257 array(
3258 $temp_id => $temp_detail,
3259 'description' => 'Yay! Your Section has been Successfully Imported.',
3260 'message' => 'Successfully Imported.',
3261 'inserted_id' => $inserted_post,
3262 'success' => true,
3263 )
3264 );
3265 wp_die();
3266 }
3267 } elseif ( 'elementor' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'elementor' === $file_type ) ) {
3268 if ( did_action( 'elementor/loaded' ) ) {
3269 if ( empty( $content ) ) {
3270 wp_send_json(
3271 array(
3272 'template_id' => $template_id,
3273 'message' => 'Content is Empty.',
3274 )
3275 );
3276 wp_die();
3277 } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'elementor' === $file_type ) {
3278
3279 $content = $this->wdkit_content_remover( $content );
3280
3281 $post_attributes = array(
3282 'post_title' => $post_title,
3283 'post_type' => $post_type,
3284 'post_status' => 'publish',
3285 'post_name' => $post_slug,
3286 );
3287
3288 if ( 'elementor_library' === $post_type ) {
3289 $el_type = ( isset( $post_content->el_type ) && ! empty( $post_content->el_type ) ) ? sanitize_text_field( $post_content->el_type ) : 'page';
3290 $new_document = \Elementor\Plugin::$instance->documents->create(
3291 $el_type,
3292 $post_attributes
3293 );
3294 } else {
3295 $new_document = \Elementor\Plugin::$instance->documents->create(
3296 $post_attributes['post_type'],
3297 $post_attributes
3298 );
3299 }
3300
3301 if ( is_wp_error( $new_document ) ) {
3302 wp_send_json(
3303 array(
3304 'import_failed' => $new_document->get_error_message(),
3305 'code' => $new_document->get_error_code(),
3306 )
3307 );
3308 wp_die();
3309 }
3310
3311 $inserted_id = $new_document->get_main_id();
3312
3313 if ( ! empty( $thumb_image ) ) {
3314 // $featured_image_url = esc_url_raw( $thumb_image );
3315 $tmp = download_url( $thumb_image );
3316 if ( is_wp_error( $tmp ) ) {
3317 error_log( 'Image download failed: ' . esc_html( $tmp->get_error_message() ) );
3318 } else {
3319 $file_array = array(
3320 'name' => wp_basename( $thumb_image ),
3321 'tmp_name' => $tmp,
3322 );
3323
3324 $image_id = media_handle_sideload( $file_array, $inserted_id );
3325
3326 if ( is_wp_error( $image_id ) ) {
3327 error_log( 'Image sideload failed: ' . esc_html( $image_id->get_error_message() ) );
3328 } else {
3329 set_post_thumbnail( $inserted_id, $image_id );
3330 }
3331
3332 @unlink( $tmp );
3333 }
3334 }
3335
3336 if ( ! empty( $category_list ) && is_array( $category_list ) ) {
3337 $category_ids = array_map( 'intval', $category_list );
3338 wp_set_post_terms( $inserted_id, $category_ids, 'category' );
3339 }
3340
3341 if ( ! empty( $tag_list ) && is_array( $tag_list ) ) {
3342 $tag_ids = array_map( 'intval', $tag_list );
3343 wp_set_post_terms( $inserted_id, $tag_ids, 'post_tag' );
3344 }
3345
3346 $settings = ( isset( $post_content->settings ) && ! empty( $post_content->settings ) ) ? json_decode( wp_json_encode( $post_content->settings ), true ) : array();
3347
3348 $content = wp_json_encode( $content );
3349 $content = $this->wdkit_media_import( $content, $file_type );
3350
3351 $new_document->save(
3352 array(
3353 'elements' => $content,
3354 'settings' => ! empty( $settings ) ? $settings : array(),
3355 )
3356 );
3357
3358 $inserted_id = $new_document->get_main_id();
3359
3360 if( $temp_type == 'navigation' ){
3361 $temp_con = $content;
3362 }
3363
3364 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
3365 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
3366 if ( ! empty( $custom_meta ) ) {
3367 foreach ( $custom_meta as $meta_key => $meta_val ) {
3368 if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
3369 $meta_val[0] = maybe_unserialize( $meta_val[0] );
3370 }
3371 if ( '' === get_post_meta( $inserted_id, $meta_key, true ) ) {
3372 add_post_meta( $inserted_id, $meta_key, $meta_val[0] );
3373 }
3374 }
3375 }
3376 }
3377
3378 $temp_detail = array(
3379 'title' => get_the_title( $inserted_id ),
3380 'edit_link' => get_edit_post_link( $inserted_id, 'internal' ),
3381 'view' => get_permalink( $inserted_id ),
3382 'id' => $inserted_id,
3383 );
3384
3385 if ( ! empty( $template_id->id ) ) {
3386 $temp_id = $template_id->id;
3387 } elseif ( ! empty( $template_id ) ) {
3388 $temp_id = $template_id;
3389 } else {
3390 $temp_id = '';
3391 }
3392
3393 \Elementor\Plugin::$instance->files_manager->clear_cache();
3394
3395 wp_send_json(
3396 array(
3397 $temp_id => $temp_detail,
3398 'content' => $temp_con,
3399 'description' => 'Yay! Your Section has been Successfully Imported.',
3400 'message' => 'Successfully Imported.',
3401 'inserted_id' => $inserted_id,
3402 'success' => true,
3403 )
3404 );
3405 wp_die();
3406 }
3407 } else {
3408 wp_send_json(
3409 array(
3410 'template_id' => $template_id,
3411 'message' => esc_html__( 'Relevant Page Builder not installed or activated', 'wdesignkit' ),
3412 )
3413 );
3414 wp_die();
3415 }
3416 }
3417 }
3418
3419 wp_send_json(
3420 array(
3421 'success' => false,
3422 'message' => esc_html__( 'Something went wrong', 'wdesignkit' ),
3423 )
3424 );
3425 wp_die();
3426 }
3427
3428 /**
3429 * Replace unicode glitch
3430 *
3431 * @since 2.0.0
3432 */
3433 private function replace_unicode_glitch( $content ) {
3434
3435 // Fix escaped unicode like \u003c → <
3436 $content = preg_replace_callback(
3437 '/\\\\u([0-9a-fA-F]{4})/',
3438 function ( $match ) {
3439 return html_entity_decode(
3440 mb_convert_encoding(
3441 pack('H*', $match[1]),
3442 'UTF-8',
3443 'UCS-2BE'
3444 ),
3445 ENT_QUOTES,
3446 'UTF-8'
3447 );
3448 },
3449 $content
3450 );
3451
3452 return $content;
3453 }
3454
3455
3456 /**
3457 * change plugins setting for import kit
3458 *
3459 * @since 2.0.0
3460 */
3461 protected function update_plugin_setting() {
3462 $temp_id = isset( $_POST['plugin_type'] ) ? sanitize_text_field( $_POST['plugin_type'] ) : '';
3463
3464 if ( $temp_id == 'elementor' ) {
3465 $unfiltered_files = get_option( 'elementor_unfiltered_files_upload', false );
3466 $load_fa4 = get_option( 'elementor_load_fa4_shim', false );
3467 $Inline_font_icons = get_option( 'elementor_experiment-e_font_icon_svg', false );
3468 $container = get_option( 'elementor_experiment-container', false );
3469
3470 if ( isset( $unfiltered_files ) ) {
3471 update_option( 'elementor_unfiltered_files_upload', 1 );
3472 } else {
3473 add_option( 'elementor_unfiltered_files_upload', 1 );
3474 }
3475
3476 if ( isset( $load_fa4 ) ) {
3477 update_option( 'elementor_load_fa4_shim', 'yes' );
3478 } else {
3479 add_option( 'elementor_load_fa4_shim', 'yes' );
3480 }
3481
3482 if ( isset( $container ) ) {
3483 update_option( 'elementor_experiment-container', 'active' );
3484 } else {
3485 add_option( 'elementor_experiment-container', 'active' );
3486 }
3487
3488 if ( isset( $Inline_font_icons ) ) {
3489 update_option( 'elementor_experiment-e_font_icon_svg', 'inactive' );
3490 } else {
3491 add_option( 'elementor_experiment-e_font_icon_svg', 'inactive' );
3492 }
3493
3494 $response = array(
3495 'message' => esc_html__( 'Plugin Setting updated', 'wdesignkit' ),
3496 'description' => esc_html__( 'Plugin Setting updated', 'wdesignkit' ),
3497 'success' => true,
3498 );
3499 } else {
3500 $response = array(
3501 'message' => esc_html__( 'Plugin not found', 'wdesignkit' ),
3502 'description' => esc_html__( 'Plugin not found', 'wdesignkit' ),
3503 'success' => false,
3504 );
3505 }
3506
3507 wp_send_json( $response );
3508 wp_die();
3509 }
3510
3511 /**
3512 * generate different color logo
3513 *
3514 * @since 2.0.0
3515 */
3516 protected function wkit_generate_site_logo() {
3517
3518 if ( empty( $_POST['image_url'] ) ) {
3519 wp_send_json_error( 'Image URL not provided.' );
3520 }
3521
3522 if ( isset( $_POST['colors'] ) ) {
3523 $img_colors = ! empty( $_POST['colors'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['colors'] ) ), true ) : array();
3524 }
3525
3526 if ( empty( $img_colors ) ) {
3527 wp_send_json_error( 'Image color not provided.' );
3528 }
3529
3530 $image_url = esc_url_raw( $_POST['image_url'] );
3531
3532 $tmp_file = download_url( $image_url );
3533 if ( is_wp_error( $tmp_file ) ) {
3534 wp_send_json_error( 'Image could not be downloaded.' );
3535 }
3536
3537 if ( mime_content_type( $tmp_file ) !== 'image/png' ) {
3538 unlink( $tmp_file );
3539 wp_send_json_error( 'Not a PNG file.' );
3540 }
3541
3542 $src = imagecreatefrompng( $tmp_file );
3543 imagesavealpha( $src, true );
3544
3545 $width = imagesx( $src );
3546 $height = imagesy( $src );
3547
3548 $hasTransparency = false;
3549 for ( $x = 0; $x < $width; $x++ ) {
3550 for ( $y = 0; $y < $height; $y++ ) {
3551 $rgba = imagecolorat( $src, $x, $y );
3552 $alpha = ( $rgba & 0x7F000000 ) >> 24;
3553
3554 if ( $alpha > 0 ) {
3555 $hasTransparency = true;
3556 break 2;
3557 }
3558 }
3559 }
3560
3561 if ( ! $hasTransparency ) {
3562 unlink( $tmp_file );
3563 wp_send_json_error( 'PNG has no transparent pixels.' );
3564 }
3565
3566 $upload_dir = wp_upload_dir();
3567 $result_urls = array();
3568
3569 foreach ( $img_colors as $name => $rgb ) {
3570 $new = imagecreatetruecolor( $width, $height );
3571 imagesavealpha( $new, true );
3572 imagealphablending( $new, false );
3573
3574 $transparent = imagecolorallocatealpha( $new, 0, 0, 0, 127 );
3575 imagefill( $new, 0, 0, $transparent );
3576
3577 for ( $x = 0; $x < $width; $x++ ) {
3578 for ( $y = 0; $y < $height; $y++ ) {
3579 $rgba = imagecolorat( $src, $x, $y );
3580 $alpha = ( $rgba & 0x7F000000 ) >> 24;
3581
3582 // Skip fully transparent pixels
3583 if ( $alpha === 127 ) {
3584 continue;
3585 }
3586
3587 // Replace pixel color directly
3588 $new_r = $rgb[0];
3589 $new_g = $rgb[1];
3590 $new_b = $rgb[2];
3591
3592 $color = imagecolorallocatealpha( $new, $new_r, $new_g, $new_b, $alpha );
3593 imagesetpixel( $new, $x, $y, $color );
3594 }
3595 }
3596
3597 $filename = 'colored-' . $name . '-' . time() . '.png';
3598 $filepath = $upload_dir['path'] . '/' . $filename;
3599
3600 imagepng( $new, $filepath );
3601 imagedestroy( $new );
3602
3603 $attachment = array(
3604 'post_mime_type' => 'image/png',
3605 'post_title' => sanitize_file_name( $filename ),
3606 'post_content' => '',
3607 'post_status' => 'inherit',
3608 );
3609
3610 $attach_id = wp_insert_attachment( $attachment, $filepath );
3611 require_once ABSPATH . 'wp-admin/includes/image.php';
3612 $attach_data = wp_generate_attachment_metadata( $attach_id, $filepath );
3613 wp_update_attachment_metadata( $attach_id, $attach_data );
3614
3615 $result_urls[ $name ] = wp_get_attachment_url( $attach_id );
3616 }
3617
3618 imagedestroy( $src );
3619 unlink( $tmp_file );
3620
3621 wp_send_json_success( $result_urls );
3622 }
3623
3624 /**
3625 * change theme setting for import kit
3626 *
3627 * @since 2.0.0
3628 */
3629 protected function update_theme_setting() {
3630 $theme_db = get_option( 'nxt-theme-options', false );
3631
3632 $container_type = 'container-fluid';
3633 $fluid_spacing = array(
3634 'md' => array(
3635 'left' => '0',
3636 'right' => '0',
3637 ),
3638 'sm' => array(
3639 'left' => '',
3640 'right' => '',
3641 ),
3642 'xs' => array(
3643 'left' => '',
3644 'right' => '',
3645 ),
3646 'md-unit' => 'px',
3647 'sm-unit' => 'px',
3648 'xs-unit' => 'px',
3649 );
3650
3651 if ( isset( $theme_db ) ) {
3652 $nexter_setting = $theme_db;
3653 $nexter_setting['site-header-container'] = $container_type;
3654 $nexter_setting['site-footer-container'] = $container_type;
3655 $nexter_setting['site-layout-container'] = $container_type;
3656 $nexter_setting['site-page-container'] = $container_type;
3657
3658 $nexter_setting['header-fluid-spacing'] = $fluid_spacing;
3659 $nexter_setting['footer-fluid-spacing'] = $fluid_spacing;
3660 $nexter_setting['site-fluid-spacing'] = $fluid_spacing;
3661 $nexter_setting['page-fluid-spacing'] = $fluid_spacing;
3662
3663 update_option( 'nxt-theme-options', $nexter_setting );
3664 } else {
3665 $nexter_setting = array(
3666 'site-header-container' => 'container-fluid',
3667 'header-fluid-spacing' => array(
3668 'md' => array(
3669 'left' => '0',
3670 'right' => '0',
3671 ),
3672 'sm' => array(
3673 'left' => '',
3674 'right' => '',
3675 ),
3676 'xs' => array(
3677 'left' => '',
3678 'right' => '',
3679 ),
3680 'md-unit' => 'px',
3681 'sm-unit' => 'px',
3682 'xs-unit' => 'px',
3683 ),
3684 'site-footer-container' => 'container-fluid',
3685 'footer-fluid-spacing' => array(
3686 'md' => array(
3687 'left' => '0',
3688 'right' => '0',
3689 ),
3690 'sm' => array(
3691 'left' => '',
3692 'right' => '',
3693 ),
3694 'xs' => array(
3695 'left' => '',
3696 'right' => '',
3697 ),
3698 'md-unit' => 'px',
3699 'sm-unit' => 'px',
3700 'xs-unit' => 'px',
3701 ),
3702 'site-layout-container' => 'container-fluid',
3703 'site-fluid-spacing' => array(
3704 'md' => array(
3705 'left' => '0',
3706 'right' => '0',
3707 ),
3708 'sm' => array(
3709 'left' => '',
3710 'right' => '',
3711 ),
3712 'xs' => array(
3713 'left' => '',
3714 'right' => '',
3715 ),
3716 'md-unit' => 'px',
3717 'sm-unit' => 'px',
3718 'xs-unit' => 'px',
3719 ),
3720 'site-page-container' => 'container-fluid',
3721 'page-fluid-spacing' => array(
3722 'md' => array(
3723 'left' => '0',
3724 'right' => '0',
3725 ),
3726 'sm' => array(
3727 'left' => '',
3728 'right' => '',
3729 ),
3730 'xs' => array(
3731 'left' => '',
3732 'right' => '',
3733 ),
3734 'md-unit' => 'px',
3735 'sm-unit' => 'px',
3736 'xs-unit' => 'px',
3737 ),
3738 'site-page-container' => '',
3739 'site-posts-container' => '',
3740 'site-archive-container' => '',
3741 );
3742
3743 add_option( 'nxt-theme-options', $nexter_setting );
3744 }
3745
3746 $response = array(
3747 'message' => esc_html__( 'Theme Setting updated', 'wdesignkit' ),
3748 'description' => esc_html__( 'Theme Setting updated', 'wdesignkit' ),
3749 'success' => true,
3750 );
3751
3752 wp_send_json( $response );
3753 wp_die();
3754 }
3755
3756 /**
3757 * change site setting for import kit
3758 *
3759 * @since 2.0.0
3760 */
3761 protected function update_site_setting() {
3762 $temp_id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
3763 $shop_id = isset( $_POST['shop_id'] ) ? sanitize_text_field( wp_unslash( $_POST['shop_id'] ) ) : '';
3764 $temp_type = isset( $_POST['temp_type'] ) ? sanitize_text_field( wp_unslash( $_POST['temp_type'] ) ) : 'page';
3765 $site_name = isset( $_POST['site_name'] ) ? sanitize_text_field( wp_unslash( $_POST['site_name'] ) ) : '';
3766 $site_tagline = isset( $_POST['site_tagline'] ) ? sanitize_text_field( wp_unslash( $_POST['site_tagline'] ) ) : '';
3767
3768 $this->wdkit_nxt_thembuilder_update();
3769
3770 if ( ! empty( $shop_id ) ) {
3771 update_option( 'woocommerce_shop_page_id', $shop_id );
3772 }
3773
3774 if ( $temp_id ) {
3775 update_option( 'show_on_front', $temp_type );
3776 update_option( 'page_on_front', $temp_id );
3777
3778 if ( ! empty( $site_name ) ) {
3779 update_option( 'blogname', $site_name );
3780 }
3781
3782 if ( ! empty( $site_tagline ) ) {
3783 update_option( 'blogdescription', $site_tagline );
3784 }
3785
3786 $response = array(
3787 'message' => esc_html__( 'Site link updated', 'wdesignkit' ),
3788 'description' => esc_html__( 'Site link updated', 'wdesignkit' ),
3789 'site_link' => get_site_url(),
3790 'success' => true,
3791 );
3792 } else {
3793 $response = array(
3794 'message' => esc_html__( 'Site not found', 'wdesignkit' ),
3795 'description' => esc_html__( 'Site not found', 'wdesignkit' ),
3796 'success' => false,
3797 );
3798 }
3799
3800 wp_send_json( $response );
3801 wp_die();
3802 }
3803
3804 /**
3805 * update theme builder
3806 *
3807 * @since 2.0.4
3808 */
3809 public function wdkit_nxt_thembuilder_update() {
3810
3811 $page_information = isset( $_POST['page_information'] ) ? sanitize_text_field( wp_unslash( $_POST['page_information'] ) ) : '';
3812 $page_information = json_decode( $page_information, true );
3813
3814 if ( ! empty( $page_information ) && is_array( $page_information ) ) {
3815 // Step 1: banavo mapping [ old_id => new_id ]
3816 $id_mapping = array();
3817 foreach ( $page_information as $page_info ) {
3818 if ( ! empty( $page_info['old_page_id'] ) ) {
3819 $id_mapping[ $page_info['old_page_id'] ] = $page_info['inserted_id'];
3820 }
3821 }
3822
3823 // Step 2: loop karo and update exclude
3824 foreach ( $page_information as $page_info ) {
3825
3826 $post_id = $page_info['inserted_id'] ?? '';
3827 $old_post_id = $page_info['old_page_id'] ?? '';
3828 $post_type = $page_info['post_type'] ?? '';
3829
3830 if ( empty( $old_post_id ) ) {
3831 continue; // only update where old id exists
3832 }
3833
3834 if ( $post_type != 'nxt_builder' ) {
3835 continue;
3836 }
3837
3838 $include_specific = get_post_meta( $post_id, 'nxt-hooks-layout-specific', true );
3839 if ( ! empty( $include_specific ) && is_array( $include_specific ) ) {
3840
3841 foreach ( $include_specific as $key => $val ) {
3842
3843 // check karo ke koi old_id ka post match kare che ke nahi
3844 foreach ( $id_mapping as $old_id => $new_id ) {
3845 $search = 'post-' . $old_id;
3846 $replace = 'post-' . $new_id;
3847
3848 if ( $val === $search ) {
3849 $include_specific[ $key ] = $replace;
3850 }
3851 }
3852 }
3853
3854 // save back updated array
3855 update_post_meta( $post_id, 'nxt-hooks-layout-specific', $include_specific );
3856 }
3857
3858 // Get exclude meta
3859 $exclude_specific = get_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific', true );
3860 if ( ! empty( $exclude_specific ) && is_array( $exclude_specific ) ) {
3861
3862 foreach ( $exclude_specific as $key => $val ) {
3863
3864 // check karo ke koi old_id ka post match kare che ke nahi
3865 foreach ( $id_mapping as $old_id => $new_id ) {
3866 $search = 'post-' . $old_id;
3867 $replace = 'post-' . $new_id;
3868
3869 if ( $val === $search ) {
3870 $exclude_specific[ $key ] = $replace;
3871 }
3872 }
3873 }
3874
3875 // save back updated array
3876 update_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific', $exclude_specific );
3877 }
3878 }
3879 }
3880 }
3881
3882 /**
3883 *
3884 * select team image for import kit
3885 *
3886 * @since 2.2.2
3887 */
3888 public function wdkit_check_user_credit() {
3889 $array_data = array(
3890 'token' => isset( $_POST['token'] ) ? sanitize_text_field( $_POST['token'] ) : '',
3891 );
3892
3893 $response = $this->wkit_api_call( $array_data, 'ai/credits/get' );
3894 $success = ! empty( $response['success'] ) ? $response['success'] : false;
3895
3896 if ( empty( $success ) ) {
3897 $response = array(
3898 'success' => false,
3899 'message' => esc_html__( 'Data Not Found', 'wdesignkit' ),
3900 'description' => esc_html__( 'Data not found', 'wdesignkit' ),
3901 );
3902
3903 wp_send_json( $response );
3904 wp_die();
3905 }
3906
3907 $response = json_decode( wp_json_encode( $response['data'] ), true );
3908
3909 wp_send_json( $response );
3910 wp_die();
3911 }
3912
3913 public function wdkit_nxt_thembuilder_reset() {
3914 $post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( $_POST['post_id'] ) : '';
3915 $sections_layout = get_post_meta( $post_id, 'nxt-hooks-layout-sections', true );
3916
3917 if ( ( ! empty( $sections_layout ) && ( $sections_layout == 'header' || $sections_layout == 'footer' || $sections_layout == 'breadcrumb' || $sections_layout == 'hooks' ) ) ) {
3918 if ( get_post_meta( $post_id, 'nxt-add-display-rule' ) ) {
3919 delete_post_meta( $post_id, 'nxt-add-display-rule' );
3920 }
3921
3922 if ( get_post_meta( $post_id, 'nxt-hooks-layout-specific' ) ) {
3923 update_post_meta( $post_id, 'nxt-hooks-layout-specific', '' );
3924 }
3925
3926 if ( get_post_meta( $post_id, 'nxt-exclude-display-rule' ) ) {
3927 update_post_meta( $post_id, 'nxt-exclude-display-rule', '' );
3928 }
3929
3930 if ( get_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific' ) ) {
3931 update_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific', '' );
3932 }
3933 }
3934 }
3935
3936
3937 /**
3938 * Share with Me Template and widgets
3939 *
3940 * @since 1.0.0
3941 */
3942 protected function wdkit_shared_with_me() {
3943 $data = isset( $_POST['api_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['api_info'] ) ) ) ) : '';
3944
3945 $array_data = array(
3946 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
3947 'type' => isset( $data->type ) ? sanitize_text_field( wp_unslash( $data->type ) ) : '',
3948 'ParPage' => isset( $data->par_page ) ? (int) $data->par_page : 12,
3949 'CurrentPage' => isset( $data->current_page ) ? (int) $data->current_page : 1,
3950 'builder' => isset( $data->builder ) ? sanitize_text_field( wp_unslash( $data->builder ) ) : '',
3951 );
3952
3953 $response = $this->wkit_api_call( $array_data, 'shared_with_me' );
3954 $success = ! empty( $response['success'] ) ? $response['success'] : false;
3955
3956 wp_send_json( $response );
3957 wp_die();
3958 }
3959
3960 /**
3961 * Add new WorkSpace
3962 *
3963 * @since 1.0.0
3964 */
3965 protected function wdkit_manage_workspace() {
3966 $args = $this->wdkit_parse_args( $_POST );
3967
3968 $user_email = ! empty( $args['email'] ) ? strtolower( sanitize_email( $args['email'] ) ) : '';
3969 $current_wid = ! empty( $_POST['current_wid'] ) ? strtolower( sanitize_text_field( $_POST['current_wid'] ) ) : '';
3970
3971 $args['current_wid'] = $current_wid;
3972
3973 if ( empty( $user_email ) ) {
3974 $response = array(
3975 'message' => $this->e_msg_login,
3976 'description' => $this->e_desc_login,
3977 'success' => false,
3978 );
3979
3980 wp_send_json( $response );
3981 wp_die();
3982 }
3983
3984 $args['token'] = $this->wdkit_login_user_token( $user_email );
3985 unset( $user_email );
3986
3987 $response = WDesignKit_Data_Query::get_data( 'manage_workspace', $args );
3988
3989 return $response;
3990 }
3991
3992 /**
3993 *
3994 * It is Use for manage workspace
3995 *
3996 * @since 1.0.0
3997 */
3998 protected function wdkit_manage_widget_workspace() {
3999 $workspace_info = isset( $_POST['workspace_info'] ) ? sanitize_text_field( wp_unslash( $_POST['workspace_info'] ) ) : array();
4000 $data = isset( $workspace_info ) ? json_decode( stripslashes( $workspace_info ) ) : array();
4001
4002 $array_data = array(
4003 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
4004 'wstype' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
4005 'widget_id' => isset( $data->widget_id ) ? (int) $data->widget_id : '',
4006 'wid' => isset( $data->wid ) ? (int) $data->wid : '',
4007 'current_wid' => isset( $data->current_wid ) ? (int) $data->current_wid : '',
4008 );
4009
4010 $response = $this->wkit_api_call( $array_data, 'manage_workspace' );
4011
4012 wp_send_json( $response['data'] );
4013 wp_die();
4014 }
4015
4016 /**
4017 *
4018 * It is Use for manage api key page
4019 *
4020 * @since 1.0.0
4021 */
4022 protected function wdkit_activate_key() {
4023 $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '';
4024 $response = '';
4025
4026 if ( empty( $user_email ) ) {
4027 $response = array(
4028 'message' => $this->e_msg_login,
4029 'description' => $this->e_desc_login,
4030 'success' => false,
4031 );
4032
4033 wp_send_json( $response );
4034 wp_die();
4035 }
4036
4037 $token = $this->wdkit_login_user_token( $email );
4038 $apikey = isset( $_POST['apikey'] ) ? sanitize_key( wp_unslash( $_POST['apikey'] ) ) : '';
4039 $product = isset( $_POST['product'] ) ? sanitize_text_field( wp_unslash( $_POST['product'] ) ) : '';
4040 $product_action = isset( $_POST['product_action'] ) ? sanitize_text_field( wp_unslash( $_POST['product_action'] ) ) : 'activate';
4041 if ( ! empty( $token ) && ! empty( $product ) && ! empty( $product_action ) ) {
4042 $args = array(
4043 'token' => $token,
4044 'product' => $product,
4045 'product_action' => $product_action,
4046 );
4047
4048 if ( 'activate' === $product_action ) {
4049 $args['apikey'] = $apikey;
4050 $args['site_url'] = home_url();
4051 }
4052
4053 $response = Wdkit_Data_Hooks::get_data( 'wkit_activate_key', $args );
4054 }
4055
4056 wp_send_json( $response );
4057 wp_die();
4058 }
4059
4060 /**
4061 *
4062 * Get list local Widget List
4063 *
4064 * @since 1.0.0
4065 */
4066 protected function wdkit_get_local_widgets() {
4067 $builder = array();
4068 $a_c_s_d_s_c = array();
4069 $j_s_o_n_array = array();
4070
4071 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'bricks', 'widget' ) ) {
4072 array_push( $builder, 'bricks' );
4073 }
4074
4075 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor', 'widget' ) ) {
4076 array_push( $builder, 'elementor' );
4077 }
4078
4079 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) {
4080 array_push( $builder, 'gutenberg' );
4081 }
4082
4083 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_core', 'widget' ) ) {
4084 array_push( $builder, 'gutenberg_core' );
4085 }
4086
4087 foreach ( $builder as $key => $name ) {
4088 $elementor_dir = WDKIT_BUILDER_PATH . '/' . $name;
4089
4090 if ( ! empty( $elementor_dir ) && is_dir( $elementor_dir ) ) {
4091 $elementor_list = scandir( $elementor_dir );
4092 $elementor_list = array_diff( $elementor_list, array( '.', '..' ) );
4093
4094 if ( ! empty( $elementor_list ) ) {
4095 foreach ( $elementor_list as $key => $value ) {
4096 $a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) . $key ]['data'] = $value;
4097 $a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) . $key ]['builder'] = $name;
4098 }
4099 }
4100 }
4101 }
4102
4103 ksort( $a_c_s_d_s_c );
4104 $a_c_s_d_s_c = array_reverse( $a_c_s_d_s_c );
4105
4106 foreach ( $a_c_s_d_s_c as $key => $value ) {
4107 $elementor_dir = WDKIT_BUILDER_PATH . '/' . $value['builder'];
4108
4109 if ( file_exists( "{$elementor_dir}/{$value['data']}" ) && is_dir( "{$elementor_dir}/{$value['data']}" ) ) {
4110 $sub_dir = scandir( "{$elementor_dir}/{$value['data']}" );
4111 $sub = array_diff( $sub_dir, array( '.', '..' ) );
4112
4113 foreach ( $sub as $sub_dir_value ) {
4114 $file = new SplFileInfo( $sub_dir_value );
4115 $check_ext = $file->getExtension();
4116 $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
4117
4118 if ( 'json' === $ext ) {
4119 $widget1 = WDKIT_BUILDER_PATH . "/{$value['builder']}/{$value['data']}/{$sub_dir_value}";
4120 $filedata = wp_json_file_decode( $widget1 );
4121 $decode_data = json_decode( wp_json_encode( $filedata ), true );
4122 array_push( $j_s_o_n_array, $decode_data['widget_data'] );
4123 }
4124 }
4125 }
4126 }
4127
4128 return $j_s_o_n_array;
4129 }
4130
4131 /**
4132 *
4133 * It is Use for manage widget category.
4134 *
4135 * @since 1.0.0
4136 */
4137 protected function wdkit_manage_widget_category() {
4138 $data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : '';
4139 $data = json_decode( stripslashes( $data ) );
4140
4141 $type = isset( $data->manage_type ) ? sanitize_text_field( wp_unslash( $data->manage_type ) ) : '';
4142 $wkit_builder_option = get_option( 'wkit_builder' );
4143
4144 if ( empty( $wkit_builder_option ) ) {
4145 add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' );
4146 }
4147
4148 if ( 'get' === $type ) {
4149 if ( ! in_array( 'WDesignKit', $wkit_builder_option ) ) {
4150 update_option( 'wkit_builder', array( 'WDesignKit' ) );
4151 }
4152 } elseif ( 'update' === $type ) {
4153 $list = isset( $data->category_list ) ? $data->category_list : array();
4154 $list = array_unique( $list );
4155 $list = array_values( $list );
4156
4157 if ( ! empty( $list ) ) {
4158 update_option( 'wkit_builder', $list );
4159 }
4160 }
4161
4162 wp_send_json( get_option( 'wkit_builder' ) );
4163 }
4164
4165 /**
4166 * Get Workspace data
4167 *
4168 * @since 2.2.5
4169 */
4170 public function wdkit_get_workspace_data() {
4171
4172 $wid = isset( $_POST['wid'] ) ? sanitize_text_field( $_POST['wid'] ) : '';
4173 $token = isset( $_POST['token'] ) ? sanitize_text_field( $_POST['token'] ) : '';
4174
4175 if ( empty( $wid ) ) {
4176 return array(
4177 'success' => false,
4178 'message' => esc_html__( 'Workspace ID Not Found', 'wdesignkit' ),
4179 'description' => esc_html__( 'Workspace ID is required', 'wdesignkit' ),
4180 );
4181 }
4182
4183 if ( empty( $token ) ) {
4184 return array(
4185 'success' => false,
4186 'message' => esc_html__( 'Token Not Found', 'wdesignkit' ),
4187 'description' => esc_html__( 'Token is required', 'wdesignkit' ),
4188 );
4189 }
4190
4191 $args = array(
4192 'token' => $token,
4193 'wid' => $wid,
4194 );
4195
4196 $this->wdkit_api = $this->wdkit_api_v2;
4197
4198 $url = "workspace/{$wid}/get";
4199
4200 $response = $this->wkit_api_call( $args, $url );
4201
4202 wp_send_json( $response['data'] );
4203 wp_die();
4204 }
4205
4206 /**
4207 *
4208 * Custom_upload_dir
4209 *
4210 * @since 1.0.0
4211 *
4212 * @param array $upload store data.
4213 */
4214 public function custom_upload_dir( $upload ) {
4215 // Specify the path to your custom upload directory.
4216 if ( isset( $this->widget_folder_u_r_l ) && ! empty( $this->widget_folder_u_r_l ) ) {
4217
4218 // Set the custom directory as the upload path.
4219 $upload['path'] = $this->widget_folder_u_r_l;
4220 // Set the URL for the uploaded file.
4221 $upload['url'] = $upload['baseurl'] . $upload['subdir'];
4222 }
4223
4224 return $upload;
4225 }
4226
4227 /**
4228 *
4229 * It is Use for delete widget from server
4230 *
4231 * @since 1.0.0
4232 */
4233 protected function wkit_widget_json() {
4234 $widget_type = ! empty( $_POST['widget_type'] ) ? wp_unslash( $_POST['widget_type'] ) : '';
4235 $folder_name = ! empty( $_POST['folder_name'] ) ? wp_unslash( $_POST['folder_name'] ) : '';
4236 $file_name = ! empty( $_POST['file_name'] ) ? ( wp_unslash( $_POST['file_name'] ) ) : '';
4237
4238 if ( empty( $widget_type ) || empty( $folder_name ) || empty( $file_name ) ) {
4239 return array(
4240 'success' => false,
4241 'message' => esc_html__( 'Widget JSON not found', 'wdesignkit' ),
4242 'description' => esc_html__( 'widget JSON file not found.', 'wdesignkit' ),
4243 );
4244 }
4245
4246 $json_path = WDKIT_BUILDER_PATH . "/{$widget_type}/{$folder_name}/{$file_name}";
4247
4248 $json_data = wp_json_file_decode( "$json_path.json" );
4249 if ( ! empty( $json_data ) ) {
4250 $result = (object) array(
4251 'success' => true,
4252 'data' => $json_data,
4253 'message' => esc_html__( 'Widget get Successfully', 'wdesignkit' ),
4254 'description' => esc_html__( 'Widget JSON get Successfully', 'wdesignkit' ),
4255 );
4256 } else {
4257 $result = (object) array(
4258 'success' => false,
4259 'message' => esc_html__( 'Widget not get', 'wdesignkit' ),
4260 'description' => esc_html__( 'Widget JSON not get', 'wdesignkit' ),
4261 );
4262 }
4263
4264 wp_send_json( $result );
4265 wp_die();
4266 }
4267
4268 /**
4269 *
4270 * It is Use for download widget from widget listing.
4271 *
4272 * @since 1.0.0
4273 */
4274 protected function wdkit_download_widget() {
4275 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
4276 $data = json_decode( stripslashes( $data ) );
4277
4278 $array_data = array(
4279 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
4280 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
4281 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
4282 );
4283
4284 $response = $this->wkit_api_call( $array_data, 'save_widget' );
4285 $success = ! empty( $response['success'] ) ? $response['success'] : false;
4286
4287 if ( empty( $success ) ) {
4288 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
4289 $result = (object) array(
4290 'success' => false,
4291 'message' => $massage,
4292 'description' => esc_html__( ' Widget not Downloaded', 'wdesignkit' ),
4293 );
4294
4295 wp_send_json( $result );
4296 wp_die();
4297 }
4298
4299 $response = json_decode( wp_json_encode( $response['data'] ), true );
4300
4301 if ( empty( $response ) || empty( $response['data'] ) ) {
4302 $message = ! empty( $response['message'] ) ? $response['message'] : 'No Response Found';
4303 $description = ! empty( $response['description'] ) ? $response['description'] : 'Widget not Downloaded';
4304
4305 $result = (object) array(
4306 'success' => false,
4307 'message' => esc_html( $message ),
4308 'description' => esc_html( $description ),
4309 );
4310
4311 wp_send_json( $result );
4312 wp_die();
4313 }
4314
4315 $img_url = ! empty( $response['data']['image'] ) ? $response['data']['image'] : '';
4316 $json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'], true ) : '';
4317
4318 if ( empty( $response['success'] ) ) {
4319 wp_send_json( $responce );
4320 wp_die();
4321 }
4322
4323 if ( empty( $img_url ) && empty( $json_data ) ) {
4324 $responce = (object) array(
4325 'success' => false,
4326 'message' => esc_html__( 'No Response Found', 'wdesignkit' ),
4327 'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ),
4328 );
4329
4330 wp_send_json( $responce );
4331 wp_die();
4332 }
4333
4334 include_once ABSPATH . 'wp-admin/includes/file.php';
4335 \WP_Filesystem();
4336 global $wp_filesystem;
4337
4338 if ( ! is_array( $json_data ) ) {
4339 $json_data = json_decode( $json_data, true );
4340 }
4341
4342 $title = ! empty( $json_data['widget_data']['widgetdata']['name'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['name'] ) : '';
4343 $builder = ! empty( $json_data['widget_data']['widgetdata']['type'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['type'] ) : '';
4344 $w_uniq = ! empty( $json_data['widget_data']['widgetdata']['widget_id'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['widget_id'] ) : '';
4345
4346 $folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
4347 $file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
4348 $builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/";
4349
4350 if ( ! is_dir( $builder_type_path ) ) {
4351 wp_mkdir_p( $builder_type_path );
4352 }
4353
4354 if ( ! is_dir( $builder_type_path . $folder_name ) ) {
4355 wp_mkdir_p( $builder_type_path . $folder_name );
4356 }
4357
4358 if ( ! empty( $img_url ) ) {
4359 $img_body = wp_remote_get( $img_url );
4360 $img_ext = pathinfo( $img_url )['extension'];
4361
4362 $wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] );
4363 $json_data['widget_data']['widgetdata']['w_image'] = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
4364 }
4365
4366 $result = (object) array(
4367 'success' => false,
4368 'message' => ! empty( $response['message'] ) ? $response['message'] : esc_html__( 'no message', 'wdesignkit' ),
4369 'description' => '',
4370 'json' => wp_json_encode( $json_data ),
4371 );
4372
4373 wp_send_json( $result );
4374 wp_die();
4375 }
4376
4377 /**
4378 *
4379 * It is Use for sync widget to server
4380 *
4381 * @since 1.0.0
4382 */
4383 protected function wdkit_add_widget() {
4384 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
4385 $data = base64_decode( $data );
4386 $data = json_decode( $data );
4387
4388 $title = isset( $data->title ) ? sanitize_text_field( $data->title ) : '';
4389 $builder = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '';
4390 $w_uniq = isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '';
4391 $w_image = isset( $data->w_image ) ? esc_url_raw( $data->w_image ) : '';
4392
4393 if ( ! empty( $w_image ) ) {
4394 $w_image = str_replace( '\\', '', $w_image );
4395 $w_image = wp_remote_get( $w_image )['body'];
4396 }
4397
4398 $array_data = array(
4399 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
4400 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
4401 'title' => isset( $data->title ) ? sanitize_text_field( $data->title ) : '',
4402 'content' => isset( $data->content ) ? sanitize_text_field( $data->content ) : '',
4403 'builder' => isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '',
4404 'w_data' => isset( $data->w_data ) ? $data->w_data : '',
4405 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
4406 'w_image' => $w_image,
4407 'w_imgext' => isset( $data->w_imgext ) ? sanitize_text_field( $data->w_imgext ) : '',
4408 'w_version' => isset( $data->w_version ) ? $data->w_version : '',
4409 'w_updates' => ! empty( $data->w_updates ) ? serialize( $data->w_updates ) : serialize( array() ),
4410 'r_id' => isset( $data->r_id ) ? $data->r_id : 0,
4411 'unique_id' => get_option( 'wdkit_unique_id' ) ?? '',
4412 );
4413
4414 $response = $this->wkit_api_call( $array_data, 'save_widget' );
4415 $success = ! empty( $response['success'] ) ? $response['success'] : false;
4416
4417 if ( empty( $success ) ) {
4418 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
4419
4420 $result = (object) array(
4421 'success' => false,
4422 'message' => $massage,
4423 'description' => esc_html__( 'Widget Not Added', 'wdesignkit' ),
4424 );
4425
4426 wp_send_json( $result );
4427 wp_die();
4428 }
4429
4430 $res = ! empty( $response['data'] ) ? $response['data'] : array();
4431
4432 $response = json_decode( wp_json_encode( $res ), true );
4433 $img_url = ! empty( $response['data']['imgurl'] ) ? $response['data']['imgurl'] : '';
4434
4435 if ( ! empty( $img_url ) && 'error' !== $res ) {
4436
4437 $img_body = wp_remote_get( $img_url );
4438 $img_ext = pathinfo( $img_url )['extension'];
4439 include_once ABSPATH . 'wp-admin/includes/file.php';
4440 \WP_Filesystem();
4441 global $wp_filesystem;
4442 $folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
4443 $file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
4444 $file_path = WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name";
4445
4446 $u_r_l = wp_json_file_decode( "$file_path.json" );
4447 $u_r_l->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
4448
4449 $wp_filesystem->put_contents( "$file_path.json", wp_json_encode( $u_r_l ) );
4450 $wp_filesystem->put_contents( "$file_path.$img_ext", $img_body['body'] );
4451 }
4452
4453 wp_send_json( $response );
4454 wp_die();
4455 }
4456
4457 /**
4458 *
4459 * It is Use for manage favourite widget
4460 *
4461 * @since 1.0.0
4462 */
4463 protected function wdkit_favourite_widget() {
4464 $data = isset( $_POST['widget_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['widget_info'] ) ) ) ) : '';
4465 $array_data = array(
4466 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
4467 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
4468 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
4469 );
4470
4471 $response = $this->wkit_api_call( $array_data, 'save_widget' );
4472 $success = ! empty( $response['success'] ) ? $response['success'] : false;
4473
4474 if ( empty( $success ) ) {
4475 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
4476
4477 $result = (object) array(
4478 'success' => false,
4479 'message' => $massage,
4480 'description' => '',
4481 );
4482
4483 wp_send_json( $result );
4484 wp_die();
4485 }
4486
4487 wp_send_json( $response );
4488 wp_die();
4489 }
4490
4491 /**
4492 * It is Used Setting Panel Defalut Data Get.
4493 *
4494 * @since 1.0.0
4495 */
4496 protected function wdkit_setting_panel() {
4497 $event = ! empty( $_POST['event'] ) ? sanitize_text_field( wp_unslash( $_POST['event'] ) ) : 'get';
4498
4499 if ( 'get' === $event ) {
4500 return self::wkit_get_settings_panel();
4501 } elseif ( 'set' === $event ) {
4502 $data = ! empty( $_POST['data'] ) ? stripslashes( sanitize_text_field( wp_unslash( $_POST['data'] ) ) ) : array();
4503
4504 $data = json_decode( $data, true );
4505
4506 update_option( 'wkit_settings_panel', $data );
4507 return self::wkit_get_settings_panel();
4508 } else {
4509 return false;
4510 }
4511 }
4512
4513 /**
4514 * Get Setting Panal Data
4515 *
4516 * @since 1.0.0
4517 */
4518 protected static function wkit_get_settings_panel() {
4519 $new_version = '';
4520 $current_version = WDKIT_VERSION;
4521 $response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/wdesignkit.json' );
4522
4523 if ( is_wp_error( $response ) ) {
4524 return false;
4525 }
4526
4527 $body = wp_remote_retrieve_body( $response );
4528 $data = json_decode( $body );
4529
4530 if ( isset( $data->version ) ) {
4531 $new_version = $data->version;
4532 }
4533
4534 $version_check = array();
4535
4536 if ( $new_version && version_compare( $current_version, $new_version, '<' ) ) {
4537 $version_check['success'] = true;
4538 $version_check['version'] = $new_version;
4539 } else {
4540 $version_check['success'] = false;
4541 $version_check['version'] = $new_version;
4542 }
4543
4544 $get_setting = get_option( 'wkit_settings_panel', false );
4545
4546 $setting_data = array(
4547 'builder' => isset( $get_setting['builder'] ) ? $get_setting['builder'] : true,
4548 'template' => isset( $get_setting['template'] ) ? $get_setting['template'] : true,
4549 'gutenberg_builder' => isset( $get_setting['gutenberg_builder'] ) ? $get_setting['gutenberg_builder'] : true,
4550 'gutenberg_core_builder' => isset( $get_setting['gutenberg_core_builder'] ) ? $get_setting['gutenberg_core_builder'] : false,
4551 'elementor_builder' => isset( $get_setting['elementor_builder'] ) ? $get_setting['elementor_builder'] : true,
4552 'bricks_builder' => isset( $get_setting['bricks_builder'] ) ? $get_setting['bricks_builder'] : false,
4553 'gutenberg_template' => isset( $get_setting['gutenberg_template'] ) ? $get_setting['gutenberg_template'] : true,
4554 'elementor_template' => isset( $get_setting['elementor_template'] ) ? $get_setting['elementor_template'] : true,
4555 'code_snippet' => isset( $get_setting['code_snippet'] ) ? $get_setting['code_snippet'] : true,
4556 'plugin_version' => $version_check,
4557 );
4558
4559 if ( isset( $get_setting['remove_db'] ) ) {
4560 $setting_data['remove_db'] = $get_setting['remove_db'];
4561 }
4562
4563 if ( isset( $get_setting['debugger_mode'] ) ) {
4564 $setting_data['debugger_mode'] = $get_setting['debugger_mode'];
4565 }
4566
4567 return $setting_data;
4568 }
4569
4570 /**
4571 * Updated White Label Data.
4572 *
4573 * @since 1.1.8
4574 */
4575 protected function wkit_white_label() {
4576
4577 $get_wl_data = ! empty( $_POST['WhiteLabelData'] ) ? wp_unslash( $_POST['WhiteLabelData'] ) : array();
4578
4579 if ( ! empty( $get_wl_data ) ) {
4580 $white_label_data = json_decode( $get_wl_data, true );
4581 $plugin_name = $white_label_data['plugin_name'];
4582 } else {
4583 $result = array(
4584 'success' => false,
4585 'message' => esc_html__( 'Data Not Found', 'wdesignkit' ),
4586 );
4587
4588 wp_send_json( $result );
4589 wp_die();
4590 }
4591
4592 if ( ! empty( $plugin_name ) ) {
4593 $get_white_label = get_option( 'wkit_white_label', false );
4594 if ( ! empty( $get_white_label ) ) {
4595 update_option( 'wkit_white_label', $white_label_data );
4596 } else {
4597 add_option( 'wkit_white_label', $white_label_data );
4598 }
4599 } else {
4600 $result = array(
4601 'success' => false,
4602 'message' => esc_html__( 'Plugin Name Not Found', 'wdesignkit' ),
4603 );
4604
4605 wp_send_json( $result );
4606 wp_die();
4607 }
4608
4609 $get_updated_data = get_option( 'wkit_white_label', false );
4610 $response = array(
4611 'message' => 'Data Added successfully',
4612 'success' => true,
4613 'data' => $get_updated_data,
4614 );
4615
4616 wp_send_json( $response );
4617 }
4618
4619 /**
4620 * Reset White Label Data.
4621 *
4622 * @since 1.1.8
4623 */
4624 public function wkit_reset_wl() {
4625 $wl_data = get_option( 'wkit_white_label' );
4626
4627 if ( ! empty( $wl_data ) ) {
4628 delete_option( 'wkit_white_label' );
4629
4630 $result = array(
4631 'success' => true,
4632 'message' => esc_html__( 'Reset White Label Successfully', 'wdesignkit' ),
4633 );
4634
4635 wp_send_json( $result );
4636 wp_die();
4637 }
4638 }
4639
4640 /**
4641 *
4642 * Use for Add new licence key.
4643 *
4644 * @since 1.0.0
4645 */
4646 protected function wdkit_activate_licence() {
4647 $args = array(
4648 'token' => ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
4649 'licencekey' => ! empty( $_POST['licencekey'] ) ? sanitize_text_field( wp_unslash( $_POST['licencekey'] ) ) : '',
4650 'licencename' => ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '',
4651 'uichemyid' => ! empty( $_POST['uichemyid'] ) ? sanitize_text_field( wp_unslash( $_POST['uichemyid'] ) ) : '',
4652 );
4653
4654 $response = $this->wkit_api_call( $args, 'wkit_activate_key' );
4655
4656 if ( ! empty( $response['data'] ) ) {
4657 $response = json_decode( wp_json_encode( $response['data'] ), true );
4658
4659 if ( ! empty( $response['data']['tpae_licence'] ) && is_serialized( $response['data']['tpae_licence'] ) ) {
4660 $response['data']['tpae_licence'] = unserialize( $response['data']['tpae_licence'] );
4661 }
4662
4663 if ( ! empty( $response['data']['tpag_licence'] ) && is_serialized( $response['data']['tpag_licence'] ) ) {
4664 $response['data']['tpag_licence'] = unserialize( $response['data']['tpag_licence'] );
4665 }
4666
4667 if ( ! empty( $response['data']['uichemy_licence'] ) && is_serialized( $response['data']['uichemy_licence'] ) ) {
4668 $response['data']['uichemy_licence'] = unserialize( $response['data']['uichemy_licence'] );
4669 }
4670
4671 if ( ! empty( $response['data']['wdkit_licence'] ) && is_serialized( $response['data']['wdkit_licence'] ) ) {
4672 $response['data']['wdkit_licence'] = unserialize( $response['data']['wdkit_licence'] );
4673
4674 // Store WDesignKit license status locally for quick access
4675 if ( ! empty( $response['data']['wdkit_licence'] ) && is_array( $response['data']['wdkit_licence'] ) ) {
4676 update_option( 'wdkit_licence_data', $response['data']['wdkit_licence'] );
4677 }
4678 }
4679
4680 if ( ! empty( $response['data']['wdkit_licence_extra'] ) && is_serialized( $response['data']['wdkit_licence_extra'] ) ) {
4681 $response['data']['wdkit_licence_extra'] = unserialize( $response['data']['wdkit_licence_extra'] );
4682 }
4683 }
4684
4685 wp_send_json( $response );
4686 wp_die();
4687 }
4688
4689 /**
4690 *
4691 * Use for Delete licence key.
4692 *
4693 * @since 1.0.0
4694 */
4695 protected function wdkit_delete_licence_key() {
4696 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
4697 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
4698 $apikey = ! empty( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : '';
4699
4700 $args = array(
4701 'token' => $token,
4702 'licencename' => $licencename,
4703 'apikey' => $apikey,
4704 );
4705
4706 $response = $this->wkit_api_call( $args, 'licence_delete' );
4707
4708 // Remove local WDesignKit license data if deleting WDesignKit license
4709 if ( 'wdkit' === $licencename ) {
4710 delete_option( 'wdkit_licence_data' );
4711 }
4712
4713 wp_send_json( $response['data'] );
4714 wp_die();
4715 }
4716
4717 /**
4718 *
4719 * Use for Sync licence key.
4720 *
4721 * @since 1.0.0
4722 */
4723 protected function wdkit_sync_licence_key() {
4724 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
4725 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
4726
4727 $args = array(
4728 'token' => $token,
4729 'licencename' => $licencename,
4730 );
4731
4732 $response = $this->wkit_api_call( $args, 'licence_sync' );
4733
4734 wp_send_json( $response['data'] );
4735 wp_die();
4736 }
4737
4738 /**
4739 * Rollback to Previous Versions
4740 *
4741 * @since 1.1.0
4742 */
4743 protected function wdkit_prev_version() {
4744
4745 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
4746
4747 $plugin_info = plugins_api(
4748 'plugin_information',
4749 array(
4750 'slug' => 'wdesignkit',
4751 )
4752 );
4753
4754 if ( empty( $plugin_info->versions ) || ! is_array( $plugin_info->versions ) ) {
4755 return array();
4756 }
4757
4758 krsort( $plugin_info->versions );
4759
4760 $versions_list = array();
4761 $index = 0;
4762
4763 foreach ( $plugin_info->versions as $version => $download_link ) {
4764
4765 $lowercase_version = strtolower( $version );
4766
4767 $is_valid_version = ! preg_match( '/(beta|rc|trunk|dev)/i', $lowercase_version );
4768
4769 $is_valid_version = apply_filters( 'wdkit_check_rollback_version', $is_valid_version, $lowercase_version );
4770
4771 if ( ! $is_valid_version || version_compare( $version, WDKIT_VERSION, '>=' ) ) {
4772 continue;
4773 }
4774
4775 $versions_list[] = $version;
4776 ++$index;
4777 }
4778
4779 // set_transient( 'wdkit_rollback_version_' . WDKIT_VERSION, $versions_list, WEEK_IN_SECONDS );
4780
4781 return $versions_list;
4782 }
4783
4784 /**
4785 * Rollback to Previous Versions
4786 *
4787 * @since 1.1.0
4788 */
4789 protected function wdkit_rollback_check() {
4790
4791 $current_ver = isset( $_POST['version'] ) ? sanitize_text_field( wp_unslash( $_POST['version'] ) ) : '';
4792 $rv = $this->wdkit_prev_version();
4793
4794 if ( empty( $current_ver ) || ! in_array( $current_ver, $rv ) ) {
4795 return array(
4796 'message' => esc_html__( 'Invalid Nonce or version not found', 'wdesignkit' ),
4797 'status' => 'error',
4798 'success' => false,
4799 );
4800 }
4801
4802 $plugin_slug = basename( WDKIT_PBNAME, '.php' );
4803
4804 $this_version = $current_ver;
4805 $this_pluginname = WDKIT_PBNAME;
4806 $this_plugin_u_r_l = sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $this_version );
4807
4808 $plugin_info = new \stdClass();
4809 $plugin_info->new_version = $this_version;
4810 $plugin_info->slug = $plugin_slug;
4811 $plugin_info->package = $this_plugin_u_r_l;
4812 $plugin_info->url = 'https://wdesignkit.com/';
4813
4814 $update_plugins_data = get_site_transient( 'update_plugins' );
4815
4816 if ( ! is_object( $update_plugins_data ) ) {
4817 $update_plugins_data = new \stdClass();
4818 }
4819
4820 $update_plugins_data->response[ $this_pluginname ] = $plugin_info;
4821
4822 set_site_transient( 'update_plugins', $update_plugins_data );
4823
4824 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
4825
4826 $logo_url = WDKIT_URL . 'assets/images/jpg/Wdesignkit-logo.png';
4827
4828 $args = array(
4829 'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this_pluginname ),
4830 'plugin' => $this_pluginname,
4831 'nonce' => 'upgrade-plugin_' . $this_pluginname,
4832 'title' => '<img src="' . esc_url( $logo_url ) . '" alt="wdesignkit-logo"><div class="theplus-rb-subtitle">' . esc_html__( 'Rollback to Previous Version', 'wdesignkit' ) . '</div>',
4833 );
4834
4835 $upgrader_plugin = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $args ) );
4836 $upgrader_plugin->upgrade( $this_pluginname );
4837
4838 activate_plugin( $this_pluginname );
4839
4840 return array(
4841 'message' => esc_html__( 'Rollback Successful, Plugin Re-activated', 'wdesignkit' ),
4842 'status' => 'Success',
4843 'success' => true,
4844 );
4845 }
4846
4847 /**
4848 *
4849 * It is Use for logout.
4850 *
4851 * @since 1.0.0
4852 */
4853 protected function wdkit_logout() {
4854 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
4855 $logout_type = isset( $_POST['logout_type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['logout_type'] ) ) ) : '';
4856
4857 $response = '';
4858
4859 if ( ! empty( $email ) ) {
4860 $token = $this->wdkit_login_user_token( $email );
4861 $args = array( 'token' => $token );
4862
4863 if ( 'session' !== $logout_type ) {
4864 delete_transient( 'wdkit_auth_' . $email );
4865 // Clear stored license data on logout so banner shows again
4866 delete_option( 'wdkit_licence_data' );
4867 $response = WDesignKit_Data_Query::get_data( 'logout', $args );
4868 }
4869 }
4870
4871 wp_send_json( $response );
4872 wp_die();
4873 }
4874
4875 /**
4876 *
4877 * It is Use for get token of login user.
4878 *
4879 * @since 1.0.0
4880 *
4881 * @param string $email check user email.
4882 */
4883 protected function wdkit_login_user_token( $email = '' ) {
4884
4885 if ( ! empty( $email ) ) {
4886 $user_key = strstr( $email, '@', true );
4887 $get_login = get_transient( 'wdkit_auth_' . $user_key );
4888
4889 if ( ! empty( $get_login ) && ! empty( $get_login['token'] ) ) {
4890 return $get_login['token'];
4891 }
4892 }
4893
4894 return false;
4895 }
4896
4897 /**
4898 * Parse args $_POST
4899 *
4900 * @since 1.0.0
4901 *
4902 * @param string $data send all post data.
4903 * @param string $type store text data.
4904 * @param string $condition store text data.
4905 */
4906 protected function wdkit_sanitizer_bypass( $data, $type, $condition = 'none' ) {
4907
4908 if ( 'none' === $condition ) {
4909 return $data[ $type ];
4910 } elseif ( 'cr_widget' === $condition ) {
4911 return $data[ $type ];
4912 }
4913 }
4914
4915
4916 /**
4917 * Parse args $_POST
4918 *
4919 * @since 1.0.0
4920 *
4921 * @param string $data send all post data.
4922 */
4923 protected function wdkit_parse_args( $data = array() ) {
4924 if ( empty( $data ) ) {
4925 return array();
4926 }
4927
4928 $args = array();
4929 if ( isset( $data['email'] ) ) {
4930 $args['email'] = isset( $data['email'] ) ? sanitize_email( $data['email'] ) : '';
4931 }
4932
4933 if ( isset( $data['data'] ) ) {
4934 $args['data'] = isset( $data['data'] ) ? wp_unslash( $data['data'] ) : array();
4935 }
4936
4937 if ( isset( $data['plugins'] ) ) {
4938 $args['plugins'] = isset( $data['plugins'] ) ? wp_unslash( $data['plugins'] ) : array();
4939 }
4940
4941 if ( isset( $data['template_id'] ) ) {
4942 $args['template_id'] = isset( $data['template_id'] ) ? intval( strtolower( sanitize_text_field( $data['template_id'] ) ) ) : '';
4943 }
4944
4945 if ( isset( $data['builder'] ) ) {
4946 $args['builder'] = isset( $data['builder'] ) ? wp_unslash( $data['builder'] ) : '';
4947 }
4948
4949 if ( isset( $data['editor'] ) ) {
4950 $args['editor'] = isset( $data['editor'] ) ? sanitize_text_field( $data['editor'] ) : '';
4951 }
4952
4953 if ( isset( $data['type_upload'] ) ) {
4954 $args['type_upload'] = isset( $data['type_upload'] ) ? sanitize_text_field( $data['type_upload'] ) : '';
4955 }
4956
4957 if ( isset( $data['title'] ) ) {
4958 $args['title'] = isset( $data['title'] ) ? wp_strip_all_tags( $data['title'] ) : '';
4959 }
4960
4961 if ( isset( $data['template_type'] ) ) {
4962 $args['template_type'] = isset( $data['template_type'] ) ? sanitize_text_field( $data['template_type'] ) : '';
4963 }
4964
4965 if ( isset( $data['wstype'] ) ) {
4966 $args['wstype'] = isset( $data['wstype'] ) ? wp_strip_all_tags( $data['wstype'] ) : '';
4967 }
4968
4969 if ( isset( $data['wid'] ) ) {
4970 $args['wid'] = isset( $data['wid'] ) ? intval( strtolower( sanitize_text_field( $data['wid'] ) ) ) : '';
4971 }
4972
4973 if ( isset( $data['perpage'] ) ) {
4974 $args['perpage'] = isset( $data['perpage'] ) ? intval( strtolower( sanitize_text_field( $data['perpage'] ) ) ) : 12;
4975 }
4976
4977 if ( isset( $data['page'] ) ) {
4978 $args['page'] = isset( $data['page'] ) ? intval( strtolower( sanitize_text_field( $data['page'] ) ) ) : 1;
4979 }
4980
4981 if ( isset( $data['buildertype'] ) ) {
4982 $args['buildertype'] = isset( $data['buildertype'] ) ? sanitize_text_field( $data['buildertype'] ) : '';
4983 }
4984
4985 if ( isset( $data['search'] ) ) {
4986 $args['search'] = isset( $data['search'] ) ? sanitize_text_field( $data['search'] ) : '';
4987 }
4988
4989 if ( isset( $data['plugin'] ) ) {
4990 $args['plugin'] = isset( $data['plugin'] ) ? wp_unslash( $data['plugin'] ) : array();
4991 }
4992
4993 if ( isset( $data['plugin_exclude'] ) ) {
4994 $args['plugin_exclude'] = isset( $data['plugin_exclude'] ) ? wp_unslash( $data['plugin_exclude'] ) : array();
4995 }
4996
4997 if ( isset( $data['ai_compatibility'] ) ) {
4998 $args['ai_compatibility'] = isset( $data['ai_compatibility'] ) ? wp_unslash( $data['ai_compatibility'] ) : array();
4999 }
5000
5001 // if ( isset( $data['global_color'] ) ) {
5002 // $args['global_color'] = isset( $data['global_color'] ) ? wp_unslash( $data['global_color'] ) : array();
5003 // }
5004
5005 // if ( isset( $data['global_font_family'] ) ) {
5006 // $args['global_font_family'] = isset( $data['global_font_family'] ) ? wp_unslash( $data['global_font_family'] ) : array();
5007 // }
5008
5009 if ( isset( $data['global_data'] ) ) {
5010 $args['global_data'] = isset( $data['global_data'] ) ? wp_unslash( $data['global_data'] ) : array();
5011 }
5012
5013 if ( isset( $data['tag'] ) ) {
5014 $args['tag'] = isset( $data['tag'] ) ? wp_unslash( $data['tag'] ) : array();
5015 }
5016
5017 if ( isset( $data['category'] ) ) {
5018 $args['category'] = isset( $data['category'] ) ? wp_unslash( $data['category'] ) : array();
5019 }
5020
5021 if ( isset( $data['free_pro'] ) ) {
5022 $args['free_pro'] = isset( $data['free_pro'] ) ? sanitize_text_field( wp_unslash( $data['free_pro'] ) ) : '';
5023 }
5024
5025 if ( isset( $data['wp_post_type'] ) ) {
5026 $args['wp_post_type'] = isset( $data['wp_post_type'] ) ? sanitize_text_field( wp_unslash( $data['wp_post_type'] ) ) : '';
5027 }
5028
5029 if ( isset( $data['favorite'] ) ) {
5030 $args['favorite'] = isset( $data['favorite'] ) ? sanitize_text_field( wp_unslash( $data['favorite'] ) ) : '';
5031 }
5032
5033 if ( isset( $data['content'] ) ) {
5034 $args['content'] = isset( $data['content'] ) ? wp_unslash( $data['content'] ) : '';
5035 }
5036
5037 if ( isset( $data['page_type'] ) ) {
5038 $args['page_type'] = isset( $data['page_type'] ) ? wp_unslash( $data['page_type'] ) : array();
5039 }
5040
5041 return $args;
5042 }
5043
5044 /**
5045 * Dark Mode
5046 *
5047 * @since 2.0.0
5048 *
5049 * @param string store darkmode value in database.
5050 */
5051 protected function wdkit_dark_mode() {
5052 $dark_mode = ! empty( $_POST['dark_mode'] ) ? sanitize_text_field( $_POST['dark_mode'] ) : 'light';
5053
5054 if ( get_option( 'wdkit_dark_mode' ) ) {
5055 update_option( 'wdkit_dark_mode', $dark_mode );
5056 } else {
5057 add_option( 'wdkit_dark_mode', $dark_mode );
5058 }
5059
5060 $response = array(
5061 'message' => esc_html__( 'Dark Mode Updated', 'wdesignkit' ),
5062 'status' => 'Success',
5063 'success' => true,
5064 );
5065
5066 wp_send_json( $response );
5067 wp_die();
5068 }
5069 }
5070
5071 Wdkit_Api_Call::get_instance();
5072 }
5073