PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow for WordPress / 1.2.6
WDesignKit – AI Templates, Widget Builder & MCP Workflow for WordPress v1.2.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 1.0.18 All 127 releases
wdesignkit / includes / admin / class-api.php

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

3,717 lines 114.5 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 $wdkit_api
41 */
42 public $wdkit_api = WDKIT_SERVER_SITE_URL . 'api/wp/';
43
44 /**
45 * Member Variable
46 *
47 * @var staring $widget_folder_u_r_l
48 */
49 public $widget_folder_u_r_l = '';
50
51 /**
52 * Member Variable
53 *
54 * @var staring $e_msg_login
55 */
56 public $e_msg_login = 'Login Error: Check your details and try again.';
57
58 /**
59 * Member Variable
60 *
61 * @var staring $e_desc_login
62 */
63 public $e_desc_login = 'Invalid Login Details';
64
65 /**
66 * Member Variable
67 *
68 * @var staring wdkit_onbording_api
69 */
70 public $wdkit_onbording_api = 'https://api.posimyth.com/wp-json/wdkit/v2/wdkit_store_user_data';
71
72 /**
73 * Member Variable
74 *
75 * @var staring wdkit_onbording_end
76 */
77 public $wdkit_onbording_end = 'wkit_onbording_end';
78
79 /**
80 * Initiator
81 */
82 public static function get_instance() {
83 if ( ! isset( self::$instance ) ) {
84 self::$instance = new self();
85 }
86
87 return self::$instance;
88 }
89
90 /**
91 * Define the core functionality of the plugin.
92 */
93 public function __construct() {
94 add_action( 'wp_ajax_get_wdesignkit', array( $this, 'wdkit_api_call' ) );
95 }
96
97 /**
98 * Error JSON message
99 *
100 * @param array $data give array.
101 * @param string $status api code number.
102 *
103 * @since 1.0.0
104 * */
105 public function wdkit_error_msg( $data = null, $status = null ) {
106 wp_send_json_error( $data );
107 wp_die();
108 }
109
110 /**
111 * Success JSON message
112 *
113 * @param array $data give array.
114 * @param string $status api code number.
115 *
116 * @since 1.0.0
117 * */
118 public function wdkit_success_msg( $data = null, $status = null ) {
119 wp_send_json_success( $data, $status );
120 wp_die();
121 }
122
123 /**
124 * Get Wdkit Api Call Ajax.
125 */
126 public function wdkit_api_call() {
127
128 check_ajax_referer( 'wdkit_nonce', 'kit_nonce' );
129
130 if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
131 wp_send_json_error( array( 'content' => __( 'Insufficient permissions.', 'wdesignkit' ) ) );
132 }
133
134 $type = isset( $_POST['type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['type'] ) ) ) : false;
135 if ( ! $type ) {
136 $this->wdkit_error_msg( __( 'Something went wrong.', 'wdesignkit' ) );
137 }
138
139 switch ( $type ) {
140 case 'onboarding_handler':
141 $data = $this->wdkit_onboarding_handler();
142 break;
143 case 'wkit_login':
144 $data = apply_filters( 'wp_wdkit_login_ajax', 'wkit_login' );
145 break;
146 case 'api_login':
147 $data = apply_filters( 'wp_wdkit_login_ajax', 'api_login' );
148 break;
149 case 'social_login':
150 $data = apply_filters( 'wp_wdkit_login_ajax', 'social_login' );
151 break;
152 case 'wkit_meta_data':
153 $data = $this->wdkit_meta_data();
154 break;
155 case 'get_user_info':
156 $data = $this->wdkit_get_user_info();
157 break;
158 case 'browse_page':
159 $data = $this->wdkit_browse_page();
160 break;
161 case 'kit_template':
162 $data = $this->wdkit_template();
163 break;
164 case 'wkit_preset_template':
165 $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_template' );
166 break;
167 case 'wdkit_preset_dwnld_template':
168 $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_dwnld_template' );
169 break;
170 case 'template_remove':
171 $data = $this->wdkit_template_remove();
172 break;
173 case 'save_template':
174 $data = $this->wdkit_put_save_template();
175 break;
176 case 'get_global_val':
177 $data = $this->wdkit_get_global_val();
178 break;
179 case 'update_global_val':
180 $data = $this->wdkit_update_global_val();
181 break;
182 case 'update_preset_setting':
183 $data = $this->wdkit_update_preset();
184 break;
185 case 'find_template':
186 $data = $this->wdkit_find_existing_template();
187 break;
188 case 'update_template':
189 $data = $this->wdkit_update_template();
190 break;
191 case 'manage_favorite':
192 $data = $this->wdkit_manage_favorite();
193 break;
194 case 'check_plugins_depends':
195 $data = $this->wdkit_check_plugins_depends();
196 break;
197 case 'install_plugins_depends':
198 $data = $this->wdkit_install_plugins_depends();
199 break;
200 case 'update_latest_plugin':
201 $data = $this->wdkit_update_latest_plugin();
202 break;
203 case 'activate_container':
204 $data = $this->wdkit_activate_container();
205 break;
206 case 'import_template':
207 $data = $this->wdkit_import_template();
208 break;
209 case 'import_multi_template':
210 $data = $this->wdkit_import_multi_template();
211 break;
212 case 'import_page_section':
213 $data = $this->import_page_section_content();
214 break;
215 case 'import_kit_template':
216 $data = $this->wdkit_import_kit_template();
217 break;
218 case 'enable_template_widgets':
219 $data = $this->wdkit_enable_template_widgets();
220 break;
221 case 'scan_nexter_widgets':
222 if (has_filter('tpgb_disable_unsed_block_filter')) {
223 $data = apply_filters( 'tpgb_disable_unsed_block_filter', array('tpgb_disable_unsed_block_filter_fun') );
224
225 $res = array(
226 'massage' => __('Disabled Successfully', 'wdesignkit'),
227 'description' => __('Unused widgets have been Disabled successfully', 'wdesignkit'),
228 'success' => true,
229 );
230 wp_send_json($res);
231 wp_die();
232 }
233
234 $data = '';
235 break;
236 case 'shared_with_me':
237 $data = $this->wdkit_shared_with_me();
238 break;
239 case 'manage_workspace':
240 $data = $this->wdkit_manage_workspace();
241 break;
242 case 'widget_browse_page':
243 $data = apply_filters( 'wp_wdkit_widget_ajax', 'widget_browse_page' );
244 break;
245 case 'wkit_create_widget':
246 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_create_widget' );
247 break;
248 case 'wkit_import_widget':
249 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_import_widget' );
250 break;
251 case 'wkit_export_widget':
252 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_export_widget' );
253 break;
254 case 'wkit_delete_widget':
255 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_delete_widget' );
256 break;
257 case 'wkit_widget_preview':
258 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_widget_preview' );
259 break;
260 case 'wkit_manage_widget_workspace':
261 $data = $this->wdkit_manage_widget_workspace();
262 break;
263 case 'wkit_activate_key':
264 $data = $this->wdkit_activate_key();
265 break;
266 case 'wkit_manage_widget_category':
267 $data = $this->wdkit_manage_widget_category();
268 break;
269 case 'wkit_widget_json':
270 $data = $this->wkit_widget_json();
271 break;
272 case 'wkit_download_widget':
273 $data = $this->wdkit_download_widget();
274 break;
275 case 'wkit_public_download_widget':
276 $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_public_download_widget' );
277 break;
278 case 'wkit_add_widget':
279 $data = $this->wdkit_add_widget();
280 break;
281 case 'wkit_favourite_widget':
282 $data = $this->wdkit_favourite_widget();
283 break;
284 case 'wkit_setting_panel':
285 $data = $this->wdkit_setting_panel();
286 break;
287 case 'media_import':
288 $data = $this->wdkit_media_import();
289 break;
290 case 'active_licence':
291 $data = $this->wdkit_activate_licence();
292 break;
293 case 'delete_licence':
294 $data = $this->wdkit_delete_licence_key();
295 break;
296 case 'sync_licence':
297 $data = $this->wdkit_sync_licence_key();
298 break;
299 case 'get_wkit_version':
300 $data = $this->wdkit_prev_version();
301 break;
302 case 'rollback_wdkit':
303 $data = $this->wdkit_rollback_check();
304 break;
305 case 'wkit_logout':
306 $data = $this->wdkit_logout();
307 break;
308 case 'wkit_white_label':
309 $this->wkit_white_label();
310 break;
311 case 'wkit_reset_wl':
312 $response = $this->wkit_reset_wl();
313 break;
314 }
315
316 $this->wdkit_success_msg( $data );
317 // wp_die();
318 }
319
320 /**
321 *
322 * This Function is used for API call
323 *
324 * @since 1.0.0
325 *
326 * @param array $data give array.
327 * @param array $name store data.
328 */
329 protected function wkit_api_call( $data, $name ) {
330 $u_r_l = $this->wdkit_api;
331
332 if ( empty( $u_r_l ) ) {
333 return array(
334 'massage' => esc_html__( 'API Not Found', 'wdesignkit' ),
335 'success' => false,
336 );
337 }
338
339 $args = array(
340 'method' => 'POST',
341 'body' => $data,
342 'timeout' => 100,
343 );
344 $response = wp_remote_post( $u_r_l . $name, $args );
345
346 if ( is_wp_error( $response ) ) {
347 $error_message = $response->get_error_message();
348
349 /* Translators: %s is a placeholder for the error message */
350 $error_message = printf( esc_html__( 'API request error: %s', 'wdesignkit' ), esc_html( $error_message ) );
351
352 return array(
353 'massage' => $error_message,
354 'success' => false,
355 );
356 }
357
358 $status_code = wp_remote_retrieve_response_code( $response );
359 if ( 200 === $status_code ) {
360
361 return array(
362 'data' => json_decode( wp_remote_retrieve_body( $response ) ),
363 'massage' => esc_html__( 'Success', 'wdesignkit' ),
364 'status' => $status_code,
365 'success' => true,
366 );
367 }
368
369 $error_message = printf( 'Server error: %d', esc_html( $status_code ) );
370
371 if ( isset( $error_data->message ) ) {
372 $error_message .= ' (' . $error_data->message . ')';
373 }
374
375 return array(
376 'massage' => $error_message,
377 'status' => $status_code,
378 'success' => false,
379 );
380 }
381
382 /**
383 *
384 * It is Use for handle onboarding data.
385 *
386 * @since 1.0.9
387 */
388 public function wdkit_onboarding_handler() {
389 $page_template = isset( $_POST['page_template'] ) ? json_decode( wp_unslash( $_POST['page_template'] ), true ) : '';
390 $page_builder = isset( $_POST['page_builder'] ) ? json_decode( wp_unslash( $_POST['page_builder'] ), true ) : '';
391
392 $elementor_plugin = isset( $_POST['elementor_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['elementor_plugin'] ) ) : 0;
393 $tpag_plugin = isset( $_POST['tpag_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['tpag_plugin'] ) ) : 0;
394 $bricks_theme = isset( $_POST['bricks_theme'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['bricks_theme'] ) ) : 0;
395
396 $server_software = ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
397
398 $web_server = $server_software;
399 $memory_limit = ini_get( 'memory_limit' );
400 $max_execution_time = ini_get( 'max_execution_time' );
401 $php_version = phpversion();
402 $wp_version = get_bloginfo( 'version' );
403 $email = get_option( 'admin_email' );
404 $siteurl = get_option( 'siteurl' );
405 $language = get_bloginfo( 'language' );
406
407 // Active Plugin Name.
408 $act_plugin = array();
409 $actplu = get_option( 'active_plugins' );
410 if ( ! function_exists( 'get_plugins' ) ) {
411 require_once ABSPATH . 'wp-admin/includes/plugin.php';
412 }
413
414 $plugins = get_plugins();
415 foreach ( $actplu as $p ) {
416 if ( isset( $plugins[ $p ] ) ) {
417 $act_plugin[] = $plugins[ $p ]['Name'];
418 }
419 }
420
421 $plugin = wp_json_encode( $act_plugin );
422
423 $theme = '';
424 $acthemeobj = wp_get_theme();
425 if ( $acthemeobj->get( 'Name' ) !== null && ! empty( $acthemeobj->get( 'Name' ) ) ) {
426 $theme = $acthemeobj->get( 'Name' );
427 }
428
429 $basic_requirements = array(
430 'elementor_install' => $elementor_plugin,
431 'tpag_install' => $tpag_plugin,
432 'bricks_install' => $bricks_theme,
433 );
434
435 $final = array(
436 'web_server' => $web_server,
437 'memory_limit' => $memory_limit,
438 'max_execution_time' => $max_execution_time,
439 'php_version' => $php_version,
440 'wp_version' => $wp_version,
441 'email' => $email,
442 'site_url' => $siteurl,
443 'site_language' => $language,
444 'theme' => $theme,
445 'plugins' => $act_plugin,
446 'basic_requirements' => $basic_requirements,
447 'page_template' => $page_template,
448 'page_builder' => $page_builder,
449 );
450
451 $response = wp_remote_post(
452 $this->wdkit_onbording_api,
453 array(
454 'method' => 'POST',
455 'body' => wp_json_encode( $final ),
456 )
457 );
458
459 $existing_value = get_option( $this->wdkit_onbording_end );
460 if ( false === $existing_value ) {
461 add_option( $this->wdkit_onbording_end, true );
462 }
463
464 if ( is_wp_error( $response ) ) {
465 $result = array(
466 'success' => false,
467 'messages' => 'Oops',
468 'description' => 'Description',
469 );
470
471 wp_send_json( $result );
472 } else {
473 $status_one = wp_remote_retrieve_response_code( $response );
474
475 if ( 200 === $status_one ) {
476 $get_data_one = wp_remote_retrieve_body( $response );
477
478 $get_res = json_decode( json_decode( $get_data_one, true ), true );
479
480 $result = array(
481 'success' => ! empty( $get_res['success'] ) ? $get_res['success'] : false,
482 'messages' => ! empty( $get_res['messages'] ) ? $get_res['messages'] : 'success',
483 'description' => ! empty( $get_res['description'] ) ? $get_res['description'] : 'Description',
484 );
485
486 wp_send_json( $result );
487 } else {
488
489 $result = array(
490 'success' => false,
491 'messages' => 'Oops',
492 'description' => 'description',
493 );
494
495 wp_send_json( $result );
496 }
497 }
498
499 wp_die();
500 }
501
502 /**
503 *
504 * It is Use for get meta data for non login user
505 *
506 * @since 1.0.0\
507 */
508 protected function wdkit_meta_data() {
509 $type = isset( $_POST['meta_type'] ) ? sanitize_text_field( wp_unslash( $_POST['meta_type'] ) ) : '';
510 $data = array( 'type' => $type );
511
512 $response = $this->wkit_api_call( $data, 'meta' );
513 $success = ! empty( $response['success'] ) ? $response['success'] : false;
514 $status = ! empty( $response['status'] ) ? (int) $response['status'] : 400;
515
516 if ( empty( $success ) ) {
517 $result = array(
518 'plugin' => array(),
519 'builder' => array(),
520 'category' => array(),
521 'widgetscategory' => array(),
522 'tags' => array(),
523 'widgetbuilder' => array(),
524
525 'message' => esc_html__( 'Server Error', 'wdesignkit' ),
526 'description' => esc_html__( 'Server Error, Data Not Found', 'wdesignkit' ),
527 'success' => false,
528 );
529
530 wp_send_json( $result );
531 wp_die();
532 }
533
534 $get_data_one = ! empty( $response['data'] ) ? $response['data'] : array();
535 $statuscode = array( 'HTTP_CODE' => $status );
536
537 $final = json_decode( wp_json_encode( $get_data_one ), true );
538
539 $final['Setting'] = self::wkit_get_settings_panel();
540 $final['widget_list'] = $this->wkit_manage_widget_sequence( array() );
541
542 $final = array(
543 'data' => $final,
544 );
545
546 wp_send_json( $final );
547 wp_die();
548 }
549
550 /**
551 *
552 * It is Use for get activate license key data from tpae and nexter blocks.
553 *
554 * @since 1.1.6
555 */
556 protected function wkit_manage_license_data() {
557 $manage_licence = array();
558 $theplus_active_check = is_plugin_active('the-plus-addons-for-elementor-page-builder/theplus_elementor_addon.php');
559 $nexter_active_check = is_plugin_active('the-plus-addons-for-block-editor/the-plus-addons-for-block-editor.php');
560
561 $theplus_licence = get_option('tpaep_licence_data', []);
562
563 if ( ! empty( $theplus_active_check ) &&! empty( $theplus_licence ) ) {
564 $manage_licence['tpae'] = $theplus_licence;
565 }
566
567 $nexter_licence = get_option('tpgb_activate', []);
568
569 if ( ! empty( $nexter_active_check ) && ! empty( $nexter_licence ) && !empty( $nexter_licence['tpgb_activate_key'] ) ) {
570 $tpgb_license_status = get_option('tpgbp_license_status', []);
571 $tpgb_license_status['license_key'] = $nexter_licence['tpgb_activate_key'];
572 $manage_licence['tpag'] = $tpgb_license_status;
573 }
574
575 return $manage_licence;
576 }
577
578 /**
579 *
580 * It is Use for get all info of user.
581 *
582 * @since 1.0.0
583 */
584 protected function wdkit_get_user_info() {
585 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
586 $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['builder'] ) ) ) : '';
587
588 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
589
590 $response = array();
591
592 if ( empty( $email ) ) {
593 $response = array(
594 'success' => false,
595 'message' => $this->e_msg_login,
596 'description' => $this->e_desc_login,
597 );
598
599 wp_send_json( $response );
600 wp_die();
601 }
602
603 $token = $this->wdkit_login_user_token( $email );
604 $args = array(
605 'token' => $token,
606 'builder' => $builder,
607 'site_url' => $site_url,
608 );
609
610 $response = WDesignKit_Data_Query::get_data( 'get_user_info', $args );
611 $status = ( ! empty( $response['status'] ) ) ? sanitize_text_field( $response['status'] ) : 'error';
612 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
613
614 /**Condtion user for user logout & expire token*/
615 if ( 'Token is Expired' === $status || 'Authorization Token not found' === $status ) {
616 delete_transient( 'wdkit_auth_' . $email );
617 }
618
619 $response['Setting'] = $this->wkit_get_settings_panel();
620 $response['widget_list'] = $this->wkit_manage_widget_sequence( $response );
621 $response['manage_licence'] = $this->wkit_manage_license_data();
622
623 $response = array(
624 'data' => $response,
625 'success' => true,
626 );
627
628 wp_send_json( $response );
629 wp_die();
630 }
631
632 /**
633 *
634 * It is Use for get all widgets local and server.
635 *
636 * @since 1.0.19
637 * @param string $response userinfo store.
638 */
639 protected function wkit_manage_widget_sequence( $response = array() ) {
640
641 $credits = ! empty( $response['credits']['widget_limit']['meta_value'] ) ? $response['credits']['widget_limit']['meta_value'] : 10;
642 $server_list = ! empty( $response['widgettemplate'] ) ? $response['widgettemplate'] : array();
643 $db_builder_list = ! empty( $response['widgetbuilder'] ) ? $response['widgetbuilder'] : array();
644
645 $placeholderimg = WDKIT_URL . 'assets/images/placeholder.jpg';
646
647 $local_list = $this->wdkit_get_local_widgets();
648
649 $server_w_unique = array_column( $server_list, 'w_unique' );
650
651 $idx_builder = array();
652 foreach ( $db_builder_list as $index => $value ) {
653 $builder_name = ! empty( $value['builder_name'] ) ? $value['builder_name'] : '';
654 $w_id = ! empty( $value['w_id'] ) ? $value['w_id'] : '';
655
656 if ( ! empty( $builder_name ) ) {
657 $idx_builder[ $w_id ] = strtolower( $builder_name );
658 }
659 }
660
661 foreach ( $server_list as $index => $value ) {
662 $get_id = $server_list[ $index ]['builder'] ? $server_list[ $index ]['builder'] : '';
663
664 $server_list[ $index ]['type'] = 'server';
665 $server_list[ $index ]['builder'] = ! empty( $idx_builder[ $get_id ] ) ? $idx_builder[ $get_id ] : '';
666 }
667
668 $count = 0;
669
670 foreach ( $local_list as $key => $value ) {
671 $widget_id = ! empty( $value['widgetdata']['widget_id'] ) ? $value['widgetdata']['widget_id'] : '';
672 $allow_push = isset( $value['widgetdata']['allow_push'] ) ? $value['widgetdata']['allow_push'] : true;
673
674 if ( in_array( $widget_id, $server_w_unique ) ) {
675
676 $index = array_search( $widget_id, $server_w_unique );
677
678 $server_list[ $index ]['title'] = $local_list[ $key ]['widgetdata']['name'];
679 $server_list[ $index ]['w_version'] = $local_list[ $key ]['widgetdata']['widget_version'];
680 $server_list[ $index ]['allow_push'] = $allow_push;
681 $server_list[ $index ]['builder'] = $local_list[ $key ]['widgetdata']['type'];
682 $server_list[ $index ]['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id'];
683 $server_list[ $index ]['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg;
684
685 $local_list[ $key ] = $server_list[ $index ];
686
687 $local_list[ $key ]['type'] = 'done';
688
689 unset( $server_list[ $index ] );
690 } else {
691 $local_list[ $key ]['widgetdata']['builder'] = $local_list[ $key ]['widgetdata']['type'];
692 $local_list[ $key ]['widgetdata']['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id'];
693 $local_list[ $key ]['widgetdata']['allow_push'] = $allow_push;
694 $local_list[ $key ]['widgetdata']['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg;
695 $local_list[ $key ]['widgetdata']['is_activated'] = 'active';
696
697 $local_list[ $key ]['widgetdata']['type'] = 'plugin';
698
699 $local_list[ $key ]['widgetdata']['title'] = $local_list[ $key ]['widgetdata']['name'];
700 unset( $local_list[ $key ]['widgetdata']['name'] );
701 unset( $local_list[ $key ]['widgetdata']['widget_id'] );
702
703 $local_list[ $key ] = $local_list[ $key ]['widgetdata'];
704 }
705 }
706
707 $final = array_merge( $local_list, $server_list );
708
709 $db_widget = array();
710
711 foreach ( $final as $key => $self ) {
712 $is_activated = ! empty( $final[ $key ]['is_activated'] ) ? $final[ $key ]['is_activated'] : 'active';
713
714 if ( 'active' === $is_activated ) {
715 ++$count;
716 }
717
718 if ( ( $count > $credits ) && ( 'unlimited' !== $credits ) ) {
719 $final[ $key ]['is_activated'] = 'deactive';
720 }
721
722 if ( ! empty( $self['is_activated'] ) && 'active' !== $self['is_activated'] ) {
723 $db_widget[] = array(
724 'w_unique' => $self['w_unique'],
725 'builder' => $self['builder'],
726 'title' => $self['title'],
727 'is_activated' => $self['is_activated'],
728 );
729 }
730 }
731
732 $get_db_widget = get_option( 'wkit_deactivate_widgets', array() );
733 if ( empty( $get_db_widget ) ) {
734 add_option( 'wkit_deactivate_widgets', $db_widget, '', 'yes' );
735 } else {
736 update_option( 'wkit_deactivate_widgets', $db_widget );
737 }
738
739 return $final;
740 }
741
742 /**
743 * Browse Page Filter
744 *
745 * @since 1.0.0
746 */
747 protected function wdkit_browse_page() {
748 $args = $this->wdkit_parse_args( $_POST );
749
750 $response = WDesignKit_Data_Query::get_data( 'browse_page', $args );
751
752 wp_send_json( $response );
753 wp_die();
754 }
755
756 /**
757 *
758 * It is Use for get template from kit.
759 *
760 * @since 1.0.0
761 */
762 protected function wdkit_template() {
763 $args = $this->wdkit_parse_args( $_POST );
764
765 $response = WDesignKit_Data_Query::get_data( 'kit_template', $args );
766
767 wp_send_json( $response );
768 wp_die();
769 }
770
771 /**
772 *
773 * It is Use for remove or delete template.
774 *
775 * @since 1.0.0
776 */
777 protected function wdkit_template_remove() {
778 $args = $this->wdkit_parse_args( $_POST );
779
780 $user_email = strtolower( sanitize_email( $args['email'] ) );
781 $response = '';
782
783 if ( empty( $user_email ) || empty( $args['template_id'] ) ) {
784 $response = response()->json(
785 array(
786 'message' => $this->e_msg_login,
787 'description' => $this->e_desc_login,
788 'success' => true,
789 )
790 );
791
792 wp_send_json( $response );
793 wp_die();
794 }
795
796 $args['token'] = $this->wdkit_login_user_token( $user_email );
797
798 unset( $user_email );
799 $response = WDesignKit_Data_Query::get_data( 'template_remove', $args );
800
801 wp_send_json( $response );
802 wp_die();
803 }
804
805 /**
806 *
807 * It is Use for save template from page builder.
808 *
809 * @since 1.0.0
810 */
811 protected function wdkit_put_save_template() {
812 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
813 $post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '';
814
815 $response = '';
816
817 if ( empty( $email ) ) {
818 $response = array(
819 'id' => 0,
820 'editpage' => '',
821 'message' => $this->e_msg_login,
822 'description' => $this->e_desc_login,
823 'success' => false,
824 );
825
826 wp_send_json( $response );
827 wp_die();
828 }
829
830 $args = $this->wdkit_parse_args( $_POST );
831 $args['token'] = $this->wdkit_login_user_token( $email );
832 unset( $args['email'] );
833
834 global $post;
835
836 $custom_fields = array();
837 if ( ! empty( $post_id ) ) {
838 $meta_fields = get_post_custom( $post_id );
839
840 foreach ( $meta_fields as $key => $value ) {
841 if ( str_contains( $key, 'nxt-' ) ) {
842 $custom_fields[ $key ] = $value;
843 }
844 }
845
846 if ( ! empty( $custom_fields ) ) {
847 $data = json_decode( $args['data'], true );
848 $data['custom_meta'] = $custom_fields;
849 $args['data'] = wp_json_encode( $data );
850 }
851 }
852
853 $response = WDesignKit_Data_Query::get_data( 'save_template', $args );
854
855 wp_send_json( $response );
856 wp_die();
857 }
858
859 /**
860 *
861 * Get Elementor Global color and Typography.
862 *
863 * @since 1.1.16
864 */
865 protected function wdkit_get_global_val() {
866
867 $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( $_POST['builder'] ) ) : '';
868
869 if( 'elementor' === $builder ){
870 $kit_id = get_option('elementor_active_kit');
871 if ( empty($kit_id) ) {
872 $response = array(
873 'message' => __('Elementor kit not found', 'wdesignkit'),
874 'description' => __('No active Elementor kit found', 'wdesignkit'),
875 'success' => false,
876 );
877
878 wp_send_json( $response );
879 wp_die();
880 }
881
882 $kit_meta = get_post_meta($kit_id, '_elementor_page_settings', true);
883 if ( empty($kit_meta['system_colors']) ) {
884 $static_meta = array (
885 'system_colors' => array (
886 0 => array ( '_id' => 'primary', 'title' => 'Primary', 'color' => '#6EC1E4' ),
887 1 => array ( '_id' => 'secondary', 'title' => 'Secondary', 'color' => '#54595F' ),
888 2 => array ( '_id' => 'text', 'title' => 'Text', 'color' => '#7A7A7A' ),
889 3 => array ( '_id' => 'accent', 'title' => 'Accent', 'color' => '#61CE70' ),
890 ),
891 'custom_colors' => array (),
892 'system_typography' => array (
893 0 => array ( '_id' => 'primary', 'title' => 'Primary', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto', 'typography_font_weight' => '600' ),
894 1 => array ( '_id' => 'secondary', 'title' => 'Secondary', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto Slab', 'typography_font_weight' => '400' ),
895 2 => array ( '_id' => 'text', 'title' => 'Text', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto', 'typography_font_weight' => '400' ),
896 3 => array ( '_id' => 'accent', 'title' => 'Accent', 'typography_typography' => 'custom', 'typography_font_family' => 'Roboto', 'typography_font_weight' => '500' ),
897 ),
898 'custom_typography' => array (),
899 'default_generic_fonts' => 'Sans-serif',
900 'site_name' => !empty(get_bloginfo('name')) ? get_bloginfo('name') : '',
901 'page_title_selector' => 'h1.entry-title',
902 'activeItemIndex' => 1,
903 'viewport_md' => 768,
904 'viewport_lg' => 1025,
905 );
906
907 $kit_meta = $static_meta;
908 update_post_meta($kit_id, '_elementor_page_settings', $kit_meta);
909 }
910
911 $system_colors = !empty($kit_meta['system_colors']) ? $kit_meta['system_colors'] : [];
912 $custom_colors = !empty($kit_meta['custom_colors']) ? $kit_meta['custom_colors'] : [];
913 $system_typography = !empty($kit_meta['system_typography']) ? $kit_meta['system_typography'] : [];
914 $custom_typography = !empty($kit_meta['custom_typography']) ? $kit_meta['custom_typography'] : [];
915
916 $color_array = array_merge($system_colors, $custom_colors);
917 $typo_array = array_merge($system_typography, $custom_typography);
918
919 $global_data = array(
920 'color' => $color_array,
921 'typography' => $typo_array
922 );
923
924 $response = array(
925 'message' => __('Global data Found', 'wdesignkit'),
926 'description' => __('Global Color and Typography found', 'wdesignkit'),
927 'data' => $global_data,
928 'success' => true,
929 );
930
931 } else if ( 'gutenberg' === $builder ){
932
933 $plus_settings = get_option('tpgb_global_options', false);
934 $plus_settings = !empty($plus_settings) ? json_decode($plus_settings, true) : json_decode('[]');
935
936 if( empty($plus_settings) ){
937
938 $static_meta = array(
939 'active' => 'preset1',
940 'darkMode' => 'none',
941 'presets' => array(
942 'preset1' => array(
943 'name' => 'Preset 1',
944 'key' => 'preset1',
945 'colors' => array(
946 array(
947 'label' => 'Primary',
948 'value' => '#8072FC',
949 ),
950 array(
951 'label' => 'Secondary',
952 'value' => '#6FC784',
953 ),
954 array(
955 'label' => 'Tertiary',
956 'value' => '#FF5A6E',
957 ),
958 array(
959 'label' => 'Accent',
960 'value' => '#F3F3F3',
961 ),
962 array(
963 'label' => 'Background',
964 'value' => '#888888',
965 ),
966 ),
967 'gradient' => array(
968 array(
969 'label' => 'Primary',
970 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
971 ),
972
973 array(
974 'label' => 'Secondary',
975 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
976 ),
977
978 array(
979 'label' => 'Tertiary',
980 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
981 ),
982
983 array(
984 'label' => 'Accent',
985 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
986 ),
987
988 array(
989 'label' => 'Background',
990 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
991 ),
992 ),
993 'spacing' => array(
994 array(
995 'label' => 'Large',
996 'value' => array(
997 'md' => 70,
998 'unit' => 'px',
999 )
1000 ),
1001 array(
1002 'label' => 'Medium',
1003 'value' => array(
1004 'md' => 40,
1005 'unit' => 'px',
1006 )
1007 ),
1008 array(
1009 'label' => 'Small',
1010 'value' => array(
1011 'md' => 20,
1012 'unit' => 'px',
1013 )
1014
1015 )
1016 ),
1017 'typography' => array(
1018 array(
1019 'label' => 'Display Text',
1020 'value' => array(
1021 'openTypography' => 1,
1022 'size' => array(
1023 'md' => 65,
1024 'unit' => 'px'
1025 ),
1026 'height' => array(
1027 'md' => 75,
1028 'unit' => 'px',
1029 ),
1030 'fontFamily' => array(
1031 'family' => 'Roboto',
1032 'type' => 'sans-serif',
1033 'fontWeight' => 700,
1034 ),
1035 'spacing' => array(
1036 'md' => 0,
1037 'unit' => 'px',
1038 ),
1039 ),
1040 ),
1041 array(
1042 'label' => 'Headline',
1043 'value' => array(
1044 'openTypography' => 1,
1045 'size' => array(
1046 'md' => 45,
1047 'unit' => 'px',
1048 ),
1049 'height' => array(
1050 'md' => 60,
1051 'unit' => 'px',
1052 ),
1053 'fontFamily' => array(
1054 'family' => 'Roboto',
1055 'type' => 'sans-serif',
1056 'fontWeight' => 700,
1057 ),
1058 'spacing' => array(
1059 'md' => 0,
1060 'unit' => 'px',
1061 ),
1062 )
1063 ),
1064 array(
1065 'label' => 'Sub Headline',
1066 'value' => array(
1067 'openTypography' => 1,
1068 'size' => array(
1069 'md' => 38,
1070 'unit' => 'px',
1071 ),
1072 'height' => array(
1073 'md' => 45,
1074 'unit' => 'px',
1075 ),
1076 'fontFamily' => array(
1077 'family' => 'Roboto',
1078 'type' => 'sans-serif',
1079 'fontWeight' => 500,
1080 ),
1081 'spacing' => array(
1082 'md' => 0,
1083 'unit' => 'px',
1084 ),
1085 )
1086 ),
1087 array(
1088 'label' => 'Title 1',
1089 'value' => array(
1090 'openTypography' => 1,
1091 'size' => array(
1092 'md' => 30,
1093 'unit' => 'px',
1094 ),
1095 'height' => array(
1096 'md' => 40,
1097 'unit' => 'px',
1098 ),
1099 'fontFamily' => array(
1100 'family' => 'Roboto',
1101 'type' => 'sans-serif',
1102 'fontWeight' => 500,
1103 ),
1104 'spacing' => array(
1105 'md' => 0,
1106 'unit' => 'px',
1107 ),
1108 )
1109 ),
1110 array(
1111 'label' => 'Title 2',
1112 'value' => array(
1113 'openTypography' => 1,
1114 'size' => array(
1115 'md' => 25,
1116 'unit' => 'px',
1117 ),
1118 'height' => array(
1119 'md' => 30,
1120 'unit' => 'px',
1121 ),
1122 'fontFamily' => array(
1123 'family' => 'Roboto',
1124 'type' => 'sans-serif',
1125 'fontWeight' => 400,
1126 ),
1127 'spacing' => array(
1128 'md' => 0,
1129 'unit' => 'px',
1130 ),
1131 )
1132 ),
1133 array(
1134 'label' => 'Body',
1135 'value' => array(
1136 'openTypography' => 1,
1137 'size' => array(
1138 'md' => 17,
1139 'unit' => 'px',
1140 ),
1141 'height' => array(
1142 'md' => 22,
1143 'unit' => 'px',
1144 ),
1145 'fontFamily' => array(
1146 'family' => 'Roboto',
1147 'type' => 'sans-serif',
1148 'fontWeight' => 400,
1149 ),
1150 'spacing' => array(
1151 'md' => 0,
1152 'unit' => 'px',
1153 ),
1154 )
1155 ),
1156 array(
1157 'label' => 'Captions',
1158 'value' => array(
1159 'openTypography' => 1,
1160 'size' => array(
1161 'md' => 13,
1162 'unit' => 'px',
1163 ),
1164 'height' => array(
1165 'md' => 16,
1166 'unit' => 'px',
1167 ),
1168 'fontFamily' => array(
1169 'family' => 'Roboto',
1170 'type' => 'sans-serif',
1171 'fontWeight' => 400,
1172 ),
1173 'spacing' => array(
1174 'md' => 0,
1175 'unit' => 'px',
1176 ),
1177 )
1178 )
1179 ),
1180 'boxshadow' => array(
1181 array(
1182 'label' => 'Normal Shadow',
1183 'value' => array(
1184 'openShadow' => 1,
1185 'inset' => 0,
1186 'horizontal' => 2,
1187 'vertical' => 6,
1188 'blur' => 10,
1189 'spread' => 0,
1190 'color' => 'rgba(0,0,0,0.15)',
1191 )
1192 ),
1193 array(
1194 'label' => 'Hover Shadow',
1195 'value' => array(
1196 'openShadow' => 1,
1197 'inset' => 0,
1198 'horizontal' => 2,
1199 'vertical' => 5,
1200 'blur' => 14,
1201 'spread' => 3,
1202 'color' => 'rgba(0,0,0,0.2)',
1203 )
1204 ),
1205 )
1206 ),
1207 'preset2' => array(
1208 'name' => 'Preset 2',
1209 'key' => 'preset2',
1210 'colors' => array(
1211 array(
1212 'label' => 'Primary',
1213 'value' => '#8072FC',
1214 ),
1215 array(
1216 'label' => 'Secondary',
1217 'value' => '#6FC784',
1218 ),
1219 array(
1220 'label' => 'Tertiary',
1221 'value' => '#FF5A6E',
1222 ),
1223 array(
1224 'label' => 'Accent',
1225 'value' => '#F3F3F3',
1226 ),
1227 array(
1228 'label' => 'Background',
1229 'value' => '#888888',
1230 ),
1231 ),
1232 'gradient' => array(
1233 array(
1234 'label' => 'Primary',
1235 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1236 ),
1237
1238 array(
1239 'label' => 'Secondary',
1240 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1241 ),
1242
1243 array(
1244 'label' => 'Tertiary',
1245 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1246 ),
1247
1248 array(
1249 'label' => 'Accent',
1250 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1251 ),
1252
1253 array(
1254 'label' => 'Background',
1255 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1256 ),
1257 ),
1258 'spacing' => array(
1259 array(
1260 'label' => 'Large',
1261 'value' => array(
1262 'md' => 70,
1263 'unit' => 'px',
1264 )
1265 ),
1266 array(
1267 'label' => 'Medium',
1268 'value' => array(
1269 'md' => 40,
1270 'unit' => 'px',
1271 )
1272 ),
1273 array(
1274 'label' => 'Small',
1275 'value' => array(
1276 'md' => 20,
1277 'unit' => 'px',
1278 )
1279
1280 )
1281 ),
1282 'typography' => array(
1283 array(
1284 'label' => 'Display Text',
1285 'value' => array(
1286 'openTypography' => 1,
1287 'size' => array(
1288 'md' => 65,
1289 'unit' => 'px'
1290 ),
1291 'height' => array(
1292 'md' => 75,
1293 'unit' => 'px',
1294 ),
1295 'fontFamily' => array(
1296 'family' => 'Roboto',
1297 'type' => 'sans-serif',
1298 'fontWeight' => 700,
1299 ),
1300 'spacing' => array(
1301 'md' => 0,
1302 'unit' => 'px',
1303 ),
1304 ),
1305 ),
1306 array(
1307 'label' => 'Headline',
1308 'value' => array(
1309 'openTypography' => 1,
1310 'size' => array(
1311 'md' => 45,
1312 'unit' => 'px',
1313 ),
1314 'height' => array(
1315 'md' => 60,
1316 'unit' => 'px',
1317 ),
1318 'fontFamily' => array(
1319 'family' => 'Roboto',
1320 'type' => 'sans-serif',
1321 'fontWeight' => 700,
1322 ),
1323 'spacing' => array(
1324 'md' => 0,
1325 'unit' => 'px',
1326 ),
1327 )
1328 ),
1329 array(
1330 'label' => 'Sub Headline',
1331 'value' => array(
1332 'openTypography' => 1,
1333 'size' => array(
1334 'md' => 38,
1335 'unit' => 'px',
1336 ),
1337 'height' => array(
1338 'md' => 45,
1339 'unit' => 'px',
1340 ),
1341 'fontFamily' => array(
1342 'family' => 'Roboto',
1343 'type' => 'sans-serif',
1344 'fontWeight' => 500,
1345 ),
1346 'spacing' => array(
1347 'md' => 0,
1348 'unit' => 'px',
1349 ),
1350 )
1351 ),
1352 array(
1353 'label' => 'Title 1',
1354 'value' => array(
1355 'openTypography' => 1,
1356 'size' => array(
1357 'md' => 30,
1358 'unit' => 'px',
1359 ),
1360 'height' => array(
1361 'md' => 40,
1362 'unit' => 'px',
1363 ),
1364 'fontFamily' => array(
1365 'family' => 'Roboto',
1366 'type' => 'sans-serif',
1367 'fontWeight' => 500,
1368 ),
1369 'spacing' => array(
1370 'md' => 0,
1371 'unit' => 'px',
1372 ),
1373 )
1374 ),
1375 array(
1376 'label' => 'Title 2',
1377 'value' => array(
1378 'openTypography' => 1,
1379 'size' => array(
1380 'md' => 25,
1381 'unit' => 'px',
1382 ),
1383 'height' => array(
1384 'md' => 30,
1385 'unit' => 'px',
1386 ),
1387 'fontFamily' => array(
1388 'family' => 'Roboto',
1389 'type' => 'sans-serif',
1390 'fontWeight' => 400,
1391 ),
1392 'spacing' => array(
1393 'md' => 0,
1394 'unit' => 'px',
1395 ),
1396 )
1397 ),
1398 array(
1399 'label' => 'Body',
1400 'value' => array(
1401 'openTypography' => 1,
1402 'size' => array(
1403 'md' => 17,
1404 'unit' => 'px',
1405 ),
1406 'height' => array(
1407 'md' => 22,
1408 'unit' => 'px',
1409 ),
1410 'fontFamily' => array(
1411 'family' => 'Roboto',
1412 'type' => 'sans-serif',
1413 'fontWeight' => 400,
1414 ),
1415 'spacing' => array(
1416 'md' => 0,
1417 'unit' => 'px',
1418 ),
1419 )
1420 ),
1421 array(
1422 'label' => 'Captions',
1423 'value' => array(
1424 'openTypography' => 1,
1425 'size' => array(
1426 'md' => 13,
1427 'unit' => 'px',
1428 ),
1429 'height' => array(
1430 'md' => 16,
1431 'unit' => 'px',
1432 ),
1433 'fontFamily' => array(
1434 'family' => 'Roboto',
1435 'type' => 'sans-serif',
1436 'fontWeight' => 400,
1437 ),
1438 'spacing' => array(
1439 'md' => 0,
1440 'unit' => 'px',
1441 ),
1442 )
1443 )
1444 ),
1445 'boxshadow' => array(
1446 array(
1447 'label' => 'Normal Shadow',
1448 'value' => array(
1449 'openShadow' => 1,
1450 'inset' => 0,
1451 'horizontal' => 2,
1452 'vertical' => 6,
1453 'blur' => 10,
1454 'spread' => 0,
1455 'color' => 'rgba(0,0,0,0.15)',
1456 )
1457 ),
1458 array(
1459 'label' => 'Hover Shadow',
1460 'value' => array(
1461 'openShadow' => 1,
1462 'inset' => 0,
1463 'horizontal' => 2,
1464 'vertical' => 5,
1465 'blur' => 14,
1466 'spread' => 3,
1467 'color' => 'rgba(0,0,0,0.2)',
1468 )
1469 ),
1470 )
1471 ),
1472 ),
1473 'globalContainer' => array(
1474 'md' => '',
1475 'unit' => 'px',
1476 )
1477 );
1478
1479 update_option('tpgb_global_options', json_encode($static_meta));
1480 $plus_settings = $static_meta;
1481 }
1482
1483 $active_id = !empty( $plus_settings['active'] ) ? $plus_settings['active'] : '';
1484 $preset_array = !empty( $plus_settings['presets'] ) ? $plus_settings['presets'] : array();
1485 $act_preset = !empty( $plus_settings['presets'][$active_id] ) ? $plus_settings['presets'][$active_id] : array();
1486
1487 $response = array(
1488 'message' => __('Global data Found', 'wdesignkit'),
1489 'description' => __('Global Color and Typography found', 'wdesignkit'),
1490 'data' => $act_preset,
1491 'success' => true,
1492 );
1493 }
1494
1495 wp_send_json( $response );
1496 wp_die();
1497 }
1498
1499 /**
1500 *
1501 * Update Elementor Global color and Typography.
1502 *
1503 * @since 1.1.20
1504 */
1505 protected function wdkit_update_global_val() {
1506
1507 $builder = ! empty( $_POST['builder'] ) ? sanitize_text_field( $_POST['builder'] ) : '';
1508
1509 if( 'elementor' == $builder ){
1510
1511 $g_color = ! empty( $_POST['g_color'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_color'] ) ), true ) : array();
1512 $g_typo = ! empty( $_POST['g_typography'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_typography'] ) ), true ) : array();
1513
1514 // Get colors from Elementor Site Kit
1515 $kit_id = get_option('elementor_active_kit');
1516 if (!$kit_id) {
1517 $response = array(
1518 'message' => __('Elementor kit not found', 'wdesignkit'),
1519 'description' => __('No active Elementor kit found', 'wdesignkit'),
1520 'success' => false,
1521 );
1522
1523 wp_send_json( $response );
1524 wp_die();
1525 }
1526
1527 $kit_meta = get_post_meta($kit_id, '_elementor_page_settings', true);
1528 if ( empty($kit_meta) ) {
1529 $response = array(
1530 'message' => __('Data Not Found', 'wdesignkit'),
1531 'description' => __('No meta data found in kit', 'wdesignkit'),
1532 'success' => false,
1533 );
1534
1535 wp_send_json( $response );
1536 wp_die();
1537 }
1538
1539 $kit_meta['custom_colors'] = array_merge($g_color, $kit_meta['custom_colors']);
1540 $kit_meta['custom_typography'] = array_merge($g_typo, $kit_meta['custom_typography']);
1541
1542 update_post_meta($kit_id, '_elementor_page_settings', $kit_meta);
1543
1544 $response = array(
1545 'message' => __('Global data Updated', 'wdesignkit'),
1546 'description' => __('Global Color and Typography Updated', 'wdesignkit'),
1547 'success' => true,
1548 );
1549
1550 } else if( 'gutenberg' == $builder ){
1551 $new_preset = ! empty( $_POST['new_preset'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['new_preset'] ) ), true ) : array();
1552 $new_preset_id = ! empty( $new_preset['key'] ) ? $new_preset['key'] : '';
1553 $plus_settings = get_option('tpgb_global_options');
1554 $site_preset = json_decode($plus_settings, true);
1555
1556 $site_preset['presets'][$new_preset_id] = $new_preset;
1557 $site_preset['active'] = $new_preset_id;
1558
1559 update_option( 'tpgb_global_options', json_encode($site_preset) );
1560
1561 $response = array(
1562 'message' => __('Global data Updated', 'wdesignkit'),
1563 'description' => __('Global Color and Typography Updated', 'wdesignkit'),
1564 'success' => true,
1565 );
1566
1567 } else {
1568 $response = array(
1569 'message' => __('Builder Not Found !', 'wdesignkit'),
1570 'description' => __('Template Builder not Found', 'wdesignkit'),
1571 'success' => true,
1572 );
1573 }
1574
1575 wp_send_json( $response );
1576 wp_die();
1577 }
1578
1579 /**
1580 *
1581 * Create Gutenberg page and save for re-generate css file.
1582 *
1583 * @since 1.2.3
1584 */
1585 protected function wdkit_update_preset() {
1586
1587 $act_type = ! empty( $_POST['act_type'] ) ? sanitize_text_field( $_POST['act_type'] ) : '';
1588 $post_id = ! empty( $_POST['post_id'] ) ? sanitize_text_field( $_POST['post_id'] ) : '';
1589
1590 if( 'create' == $act_type ){
1591
1592 $page_id = wp_insert_post([
1593 'post_title' => 'WDesignKit Gutenberg',
1594 'post_status' => 'publish',
1595 'post_type' => 'post',
1596 'post_name' => sanitize_title('wdesignkit'),
1597 'post_content' => '<!-- wp:heading --><h2 class="wp-block-heading">Add Your Heading Text Here<h2><!-- /wp:heading -->',
1598 'meta_input' => [
1599 'gutenberg_preview' => true,
1600 '_wp_page_template' => 'default',
1601 ],
1602 ]);
1603
1604 if ( is_wp_error($page_id) || !$page_id ) {
1605 $response = array(
1606 'success' => true,
1607 'message' => esc_html__( 'Page Not Found!', 'wdesignkit' ),
1608 'description' => esc_html__( 'Page Not Found!', 'wdesignkit' ),
1609 );
1610
1611 wp_send_json($response);
1612 wp_die();
1613 }
1614
1615 update_post_meta($page_id, '_edit_lock', time() . ':1');
1616 update_post_meta($page_id, '_edit_last', get_current_user_id());
1617
1618 $preview_url = admin_url('post.php?post=' . $page_id . '&action=edit');
1619
1620 $response = array(
1621 'success' => true,
1622 'post_id' => $page_id,
1623 'preview_url' => $preview_url,
1624 'message' => esc_html__( 'Page Created', 'wdesignkit' ),
1625 'description' => esc_html__( 'Page Created', 'wdesignkit' ),
1626 );
1627
1628 wp_send_json($response);
1629 wp_die();
1630
1631 }
1632
1633 if ( !empty($post_id) && ( $act_type == 'remove' ) ){
1634
1635 wp_delete_post($post_id, true);
1636
1637 $response = array(
1638 'success' => true,
1639 'message' => esc_html__( 'post deleted', 'wdesignkit' ),
1640 'description' => esc_html__( 'post deleted', 'wdesignkit' ),
1641 );
1642
1643 wp_send_json($response);
1644 wp_die();
1645 }
1646 }
1647
1648 /**
1649 *
1650 * It is For Find User Existing template List.
1651 *
1652 * @since 1.0.6
1653 */
1654 protected function wdkit_find_existing_template() {
1655 $array_data = array(
1656 'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '',
1657 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
1658 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
1659 'u_id' => isset( $_POST['u_id'] ) ? sanitize_text_field( wp_unslash( $_POST['u_id'] ) ) : '',
1660 'builder' => isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '',
1661 'parpage' => isset( $_POST['parpage'] ) ? sanitize_text_field( wp_unslash( $_POST['parpage'] ) ) : 12,
1662 );
1663
1664 $response = $this->wkit_api_call( $array_data, 'existing_template' );
1665
1666 wp_send_json( $response );
1667 wp_die();
1668 }
1669
1670 /**
1671 *
1672 * It is For Update User Existing template List.
1673 *
1674 * @since 1.0.6
1675 */
1676 protected function wdkit_update_template() {
1677 $array_data = array(
1678 'data' => isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '',
1679 'post_id' => isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '',
1680 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
1681 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
1682 'id' => isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '',
1683 'global_data' => isset( $_POST['global_data'] ) ? wp_unslash( $_POST['global_data'] ) : array(),
1684 // 'global_font_family' => isset( $_POST['global_font_family'] ) ? wp_unslash( $_POST['global_font_family'] ) : array(),
1685 // 'global_color' => isset( $_POST['global_color'] ) ? wp_unslash( $_POST['global_color'] ) : array(),
1686 );
1687
1688 if ( ! empty( $array_data['post_id'] ) ) {
1689 $custom_fields = array();
1690 $post_id = $array_data['post_id'];
1691
1692 $meta_fields = get_post_custom( $post_id );
1693
1694 foreach ( $meta_fields as $key => $value ) {
1695 if ( str_contains( $key, 'nxt-' ) ) {
1696 $custom_fields[ $key ] = $value;
1697 }
1698 }
1699
1700 if ( ! empty( $custom_fields ) ) {
1701 $data = json_decode( $array_data['data'], true );
1702 $data['custom_meta'] = $custom_fields;
1703 $array_data['data'] = wp_json_encode( $data );
1704 }
1705 }
1706
1707 $response = $this->wkit_api_call( $array_data, 'existing_template' );
1708
1709 wp_send_json( $response );
1710 wp_die();
1711 }
1712
1713 /**
1714 *
1715 * It is Use for manage favourite template.
1716 *
1717 * @since 1.0.0
1718 */
1719 protected function wdkit_manage_favorite() {
1720 $template_id = isset( $_POST['template_id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['template_id'] ) ) ) : 0;
1721 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
1722
1723 if ( empty( $email ) || empty( $template_id ) ) {
1724 $response = array(
1725 'message' => $this->e_msg_login,
1726 'description' => $this->e_desc_login,
1727 'success' => false,
1728 );
1729
1730 wp_send_json( $response );
1731 wp_die();
1732 }
1733
1734 $args = $this->wdkit_parse_args( $_POST );
1735 $args['token'] = $this->wdkit_login_user_token( $email );
1736
1737 unset( $args['email'] );
1738 $response = WDesignKit_Data_Query::get_data( 'manage_favorite', $args );
1739
1740 wp_send_json( $response );
1741 wp_die();
1742 }
1743
1744 /**
1745 *
1746 * It is Use for Check Plugin Dependency of template.
1747 *
1748 * @since 1.0.0
1749 * @version 1.0.9
1750 */
1751 protected function wdkit_check_plugins_depends() {
1752 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ) ) : array();
1753 $update_plugin = array();
1754
1755 if ( empty( $plugins ) || ! is_array( $plugins ) ) {
1756 $this->wdkit_error_msg( array( 'plugins' => 'No Plugins' ) );
1757 }
1758
1759 $all_plugins = $this->get_plugins();
1760 foreach ( $plugins as $plugin ) {
1761 $pluginslug = ! empty( $plugin->plugin_slug ) ? sanitize_text_field( wp_unslash( $plugin->plugin_slug ) ) : '';
1762 $free_pro = ! empty( $plugin->freepro ) ? sanitize_text_field( wp_unslash( $plugin->freepro ) ) : '0';
1763 $type = ! empty( $plugin->type ) ? sanitize_text_field( wp_unslash( $plugin->type ) ) : 'plugin';
1764
1765 if ( is_null( $pluginslug ) ) {
1766 $plugin->status = 'warning';
1767 $update_plugin[] = $plugin;
1768
1769 continue;
1770 }
1771
1772 if ( 'plugin' === $type ) {
1773 if ( ! is_plugin_active( $pluginslug ) ) {
1774 if ( ! isset( $all_plugins[ $pluginslug ] ) ) {
1775 if ( isset( $free_pro ) && '1' === $free_pro ) {
1776 $plugin->status = 'manually';
1777 } else {
1778 $plugin->status = 'unavailable';
1779 }
1780 } else {
1781 $plugin->status = 'inactive';
1782 }
1783
1784 $update_plugin[] = $plugin;
1785 } elseif ( is_plugin_active( $pluginslug ) ) {
1786 $plugin->status = 'active';
1787 $update_plugin[] = $plugin;
1788 }
1789 } elseif ( 'theme' === $type ) {
1790 $theme_array = array_keys( wp_get_themes() );
1791 $theme_slug = get_stylesheet();
1792
1793 if ( $theme_slug === $plugin->name ) {
1794
1795 $plugin->status = 'active';
1796 } else {
1797 $theme_name = $plugin->name;
1798 if ( ! in_array( $theme_name, $theme_array ) ) {
1799 if ( isset( $free_pro ) && '1' === $free_pro ) {
1800 $plugin->status = 'manually';
1801 } else {
1802 $plugin->status = 'unavailable';
1803 }
1804 } else {
1805 $plugin->status = 'inactive';
1806 }
1807 }
1808
1809 $update_plugin[] = $plugin;
1810 }
1811 }
1812
1813 $response = array(
1814 'plugins' => $update_plugin,
1815 'ele_container' => get_option( 'elementor_experiment-container', false )
1816 );
1817
1818 $this->wdkit_success_msg( $response );
1819 }
1820
1821 /**
1822 *
1823 * It is Use for Install dependent plugin.
1824 *
1825 * @since 1.0.0
1826 * @version 1.0.9
1827 */
1828 protected function wdkit_install_plugins_depends() {
1829 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ), true ) : array();
1830 $type = ! empty( $plugins['type'] ) ? $plugins['type'] : 'plugin';
1831
1832 $responce = '';
1833 if ( 'plugin' === $type ) {
1834 $responce = Wdkit_Depends_Installer::get_instance()->wdkit_install_plugin( $plugins );
1835 } elseif ( 'theme' === $type ) {
1836 $theme_name = ! empty( $plugins['original_slug'] ) ? $plugins['original_slug'] : '';
1837 if ( ! empty( $theme_name ) ) {
1838
1839 $activate_result = switch_theme( $theme_name );
1840
1841 if ( ! is_wp_error( $activate_result ) ) {
1842 $responce = array(
1843 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ),
1844 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ),
1845 'slug' => 'the-plus-addons-for-block-editor',
1846 'status' => 'active',
1847 'success' => true,
1848 );
1849 } else {
1850 $responce = array(
1851 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ),
1852 'description' => $activate_result->get_error_message(),
1853 'status' => 'inactive',
1854 'success' => false,
1855 );
1856 }
1857 } else {
1858 $responce = array(
1859 'message' => esc_html__( 'Theme Name not Found', 'wdesignkit' ),
1860 'description' => esc_html__( 'Can Not Found Theme Name you Enterd.', 'wdesignkit' ),
1861 'success' => true,
1862 );
1863 }
1864 }
1865
1866 wp_send_json( $responce );
1867 wp_die();
1868 }
1869
1870 /**
1871 *
1872 * It is Use Update WDesignKit plugin latest version.
1873 *
1874 * @since 1.0.17
1875 */
1876 protected function wdkit_update_latest_plugin() {
1877
1878 return Wdkit_Depends_Installer::get_instance()->wdkit_update_plugin();
1879 }
1880
1881 /**
1882 *
1883 * It is Use for get plugin list.
1884 *
1885 * @since 1.0.0
1886 */
1887 private function get_plugins() {
1888 if ( ! function_exists( 'get_plugins' ) ) {
1889 require_once \ABSPATH . 'wp-admin/includes/plugin.php';
1890 }
1891
1892 return get_plugins();
1893 }
1894
1895 /**
1896 * Get Download Template Content
1897 *
1898 * @since 1.0.0
1899 */
1900 protected function wdkit_activate_container() {
1901
1902 $option_value = get_option( 'elementor_experiment-container', false );
1903
1904 if ( $option_value === false ) {
1905 add_option( 'elementor_experiment-container', 'active' );
1906 } else {
1907 update_option( 'elementor_experiment-container', 'active' );
1908 }
1909
1910 $result = array(
1911 'message' => esc_html__( 'Container Activated Successfully', 'wdesignkit' ),
1912 'description' => esc_html__( 'Elementor Container Activated Successfully.', 'wdesignkit' ),
1913 'success' => true,
1914 );
1915
1916 wp_send_json( $response );
1917 wp_die();
1918 }
1919
1920 /**
1921 * Get Download Template Content
1922 *
1923 * @since 1.0.0
1924 */
1925 protected function wdkit_import_template() {
1926 $args = $this->wdkit_parse_args( $_POST );
1927 $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
1928
1929 if( ! empty( $args['builder'] ) && 'gutenberg' === $args['builder'] ){
1930 apply_filters( 'tpgb_blocks_enable_all', 'tpgb_blocks_enable_all_filter' );
1931 }
1932
1933 $response = '';
1934 if ( empty( $args['template_id'] ) ) {
1935 $result = array(
1936 'content' => '',
1937 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
1938 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
1939 'success' => false,
1940 );
1941
1942 wp_send_json( $response );
1943 wp_die();
1944 }
1945
1946 $args['token'] = $this->wdkit_login_user_token( $args['email'] );
1947
1948 unset( $args['email'] );
1949 $response = WDesignKit_Data_Query::get_data( $api_type, $args );
1950 $custom_meta = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
1951
1952 /** Custom meta Field */
1953 if ( ! empty( $custom_meta ) && 'true' === $custom_meta && ! empty( $response ) && ! empty( $response['content'] ) ) {
1954
1955 $res_content = json_decode( $response['content'], true );
1956 if ( isset( $res_content['custom_meta'] ) && ! empty( $res_content['custom_meta'] ) ) {
1957 $meta_data = $res_content['custom_meta'];
1958
1959 if ( ! empty( $meta_data ) ) {
1960 foreach ( $meta_data as $meta_key => $meta_val ) {
1961 if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
1962 $meta_val[0] = maybe_unserialize( $meta_val[0] );
1963 }
1964
1965 if ( get_post_meta( get_the_ID(), $meta_key, true ) === '' ) {
1966 add_post_meta( get_the_ID(), $meta_key, $meta_val[0] );
1967 } else {
1968 update_post_meta( get_the_ID(), $meta_key, $meta_val[0] );
1969 }
1970 }
1971 }
1972 }
1973 }
1974
1975 wp_send_json( $response );
1976 wp_die();
1977 }
1978
1979 /**
1980 * This Function is Use For Media Import
1981 *
1982 * @since 1.0.0
1983 *
1984 * @param array $content store media content.
1985 * @param string $editor it is check editor.
1986 */
1987 public function wdkit_media_import( $content = array(), $editor = '' ) {
1988
1989 if ( empty( $content ) && empty( $editor ) ) {
1990 $args = $this->wdkit_parse_args( $_POST );
1991 $content = ! empty( $args['content'] ) ? json_decode( $args['content'], true ) : array();
1992 } else {
1993 $args = array(
1994 'content' => $content,
1995 'editor' => $editor,
1996 );
1997 $content = ! empty( $args['content'] ) ? $args['content'] : array();
1998
1999 if ( 'elementor' === $args['editor'] ) {
2000 $content = json_decode( $content, true );
2001 }
2002 }
2003
2004 if ( ! class_exists( 'Wdkit_Import_Images' ) ) {
2005 require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php';
2006 }
2007
2008 if ( ! empty( $args['editor'] ) && 'gutenberg' === $args['editor'] && ! empty( $content ) ) {
2009 $media_import = array( $content );
2010 $media_import = self::blocks_import_media_copy_content( $media_import );
2011 $content = $media_import[0];
2012 } elseif ( ! empty( $args['editor'] ) && 'elementor' === $args['editor'] && ! empty( $content ) ) {
2013 $media_import = array( $content );
2014 $media_import = self::widgets_elements_id_change( $media_import );
2015 $media_import = self::widgets_import_media_copy_content( $media_import );
2016 $content = $media_import[0];
2017 }
2018
2019 return $content;
2020 }
2021
2022 /**
2023 * Widgets elements data
2024 *
2025 * @since 1.0.0
2026 * @param string $media_import it is store media data.
2027 */
2028 protected static function widgets_elements_id_change( $media_import ) {
2029 if ( did_action( 'elementor/loaded' ) ) {
2030 return \Elementor\Plugin::instance()->db->iterate_data(
2031 $media_import,
2032 function ( $element ) {
2033 $element['id'] = \Elementor\Utils::generate_random_string();
2034 return $element;
2035 }
2036 );
2037 } else {
2038 return $media_import;
2039 }
2040 }
2041
2042 /**
2043 * Widgets Media import copy content.
2044 *
2045 * @since 1.0.0
2046 *
2047 * @param string $media_import it is store media data.
2048 */
2049 protected static function widgets_import_media_copy_content( $media_import ) {
2050 if ( did_action( 'elementor/loaded' ) ) {
2051
2052 return \Elementor\Plugin::instance()->db->iterate_data(
2053 $media_import,
2054 function ( $element_data ) {
2055 $elements = \Elementor\Plugin::instance()->elements_manager->create_element_instance( $element_data );
2056
2057 if ( ! $elements ) {
2058 return null;
2059 }
2060
2061 return self::widgets_element_import_start( $elements );
2062 }
2063 );
2064 } else {
2065 return $media_import;
2066 }
2067 }
2068
2069 /**
2070 * Start element copy content for media import.
2071 *
2072 * @since 1.0.0
2073 *
2074 * @param string \Elementor\Controls_Stack $element it is store elementor data.
2075 */
2076 protected static function widgets_element_import_start( \Elementor\Controls_Stack $element ) {
2077 $get_element_instance = $element->get_data();
2078 $tp_mi_on_fun = 'on_import';
2079
2080 if ( method_exists( $element, $tp_mi_on_fun ) ) {
2081 $get_element_instance = $element->{$tp_mi_on_fun}( $get_element_instance );
2082 }
2083
2084 foreach ( $element->get_controls() as $get_control ) {
2085 $control_type = \Elementor\Plugin::instance()->controls_manager->get_control( $get_control['type'] );
2086 $control_name = $get_control['name'];
2087
2088 if ( ! $control_type ) {
2089 return $get_element_instance;
2090 }
2091
2092 if ( method_exists( $control_type, $tp_mi_on_fun ) ) {
2093 $get_element_instance['settings'][ $control_name ] = $control_type->{$tp_mi_on_fun}( $element->get_settings( $control_name ), $get_control );
2094 }
2095 }
2096
2097 return $get_element_instance;
2098 }
2099
2100 /**
2101 * Blocks Recursively data
2102 *
2103 * @param string $data_import gutenber data import.
2104 */
2105 public static function blocks_import_media_copy_content( $data_import ) {
2106 if ( ! empty( $data_import ) ) {
2107 foreach ( $data_import[0] as $key => $val ) {
2108 if ( array_key_exists( 'blockName', $val ) && ( empty( $val['blockName'] ) || null === $val['blockName'] || empty( $val['blockName'] ) || ' ' === $val['blockName'] ) ) {
2109 unset( $data_import[0][ $key ] );
2110 }
2111 }
2112 }
2113
2114 return self::blocks_array_recursively_data(
2115 $data_import,
2116 function ( $block_data ) {
2117 $elements = self::blocks_data_instance( $block_data );
2118 return $elements;
2119 }
2120 );
2121 }
2122
2123 /**
2124 * Blocks Recursively data
2125 *
2126 * @param array $data store data.
2127 * @param string $callback store data.
2128 * @param string $args store data.
2129 */
2130 public static function blocks_array_recursively_data( $data, $callback, $args = array() ) {
2131 if ( ( isset( $data['name'] ) && ! empty( $data['name'] ) ) || ( isset( $data['blockName'] ) && ! empty( $data['blockName'] ) ) ) {
2132 if ( ! empty( $data['innerBlocks'] ) ) {
2133 $data['innerBlocks'] = self::blocks_array_recursively_data( $data['innerBlocks'], $callback, $args );
2134 }
2135
2136 return call_user_func( $callback, $data, $args );
2137 }
2138
2139 if ( ! empty( $data ) ) {
2140 $data = (array) $data;
2141 foreach ( $data as $block_key => $block_value ) {
2142 $block_data = self::blocks_array_recursively_data( $data[ $block_key ], $callback, $args );
2143
2144 if ( null === $block_data ) {
2145 continue;
2146 }
2147
2148 $data[ $block_key ] = $block_data;
2149 }
2150 }
2151
2152 return $data;
2153 }
2154
2155 /**
2156 * Check Blocks data media Url
2157 *
2158 * @param array $block_data store data.
2159 * @param array $args store data.
2160 * @param array $block_args store data.
2161 */
2162 public static function blocks_data_instance( array $block_data, array $args = array(), $block_args = null ) {
2163
2164 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'] ) ) ) {
2165 $blocks_attr = isset( $block_data['attributes'] ) ? $block_data['attributes'] : ( isset( $block_data['attrs'] ) ? $block_data['attrs'] : array() );
2166 foreach ( $blocks_attr as $block_key => $block_val ) {
2167 if ( isset( $block_val['url'] ) && isset( $block_val['id'] ) && ! empty( $block_val['url'] ) ) {
2168 $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
2169 $blocks_attr[ $block_key ] = $new_media;
2170 } elseif ( isset( $block_val['url'] ) && ! empty( $block_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $block_val['url'] ) ) {
2171 $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
2172 $blocks_attr[ $block_key ] = $new_media;
2173 } elseif ( is_array( $block_val ) && ! empty( $block_val ) ) {
2174 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 ) ) {
2175 foreach ( $block_val as $key => $val ) {
2176 if ( is_array( $val ) && ! empty( $val ) ) {
2177
2178 if ( isset( $val['url'] ) && ( isset( $val['Id'] ) || isset( $val['id'] ) ) && ! empty( $val['url'] ) ) {
2179 $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
2180 $blocks_attr[ $block_key ][ $key ] = $new_media;
2181 } elseif ( isset( $val['url'] ) && ! empty( $val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $val['url'] ) ) {
2182 $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
2183 $blocks_attr[ $block_key ][ $key ] = $new_media;
2184 } else {
2185 foreach ( $val as $sub_key => $sub_val ) {
2186 if ( isset( $sub_val['url'] ) && ( isset( $sub_val['Id'] ) || isset( $sub_val['id'] ) ) && ! empty( $sub_val['url'] ) ) {
2187 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
2188
2189 if ( is_array($sub_val) && is_array($new_media) ){
2190 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = array_merge( $sub_val , $new_media );
2191 } else {
2192 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
2193 }
2194
2195 } elseif ( isset( $sub_val['url'] ) && ! empty( $sub_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val['url'] ) ) {
2196 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
2197 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
2198 } elseif ( is_array( $sub_val ) && ! empty( $sub_val ) ) {
2199 foreach ( $sub_val as $sub_key1 => $sub_val1 ) {
2200 if ( isset( $sub_val1['url'] ) && ( isset( $sub_val1['Id'] ) || isset( $sub_val1['id'] ) ) && ! empty( $sub_val1['url'] ) ) {
2201 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
2202
2203 if ( is_array($sub_val1) && is_array($new_media) ){
2204 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = array_merge( $sub_val1 , $new_media );
2205 } else {
2206 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media ;
2207 }
2208
2209 } elseif ( isset( $sub_val1['url'] ) && ! empty( $sub_val1['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val1['url'] ) ) {
2210 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
2211 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media;
2212 }
2213 }
2214 }
2215 }
2216 }
2217 }
2218 }
2219 }
2220 }
2221 }
2222 if ( isset( $block_data['attributes'] ) ) {
2223 $block_data['attributes'] = $blocks_attr;
2224 } elseif ( isset( $block_data['attrs'] ) ) {
2225 $block_data['attrs'] = $blocks_attr;
2226 }
2227 }
2228
2229 return $block_data;
2230 }
2231
2232 /**
2233 * Kit Template Import Pages/Sections
2234 *
2235 * @since 1.0.0
2236 * */
2237 protected function wdkit_import_kit_template() {
2238
2239 if ( ! current_user_can( 'manage_options' ) ) {
2240 return false;
2241 }
2242
2243 $builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '';
2244
2245 if( ! empty( $builder ) && 'gutenberg' === $builder ){
2246 apply_filters( 'widget_load_nxt', 'tpgb_blocks_enable_all_filter' );
2247 }
2248
2249 $page_section = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : '';
2250
2251 if ( isset( $page_section ) ) {
2252 $args['page_section'] = ! empty( $page_section ) ? sanitize_text_field( wp_unslash( $page_section ) ) : '';
2253 }
2254
2255 $template_ids = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array();
2256 $email = ! empty( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : '';
2257 $editor = isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : '';
2258 $website_kit = isset( $_POST['website_kit'] ) ? sanitize_text_field( wp_unslash( $_POST['website_kit'] ) ) : '';
2259 $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
2260
2261 if ( empty( $template_ids ) ) {
2262 $output = array(
2263 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
2264 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
2265 'success' => false,
2266 );
2267
2268 wp_send_json( $output );
2269 wp_die();
2270 }
2271
2272 /**Not Usefull*/
2273 if ( isset( $_POST['select'] ) ) {
2274 $args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : '';
2275 }
2276
2277 $args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
2278 $args['editor'] = $editor;
2279
2280 $token = $this->wdkit_login_user_token( $email );
2281
2282 $temp_args = array(
2283 'token' => $token,
2284 'template_id' => $template_ids['id'],
2285 'editor' => $editor,
2286 'website_kit' => $website_kit,
2287 );
2288
2289 $response = WDesignKit_Data_Query::get_data( $api_type, $temp_args );
2290 $output = array();
2291
2292 if ( 'error' === $response['content'] ) {
2293 wp_send_json( $response );
2294 wp_die();
2295 } else {
2296
2297 $result = array(
2298 'response' => $response,
2299 'args' => $args,
2300 'id' => $template_ids['id'],
2301 'temp_data' => $template_ids,
2302 );
2303
2304 $output['message'] = $response['message'];
2305 $output['description'] = $response['description'];
2306 $output['data'] = $result;
2307 $output['success'] = $response['success'];
2308 }
2309
2310 wp_send_json( $output );
2311 wp_die();
2312 }
2313
2314 protected function wdkit_enable_template_widgets() {
2315 $widget_list = ! empty( $_POST['widget_list'] ) ? json_decode( wp_unslash( $_POST['widget_list'] ), true ) : [];
2316
2317 if ( empty( $widget_list ) ){
2318 $res = array(
2319 'massage' => __('Widget array not found', 'wdesignkit'),
2320 'description' => __('Widget array not found', 'wdesignkit'),
2321 'success' => false,
2322 );
2323 wp_send_json($res);
2324 wp_die();
2325 }
2326
2327 if ( ! has_filter('tpae_enable_selected_widgets') ){
2328 $res = array(
2329 'massage' => __('Relevant Plugin not Activated', 'wdesignkit'),
2330 'description' => __('Relevant Plugin not Installed / Activated', 'wdesignkit'),
2331 'success' => false,
2332 );
2333 wp_send_json($res);
2334 wp_die();
2335 }
2336
2337 $w_list = array(
2338 'widgets' => $widget_list
2339 );
2340
2341 $result = apply_filters( 'tpae_enable_selected_widgets', $w_list );
2342
2343 if( !empty( $result['success'] ) ){
2344 $res = array(
2345 'massage' => __('Enabled widgets successfully', 'wdesignkit'),
2346 'description' => __('Used widgets have been enabled successfully', 'wdesignkit'),
2347 'success' => true,
2348 );
2349 } else {
2350 $res = array(
2351 'massage' => __( $result['message'], 'wdesignkit'),
2352 'description' => __( $result['description'], 'wdesignkit'),
2353 'success' => true,
2354 );
2355 }
2356
2357 wp_send_json($res);
2358 wp_die();
2359 }
2360
2361 /**
2362 * Import single template and section from plugin only
2363 * */
2364 protected function wdkit_import_multi_template() {
2365 $args = $this->wdkit_parse_args( $_POST );
2366 $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
2367
2368 if ( ! current_user_can( 'manage_options' ) ) {
2369 return false;
2370 }
2371
2372 if( ! empty( $args['builder'] ) && 'gutenberg' === $args['builder'] ){
2373 apply_filters( 'widget_load_nxt', 'tpgb_blocks_enable_all_filter' );
2374 }
2375
2376 if ( empty( $_POST['template_ids'] ) ) {
2377 $output = array(
2378 'data' => array(),
2379 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
2380 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
2381 'success' => false,
2382 );
2383
2384 wp_send_json( $output );
2385 wp_die();
2386 }
2387
2388 if ( isset( $_POST['template_ids'] ) ) {
2389 $args['template_ids'] = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array();
2390 }
2391
2392 if ( isset( $_POST['page_section'] ) ) {
2393 $args['page_section'] = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : '';
2394 }
2395
2396 if ( isset( $_POST['select'] ) ) {
2397 $args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : '';
2398 }
2399
2400 $args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
2401 if ( ! empty( $args['template_ids'] ) && ! empty( $args['page_section'] ) ) {
2402 $output = array();
2403 if ( is_array( $args['template_ids'] ) ) {
2404 foreach ( $args['template_ids'] as $key => $value ) {
2405 if ( ! empty( $value['id'] ) ) {
2406 $token = $this->wdkit_login_user_token( $args['email'] );
2407 $temp_args = array(
2408 'token' => $token,
2409 'template_id' => $value['id'],
2410 'editor' => $args['editor'],
2411 );
2412
2413 $response = WDesignKit_Data_Query::get_data( $api_type, $temp_args );
2414
2415 if ( 'error' === $response['content'] ) {
2416 wp_send_json( $response );
2417 wp_die();
2418 }
2419
2420 $result = array(
2421 'response' => $response,
2422 'args' => $args,
2423 'id' => $args['template_ids'],
2424 'value' => $value,
2425 );
2426
2427 $output['message'] = $response['message'];
2428 $output['description'] = $response['description'];
2429 $output['data'] = $result;
2430 $output['success'] = true;
2431
2432 }
2433 }
2434 } else {
2435 $token = $this->wdkit_login_user_token( $args['email'] );
2436 $temp_args = array(
2437 'token' => $token,
2438 'template_id' => $args['template_ids'],
2439 'editor' => $args['editor'],
2440 );
2441
2442 $response = WDesignKit_Data_Query::get_data( $api_type, $temp_args );
2443
2444 if ( 'error' === $response['content'] ) {
2445 wp_send_json( $response );
2446 wp_die();
2447 }
2448
2449 $result = array(
2450 'response' => $response,
2451 'args' => $args,
2452 'id' => $args['template_ids'],
2453 );
2454
2455 $output['message'] = $response['message'];
2456 $output['description'] = $response['description'];
2457 $output['data'] = $result;
2458 $output['success'] = true;
2459 }
2460
2461
2462 wp_send_json( $output );
2463 wp_die();
2464 }
2465 }
2466
2467 /**
2468 * Import single template and section from plugin only
2469 *
2470 * @param array $args store data.
2471 * @param array $template_id store data.
2472 * @param array $data store data.
2473 * @param array $temp_data store data.
2474 * */
2475 protected function import_page_section_content() {
2476
2477 if ( isset( $_POST['args'] ) ) {
2478 $args = ! empty( $_POST['args'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['args'] ) ), true ) : array();
2479 }
2480
2481 if ( isset( $_POST['temp_data'] ) ) {
2482 $temp_data = ! empty( $_POST['temp_data'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['temp_data'] ) ), true ) : array();
2483 }
2484
2485 if ( isset( $_POST['template_id'] ) ) {
2486 $template_id = ! empty( $_POST['template_id'] ) ? json_decode(sanitize_text_field( wp_unslash( $_POST['template_id'] ), true)) : '';
2487 }
2488
2489 if ( isset( $_POST['data'] ) ) {
2490 $data = ! empty( $_POST['data'] ) ? json_decode( wp_unslash( $_POST['data'] )) : '';
2491 }
2492
2493 $enqueue_instance = new Wdkit_Enqueue();
2494 $get_post_type = $enqueue_instance->wdkit_get_post_type_list();
2495
2496 $post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page';
2497
2498 if ( 'section' === $post_type ) {
2499 $post_type = $temp_data['wp_post_type'];
2500 } else {
2501 $post_type = $temp_data['wp_post_type'];
2502 }
2503
2504 if ( ! array_key_exists( $post_type, $get_post_type ) ) {
2505 $post_type = 'page';
2506 }
2507
2508 if ( ! empty( $data ) && ! empty( $template_id ) && ! empty( $post_type ) && current_user_can( 'manage_options' ) ) {
2509 $post_content = $data;
2510 $post_title = isset( $post_content->title ) ? sanitize_text_field( $post_content->title ) : '';
2511 $file_type = isset( $post_content->file_type ) ? sanitize_text_field( $post_content->file_type ) : '';
2512 $content = isset( $post_content->content ) ? wp_slash( $post_content->content ) : '';
2513
2514 if ( 'gutenberg' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'wp_block' === $file_type ) ) {
2515 if ( empty( $content ) ) {
2516 wp_send_json(
2517 array(
2518 'template_id' => $template_id,
2519 'message' => 'Content is Empty.',
2520 )
2521 );
2522 wp_die();
2523 } else if ( ! empty( $content ) && ! empty( $file_type ) && 'wp_block' === $file_type ) {
2524 $parse_blocks = parse_blocks( stripslashes( $content ) );
2525
2526 $editor = ( 'wdkit' === $args['editor'] ) ? 'gutenberg' : $args['editor'];
2527 $content = $this->wdkit_media_import( $parse_blocks, $editor );
2528 $content = addslashes( serialize_blocks( $content ) );
2529
2530 $inserted_post = wp_insert_post(
2531 array(
2532 'post_status' => 'publish',
2533 'post_type' => $post_type,
2534 'post_title' => $post_title,
2535 'post_content' => $content,
2536 )
2537 );
2538
2539 if ( is_wp_error( $inserted_post ) ) {
2540 wp_send_json(
2541 array(
2542 'import_failed' => $inserted_post->get_error_message(),
2543 'code' => $inserted_post->get_error_code(),
2544 )
2545 );
2546 wp_die();
2547 }
2548
2549 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
2550 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
2551 if ( ! empty( $custom_meta ) ) {
2552 foreach ( $custom_meta as $meta_key => $meta_val ) {
2553 if ( isset( $meta_val[0] ) && ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
2554 $meta_val[0] = maybe_unserialize( $meta_val[0] );
2555 }
2556
2557 if ( '' === get_post_meta( $inserted_post, $meta_key, true ) && isset( $meta_val[0] ) ) {
2558 add_post_meta( $inserted_post, $meta_key, $meta_val[0] );
2559 }
2560 }
2561 }
2562 }
2563
2564 if (has_filter('tpgb_disable_unsed_block_filter')) {
2565 apply_filters( 'tpgb_disable_unsed_block_filter', array('tpgb_disable_unsed_block_filter_fun') );
2566 }
2567
2568 $temp_detail = array(
2569 'title' => get_the_title( $inserted_post ),
2570 'edit_link' => get_edit_post_link( $inserted_post, 'internal' ),
2571 'view' => get_permalink( $inserted_post ),
2572 );
2573
2574 if ( !empty( $template_id[0]->id ) ){
2575 $temp_id = $template_id[0]->id;
2576 } else if ( !empty($template_id) ) {
2577 $temp_id = $template_id;
2578 } else {
2579 $temp_id = '';
2580 }
2581
2582 wp_send_json(
2583 array(
2584 $temp_id => $temp_detail,
2585 'description' => "Yay! Your Section has been Successfully Imported.",
2586 'message' => "Successfully Imported.",
2587 'success' => true
2588 )
2589 );
2590 }
2591 } elseif ( 'elementor' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'elementor' === $file_type ) ) {
2592 if ( did_action( 'elementor/loaded' ) ) {
2593 if ( empty( $content ) ) {
2594 wp_send_json(
2595 array(
2596 'template_id' => $template_id,
2597 'message' => 'Content is Empty.',
2598 )
2599 );
2600 wp_die();
2601 } else if ( ! empty( $content ) && ! empty( $file_type ) && 'elementor' === $file_type ) {
2602
2603 $post_attributes = array(
2604 'post_title' => $post_title,
2605 'post_type' => $post_type,
2606 'post_status' => 'publish',
2607 );
2608
2609 if ( 'elementor_library' === $post_type ) {
2610 $el_type = ( isset( $post_content->el_type ) && ! empty( $post_content->el_type ) ) ? sanitize_text_field( $post_content->el_type ) : 'page';
2611 $new_document = \Elementor\Plugin::$instance->documents->create(
2612 $el_type,
2613 $post_attributes
2614 );
2615 } else {
2616 $new_document = \Elementor\Plugin::$instance->documents->create(
2617 $post_attributes['post_type'],
2618 $post_attributes
2619 );
2620 }
2621
2622 if ( is_wp_error( $new_document ) ) {
2623 wp_send_json(
2624 array(
2625 'import_failed' => $new_document->get_error_message(),
2626 'code' => $new_document->get_error_code(),
2627 )
2628 );
2629 wp_die();
2630 }
2631
2632 $settings = ( isset( $post_content->settings ) && ! empty( $post_content->settings ) ) ? json_decode( wp_json_encode( $post_content->settings ), true ) : array();
2633
2634 $content = wp_json_encode( $content );
2635 $content = $this->wdkit_media_import( $content, $file_type );
2636
2637 $new_document->save(
2638 array(
2639 'elements' => $content,
2640 'settings' => ! empty( $settings ) ? $settings : array(),
2641 )
2642 );
2643
2644 $inserted_id = $new_document->get_main_id();
2645
2646 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
2647 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
2648 if ( ! empty( $custom_meta ) ) {
2649 foreach ( $custom_meta as $meta_key => $meta_val ) {
2650 if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
2651 $meta_val[0] = maybe_unserialize( $meta_val[0] );
2652 }
2653 if ( '' === get_post_meta( $inserted_id, $meta_key, true ) ) {
2654 add_post_meta( $inserted_id, $meta_key, $meta_val[0] );
2655 }
2656 }
2657 }
2658 }
2659
2660 $temp_detail = array(
2661 'title' => get_the_title( $inserted_id ),
2662 'edit_link' => get_edit_post_link( $inserted_id, 'internal' ),
2663 'view' => get_permalink( $inserted_id ),
2664 );
2665
2666 if ( !empty( $template_id[0]->id ) ){
2667 $temp_id = $template_id[0]->id;
2668 } else if ( !empty($template_id) ) {
2669 $temp_id = $template_id;
2670 } else {
2671 $temp_id = '';
2672 }
2673
2674 \Elementor\Plugin::$instance->files_manager->clear_cache();
2675
2676 wp_send_json(
2677 array(
2678 $temp_id => $temp_detail,
2679 'description' => "Yay! Your Section has been Successfully Imported.",
2680 'message' => "Successfully Imported.",
2681 'success' => true
2682 )
2683 );
2684 }
2685 } else {
2686 wp_send_json(
2687 array(
2688 'template_id' => $template_id,
2689 'message' => esc_html__( 'Relevant Page Builder not installed or activated', 'wdesignkit' ),
2690 )
2691 );
2692 wp_die();
2693 }
2694 }
2695 }
2696 }
2697
2698 /**
2699 * Share with Me Template and widgets
2700 *
2701 * @since 1.0.0
2702 */
2703 protected function wdkit_shared_with_me() {
2704 $data = isset( $_POST['api_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['api_info'] ) ) ) ) : '';
2705
2706 $array_data = array(
2707 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
2708 'type' => isset( $data->type ) ? sanitize_text_field( wp_unslash( $data->type ) ) : '',
2709 'ParPage' => isset( $data->par_page ) ? (int) $data->par_page : 12,
2710 'CurrentPage' => isset( $data->current_page ) ? (int) $data->current_page : 1,
2711 'builder' => isset( $data->builder ) ? sanitize_text_field( wp_unslash( $data->builder ) ) : '',
2712 );
2713
2714 $response = $this->wkit_api_call( $array_data, 'shared_with_me' );
2715 $success = ! empty( $response['success'] ) ? $response['success'] : false;
2716
2717 wp_send_json( $response );
2718 wp_die();
2719 }
2720
2721 /**
2722 * Add new WorkSpace
2723 *
2724 * @since 1.0.0
2725 */
2726 protected function wdkit_manage_workspace() {
2727 $args = $this->wdkit_parse_args( $_POST );
2728
2729 $user_email = ! empty( $args['email'] ) ? strtolower( sanitize_email( $args['email'] ) ) : '';
2730 $current_wid = ! empty( $_POST['current_wid'] ) ? strtolower( sanitize_text_field( $_POST['current_wid'] ) ) : '';
2731
2732 $args['current_wid'] = $current_wid;
2733
2734 if ( empty( $user_email ) ) {
2735 $response = array(
2736 'message' => $this->e_msg_login,
2737 'description' => $this->e_desc_login,
2738 'success' => false,
2739 );
2740
2741 wp_send_json( $response );
2742 wp_die();
2743 }
2744
2745 $args['token'] = $this->wdkit_login_user_token( $user_email );
2746 unset( $user_email );
2747
2748 $response = WDesignKit_Data_Query::get_data( 'manage_workspace', $args );
2749
2750 return $response;
2751 }
2752
2753 /**
2754 *
2755 * It is Use for manage workspace
2756 *
2757 * @since 1.0.0
2758 */
2759 protected function wdkit_manage_widget_workspace() {
2760 $workspace_info = isset( $_POST['workspace_info'] ) ? sanitize_text_field( wp_unslash( $_POST['workspace_info'] ) ) : array();
2761 $data = isset( $workspace_info ) ? json_decode( stripslashes( $workspace_info ) ) : array();
2762
2763 $array_data = array(
2764 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
2765 'wstype' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
2766 'widget_id' => isset( $data->widget_id ) ? (int) $data->widget_id : '',
2767 'wid' => isset( $data->wid ) ? (int) $data->wid : '',
2768 'current_wid' => isset( $data->current_wid ) ? (int) $data->current_wid : '',
2769 );
2770
2771 $response = $this->wkit_api_call( $array_data, 'manage_workspace' );
2772
2773 wp_send_json( $response['data'] );
2774 wp_die();
2775 }
2776
2777 /**
2778 *
2779 * It is Use for manage api key page
2780 *
2781 * @since 1.0.0
2782 */
2783 protected function wdkit_activate_key() {
2784 $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '';
2785 $response = '';
2786
2787 if ( empty( $user_email ) ) {
2788 $response = array(
2789 'message' => $this->e_msg_login,
2790 'description' => $this->e_desc_login,
2791 'success' => false,
2792 );
2793
2794 wp_send_json( $response );
2795 wp_die();
2796 }
2797
2798 $token = $this->wdkit_login_user_token( $email );
2799 $apikey = isset( $_POST['apikey'] ) ? sanitize_key( wp_unslash( $_POST['apikey'] ) ) : '';
2800 $product = isset( $_POST['product'] ) ? sanitize_text_field( wp_unslash( $_POST['product'] ) ) : '';
2801 $product_action = isset( $_POST['product_action'] ) ? sanitize_text_field( wp_unslash( $_POST['product_action'] ) ) : 'activate';
2802 if ( ! empty( $token ) && ! empty( $product ) && ! empty( $product_action ) ) {
2803 $args = array(
2804 'token' => $token,
2805 'product' => $product,
2806 'product_action' => $product_action,
2807 );
2808
2809 if ( 'activate' === $product_action ) {
2810 $args['apikey'] = $apikey;
2811 $args['site_url'] = home_url();
2812 }
2813
2814 $response = Wdkit_Data_Hooks::get_data( 'wkit_activate_key', $args );
2815 }
2816
2817 wp_send_json( $response );
2818 wp_die();
2819 }
2820
2821 /**
2822 *
2823 * Get list local Widget List
2824 *
2825 * @since 1.0.0
2826 */
2827 protected function wdkit_get_local_widgets() {
2828 $builder = array();
2829 $a_c_s_d_s_c = array();
2830 $j_s_o_n_array = array();
2831
2832 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'bricks', 'widget' ) ) {
2833 array_push( $builder, 'bricks' );
2834 }
2835
2836 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor', 'widget' ) ) {
2837 array_push( $builder, 'elementor' );
2838 }
2839
2840 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) {
2841 array_push( $builder, 'gutenberg' );
2842 }
2843
2844 foreach ( $builder as $key => $name ) {
2845 $elementor_dir = WDKIT_BUILDER_PATH . '/' . $name;
2846
2847 if ( ! empty( $elementor_dir ) && is_dir( $elementor_dir ) ) {
2848 $elementor_list = scandir( $elementor_dir );
2849 $elementor_list = array_diff( $elementor_list, array( '.', '..' ) );
2850
2851 if ( ! empty( $elementor_list ) ) {
2852 foreach ( $elementor_list as $key => $value ) {
2853 $a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) . $key]['data'] = $value;
2854 $a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) . $key]['builder'] = $name;
2855 }
2856 }
2857 }
2858 }
2859
2860 ksort( $a_c_s_d_s_c );
2861 $a_c_s_d_s_c = array_reverse( $a_c_s_d_s_c );
2862
2863 foreach ( $a_c_s_d_s_c as $key => $value ) {
2864 $elementor_dir = WDKIT_BUILDER_PATH . '/' . $value['builder'];
2865
2866 if ( file_exists( "{$elementor_dir}/{$value['data']}" ) && is_dir( "{$elementor_dir}/{$value['data']}" ) ) {
2867 $sub_dir = scandir( "{$elementor_dir}/{$value['data']}" );
2868 $sub = array_diff( $sub_dir, array( '.', '..' ) );
2869
2870 foreach ( $sub as $sub_dir_value ) {
2871 $file = new SplFileInfo( $sub_dir_value );
2872 $check_ext = $file->getExtension();
2873 $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
2874
2875 if ( 'json' === $ext ) {
2876 $widget1 = WDKIT_BUILDER_PATH . "/{$value['builder']}/{$value['data']}/{$sub_dir_value}";
2877 $filedata = wp_json_file_decode( $widget1 );
2878 $decode_data = json_decode( wp_json_encode( $filedata ), true );
2879 array_push( $j_s_o_n_array, $decode_data['widget_data'] );
2880 }
2881 }
2882 }
2883 }
2884
2885 return $j_s_o_n_array;
2886 }
2887
2888 /**
2889 *
2890 * It is Use for manage widget category.
2891 *
2892 * @since 1.0.0
2893 */
2894 protected function wdkit_manage_widget_category() {
2895 $data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : '';
2896 $data = json_decode( stripslashes( $data ) );
2897
2898 $type = isset( $data->manage_type ) ? sanitize_text_field( wp_unslash( $data->manage_type ) ) : '';
2899 $wkit_builder_option = get_option( 'wkit_builder' );
2900
2901 if ( empty( $wkit_builder_option ) ) {
2902 add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' );
2903 }
2904
2905 if ( 'get' === $type ) {
2906 if ( ! in_array( 'WDesignKit', $wkit_builder_option ) ) {
2907 update_option( 'wkit_builder', array( 'WDesignKit' ) );
2908 }
2909 } elseif ( 'update' === $type ) {
2910 $list = isset( $data->category_list ) ? $data->category_list : array();
2911 $list = array_unique( $list );
2912 $list = array_values( $list );
2913
2914 if ( ! empty( $list ) ) {
2915 update_option( 'wkit_builder', $list );
2916 }
2917 }
2918
2919 wp_send_json( get_option( 'wkit_builder' ) );
2920 }
2921
2922 /**
2923 *
2924 * Custom_upload_dir
2925 *
2926 * @since 1.0.0
2927 *
2928 * @param array $upload store data.
2929 */
2930 public function custom_upload_dir( $upload ) {
2931 // Specify the path to your custom upload directory.
2932 if ( isset( $this->widget_folder_u_r_l ) && ! empty( $this->widget_folder_u_r_l ) ) {
2933
2934 // Set the custom directory as the upload path.
2935 $upload['path'] = $this->widget_folder_u_r_l;
2936 // Set the URL for the uploaded file.
2937 $upload['url'] = $upload['baseurl'] . $upload['subdir'];
2938 }
2939
2940 return $upload;
2941 }
2942
2943 /**
2944 *
2945 * It is Use for delete widget from server
2946 *
2947 * @since 1.0.0
2948 */
2949 protected function wkit_widget_json() {
2950 $widget_type = !empty( $_POST['widget_type'] ) ? wp_unslash( $_POST['widget_type'] ) : '';
2951 $folder_name = !empty( $_POST['folder_name'] ) ? wp_unslash( $_POST['folder_name'] ) : '';
2952 $file_name = !empty( $_POST['file_name'] ) ? ( wp_unslash( $_POST['file_name'] ) ) : '';
2953
2954 if ( empty( $widget_type ) || empty( $folder_name ) || empty( $file_name ) ) {
2955 return array(
2956 'success' => false,
2957 'message' => esc_html__( 'Widget JSON not found', 'wdesignkit' ),
2958 'description' => esc_html__( 'widget JSON file not found.', 'wdesignkit' ),
2959 );
2960 }
2961
2962 $json_path = WDKIT_BUILDER_PATH . "/{$widget_type}/{$folder_name}/{$file_name}";
2963
2964 $json_data = wp_json_file_decode( "$json_path.json" );
2965 if ( ! empty( $json_data ) ) {
2966 $result = (object) array(
2967 'success' => true,
2968 'data' => $json_data,
2969 'message' => esc_html__( 'Widget get Successfully', 'wdesignkit' ),
2970 'description' => esc_html__( 'Widget JSON get Successfully', 'wdesignkit' ),
2971 );
2972 } else {
2973 $result = (object) array(
2974 'success' => false,
2975 'message' => esc_html__( 'Widget not get', 'wdesignkit' ),
2976 'description' => esc_html__( 'Widget JSON not get', 'wdesignkit' ),
2977 );
2978 }
2979
2980 wp_send_json( $result );
2981 wp_die();
2982 }
2983
2984 /**
2985 *
2986 * It is Use for download widget from widget listing.
2987 *
2988 * @since 1.0.0
2989 */
2990 protected function wdkit_download_widget() {
2991 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
2992 $data = json_decode( stripslashes( $data ) );
2993
2994 $array_data = array(
2995 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
2996 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
2997 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
2998 );
2999
3000 $response = $this->wkit_api_call( $array_data, 'save_widget' );
3001 $success = ! empty( $response['success'] ) ? $response['success'] : false;
3002
3003 if ( empty( $success ) ) {
3004 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
3005 $result = (object) array(
3006 'success' => false,
3007 'message' => $massage,
3008 'description' => esc_html__( ' Widget not Downloaded', 'wdesignkit' ),
3009 );
3010
3011 wp_send_json( $result );
3012 wp_die();
3013 }
3014
3015 $response = json_decode( wp_json_encode( $response['data'] ), true );
3016
3017 if ( empty( $response ) || empty( $response['data'] ) ) {
3018 $message = ! empty( $response['message'] ) ? $response['message'] : 'No Response Found';
3019 $description = ! empty( $response['description'] ) ? $response['description'] : 'Widget not Downloaded';
3020
3021 $result = (object) array(
3022 'success' => false,
3023 'message' => esc_html( $message ),
3024 'description' => esc_html( $description ),
3025 );
3026
3027 wp_send_json( $result );
3028 wp_die();
3029 }
3030
3031 $img_url = ! empty( $response['data']['image'] ) ? $response['data']['image'] : '';
3032 $json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'], true ) : '';
3033
3034 if( empty( $response['success'] ) ){
3035 wp_send_json( $responce );
3036 wp_die();
3037 }
3038
3039 if ( empty( $img_url ) && empty( $json_data ) ) {
3040 $responce = (object) array(
3041 'success' => false,
3042 'message' => esc_html__( 'No Response Found', 'wdesignkit' ),
3043 'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ),
3044 );
3045
3046 wp_send_json( $responce );
3047 wp_die();
3048 }
3049
3050 include_once ABSPATH . 'wp-admin/includes/file.php';
3051 \WP_Filesystem();
3052 global $wp_filesystem;
3053
3054 if( !is_array($json_data) ){
3055 $json_data = json_decode( $json_data, true );
3056 }
3057
3058 $title = ! empty( $json_data['widget_data']['widgetdata']['name'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['name'] ) : '';
3059 $builder = ! empty( $json_data['widget_data']['widgetdata']['type'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['type'] ) : '';
3060 $w_uniq = ! empty( $json_data['widget_data']['widgetdata']['widget_id'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['widget_id'] ) : '';
3061
3062 $folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
3063 $file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
3064 $builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/";
3065
3066 if ( ! is_dir( $builder_type_path ) ) {
3067 wp_mkdir_p( $builder_type_path );
3068 }
3069
3070 if ( ! is_dir( $builder_type_path . $folder_name ) ) {
3071 wp_mkdir_p( $builder_type_path . $folder_name );
3072 }
3073
3074 if ( ! empty( $img_url ) ) {
3075 $img_body = wp_remote_get( $img_url );
3076 $img_ext = pathinfo( $img_url )['extension'];
3077
3078 $wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] );
3079 $json_data['widget_data']['widgetdata']['w_image'] = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
3080 }
3081
3082 $result = (object) array(
3083 'success' => false,
3084 'message' => ! empty( $response['message'] ) ? $response['message'] : esc_html__( 'no message', 'wdesignkit' ),
3085 'description' => '',
3086 'json' => wp_json_encode( $json_data ),
3087 );
3088
3089 wp_send_json( $result );
3090 wp_die();
3091 }
3092
3093 /**
3094 *
3095 * It is Use for sync widget to server
3096 *
3097 * @since 1.0.0
3098 */
3099 protected function wdkit_add_widget() {
3100 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
3101 $data = json_decode( stripslashes( $data ) );
3102
3103 $title = isset( $data->title ) ? sanitize_text_field( $data->title ) : '';
3104 $builder = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '';
3105 $w_uniq = isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '';
3106 $w_image = isset( $data->w_image ) ? esc_url_raw( $data->w_image ) : '';
3107
3108 if ( ! empty( $w_image ) ) {
3109 $w_image = str_replace( '\\', '', $w_image );
3110 $w_image = wp_remote_get( $w_image )['body'];
3111 }
3112
3113 $array_data = array(
3114 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
3115 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
3116 'title' => isset( $data->title ) ? sanitize_text_field( $data->title ) : '',
3117 'content' => isset( $data->content ) ? sanitize_text_field( $data->content ) : '',
3118 'builder' => isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '',
3119 'w_data' => isset( $data->w_data ) ? $data->w_data : '',
3120 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
3121 'w_image' => $w_image,
3122 'w_imgext' => isset( $data->w_imgext ) ? sanitize_text_field( $data->w_imgext ) : '',
3123 'w_version' => isset( $data->w_version ) ? $data->w_version : '',
3124 'w_updates' => ! empty( $data->w_updates ) ? serialize( $data->w_updates ) : serialize( array() ),
3125 'r_id' => isset( $data->r_id ) ? $data->r_id : 0,
3126 );
3127
3128 $response = $this->wkit_api_call( $array_data, 'save_widget' );
3129 $success = ! empty( $response['success'] ) ? $response['success'] : false;
3130
3131 if ( empty( $success ) ) {
3132 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
3133
3134 $result = (object) array(
3135 'success' => false,
3136 'message' => $massage,
3137 'description' => esc_html__( 'Widget Not Added', 'wdesignkit' ),
3138 );
3139
3140 wp_send_json( $result );
3141 wp_die();
3142 }
3143
3144 $res = ! empty( $response['data'] ) ? $response['data'] : array();
3145
3146 $response = json_decode( wp_json_encode( $res ), true );
3147 $img_url = ! empty( $response['data']['imgurl'] ) ? $response['data']['imgurl'] : '';
3148
3149 if ( ! empty( $img_url ) && 'error' !== $res ) {
3150 $img_body = wp_remote_get( $img_url );
3151 $img_ext = pathinfo( $img_url )['extension'];
3152 include_once ABSPATH . 'wp-admin/includes/file.php';
3153 \WP_Filesystem();
3154 global $wp_filesystem;
3155 $folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
3156 $file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
3157 $file_path = WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name";
3158
3159 $u_r_l = wp_json_file_decode( "$file_path.json" );
3160 $u_r_l->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
3161
3162 $wp_filesystem->put_contents( "$file_path.json", wp_json_encode( $u_r_l ) );
3163 $wp_filesystem->put_contents( "$file_path.$img_ext", $img_body['body'] );
3164 }
3165
3166 wp_send_json( $response );
3167 wp_die();
3168 }
3169
3170 /**
3171 *
3172 * It is Use for manage favourite widget
3173 *
3174 * @since 1.0.0
3175 */
3176 protected function wdkit_favourite_widget() {
3177 $data = isset( $_POST['widget_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['widget_info'] ) ) ) ) : '';
3178 $array_data = array(
3179 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
3180 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
3181 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
3182 );
3183
3184 $response = $this->wkit_api_call( $array_data, 'save_widget' );
3185 $success = ! empty( $response['success'] ) ? $response['success'] : false;
3186
3187 if ( empty( $success ) ) {
3188 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
3189
3190 $result = (object) array(
3191 'success' => false,
3192 'message' => $massage,
3193 'description' => '',
3194 );
3195
3196 wp_send_json( $result );
3197 wp_die();
3198 }
3199
3200 wp_send_json( $response );
3201 wp_die();
3202 }
3203
3204 /**
3205 * It is Used Setting Panel Defalut Data Get.
3206 *
3207 * @since 1.0.0
3208 */
3209 protected function wdkit_setting_panel() {
3210 $event = ! empty( $_POST['event'] ) ? sanitize_text_field( wp_unslash( $_POST['event'] ) ) : 'get';
3211
3212 if ( 'get' === $event ) {
3213 return self::wkit_get_settings_panel();
3214 } elseif ( 'set' === $event ) {
3215 $data = ! empty( $_POST['data'] ) ? stripslashes( sanitize_text_field( wp_unslash( $_POST['data'] ) ) ) : array();
3216
3217 $data = json_decode( $data, true );
3218
3219 update_option( 'wkit_settings_panel', $data );
3220 return self::wkit_get_settings_panel();
3221 } else {
3222 return false;
3223 }
3224 }
3225
3226 /**
3227 * Get Setting Panal Data
3228 *
3229 * @since 1.0.0
3230 */
3231 protected static function wkit_get_settings_panel() {
3232 $new_version = '';
3233 $current_version = WDKIT_VERSION;
3234 $response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/wdesignkit.json' );
3235
3236 if ( is_wp_error( $response ) ) {
3237 return false;
3238 }
3239
3240 $body = wp_remote_retrieve_body( $response );
3241 $data = json_decode( $body );
3242
3243 if ( isset( $data->version ) ) {
3244 $new_version = $data->version;
3245 }
3246
3247 $version_check = array();
3248
3249 if ( $new_version && version_compare( $current_version, $new_version, '<' ) ) {
3250 $version_check['success'] = true;
3251 $version_check['version'] = $new_version;
3252 } else {
3253 $version_check['success'] = false;
3254 $version_check['version'] = $new_version;
3255 }
3256
3257 $get_setting = get_option( 'wkit_settings_panel', false );
3258
3259 $setting_data = array(
3260 'builder' => isset( $get_setting['builder'] ) ? $get_setting['builder'] : true,
3261 'template' => isset( $get_setting['template'] ) ? $get_setting['template'] : true,
3262 'gutenberg_builder' => isset( $get_setting['gutenberg_builder'] ) ? $get_setting['gutenberg_builder'] : true,
3263 'elementor_builder' => isset( $get_setting['elementor_builder'] ) ? $get_setting['elementor_builder'] : true,
3264 'bricks_builder' => isset( $get_setting['bricks_builder'] ) ? $get_setting['bricks_builder'] : false,
3265 'gutenberg_template' => isset( $get_setting['gutenberg_template'] ) ? $get_setting['gutenberg_template'] : true,
3266 'elementor_template' => isset( $get_setting['elementor_template'] ) ? $get_setting['elementor_template'] : true,
3267 'plugin_version' => $version_check
3268 );
3269
3270 if(isset( $get_setting['remove_db'] )){
3271 $setting_data['remove_db'] = $get_setting['remove_db'];
3272 }
3273
3274 if(isset( $get_setting['debugger_mode'] )){
3275 $setting_data['debugger_mode'] = $get_setting['debugger_mode'];
3276 }
3277
3278 return $setting_data;
3279 }
3280
3281 /**
3282 * Updated White Label Data.
3283 *
3284 * @since 1.1.8
3285 */
3286 protected function wkit_white_label() {
3287
3288 $get_wl_data = !empty( $_POST['WhiteLabelData'] ) ? wp_unslash( $_POST['WhiteLabelData'] ) : array();
3289
3290 if ( !empty( $get_wl_data ) ) {
3291 $white_label_data = json_decode($get_wl_data, true);
3292 $plugin_name = $white_label_data['plugin_name'];
3293 }else{
3294 $result = array(
3295 'success' => false,
3296 'message' => esc_html__('Data Not Found', 'wdesignkit'),
3297 );
3298
3299 wp_send_json( $result );
3300 wp_die();
3301 }
3302
3303 if (!empty($plugin_name)) {
3304 $get_white_label = get_option('wkit_white_label', false);
3305 if (!empty($get_white_label)) {
3306 update_option( 'wkit_white_label', $white_label_data );
3307 }else{
3308 add_option( 'wkit_white_label', $white_label_data );
3309 }
3310 }else{
3311 $result = array(
3312 'success' => false,
3313 'message' => esc_html__('Plugin Name Not Found', 'wdesignkit'),
3314 );
3315
3316 wp_send_json( $result );
3317 wp_die();
3318 }
3319
3320 $get_updated_data = get_option('wkit_white_label', false);
3321 $response = array(
3322 'message' => 'Data Added successfully',
3323 'success' => true,
3324 'data' => $get_updated_data,
3325 );
3326
3327 wp_send_json( $response );
3328 }
3329
3330 /**
3331 * Reset White Label Data.
3332 *
3333 * @since 1.1.8
3334 */
3335 public function wkit_reset_wl() {
3336 $wl_data = get_option('wkit_white_label');
3337
3338 if ( !empty( $wl_data ) ) {
3339 delete_option('wkit_white_label');
3340
3341 $result = array(
3342 'success' => true,
3343 'message' => esc_html__('Reset White Label Successfully', 'wdesignkit'),
3344 );
3345
3346 wp_send_json( $result );
3347 wp_die();
3348 }
3349 }
3350
3351 /**
3352 *
3353 * Use for Add new licence key.
3354 *
3355 * @since 1.0.0
3356 */
3357 protected function wdkit_activate_licence() {
3358 $args = array(
3359 'token' => ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
3360 'licencekey' => ! empty( $_POST['licencekey'] ) ? sanitize_text_field( wp_unslash( $_POST['licencekey'] ) ) : '',
3361 'licencename' => ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '',
3362 'uichemyid' => ! empty( $_POST['uichemyid'] ) ? sanitize_text_field( wp_unslash( $_POST['uichemyid'] ) ) : '',
3363 );
3364
3365 $response = $this->wkit_api_call( $args, 'wkit_activate_key' );
3366
3367 wp_send_json( $response['data'] );
3368 wp_die();
3369 }
3370
3371 /**
3372 *
3373 * Use for Delete licence key.
3374 *
3375 * @since 1.0.0
3376 */
3377 protected function wdkit_delete_licence_key() {
3378 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
3379 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
3380 $apikey = ! empty( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : '';
3381
3382 $args = array(
3383 'token' => $token,
3384 'licencename' => $licencename,
3385 'apikey' => $apikey,
3386 );
3387
3388 $response = $this->wkit_api_call( $args, 'licence_delete' );
3389
3390 wp_send_json( $response['data'] );
3391 wp_die();
3392 }
3393
3394 /**
3395 *
3396 * Use for Sync licence key.
3397 *
3398 * @since 1.0.0
3399 */
3400 protected function wdkit_sync_licence_key() {
3401 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
3402 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
3403
3404 $args = array(
3405 'token' => $token,
3406 'licencename' => $licencename,
3407 );
3408
3409 $response = $this->wkit_api_call( $args, 'licence_sync' );
3410
3411 wp_send_json( $response['data'] );
3412 wp_die();
3413 }
3414
3415 /**
3416 * Rollback to Previous Versions
3417 *
3418 * @since 1.1.0
3419 */
3420 protected function wdkit_prev_version() {
3421
3422 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
3423
3424 $plugin_info = plugins_api(
3425 'plugin_information',
3426 array(
3427 'slug' => 'wdesignkit',
3428 )
3429 );
3430
3431 if ( empty( $plugin_info->versions ) || ! is_array( $plugin_info->versions ) ) {
3432 return array();
3433 }
3434
3435 krsort( $plugin_info->versions );
3436
3437 $versions_list = array();
3438 $index = 0;
3439
3440 foreach ( $plugin_info->versions as $version => $download_link ) {
3441
3442 $lowercase_version = strtolower( $version );
3443
3444 $is_valid_version = ! preg_match( '/(beta|rc|trunk|dev)/i', $lowercase_version );
3445
3446 $is_valid_version = apply_filters( 'wdkit_check_rollback_version', $is_valid_version, $lowercase_version );
3447
3448 if ( ! $is_valid_version || version_compare( $version, WDKIT_VERSION, '>=' ) ) {
3449 continue;
3450 }
3451
3452 $versions_list[] = $version;
3453 ++$index;
3454 }
3455
3456 // set_transient( 'wdkit_rollback_version_' . WDKIT_VERSION, $versions_list, WEEK_IN_SECONDS );
3457
3458 return $versions_list;
3459 }
3460
3461 /**
3462 * Rollback to Previous Versions
3463 *
3464 * @since 1.1.0
3465 */
3466 protected function wdkit_rollback_check() {
3467
3468 $current_ver = isset( $_POST['version'] ) ? sanitize_text_field( wp_unslash( $_POST['version'] ) ) : '';
3469 $rv = $this->wdkit_prev_version();
3470
3471 if ( empty( $current_ver ) || ! in_array( $current_ver, $rv) ) {
3472 return array(
3473 'message' => esc_html__( 'Invalid Nonce or version not found', 'wdesignkit' ),
3474 'status' => 'error',
3475 'success' => false,
3476 );
3477 }
3478
3479 $plugin_slug = basename( WDKIT_PBNAME, '.php' );
3480
3481 $this_version = $current_ver;
3482 $this_pluginname = WDKIT_PBNAME;
3483 $this_plugin_u_r_l = sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $this_version );
3484
3485 $plugin_info = new \stdClass();
3486 $plugin_info->new_version = $this_version;
3487 $plugin_info->slug = $plugin_slug;
3488 $plugin_info->package = $this_plugin_u_r_l;
3489 $plugin_info->url = 'https://wdesignkit.com/';
3490
3491 $update_plugins_data = get_site_transient( 'update_plugins' );
3492
3493 if ( ! is_object( $update_plugins_data ) ) {
3494 $update_plugins_data = new \stdClass();
3495 }
3496
3497 $update_plugins_data->response[ $this_pluginname ] = $plugin_info;
3498
3499 set_site_transient( 'update_plugins', $update_plugins_data );
3500
3501 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
3502
3503 $logo_url = WDKIT_URL . 'assets/images/jpg/Wdesignkit-logo.png';
3504
3505 $args = array(
3506 'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this_pluginname ),
3507 'plugin' => $this_pluginname,
3508 'nonce' => 'upgrade-plugin_' . $this_pluginname,
3509 'title' => '<img src="' . esc_url( $logo_url ) . '" alt="wdesignkit-logo"><div class="theplus-rb-subtitle">' . esc_html__( 'Rollback to Previous Version', 'wdesignkit' ) . '</div>',
3510 );
3511
3512 $upgrader_plugin = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $args ) );
3513 $upgrader_plugin->upgrade( $this_pluginname );
3514
3515 activate_plugin( $this_pluginname );
3516
3517 return array(
3518 'message' => esc_html__( 'Rollback Successful, Plugin Re-activated', 'wdesignkit' ),
3519 'status' => 'Success',
3520 'success' => true,
3521 );
3522 }
3523
3524 /**
3525 *
3526 * It is Use for logout.
3527 *
3528 * @since 1.0.0
3529 */
3530 protected function wdkit_logout() {
3531 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
3532 $logout_type = isset( $_POST['logout_type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['logout_type'] ) ) ) : '';
3533
3534 $response = '';
3535
3536 if ( ! empty( $email ) ) {
3537 $token = $this->wdkit_login_user_token( $email );
3538 $args = array( 'token' => $token );
3539
3540 if ( 'session' !== $logout_type ) {
3541 delete_transient( 'wdkit_auth_' . $email );
3542 $response = WDesignKit_Data_Query::get_data( 'logout', $args );
3543 }
3544 }
3545
3546 wp_send_json( $response );
3547 wp_die();
3548 }
3549
3550 /**
3551 *
3552 * It is Use for get token of login user.
3553 *
3554 * @since 1.0.0
3555 *
3556 * @param string $email check user email.
3557 */
3558 protected function wdkit_login_user_token( $email = '' ) {
3559
3560 if ( ! empty( $email ) ) {
3561 $user_key = strstr( $email, '@', true );
3562 $get_login = get_transient( 'wdkit_auth_' . $user_key );
3563
3564 if ( ! empty( $get_login ) && ! empty( $get_login['token'] ) ) {
3565 return $get_login['token'];
3566 }
3567 }
3568
3569 return false;
3570 }
3571
3572 /**
3573 * Parse args $_POST
3574 *
3575 * @since 1.0.0
3576 *
3577 * @param string $data send all post data.
3578 * @param string $type store text data.
3579 * @param string $condition store text data.
3580 */
3581 protected function wdkit_sanitizer_bypass( $data, $type, $condition = 'none' ) {
3582
3583 if ( 'none' === $condition ) {
3584 return $data[ $type ];
3585 } elseif ( 'cr_widget' === $condition ) {
3586 return $data[ $type ];
3587 }
3588 }
3589
3590
3591 /**
3592 * Parse args $_POST
3593 *
3594 * @since 1.0.0
3595 *
3596 * @param string $data send all post data.
3597 */
3598 protected function wdkit_parse_args( $data = array() ) {
3599 if ( empty( $data ) ) {
3600 return array();
3601 }
3602
3603 $args = array();
3604 if ( isset( $data['email'] ) ) {
3605 $args['email'] = isset( $data['email'] ) ? sanitize_email( $data['email'] ) : '';
3606 }
3607
3608 if ( isset( $data['data'] ) ) {
3609 $args['data'] = isset( $data['data'] ) ? wp_unslash( $data['data'] ) : array();
3610 }
3611
3612 if ( isset( $data['plugins'] ) ) {
3613 $args['plugins'] = isset( $data['plugins'] ) ? wp_unslash( $data['plugins'] ) : array();
3614 }
3615
3616 if ( isset( $data['template_id'] ) ) {
3617 $args['template_id'] = isset( $data['template_id'] ) ? intval( strtolower( sanitize_text_field( $data['template_id'] ) ) ) : '';
3618 }
3619
3620 if ( isset( $data['builder'] ) ) {
3621 $args['builder'] = isset( $data['builder'] ) ? wp_unslash( $data['builder'] ) : '';
3622 }
3623
3624 if ( isset( $data['editor'] ) ) {
3625 $args['editor'] = isset( $data['editor'] ) ? sanitize_text_field( $data['editor'] ) : '';
3626 }
3627
3628 if ( isset( $data['type_upload'] ) ) {
3629 $args['type_upload'] = isset( $data['type_upload'] ) ? sanitize_text_field( $data['type_upload'] ) : '';
3630 }
3631
3632 if ( isset( $data['title'] ) ) {
3633 $args['title'] = isset( $data['title'] ) ? wp_strip_all_tags( $data['title'] ) : '';
3634 }
3635
3636 if ( isset( $data['template_type'] ) ) {
3637 $args['template_type'] = isset( $data['template_type'] ) ? sanitize_text_field( $data['template_type'] ) : '';
3638 }
3639
3640 if ( isset( $data['wstype'] ) ) {
3641 $args['wstype'] = isset( $data['wstype'] ) ? wp_strip_all_tags( $data['wstype'] ) : '';
3642 }
3643
3644 if ( isset( $data['wid'] ) ) {
3645 $args['wid'] = isset( $data['wid'] ) ? intval( strtolower( sanitize_text_field( $data['wid'] ) ) ) : '';
3646 }
3647
3648 if ( isset( $data['perpage'] ) ) {
3649 $args['perpage'] = isset( $data['perpage'] ) ? intval( strtolower( sanitize_text_field( $data['perpage'] ) ) ) : 12;
3650 }
3651
3652 if ( isset( $data['page'] ) ) {
3653 $args['page'] = isset( $data['page'] ) ? intval( strtolower( sanitize_text_field( $data['page'] ) ) ) : 1;
3654 }
3655
3656 if ( isset( $data['buildertype'] ) ) {
3657 $args['buildertype'] = isset( $data['buildertype'] ) ? sanitize_text_field( $data['buildertype'] ) : '';
3658 }
3659
3660 if ( isset( $data['search'] ) ) {
3661 $args['search'] = isset( $data['search'] ) ? sanitize_text_field( $data['search'] ) : '';
3662 }
3663
3664 if ( isset( $data['plugin'] ) ) {
3665 $args['plugin'] = isset( $data['plugin'] ) ? wp_unslash( $data['plugin'] ) : array();
3666 }
3667
3668 if ( isset( $data['plugin_exclude'] ) ) {
3669 $args['plugin_exclude'] = isset( $data['plugin_exclude'] ) ? wp_unslash( $data['plugin_exclude'] ) : array();
3670 }
3671
3672 // if ( isset( $data['global_color'] ) ) {
3673 // $args['global_color'] = isset( $data['global_color'] ) ? wp_unslash( $data['global_color'] ) : array();
3674 // }
3675
3676 // if ( isset( $data['global_font_family'] ) ) {
3677 // $args['global_font_family'] = isset( $data['global_font_family'] ) ? wp_unslash( $data['global_font_family'] ) : array();
3678 // }
3679
3680 if ( isset( $data['global_data'] ) ) {
3681 $args['global_data'] = isset( $data['global_data'] ) ? wp_unslash( $data['global_data'] ) : array();
3682 }
3683
3684 if ( isset( $data['tag'] ) ) {
3685 $args['tag'] = isset( $data['tag'] ) ? wp_unslash( $data['tag'] ) : array();
3686 }
3687
3688 if ( isset( $data['category'] ) ) {
3689 $args['category'] = isset( $data['category'] ) ? wp_unslash( $data['category'] ) : array();
3690 }
3691
3692 if ( isset( $data['free_pro'] ) ) {
3693 $args['free_pro'] = isset( $data['free_pro'] ) ? sanitize_text_field( wp_unslash( $data['free_pro'] ) ) : '';
3694 }
3695
3696 if ( isset( $data['wp_post_type'] ) ) {
3697 $args['wp_post_type'] = isset( $data['wp_post_type'] ) ? sanitize_text_field( wp_unslash( $data['wp_post_type'] ) ) : '';
3698 }
3699
3700 if ( isset( $data['favorite'] ) ) {
3701 $args['favorite'] = isset( $data['favorite'] ) ? sanitize_text_field( wp_unslash( $data['favorite'] ) ) : '';
3702 }
3703
3704 if ( isset( $data['content'] ) ) {
3705 $args['content'] = isset( $data['content'] ) ? wp_unslash( $data['content'] ) : '';
3706 }
3707
3708 if ( isset( $data['page_type'] ) ) {
3709 $args['page_type'] = isset( $data['page_type'] ) ? wp_unslash( $data['page_type'] ) : array();
3710 }
3711
3712 return $args;
3713 }
3714 }
3715
3716 Wdkit_Api_Call::get_instance();
3717 }