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

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