PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.3.3
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.3.3
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.3, at includes/admin/class-api.php

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