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

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