| @@ -26,9 +26,8 @@ | ||
| 26 | 26 | class Manager { |
| 27 | 27 | |
| 28 | 28 | const ERROR_TEMPLATE_SOURCE_NOT_FOUND = 'Template source not found.'; |
| 29 | 29 | const ERROR_TEMPLATE_IDS_MISSING = 'Template IDs are missing.'; |
| 30 | - const ERROR_JSON_UPLOAD_NOT_ALLOWED = 'Uploading JSON files is not allowed for this user.'; | |
| 31 | 30 | |
| 32 | 31 | /** |
| 33 | 32 | * Registered template sources. |
| 34 | 33 | * |
| @@ -600,12 +599,8 @@ | ||
| 600 | 599 | * |
| 601 | 600 | * @return mixed Whether the export succeeded or failed. |
| 602 | 601 | */ |
| 603 | 602 | public function import_template( array $data ) { |
| 604 | - if ( ! User::is_current_user_can_upload_json() ) { | |
| 605 | - return new \WP_Error( 'template_error', self::ERROR_JSON_UPLOAD_NOT_ALLOWED ); | |
| 606 | - } | |
| 607 | - | |
| 608 | 603 | // If the template is a JSON file, allow uploading it. |
| 609 | 604 | add_filter( 'elementor/files/allow-file-type/json', [ $this, 'enable_json_template_upload' ] ); |
| 610 | 605 | add_filter( 'elementor/files/allow_unfiltered_upload', [ $this, 'enable_json_template_upload' ] ); |
| 611 | 606 | |
| @@ -615,8 +610,10 @@ | ||
| 615 | 610 | remove_filter( 'elementor/files/allow-file-type/json', [ $this, 'enable_json_template_upload' ] ); |
| 616 | 611 | remove_filter( 'elementor/files/allow_unfiltered_upload', [ $this, 'enable_json_template_upload' ] ); |
| 617 | 612 | |
| 618 | 613 | if ( is_wp_error( $upload_result ) ) { |
| 614 | + Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $upload_result['tmp_name'] ) ); | |
| 615 | + | |
| 619 | 616 | return $upload_result; |
| 620 | 617 | } |
| 621 | 618 | |
| 622 | 619 | $source = $this->get_source( $data['source'] ?? 'local' ); |
| @@ -683,17 +680,9 @@ | ||
| 683 | 680 | } |
| 684 | 681 | |
| 685 | 682 | $import_data = $document->get_import_data( [ 'content' => $elements ] ); |
| 686 | 683 | |
| 687 | - $content = $document::on_import_update_dynamic_content( | |
| 688 | - $import_data['content'], | |
| 689 | - [ 'post_ids' => [] ] | |
| 690 | - ); | |
| 691 | - | |
| 692 | - return Plugin::$instance->db->iterate_data( $content, function( $element_data ) { | |
| 693 | - unset( $element_data['htmlCache'] ); | |
| 694 | - return $element_data; | |
| 695 | - } ); | |
| 684 | + return $import_data['content']; | |
| 696 | 685 | } |
| 697 | 686 | |
| 698 | 687 | public function process_global_styles( array $args ) { |
| 699 | 688 | $validate_args = $this->ensure_args( [ 'content', 'import_mode' ], $args ); |
| @@ -901,12 +890,8 @@ | ||
| 901 | 890 | * @throws \Exception If current user has no permission or the post is not found. |
| 902 | 891 | */ |
| 903 | 892 | private function handle_ajax_request( $ajax_request, array $data ) { |
| 904 | 893 | if ( ! User::is_current_user_can_edit_post_type( Source_Local::CPT ) ) { |
| 905 | - throw new \Exception( 'Access denied.' ); | |
| 906 | - } | |
| 907 | - | |
| 908 | - if ( 'import_template' === $ajax_request && ! User::is_current_user_can_upload_json() ) { | |
| 909 | 894 | throw new \Exception( 'Access denied.' ); |
| 910 | 895 | } |
| 911 | 896 | |
| 912 | 897 | if ( ! empty( $data['editor_post_id'] ) ) { |