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

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

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