120,
'headers' => [
'Authorization' => 'Bearer ' . $api_key,
'Content-Type' => 'application/json',
],
'body' => json_encode([
'model' => 'gpt-4o-mini',
'messages' => [
[
'role' => 'user',
'content' => $gpt_prompt,
],
],
'temperature' => 0.7,
]),
]);
if (is_wp_error($result)) {
wp_send_json([
'success' => false,
'message' => 'API connection failed',
'description' => $result->get_error_message(),
]);
wp_die();
}
$response_code = wp_remote_retrieve_response_code($result);
if ($response_code !== 200) {
$body = wp_remote_retrieve_body($result);
$error_message = 'Unknown error occurred';
$decoded_body = json_decode($body, true);
if (isset($decoded_body['error']['message'])) {
$error_message = $decoded_body['error']['message'];
}
wp_send_json([
'success' => false,
'message' => "API returned status code $response_code",
'description' => $error_message,
'raw' => $decoded_body,
]);
wp_die();
}
$body = json_decode(wp_remote_retrieve_body($result), true);
if (!isset($body['choices'][0]['message']['content'])) {
wp_send_json([
'success' => false,
'message' => 'Unexpected API response format',
'description' => 'The expected content was not found in the API response.',
'raw' => $body,
]);
wp_die();
}
wp_send_json([
'success' => true,
'message' => 'Text content converted successfully',
'description' => 'Text content converted successfully',
'response' => $body['choices'][0]['message']['content'],
'raw' => $body,
]);
wp_die();
}
/**
* Share with Me Template and widgets
*
* @since 1.0.0
*/
protected function wdkit_shared_with_me() {
$data = isset( $_POST['api_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['api_info'] ) ) ) ) : '';
$array_data = array(
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
'type' => isset( $data->type ) ? sanitize_text_field( wp_unslash( $data->type ) ) : '',
'ParPage' => isset( $data->par_page ) ? (int) $data->par_page : 12,
'CurrentPage' => isset( $data->current_page ) ? (int) $data->current_page : 1,
'builder' => isset( $data->builder ) ? sanitize_text_field( wp_unslash( $data->builder ) ) : '',
);
$response = $this->wkit_api_call( $array_data, 'shared_with_me' );
$success = ! empty( $response['success'] ) ? $response['success'] : false;
wp_send_json( $response );
wp_die();
}
/**
* Add new WorkSpace
*
* @since 1.0.0
*/
protected function wdkit_manage_workspace() {
$args = $this->wdkit_parse_args( $_POST );
$user_email = ! empty( $args['email'] ) ? strtolower( sanitize_email( $args['email'] ) ) : '';
$current_wid = ! empty( $_POST['current_wid'] ) ? strtolower( sanitize_text_field( $_POST['current_wid'] ) ) : '';
$args['current_wid'] = $current_wid;
if ( empty( $user_email ) ) {
$response = array(
'message' => $this->e_msg_login,
'description' => $this->e_desc_login,
'success' => false,
);
wp_send_json( $response );
wp_die();
}
$args['token'] = $this->wdkit_login_user_token( $user_email );
unset( $user_email );
$response = WDesignKit_Data_Query::get_data( 'manage_workspace', $args );
return $response;
}
/**
*
* It is Use for manage workspace
*
* @since 1.0.0
*/
protected function wdkit_manage_widget_workspace() {
$workspace_info = isset( $_POST['workspace_info'] ) ? sanitize_text_field( wp_unslash( $_POST['workspace_info'] ) ) : array();
$data = isset( $workspace_info ) ? json_decode( stripslashes( $workspace_info ) ) : array();
$array_data = array(
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
'wstype' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
'widget_id' => isset( $data->widget_id ) ? (int) $data->widget_id : '',
'wid' => isset( $data->wid ) ? (int) $data->wid : '',
'current_wid' => isset( $data->current_wid ) ? (int) $data->current_wid : '',
);
$response = $this->wkit_api_call( $array_data, 'manage_workspace' );
wp_send_json( $response['data'] );
wp_die();
}
/**
*
* It is Use for manage api key page
*
* @since 1.0.0
*/
protected function wdkit_activate_key() {
$email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '';
$response = '';
if ( empty( $user_email ) ) {
$response = array(
'message' => $this->e_msg_login,
'description' => $this->e_desc_login,
'success' => false,
);
wp_send_json( $response );
wp_die();
}
$token = $this->wdkit_login_user_token( $email );
$apikey = isset( $_POST['apikey'] ) ? sanitize_key( wp_unslash( $_POST['apikey'] ) ) : '';
$product = isset( $_POST['product'] ) ? sanitize_text_field( wp_unslash( $_POST['product'] ) ) : '';
$product_action = isset( $_POST['product_action'] ) ? sanitize_text_field( wp_unslash( $_POST['product_action'] ) ) : 'activate';
if ( ! empty( $token ) && ! empty( $product ) && ! empty( $product_action ) ) {
$args = array(
'token' => $token,
'product' => $product,
'product_action' => $product_action,
);
if ( 'activate' === $product_action ) {
$args['apikey'] = $apikey;
$args['site_url'] = home_url();
}
$response = Wdkit_Data_Hooks::get_data( 'wkit_activate_key', $args );
}
wp_send_json( $response );
wp_die();
}
/**
*
* Get list local Widget List
*
* @since 1.0.0
*/
protected function wdkit_get_local_widgets() {
$builder = array();
$a_c_s_d_s_c = array();
$j_s_o_n_array = array();
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'bricks', 'widget' ) ) {
array_push( $builder, 'bricks' );
}
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor', 'widget' ) ) {
array_push( $builder, 'elementor' );
}
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) {
array_push( $builder, 'gutenberg' );
}
foreach ( $builder as $key => $name ) {
$elementor_dir = WDKIT_BUILDER_PATH . '/' . $name;
if ( ! empty( $elementor_dir ) && is_dir( $elementor_dir ) ) {
$elementor_list = scandir( $elementor_dir );
$elementor_list = array_diff( $elementor_list, array( '.', '..' ) );
if ( ! empty( $elementor_list ) ) {
foreach ( $elementor_list as $key => $value ) {
$a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) . $key]['data'] = $value;
$a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) . $key]['builder'] = $name;
}
}
}
}
ksort( $a_c_s_d_s_c );
$a_c_s_d_s_c = array_reverse( $a_c_s_d_s_c );
foreach ( $a_c_s_d_s_c as $key => $value ) {
$elementor_dir = WDKIT_BUILDER_PATH . '/' . $value['builder'];
if ( file_exists( "{$elementor_dir}/{$value['data']}" ) && is_dir( "{$elementor_dir}/{$value['data']}" ) ) {
$sub_dir = scandir( "{$elementor_dir}/{$value['data']}" );
$sub = array_diff( $sub_dir, array( '.', '..' ) );
foreach ( $sub as $sub_dir_value ) {
$file = new SplFileInfo( $sub_dir_value );
$check_ext = $file->getExtension();
$ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
if ( 'json' === $ext ) {
$widget1 = WDKIT_BUILDER_PATH . "/{$value['builder']}/{$value['data']}/{$sub_dir_value}";
$filedata = wp_json_file_decode( $widget1 );
$decode_data = json_decode( wp_json_encode( $filedata ), true );
array_push( $j_s_o_n_array, $decode_data['widget_data'] );
}
}
}
}
return $j_s_o_n_array;
}
/**
*
* It is Use for manage widget category.
*
* @since 1.0.0
*/
protected function wdkit_manage_widget_category() {
$data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : '';
$data = json_decode( stripslashes( $data ) );
$type = isset( $data->manage_type ) ? sanitize_text_field( wp_unslash( $data->manage_type ) ) : '';
$wkit_builder_option = get_option( 'wkit_builder' );
if ( empty( $wkit_builder_option ) ) {
add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' );
}
if ( 'get' === $type ) {
if ( ! in_array( 'WDesignKit', $wkit_builder_option ) ) {
update_option( 'wkit_builder', array( 'WDesignKit' ) );
}
} elseif ( 'update' === $type ) {
$list = isset( $data->category_list ) ? $data->category_list : array();
$list = array_unique( $list );
$list = array_values( $list );
if ( ! empty( $list ) ) {
update_option( 'wkit_builder', $list );
}
}
wp_send_json( get_option( 'wkit_builder' ) );
}
/**
*
* Custom_upload_dir
*
* @since 1.0.0
*
* @param array $upload store data.
*/
public function custom_upload_dir( $upload ) {
// Specify the path to your custom upload directory.
if ( isset( $this->widget_folder_u_r_l ) && ! empty( $this->widget_folder_u_r_l ) ) {
// Set the custom directory as the upload path.
$upload['path'] = $this->widget_folder_u_r_l;
// Set the URL for the uploaded file.
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
}
return $upload;
}
/**
*
* It is Use for delete widget from server
*
* @since 1.0.0
*/
protected function wkit_widget_json() {
$widget_type = !empty( $_POST['widget_type'] ) ? wp_unslash( $_POST['widget_type'] ) : '';
$folder_name = !empty( $_POST['folder_name'] ) ? wp_unslash( $_POST['folder_name'] ) : '';
$file_name = !empty( $_POST['file_name'] ) ? ( wp_unslash( $_POST['file_name'] ) ) : '';
if ( empty( $widget_type ) || empty( $folder_name ) || empty( $file_name ) ) {
return array(
'success' => false,
'message' => esc_html__( 'Widget JSON not found', 'wdesignkit' ),
'description' => esc_html__( 'widget JSON file not found.', 'wdesignkit' ),
);
}
$json_path = WDKIT_BUILDER_PATH . "/{$widget_type}/{$folder_name}/{$file_name}";
$json_data = wp_json_file_decode( "$json_path.json" );
if ( ! empty( $json_data ) ) {
$result = (object) array(
'success' => true,
'data' => $json_data,
'message' => esc_html__( 'Widget get Successfully', 'wdesignkit' ),
'description' => esc_html__( 'Widget JSON get Successfully', 'wdesignkit' ),
);
} else {
$result = (object) array(
'success' => false,
'message' => esc_html__( 'Widget not get', 'wdesignkit' ),
'description' => esc_html__( 'Widget JSON not get', 'wdesignkit' ),
);
}
wp_send_json( $result );
wp_die();
}
/**
*
* It is Use for download widget from widget listing.
*
* @since 1.0.0
*/
protected function wdkit_download_widget() {
$data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
$data = json_decode( stripslashes( $data ) );
$array_data = array(
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
);
$response = $this->wkit_api_call( $array_data, 'save_widget' );
$success = ! empty( $response['success'] ) ? $response['success'] : false;
if ( empty( $success ) ) {
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
$result = (object) array(
'success' => false,
'message' => $massage,
'description' => esc_html__( ' Widget not Downloaded', 'wdesignkit' ),
);
wp_send_json( $result );
wp_die();
}
$response = json_decode( wp_json_encode( $response['data'] ), true );
if ( empty( $response ) || empty( $response['data'] ) ) {
$message = ! empty( $response['message'] ) ? $response['message'] : 'No Response Found';
$description = ! empty( $response['description'] ) ? $response['description'] : 'Widget not Downloaded';
$result = (object) array(
'success' => false,
'message' => esc_html( $message ),
'description' => esc_html( $description ),
);
wp_send_json( $result );
wp_die();
}
$img_url = ! empty( $response['data']['image'] ) ? $response['data']['image'] : '';
$json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'], true ) : '';
if( empty( $response['success'] ) ){
wp_send_json( $responce );
wp_die();
}
if ( empty( $img_url ) && empty( $json_data ) ) {
$responce = (object) array(
'success' => false,
'message' => esc_html__( 'No Response Found', 'wdesignkit' ),
'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ),
);
wp_send_json( $responce );
wp_die();
}
include_once ABSPATH . 'wp-admin/includes/file.php';
\WP_Filesystem();
global $wp_filesystem;
if( !is_array($json_data) ){
$json_data = json_decode( $json_data, true );
}
$title = ! empty( $json_data['widget_data']['widgetdata']['name'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['name'] ) : '';
$builder = ! empty( $json_data['widget_data']['widgetdata']['type'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['type'] ) : '';
$w_uniq = ! empty( $json_data['widget_data']['widgetdata']['widget_id'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['widget_id'] ) : '';
$folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
$file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
$builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/";
if ( ! is_dir( $builder_type_path ) ) {
wp_mkdir_p( $builder_type_path );
}
if ( ! is_dir( $builder_type_path . $folder_name ) ) {
wp_mkdir_p( $builder_type_path . $folder_name );
}
if ( ! empty( $img_url ) ) {
$img_body = wp_remote_get( $img_url );
$img_ext = pathinfo( $img_url )['extension'];
$wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] );
$json_data['widget_data']['widgetdata']['w_image'] = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
}
$result = (object) array(
'success' => false,
'message' => ! empty( $response['message'] ) ? $response['message'] : esc_html__( 'no message', 'wdesignkit' ),
'description' => '',
'json' => wp_json_encode( $json_data ),
);
wp_send_json( $result );
wp_die();
}
/**
*
* It is Use for sync widget to server
*
* @since 1.0.0
*/
protected function wdkit_add_widget() {
$data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
$data = json_decode( stripslashes( $data ) );
$title = isset( $data->title ) ? sanitize_text_field( $data->title ) : '';
$builder = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '';
$w_uniq = isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '';
$w_image = isset( $data->w_image ) ? esc_url_raw( $data->w_image ) : '';
if ( ! empty( $w_image ) ) {
$w_image = str_replace( '\\', '', $w_image );
$w_image = wp_remote_get( $w_image )['body'];
}
$array_data = array(
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
'title' => isset( $data->title ) ? sanitize_text_field( $data->title ) : '',
'content' => isset( $data->content ) ? sanitize_text_field( $data->content ) : '',
'builder' => isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '',
'w_data' => isset( $data->w_data ) ? $data->w_data : '',
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
'w_image' => $w_image,
'w_imgext' => isset( $data->w_imgext ) ? sanitize_text_field( $data->w_imgext ) : '',
'w_version' => isset( $data->w_version ) ? $data->w_version : '',
'w_updates' => ! empty( $data->w_updates ) ? serialize( $data->w_updates ) : serialize( array() ),
'r_id' => isset( $data->r_id ) ? $data->r_id : 0,
);
$response = $this->wkit_api_call( $array_data, 'save_widget' );
$success = ! empty( $response['success'] ) ? $response['success'] : false;
if ( empty( $success ) ) {
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
$result = (object) array(
'success' => false,
'message' => $massage,
'description' => esc_html__( 'Widget Not Added', 'wdesignkit' ),
);
wp_send_json( $result );
wp_die();
}
$res = ! empty( $response['data'] ) ? $response['data'] : array();
$response = json_decode( wp_json_encode( $res ), true );
$img_url = ! empty( $response['data']['imgurl'] ) ? $response['data']['imgurl'] : '';
if ( ! empty( $img_url ) && 'error' !== $res ) {
$img_body = wp_remote_get( $img_url );
$img_ext = pathinfo( $img_url )['extension'];
include_once ABSPATH . 'wp-admin/includes/file.php';
\WP_Filesystem();
global $wp_filesystem;
$folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
$file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
$file_path = WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name";
$u_r_l = wp_json_file_decode( "$file_path.json" );
$u_r_l->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
$wp_filesystem->put_contents( "$file_path.json", wp_json_encode( $u_r_l ) );
$wp_filesystem->put_contents( "$file_path.$img_ext", $img_body['body'] );
}
wp_send_json( $response );
wp_die();
}
/**
*
* It is Use for manage favourite widget
*
* @since 1.0.0
*/
protected function wdkit_favourite_widget() {
$data = isset( $_POST['widget_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['widget_info'] ) ) ) ) : '';
$array_data = array(
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
);
$response = $this->wkit_api_call( $array_data, 'save_widget' );
$success = ! empty( $response['success'] ) ? $response['success'] : false;
if ( empty( $success ) ) {
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
$result = (object) array(
'success' => false,
'message' => $massage,
'description' => '',
);
wp_send_json( $result );
wp_die();
}
wp_send_json( $response );
wp_die();
}
/**
* It is Used Setting Panel Defalut Data Get.
*
* @since 1.0.0
*/
protected function wdkit_setting_panel() {
$event = ! empty( $_POST['event'] ) ? sanitize_text_field( wp_unslash( $_POST['event'] ) ) : 'get';
if ( 'get' === $event ) {
return self::wkit_get_settings_panel();
} elseif ( 'set' === $event ) {
$data = ! empty( $_POST['data'] ) ? stripslashes( sanitize_text_field( wp_unslash( $_POST['data'] ) ) ) : array();
$data = json_decode( $data, true );
update_option( 'wkit_settings_panel', $data );
return self::wkit_get_settings_panel();
} else {
return false;
}
}
/**
* Get Setting Panal Data
*
* @since 1.0.0
*/
protected static function wkit_get_settings_panel() {
$new_version = '';
$current_version = WDKIT_VERSION;
$response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/wdesignkit.json' );
if ( is_wp_error( $response ) ) {
return false;
}
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body );
if ( isset( $data->version ) ) {
$new_version = $data->version;
}
$version_check = array();
if ( $new_version && version_compare( $current_version, $new_version, '<' ) ) {
$version_check['success'] = true;
$version_check['version'] = $new_version;
} else {
$version_check['success'] = false;
$version_check['version'] = $new_version;
}
$get_setting = get_option( 'wkit_settings_panel', false );
$setting_data = array(
'builder' => isset( $get_setting['builder'] ) ? $get_setting['builder'] : true,
'template' => isset( $get_setting['template'] ) ? $get_setting['template'] : true,
'gutenberg_builder' => isset( $get_setting['gutenberg_builder'] ) ? $get_setting['gutenberg_builder'] : true,
'elementor_builder' => isset( $get_setting['elementor_builder'] ) ? $get_setting['elementor_builder'] : true,
'bricks_builder' => isset( $get_setting['bricks_builder'] ) ? $get_setting['bricks_builder'] : false,
'gutenberg_template' => isset( $get_setting['gutenberg_template'] ) ? $get_setting['gutenberg_template'] : true,
'elementor_template' => isset( $get_setting['elementor_template'] ) ? $get_setting['elementor_template'] : true,
'code_snippet' => isset( $get_setting['code_snippet'] ) ? $get_setting['code_snippet'] : true,
'plugin_version' => $version_check
);
if(isset( $get_setting['remove_db'] )){
$setting_data['remove_db'] = $get_setting['remove_db'];
}
if(isset( $get_setting['debugger_mode'] )){
$setting_data['debugger_mode'] = $get_setting['debugger_mode'];
}
return $setting_data;
}
/**
* Updated White Label Data.
*
* @since 1.1.8
*/
protected function wkit_white_label() {
$get_wl_data = !empty( $_POST['WhiteLabelData'] ) ? wp_unslash( $_POST['WhiteLabelData'] ) : array();
if ( !empty( $get_wl_data ) ) {
$white_label_data = json_decode($get_wl_data, true);
$plugin_name = $white_label_data['plugin_name'];
}else{
$result = array(
'success' => false,
'message' => esc_html__('Data Not Found', 'wdesignkit'),
);
wp_send_json( $result );
wp_die();
}
if (!empty($plugin_name)) {
$get_white_label = get_option('wkit_white_label', false);
if (!empty($get_white_label)) {
update_option( 'wkit_white_label', $white_label_data );
}else{
add_option( 'wkit_white_label', $white_label_data );
}
}else{
$result = array(
'success' => false,
'message' => esc_html__('Plugin Name Not Found', 'wdesignkit'),
);
wp_send_json( $result );
wp_die();
}
$get_updated_data = get_option('wkit_white_label', false);
$response = array(
'message' => 'Data Added successfully',
'success' => true,
'data' => $get_updated_data,
);
wp_send_json( $response );
}
/**
* Reset White Label Data.
*
* @since 1.1.8
*/
public function wkit_reset_wl() {
$wl_data = get_option('wkit_white_label');
if ( !empty( $wl_data ) ) {
delete_option('wkit_white_label');
$result = array(
'success' => true,
'message' => esc_html__('Reset White Label Successfully', 'wdesignkit'),
);
wp_send_json( $result );
wp_die();
}
}
/**
*
* Use for Add new licence key.
*
* @since 1.0.0
*/
protected function wdkit_activate_licence() {
$args = array(
'token' => ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
'licencekey' => ! empty( $_POST['licencekey'] ) ? sanitize_text_field( wp_unslash( $_POST['licencekey'] ) ) : '',
'licencename' => ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '',
'uichemyid' => ! empty( $_POST['uichemyid'] ) ? sanitize_text_field( wp_unslash( $_POST['uichemyid'] ) ) : '',
);
$response = $this->wkit_api_call( $args, 'wkit_activate_key' );
if( !empty( $response['data'] ) ){
$response = json_decode( wp_json_encode( $response['data'] ), true );
if( !empty($response['data']['tpae_licence']) && is_serialized($response['data']['tpae_licence'])){
$response['data']['tpae_licence'] = unserialize($response['data']['tpae_licence']);
}
if( !empty($response['data']['tpag_licence']) && is_serialized($response['data']['tpag_licence'])){
$response['data']['tpag_licence'] = unserialize($response['data']['tpag_licence']);
}
if( !empty($response['data']['uichemy_licence']) && is_serialized($response['data']['uichemy_licence'])){
$response['data']['uichemy_licence'] = unserialize($response['data']['uichemy_licence']);
}
if( !empty($response['data']['wdkit_licence']) && is_serialized($response['data']['wdkit_licence'])){
$response['data']['wdkit_licence'] = unserialize($response['data']['wdkit_licence']);
}
if( !empty($response['data']['wdkit_licence_extra']) && is_serialized($response['data']['wdkit_licence_extra'])){
$response['data']['wdkit_licence_extra'] = unserialize($response['data']['wdkit_licence_extra']);
}
}
wp_send_json( $response );
wp_die();
}
/**
*
* Use for Delete licence key.
*
* @since 1.0.0
*/
protected function wdkit_delete_licence_key() {
$token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
$licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
$apikey = ! empty( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : '';
$args = array(
'token' => $token,
'licencename' => $licencename,
'apikey' => $apikey,
);
$response = $this->wkit_api_call( $args, 'licence_delete' );
wp_send_json( $response['data'] );
wp_die();
}
/**
*
* Use for Sync licence key.
*
* @since 1.0.0
*/
protected function wdkit_sync_licence_key() {
$token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
$licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
$args = array(
'token' => $token,
'licencename' => $licencename,
);
$response = $this->wkit_api_call( $args, 'licence_sync' );
wp_send_json( $response['data'] );
wp_die();
}
/**
* Rollback to Previous Versions
*
* @since 1.1.0
*/
protected function wdkit_prev_version() {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$plugin_info = plugins_api(
'plugin_information',
array(
'slug' => 'wdesignkit',
)
);
if ( empty( $plugin_info->versions ) || ! is_array( $plugin_info->versions ) ) {
return array();
}
krsort( $plugin_info->versions );
$versions_list = array();
$index = 0;
foreach ( $plugin_info->versions as $version => $download_link ) {
$lowercase_version = strtolower( $version );
$is_valid_version = ! preg_match( '/(beta|rc|trunk|dev)/i', $lowercase_version );
$is_valid_version = apply_filters( 'wdkit_check_rollback_version', $is_valid_version, $lowercase_version );
if ( ! $is_valid_version || version_compare( $version, WDKIT_VERSION, '>=' ) ) {
continue;
}
$versions_list[] = $version;
++$index;
}
// set_transient( 'wdkit_rollback_version_' . WDKIT_VERSION, $versions_list, WEEK_IN_SECONDS );
return $versions_list;
}
/**
* Rollback to Previous Versions
*
* @since 1.1.0
*/
protected function wdkit_rollback_check() {
$current_ver = isset( $_POST['version'] ) ? sanitize_text_field( wp_unslash( $_POST['version'] ) ) : '';
$rv = $this->wdkit_prev_version();
if ( empty( $current_ver ) || ! in_array( $current_ver, $rv) ) {
return array(
'message' => esc_html__( 'Invalid Nonce or version not found', 'wdesignkit' ),
'status' => 'error',
'success' => false,
);
}
$plugin_slug = basename( WDKIT_PBNAME, '.php' );
$this_version = $current_ver;
$this_pluginname = WDKIT_PBNAME;
$this_plugin_u_r_l = sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $this_version );
$plugin_info = new \stdClass();
$plugin_info->new_version = $this_version;
$plugin_info->slug = $plugin_slug;
$plugin_info->package = $this_plugin_u_r_l;
$plugin_info->url = 'https://wdesignkit.com/';
$update_plugins_data = get_site_transient( 'update_plugins' );
if ( ! is_object( $update_plugins_data ) ) {
$update_plugins_data = new \stdClass();
}
$update_plugins_data->response[ $this_pluginname ] = $plugin_info;
set_site_transient( 'update_plugins', $update_plugins_data );
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$logo_url = WDKIT_URL . 'assets/images/jpg/Wdesignkit-logo.png';
$args = array(
'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this_pluginname ),
'plugin' => $this_pluginname,
'nonce' => 'upgrade-plugin_' . $this_pluginname,
'title' => ' . ')
' . esc_html__( 'Rollback to Previous Version', 'wdesignkit' ) . '
',
);
$upgrader_plugin = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $args ) );
$upgrader_plugin->upgrade( $this_pluginname );
activate_plugin( $this_pluginname );
return array(
'message' => esc_html__( 'Rollback Successful, Plugin Re-activated', 'wdesignkit' ),
'status' => 'Success',
'success' => true,
);
}
/**
*
* It is Use for logout.
*
* @since 1.0.0
*/
protected function wdkit_logout() {
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
$logout_type = isset( $_POST['logout_type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['logout_type'] ) ) ) : '';
$response = '';
if ( ! empty( $email ) ) {
$token = $this->wdkit_login_user_token( $email );
$args = array( 'token' => $token );
if ( 'session' !== $logout_type ) {
delete_transient( 'wdkit_auth_' . $email );
$response = WDesignKit_Data_Query::get_data( 'logout', $args );
}
}
wp_send_json( $response );
wp_die();
}
/**
*
* It is Use for get token of login user.
*
* @since 1.0.0
*
* @param string $email check user email.
*/
protected function wdkit_login_user_token( $email = '' ) {
if ( ! empty( $email ) ) {
$user_key = strstr( $email, '@', true );
$get_login = get_transient( 'wdkit_auth_' . $user_key );
if ( ! empty( $get_login ) && ! empty( $get_login['token'] ) ) {
return $get_login['token'];
}
}
return false;
}
/**
* Parse args $_POST
*
* @since 1.0.0
*
* @param string $data send all post data.
* @param string $type store text data.
* @param string $condition store text data.
*/
protected function wdkit_sanitizer_bypass( $data, $type, $condition = 'none' ) {
if ( 'none' === $condition ) {
return $data[ $type ];
} elseif ( 'cr_widget' === $condition ) {
return $data[ $type ];
}
}
/**
* Parse args $_POST
*
* @since 1.0.0
*
* @param string $data send all post data.
*/
protected function wdkit_parse_args( $data = array() ) {
if ( empty( $data ) ) {
return array();
}
$args = array();
if ( isset( $data['email'] ) ) {
$args['email'] = isset( $data['email'] ) ? sanitize_email( $data['email'] ) : '';
}
if ( isset( $data['data'] ) ) {
$args['data'] = isset( $data['data'] ) ? wp_unslash( $data['data'] ) : array();
}
if ( isset( $data['plugins'] ) ) {
$args['plugins'] = isset( $data['plugins'] ) ? wp_unslash( $data['plugins'] ) : array();
}
if ( isset( $data['template_id'] ) ) {
$args['template_id'] = isset( $data['template_id'] ) ? intval( strtolower( sanitize_text_field( $data['template_id'] ) ) ) : '';
}
if ( isset( $data['builder'] ) ) {
$args['builder'] = isset( $data['builder'] ) ? wp_unslash( $data['builder'] ) : '';
}
if ( isset( $data['editor'] ) ) {
$args['editor'] = isset( $data['editor'] ) ? sanitize_text_field( $data['editor'] ) : '';
}
if ( isset( $data['type_upload'] ) ) {
$args['type_upload'] = isset( $data['type_upload'] ) ? sanitize_text_field( $data['type_upload'] ) : '';
}
if ( isset( $data['title'] ) ) {
$args['title'] = isset( $data['title'] ) ? wp_strip_all_tags( $data['title'] ) : '';
}
if ( isset( $data['template_type'] ) ) {
$args['template_type'] = isset( $data['template_type'] ) ? sanitize_text_field( $data['template_type'] ) : '';
}
if ( isset( $data['wstype'] ) ) {
$args['wstype'] = isset( $data['wstype'] ) ? wp_strip_all_tags( $data['wstype'] ) : '';
}
if ( isset( $data['wid'] ) ) {
$args['wid'] = isset( $data['wid'] ) ? intval( strtolower( sanitize_text_field( $data['wid'] ) ) ) : '';
}
if ( isset( $data['perpage'] ) ) {
$args['perpage'] = isset( $data['perpage'] ) ? intval( strtolower( sanitize_text_field( $data['perpage'] ) ) ) : 12;
}
if ( isset( $data['page'] ) ) {
$args['page'] = isset( $data['page'] ) ? intval( strtolower( sanitize_text_field( $data['page'] ) ) ) : 1;
}
if ( isset( $data['buildertype'] ) ) {
$args['buildertype'] = isset( $data['buildertype'] ) ? sanitize_text_field( $data['buildertype'] ) : '';
}
if ( isset( $data['search'] ) ) {
$args['search'] = isset( $data['search'] ) ? sanitize_text_field( $data['search'] ) : '';
}
if ( isset( $data['plugin'] ) ) {
$args['plugin'] = isset( $data['plugin'] ) ? wp_unslash( $data['plugin'] ) : array();
}
if ( isset( $data['plugin_exclude'] ) ) {
$args['plugin_exclude'] = isset( $data['plugin_exclude'] ) ? wp_unslash( $data['plugin_exclude'] ) : array();
}
// if ( isset( $data['global_color'] ) ) {
// $args['global_color'] = isset( $data['global_color'] ) ? wp_unslash( $data['global_color'] ) : array();
// }
// if ( isset( $data['global_font_family'] ) ) {
// $args['global_font_family'] = isset( $data['global_font_family'] ) ? wp_unslash( $data['global_font_family'] ) : array();
// }
if ( isset( $data['global_data'] ) ) {
$args['global_data'] = isset( $data['global_data'] ) ? wp_unslash( $data['global_data'] ) : array();
}
if ( isset( $data['tag'] ) ) {
$args['tag'] = isset( $data['tag'] ) ? wp_unslash( $data['tag'] ) : array();
}
if ( isset( $data['category'] ) ) {
$args['category'] = isset( $data['category'] ) ? wp_unslash( $data['category'] ) : array();
}
if ( isset( $data['free_pro'] ) ) {
$args['free_pro'] = isset( $data['free_pro'] ) ? sanitize_text_field( wp_unslash( $data['free_pro'] ) ) : '';
}
if ( isset( $data['wp_post_type'] ) ) {
$args['wp_post_type'] = isset( $data['wp_post_type'] ) ? sanitize_text_field( wp_unslash( $data['wp_post_type'] ) ) : '';
}
if ( isset( $data['favorite'] ) ) {
$args['favorite'] = isset( $data['favorite'] ) ? sanitize_text_field( wp_unslash( $data['favorite'] ) ) : '';
}
if ( isset( $data['content'] ) ) {
$args['content'] = isset( $data['content'] ) ? wp_unslash( $data['content'] ) : '';
}
if ( isset( $data['page_type'] ) ) {
$args['page_type'] = isset( $data['page_type'] ) ? wp_unslash( $data['page_type'] ) : array();
}
return $args;
}
/**
* Dark Mode
*
* @since 2.0.0
*
* @param string store darkmode value in database.
*/
protected function wdkit_dark_mode(){
$dark_mode = ! empty( $_POST['dark_mode'] ) ? sanitize_text_field( $_POST['dark_mode'] ) : 'light';
if (get_option('wdkit_dark_mode')) {
update_option('wdkit_dark_mode', $dark_mode);
} else {
add_option('wdkit_dark_mode', $dark_mode);
}
$response = array(
'message' => esc_html__( 'Dark Mode Updated', 'wdesignkit' ),
'status' => 'Success',
'success' => true,
);
wp_send_json( $response );
wp_die();
}
}
Wdkit_Api_Call::get_instance();
}