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 +1010 -3696 2.6.21.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();
@@ -135,84 +115,9 @@
135 115 wp_send_json_success( $data, $status );
136 116 wp_die();
137 117 }
138 118
139 -
140 119 /**
141 - * Memory headroom left for image work, in bytes. 0 means unlimited.
142 - */
143 - private static function wdkit_available_image_memory() {
144 - $limit = wp_convert_hr_to_bytes( ini_get( 'memory_limit' ) );
145 -
146 - if ( $limit <= 0 ) {
147 - return 0;
148 - }
149 -
150 - return max( 0, $limit - memory_get_usage( true ) );
151 - }
152 -
153 - /**
154 - * Stop WordPress decoding images that cannot fit in the memory available.
155 - *
156 - * Both filters are consulted by wp_create_image_subsizes() *before* it loads an image
157 - * editor, so refusing here means the oversized image is never decoded:
158 - *
159 - * big_image_size_threshold -> falsy skips the "-scaled" copy (needs a full decode)
160 - * intermediate_image_sizes_advanced -> empty makes _wp_make_subsizes() return early,
161 - * ahead of its wp_get_image_editor() call
162 - *
163 - * The original file is still attached and usable; only the derived sizes are skipped.
164 - * That trades ideal thumbnails for an import that completes, instead of a fatal that
165 - * takes the whole page down and repeats on every retry.
166 - *
167 - * @since 2.6.2
168 - */
169 - private static function wdkit_guard_oversized_images() {
170 - static $registered = false;
171 -
172 - // Registering twice would stack duplicate closures on both filters.
173 - if ( $registered ) {
174 - return;
175 - }
176 -
177 - $registered = true;
178 -
179 - if ( ! class_exists( 'Wdkit_Image_Guard' ) ) {
180 - require_once WDKIT_INCLUDES . 'admin/class-wdkit-image-guard.php';
181 - }
182 -
183 - add_filter(
184 - 'big_image_size_threshold',
185 - function ( $threshold, $imagesize = array(), $file = '', $attachment_id = 0 ) {
186 - if ( ! empty( $imagesize[0] ) && ! empty( $imagesize[1] )
187 - && ! Wdkit_Image_Guard::decode_fits( $imagesize[0], $imagesize[1], self::wdkit_available_image_memory() )
188 - ) {
189 - return false;
190 - }
191 -
192 - return $threshold;
193 - },
194 - 99,
195 - 4
196 - );
197 -
198 - add_filter(
199 - 'intermediate_image_sizes_advanced',
200 - function ( $sizes, $image_meta = array(), $attachment_id = 0 ) {
201 - if ( ! empty( $image_meta['width'] ) && ! empty( $image_meta['height'] )
202 - && ! Wdkit_Image_Guard::decode_fits( $image_meta['width'], $image_meta['height'], self::wdkit_available_image_memory() )
203 - ) {
204 - return array();
205 - }
206 -
207 - return $sizes;
208 - },
209 - 99,
210 - 3
211 - );
212 - }
213 -
214 - /**
215 120 * Get Wdkit Api Call Ajax.
216 121 */
217 122 public function wdkit_api_call() {
218 123
@@ -231,40 +136,33 @@
231 136 case 'onboarding_handler':
232 137 $data = $this->wdkit_onboarding_handler();
233 138 break;
234 139 case 'wkit_login':
235 - $data = apply_filters( 'wp_wdkit_login_ajax', 'wkit_login' );
140 + $data = $this->wdkit_login();
236 141 break;
237 142 case 'api_login':
238 - $data = apply_filters( 'wp_wdkit_login_ajax', 'api_login' );
143 + $data = $this->wdkit_api_login();
239 144 break;
240 145 case 'social_login':
241 - $data = apply_filters( 'wp_wdkit_login_ajax', 'social_login' );
146 + $data = $this->wdkit_social_login();
242 147 break;
243 - case 'forgot_password':
244 - $data = apply_filters( 'wp_wdkit_login_ajax', 'forgot_password' );
245 - break;
246 - case 'wdkit_user_signup':
247 - $data = apply_filters( 'wp_wdkit_login_ajax', 'wdkit_user_signup' );
248 - break;
249 148 case 'wkit_meta_data':
250 149 $data = $this->wdkit_meta_data();
251 150 break;
252 151 case 'get_user_info':
152 + $id = isset( $_POST['id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['id'] ) ) ) : false;
253 153 $data = $this->wdkit_get_user_info();
254 154 break;
255 155 case 'browse_page':
256 156 $data = $this->wdkit_browse_page();
257 157 break;
158 + case 'widget_browse_page':
159 + $data = $this->wdkit_widget_browse_page();
160 + break;
258 161 case 'kit_template':
162 + $id = isset( $_POST['id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['id'] ) ) ) : false;
259 163 $data = $this->wdkit_template();
260 164 break;
261 - case 'wkit_preset_template':
262 - $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_template' );
263 - break;
264 - case 'wdkit_preset_dwnld_template':
265 - $data = apply_filters( 'wp_wdkit_preset_ajax', 'wdkit_preset_dwnld_template' );
266 - break;
267 165 case 'template_remove':
268 166 $data = $this->wdkit_template_remove();
269 167 break;
270 168 case 'save_template':
@@ -269,29 +167,8 @@
269 167 break;
270 168 case 'save_template':
271 169 $data = $this->wdkit_put_save_template();
272 170 break;
273 - case 'update_save_temp_image':
274 - $data = $this->wdkit_update_save_temp_image();
275 - break;
276 - case 'save_wp_images':
277 - $data = $this->wdkit_save_wp_images();
278 - break;
279 - case 'get_global_val':
280 - $data = $this->wdkit_get_global_val();
281 - break;
282 - case 'update_global_val':
283 - $data = $this->wdkit_update_global_val();
284 - break;
285 - case 'wdkit_get_site_setting':
286 - $data = $this->wdkit_get_site_setting();
287 - break;
288 - case 'wdkit_update_site_setting':
289 - $data = $this->wdkit_update_site_setting();
290 - break;
291 - case 'update_preset_setting':
292 - $data = $this->wdkit_update_preset();
293 - break;
294 171 case 'find_template':
295 172 $data = $this->wdkit_find_existing_template();
296 173 break;
297 174 case 'update_template':
@@ -305,65 +182,11 @@
305 182 break;
306 183 case 'install_plugins_depends':
307 184 $data = $this->wdkit_install_plugins_depends();
308 185 break;
309 - case 'generate_site_logo':
310 - $data = $this->wkit_generate_site_logo();
311 - break;
312 - case 'generate_ai_content':
313 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'generate_ai_content' );
314 - break;
315 - case 'generate_ai_content_batch':
316 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'generate_ai_content_batch' );
317 - break;
318 - case 'reset_site':
319 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'reset_site' );
320 - break;
321 - case 'wdkit_nxt_thembuilder_reset':
322 - $data = $this->wdkit_nxt_thembuilder_reset();
323 - break;
324 - case 'wdkit_check_user_credit':
325 - $data = $this->wdkit_check_user_credit();
326 - break;
327 - case 'wdkit_remove_header_footer':
328 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wdkit_remove_header_footer' );
329 - break;
330 - case 'check_post_count':
331 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'check_post_count' );
332 - break;
333 - case 'wkit_check_product_count':
334 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_check_product_count' );
335 - break;
336 - case 'select_team_img':
337 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'select_team_img' );
338 - break;
339 - case 'wkit_ai_desc_keyword':
340 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_ai_desc_keyword' );
341 - break;
342 - case 'wkit_ai_credit_update':
343 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_ai_credit_update' );
344 - break;
345 - case 'wkit_generate_post_data':
346 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_generate_post_data' );
347 - break;
348 - case 'wkit_generate_product_data':
349 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_generate_product_data' );
350 - break;
351 - case 'wkit_cteate_product':
352 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_cteate_product' );
353 - break;
354 - case 'wkit_remove_dummy_post':
355 - $data = apply_filters( 'wp_wdkit_import_temp_ajax', 'wkit_remove_dummy_post' );
356 - break;
357 186 case 'update_latest_plugin':
358 187 $data = $this->wdkit_update_latest_plugin();
359 188 break;
360 - case 'activate_container':
361 - $data = $this->wdkit_activate_container();
362 - break;
363 - case 'import_taxonomy':
364 - $data = $this->wdkit_import_taxonomy();
365 - break;
366 189 case 'import_template':
367 190 $data = $this->wdkit_import_template();
368 191 break;
369 192 case 'import_multi_template':
@@ -368,58 +191,11 @@
368 191 break;
369 192 case 'import_multi_template':
370 193 $data = $this->wdkit_import_multi_template();
371 194 break;
372 - case 'import_page_section':
373 - $data = $this->import_page_section_content();
374 - break;
375 - case 'wkit_update_elementor_template':
376 - $data = $this->wkit_update_elementor_template();
377 - break;
378 - case 'wdkit_update_page_content':
379 - $data = $this->wdkit_update_page_content();
380 - break;
381 - case 'update_plugin_setting':
382 - $data = $this->update_plugin_setting();
383 - break;
384 - case 'update_theme_setting':
385 - $data = $this->update_theme_setting();
386 - break;
387 - case 'update_site_setting':
388 - $data = $this->update_site_setting();
389 - break;
390 195 case 'import_kit_template':
391 196 $data = $this->wdkit_import_kit_template();
392 197 break;
393 - case 'enable_template_widgets':
394 - $data = $this->wdkit_enable_template_widgets();
395 - break;
396 - case 'scan_nexter_widgets':
397 - if ( ! empty( $_POST['blockNames'] ) && has_filter( 'nexter_block_list_merge' ) ) {
398 -
399 - $posted_blocks = json_decode( stripslashes( $_POST['blockNames'] ), true );
400 -
401 - if ( is_array( $posted_blocks ) ) {
402 - $blockList = array_map( 'sanitize_text_field', $posted_blocks );
403 -
404 - // अब filter call करो
405 - $result = apply_filters( 'nexter_block_list_merge', $blockList );
406 -
407 - wp_send_json( $result );
408 - wp_die();
409 - }
410 - }
411 -
412 - wp_send_json(
413 - array(
414 - 'success' => false,
415 - 'message' => __( 'No block names received or filter not found.', 'wdesignkit' ),
416 - 'description' => 'Ensure blockNames are posted and the filter is attached.',
417 - )
418 - );
419 - wp_die();
420 - $data = '';
421 - break;
422 198 case 'shared_with_me':
423 199 $data = $this->wdkit_shared_with_me();
424 200 break;
425 201 case 'manage_workspace':
@@ -424,32 +200,8 @@
424 200 break;
425 201 case 'manage_workspace':
426 202 $data = $this->wdkit_manage_workspace();
427 203 break;
428 - case 'widget_browse_page':
429 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'widget_browse_page' );
430 - break;
431 - case 'wkit_create_widget':
432 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_create_widget' );
433 - break;
434 - case 'wkit_import_widget':
435 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_import_widget' );
436 - break;
437 - case 'wkit_export_widget':
438 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_export_widget' );
439 - break;
440 - case 'wkit_delete_widget':
441 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_delete_widget' );
442 - break;
443 - case 'wkit_widget_preview':
444 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_widget_preview' );
445 - break;
446 - case 'wkit_check_widget_versions':
447 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_check_widget_versions' );
448 - break;
449 - case 'wkit_plugin_download_get':
450 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_plugin_download_get' );
451 - break;
452 204 case 'wkit_manage_widget_workspace':
453 205 $data = $this->wdkit_manage_widget_workspace();
454 206 break;
455 207 case 'wkit_activate_key':
@@ -457,16 +209,25 @@
457 209 break;
458 210 case 'wkit_manage_widget_category':
459 211 $data = $this->wdkit_manage_widget_category();
460 212 break;
461 - case 'wkit_widget_json':
462 - $data = $this->wkit_widget_json();
213 + case 'wkit_create_widget':
214 + $data = $this->wdkit_create_widget();
463 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;
464 225 case 'wkit_download_widget':
465 226 $data = $this->wdkit_download_widget();
466 227 break;
467 228 case 'wkit_public_download_widget':
468 - $data = apply_filters( 'wp_wdkit_widget_ajax', 'wkit_public_download_widget' );
229 + $data = $this->wdkit_public_download_widget();
469 230 break;
470 231 case 'wkit_add_widget':
471 232 $data = $this->wdkit_add_widget();
472 233 break;
@@ -487,36 +248,14 @@
487 248 break;
488 249 case 'sync_licence':
489 250 $data = $this->wdkit_sync_licence_key();
490 251 break;
491 - case 'get_wkit_version':
492 - $data = $this->wdkit_prev_version();
493 - break;
494 - case 'rollback_wdkit':
495 - $data = $this->wdkit_rollback_check();
496 - break;
497 252 case 'wkit_logout':
498 253 $data = $this->wdkit_logout();
499 254 break;
500 - case 'wkit_white_label':
501 - $this->wkit_white_label();
502 - break;
503 - case 'wkit_reset_wl':
504 - $data = $this->wkit_reset_wl();
505 - break;
506 - case 'wdkit_dark_mode':
507 - $data = $this->wdkit_dark_mode();
508 - break;
509 - case 'wdkit_get_workspace_data':
510 - $data = $this->wdkit_get_workspace_data();
511 - break;
512 - default:
513 - $this->wdkit_error_msg( __( 'Unknown request type.', 'wdesignkit' ) );
514 - return;
515 255 }
516 256
517 257 $this->wdkit_success_msg( $data );
518 - // wp_die();
519 258 }
520 259
521 260 /**
522 261 *
@@ -523,13 +262,12 @@
523 262 * This Function is used for API call
524 263 *
525 264 * @since 1.0.0
526 265 *
527 - * @param array $data give array.
528 - * @param array $name store data.
529 - * @param int $timeout optional HTTP timeout in seconds. Default 100.
266 + * @param array $data give array.
267 + * @param array $name store data.
530 268 */
531 - protected function wkit_api_call( $data, $name, $timeout = 100 ) {
269 + protected function wkit_api_call( $data, $name ) {
532 270 $u_r_l = $this->wdkit_api;
533 271
534 272 if ( empty( $u_r_l ) ) {
535 273 return array(
@@ -540,9 +278,9 @@
540 278
541 279 $args = array(
542 280 'method' => 'POST',
543 281 'body' => $data,
544 - 'timeout' => $timeout,
282 + 'timeout' => 100,
545 283 );
546 284 $response = wp_remote_post( $u_r_l . $name, $args );
547 285
548 286 if ( is_wp_error( $response ) ) {
@@ -548,9 +286,9 @@
548 286 if ( is_wp_error( $response ) ) {
549 287 $error_message = $response->get_error_message();
550 288
551 289 /* Translators: %s is a placeholder for the error message */
552 - $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 ) );
553 291
554 292 return array(
555 293 'massage' => $error_message,
556 294 'success' => false,
@@ -567,9 +305,9 @@
567 305 'success' => true,
568 306 );
569 307 }
570 308
571 - $error_message = sprintf( 'Server error: %d', esc_html( $status_code ) );
309 + $error_message = printf( 'Server error: %d', esc_html( $status_code ) );
572 310
573 311 if ( isset( $error_data->message ) ) {
574 312 $error_message .= ' (' . $error_data->message . ')';
575 313 }
@@ -581,9 +319,41 @@
581 319 );
582 320 }
583 321
584 322 /**
323 + * This Function is used for API call
585 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 + *
586 356 * It is Use for handle onboarding data.
587 357 *
588 358 * @since 1.0.9
589 359 */
@@ -593,9 +363,8 @@
593 363
594 364 $elementor_plugin = isset( $_POST['elementor_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['elementor_plugin'] ) ) : 0;
595 365 $tpag_plugin = isset( $_POST['tpag_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['tpag_plugin'] ) ) : 0;
596 366 $bricks_theme = isset( $_POST['bricks_theme'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['bricks_theme'] ) ) : 0;
597 - $site_info = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : false;
598 367
599 368 $server_software = ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
600 369
601 370 $web_server = $server_software;
@@ -634,27 +403,23 @@
634 403 'tpag_install' => $tpag_plugin,
635 404 'bricks_install' => $bricks_theme,
636 405 );
637 406
638 - if ( ! empty( $site_info ) ) {
639 - $final = array(
640 - 'web_server' => $web_server,
641 - 'memory_limit' => $memory_limit,
642 - 'max_execution_time' => $max_execution_time,
643 - 'php_version' => $php_version,
644 - 'wp_version' => $wp_version,
645 - 'email' => $email,
646 - 'site_url' => $siteurl,
647 - 'site_language' => $language,
648 - 'theme' => $theme,
649 - 'plugins' => $act_plugin,
650 - 'basic_requirements' => $basic_requirements,
651 - 'page_template' => $page_template,
652 - 'page_builder' => $page_builder,
653 - );
654 - } else {
655 - $final = array();
656 - }
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 + );
657 422
658 423 $response = wp_remote_post(
659 424 $this->wdkit_onbording_api,
660 425 array(
@@ -707,11 +472,172 @@
707 472 }
708 473
709 474 /**
710 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 + *
711 637 * It is Use for get meta data for non login user
712 638 *
713 - * @since 1.0.0
639 + * @since 1.0.0\
714 640 */
715 641 protected function wdkit_meta_data() {
716 642 $type = isset( $_POST['meta_type'] ) ? sanitize_text_field( wp_unslash( $_POST['meta_type'] ) ) : '';
717 643 $data = array( 'type' => $type );
@@ -755,49 +681,13 @@
755 681 }
756 682
757 683 /**
758 684 *
759 - * It is Use for get activate license key data from tpae and nexter blocks.
760 - *
761 - * @since 1.1.6
762 - */
763 - protected function wkit_manage_license_data() {
764 - $manage_licence = array();
765 - $theplus_active_check = is_plugin_active( 'the-plus-addons-for-elementor-page-builder/theplus_elementor_addon.php' );
766 - $nexter_active_check = is_plugin_active( 'the-plus-addons-for-block-editor/the-plus-addons-for-block-editor.php' );
767 -
768 - $theplus_licence = get_option( 'tpaep_licence_data', array() );
769 -
770 - // Also require the TPAE Pro plugin to be active (Pro defines THEPLUS_VERSION;
771 - // the free plugin defines L_THEPLUS_VERSION). This hides the "found active
772 - // key" notice when the Pro plugin is removed even though its licence option
773 - // still lingers in the database.
774 - if ( ! empty( $theplus_active_check ) && defined( 'THEPLUS_VERSION' ) && ! empty( $theplus_licence ) ) {
775 - $manage_licence['tpae'] = $theplus_licence;
776 - }
777 -
778 - $nexter_licence = get_option( 'tpgb_activate', array() );
779 -
780 - // Also require the Nexter Blocks Pro plugin to be active (Pro defines
781 - // TPGBP_VERSION; the free plugin defines TPGB_VERSION), so the notice hides
782 - // when the Pro plugin is removed but its licence option persists.
783 - if ( ! empty( $nexter_active_check ) && defined( 'TPGBP_VERSION' ) && ! empty( $nexter_licence ) && ! empty( $nexter_licence['tpgb_activate_key'] ) ) {
784 - $tpgb_license_status = get_option( 'tpgbp_license_status', array() );
785 - $tpgb_license_status['license_key'] = $nexter_licence['tpgb_activate_key'];
786 - $manage_licence['tpag'] = $tpgb_license_status;
787 - }
788 -
789 - return $manage_licence;
790 - }
791 -
792 - /**
793 - *
794 685 * It is Use for get all info of user.
795 686 *
796 687 * @since 1.0.0
797 688 */
798 689 protected function wdkit_get_user_info() {
799 - $token = isset( $_POST['token'] ) ? wp_unslash( $_POST['token'] ) : false;
800 690 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
801 691 $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['builder'] ) ) ) : '';
802 692
803 693 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
@@ -803,9 +693,9 @@
803 693 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
804 694
805 695 $response = array();
806 696
807 - if ( empty( $token ) ) {
697 + if ( empty( $email ) ) {
808 698 $response = array(
809 699 'success' => false,
810 700 'message' => $this->e_msg_login,
811 701 'description' => $this->e_desc_login,
@@ -814,10 +704,10 @@
814 704 wp_send_json( $response );
815 705 wp_die();
816 706 }
817 707
818 - // $token = $this->wdkit_login_user_token( $email );
819 - $args = array(
708 + $token = $this->wdkit_login_user_token( $email );
709 + $args = array(
820 710 'token' => $token,
821 711 'builder' => $builder,
822 712 'site_url' => $site_url,
823 713 );
@@ -822,18 +712,8 @@
822 712 'site_url' => $site_url,
823 713 );
824 714
825 715 $response = WDesignKit_Data_Query::get_data( 'get_user_info', $args );
826 -
827 - if ( is_wp_error( $response ) ) {
828 - wp_send_json( array(
829 - 'success' => false,
830 - 'message' => $response->get_error_message(),
831 - 'description' => $response->get_error_message(),
832 - ) );
833 - wp_die();
834 - }
835 -
836 716 $status = ( ! empty( $response['status'] ) ) ? sanitize_text_field( $response['status'] ) : 'error';
837 717 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
838 718
839 719 /**Condtion user for user logout & expire token*/
@@ -838,32 +718,13 @@
838 718
839 719 /**Condtion user for user logout & expire token*/
840 720 if ( 'Token is Expired' === $status || 'Authorization Token not found' === $status ) {
841 721 delete_transient( 'wdkit_auth_' . $email );
842 - // Clear stored license data when token expires so banner shows again
843 - delete_option( 'wdkit_licence_data' );
844 722 }
845 723
846 - if ( empty( $response ) ) {
847 - $response['login_reset'] = 'yes';
848 - }
724 + $response['Setting'] = $this->wkit_get_settings_panel();
725 + $response['widget_list'] = $this->wkit_manage_widget_sequence( $response );
849 726
850 - // Store WDesignKit license data locally if present in response
851 - if ( ! empty( $response['credits']['wdkit_licence'] ) && is_array( $response['credits']['wdkit_licence'] ) ) {
852 - $wdkit_licence = $response['credits']['wdkit_licence'];
853 - // Handle serialized data
854 - if ( is_string( $wdkit_licence ) && is_serialized( $wdkit_licence ) ) {
855 - $wdkit_licence = unserialize( $wdkit_licence );
856 - }
857 - if ( ! empty( $wdkit_licence ) && is_array( $wdkit_licence ) ) {
858 - update_option( 'wdkit_licence_data', $wdkit_licence );
859 - }
860 - }
861 -
862 - $response['Setting'] = $this->wkit_get_settings_panel();
863 - $response['widget_list'] = $this->wkit_manage_widget_sequence( $response );
864 - $response['manage_licence'] = $this->wkit_manage_license_data();
865 -
866 727 $response = array(
867 728 'data' => $response,
868 729 'success' => true,
869 730 );
@@ -892,13 +753,13 @@
892 753 $server_w_unique = array_column( $server_list, 'w_unique' );
893 754
894 755 $idx_builder = array();
895 756 foreach ( $db_builder_list as $index => $value ) {
896 - $builder_name = ! empty( $value['builder_slug'] ) ? $value['builder_slug'] : '';
757 + $builder_name = ! empty( $value['builder_name'] ) ? $value['builder_name'] : '';
897 758 $w_id = ! empty( $value['w_id'] ) ? $value['w_id'] : '';
898 759
899 760 if ( ! empty( $builder_name ) ) {
900 - $idx_builder[ $w_id ] = strtolower( str_replace( ' ', '_', trim( $builder_name ) ) );
761 + $idx_builder[ $w_id ] = strtolower( $builder_name );
901 762 }
902 763 }
903 764
904 765 foreach ( $server_list as $index => $value ) {
@@ -910,9 +771,9 @@
910 771
911 772 $count = 0;
912 773
913 774 foreach ( $local_list as $key => $value ) {
914 - $widget_id = ! empty( $value['widgetdata']['widget_id'] ) ? $value['widgetdata']['widget_id'] : '';
775 + $widget_id = ! empty( $value['widgetdata']['widget_id'] ) ? $value['widgetdata']['widget_id'] : '';
915 776 $allow_push = isset( $value['widgetdata']['allow_push'] ) ? $value['widgetdata']['allow_push'] : true;
916 777
917 778 if ( in_array( $widget_id, $server_w_unique ) ) {
918 779
@@ -932,9 +793,9 @@
932 793 unset( $server_list[ $index ] );
933 794 } else {
934 795 $local_list[ $key ]['widgetdata']['builder'] = $local_list[ $key ]['widgetdata']['type'];
935 796 $local_list[ $key ]['widgetdata']['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id'];
936 - $local_list[ $key ]['widgetdata']['allow_push'] = $allow_push;
797 + $local_list[ $key ]['widgetdata']['allow_push'] = $allow_push;
937 798 $local_list[ $key ]['widgetdata']['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg;
938 799 $local_list[ $key ]['widgetdata']['is_activated'] = 'active';
939 800
940 801 $local_list[ $key ]['widgetdata']['type'] = 'plugin';
@@ -957,9 +818,9 @@
957 818 if ( 'active' === $is_activated ) {
958 819 ++$count;
959 820 }
960 821
961 - if ( ( $count > $credits ) && ( 'unlimited' !== $credits ) ) {
822 + if ( ($count > $credits) && ('unlimited' !== $credits)) {
962 823 $final[ $key ]['is_activated'] = 'deactive';
963 824 }
964 825
965 826 if ( ! empty( $self['is_activated'] ) && 'active' !== $self['is_activated'] ) {
@@ -991,21 +852,47 @@
991 852 $args = $this->wdkit_parse_args( $_POST );
992 853
993 854 $response = WDesignKit_Data_Query::get_data( 'browse_page', $args );
994 855
995 - if ( is_wp_error( $response ) ) {
996 - wp_send_json( array(
997 - 'success' => false,
998 - 'message' => $response->get_error_message(),
999 - ) );
856 + wp_send_json( $response );
857 + wp_die();
858 + }
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 );
1000 891 wp_die();
1001 892 }
1002 893
1003 - $manage_licence = array();
1004 - $manage_licence['theplus_elementor_addon'] = ! empty( defined( 'THEPLUS_VERSION' ) ) ? true : false;
1005 - $manage_licence['tpag'] = ! empty( defined( 'TPGBP_VERSION' ) ) ? true : false;
1006 - $manage_licence['elementor-pro'] = ! empty( defined( 'ELEMENTOR_PRO_VERSION' ) ) ? true : false;
1007 - $response['manage_licence'] = $manage_licence;
894 + $response = json_decode( wp_json_encode( $response['data'] ), true );
1008 895
1009 896 wp_send_json( $response );
1010 897 wp_die();
1011 898 }
@@ -1036,14 +923,15 @@
1036 923
1037 924 $user_email = strtolower( sanitize_email( $args['email'] ) );
1038 925 $response = '';
1039 926
1040 - // Bug D fix: response()->json() is Laravel syntax — causes PHP fatal. Use plain array.
1041 927 if ( empty( $user_email ) || empty( $args['template_id'] ) ) {
1042 - $response = array(
1043 - 'message' => $this->e_msg_login,
1044 - 'description' => $this->e_desc_login,
1045 - 'success' => false,
928 + $response = response()->json(
929 + array(
930 + 'message' => $this->e_msg_login,
931 + 'description' => $this->e_desc_login,
932 + 'success' => true,
933 + )
1046 934 );
1047 935
1048 936 wp_send_json( $response );
1049 937 wp_die();
@@ -1064,12 +952,9 @@
1064 952 *
1065 953 * @since 1.0.0
1066 954 */
1067 955 protected function wdkit_put_save_template() {
1068 - $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
1069 - $post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '';
1070 - $builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '';
1071 -
956 + $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
1072 957 $response = '';
1073 958
1074 959 if ( empty( $email ) ) {
1075 960 $response = array(
@@ -1087,19 +972,14 @@
1087 972 $args = $this->wdkit_parse_args( $_POST );
1088 973 $args['token'] = $this->wdkit_login_user_token( $email );
1089 974 unset( $args['email'] );
1090 975
1091 - if( 'elementor' === $builder ){
1092 - $args['data'] = base64_decode( $args['data'] );
1093 - } else if ( 'gutenberg' === $builder ) {
1094 - $args['data'] = base64_decode( $args['data'] );
1095 - }
1096 -
1097 976 global $post;
1098 977
978 + $post_id = get_the_ID();
1099 979 $custom_fields = array();
1100 980 if ( ! empty( $post_id ) ) {
1101 - $meta_fields = get_post_custom( $post_id );
981 + $meta_fields = get_post_custom( get_the_ID() );
1102 982
1103 983 foreach ( $meta_fields as $key => $value ) {
1104 984 if ( str_contains( $key, 'nxt-' ) ) {
1105 985 $custom_fields[ $key ] = $value;
@@ -1120,1115 +1000,8 @@
1120 1000 }
1121 1001
1122 1002 /**
1123 1003 *
1124 - * It is Use for update save template image.
1125 - *
1126 - * @since 2.0.6
1127 - */
1128 - protected function wdkit_update_save_temp_image() {
1129 - $temp_content = isset( $_POST['temp_content'] ) ? esc_url_raw( $_POST['temp_content'] ) : '';
1130 - $content_name = isset( $_POST['content_name'] ) ? sanitize_text_field( $_POST['content_name'] ) : '';
1131 - $token = isset( $_POST['token'] ) ? sanitize_text_field( $_POST['token'] ) : '';
1132 - $user_type = isset( $_POST['user_type'] ) ? sanitize_text_field( $_POST['user_type'] ) : '';
1133 - $type = isset( $_POST['content_type'] ) ? sanitize_text_field( $_POST['content_type'] ) : '';
1134 - $id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : '';
1135 - if ( empty( $temp_content ) || empty( $user_type ) || empty( $id ) || empty( $token ) ) {
1136 - $response = array(
1137 - 'message' => __( 'Data not found', 'wdesignkit' ),
1138 - 'description' => __( 'Data not found', 'wdesignkit' ),
1139 - 'success' => false,
1140 - );
1141 - } else {
1142 - $temp_content = str_replace( '\\', '', $temp_content );
1143 - $temp_content = wp_remote_get( $temp_content )['body'];
1144 - $temp_content = base64_encode( $temp_content );
1145 -
1146 - $args = array(
1147 - 'token' => $token,
1148 - 'template_id' => $id,
1149 - 'name' => $content_name,
1150 - 'content' => $temp_content,
1151 - 'type' => $type,
1152 - );
1153 -
1154 - $response = $this->wkit_api_call( $args, 'save_images' );
1155 - $success = ! empty( $response['success'] ) ? $response['success'] : false;
1156 -
1157 - if ( $success ) {
1158 - $response = array(
1159 - 'data' => $response['data'],
1160 - 'success' => true,
1161 - );
1162 - } else {
1163 - $response = array(
1164 - 'message' => __( 'API Error', 'wdesignkit' ),
1165 - 'description' => __( 'API Error', 'wdesignkit' ),
1166 - 'data' => $response['data'],
1167 - 'success' => false,
1168 - );
1169 - }
1170 - }
1171 -
1172 - wp_send_json( $response );
1173 - wp_die();
1174 - }
1175 -
1176 - /**
1177 - *
1178 - * It is Use for save image to WordPress Media Library.
1179 - *
1180 - * @since 2.3.3
1181 - */
1182 - protected function wdkit_save_wp_images() {
1183 -
1184 - // media_sideload_image() generates every registered thumbnail size, which decodes
1185 - // the full source bitmap. Same guard as the page import.
1186 - $this->wdkit_guard_oversized_images();
1187 -
1188 - $image_url = isset( $_POST['image'] ) ? sanitize_text_field( $_POST['image'] ) : '';
1189 -
1190 - if ( empty( $image_url ) ) {
1191 - $response = array(
1192 - 'message' => __( 'No Image Provided', 'wdesignkit' ),
1193 - 'description' => __( 'No Image URL provided for save.', 'wdesignkit' ),
1194 - 'success' => false,
1195 - );
1196 - } else {
1197 -
1198 - $attachment_id = media_sideload_image( $image_url, 0, null, 'id' );
1199 -
1200 - if ( is_wp_error( $attachment_id ) ) {
1201 - $response = array(
1202 - 'message' => __( 'Upload Failed', 'wdesignkit' ),
1203 - 'description' => $attachment_id->get_error_message(),
1204 - 'success' => false,
1205 - );
1206 - } else {
1207 - $saved_url = wp_get_attachment_url( $attachment_id );
1208 -
1209 - // Elementor's importer skips an image only when it finds
1210 - // _elementor_source_image_hash matching sha1 of the URL it is given. The
1211 - // content we hand it now carries this local URL, so stamp the hash of that
1212 - // URL too - without it Elementor re-downloads a file already on disk and
1213 - // leaves a "-1" duplicate behind for every image on every page that uses it.
1214 - if ( $saved_url ) {
1215 - update_post_meta( $attachment_id, '_elementor_source_image_hash', sha1( $saved_url ) );
1216 -
1217 - // Same purpose for the block importer, which keys off its own meta.
1218 - update_post_meta( $attachment_id, 'tpgb_source_image_key', sha1( $saved_url ) );
1219 - }
1220 -
1221 - $response = array(
1222 - 'message' => __( 'Image Saved', 'wdesignkit' ),
1223 - 'description' => __( 'Image successfully saved to Media Library.', 'wdesignkit' ),
1224 - 'success' => true,
1225 - 'url' => $saved_url,
1226 - );
1227 - }
1228 -
1229 - }
1230 -
1231 - wp_send_json( $response );
1232 - wp_die();
1233 - }
1234 -
1235 - /**
1236 - *
1237 - * Get Elementor Global color and Typography.
1238 - *
1239 - * @since 1.1.16
1240 - */
1241 - protected function wdkit_get_global_val() {
1242 -
1243 - $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( $_POST['builder'] ) ) : '';
1244 -
1245 - if ( 'elementor' === $builder ) {
1246 - $kit_id = get_option( 'elementor_active_kit' );
1247 - if ( empty( $kit_id ) ) {
1248 - $response = array(
1249 - 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
1250 - 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
1251 - 'success' => false,
1252 - );
1253 -
1254 - wp_send_json( $response );
1255 - wp_die();
1256 - }
1257 -
1258 - $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
1259 - if ( empty( $kit_meta['system_colors'] ) ) {
1260 - $static_meta = array(
1261 - 'system_colors' => array(
1262 - 0 => array(
1263 - '_id' => 'primary',
1264 - 'title' => 'Primary',
1265 - 'color' => '#6EC1E4',
1266 - ),
1267 - 1 => array(
1268 - '_id' => 'secondary',
1269 - 'title' => 'Secondary',
1270 - 'color' => '#54595F',
1271 - ),
1272 - 2 => array(
1273 - '_id' => 'text',
1274 - 'title' => 'Text',
1275 - 'color' => '#7A7A7A',
1276 - ),
1277 - 3 => array(
1278 - '_id' => 'accent',
1279 - 'title' => 'Accent',
1280 - 'color' => '#61CE70',
1281 - ),
1282 - ),
1283 - 'custom_colors' => array(),
1284 - 'system_typography' => array(
1285 - 0 => array(
1286 - '_id' => 'primary',
1287 - 'title' => 'Primary',
1288 - 'typography_typography' => 'custom',
1289 - 'typography_font_family' => 'Roboto',
1290 - 'typography_font_weight' => '600',
1291 - ),
1292 - 1 => array(
1293 - '_id' => 'secondary',
1294 - 'title' => 'Secondary',
1295 - 'typography_typography' => 'custom',
1296 - 'typography_font_family' => 'Roboto Slab',
1297 - 'typography_font_weight' => '400',
1298 - ),
1299 - 2 => array(
1300 - '_id' => 'text',
1301 - 'title' => 'Text',
1302 - 'typography_typography' => 'custom',
1303 - 'typography_font_family' => 'Roboto',
1304 - 'typography_font_weight' => '400',
1305 - ),
1306 - 3 => array(
1307 - '_id' => 'accent',
1308 - 'title' => 'Accent',
1309 - 'typography_typography' => 'custom',
1310 - 'typography_font_family' => 'Roboto',
1311 - 'typography_font_weight' => '500',
1312 - ),
1313 - ),
1314 - 'custom_typography' => array(),
1315 - 'default_generic_fonts' => 'Sans-serif',
1316 - 'site_name' => ! empty( get_bloginfo( 'name' ) ) ? get_bloginfo( 'name' ) : '',
1317 - 'page_title_selector' => 'h1.entry-title',
1318 - 'activeItemIndex' => 1,
1319 - 'viewport_md' => 768,
1320 - 'viewport_lg' => 1025,
1321 - );
1322 -
1323 - $kit_meta = $static_meta;
1324 - update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta );
1325 - }
1326 -
1327 - $system_colors = ! empty( $kit_meta['system_colors'] ) ? $kit_meta['system_colors'] : array();
1328 - $custom_colors = ! empty( $kit_meta['custom_colors'] ) ? $kit_meta['custom_colors'] : array();
1329 - $system_typography = ! empty( $kit_meta['system_typography'] ) ? $kit_meta['system_typography'] : array();
1330 - $custom_typography = ! empty( $kit_meta['custom_typography'] ) ? $kit_meta['custom_typography'] : array();
1331 -
1332 - $color_array = array_merge( $system_colors, $custom_colors );
1333 - $typo_array = array_merge( $system_typography, $custom_typography );
1334 -
1335 - $global_data = array(
1336 - 'color' => $color_array,
1337 - 'typography' => $typo_array,
1338 - );
1339 -
1340 - $response = array(
1341 - 'message' => __( 'Global data Found', 'wdesignkit' ),
1342 - 'description' => __( 'Global Color and Typography found', 'wdesignkit' ),
1343 - 'data' => $global_data,
1344 - 'success' => true,
1345 - );
1346 -
1347 - } elseif ( 'gutenberg' === $builder ) {
1348 -
1349 - $plus_settings = get_option( 'tpgb_global_options', false );
1350 - $plus_settings = ! empty( $plus_settings ) ? json_decode( $plus_settings, true ) : json_decode( '[]' );
1351 -
1352 - if ( empty( $plus_settings ) ) {
1353 -
1354 - $static_meta = array(
1355 - 'active' => 'preset1',
1356 - 'darkMode' => 'none',
1357 - 'presets' => array(
1358 - 'preset1' => array(
1359 - 'name' => 'Preset 1',
1360 - 'key' => 'preset1',
1361 - 'colors' => array(
1362 - array(
1363 - 'label' => 'Primary',
1364 - 'value' => '#8072FC',
1365 - ),
1366 - array(
1367 - 'label' => 'Secondary',
1368 - 'value' => '#6FC784',
1369 - ),
1370 - array(
1371 - 'label' => 'Tertiary',
1372 - 'value' => '#FF5A6E',
1373 - ),
1374 - array(
1375 - 'label' => 'Accent',
1376 - 'value' => '#F3F3F3',
1377 - ),
1378 - array(
1379 - 'label' => 'Background',
1380 - 'value' => '#888888',
1381 - ),
1382 - ),
1383 - 'gradient' => array(
1384 - array(
1385 - 'label' => 'Primary',
1386 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1387 - ),
1388 -
1389 - array(
1390 - 'label' => 'Secondary',
1391 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1392 - ),
1393 -
1394 - array(
1395 - 'label' => 'Tertiary',
1396 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1397 - ),
1398 -
1399 - array(
1400 - 'label' => 'Accent',
1401 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1402 - ),
1403 -
1404 - array(
1405 - 'label' => 'Background',
1406 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1407 - ),
1408 - ),
1409 - 'spacing' => array(
1410 - array(
1411 - 'label' => 'Large',
1412 - 'value' => array(
1413 - 'md' => 70,
1414 - 'unit' => 'px',
1415 - ),
1416 - ),
1417 - array(
1418 - 'label' => 'Medium',
1419 - 'value' => array(
1420 - 'md' => 40,
1421 - 'unit' => 'px',
1422 - ),
1423 - ),
1424 - array(
1425 - 'label' => 'Small',
1426 - 'value' => array(
1427 - 'md' => 20,
1428 - 'unit' => 'px',
1429 - ),
1430 -
1431 - ),
1432 - ),
1433 - 'typography' => array(
1434 - array(
1435 - 'label' => 'Display Text',
1436 - 'value' => array(
1437 - 'openTypography' => 1,
1438 - 'size' => array(
1439 - 'md' => 65,
1440 - 'unit' => 'px',
1441 - ),
1442 - 'height' => array(
1443 - 'md' => 75,
1444 - 'unit' => 'px',
1445 - ),
1446 - 'fontFamily' => array(
1447 - 'family' => 'Roboto',
1448 - 'type' => 'sans-serif',
1449 - 'fontWeight' => 700,
1450 - ),
1451 - 'spacing' => array(
1452 - 'md' => 0,
1453 - 'unit' => 'px',
1454 - ),
1455 - ),
1456 - ),
1457 - array(
1458 - 'label' => 'Headline',
1459 - 'value' => array(
1460 - 'openTypography' => 1,
1461 - 'size' => array(
1462 - 'md' => 45,
1463 - 'unit' => 'px',
1464 - ),
1465 - 'height' => array(
1466 - 'md' => 60,
1467 - 'unit' => 'px',
1468 - ),
1469 - 'fontFamily' => array(
1470 - 'family' => 'Roboto',
1471 - 'type' => 'sans-serif',
1472 - 'fontWeight' => 700,
1473 - ),
1474 - 'spacing' => array(
1475 - 'md' => 0,
1476 - 'unit' => 'px',
1477 - ),
1478 - ),
1479 - ),
1480 - array(
1481 - 'label' => 'Sub Headline',
1482 - 'value' => array(
1483 - 'openTypography' => 1,
1484 - 'size' => array(
1485 - 'md' => 38,
1486 - 'unit' => 'px',
1487 - ),
1488 - 'height' => array(
1489 - 'md' => 45,
1490 - 'unit' => 'px',
1491 - ),
1492 - 'fontFamily' => array(
1493 - 'family' => 'Roboto',
1494 - 'type' => 'sans-serif',
1495 - 'fontWeight' => 500,
1496 - ),
1497 - 'spacing' => array(
1498 - 'md' => 0,
1499 - 'unit' => 'px',
1500 - ),
1501 - ),
1502 - ),
1503 - array(
1504 - 'label' => 'Title 1',
1505 - 'value' => array(
1506 - 'openTypography' => 1,
1507 - 'size' => array(
1508 - 'md' => 30,
1509 - 'unit' => 'px',
1510 - ),
1511 - 'height' => array(
1512 - 'md' => 40,
1513 - 'unit' => 'px',
1514 - ),
1515 - 'fontFamily' => array(
1516 - 'family' => 'Roboto',
1517 - 'type' => 'sans-serif',
1518 - 'fontWeight' => 500,
1519 - ),
1520 - 'spacing' => array(
1521 - 'md' => 0,
1522 - 'unit' => 'px',
1523 - ),
1524 - ),
1525 - ),
1526 - array(
1527 - 'label' => 'Title 2',
1528 - 'value' => array(
1529 - 'openTypography' => 1,
1530 - 'size' => array(
1531 - 'md' => 25,
1532 - 'unit' => 'px',
1533 - ),
1534 - 'height' => array(
1535 - 'md' => 30,
1536 - 'unit' => 'px',
1537 - ),
1538 - 'fontFamily' => array(
1539 - 'family' => 'Roboto',
1540 - 'type' => 'sans-serif',
1541 - 'fontWeight' => 400,
1542 - ),
1543 - 'spacing' => array(
1544 - 'md' => 0,
1545 - 'unit' => 'px',
1546 - ),
1547 - ),
1548 - ),
1549 - array(
1550 - 'label' => 'Body',
1551 - 'value' => array(
1552 - 'openTypography' => 1,
1553 - 'size' => array(
1554 - 'md' => 17,
1555 - 'unit' => 'px',
1556 - ),
1557 - 'height' => array(
1558 - 'md' => 22,
1559 - 'unit' => 'px',
1560 - ),
1561 - 'fontFamily' => array(
1562 - 'family' => 'Roboto',
1563 - 'type' => 'sans-serif',
1564 - 'fontWeight' => 400,
1565 - ),
1566 - 'spacing' => array(
1567 - 'md' => 0,
1568 - 'unit' => 'px',
1569 - ),
1570 - ),
1571 - ),
1572 - array(
1573 - 'label' => 'Captions',
1574 - 'value' => array(
1575 - 'openTypography' => 1,
1576 - 'size' => array(
1577 - 'md' => 13,
1578 - 'unit' => 'px',
1579 - ),
1580 - 'height' => array(
1581 - 'md' => 16,
1582 - 'unit' => 'px',
1583 - ),
1584 - 'fontFamily' => array(
1585 - 'family' => 'Roboto',
1586 - 'type' => 'sans-serif',
1587 - 'fontWeight' => 400,
1588 - ),
1589 - 'spacing' => array(
1590 - 'md' => 0,
1591 - 'unit' => 'px',
1592 - ),
1593 - ),
1594 - ),
1595 - ),
1596 - 'boxshadow' => array(
1597 - array(
1598 - 'label' => 'Normal Shadow',
1599 - 'value' => array(
1600 - 'openShadow' => 1,
1601 - 'inset' => 0,
1602 - 'horizontal' => 2,
1603 - 'vertical' => 6,
1604 - 'blur' => 10,
1605 - 'spread' => 0,
1606 - 'color' => 'rgba(0,0,0,0.15)',
1607 - ),
1608 - ),
1609 - array(
1610 - 'label' => 'Hover Shadow',
1611 - 'value' => array(
1612 - 'openShadow' => 1,
1613 - 'inset' => 0,
1614 - 'horizontal' => 2,
1615 - 'vertical' => 5,
1616 - 'blur' => 14,
1617 - 'spread' => 3,
1618 - 'color' => 'rgba(0,0,0,0.2)',
1619 - ),
1620 - ),
1621 - ),
1622 - ),
1623 - 'preset2' => array(
1624 - 'name' => 'Preset 2',
1625 - 'key' => 'preset2',
1626 - 'colors' => array(
1627 - array(
1628 - 'label' => 'Primary',
1629 - 'value' => '#8072FC',
1630 - ),
1631 - array(
1632 - 'label' => 'Secondary',
1633 - 'value' => '#6FC784',
1634 - ),
1635 - array(
1636 - 'label' => 'Tertiary',
1637 - 'value' => '#FF5A6E',
1638 - ),
1639 - array(
1640 - 'label' => 'Accent',
1641 - 'value' => '#F3F3F3',
1642 - ),
1643 - array(
1644 - 'label' => 'Background',
1645 - 'value' => '#888888',
1646 - ),
1647 - ),
1648 - 'gradient' => array(
1649 - array(
1650 - 'label' => 'Primary',
1651 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1652 - ),
1653 -
1654 - array(
1655 - 'label' => 'Secondary',
1656 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1657 - ),
1658 -
1659 - array(
1660 - 'label' => 'Tertiary',
1661 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1662 - ),
1663 -
1664 - array(
1665 - 'label' => 'Accent',
1666 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1667 - ),
1668 -
1669 - array(
1670 - 'label' => 'Background',
1671 - 'value' => 'linear-gradient(135deg,rgb(8,148,229) 0%,rgb(155,81,224) 100%)',
1672 - ),
1673 - ),
1674 - 'spacing' => array(
1675 - array(
1676 - 'label' => 'Large',
1677 - 'value' => array(
1678 - 'md' => 70,
1679 - 'unit' => 'px',
1680 - ),
1681 - ),
1682 - array(
1683 - 'label' => 'Medium',
1684 - 'value' => array(
1685 - 'md' => 40,
1686 - 'unit' => 'px',
1687 - ),
1688 - ),
1689 - array(
1690 - 'label' => 'Small',
1691 - 'value' => array(
1692 - 'md' => 20,
1693 - 'unit' => 'px',
1694 - ),
1695 -
1696 - ),
1697 - ),
1698 - 'typography' => array(
1699 - array(
1700 - 'label' => 'Display Text',
1701 - 'value' => array(
1702 - 'openTypography' => 1,
1703 - 'size' => array(
1704 - 'md' => 65,
1705 - 'unit' => 'px',
1706 - ),
1707 - 'height' => array(
1708 - 'md' => 75,
1709 - 'unit' => 'px',
1710 - ),
1711 - 'fontFamily' => array(
1712 - 'family' => 'Roboto',
1713 - 'type' => 'sans-serif',
1714 - 'fontWeight' => 700,
1715 - ),
1716 - 'spacing' => array(
1717 - 'md' => 0,
1718 - 'unit' => 'px',
1719 - ),
1720 - ),
1721 - ),
1722 - array(
1723 - 'label' => 'Headline',
1724 - 'value' => array(
1725 - 'openTypography' => 1,
1726 - 'size' => array(
1727 - 'md' => 45,
1728 - 'unit' => 'px',
1729 - ),
1730 - 'height' => array(
1731 - 'md' => 60,
1732 - 'unit' => 'px',
1733 - ),
1734 - 'fontFamily' => array(
1735 - 'family' => 'Roboto',
1736 - 'type' => 'sans-serif',
1737 - 'fontWeight' => 700,
1738 - ),
1739 - 'spacing' => array(
1740 - 'md' => 0,
1741 - 'unit' => 'px',
1742 - ),
1743 - ),
1744 - ),
1745 - array(
1746 - 'label' => 'Sub Headline',
1747 - 'value' => array(
1748 - 'openTypography' => 1,
1749 - 'size' => array(
1750 - 'md' => 38,
1751 - 'unit' => 'px',
1752 - ),
1753 - 'height' => array(
1754 - 'md' => 45,
1755 - 'unit' => 'px',
1756 - ),
1757 - 'fontFamily' => array(
1758 - 'family' => 'Roboto',
1759 - 'type' => 'sans-serif',
1760 - 'fontWeight' => 500,
1761 - ),
1762 - 'spacing' => array(
1763 - 'md' => 0,
1764 - 'unit' => 'px',
1765 - ),
1766 - ),
1767 - ),
1768 - array(
1769 - 'label' => 'Title 1',
1770 - 'value' => array(
1771 - 'openTypography' => 1,
1772 - 'size' => array(
1773 - 'md' => 30,
1774 - 'unit' => 'px',
1775 - ),
1776 - 'height' => array(
1777 - 'md' => 40,
1778 - 'unit' => 'px',
1779 - ),
1780 - 'fontFamily' => array(
1781 - 'family' => 'Roboto',
1782 - 'type' => 'sans-serif',
1783 - 'fontWeight' => 500,
1784 - ),
1785 - 'spacing' => array(
1786 - 'md' => 0,
1787 - 'unit' => 'px',
1788 - ),
1789 - ),
1790 - ),
1791 - array(
1792 - 'label' => 'Title 2',
1793 - 'value' => array(
1794 - 'openTypography' => 1,
1795 - 'size' => array(
1796 - 'md' => 25,
1797 - 'unit' => 'px',
1798 - ),
1799 - 'height' => array(
1800 - 'md' => 30,
1801 - 'unit' => 'px',
1802 - ),
1803 - 'fontFamily' => array(
1804 - 'family' => 'Roboto',
1805 - 'type' => 'sans-serif',
1806 - 'fontWeight' => 400,
1807 - ),
1808 - 'spacing' => array(
1809 - 'md' => 0,
1810 - 'unit' => 'px',
1811 - ),
1812 - ),
1813 - ),
1814 - array(
1815 - 'label' => 'Body',
1816 - 'value' => array(
1817 - 'openTypography' => 1,
1818 - 'size' => array(
1819 - 'md' => 17,
1820 - 'unit' => 'px',
1821 - ),
1822 - 'height' => array(
1823 - 'md' => 22,
1824 - 'unit' => 'px',
1825 - ),
1826 - 'fontFamily' => array(
1827 - 'family' => 'Roboto',
1828 - 'type' => 'sans-serif',
1829 - 'fontWeight' => 400,
1830 - ),
1831 - 'spacing' => array(
1832 - 'md' => 0,
1833 - 'unit' => 'px',
1834 - ),
1835 - ),
1836 - ),
1837 - array(
1838 - 'label' => 'Captions',
1839 - 'value' => array(
1840 - 'openTypography' => 1,
1841 - 'size' => array(
1842 - 'md' => 13,
1843 - 'unit' => 'px',
1844 - ),
1845 - 'height' => array(
1846 - 'md' => 16,
1847 - 'unit' => 'px',
1848 - ),
1849 - 'fontFamily' => array(
1850 - 'family' => 'Roboto',
1851 - 'type' => 'sans-serif',
1852 - 'fontWeight' => 400,
1853 - ),
1854 - 'spacing' => array(
1855 - 'md' => 0,
1856 - 'unit' => 'px',
1857 - ),
1858 - ),
1859 - ),
1860 - ),
1861 - 'boxshadow' => array(
1862 - array(
1863 - 'label' => 'Normal Shadow',
1864 - 'value' => array(
1865 - 'openShadow' => 1,
1866 - 'inset' => 0,
1867 - 'horizontal' => 2,
1868 - 'vertical' => 6,
1869 - 'blur' => 10,
1870 - 'spread' => 0,
1871 - 'color' => 'rgba(0,0,0,0.15)',
1872 - ),
1873 - ),
1874 - array(
1875 - 'label' => 'Hover Shadow',
1876 - 'value' => array(
1877 - 'openShadow' => 1,
1878 - 'inset' => 0,
1879 - 'horizontal' => 2,
1880 - 'vertical' => 5,
1881 - 'blur' => 14,
1882 - 'spread' => 3,
1883 - 'color' => 'rgba(0,0,0,0.2)',
1884 - ),
1885 - ),
1886 - ),
1887 - ),
1888 - ),
1889 - 'globalContainer' => array(
1890 - 'md' => '',
1891 - 'unit' => 'px',
1892 - ),
1893 - );
1894 -
1895 - update_option( 'tpgb_global_options', json_encode( $static_meta ) );
1896 - $plus_settings = $static_meta;
1897 - }
1898 -
1899 - $active_id = ! empty( $plus_settings['active'] ) ? $plus_settings['active'] : '';
1900 - $preset_array = ! empty( $plus_settings['presets'] ) ? $plus_settings['presets'] : array();
1901 - $act_preset = ! empty( $plus_settings['presets'][ $active_id ] ) ? $plus_settings['presets'][ $active_id ] : array();
1902 -
1903 - foreach ( $act_preset['colors'] as $index => &$item ) {
1904 - $item['id'] = $index + 1;
1905 - }
1906 - unset( $item );
1907 -
1908 - foreach ( $act_preset['typography'] as $index => &$item ) {
1909 - $item['id'] = $index + 1;
1910 - }
1911 - unset( $item );
1912 -
1913 - $act_preset['color'] = $act_preset['colors'];
1914 - unset( $act_preset['colors'] );
1915 -
1916 - $response = array(
1917 - 'message' => __( 'Global data Found', 'wdesignkit' ),
1918 - 'description' => __( 'Global Color and Typography found', 'wdesignkit' ),
1919 - 'data' => $act_preset,
1920 - 'success' => true,
1921 - );
1922 - }
1923 -
1924 - wp_send_json( $response );
1925 - wp_die();
1926 - }
1927 -
1928 - /**
1929 - *
1930 - * Get site settings.
1931 - *
1932 - * @since 2.1.3
1933 - */
1934 - protected function wdkit_get_site_setting() {
1935 -
1936 - $kit_id = get_option( 'elementor_active_kit' );
1937 - if ( empty( $kit_id ) ) {
1938 - $response = array(
1939 - 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
1940 - 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
1941 - 'success' => false,
1942 - );
1943 -
1944 - wp_send_json( $response );
1945 - wp_die();
1946 - }
1947 -
1948 - $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
1949 -
1950 - $container_width = ! empty( $kit_meta['container_width'] ) ? $kit_meta['container_width'] : array();
1951 - $globals = ! empty( $kit_meta['__globals__'] ) ? $kit_meta['__globals__'] : array();
1952 - $body_background_color = ! empty( $kit_meta['body_background_color'] ) ? $kit_meta['body_background_color'] : array();
1953 -
1954 - $site_globals = array(
1955 - 'body_background_color' => $body_background_color,
1956 - 'container_width' => $container_width,
1957 - 'globals' => $globals,
1958 - );
1959 -
1960 - $response = array(
1961 - 'message' => __( 'Global data Found', 'wdesignkit' ),
1962 - 'description' => __( 'Global Color and Typography found', 'wdesignkit' ),
1963 - 'data' => $site_globals,
1964 - 'success' => true,
1965 - );
1966 -
1967 - wp_send_json( $response );
1968 - wp_die();
1969 - }
1970 -
1971 - /**
1972 - *
1973 - * update site settings.
1974 - *
1975 - * @since 2.1.3
1976 - */
1977 - protected function wdkit_update_site_setting() {
1978 -
1979 - $builder = ! empty( $_POST['builder'] ) ? sanitize_text_field( $_POST['builder'] ) : '';
1980 - $site_data = ! empty( $_POST['site_data'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['site_data'] ) ), true ) : array();
1981 -
1982 - if ( 'elementor' == $builder ) {
1983 - $kit_id = get_option( 'elementor_active_kit' );
1984 - if ( ! $kit_id && did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Core\Kits\Manager' ) ) {
1985 - \Elementor\Core\Kits\Manager::create_default_kit();
1986 - $kit_id = get_option( 'elementor_active_kit' );
1987 - }
1988 -
1989 - if ( ! $kit_id ) {
1990 - $response = array(
1991 - 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
1992 - 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
1993 - 'success' => false,
1994 - );
1995 -
1996 - wp_send_json( $response );
1997 - wp_die();
1998 - }
1999 -
2000 - // A freshly created kit has no `_elementor_page_settings` meta yet,
2001 - // so an empty result here is a valid starting point, not an error.
2002 - $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
2003 - if ( ! is_array( $kit_meta ) ) {
2004 - $kit_meta = array();
2005 - }
2006 -
2007 - $kit_meta['container_width'] = ! empty( $site_data['container_width'] ) ? $site_data['container_width'] : array();
2008 - $kit_meta['__globals__'] = ! empty( $site_data['globals'] ) ? $site_data['globals'] : array();
2009 - $kit_meta['body_background_color'] = ! empty( $site_data['body_background_color'] ) ? $site_data['body_background_color'] : array();
2010 -
2011 - update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta );
2012 -
2013 - // Regenerate Elementor's cached CSS. Writing the kit meta directly does
2014 - // not rebuild the kit stylesheet, so the imported body background colour
2015 - // and container width would otherwise never render on the frontend.
2016 - $this->wdkit_regenerate_elementor_kit_css();
2017 -
2018 - $response = array(
2019 - 'message' => __( 'Site data Updated', 'wdesignkit' ),
2020 - 'description' => __( 'Site Globals Updated', 'wdesignkit' ),
2021 - 'success' => true,
2022 - );
2023 -
2024 - } elseif ( 'gutenberg' == $builder ) {
2025 - $plus_settings = get_option( 'tpgb_global_options' );
2026 -
2027 - $site_preset = json_decode( $plus_settings, true );
2028 - $site_preset['globalContainer'] = $site_data;
2029 -
2030 - update_option( 'tpgb_global_options', json_encode( $site_preset ) );
2031 -
2032 - $response = array(
2033 - 'message' => __( 'Site data Updated', 'wdesignkit' ),
2034 - 'description' => __( 'Site Globals Updated', 'wdesignkit' ),
2035 - 'success' => true,
2036 - );
2037 -
2038 - } else {
2039 - $response = array(
2040 - 'message' => __( 'Builder Not Found !', 'wdesignkit' ),
2041 - 'description' => __( 'Template Builder not Found', 'wdesignkit' ),
2042 - 'success' => true,
2043 - );
2044 - }
2045 -
2046 - wp_send_json( $response );
2047 - wp_die();
2048 - }
2049 -
2050 - /**
2051 - *
2052 - * Update Elementor Global color and Typography.
2053 - *
2054 - * @since 1.1.20
2055 - */
2056 - protected function wdkit_update_global_val() {
2057 -
2058 - $builder = ! empty( $_POST['builder'] ) ? sanitize_text_field( $_POST['builder'] ) : '';
2059 -
2060 - if ( 'elementor' == $builder ) {
2061 -
2062 - $g_color = ! empty( $_POST['g_color'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_color'] ) ), true ) : array();
2063 - $g_typo = ! empty( $_POST['g_typography'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['g_typography'] ) ), true ) : array();
2064 -
2065 - // Get colors from Elementor Site Kit
2066 - $kit_id = get_option( 'elementor_active_kit' );
2067 - if ( ! $kit_id && did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Core\Kits\Manager' ) ) {
2068 - // No kit has ever been created on this site (the option is only
2069 - // ever populated by Elementor's own activation hook). Create one
2070 - // via Elementor's own helper so the import has somewhere to write.
2071 - \Elementor\Core\Kits\Manager::create_default_kit();
2072 - $kit_id = get_option( 'elementor_active_kit' );
2073 - }
2074 -
2075 - if ( ! $kit_id ) {
2076 - $response = array(
2077 - 'message' => __( 'Elementor kit not found', 'wdesignkit' ),
2078 - 'description' => __( 'No active Elementor kit found', 'wdesignkit' ),
2079 - 'success' => false,
2080 - );
2081 -
2082 - wp_send_json( $response );
2083 - wp_die();
2084 - }
2085 -
2086 - // A freshly created kit has no `_elementor_page_settings` meta yet,
2087 - // so an empty result here is a valid starting point, not an error.
2088 - $kit_meta = get_post_meta( $kit_id, '_elementor_page_settings', true );
2089 - if ( ! is_array( $kit_meta ) ) {
2090 - $kit_meta = array();
2091 - }
2092 -
2093 - $kit_meta['custom_colors'] = array_merge( $g_color, $kit_meta['custom_colors'] ?? array() );
2094 - $kit_meta['custom_typography'] = array_merge( $g_typo, $kit_meta['custom_typography'] ?? array() );
2095 -
2096 - update_post_meta( $kit_id, '_elementor_page_settings', $kit_meta );
2097 -
2098 - // Regenerate Elementor's cached CSS. Writing the kit meta directly does
2099 - // not rebuild the kit stylesheet, so the imported global colours and
2100 - // fonts would otherwise never render on the frontend.
2101 - $this->wdkit_regenerate_elementor_kit_css();
2102 -
2103 - $response = array(
2104 - 'message' => __( 'Global data Updated', 'wdesignkit' ),
2105 - 'description' => __( 'Global Color and Typography Updated', 'wdesignkit' ),
2106 - 'success' => true,
2107 - );
2108 -
2109 - } elseif ( 'gutenberg' == $builder ) {
2110 - $new_preset = ! empty( $_POST['new_preset'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['new_preset'] ) ), true ) : array();
2111 - $new_preset_id = ! empty( $new_preset['key'] ) ? $new_preset['key'] : '';
2112 - $plus_settings = get_option( 'tpgb_global_options' );
2113 - $site_preset = json_decode( $plus_settings, true );
2114 -
2115 - $site_preset['presets'][ $new_preset_id ] = $new_preset;
2116 - $site_preset['active'] = $new_preset_id;
2117 -
2118 - update_option( 'tpgb_global_options', json_encode( $site_preset ) );
2119 -
2120 - $response = array(
2121 - 'message' => __( 'Global data Updated', 'wdesignkit' ),
2122 - 'description' => __( 'Global Color and Typography Updated', 'wdesignkit' ),
2123 - 'success' => true,
2124 - );
2125 -
2126 - } else {
2127 - $response = array(
2128 - 'message' => __( 'Builder Not Found !', 'wdesignkit' ),
2129 - 'description' => __( 'Template Builder not Found', 'wdesignkit' ),
2130 - 'success' => true,
2131 - );
2132 - }
2133 -
2134 - wp_send_json( $response );
2135 - wp_die();
2136 - }
2137 -
2138 - /**
2139 - * Regenerate Elementor's cached CSS files after the active kit's
2140 - * `_elementor_page_settings` meta has been changed directly.
2141 - *
2142 - * Elementor renders global colours, global fonts and the body background
2143 - * colour into a cached kit stylesheet. Updating the meta via
2144 - * update_post_meta() does not rebuild that stylesheet, so imported site
2145 - * settings never reach the frontend until the cache is cleared. This
2146 - * mirrors the clear_cache() call already used by the page/section import.
2147 - *
2148 - * @since 2.3.2
2149 - *
2150 - * @return void
2151 - */
2152 - protected function wdkit_regenerate_elementor_kit_css() {
2153 - if ( did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Plugin' ) ) {
2154 - \Elementor\Plugin::$instance->files_manager->clear_cache();
2155 - }
2156 - }
2157 -
2158 - /**
2159 - *
2160 - * Create Gutenberg page and save for re-generate css file.
2161 - *
2162 - * @since 1.2.3
2163 - */
2164 - protected function wdkit_update_preset() {
2165 -
2166 - $act_type = ! empty( $_POST['act_type'] ) ? sanitize_text_field( $_POST['act_type'] ) : '';
2167 - $post_id = ! empty( $_POST['post_id'] ) ? sanitize_text_field( $_POST['post_id'] ) : '';
2168 -
2169 - if ( 'create' == $act_type ) {
2170 -
2171 - $page_id = wp_insert_post(
2172 - array(
2173 - 'post_title' => 'WDesignKit Gutenberg',
2174 - 'post_status' => 'publish',
2175 - 'post_type' => 'post',
2176 - 'post_name' => sanitize_title( 'wdesignkit' ),
2177 - 'post_content' => '<!-- wp:heading --><h2 class="wp-block-heading">Add Your Heading Text Here<h2><!-- /wp:heading -->',
2178 - 'meta_input' => array(
2179 - 'gutenberg_preview' => true,
2180 - '_wp_page_template' => 'default',
2181 - ),
2182 - )
2183 - );
2184 -
2185 - if ( is_wp_error( $page_id ) || ! $page_id ) {
2186 - $response = array(
2187 - 'success' => true,
2188 - 'message' => esc_html__( 'Page Not Found!', 'wdesignkit' ),
2189 - 'description' => esc_html__( 'Page Not Found!', 'wdesignkit' ),
2190 - );
2191 -
2192 - wp_send_json( $response );
2193 - wp_die();
2194 - }
2195 -
2196 - update_post_meta( $page_id, '_edit_lock', time() . ':1' );
2197 - update_post_meta( $page_id, '_edit_last', get_current_user_id() );
2198 -
2199 - $preview_url = admin_url( 'post.php?post=' . $page_id . '&action=edit' );
2200 -
2201 - $response = array(
2202 - 'success' => true,
2203 - 'post_id' => $page_id,
2204 - 'preview_url' => $preview_url,
2205 - 'message' => esc_html__( 'Page Created', 'wdesignkit' ),
2206 - 'description' => esc_html__( 'Page Created', 'wdesignkit' ),
2207 - );
2208 -
2209 - wp_send_json( $response );
2210 - wp_die();
2211 -
2212 - }
2213 -
2214 - if ( ! empty( $post_id ) && ( $act_type == 'remove' ) ) {
2215 -
2216 - wp_delete_post( $post_id, true );
2217 -
2218 - $response = array(
2219 - 'success' => true,
2220 - 'message' => esc_html__( 'post deleted', 'wdesignkit' ),
2221 - 'description' => esc_html__( 'post deleted', 'wdesignkit' ),
2222 - );
2223 -
2224 - wp_send_json( $response );
2225 - wp_die();
2226 - }
2227 - }
2228 -
2229 - /**
2230 - *
2231 1004 * It is For Find User Existing template List.
2232 1005 *
2233 1006 * @since 1.0.6
2234 1007 */
@@ -2255,39 +1028,16 @@
2255 1028 * @since 1.0.6
2256 1029 */
2257 1030 protected function wdkit_update_template() {
2258 1031 $array_data = array(
2259 - 'data' => isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '',
2260 - 'post_id' => isset( $_POST['post_id'] ) ? sanitize_text_field( wp_unslash( $_POST['post_id'] ) ) : '',
2261 - 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
2262 - 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
2263 - 'id' => isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '',
2264 - 'global_data' => isset( $_POST['global_data'] ) ? wp_unslash( $_POST['global_data'] ) : array(),
2265 - // 'global_font_family' => isset( $_POST['global_font_family'] ) ? wp_unslash( $_POST['global_font_family'] ) : array(),
2266 - // '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'] ) ) : '',
2267 1036 );
2268 1037
2269 - if ( ! empty( $array_data['post_id'] ) ) {
2270 - $custom_fields = array();
2271 - $post_id = $array_data['post_id'];
1038 + $response = $this->wkit_api_call( $array_data, 'existing_template' );
2272 1039
2273 - $meta_fields = get_post_custom( $post_id );
2274 -
2275 - foreach ( $meta_fields as $key => $value ) {
2276 - if ( str_contains( $key, 'nxt-' ) ) {
2277 - $custom_fields[ $key ] = $value;
2278 - }
2279 - }
2280 -
2281 - if ( ! empty( $custom_fields ) ) {
2282 - $data = json_decode( $array_data['data'], true );
2283 - $data['custom_meta'] = $custom_fields;
2284 - $array_data['data'] = wp_json_encode( $data );
2285 - }
2286 - }
2287 -
2288 - $array_data['remove'] = 'yes';
2289 - $response = $this->wkit_api_call( $array_data, 'existing_template' );
2290 1040 wp_send_json( $response );
2291 1041 wp_die();
2292 1042 }
2293 1043
@@ -2331,9 +1081,8 @@
2331 1081 */
2332 1082 protected function wdkit_check_plugins_depends() {
2333 1083 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ) ) : array();
2334 1084 $update_plugin = array();
2335 - $update_theme = array();
2336 1085
2337 1086 if ( empty( $plugins ) || ! is_array( $plugins ) ) {
2338 1087 $this->wdkit_error_msg( array( 'plugins' => 'No Plugins' ) );
2339 1088 }
@@ -2346,9 +1095,8 @@
2346 1095
2347 1096 if ( is_null( $pluginslug ) ) {
2348 1097 $plugin->status = 'warning';
2349 1098 $update_plugin[] = $plugin;
2350 - $update_theme[] = $plugin;
2351 1099
2352 1100 continue;
2353 1101 }
2354 1102
@@ -2369,13 +1117,12 @@
2369 1117 $plugin->status = 'active';
2370 1118 $update_plugin[] = $plugin;
2371 1119 }
2372 1120 } elseif ( 'theme' === $type ) {
2373 - $theme_array = array_keys( wp_get_themes() );
2374 - $theme_slug = get_stylesheet();
2375 - $parent_theme_slug = get_template();
1121 + $theme_array = array_keys( wp_get_themes() );
1122 + $theme_slug = get_stylesheet();
2376 1123
2377 - if ( $theme_slug === $plugin->original_slug || $parent_theme_slug === $plugin->original_slug ) {
1124 + if ( $theme_slug === $plugin->original_slug ) {
2378 1125
2379 1126 $plugin->status = 'active';
2380 1127 } else {
2381 1128 $theme_name = $plugin->original_slug;
@@ -2389,19 +1136,13 @@
2389 1136 $plugin->status = 'inactive';
2390 1137 }
2391 1138 }
2392 1139
2393 - $update_theme[] = $plugin;
1140 + $update_plugin[] = $plugin;
2394 1141 }
2395 1142 }
2396 1143
2397 - $response = array(
2398 - 'plugins' => $update_plugin,
2399 - 'theme' => $update_theme,
2400 - 'ele_container' => get_option( 'elementor_experiment-container', false ),
2401 - );
2402 -
2403 - $this->wdkit_success_msg( $response );
1144 + $this->wdkit_success_msg( array( 'plugins' => $update_plugin ) );
2404 1145 }
2405 1146
2406 1147 /**
2407 1148 *
@@ -2412,9 +1153,8 @@
2412 1153 */
2413 1154 protected function wdkit_install_plugins_depends() {
2414 1155 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ), true ) : array();
2415 1156 $type = ! empty( $plugins['type'] ) ? $plugins['type'] : 'plugin';
2416 - $p_id = ! empty( $plugins['p_id'] ) ? $plugins['p_id'] : 'plugin';
2417 1157
2418 1158 $responce = '';
2419 1159 if ( 'plugin' === $type ) {
2420 1160 $responce = Wdkit_Depends_Installer::get_instance()->wdkit_install_plugin( $plugins );
@@ -2421,46 +1161,24 @@
2421 1161 } elseif ( 'theme' === $type ) {
2422 1162 $theme_name = ! empty( $plugins['original_slug'] ) ? $plugins['original_slug'] : '';
2423 1163 if ( ! empty( $theme_name ) ) {
2424 1164
2425 - $theme_array = array_keys( wp_get_themes() );
2426 - $theme_slug = get_stylesheet();
1165 + $activate_result = switch_theme( $theme_name );
2427 1166
2428 - if ( in_array( $theme_name, $theme_array ) ) {
2429 - $activate_result = switch_theme( $theme_name );
2430 -
2431 - if ( ! is_wp_error( $activate_result ) ) {
2432 - $responce = array(
2433 - 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ),
2434 - 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ),
2435 - 'slug' => 'nexter',
2436 - 'p_id' => $p_id,
2437 - 'status' => 'active',
2438 - 'success' => true,
2439 - );
2440 - } else {
2441 - $responce = array(
2442 - 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ),
2443 - 'description' => $activate_result->get_error_message(),
2444 - 'status' => 'inactive',
2445 - 'p_id' => $p_id,
2446 - 'success' => false,
2447 - );
2448 - }
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 + );
2449 1175 } else {
2450 - $result = $this->wdkit_install_theme_depends( $theme_name );
2451 -
2452 - $message = ! empty( $result['message'] ) ? $result['message'] : esc_html__( 'Somthing Wrong', 'wdesignkit' );
2453 - $description = ! empty( $result['description'] ) ? $result['description'] : esc_html__( 'Error Somthing Wrong', 'wdesignkit' );
2454 - $status = ! empty( $result['status'] ) ? $result['status'] : esc_html__( 'inactive', 'wdesignkit' );
2455 - $success = ! empty( $result['success'] ) ? $result['success'] : false;
2456 -
2457 1176 $responce = array(
2458 - 'message' => $message,
2459 - 'description' => $description,
2460 - 'p_id' => $p_id,
2461 - 'status' => $status,
2462 - 'success' => $success,
1177 + 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ),
1178 + 'description' => $activate_result->get_error_message(),
1179 + 'status' => 'inactive',
1180 + 'success' => false,
2463 1181 );
2464 1182 }
2465 1183 } else {
2466 1184 $responce = array(
@@ -2465,9 +1183,9 @@
2465 1183 } else {
2466 1184 $responce = array(
2467 1185 'message' => esc_html__( 'Theme Name not Found', 'wdesignkit' ),
2468 1186 'description' => esc_html__( 'Can Not Found Theme Name you Enterd.', 'wdesignkit' ),
2469 - 'success' => false,
1187 + 'success' => true,
2470 1188 );
2471 1189 }
2472 1190 }
2473 1191
@@ -2474,103 +1192,8 @@
2474 1192 wp_send_json( $responce );
2475 1193 wp_die();
2476 1194 }
2477 1195
2478 - protected function wdkit_install_theme_depends( $name = 'nexter' ) {
2479 -
2480 - if ( ! current_user_can( 'install_themes' ) ) {
2481 - $response = $this->tpae_set_response( false, 'Invalid nonce.', 'The security check failed. Please refresh the page and try again.' );
2482 - return $response;
2483 - }
2484 -
2485 - $theme_slug = $name;
2486 - $theme_api_url = 'https://api.wordpress.org/themes/info/1.0/';
2487 -
2488 - // Parameters for the request
2489 - $args = array(
2490 - 'body' => array(
2491 - 'action' => 'theme_information',
2492 - 'request' => serialize(
2493 - (object) array(
2494 - 'slug' => $name,
2495 - 'fields' => array(
2496 - 'description' => false,
2497 - 'sections' => false,
2498 - 'rating' => true,
2499 - 'ratings' => false,
2500 - 'downloaded' => true,
2501 - 'download_link' => true,
2502 - 'last_updated' => true,
2503 - 'homepage' => true,
2504 - 'tags' => true,
2505 - 'template' => true,
2506 - 'active_installs' => false,
2507 - 'parent' => false,
2508 - 'versions' => false,
2509 - 'screenshot_url' => true,
2510 - 'active_installs' => false,
2511 - ),
2512 - )
2513 - ),
2514 - ),
2515 - );
2516 -
2517 - // Make the request
2518 - $response = wp_remote_post( $theme_api_url, $args );
2519 - // Check for errors
2520 - if ( is_wp_error( $response ) ) {
2521 - $error_message = $response->get_error_message();
2522 -
2523 - $result = $this->tpae_set_response( false, 'oops', 'oops', '' );
2524 - } else {
2525 - $theme_info = unserialize( $response['body'] );
2526 - $theme_name = $theme_info->name;
2527 - $theme_zip_url = $theme_info->download_link;
2528 -
2529 - global $wp_filesystem;
2530 - // Install the theme
2531 - $theme = wp_remote_get( $theme_zip_url, array( 'timeout' => 30 ) );
2532 -
2533 - if ( ! function_exists( 'WP_Filesystem' ) ) {
2534 - require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' );
2535 - }
2536 -
2537 - WP_Filesystem();
2538 -
2539 - $active_theme = wp_get_theme();
2540 - $theme_name = $active_theme->get( 'Name' );
2541 -
2542 - $wp_filesystem->put_contents( WP_CONTENT_DIR . '/themes/' . $theme_slug . '.zip', $theme['body'] );
2543 - $zip = new ZipArchive();
2544 - if ( $zip->open( WP_CONTENT_DIR . '/themes/' . $theme_slug . '.zip' ) === true ) {
2545 - $zip->extractTo( WP_CONTENT_DIR . '/themes/' );
2546 - $zip->close();
2547 - }
2548 -
2549 - $wp_filesystem->delete( WP_CONTENT_DIR . '/themes/' . $theme_slug . '.zip' );
2550 -
2551 - $activate_result = switch_theme( $name );
2552 -
2553 - if ( ! is_wp_error( $activate_result ) ) {
2554 - $response = array(
2555 - 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ),
2556 - 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ),
2557 - 'status' => 'active',
2558 - 'success' => true,
2559 - );
2560 - } else {
2561 - $response = array(
2562 - 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ),
2563 - 'description' => $activate_result->get_error_message(),
2564 - 'status' => 'inactive',
2565 - 'success' => false,
2566 - );
2567 - }
2568 - }
2569 -
2570 - return $response;
2571 - }
2572 -
2573 1196 /**
2574 1197 *
2575 1198 * It is Use Update WDesignKit plugin latest version.
2576 1199 *
@@ -2599,118 +1222,25 @@
2599 1222 * Get Download Template Content
2600 1223 *
2601 1224 * @since 1.0.0
2602 1225 */
2603 - protected function wdkit_activate_container() {
1226 + protected function wdkit_import_template() {
1227 + $args = $this->wdkit_parse_args( $_POST );
2604 1228
2605 - $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 + );
2606 1236
2607 - if ( $option_value === false ) {
2608 - add_option( 'elementor_experiment-container', 'active' );
2609 - } else {
2610 - update_option( 'elementor_experiment-container', 'active' );
1237 + wp_send_json( $response );
1238 + wp_die();
2611 1239 }
2612 1240
2613 - $result = array(
2614 - 'message' => esc_html__( 'Container Activated Successfully', 'wdesignkit' ),
2615 - 'description' => esc_html__( 'Elementor Container Activated Successfully.', 'wdesignkit' ),
2616 - 'success' => true,
2617 - );
2618 -
2619 - wp_send_json( $response );
2620 - wp_die();
2621 - }
2622 -
2623 - /**
2624 - * import category and tags for post
2625 - *
2626 - * @since 2.0.0
2627 - */
2628 - protected function wdkit_import_taxonomy() {
2629 - $category = isset( $_POST['category'] ) ? json_decode( wp_unslash( $_POST['category'] ) ) : array();
2630 - $tags = isset( $_POST['tags'] ) ? json_decode( wp_unslash( $_POST['tags'] ) ) : array();
2631 -
2632 - $response = array(
2633 - 'success' => false,
2634 - 'categories' => array(),
2635 - 'tags' => array(),
2636 - );
2637 -
2638 - if ( ! empty( $category ) && count( $category ) > 0 ) {
2639 - foreach ( $category as $category_name ) {
2640 - $category_name = sanitize_text_field( $category_name );
2641 -
2642 - $term_exists = term_exists( $category_name, 'category' );
2643 - if ( ! $term_exists ) {
2644 - $result = wp_insert_term( $category_name, 'category' );
2645 - if ( ! is_wp_error( $result ) ) {
2646 - $response['categories'][] = array(
2647 - 'name' => $category_name,
2648 - 'term_id' => $result['term_id'],
2649 - );
2650 - } else {
2651 - $response['categories'][] = array(
2652 - 'name' => $category_name,
2653 - 'error' => $result->get_error_message(),
2654 - );
2655 - }
2656 - } else {
2657 - $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
2658 - $response['categories'][] = array(
2659 - 'name' => $category_name,
2660 - 'term_id' => $term_id,
2661 - );
2662 - }
2663 - }
2664 -
2665 - $response['success'] = true;
2666 - }
2667 -
2668 - if ( ! empty( $tags ) && count( $tags ) > 0 ) {
2669 - foreach ( $tags as $tags_name ) {
2670 - $tags_name = sanitize_text_field( $tags_name );
2671 -
2672 - $term_exists = term_exists( $tags_name, 'post_tag' );
2673 - if ( ! $term_exists ) {
2674 - $result = wp_insert_term( $tags_name, 'post_tag' );
2675 - if ( ! is_wp_error( $result ) ) {
2676 - $response['tags'][] = array(
2677 - 'name' => $tags_name,
2678 - 'term_id' => $result['term_id'],
2679 - );
2680 - } else {
2681 - $response['tags'][] = array(
2682 - 'name' => $tags_name,
2683 - 'error' => $result->get_error_message(),
2684 - );
2685 - }
2686 - } else {
2687 - $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
2688 - $response['tags'][] = array(
2689 - 'name' => $tags_name,
2690 - 'term_id' => $term_id,
2691 - );
2692 - }
2693 - }
2694 -
2695 - $response['success'] = true;
2696 - }
2697 -
2698 - wp_send_json( $response );
2699 - wp_die();
2700 - }
2701 -
2702 - /**
2703 - * Get Download Template Content
2704 - *
2705 - * @since 1.0.0
2706 - */
2707 - protected function wdkit_import_template() {
2708 - $args = $this->wdkit_parse_args( $_POST );
2709 - $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
2710 -
2711 1241 $response = '';
2712 - if ( empty( $args['template_id'] ) ) {
1242 + if ( empty( $args['email'] ) || empty( $args['template_id'] ) ) {
2713 1243 $result = array(
2714 1244 'content' => '',
2715 1245 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
2716 1246 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
@@ -2723,19 +1253,9 @@
2723 1253
2724 1254 $args['token'] = $this->wdkit_login_user_token( $args['email'] );
2725 1255
2726 1256 unset( $args['email'] );
2727 - $args['unique_id'] = get_option( 'wdkit_unique_id' ) ?? '';
2728 - $response = WDesignKit_Data_Query::get_data( $api_type, $args );
2729 -
2730 - if ( is_wp_error( $response ) ) {
2731 - wp_send_json( array(
2732 - 'success' => false,
2733 - 'message' => $response->get_error_message(),
2734 - ) );
2735 - wp_die();
2736 - }
2737 -
1257 + $response = WDesignKit_Data_Query::get_data( 'import_template', $args );
2738 1258 $custom_meta = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
2739 1259
2740 1260 /** Custom meta Field */
2741 1261 if ( ! empty( $custom_meta ) && 'true' === $custom_meta && ! empty( $response ) && ! empty( $response['content'] ) ) {
@@ -2771,259 +1291,8 @@
2771 1291 *
2772 1292 * @param array $content store media content.
2773 1293 * @param string $editor it is check editor.
2774 1294 */
2775 - /**
2776 - * Resolve a local upload URL back to its attachment ID.
2777 - *
2778 - * Handles the "-scaled" copy WordPress makes for large originals and any
2779 - * "-1920x1280" size suffix, both of which attachment_url_to_postid() misses because
2780 - * they are not the value stored in _wp_attached_file.
2781 - *
2782 - * @since 2.6.2
2783 - *
2784 - * @param string $url Local upload URL.
2785 - * @return int Attachment ID, or 0.
2786 - */
2787 - private static function wdkit_attachment_id_from_url( $url ) {
2788 - static $cache = array();
2789 -
2790 - if ( isset( $cache[ $url ] ) ) {
2791 - return $cache[ $url ];
2792 - }
2793 -
2794 - $id = (int) attachment_url_to_postid( $url );
2795 -
2796 - if ( ! $id ) {
2797 - // Try the original file behind a -scaled or -WxH derivative.
2798 - $stripped = preg_replace( '/-scaled(\.[a-z0-9]+)$/i', '$1', $url );
2799 - $stripped = preg_replace( '/-\d+x\d+(\.[a-z0-9]+)$/i', '$1', (string) $stripped );
2800 -
2801 - if ( $stripped && $stripped !== $url ) {
2802 - $id = (int) attachment_url_to_postid( $stripped );
2803 - }
2804 - }
2805 -
2806 - // Only remember hits. Page imports run concurrently, so an attachment created by a
2807 - // sibling request may not exist yet when this is first asked — caching that miss
2808 - // would keep every later control in this request pointing at nothing.
2809 - if ( $id ) {
2810 - $cache[ $url ] = $id;
2811 - }
2812 -
2813 - return $id;
2814 - }
2815 -
2816 - /**
2817 - * Is this media reference still pointing off-site?
2818 - *
2819 - * Template content arrives holding the URLs of wherever the media lived before. Those
2820 - * carry that site's attachment IDs, which have no meaning here - and can collide with
2821 - * unrelated local posts.
2822 - *
2823 - * @since 2.6.2
2824 - *
2825 - * @param string $url URL from a media control.
2826 - * @return bool True when the URL points at another site's uploads.
2827 - */
2828 - private static function wdkit_is_foreign_media_url( $url ) {
2829 -
2830 - if ( ! class_exists( 'Wdkit_Image_Guard' ) ) {
2831 - require_once WDKIT_INCLUDES . 'admin/class-wdkit-image-guard.php';
2832 - }
2833 -
2834 - $uploads = wp_get_upload_dir();
2835 -
2836 - return Wdkit_Image_Guard::is_foreign_media( $url, isset( $uploads['baseurl'] ) ? $uploads['baseurl'] : '' );
2837 - }
2838 -
2839 - /**
2840 - * Find - or make - the local attachment behind a source-site media URL.
2841 - *
2842 - * Elementor stamps every image it imports with `_elementor_source_image_hash`
2843 - * (sha1 of the URL it came from), and its importer consults that before doing any
2844 - * network work. Delegating here means a URL already imported at create time resolves
2845 - * from the database, and one that never made it is fetched exactly once.
2846 - *
2847 - * Only ever called for foreign URLs. Handing it a local URL would re-download the
2848 - * file and leave a duplicate, because the stored hash is of the *remote* URL and so
2849 - * would never match.
2850 - *
2851 - * @since 2.6.2
2852 - *
2853 - * @param string $url Source-site media URL.
2854 - * @param int $source_id The source site's attachment ID, used as Elementor's cache key.
2855 - * @return array Local `id` and `url`, or an empty array when it cannot be resolved.
2856 - */
2857 - private static function wdkit_localise_media_url( $url, $source_id = 0 ) {
2858 - static $cache = array();
2859 -
2860 - if ( isset( $cache[ $url ] ) ) {
2861 - return $cache[ $url ];
2862 - }
2863 -
2864 - if ( ! did_action( 'elementor/loaded' ) || ! class_exists( '\\Elementor\\Plugin' ) ) {
2865 - return array();
2866 - }
2867 -
2868 - $images = \Elementor\Plugin::$instance->templates_manager->get_import_images_instance();
2869 -
2870 - if ( ! $images ) {
2871 - return array();
2872 - }
2873 -
2874 - // A download may happen, so keep the oversized-image guard in force.
2875 - self::wdkit_guard_oversized_images();
2876 -
2877 - $imported = $images->import(
2878 - array(
2879 - // Elementor only checks its hash table when an id is present.
2880 - 'id' => $source_id ? $source_id : 1,
2881 - 'url' => $url,
2882 - )
2883 - );
2884 -
2885 - $local = ( ! empty( $imported['id'] ) && ! empty( $imported['url'] ) )
2886 - ? array(
2887 - 'id' => (int) $imported['id'],
2888 - 'url' => $imported['url'],
2889 - )
2890 - : array();
2891 -
2892 - // Remember hits only: a sibling request importing concurrently may simply not have
2893 - // finished yet, and caching that miss would strand every later control on this page.
2894 - if ( $local ) {
2895 - $cache[ $url ] = $local;
2896 - }
2897 -
2898 - return $local;
2899 - }
2900 -
2901 - /**
2902 - * Repair dangling attachment IDs across every page of a finished import.
2903 - *
2904 - * The create-time repair in wdkit_media_import() can only see attachments that already
2905 - * exist. Pages import concurrently and share images — an icon first imported by one
2906 - * page is referenced by several others — so a page that runs early legitimately cannot
2907 - * resolve an image a sibling request has not created yet.
2908 - *
2909 - * This runs at the finalize step, once every page and attachment exists, and fixes
2910 - * whatever the per-page pass had to leave behind.
2911 - *
2912 - * @since 2.6.2
2913 - *
2914 - * @param array $page_ids Imported post IDs.
2915 - * @return int Number of pages actually rewritten.
2916 - */
2917 - private function wdkit_sweep_attachment_ids( $page_ids ) {
2918 -
2919 - if ( empty( $page_ids ) || ! did_action( 'elementor/loaded' ) ) {
2920 - return 0;
2921 - }
2922 -
2923 - $fixed = 0;
2924 -
2925 - foreach ( array_unique( array_map( 'intval', $page_ids ) ) as $post_id ) {
2926 -
2927 - if ( ! $post_id ) {
2928 - continue;
2929 - }
2930 -
2931 - $raw = get_post_meta( $post_id, '_elementor_data', true );
2932 -
2933 - if ( empty( $raw ) ) {
2934 - continue;
2935 - }
2936 -
2937 - $data = is_array( $raw ) ? $raw : json_decode( $raw, true );
2938 -
2939 - if ( ! is_array( $data ) ) {
2940 - continue;
2941 - }
2942 -
2943 - $repaired = self::wdkit_repair_attachment_ids( $data );
2944 -
2945 - if ( wp_json_encode( $repaired ) === wp_json_encode( $data ) ) {
2946 - continue;
2947 - }
2948 -
2949 - // Save through the document API so Elementor regenerates the page CSS — the
2950 - // background-image rules are only emitted once the IDs resolve.
2951 - $document = \Elementor\Plugin::$instance->documents->get( $post_id );
2952 -
2953 - // Count only a save that actually happened. Document::save() returns false
2954 - // without saving when the current user cannot edit the post, and reporting
2955 - // those as repaired hides the fact that nothing changed.
2956 - if ( $document && $document->save( array( 'elements' => $repaired ) ) ) {
2957 - ++$fixed;
2958 - }
2959 - }
2960 -
2961 - if ( $fixed ) {
2962 - \Elementor\Plugin::$instance->files_manager->clear_cache();
2963 - }
2964 -
2965 - return $fixed;
2966 - }
2967 -
2968 - /**
2969 - * Repair media controls whose attachment ID does not resolve.
2970 - *
2971 - * Elementor media controls store `{ url, id }`. Controls flagged `has_sizes` — the
2972 - * container/section **background image** among them — do not render from `url` at all:
2973 - * CSS generation resolves the image through the attachment ID, so a dangling ID
2974 - * produces no `background-image` rule and the section renders with no image even
2975 - * though its URL is perfectly correct.
2976 - *
2977 - * IDs arrive dangling whenever Elementor's own importer does not rewrite a control —
2978 - * it carries the source site's ID, which means nothing locally. Now that the URL is
2979 - * already a local upload before import, the ID can simply be looked up from it.
2980 - *
2981 - * @since 2.6.2
2982 - *
2983 - * @param mixed $node Elementor data, walked recursively.
2984 - * @return mixed Data with resolvable attachment IDs.
2985 - */
2986 - private static function wdkit_repair_attachment_ids( $node ) {
2987 -
2988 - if ( ! is_array( $node ) ) {
2989 - return $node;
2990 - }
2991 -
2992 - // A media control value: has a url, and an id slot to correct.
2993 - if ( isset( $node['url'] ) && is_string( $node['url'] ) && array_key_exists( 'id', $node ) ) {
2994 -
2995 - $current = (int) $node['id'];
2996 - $is_live = $current && 'attachment' === get_post_type( $current );
2997 -
2998 - if ( self::wdkit_is_foreign_media_url( $node['url'] ) ) {
2999 - // Still pointing at the source site. Ask Elementor for the local copy: its
3000 - // _elementor_source_image_hash lookup returns the attachment the create-time
3001 - // import already made, so this normally costs a single query and no download.
3002 - $local = self::wdkit_localise_media_url( $node['url'], $current );
3003 -
3004 - if ( ! empty( $local['id'] ) && ! empty( $local['url'] ) ) {
3005 - $node['id'] = $local['id'];
3006 - $node['url'] = $local['url'];
3007 - }
3008 - } elseif ( ! $is_live && false !== strpos( $node['url'], '/wp-content/uploads/' ) ) {
3009 - $resolved = self::wdkit_attachment_id_from_url( $node['url'] );
3010 -
3011 - if ( $resolved ) {
3012 - $node['id'] = $resolved;
3013 - }
3014 - }
3015 - }
3016 -
3017 - foreach ( $node as $key => $value ) {
3018 - if ( is_array( $value ) ) {
3019 - $node[ $key ] = self::wdkit_repair_attachment_ids( $value );
3020 - }
3021 - }
3022 -
3023 - return $node;
3024 - }
3025 -
3026 1295 public function wdkit_media_import( $content = array(), $editor = '' ) {
3027 1296
3028 1297 if ( empty( $content ) && empty( $editor ) ) {
3029 1298 $args = $this->wdkit_parse_args( $_POST );
@@ -3043,9 +1312,8 @@
3043 1312 if ( ! class_exists( 'Wdkit_Import_Images' ) ) {
3044 1313 require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php';
3045 1314 }
3046 1315
3047 -
3048 1316 if ( ! empty( $args['editor'] ) && 'gutenberg' === $args['editor'] && ! empty( $content ) ) {
3049 1317 $media_import = array( $content );
3050 1318 $media_import = self::blocks_import_media_copy_content( $media_import );
3051 1319 $content = $media_import[0];
@@ -3053,13 +1321,8 @@
3053 1321 $media_import = array( $content );
3054 1322 $media_import = self::widgets_elements_id_change( $media_import );
3055 1323 $media_import = self::widgets_import_media_copy_content( $media_import );
3056 1324 $content = $media_import[0];
3057 -
3058 - // Last: point any control Elementor left holding a foreign attachment ID at the
3059 - // local attachment its URL already refers to. Without this, has_sizes controls
3060 - // such as container background images resolve to nothing and render empty.
3061 - $content = self::wdkit_repair_attachment_ids( $content );
3062 1325 }
3063 1326
3064 1327 return $content;
3065 1328 }
@@ -3130,13 +1393,9 @@
3130 1393 $control_type = \Elementor\Plugin::instance()->controls_manager->get_control( $get_control['type'] );
3131 1394 $control_name = $get_control['name'];
3132 1395
3133 1396 if ( ! $control_type ) {
3134 - // Skip just this control. Returning here would abandon every control after
3135 - // it, so a single unregistered type - routine when a kit uses an addon that
3136 - // is not fully active yet - would silently leave the rest of the element's
3137 - // media pointing at the source site.
3138 - continue;
1397 + return $get_element_instance;
3139 1398 }
3140 1399
3141 1400 if ( method_exists( $control_type, $tp_mi_on_fun ) ) {
3142 1401 $get_element_instance['settings'][ $control_name ] = $control_type->{$tp_mi_on_fun}( $element->get_settings( $control_name ), $get_control );
@@ -3211,16 +1470,57 @@
3211 1470 public static function blocks_data_instance( array $block_data, array $args = array(), $block_args = null ) {
3212 1471
3213 1472 if ( ( isset( $block_data['name'] ) && isset( $block_data['clientId'] ) && isset( $block_data['attributes'] ) ) || ( isset( $block_data['blockName'] ) && isset( $block_data['attrs'] ) && ! empty( $block_data['attrs'] ) ) ) {
3214 1473 $blocks_attr = isset( $block_data['attributes'] ) ? $block_data['attributes'] : ( isset( $block_data['attrs'] ) ? $block_data['attrs'] : array() );
3215 - $blocks_attr = self::wdkit_import_block_media( $blocks_attr );
1474 + foreach ( $blocks_attr as $block_key => $block_val ) {
1475 + if ( isset( $block_val['url'] ) && isset( $block_val['id'] ) && ! empty( $block_val['url'] ) ) {
1476 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
1477 + $blocks_attr[ $block_key ] = $new_media;
1478 + } elseif ( isset( $block_val['url'] ) && ! empty( $block_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $block_val['url'] ) ) {
1479 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
1480 + $blocks_attr[ $block_key ] = $new_media;
1481 + } elseif ( is_array( $block_val ) && ! empty( $block_val ) ) {
1482 + if ( ! array_key_exists( 'md', $block_val ) && ! array_key_exists( 'openTypography', $block_val ) && ! array_key_exists( 'openBorder', $block_val ) && ! array_key_exists( 'openShadow', $block_val ) && ! array_key_exists( 'openFilter', $block_val ) ) {
1483 + foreach ( $block_val as $key => $val ) {
1484 + if ( is_array( $val ) && ! empty( $val ) ) {
1485 +
1486 + if ( isset( $val['url'] ) && ( isset( $val['Id'] ) || isset( $val['id'] ) ) && ! empty( $val['url'] ) ) {
1487 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
1488 + $blocks_attr[ $block_key ][ $key ] = $new_media;
1489 + } elseif ( isset( $val['url'] ) && ! empty( $val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $val['url'] ) ) {
1490 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
1491 + $blocks_attr[ $block_key ][ $key ] = $new_media;
1492 + } else {
1493 + foreach ( $val as $sub_key => $sub_val ) {
1494 + if ( isset( $sub_val['url'] ) && ( isset( $sub_val['Id'] ) || isset( $sub_val['id'] ) ) && ! empty( $sub_val['url'] ) ) {
1495 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
1496 + $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
1497 + } elseif ( isset( $sub_val['url'] ) && ! empty( $sub_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val['url'] ) ) {
1498 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
1499 + $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
1500 + } elseif ( is_array( $sub_val ) && ! empty( $sub_val ) ) {
1501 + foreach ( $sub_val as $sub_key1 => $sub_val1 ) {
1502 + if ( isset( $sub_val1['url'] ) && ( isset( $sub_val1['Id'] ) || isset( $sub_val1['id'] ) ) && ! empty( $sub_val1['url'] ) ) {
1503 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
1504 + $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media;
1505 + } elseif ( isset( $sub_val1['url'] ) && ! empty( $sub_val1['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val1['url'] ) ) {
1506 + $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
1507 + $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media;
1508 + }
1509 + }
1510 + }
1511 + }
1512 + }
1513 + }
1514 + }
1515 + }
1516 + }
1517 + }
3216 1518 if ( isset( $block_data['attributes'] ) ) {
3217 1519 $block_data['attributes'] = $blocks_attr;
3218 1520 } elseif ( isset( $block_data['attrs'] ) ) {
3219 1521 $block_data['attrs'] = $blocks_attr;
3220 1522 }
3221 -
3222 - $block_data = self::wdkit_relink_block_markup( $block_data );
3223 1523 }
3224 1524
3225 1525 return $block_data;
3226 1526 }
@@ -3225,284 +1525,8 @@
3225 1525 return $block_data;
3226 1526 }
3227 1527
3228 1528 /**
3229 - * Run block markup through the media import, the way the create path does.
3230 - *
3231 - * Used wherever block content is written from the browser: media import, then the Nexter
3232 - * block processor so each block's rendered copy matches its attributes, then serialise.
3233 - *
3234 - * @since 2.6.2
3235 - *
3236 - * @param string $content Block markup.
3237 - * @return string Block markup with local media.
3238 - */
3239 - private function wdkit_relink_gutenberg_content( $content ) {
3240 -
3241 - if ( ! is_string( $content ) || false === strpos( $content, '<!-- wp:' ) ) {
3242 - return $content;
3243 - }
3244 -
3245 - // wdkit_media_import() loads this itself, but it is referenced before that below.
3246 - if ( ! class_exists( 'Wdkit_Import_Images' ) ) {
3247 - require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php';
3248 - }
3249 -
3250 - // Thumbnail generation decodes each image, so keep the oversized-image guard in force.
3251 - self::wdkit_guard_oversized_images();
3252 -
3253 -
3254 - // Block attributes are JSON inside the block delimiters, so they only survive a parse
3255 - // when the string carries exactly one level of escaping. Arrive with an extra level and
3256 - // parse_blocks() reads no attributes at all - serialising that back out writes every
3257 - // block bare, throwing away titles, body text, icons and styling.
3258 - $parsable = self::wdkit_parsable_block_content( $content );
3259 -
3260 - if ( null === $parsable ) {
3261 -
3262 - return $content;
3263 - }
3264 -
3265 - $blocks = parse_blocks( $parsable );
3266 - $blocks = $this->wdkit_media_import( $blocks, 'gutenberg' );
3267 -
3268 - if ( empty( $blocks ) || ! is_array( $blocks ) ) {
3269 - return $content;
3270 - }
3271 -
3272 - if ( class_exists( 'WDKIT_Nexter_Block_Processor' ) ) {
3273 - $processor = new WDKIT_Nexter_Block_Processor();
3274 - $blocks = $processor->run( $blocks );
3275 - }
3276 -
3277 - $serialised = serialize_blocks( $blocks );
3278 -
3279 - // Last line of defence. This function exists to repoint media, so a result carrying
3280 - // fewer block attributes than it started with is a broken round trip, not a rewrite.
3281 - // Leaving the media wrong is recoverable; saving gutted content is not.
3282 - $before = self::wdkit_block_attr_count( $parsable );
3283 - $after = self::wdkit_block_attr_count( $serialised );
3284 -
3285 - if ( $after < $before ) {
3286 -
3287 - return $content;
3288 - }
3289 -
3290 - // Never hand back nothing: an empty result would blank the page.
3291 - return ! empty( $serialised ) ? $serialised : $content;
3292 - }
3293 -
3294 - /**
3295 - * Rebuild the block stylesheet for a page whose content we just rewrote.
3296 - *
3297 - * The addon keeps each block's styling in a generated per-page stylesheet, and every rule
3298 - * is keyed to the block id it was written for. That file is produced when the page is
3299 - * saved through the editor - not by wp_update_post() from an AJAX handler - so rewriting
3300 - * content here leaves the page pointing at a stylesheet built for the previous markup.
3301 - * Blocks whose ids are not in that file get no rules at all and render unstyled.
3302 - *
3303 - * @since 2.6.2
3304 - *
3305 - * @param int $post_id Page whose content changed.
3306 - * @return bool True when a rebuild was triggered.
3307 - */
3308 - private static function wdkit_rebuild_block_css( $post_id ) {
3309 -
3310 - if ( ! $post_id ) {
3311 - return false;
3312 - }
3313 -
3314 - foreach ( get_declared_classes() as $class ) {
3315 - if ( ! method_exists( $class, 'make_block_css_by_post_id' ) ) {
3316 - continue;
3317 - }
3318 -
3319 - try {
3320 - if ( method_exists( $class, 'instance' ) ) {
3321 - $instance = $class::instance();
3322 - } elseif ( method_exists( $class, 'get_instance' ) ) {
3323 - $instance = $class::get_instance();
3324 - } else {
3325 - $instance = new $class();
3326 - }
3327 -
3328 - $instance->make_block_css_by_post_id( $post_id );
3329 -
3330 -
3331 - return true;
3332 - } catch ( \Throwable $e ) {
3333 - // Styling is best-effort: a failure here must not fail the import.
3334 -
3335 - return false;
3336 - }
3337 - }
3338 -
3339 - return false;
3340 - }
3341 -
3342 - /**
3343 - * How many block attributes does this markup actually yield when parsed?
3344 - *
3345 - * Used as a before/after measure: block attributes are the part of block markup a round
3346 - * trip can silently drop, so counting them is how we tell a rewrite from a mangling.
3347 - *
3348 - * @since 2.6.2
3349 - *
3350 - * @param string $content Block markup.
3351 - * @return int Total attributes across every block.
3352 - */
3353 - private static function wdkit_block_attr_count( $content ) {
3354 - $total = 0;
3355 -
3356 - $walk = function ( $blocks ) use ( &$walk, &$total ) {
3357 - foreach ( $blocks as $block ) {
3358 - if ( ! empty( $block['attrs'] ) && is_array( $block['attrs'] ) ) {
3359 - $total += count( $block['attrs'] );
3360 - }
3361 -
3362 - if ( ! empty( $block['innerBlocks'] ) ) {
3363 - $walk( $block['innerBlocks'] );
3364 - }
3365 - }
3366 - };
3367 -
3368 - $walk( parse_blocks( (string) $content ) );
3369 -
3370 - return $total;
3371 - }
3372 -
3373 - /**
3374 - * Return this content in a form whose block attributes actually parse.
3375 - *
3376 - * Content written straight to post_content never had to parse, so an extra level of
3377 - * escaping on the way in did no harm. Parsing it - which repointing media requires - makes
3378 - * that escaping fatal: `{\"Title\":\"…\"}` is not JSON, so every attribute is discarded.
3379 - *
3380 - * Rather than assume a slash depth, this measures: if stripping one level yields more
3381 - * attributes, the content was over-escaped and the stripped form is the real one.
3382 - *
3383 - * @since 2.6.2
3384 - *
3385 - * @param string $content Block markup as received.
3386 - * @return string|null Markup safe to parse, or null when no form of it parses.
3387 - */
3388 - private static function wdkit_parsable_block_content( $content ) {
3389 -
3390 - $as_is = self::wdkit_block_attr_count( $content );
3391 -
3392 - // Nothing claims to carry attributes, so there is nothing to lose either.
3393 - if ( false === strpos( $content, '{' ) ) {
3394 - return $content;
3395 - }
3396 -
3397 - $stripped = wp_unslash( $content );
3398 - $stripped_attrs = self::wdkit_block_attr_count( $stripped );
3399 -
3400 - if ( $stripped_attrs > $as_is ) {
3401 - return $stripped;
3402 - }
3403 -
3404 - if ( $as_is > 0 ) {
3405 - return $content;
3406 - }
3407 -
3408 - // Neither form parses into attributes even though the markup contains JSON: better to
3409 - // leave the content exactly as it arrived than to rewrite it into something bare.
3410 - return null;
3411 - }
3412 -
3413 - /**
3414 - * Point a block's saved markup at the media that was just localised.
3415 - *
3416 - * A block stores a rendered copy of itself in `innerHTML` / `innerContent`, and for many
3417 - * blocks that copy is what the front end actually outputs. Importing the attributes alone
3418 - * therefore fixes the editor while leaving the page still loading from the site the
3419 - * template came from - and those hosts answer 403, so the image renders broken.
3420 - *
3421 - * @since 2.6.2
3422 - *
3423 - * @param array $block_data One parsed block.
3424 - * @return array The block with its markup repointed.
3425 - */
3426 - private static function wdkit_relink_block_markup( $block_data ) {
3427 -
3428 - $map = Wdkit_Import_Images::get_url_map();
3429 -
3430 - if ( empty( $map ) ) {
3431 - return $block_data;
3432 - }
3433 -
3434 - $from = array_keys( $map );
3435 - $to = array_values( $map );
3436 -
3437 - if ( ! empty( $block_data['innerHTML'] ) && is_string( $block_data['innerHTML'] ) ) {
3438 - $block_data['innerHTML'] = str_replace( $from, $to, $block_data['innerHTML'] );
3439 - }
3440 -
3441 - if ( ! empty( $block_data['innerContent'] ) && is_array( $block_data['innerContent'] ) ) {
3442 - foreach ( $block_data['innerContent'] as $index => $chunk ) {
3443 - if ( is_string( $chunk ) ) {
3444 - $block_data['innerContent'][ $index ] = str_replace( $from, $to, $chunk );
3445 - }
3446 - }
3447 - }
3448 -
3449 - return $block_data;
3450 - }
3451 -
3452 - /**
3453 - * Import every media reference held in a block's attributes.
3454 - *
3455 - * Block attributes nest arbitrarily - a repeater of cards each with an image, responsive
3456 - * variants, nested inner settings - so this recurses rather than reaching a fixed number
3457 - * of levels down. The previous version was unrolled exactly four levels deep and also
3458 - * skipped any subtree carrying an `md` key, which meant anything below that simply kept
3459 - * the source site's URL and attachment ID and rendered as an empty placeholder.
3460 - *
3461 - * A node counts as media when it has a non-empty string `url` and either an id slot or a
3462 - * URL that names an image file. That pairing is what distinguishes a media control from
3463 - * a link, which also carries a `url`.
3464 - *
3465 - * @since 2.6.2
3466 - *
3467 - * @param mixed $node Block attributes, walked recursively.
3468 - * @return mixed Attributes with local media.
3469 - */
3470 - private static function wdkit_import_block_media( $node ) {
3471 -
3472 - if ( ! is_array( $node ) ) {
3473 - return $node;
3474 - }
3475 -
3476 - $url = isset( $node['url'] ) && is_string( $node['url'] ) ? $node['url'] : '';
3477 -
3478 - if ( '' !== $url
3479 - && ( array_key_exists( 'id', $node ) || array_key_exists( 'Id', $node )
3480 - || preg_match( '/\.(?:jpe?g|png|gif|svg|webp|avif|bmp)$/i', (string) wp_parse_url( $url, PHP_URL_PATH ) ) )
3481 - ) {
3482 - $imported = Wdkit_Import_Images::wdkit_Import_media( $node );
3483 -
3484 - // Only accept a real result. The importer returns the node untouched when it
3485 - // cannot localise the file, and anything falsy here would wipe out the URL and
3486 - // leave the block with no image at all.
3487 - if ( ! empty( $imported['url'] ) ) {
3488 - $node = array_merge( $node, $imported );
3489 - }
3490 - }
3491 -
3492 - // Keep walking even after importing this node. A media value carries its own `sizes`
3493 - // map of per-size URLs, and returning here left every one of those pointing at the
3494 - // site the template came from - which is what the widgets actually render from.
3495 - foreach ( $node as $key => $value ) {
3496 - if ( is_array( $value ) ) {
3497 - $node[ $key ] = self::wdkit_import_block_media( $value );
3498 - }
3499 - }
3500 -
3501 - return $node;
3502 - }
3503 -
3504 - /**
3505 1529 * Kit Template Import Pages/Sections
3506 1530 *
3507 1531 * @since 1.0.0
3508 1532 * */
@@ -3511,10 +1535,8 @@
3511 1535 if ( ! current_user_can( 'manage_options' ) ) {
3512 1536 return false;
3513 1537 }
3514 1538
3515 - $builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '';
3516 -
3517 1539 $page_section = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : '';
3518 1540
3519 1541 if ( isset( $page_section ) ) {
3520 1542 $args['page_section'] = ! empty( $page_section ) ? sanitize_text_field( wp_unslash( $page_section ) ) : '';
@@ -3519,16 +1541,14 @@
3519 1541 if ( isset( $page_section ) ) {
3520 1542 $args['page_section'] = ! empty( $page_section ) ? sanitize_text_field( wp_unslash( $page_section ) ) : '';
3521 1543 }
3522 1544
3523 - $template_ids = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array();
3524 - $email = ! empty( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : '';
3525 - $editor = isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : '';
3526 - $website_kit = isset( $_POST['website_kit'] ) ? sanitize_text_field( wp_unslash( $_POST['website_kit'] ) ) : '';
3527 - $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
3528 - $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'] ) ) : '';
3529 1549
3530 - if ( empty( $template_ids ) ) {
1550 + if ( empty( $email ) || empty( $template_ids ) ) {
3531 1551 $output = array(
3532 1552 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
3533 1553 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
3534 1554 'success' => false,
@@ -3552,100 +1572,32 @@
3552 1572 'token' => $token,
3553 1573 'template_id' => $template_ids['id'],
3554 1574 'editor' => $editor,
3555 1575 'website_kit' => $website_kit,
3556 - 'unique_id' => get_option( 'wdkit_unique_id' ) ?? '',
3557 1576 );
3558 1577
3559 - $response = WDesignKit_Data_Query::get_data( $api_type, $temp_args );
1578 + $response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args );
3560 1579 $output = array();
3561 1580
3562 - if ( is_wp_error( $response ) ) {
3563 -
1581 + if ( 'error' === $response['content'] ) {
3564 1582 wp_send_json( $response );
3565 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'];
3566 1589 }
3567 1590
3568 - if ( isset( $response['content'] ) && 'error' === $response['content'] ) {
3569 - wp_send_json( $response );
3570 - wp_die();
3571 - }
3572 -
3573 - $result = array(
3574 - 'response' => $response,
3575 - 'args' => $args,
3576 - 'id' => $template_ids['id'],
3577 - 'temp_data' => $template_ids,
3578 - );
3579 -
3580 - $output['message'] = $response['message'];
3581 - $output['description'] = $response['description'];
3582 - $output['data'] = $result;
3583 - $output['success'] = $response['success'];
3584 -
3585 1591 wp_send_json( $output );
3586 1592 wp_die();
3587 1593 }
3588 1594
3589 - public function wdkit_enable_template_widgets() {
3590 - $widget_list = ! empty( $_POST['widget_list'] ) ? json_decode( wp_unslash( $_POST['widget_list'] ), true ) : array();
3591 - $extensions_list = ! empty( $_POST['extensions_list'] ) ? json_decode( wp_unslash( $_POST['extensions_list'] ), true ) : array();
3592 -
3593 - if ( empty( $widget_list ) && empty( $extensions_list ) ) {
3594 - $res = array(
3595 - 'massage' => __( 'Widget array not found', 'wdesignkit' ),
3596 - 'description' => __( 'Widget array not found', 'wdesignkit' ),
3597 - 'success' => false,
3598 - );
3599 - wp_send_json( $res );
3600 - wp_die();
3601 - }
3602 -
3603 - if ( ! has_filter( 'tpae_enable_selected_widgets' ) ) {
3604 - $res = array(
3605 - 'massage' => __( 'Relevant Plugin not Activated', 'wdesignkit' ),
3606 - 'description' => __( 'Relevant Plugin not Installed / Activated', 'wdesignkit' ),
3607 - 'success' => false,
3608 - );
3609 - wp_send_json( $res );
3610 - wp_die();
3611 - }
3612 -
3613 - $w_list = array(
3614 - 'widgets' => $widget_list,
3615 - 'extensions' => $extensions_list,
3616 - );
3617 -
3618 - $result = apply_filters( 'tpae_enable_selected_widgets', $w_list );
3619 -
3620 - if ( ! empty( $result['success'] ) ) {
3621 - $res = array(
3622 - 'massage' => __( 'Enabled widgets successfully', 'wdesignkit' ),
3623 - 'description' => __( 'Used widgets have been enabled successfully', 'wdesignkit' ),
3624 - 'success' => true,
3625 - );
3626 - } else {
3627 -
3628 - $message = isset( $result['message'] ) ? $result['message'] : __( 'Failed to enable widgets', 'wdesignkit' );
3629 - $description = isset( $result['description'] ) ? $result['description'] : __( 'Failed to enable widgets', 'wdesignkit' );
3630 -
3631 - $res = array(
3632 - 'massage' => $message,
3633 - 'description' => $description,
3634 - 'success' => false,
3635 - );
3636 - }
3637 -
3638 - wp_send_json( $res );
3639 - wp_die();
3640 - }
3641 -
3642 1595 /**
3643 1596 * Import single template and section from plugin only
3644 1597 * */
3645 1598 protected function wdkit_import_multi_template() {
3646 - $args = $this->wdkit_parse_args( $_POST );
3647 - $api_type = isset( $_POST['api_type'] ) ? sanitize_text_field( wp_unslash( $_POST['api_type'] ) ) : 'import_template';
1599 + $args = $this->wdkit_parse_args( $_POST );
3648 1600
3649 1601 if ( ! current_user_can( 'manage_options' ) ) {
3650 1602 return false;
3651 1603 }
@@ -3674,50 +1626,56 @@
3674 1626 $args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : '';
3675 1627 }
3676 1628
3677 1629 $args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
3678 -
3679 1630 if ( ! empty( $args['template_ids'] ) && ! empty( $args['page_section'] ) ) {
3680 1631 $output = array();
3681 - 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 {
3682 1656 $token = $this->wdkit_login_user_token( $args['email'] );
3683 -
3684 1657 $temp_args = array(
3685 1658 'token' => $token,
3686 - 'template_id' => $args['template_ids']['id'],
1659 + 'template_id' => $args['template_ids'],
3687 1660 'editor' => $args['editor'],
3688 - 'unique_id' => get_option( 'wdkit_unique_id' ) ?? '',
3689 1661 );
3690 1662
3691 - $response = WDesignKit_Data_Query::get_data( $api_type, $temp_args );
1663 + $response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args );
3692 1664
3693 - if ( is_wp_error( $response ) ) {
3694 - wp_send_json( array(
3695 - 'success' => false,
3696 - 'message' => $response->get_error_message(),
3697 - ) );
3698 - wp_die();
3699 - }
3700 -
3701 - if ( isset( $response['content'] ) && 'error' === $response['content'] ) {
1665 + if ( 'error' === $response['content'] ) {
3702 1666 wp_send_json( $response );
3703 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'];
3704 1673 }
1674 + }
3705 1675
3706 - $result = array(
3707 - 'response' => $response,
3708 - 'args' => $args,
3709 - 'id' => $args['template_ids'],
3710 - 'value' => $args['template_ids'],
3711 - );
1676 + $output['success'] = true;
3712 1677
3713 - $output['message'] = $response['message'];
3714 - $output['description'] = $response['description'];
3715 - $output['data'] = $result;
3716 - $output['success'] = true;
3717 -
3718 - }
3719 -
3720 1678 wp_send_json( $output );
3721 1679 wp_die();
3722 1680 }
3723 1681 }
@@ -3722,151 +1680,8 @@
3722 1680 }
3723 1681 }
3724 1682
3725 1683 /**
3726 - * It is Use for remove selected category from content.
3727 - *
3728 - * @since 2.0.5
3729 - */
3730 - public function wdkit_content_remover( &$data ) {
3731 -
3732 - if ( is_array( $data ) ) {
3733 -
3734 - foreach ( $data as $key => &$value ) {
3735 - if ( $key === 'post_category' ) {
3736 - $data[ $key ] = array();
3737 - } else if ($key === 'include_products'){
3738 - $data[ $key ] = "";
3739 - } else {
3740 - $this->wdkit_content_remover( $value );
3741 - }
3742 - }
3743 - } elseif ( is_object( $data ) ) {
3744 -
3745 - foreach ( $data as $key => &$value ) {
3746 - if ( $key === 'post_category' ) {
3747 - $data->$key = array();
3748 - } else if ($key === 'include_products'){
3749 - $data->$key = "";
3750 - } else {
3751 - $this->wdkit_content_remover( $value );
3752 - }
3753 - }
3754 - }
3755 -
3756 - return $data;
3757 - }
3758 -
3759 - protected function wkit_update_elementor_template(){
3760 -
3761 - if ( isset( $_POST['data'] ) ) {
3762 - $content = ! empty( $_POST['data'] ) ? json_decode( wp_unslash( $_POST['data'] ), true ) : '';
3763 - }
3764 -
3765 - if ( isset( $_POST['template_id'] ) ) {
3766 - $template_id = ! empty( $_POST['template_id'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_id'] ), true ) ) : '';
3767 - }
3768 -
3769 - $document = \Elementor\Plugin::$instance->documents->get($template_id);
3770 -
3771 - // This saves content posted straight from the browser, which carries local image
3772 - // URLs but still the source template's attachment IDs. Without repairing them the
3773 - // save undoes what wdkit_media_import() fixed on create, and has_sizes controls —
3774 - // container background images especially — resolve to nothing and render empty.
3775 - $content = self::wdkit_repair_attachment_ids( $content );
3776 -
3777 - $document->save([
3778 - 'elements' => $content
3779 - ]);
3780 - }
3781 -
3782 - /**
3783 - * Update the content of an already-created page.
3784 - *
3785 - * Used by the async ("Site Ready first") import path: pages are created up front with
3786 - * their un-rewritten template content, then this writes the AI-rewritten content into
3787 - * each page in the background. Elementor saves via the document API (same as
3788 - * wkit_update_elementor_template); Gutenberg writes post_content directly.
3789 - *
3790 - * @since 2.6.2
3791 - */
3792 - protected function wdkit_update_page_content() {
3793 - $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
3794 - $builder = isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '';
3795 -
3796 - if ( ! $post_id || ! current_user_can( 'edit_post', $post_id ) ) {
3797 - return array(
3798 - 'success' => false,
3799 - 'message' => esc_html__( 'Invalid page or insufficient permission', 'wdesignkit' ),
3800 - );
3801 - }
3802 -
3803 - if ( 'gutenberg' === $builder ) {
3804 - // Do NOT run kses here: Gutenberg block delimiters are HTML comments
3805 - // (<!-- wp:... -->) which kses strips. Mirror the create path, which stores
3806 - // the block markup slashed and unfiltered (endpoint is manage_options-gated
3807 - // and the content is plugin-generated).
3808 - $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
3809 -
3810 - // This content comes straight from the browser and still carries the template
3811 - // site's media URLs and attachment IDs, so it has to go through the same pipeline
3812 - // the create path uses. Without this the save simply undid the import: the files
3813 - // were fetched, then overwritten by a copy still pointing at the source site.
3814 - //
3815 - // Re-running is cheap. Every URL already handled resolves from the source-hash
3816 - // lookup, and media that is already local resolves straight from its URL, so no
3817 - // image is fetched or stored twice.
3818 - $content = $this->wdkit_relink_gutenberg_content( $content );
3819 -
3820 - $result = wp_update_post(
3821 - array(
3822 - 'ID' => $post_id,
3823 - 'post_content' => wp_slash( $content ),
3824 - ),
3825 - true
3826 - );
3827 -
3828 - if ( is_wp_error( $result ) ) {
3829 - return array(
3830 - 'success' => false,
3831 - 'message' => $result->get_error_message(),
3832 - );
3833 - }
3834 -
3835 - self::wdkit_rebuild_block_css( $post_id );
3836 - } else {
3837 - $elements = isset( $_POST['content'] ) ? json_decode( wp_unslash( $_POST['content'] ), true ) : array();
3838 -
3839 - if ( ! class_exists( '\\Elementor\\Plugin' ) ) {
3840 - return array(
3841 - 'success' => false,
3842 - 'message' => esc_html__( 'Elementor not available', 'wdesignkit' ),
3843 - );
3844 - }
3845 -
3846 - $document = \Elementor\Plugin::$instance->documents->get( $post_id );
3847 - if ( ! $document ) {
3848 - return array(
3849 - 'success' => false,
3850 - 'message' => esc_html__( 'Elementor document not found', 'wdesignkit' ),
3851 - );
3852 - }
3853 -
3854 - // Same as wkit_update_elementor_template(): browser-posted content keeps the
3855 - // source template's attachment IDs, so repair them or this save undoes the
3856 - // create-time fix and background images stop rendering.
3857 - $elements = self::wdkit_repair_attachment_ids( $elements );
3858 -
3859 - $document->save( array( 'elements' => $elements ) );
3860 - }
3861 -
3862 - return array(
3863 - 'success' => true,
3864 - 'message' => esc_html__( 'Page content updated', 'wdesignkit' ),
3865 - );
3866 - }
3867 -
3868 - /**
3869 1684 * Import single template and section from plugin only
3870 1685 *
3871 1686 * @param array $args store data.
3872 1687 * @param array $template_id store data.
@@ -3872,53 +1687,9 @@
3872 1687 * @param array $template_id store data.
3873 1688 * @param array $data store data.
3874 1689 * @param array $temp_data store data.
3875 1690 * */
3876 - protected function import_page_section_content() {
3877 -
3878 - // Elementor sideloads every image referenced by the page from inside this request.
3879 - // A single oversized source image decodes to more than the whole memory limit, so
3880 - // guard before any of that starts.
3881 - $this->wdkit_guard_oversized_images();
3882 -
3883 - // Sideloading images for image-heavy pages (wdkit_media_import → Imagick
3884 - // thumbnail generation per image) can exceed the default 30s execution
3885 - // limit and fatal the request mid-import. Give this single page import
3886 - // more headroom; harmless no-op where set_time_limit() is disabled.
3887 - if ( function_exists( 'set_time_limit' ) ) {
3888 - @set_time_limit( 120 );
3889 - }
3890 -
3891 - if ( isset( $_POST['args'] ) ) {
3892 - $args = ! empty( $_POST['args'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['args'] ) ), true ) : array();
3893 - }
3894 -
3895 - if ( isset( $_POST['temp_data'] ) ) {
3896 - $temp_data = ! empty( $_POST['temp_data'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['temp_data'] ) ), true ) : array();
3897 - }
3898 -
3899 - if ( isset( $_POST['category_list'] ) ) {
3900 - $category_list = ! empty( $_POST['category_list'] ) ? json_decode( wp_unslash( $_POST['category_list'] ), true ) : '';
3901 - }
3902 -
3903 - if ( isset( $_POST['tag_list'] ) ) {
3904 - $tag_list = ! empty( $_POST['tag_list'] ) ? json_decode( wp_unslash( $_POST['tag_list'] ), true ) : '';
3905 - }
3906 -
3907 - if ( isset( $_POST['thumb_image'] ) ) {
3908 - $thumb_image = ! empty( $_POST['thumb_image'] ) ? esc_url_raw( $_POST['thumb_image'] ) : '';
3909 - }
3910 -
3911 - if ( isset( $_POST['template_id'] ) ) {
3912 - $template_id = ! empty( $_POST['template_id'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_id'] ), true ) ) : '';
3913 - }
3914 -
3915 - $temp_type = isset( $_POST['temp_type'] ) ? sanitize_text_field( wp_unslash( $_POST['temp_type'] ) ) : 'normal';
3916 -
3917 - if ( isset( $_POST['data'] ) ) {
3918 - $data = ! empty( $_POST['data'] ) ? json_decode( wp_unslash( $_POST['data'] ) ) : '';
3919 - }
3920 -
1691 + private function import_page_section_content( $args, $template_id, $data, $temp_data = array() ) {
3921 1692 $enqueue_instance = new Wdkit_Enqueue();
3922 1693 $get_post_type = $enqueue_instance->wdkit_get_post_type_list();
3923 1694
3924 1695 $post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page';
@@ -3924,10 +1695,8 @@
3924 1695 $post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page';
3925 1696
3926 1697 if ( 'section' === $post_type ) {
3927 1698 $post_type = $temp_data['wp_post_type'];
3928 - } else {
3929 - $post_type = $temp_data['wp_post_type'];
3930 1699 }
3931 1700
3932 1701 if ( ! array_key_exists( $post_type, $get_post_type ) ) {
3933 1702 $post_type = 'page';
@@ -3932,15 +1701,13 @@
3932 1701 if ( ! array_key_exists( $post_type, $get_post_type ) ) {
3933 1702 $post_type = 'page';
3934 1703 }
3935 1704
3936 - if ( ! empty( $data ) && ! empty( $template_id ) && ! empty( $post_type ) && current_user_can( 'manage_options' ) ) {
3937 - $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'] );
3938 1707 $post_title = isset( $post_content->title ) ? sanitize_text_field( $post_content->title ) : '';
3939 - $post_slug = isset( $post_content->slug ) ? sanitize_text_field( $post_content->slug ) : '';
3940 1708 $file_type = isset( $post_content->file_type ) ? sanitize_text_field( $post_content->file_type ) : '';
3941 1709 $content = isset( $post_content->content ) ? wp_slash( $post_content->content ) : '';
3942 - $temp_con = '';
3943 1710
3944 1711 if ( 'gutenberg' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'wp_block' === $file_type ) ) {
3945 1712 if ( empty( $content ) ) {
3946 1713 wp_send_json(
@@ -3945,31 +1712,24 @@
3945 1712 if ( empty( $content ) ) {
3946 1713 wp_send_json(
3947 1714 array(
3948 1715 'template_id' => $template_id,
3949 - 'message' => __( 'Content is Empty.', 'wdesignkit' ),
1716 + 'message' => 'Content is Empty.',
3950 1717 )
3951 1718 );
3952 1719 wp_die();
3953 1720 } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'wp_block' === $file_type ) {
1721 + $parse_blocks = parse_blocks( stripslashes( $content ) );
3954 1722
3955 1723 $editor = ( 'wdkit' === $args['editor'] ) ? 'gutenberg' : $args['editor'];
3956 - $blocks = parse_blocks( stripslashes( $content ) );
1724 + $content = $this->wdkit_media_import( $parse_blocks, $editor );
1725 + $content = addslashes( serialize_blocks( $content ) );
3957 1726
3958 - $blocks = $this->wdkit_media_import( $blocks, $editor );
3959 -
3960 - $processor = new WDKIT_Nexter_Block_Processor();
3961 - $blocks = $processor->run( $blocks );
3962 - $content = serialize_blocks( $blocks );
3963 -
3964 - $content = $this->replace_unicode_glitch( serialize_blocks( $blocks ) );
3965 -
3966 1727 $inserted_post = wp_insert_post(
3967 1728 array(
3968 1729 'post_status' => 'publish',
3969 1730 'post_type' => $post_type,
3970 1731 'post_title' => $post_title,
3971 - 'post_name' => $post_slug,
3972 1732 'post_content' => $content,
3973 1733 )
3974 1734 );
3975 1735
@@ -3982,41 +1742,8 @@
3982 1742 );
3983 1743 wp_die();
3984 1744 }
3985 1745
3986 - if ( ! empty( $thumb_image ) ) {
3987 - // $featured_image_url = esc_url_raw( $thumb_image );
3988 - $tmp = download_url( $thumb_image );
3989 - if ( is_wp_error( $tmp ) ) {
3990 - error_log( 'Image download failed: ' . esc_html( $tmp->get_error_message() ) );
3991 - } else {
3992 - $file_array = array(
3993 - 'name' => wp_basename( $thumb_image ),
3994 - 'tmp_name' => $tmp,
3995 - );
3996 -
3997 - $image_id = media_handle_sideload( $file_array, $inserted_post );
3998 -
3999 - if ( is_wp_error( $image_id ) ) {
4000 - error_log( 'Image sideload failed: ' . esc_html( $image_id->get_error_message() ) );
4001 - } else {
4002 - set_post_thumbnail( $inserted_post, $image_id );
4003 - }
4004 -
4005 - @unlink( $tmp );
4006 - }
4007 - }
4008 -
4009 - if ( ! empty( $category_list ) && is_array( $category_list ) ) {
4010 - $category_ids = array_map( 'intval', $category_list );
4011 - wp_set_post_terms( $inserted_post, $category_ids, 'category' );
4012 - }
4013 -
4014 - if ( ! empty( $tag_list ) && is_array( $tag_list ) ) {
4015 - $tag_ids = array_map( 'intval', $tag_list );
4016 - wp_set_post_terms( $inserted_post, $tag_ids, 'post_tag' );
4017 - }
4018 -
4019 1746 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
4020 1747 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
4021 1748 if ( ! empty( $custom_meta ) ) {
4022 1749 foreach ( $custom_meta as $meta_key => $meta_val ) {
@@ -4030,42 +1757,13 @@
4030 1757 }
4031 1758 }
4032 1759 }
4033 1760
4034 - $temp_detail = array(
1761 + return array(
4035 1762 'title' => get_the_title( $inserted_post ),
4036 1763 'edit_link' => get_edit_post_link( $inserted_post, 'internal' ),
4037 1764 'view' => get_permalink( $inserted_post ),
4038 - 'id' => $inserted_post,
4039 1765 );
4040 -
4041 - if ( ! empty( $template_id->id ) ) {
4042 - $temp_id = $template_id->id;
4043 - } elseif ( ! empty( $template_id ) ) {
4044 - $temp_id = $template_id;
4045 - } else {
4046 - $temp_id = '';
4047 - }
4048 -
4049 - wp_update_post([
4050 - 'ID' => $inserted_post,
4051 - ]);
4052 -
4053 - if (class_exists('Tpgb_Library') && method_exists('Tpgb_Library', 'remove_backend_dir_files')) {
4054 - Tpgb_Library()->remove_backend_dir_files();
4055 - }
4056 -
4057 - clean_post_cache( $inserted_post );
4058 - wp_send_json(
4059 - array(
4060 - $temp_id => $temp_detail,
4061 - 'description' => 'Yay! Your Section has been Successfully Imported.',
4062 - 'message' => __( 'Successfully Imported.', 'wdesignkit' ),
4063 - 'inserted_id' => $inserted_post,
4064 - 'success' => true,
4065 - )
4066 - );
4067 - wp_die();
4068 1766 }
4069 1767 } elseif ( 'elementor' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'elementor' === $file_type ) ) {
4070 1768 if ( did_action( 'elementor/loaded' ) ) {
4071 1769 if ( empty( $content ) ) {
@@ -4071,21 +1769,17 @@
4071 1769 if ( empty( $content ) ) {
4072 1770 wp_send_json(
4073 1771 array(
4074 1772 'template_id' => $template_id,
4075 - 'message' => __( 'Content is Empty.', 'wdesignkit' ),
1773 + 'message' => 'Content is Empty.',
4076 1774 )
4077 1775 );
4078 1776 wp_die();
4079 1777 } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'elementor' === $file_type ) {
4080 -
4081 - $content = $this->wdkit_content_remover( $content );
4082 -
4083 1778 $post_attributes = array(
4084 1779 'post_title' => $post_title,
4085 1780 'post_type' => $post_type,
4086 1781 'post_status' => 'publish',
4087 - 'post_name' => $post_slug,
4088 1782 );
4089 1783
4090 1784 if ( 'elementor_library' === $post_type ) {
4091 1785 $el_type = ( isset( $post_content->el_type ) && ! empty( $post_content->el_type ) ) ? sanitize_text_field( $post_content->el_type ) : 'page';
@@ -4109,43 +1803,8 @@
4109 1803 );
4110 1804 wp_die();
4111 1805 }
4112 1806
4113 - $inserted_id = $new_document->get_main_id();
4114 -
4115 - if ( ! empty( $thumb_image ) ) {
4116 - // $featured_image_url = esc_url_raw( $thumb_image );
4117 - $tmp = download_url( $thumb_image );
4118 - if ( is_wp_error( $tmp ) ) {
4119 - error_log( 'Image download failed: ' . esc_html( $tmp->get_error_message() ) );
4120 - } else {
4121 - $file_array = array(
4122 - 'name' => wp_basename( $thumb_image ),
4123 - 'tmp_name' => $tmp,
4124 - );
4125 -
4126 - $image_id = media_handle_sideload( $file_array, $inserted_id );
4127 -
4128 - if ( is_wp_error( $image_id ) ) {
4129 - error_log( 'Image sideload failed: ' . esc_html( $image_id->get_error_message() ) );
4130 - } else {
4131 - set_post_thumbnail( $inserted_id, $image_id );
4132 - }
4133 -
4134 - @unlink( $tmp );
4135 - }
4136 - }
4137 -
4138 - if ( ! empty( $category_list ) && is_array( $category_list ) ) {
4139 - $category_ids = array_map( 'intval', $category_list );
4140 - wp_set_post_terms( $inserted_id, $category_ids, 'category' );
4141 - }
4142 -
4143 - if ( ! empty( $tag_list ) && is_array( $tag_list ) ) {
4144 - $tag_ids = array_map( 'intval', $tag_list );
4145 - wp_set_post_terms( $inserted_id, $tag_ids, 'post_tag' );
4146 - }
4147 -
4148 1807 $settings = ( isset( $post_content->settings ) && ! empty( $post_content->settings ) ) ? json_decode( wp_json_encode( $post_content->settings ), true ) : array();
4149 1808
4150 1809 $content = wp_json_encode( $content );
4151 1810 $content = $this->wdkit_media_import( $content, $file_type );
@@ -4158,12 +1817,8 @@
4158 1817 );
4159 1818
4160 1819 $inserted_id = $new_document->get_main_id();
4161 1820
4162 - if( $temp_type == 'navigation' ){
4163 - $temp_con = $content;
4164 - }
4165 -
4166 1821 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
4167 1822 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
4168 1823 if ( ! empty( $custom_meta ) ) {
4169 1824 foreach ( $custom_meta as $meta_key => $meta_val ) {
@@ -4176,36 +1831,13 @@
4176 1831 }
4177 1832 }
4178 1833 }
4179 1834
4180 - $temp_detail = array(
1835 + return array(
4181 1836 'title' => get_the_title( $inserted_id ),
4182 1837 'edit_link' => get_edit_post_link( $inserted_id, 'internal' ),
4183 1838 'view' => get_permalink( $inserted_id ),
4184 - 'id' => $inserted_id,
4185 1839 );
4186 -
4187 - if ( ! empty( $template_id->id ) ) {
4188 - $temp_id = $template_id->id;
4189 - } elseif ( ! empty( $template_id ) ) {
4190 - $temp_id = $template_id;
4191 - } else {
4192 - $temp_id = '';
4193 - }
4194 -
4195 - \Elementor\Plugin::$instance->files_manager->clear_cache();
4196 -
4197 - wp_send_json(
4198 - array(
4199 - $temp_id => $temp_detail,
4200 - 'content' => $temp_con,
4201 - 'description' => 'Yay! Your Section has been Successfully Imported.',
4202 - 'message' => __( 'Successfully Imported.', 'wdesignkit' ),
4203 - 'inserted_id' => $inserted_id,
4204 - 'success' => true,
4205 - )
4206 - );
4207 - wp_die();
4208 1840 }
4209 1841 } else {
4210 1842 wp_send_json(
4211 1843 array(
@@ -4216,533 +1848,11 @@
4216 1848 wp_die();
4217 1849 }
4218 1850 }
4219 1851 }
4220 -
4221 - wp_send_json(
4222 - array(
4223 - 'success' => false,
4224 - 'message' => esc_html__( 'Something went wrong', 'wdesignkit' ),
4225 - )
4226 - );
4227 - wp_die();
4228 1852 }
4229 1853
4230 1854 /**
4231 - * Replace unicode glitch
4232 - *
4233 - * @since 2.0.0
4234 - */
4235 - private function replace_unicode_glitch( $content ) {
4236 -
4237 - // Fix escaped unicode like \u003c → <
4238 - $content = preg_replace_callback(
4239 - '/\\\\u([0-9a-fA-F]{4})/',
4240 - function ( $match ) {
4241 - return html_entity_decode(
4242 - mb_convert_encoding(
4243 - pack('H*', $match[1]),
4244 - 'UTF-8',
4245 - 'UCS-2BE'
4246 - ),
4247 - ENT_QUOTES,
4248 - 'UTF-8'
4249 - );
4250 - },
4251 - $content
4252 - );
4253 -
4254 - return $content;
4255 - }
4256 -
4257 -
4258 - /**
4259 - * change plugins setting for import kit
4260 - *
4261 - * @since 2.0.0
4262 - */
4263 - protected function update_plugin_setting() {
4264 - $temp_id = isset( $_POST['plugin_type'] ) ? sanitize_text_field( $_POST['plugin_type'] ) : '';
4265 -
4266 - if ( $temp_id == 'elementor' ) {
4267 - $unfiltered_files = get_option( 'elementor_unfiltered_files_upload', false );
4268 - $load_fa4 = get_option( 'elementor_load_fa4_shim', false );
4269 - $Inline_font_icons = get_option( 'elementor_experiment-e_font_icon_svg', false );
4270 - $container = get_option( 'elementor_experiment-container', false );
4271 -
4272 - if ( isset( $unfiltered_files ) ) {
4273 - update_option( 'elementor_unfiltered_files_upload', 1 );
4274 - } else {
4275 - add_option( 'elementor_unfiltered_files_upload', 1 );
4276 - }
4277 -
4278 - if ( isset( $load_fa4 ) ) {
4279 - update_option( 'elementor_load_fa4_shim', 'yes' );
4280 - } else {
4281 - add_option( 'elementor_load_fa4_shim', 'yes' );
4282 - }
4283 -
4284 - if ( isset( $container ) ) {
4285 - update_option( 'elementor_experiment-container', 'active' );
4286 - } else {
4287 - add_option( 'elementor_experiment-container', 'active' );
4288 - }
4289 -
4290 - if ( isset( $Inline_font_icons ) ) {
4291 - update_option( 'elementor_experiment-e_font_icon_svg', 'inactive' );
4292 - } else {
4293 - add_option( 'elementor_experiment-e_font_icon_svg', 'inactive' );
4294 - }
4295 -
4296 - $response = array(
4297 - 'message' => esc_html__( 'Plugin Setting updated', 'wdesignkit' ),
4298 - 'description' => esc_html__( 'Plugin Setting updated', 'wdesignkit' ),
4299 - 'success' => true,
4300 - );
4301 - } else {
4302 - $response = array(
4303 - 'message' => esc_html__( 'Plugin not found', 'wdesignkit' ),
4304 - 'description' => esc_html__( 'Plugin not found', 'wdesignkit' ),
4305 - 'success' => false,
4306 - );
4307 - }
4308 -
4309 - wp_send_json( $response );
4310 - wp_die();
4311 - }
4312 -
4313 - /**
4314 - * generate different color logo
4315 - *
4316 - * @since 2.0.0
4317 - */
4318 - protected function wkit_generate_site_logo() {
4319 -
4320 - if ( empty( $_POST['image_url'] ) ) {
4321 - wp_send_json_error( 'Image URL not provided.' );
4322 - }
4323 -
4324 - if ( isset( $_POST['colors'] ) ) {
4325 - $img_colors = ! empty( $_POST['colors'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['colors'] ) ), true ) : array();
4326 - }
4327 -
4328 - if ( empty( $img_colors ) ) {
4329 - wp_send_json_error( 'Image color not provided.' );
4330 - }
4331 -
4332 - $image_url = esc_url_raw( $_POST['image_url'] );
4333 -
4334 - $tmp_file = download_url( $image_url );
4335 - if ( is_wp_error( $tmp_file ) ) {
4336 - wp_send_json_error( 'Image could not be downloaded.' );
4337 - }
4338 -
4339 - if ( mime_content_type( $tmp_file ) !== 'image/png' ) {
4340 - unlink( $tmp_file );
4341 - wp_send_json_error( 'Not a PNG file.' );
4342 - }
4343 -
4344 - $src = imagecreatefrompng( $tmp_file );
4345 - imagesavealpha( $src, true );
4346 -
4347 - $width = imagesx( $src );
4348 - $height = imagesy( $src );
4349 -
4350 - $hasTransparency = false;
4351 - for ( $x = 0; $x < $width; $x++ ) {
4352 - for ( $y = 0; $y < $height; $y++ ) {
4353 - $rgba = imagecolorat( $src, $x, $y );
4354 - $alpha = ( $rgba & 0x7F000000 ) >> 24;
4355 -
4356 - if ( $alpha > 0 ) {
4357 - $hasTransparency = true;
4358 - break 2;
4359 - }
4360 - }
4361 - }
4362 -
4363 - if ( ! $hasTransparency ) {
4364 - unlink( $tmp_file );
4365 - wp_send_json_error( 'PNG has no transparent pixels.' );
4366 - }
4367 -
4368 - $upload_dir = wp_upload_dir();
4369 - $result_urls = array();
4370 -
4371 - foreach ( $img_colors as $name => $rgb ) {
4372 - $new = imagecreatetruecolor( $width, $height );
4373 - imagesavealpha( $new, true );
4374 - imagealphablending( $new, false );
4375 -
4376 - $transparent = imagecolorallocatealpha( $new, 0, 0, 0, 127 );
4377 - imagefill( $new, 0, 0, $transparent );
4378 -
4379 - for ( $x = 0; $x < $width; $x++ ) {
4380 - for ( $y = 0; $y < $height; $y++ ) {
4381 - $rgba = imagecolorat( $src, $x, $y );
4382 - $alpha = ( $rgba & 0x7F000000 ) >> 24;
4383 -
4384 - // Skip fully transparent pixels
4385 - if ( $alpha === 127 ) {
4386 - continue;
4387 - }
4388 -
4389 - // Replace pixel color directly
4390 - $new_r = $rgb[0];
4391 - $new_g = $rgb[1];
4392 - $new_b = $rgb[2];
4393 -
4394 - $color = imagecolorallocatealpha( $new, $new_r, $new_g, $new_b, $alpha );
4395 - imagesetpixel( $new, $x, $y, $color );
4396 - }
4397 - }
4398 -
4399 - $filename = 'colored-' . $name . '-' . time() . '.png';
4400 - $filepath = $upload_dir['path'] . '/' . $filename;
4401 -
4402 - imagepng( $new, $filepath );
4403 - imagedestroy( $new );
4404 -
4405 - $attachment = array(
4406 - 'post_mime_type' => 'image/png',
4407 - 'post_title' => sanitize_file_name( $filename ),
4408 - 'post_content' => '',
4409 - 'post_status' => 'inherit',
4410 - );
4411 -
4412 - $attach_id = wp_insert_attachment( $attachment, $filepath );
4413 - require_once ABSPATH . 'wp-admin/includes/image.php';
4414 - $attach_data = wp_generate_attachment_metadata( $attach_id, $filepath );
4415 - wp_update_attachment_metadata( $attach_id, $attach_data );
4416 -
4417 - $result_urls[ $name ] = wp_get_attachment_url( $attach_id );
4418 - }
4419 -
4420 - imagedestroy( $src );
4421 - unlink( $tmp_file );
4422 -
4423 - wp_send_json_success( $result_urls );
4424 - }
4425 -
4426 - /**
4427 - * change theme setting for import kit
4428 - *
4429 - * @since 2.0.0
4430 - */
4431 - protected function update_theme_setting() {
4432 - $theme_db = get_option( 'nxt-theme-options', false );
4433 -
4434 - $container_type = 'container-fluid';
4435 - $fluid_spacing = array(
4436 - 'md' => array(
4437 - 'left' => '0',
4438 - 'right' => '0',
4439 - ),
4440 - 'sm' => array(
4441 - 'left' => '',
4442 - 'right' => '',
4443 - ),
4444 - 'xs' => array(
4445 - 'left' => '',
4446 - 'right' => '',
4447 - ),
4448 - 'md-unit' => 'px',
4449 - 'sm-unit' => 'px',
4450 - 'xs-unit' => 'px',
4451 - );
4452 -
4453 - if ( isset( $theme_db ) ) {
4454 - $nexter_setting = $theme_db;
4455 - $nexter_setting['site-header-container'] = $container_type;
4456 - $nexter_setting['site-footer-container'] = $container_type;
4457 - $nexter_setting['site-layout-container'] = $container_type;
4458 - $nexter_setting['site-page-container'] = $container_type;
4459 -
4460 - $nexter_setting['header-fluid-spacing'] = $fluid_spacing;
4461 - $nexter_setting['footer-fluid-spacing'] = $fluid_spacing;
4462 - $nexter_setting['site-fluid-spacing'] = $fluid_spacing;
4463 - $nexter_setting['page-fluid-spacing'] = $fluid_spacing;
4464 -
4465 - update_option( 'nxt-theme-options', $nexter_setting );
4466 - } else {
4467 - $nexter_setting = array(
4468 - 'site-header-container' => 'container-fluid',
4469 - 'header-fluid-spacing' => array(
4470 - 'md' => array(
4471 - 'left' => '0',
4472 - 'right' => '0',
4473 - ),
4474 - 'sm' => array(
4475 - 'left' => '',
4476 - 'right' => '',
4477 - ),
4478 - 'xs' => array(
4479 - 'left' => '',
4480 - 'right' => '',
4481 - ),
4482 - 'md-unit' => 'px',
4483 - 'sm-unit' => 'px',
4484 - 'xs-unit' => 'px',
4485 - ),
4486 - 'site-footer-container' => 'container-fluid',
4487 - 'footer-fluid-spacing' => array(
4488 - 'md' => array(
4489 - 'left' => '0',
4490 - 'right' => '0',
4491 - ),
4492 - 'sm' => array(
4493 - 'left' => '',
4494 - 'right' => '',
4495 - ),
4496 - 'xs' => array(
4497 - 'left' => '',
4498 - 'right' => '',
4499 - ),
4500 - 'md-unit' => 'px',
4501 - 'sm-unit' => 'px',
4502 - 'xs-unit' => 'px',
4503 - ),
4504 - 'site-layout-container' => 'container-fluid',
4505 - 'site-fluid-spacing' => array(
4506 - 'md' => array(
4507 - 'left' => '0',
4508 - 'right' => '0',
4509 - ),
4510 - 'sm' => array(
4511 - 'left' => '',
4512 - 'right' => '',
4513 - ),
4514 - 'xs' => array(
4515 - 'left' => '',
4516 - 'right' => '',
4517 - ),
4518 - 'md-unit' => 'px',
4519 - 'sm-unit' => 'px',
4520 - 'xs-unit' => 'px',
4521 - ),
4522 - 'site-page-container' => 'container-fluid',
4523 - 'page-fluid-spacing' => array(
4524 - 'md' => array(
4525 - 'left' => '0',
4526 - 'right' => '0',
4527 - ),
4528 - 'sm' => array(
4529 - 'left' => '',
4530 - 'right' => '',
4531 - ),
4532 - 'xs' => array(
4533 - 'left' => '',
4534 - 'right' => '',
4535 - ),
4536 - 'md-unit' => 'px',
4537 - 'sm-unit' => 'px',
4538 - 'xs-unit' => 'px',
4539 - ),
4540 - 'site-page-container' => '',
4541 - 'site-posts-container' => '',
4542 - 'site-archive-container' => '',
4543 - );
4544 -
4545 - add_option( 'nxt-theme-options', $nexter_setting );
4546 - }
4547 -
4548 - $response = array(
4549 - 'message' => esc_html__( 'Theme Setting updated', 'wdesignkit' ),
4550 - 'description' => esc_html__( 'Theme Setting updated', 'wdesignkit' ),
4551 - 'success' => true,
4552 - );
4553 -
4554 - wp_send_json( $response );
4555 - wp_die();
4556 - }
4557 -
4558 - /**
4559 - * change site setting for import kit
4560 - *
4561 - * @since 2.0.0
4562 - */
4563 - protected function update_site_setting() {
4564 - $temp_id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
4565 - $shop_id = isset( $_POST['shop_id'] ) ? sanitize_text_field( wp_unslash( $_POST['shop_id'] ) ) : '';
4566 - $temp_type = isset( $_POST['temp_type'] ) ? sanitize_text_field( wp_unslash( $_POST['temp_type'] ) ) : 'page';
4567 - $site_name = isset( $_POST['site_name'] ) ? sanitize_text_field( wp_unslash( $_POST['site_name'] ) ) : '';
4568 - $site_tagline = isset( $_POST['site_tagline'] ) ? sanitize_text_field( wp_unslash( $_POST['site_tagline'] ) ) : '';
4569 -
4570 - $this->wdkit_nxt_thembuilder_update();
4571 -
4572 - if ( ! empty( $shop_id ) ) {
4573 - update_option( 'woocommerce_shop_page_id', $shop_id );
4574 - }
4575 -
4576 - if ( $temp_id ) {
4577 - update_option( 'show_on_front', $temp_type );
4578 - update_option( 'page_on_front', $temp_id );
4579 -
4580 - if ( ! empty( $site_name ) ) {
4581 - update_option( 'blogname', $site_name );
4582 - }
4583 -
4584 - if ( ! empty( $site_tagline ) ) {
4585 - update_option( 'blogdescription', $site_tagline );
4586 - }
4587 -
4588 - $response = array(
4589 - 'message' => esc_html__( 'Site link updated', 'wdesignkit' ),
4590 - 'description' => esc_html__( 'Site link updated', 'wdesignkit' ),
4591 - 'site_link' => get_site_url(),
4592 - 'success' => true,
4593 - );
4594 - } else {
4595 - $response = array(
4596 - 'message' => esc_html__( 'Site not found', 'wdesignkit' ),
4597 - 'description' => esc_html__( 'Site not found', 'wdesignkit' ),
4598 - 'success' => false,
4599 - );
4600 - }
4601 -
4602 - wp_send_json( $response );
4603 - wp_die();
4604 - }
4605 -
4606 - /**
4607 - * update theme builder
4608 - *
4609 - * @since 2.0.4
4610 - */
4611 - public function wdkit_nxt_thembuilder_update() {
4612 -
4613 - $page_information = isset( $_POST['page_information'] ) ? sanitize_text_field( wp_unslash( $_POST['page_information'] ) ) : '';
4614 - $page_information = json_decode( $page_information, true );
4615 -
4616 - if ( ! empty( $page_information ) && is_array( $page_information ) ) {
4617 -
4618 - // Every page and attachment now exists, so resolve any image ID the per-page
4619 - // pass could not (siblings import concurrently and share icons).
4620 - $this->wdkit_sweep_attachment_ids( wp_list_pluck( $page_information, 'inserted_id' ) );
4621 -
4622 - // Step 1: banavo mapping [ old_id => new_id ]
4623 - $id_mapping = array();
4624 - foreach ( $page_information as $page_info ) {
4625 - if ( ! empty( $page_info['old_page_id'] ) ) {
4626 - $id_mapping[ $page_info['old_page_id'] ] = $page_info['inserted_id'];
4627 - }
4628 - }
4629 -
4630 - // Step 2: loop karo and update exclude
4631 - foreach ( $page_information as $page_info ) {
4632 -
4633 - $post_id = $page_info['inserted_id'] ?? '';
4634 - $old_post_id = $page_info['old_page_id'] ?? '';
4635 - $post_type = $page_info['post_type'] ?? '';
4636 -
4637 - if ( empty( $old_post_id ) ) {
4638 - continue; // only update where old id exists
4639 - }
4640 -
4641 - if ( $post_type != 'nxt_builder' ) {
4642 - continue;
4643 - }
4644 -
4645 - $include_specific = get_post_meta( $post_id, 'nxt-hooks-layout-specific', true );
4646 - if ( ! empty( $include_specific ) && is_array( $include_specific ) ) {
4647 -
4648 - foreach ( $include_specific as $key => $val ) {
4649 -
4650 - // check karo ke koi old_id ka post match kare che ke nahi
4651 - foreach ( $id_mapping as $old_id => $new_id ) {
4652 - $search = 'post-' . $old_id;
4653 - $replace = 'post-' . $new_id;
4654 -
4655 - if ( $val === $search ) {
4656 - $include_specific[ $key ] = $replace;
4657 - }
4658 - }
4659 - }
4660 -
4661 - // save back updated array
4662 - update_post_meta( $post_id, 'nxt-hooks-layout-specific', $include_specific );
4663 - }
4664 -
4665 - // Get exclude meta
4666 - $exclude_specific = get_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific', true );
4667 - if ( ! empty( $exclude_specific ) && is_array( $exclude_specific ) ) {
4668 -
4669 - foreach ( $exclude_specific as $key => $val ) {
4670 -
4671 - // check karo ke koi old_id ka post match kare che ke nahi
4672 - foreach ( $id_mapping as $old_id => $new_id ) {
4673 - $search = 'post-' . $old_id;
4674 - $replace = 'post-' . $new_id;
4675 -
4676 - if ( $val === $search ) {
4677 - $exclude_specific[ $key ] = $replace;
4678 - }
4679 - }
4680 - }
4681 -
4682 - // save back updated array
4683 - update_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific', $exclude_specific );
4684 - }
4685 - }
4686 - }
4687 - }
4688 -
4689 - /**
4690 - *
4691 - * select team image for import kit
4692 - *
4693 - * @since 2.2.2
4694 - */
4695 - public function wdkit_check_user_credit() {
4696 - $array_data = array(
4697 - 'token' => isset( $_POST['token'] ) ? sanitize_text_field( $_POST['token'] ) : '',
4698 - );
4699 -
4700 - $response = $this->wkit_api_call( $array_data, 'ai/credits/get' );
4701 - $success = ! empty( $response['success'] ) ? $response['success'] : false;
4702 -
4703 - if ( empty( $success ) ) {
4704 - $response = array(
4705 - 'success' => false,
4706 - 'message' => esc_html__( 'Data Not Found', 'wdesignkit' ),
4707 - 'description' => esc_html__( 'Data not found', 'wdesignkit' ),
4708 - );
4709 -
4710 - wp_send_json( $response );
4711 - wp_die();
4712 - }
4713 -
4714 - $response = json_decode( wp_json_encode( $response['data'] ), true );
4715 -
4716 - wp_send_json( $response );
4717 - wp_die();
4718 - }
4719 -
4720 - public function wdkit_nxt_thembuilder_reset() {
4721 - $post_id = isset( $_POST['post_id'] ) ? sanitize_text_field( $_POST['post_id'] ) : '';
4722 - $sections_layout = get_post_meta( $post_id, 'nxt-hooks-layout-sections', true );
4723 -
4724 - if ( ( ! empty( $sections_layout ) && ( $sections_layout == 'header' || $sections_layout == 'footer' || $sections_layout == 'breadcrumb' || $sections_layout == 'hooks' ) ) ) {
4725 - if ( get_post_meta( $post_id, 'nxt-add-display-rule' ) ) {
4726 - delete_post_meta( $post_id, 'nxt-add-display-rule' );
4727 - }
4728 -
4729 - if ( get_post_meta( $post_id, 'nxt-hooks-layout-specific' ) ) {
4730 - update_post_meta( $post_id, 'nxt-hooks-layout-specific', '' );
4731 - }
4732 -
4733 - if ( get_post_meta( $post_id, 'nxt-exclude-display-rule' ) ) {
4734 - update_post_meta( $post_id, 'nxt-exclude-display-rule', '' );
4735 - }
4736 -
4737 - if ( get_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific' ) ) {
4738 - update_post_meta( $post_id, 'nxt-hooks-layout-exclude-specific', '' );
4739 - }
4740 - }
4741 - }
4742 -
4743 -
4744 - /**
4745 1855 * Share with Me Template and widgets
4746 1856 *
4747 1857 * @since 1.0.0
4748 1858 */
@@ -4829,10 +1939,9 @@
4829 1939 protected function wdkit_activate_key() {
4830 1940 $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '';
4831 1941 $response = '';
4832 1942
4833 - // Bug C fix: variable was $user_email but only $email is set above — always triggered empty() guard.
4834 - if ( empty( $email ) ) {
1943 + if ( empty( $user_email ) ) {
4835 1944 $response = array(
4836 1945 'message' => $this->e_msg_login,
4837 1946 'description' => $this->e_desc_login,
4838 1947 'success' => false,
@@ -4887,12 +1996,8 @@
4887 1996 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) {
4888 1997 array_push( $builder, 'gutenberg' );
4889 1998 }
4890 1999
4891 - if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg_core', 'widget' ) ) {
4892 - array_push( $builder, 'gutenberg_core' );
4893 - }
4894 -
4895 2000 foreach ( $builder as $key => $name ) {
4896 2001 $elementor_dir = WDKIT_BUILDER_PATH . '/' . $name;
4897 2002
4898 2003 if ( ! empty( $elementor_dir ) && is_dir( $elementor_dir ) ) {
@@ -4900,10 +2005,10 @@
4900 2005 $elementor_list = array_diff( $elementor_list, array( '.', '..' ) );
4901 2006
4902 2007 if ( ! empty( $elementor_list ) ) {
4903 2008 foreach ( $elementor_list as $key => $value ) {
4904 - $a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) . $key ]['data'] = $value;
4905 - $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;
4906 2011 }
4907 2012 }
4908 2013 }
4909 2014 }
@@ -4970,108 +2075,521 @@
4970 2075 wp_send_json( get_option( 'wkit_builder' ) );
4971 2076 }
4972 2077
4973 2078 /**
4974 - * Get Workspace data
4975 2079 *
4976 - * @since 2.2.5
2080 + * Custom_upload_dir
2081 + *
2082 + * @since 1.0.0
2083 + *
2084 + * @param array $upload store data.
4977 2085 */
4978 - 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 ) ) {
4979 2089
4980 - $wid = isset( $_POST['wid'] ) ? sanitize_text_field( $_POST['wid'] ) : '';
4981 - $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 + }
4982 2095
4983 - if ( empty( $wid ) ) {
4984 - 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' ),
4985 2126 'success' => false,
4986 - 'message' => esc_html__( 'Workspace ID Not Found', 'wdesignkit' ),
4987 - 'description' => esc_html__( 'Workspace ID is required', 'wdesignkit' ),
4988 2127 );
2128 +
2129 + wp_send_json( $responce );
2130 + wp_die();
4989 2131 }
4990 2132
4991 - if ( empty( $token ) ) {
4992 - 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' ),
4993 2164 'success' => false,
4994 - 'message' => esc_html__( 'Token Not Found', 'wdesignkit' ),
4995 - 'description' => esc_html__( 'Token is required', 'wdesignkit' ),
4996 2165 );
2166 +
2167 + wp_send_json( $responce );
2168 + wp_die();
4997 2169 }
4998 2170
4999 - $args = array(
5000 - 'token' => $token,
5001 - 'wid' => $wid,
5002 - );
2171 + $builder_type_path = trailingslashit( WDKIT_BUILDER_PATH ) . trailingslashit( $widget_type );
2172 + $widget_file_url = $builder_type_path . $folder_name;
5003 2173
5004 - $this->wdkit_api = $this->wdkit_api_v2;
2174 + if ( ! is_dir( $widget_file_url ) ) {
2175 + wp_mkdir_p( $widget_file_url );
2176 + }
5005 2177
5006 - $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;
5007 2183
5008 - $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( '.', '..' ) );
5009 2187
5010 - 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 );
5011 2331 wp_die();
5012 2332 }
5013 2333
5014 2334 /**
5015 2335 *
5016 - * Custom_upload_dir
2336 + * It is Use for delete widget from server
5017 2337 *
5018 2338 * @since 1.0.0
5019 - *
5020 - * @param array $upload store data.
5021 2339 */
5022 - public function custom_upload_dir( $upload ) {
5023 - // Specify the path to your custom upload directory.
5024 - 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 + }
5025 2345
5026 - // Set the custom directory as the upload path.
5027 - $upload['path'] = $this->widget_folder_u_r_l;
5028 - // Set the URL for the uploaded file.
5029 - $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 );
5030 2356 }
5031 2357
5032 - 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 + }
5033 2449 }
5034 2450
5035 2451 /**
5036 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 + *
5037 2466 * It is Use for delete widget from server
5038 2467 *
5039 2468 * @since 1.0.0
5040 2469 */
5041 - protected function wkit_widget_json() {
5042 - $widget_type = ! empty( $_POST['widget_type'] ) ? wp_unslash( $_POST['widget_type'] ) : '';
5043 - $folder_name = ! empty( $_POST['folder_name'] ) ? wp_unslash( $_POST['folder_name'] ) : '';
5044 - $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 ) );
5045 2473
5046 - if ( empty( $widget_type ) || empty( $folder_name ) || empty( $file_name ) ) {
5047 - 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(
5048 2483 'success' => false,
5049 - 'message' => esc_html__( 'Widget JSON not found', 'wdesignkit' ),
5050 - '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' ),
5051 2487 );
2488 +
2489 + wp_send_json( $result );
2490 + wp_die();
5052 2491 }
5053 2492
5054 - $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}";
5055 2495
5056 - $json_data = wp_json_file_decode( "$json_path.json" );
5057 - 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 +
5058 2511 $result = (object) array(
5059 2512 'success' => true,
5060 - 'data' => $json_data,
5061 - 'message' => esc_html__( 'Widget get Successfully', 'wdesignkit' ),
5062 - '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' ),
5063 2516 );
2517 +
2518 + wp_send_json( $result );
2519 + wp_die();
5064 2520 } else {
5065 2521 $result = (object) array(
5066 2522 'success' => false,
5067 - 'message' => esc_html__( 'Widget not get', 'wdesignkit' ),
5068 - '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' ),
5069 2526 );
2527 +
2528 + wp_send_json( $result );
2529 + wp_die();
5070 2530 }
2531 + }
5071 2532
5072 - wp_send_json( $result );
5073 - 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 + }
5074 2592 }
5075 2593
5076 2594 /**
5077 2595 *
@@ -5086,10 +2604,8 @@
5086 2604 $array_data = array(
5087 2605 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
5088 2606 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
5089 2607 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
5090 - // Bug F fix: u_id (widget owner's user ID) was missing — cloud cannot locate the widget without it.
5091 - 'u_id' => isset( $data->u_id ) ? sanitize_text_field( $data->u_id ) : '',
5092 2608 );
5093 2609
5094 2610 $response = $this->wkit_api_call( $array_data, 'save_widget' );
5095 2611 $success = ! empty( $response['success'] ) ? $response['success'] : false;
@@ -5122,16 +2638,10 @@
5122 2638 wp_die();
5123 2639 }
5124 2640
5125 2641 $img_url = ! empty( $response['data']['image'] ) ? $response['data']['image'] : '';
5126 - $json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'], true ) : '';
2642 + $json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'] ) : '';
5127 2643
5128 - // Bug E fix (part 1): $responce was a typo of $response — sent undefined variable (null) to frontend.
5129 - if ( empty( $response['success'] ) ) {
5130 - wp_send_json( $response );
5131 - wp_die();
5132 - }
5133 -
5134 2644 if ( empty( $img_url ) && empty( $json_data ) ) {
5135 2645 $responce = (object) array(
5136 2646 'success' => false,
5137 2647 'message' => esc_html__( 'No Response Found', 'wdesignkit' ),
@@ -5145,16 +2655,12 @@
5145 2655 include_once ABSPATH . 'wp-admin/includes/file.php';
5146 2656 \WP_Filesystem();
5147 2657 global $wp_filesystem;
5148 2658
5149 - if ( ! is_array( $json_data ) ) {
5150 - $json_data = json_decode( $json_data, true );
5151 - }
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 ) : '';
5152 2662
5153 - $title = ! empty( $json_data['widget_data']['widgetdata']['name'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['name'] ) : '';
5154 - $builder = ! empty( $json_data['widget_data']['widgetdata']['type'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['type'] ) : '';
5155 - $w_uniq = ! empty( $json_data['widget_data']['widgetdata']['widget_id'] ) ? sanitize_text_field( $json_data['widget_data']['widgetdata']['widget_id'] ) : '';
5156 -
5157 2663 $folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
5158 2664 $file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
5159 2665 $builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/";
5160 2666
@@ -5170,14 +2676,13 @@
5170 2676 $img_body = wp_remote_get( $img_url );
5171 2677 $img_ext = pathinfo( $img_url )['extension'];
5172 2678
5173 2679 $wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] );
5174 - $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";
5175 2681 }
5176 2682
5177 - // Bug E fix (part 2): success was hardcoded false on the successful download path — always reported failure.
5178 2683 $result = (object) array(
5179 - 'success' => true,
2684 + 'success' => false,
5180 2685 'message' => ! empty( $response['message'] ) ? $response['message'] : esc_html__( 'no message', 'wdesignkit' ),
5181 2686 'description' => '',
5182 2687 'json' => wp_json_encode( $json_data ),
5183 2688 );
@@ -5187,8 +2692,87 @@
5187 2692 }
5188 2693
5189 2694 /**
5190 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 + *
5191 2775 * It is Use for sync widget to server
5192 2776 *
5193 2777 * @since 1.0.0
5194 2778 */
@@ -5193,10 +2777,9 @@
5193 2777 * @since 1.0.0
5194 2778 */
5195 2779 protected function wdkit_add_widget() {
5196 2780 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
5197 - $data = base64_decode( $data );
5198 - $data = json_decode( $data );
2781 + $data = json_decode( stripslashes( $data ) );
5199 2782
5200 2783 $title = isset( $data->title ) ? sanitize_text_field( $data->title ) : '';
5201 2784 $builder = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '';
5202 2785 $w_uniq = isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '';
@@ -5219,9 +2802,8 @@
5219 2802 'w_imgext' => isset( $data->w_imgext ) ? sanitize_text_field( $data->w_imgext ) : '',
5220 2803 'w_version' => isset( $data->w_version ) ? $data->w_version : '',
5221 2804 'w_updates' => ! empty( $data->w_updates ) ? serialize( $data->w_updates ) : serialize( array() ),
5222 2805 'r_id' => isset( $data->r_id ) ? $data->r_id : 0,
5223 - 'unique_id' => get_option( 'wdkit_unique_id' ) ?? '',
5224 2806 );
5225 2807
5226 2808 $response = $this->wkit_api_call( $array_data, 'save_widget' );
5227 2809 $success = ! empty( $response['success'] ) ? $response['success'] : false;
@@ -5244,9 +2826,8 @@
5244 2826 $response = json_decode( wp_json_encode( $res ), true );
5245 2827 $img_url = ! empty( $response['data']['imgurl'] ) ? $response['data']['imgurl'] : '';
5246 2828
5247 2829 if ( ! empty( $img_url ) && 'error' !== $res ) {
5248 -
5249 2830 $img_body = wp_remote_get( $img_url );
5250 2831 $img_ext = pathinfo( $img_url )['extension'];
5251 2832 include_once ABSPATH . 'wp-admin/includes/file.php';
5252 2833 \WP_Filesystem();
@@ -5327,9 +2908,9 @@
5327 2908 *
5328 2909 * @since 1.0.0
5329 2910 */
5330 2911 protected static function wkit_get_settings_panel() {
5331 - $new_version = '';
2912 +
5332 2913 $current_version = WDKIT_VERSION;
5333 2914 $response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/wdesignkit.json' );
5334 2915
5335 2916 if ( is_wp_error( $response ) ) {
@@ -5354,108 +2935,23 @@
5354 2935 }
5355 2936
5356 2937 $get_setting = get_option( 'wkit_settings_panel', false );
5357 2938
5358 - $setting_data = array(
5359 - 'builder' => isset( $get_setting['builder'] ) ? $get_setting['builder'] : true,
5360 - 'template' => isset( $get_setting['template'] ) ? $get_setting['template'] : true,
5361 - 'gutenberg_builder' => isset( $get_setting['gutenberg_builder'] ) ? $get_setting['gutenberg_builder'] : true,
5362 - 'gutenberg_core_builder' => isset( $get_setting['gutenberg_core_builder'] ) ? $get_setting['gutenberg_core_builder'] : false,
5363 - 'elementor_builder' => isset( $get_setting['elementor_builder'] ) ? $get_setting['elementor_builder'] : true,
5364 - 'bricks_builder' => isset( $get_setting['bricks_builder'] ) ? $get_setting['bricks_builder'] : false,
5365 - 'gutenberg_template' => isset( $get_setting['gutenberg_template'] ) ? $get_setting['gutenberg_template'] : true,
5366 - 'elementor_template' => isset( $get_setting['elementor_template'] ) ? $get_setting['elementor_template'] : true,
5367 - 'code_snippet' => isset( $get_setting['code_snippet'] ) ? $get_setting['code_snippet'] : true,
5368 - 'cross_copy_paste' => isset( $get_setting['cross_copy_paste'] ) ? $get_setting['cross_copy_paste'] : false,
5369 - 'cross_copy_paste_elementor' => isset( $get_setting['cross_copy_paste_elementor'] ) ? $get_setting['cross_copy_paste_elementor'] : false,
5370 - 'cross_copy_paste_gutenberg' => isset( $get_setting['cross_copy_paste_gutenberg'] ) ? $get_setting['cross_copy_paste_gutenberg'] : false,
5371 - 'cross_copy_paste_bricks' => isset( $get_setting['cross_copy_paste_bricks'] ) ? $get_setting['cross_copy_paste_bricks'] : false,
5372 - '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,
5373 2949 );
5374 -
5375 - if ( isset( $get_setting['remove_db'] ) ) {
5376 - $setting_data['remove_db'] = $get_setting['remove_db'];
5377 - }
5378 -
5379 - if ( isset( $get_setting['debugger_mode'] ) ) {
5380 - $setting_data['debugger_mode'] = $get_setting['debugger_mode'];
5381 - }
5382 -
5383 - return $setting_data;
5384 2950 }
5385 2951
5386 2952 /**
5387 - * Updated White Label Data.
5388 2953 *
5389 - * @since 1.1.8
5390 - */
5391 - protected function wkit_white_label() {
5392 -
5393 - $get_wl_data = ! empty( $_POST['WhiteLabelData'] ) ? wp_unslash( $_POST['WhiteLabelData'] ) : array();
5394 -
5395 - if ( ! empty( $get_wl_data ) ) {
5396 - $white_label_data = json_decode( $get_wl_data, true );
5397 - $plugin_name = $white_label_data['plugin_name'];
5398 - } else {
5399 - $result = array(
5400 - 'success' => false,
5401 - 'message' => esc_html__( 'Data Not Found', 'wdesignkit' ),
5402 - );
5403 -
5404 - wp_send_json( $result );
5405 - wp_die();
5406 - }
5407 -
5408 - if ( ! empty( $plugin_name ) ) {
5409 - $get_white_label = get_option( 'wkit_white_label', false );
5410 - if ( ! empty( $get_white_label ) ) {
5411 - update_option( 'wkit_white_label', $white_label_data );
5412 - } else {
5413 - add_option( 'wkit_white_label', $white_label_data );
5414 - }
5415 - } else {
5416 - $result = array(
5417 - 'success' => false,
5418 - 'message' => esc_html__( 'Plugin Name Not Found', 'wdesignkit' ),
5419 - );
5420 -
5421 - wp_send_json( $result );
5422 - wp_die();
5423 - }
5424 -
5425 - $get_updated_data = get_option( 'wkit_white_label', false );
5426 - $response = array(
5427 - 'message' => __( 'Data Added successfully', 'wdesignkit' ),
5428 - 'success' => true,
5429 - 'data' => $get_updated_data,
5430 - );
5431 -
5432 - wp_send_json( $response );
5433 - }
5434 -
5435 - /**
5436 - * Reset White Label Data.
5437 - *
5438 - * @since 1.1.8
5439 - */
5440 - public function wkit_reset_wl() {
5441 - $wl_data = get_option( 'wkit_white_label' );
5442 -
5443 - if ( ! empty( $wl_data ) ) {
5444 - delete_option( 'wkit_white_label' );
5445 -
5446 - $result = array(
5447 - 'success' => true,
5448 - 'message' => esc_html__( 'Reset White Label Successfully', 'wdesignkit' ),
5449 - );
5450 -
5451 - wp_send_json( $result );
5452 - wp_die();
5453 - }
5454 - }
5455 -
5456 - /**
5457 - *
5458 2954 * Use for Add new licence key.
5459 2955 *
5460 2956 * @since 1.0.0
5461 2957 */
@@ -5468,38 +2964,9 @@
5468 2964 );
5469 2965
5470 2966 $response = $this->wkit_api_call( $args, 'wkit_activate_key' );
5471 2967
5472 - if ( ! empty( $response['data'] ) ) {
5473 - $response = json_decode( wp_json_encode( $response['data'] ), true );
5474 -
5475 - if ( ! empty( $response['data']['tpae_licence'] ) && is_serialized( $response['data']['tpae_licence'] ) ) {
5476 - $response['data']['tpae_licence'] = unserialize( $response['data']['tpae_licence'] );
5477 - }
5478 -
5479 - if ( ! empty( $response['data']['tpag_licence'] ) && is_serialized( $response['data']['tpag_licence'] ) ) {
5480 - $response['data']['tpag_licence'] = unserialize( $response['data']['tpag_licence'] );
5481 - }
5482 -
5483 - if ( ! empty( $response['data']['uichemy_licence'] ) && is_serialized( $response['data']['uichemy_licence'] ) ) {
5484 - $response['data']['uichemy_licence'] = unserialize( $response['data']['uichemy_licence'] );
5485 - }
5486 -
5487 - if ( ! empty( $response['data']['wdkit_licence'] ) && is_serialized( $response['data']['wdkit_licence'] ) ) {
5488 - $response['data']['wdkit_licence'] = unserialize( $response['data']['wdkit_licence'] );
5489 -
5490 - // Store WDesignKit license status locally for quick access
5491 - if ( ! empty( $response['data']['wdkit_licence'] ) && is_array( $response['data']['wdkit_licence'] ) ) {
5492 - update_option( 'wdkit_licence_data', $response['data']['wdkit_licence'] );
5493 - }
5494 - }
5495 -
5496 - if ( ! empty( $response['data']['wdkit_licence_extra'] ) && is_serialized( $response['data']['wdkit_licence_extra'] ) ) {
5497 - $response['data']['wdkit_licence_extra'] = unserialize( $response['data']['wdkit_licence_extra'] );
5498 - }
5499 - }
5500 -
5501 - wp_send_json( $response );
2968 + wp_send_json( $response['data'] );
5502 2969 wp_die();
5503 2970 }
5504 2971
5505 2972 /**
@@ -5510,23 +2977,16 @@
5510 2977 */
5511 2978 protected function wdkit_delete_licence_key() {
5512 2979 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
5513 2980 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
5514 - $apikey = ! empty( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : '';
5515 2981
5516 2982 $args = array(
5517 2983 'token' => $token,
5518 2984 'licencename' => $licencename,
5519 - 'apikey' => $apikey,
5520 2985 );
5521 2986
5522 2987 $response = $this->wkit_api_call( $args, 'licence_delete' );
5523 2988
5524 - // Remove local WDesignKit license data if deleting WDesignKit license
5525 - if ( 'wdkit' === $licencename ) {
5526 - delete_option( 'wdkit_licence_data' );
5527 - }
5528 -
5529 2989 wp_send_json( $response['data'] );
5530 2990 wp_die();
5531 2991 }
5532 2992
@@ -5538,16 +2998,12 @@
5538 2998 */
5539 2999 protected function wdkit_sync_licence_key() {
5540 3000 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
5541 3001 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
5542 - // Needed to identify which extra-credit key to sync (wdkit_extra / wdkit_ai_extra
5543 - // are arrays matched by the api key's last digits on the server).
5544 - $apikey = ! empty( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : '';
5545 3002
5546 3003 $args = array(
5547 3004 'token' => $token,
5548 3005 'licencename' => $licencename,
5549 - 'apikey' => $apikey,
5550 3006 );
5551 3007
5552 3008 $response = $this->wkit_api_call( $args, 'licence_sync' );
5553 3009
@@ -5555,118 +3011,9 @@
5555 3011 wp_die();
5556 3012 }
5557 3013
5558 3014 /**
5559 - * Rollback to Previous Versions
5560 3015 *
5561 - * @since 1.1.0
5562 - */
5563 - protected function wdkit_prev_version() {
5564 -
5565 - require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
5566 -
5567 - $plugin_info = plugins_api(
5568 - 'plugin_information',
5569 - array(
5570 - 'slug' => 'wdesignkit',
5571 - )
5572 - );
5573 -
5574 - if ( empty( $plugin_info->versions ) || ! is_array( $plugin_info->versions ) ) {
5575 - return array();
5576 - }
5577 -
5578 - krsort( $plugin_info->versions );
5579 -
5580 - $versions_list = array();
5581 - $index = 0;
5582 -
5583 - foreach ( $plugin_info->versions as $version => $download_link ) {
5584 -
5585 - $lowercase_version = strtolower( $version );
5586 -
5587 - $is_valid_version = ! preg_match( '/(beta|rc|trunk|dev)/i', $lowercase_version );
5588 -
5589 - $is_valid_version = apply_filters( 'wdkit_check_rollback_version', $is_valid_version, $lowercase_version );
5590 -
5591 - if ( ! $is_valid_version || version_compare( $version, WDKIT_VERSION, '>=' ) ) {
5592 - continue;
5593 - }
5594 -
5595 - $versions_list[] = $version;
5596 - ++$index;
5597 - }
5598 -
5599 - // set_transient( 'wdkit_rollback_version_' . WDKIT_VERSION, $versions_list, WEEK_IN_SECONDS );
5600 -
5601 - return $versions_list;
5602 - }
5603 -
5604 - /**
5605 - * Rollback to Previous Versions
5606 - *
5607 - * @since 1.1.0
5608 - */
5609 - protected function wdkit_rollback_check() {
5610 -
5611 - $current_ver = isset( $_POST['version'] ) ? sanitize_text_field( wp_unslash( $_POST['version'] ) ) : '';
5612 - $rv = $this->wdkit_prev_version();
5613 -
5614 - if ( empty( $current_ver ) || ! in_array( $current_ver, $rv ) ) {
5615 - return array(
5616 - 'message' => esc_html__( 'Invalid Nonce or version not found', 'wdesignkit' ),
5617 - 'status' => 'error',
5618 - 'success' => false,
5619 - );
5620 - }
5621 -
5622 - $plugin_slug = basename( WDKIT_PBNAME, '.php' );
5623 -
5624 - $this_version = $current_ver;
5625 - $this_pluginname = WDKIT_PBNAME;
5626 - $this_plugin_u_r_l = sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $this_version );
5627 -
5628 - $plugin_info = new \stdClass();
5629 - $plugin_info->new_version = $this_version;
5630 - $plugin_info->slug = $plugin_slug;
5631 - $plugin_info->package = $this_plugin_u_r_l;
5632 - $plugin_info->url = 'https://wdesignkit.com/';
5633 -
5634 - $update_plugins_data = get_site_transient( 'update_plugins' );
5635 -
5636 - if ( ! is_object( $update_plugins_data ) ) {
5637 - $update_plugins_data = new \stdClass();
5638 - }
5639 -
5640 - $update_plugins_data->response[ $this_pluginname ] = $plugin_info;
5641 -
5642 - set_site_transient( 'update_plugins', $update_plugins_data );
5643 -
5644 - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
5645 -
5646 - $logo_url = WDKIT_URL . 'assets/images/jpg/Wdesignkit-logo.png';
5647 -
5648 - $args = array(
5649 - 'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this_pluginname ),
5650 - 'plugin' => $this_pluginname,
5651 - 'nonce' => 'upgrade-plugin_' . $this_pluginname,
5652 - 'title' => '<img src="' . esc_url( $logo_url ) . '" alt="wdesignkit-logo"><div class="theplus-rb-subtitle">' . esc_html__( 'Rollback to Previous Version', 'wdesignkit' ) . '</div>',
5653 - );
5654 -
5655 - $upgrader_plugin = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $args ) );
5656 - $upgrader_plugin->upgrade( $this_pluginname );
5657 -
5658 - activate_plugin( $this_pluginname );
5659 -
5660 - return array(
5661 - 'message' => esc_html__( 'Rollback Successful, Plugin Re-activated', 'wdesignkit' ),
5662 - 'status' => 'Success',
5663 - 'success' => true,
5664 - );
5665 - }
5666 -
5667 - /**
5668 - *
5669 3016 * It is Use for logout.
5670 3017 *
5671 3018 * @since 1.0.0
5672 3019 */
@@ -5681,10 +3028,8 @@
5681 3028 $args = array( 'token' => $token );
5682 3029
5683 3030 if ( 'session' !== $logout_type ) {
5684 3031 delete_transient( 'wdkit_auth_' . $email );
5685 - // Clear stored license data on logout so banner shows again
5686 - delete_option( 'wdkit_licence_data' );
5687 3032 $response = WDesignKit_Data_Query::get_data( 'logout', $args );
5688 3033 }
5689 3034 }
5690 3035
@@ -5731,9 +3076,24 @@
5731 3076 return $data[ $type ];
5732 3077 }
5733 3078 }
5734 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' ) {
5735 3090
3091 + if ( 'name' === $condition ) {
3092 + return wp_normalize_path( $data[ $type ]['tmp_name'] );
3093 + }
3094 + }
3095 +
5736 3096 /**
5737 3097 * Parse args $_POST
5738 3098 *
5739 3099 * @since 1.0.0
@@ -5809,28 +3169,8 @@
5809 3169 if ( isset( $data['plugin'] ) ) {
5810 3170 $args['plugin'] = isset( $data['plugin'] ) ? wp_unslash( $data['plugin'] ) : array();
5811 3171 }
5812 3172
5813 - if ( isset( $data['plugin_exclude'] ) ) {
5814 - $args['plugin_exclude'] = isset( $data['plugin_exclude'] ) ? wp_unslash( $data['plugin_exclude'] ) : array();
5815 - }
5816 -
5817 - if ( isset( $data['ai_compatibility'] ) ) {
5818 - $args['ai_compatibility'] = isset( $data['ai_compatibility'] ) ? wp_unslash( $data['ai_compatibility'] ) : array();
5819 - }
5820 -
5821 - // if ( isset( $data['global_color'] ) ) {
5822 - // $args['global_color'] = isset( $data['global_color'] ) ? wp_unslash( $data['global_color'] ) : array();
5823 - // }
5824 -
5825 - // if ( isset( $data['global_font_family'] ) ) {
5826 - // $args['global_font_family'] = isset( $data['global_font_family'] ) ? wp_unslash( $data['global_font_family'] ) : array();
5827 - // }
5828 -
5829 - if ( isset( $data['global_data'] ) ) {
5830 - $args['global_data'] = isset( $data['global_data'] ) ? wp_unslash( $data['global_data'] ) : array();
5831 - }
5832 -
5833 3173 if ( isset( $data['tag'] ) ) {
5834 3174 $args['tag'] = isset( $data['tag'] ) ? wp_unslash( $data['tag'] ) : array();
5835 3175 }
5836 3176
@@ -5859,34 +3199,8 @@
5859 3199 }
5860 3200
5861 3201 return $args;
5862 3202 }
5863 -
5864 - /**
5865 - * Dark Mode
5866 - *
5867 - * @since 2.0.0
5868 - *
5869 - * @param string store darkmode value in database.
5870 - */
5871 - protected function wdkit_dark_mode() {
5872 - $dark_mode = ! empty( $_POST['dark_mode'] ) ? sanitize_text_field( $_POST['dark_mode'] ) : 'light';
5873 -
5874 - if ( get_option( 'wdkit_dark_mode' ) ) {
5875 - update_option( 'wdkit_dark_mode', $dark_mode );
5876 - } else {
5877 - add_option( 'wdkit_dark_mode', $dark_mode );
5878 - }
5879 -
5880 - $response = array(
5881 - 'message' => esc_html__( 'Dark Mode Updated', 'wdesignkit' ),
5882 - 'status' => 'Success',
5883 - 'success' => true,
5884 - );
5885 -
5886 - wp_send_json( $response );
5887 - wp_die();
5888 - }
5889 3203 }
5890 3204
5891 3205 Wdkit_Api_Call::get_instance();
5892 -}
3206 +}