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

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

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