| @@ -458,22 +458,19 @@ | ||
| 458 | 458 | * |
| 459 | 459 | * @return mixed Whether the export succeeded or failed. |
| 460 | 460 | */ |
| 461 | 461 | public function import_template( array $data ) { |
| 462 | - /** @var Source_Local $source */ | |
| 463 | - $file_content = base64_decode( $data['fileData'] ); | |
| 462 | + // Imported templates can be either JSON files, or Zip files containing multiple JSON files | |
| 463 | + $upload_result = Plugin::$instance->uploads_manager->handle_elementor_upload( $data, [ 'zip', 'json' ] ); | |
| 464 | 464 | |
| 465 | - $tmp_file = tmpfile(); | |
| 465 | + if ( is_wp_error( $upload_result ) ) { | |
| 466 | + return $upload_result; | |
| 467 | + } | |
| 466 | 468 | |
| 467 | - fwrite( $tmp_file, $file_content ); | |
| 469 | + /** @var Source_Local $source_local */ | |
| 470 | + $source_local = $this->get_source( 'local' ); | |
| 468 | 471 | |
| 469 | - $source = $this->get_source( 'local' ); | |
| 470 | - | |
| 471 | - $result = $source->import_template( $data['fileName'], stream_get_meta_data( $tmp_file )['uri'] ); | |
| 472 | - | |
| 473 | - fclose( $tmp_file ); | |
| 474 | - | |
| 475 | - return $result; | |
| 472 | + return $source_local->import_template( $upload_result['name'], $upload_result['tmp_name'] ); | |
| 476 | 473 | } |
| 477 | 474 | |
| 478 | 475 | /** |
| 479 | 476 | * Mark template as favorite. |