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