@@ -448,13 +448,86 @@ public function parse_ajax() {
448
448
// Export scheme file.
449
449
} elseif ( 'export ' === $ _REQUEST ['type ' ] ) {
450
450
$ this ->download_schemes ();
451
+
452
+ // Import scheme file.
453
+ } elseif ( 'import ' === $ _REQUEST ['type ' ] ) {
454
+ $ this ->import_schemes ();
451
455
}
452
456
}
453
457
} else {
454
458
wp_die ( esc_html__ ( 'Invalid Security Credentials. Please reload the page and try again. ' , 'redux-framework ' ) );
455
459
}
456
460
}
457
461
462
+ /**
463
+ * Download Scheme File.
464
+ *
465
+ * @since 4.4.18
466
+ * @access private
467
+ * @return void
468
+ */
469
+ private function import_schemes () {
470
+ if ( isset ( $ _REQUEST ['content ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
471
+ $ content = wp_unslash ( $ _REQUEST ['content ' ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
472
+ $ content = is_array ( $ content ) ? array_map ( 'stripslashes_deep ' , $ content ) : stripslashes ( $ content );
473
+ $ content = json_decode ( $ content , true );
474
+
475
+ if ( is_null ( $ content ) ) {
476
+ $ result = array (
477
+ 'result ' => false ,
478
+ 'data ' => esc_html__ ( 'Import unsuccessful! Malformed JSON data detected. ' , 'redux-framework ' ),
479
+ );
480
+
481
+ $ result = wp_json_encode ( $ result );
482
+
483
+ echo $ result ; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
484
+
485
+ die;
486
+ }
487
+
488
+ if ( isset ( $ content ['Default ' ]['color_scheme_name ' ] ) ) {
489
+ $ content = wp_json_encode ( $ content );
490
+
491
+ $ param_array = array (
492
+ 'content ' => $ content ,
493
+ 'overwrite ' => true ,
494
+ 'chmod ' => FS_CHMOD_FILE ,
495
+ );
496
+
497
+ $ import_file = Redux_Color_Scheme_Functions::$ upload_dir . Redux_Color_Scheme_Functions::$ parent ->args ['opt_name ' ] . '_ ' . Redux_Color_Scheme_Functions::$ field_id . '.json ' ;
498
+
499
+ if ( true === Redux_Color_Scheme_Functions::$ parent ->filesystem ->execute ( 'put_contents ' , $ import_file , $ param_array ) ) {
500
+ $ result = array (
501
+ 'result ' => true ,
502
+ // translators: %s = HTML content.
503
+ 'data ' => sprintf ( esc_html__ ( 'Import successful! Click %s to refresh. ' , 'redux-framework ' ), '<strong> ' . esc_html__ ( 'OK ' , 'redux-framework ' ) . '</strong> ' ),
504
+ );
505
+ } else {
506
+ $ result = array (
507
+ 'result ' => false ,
508
+ 'data ' => esc_html__ ( 'Import unsuccessful! File permission error: Could not write import data to server. ' , 'redux-framework ' ),
509
+ );
510
+ }
511
+ } else {
512
+ $ result = array (
513
+ 'result ' => false ,
514
+ 'data ' => esc_html__ ( 'Import unsuccessful! The selected file is not a valid color scheme file. ' , 'redux-framework ' ),
515
+ );
516
+ }
517
+ } else {
518
+ $ result = array (
519
+ 'result ' => false ,
520
+ 'data ' => esc_html__ ( 'Import unsuccessful! No data detected in the import file. ' , 'redux-framework ' ),
521
+ );
522
+ }
523
+
524
+ $ result = wp_json_encode ( $ result );
525
+
526
+ echo $ result ; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
527
+
528
+ die;
529
+ }
530
+
458
531
/**
459
532
* Download Scheme File.
460
533
*
0 commit comments