| @@ -5,9 +5,8 @@ | ||
| 5 | 5 | use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 6 | 6 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 7 | 7 | use Elementor\Includes\TemplateLibrary\Data\Controller; |
| 8 | 8 | use Elementor\TemplateLibrary\Classes\Import_Images; |
| 9 | -use Elementor\Core\Utils\Template_Library_Import_Export_Utils; | |
| 10 | 9 | use Elementor\Plugin; |
| 11 | 10 | use Elementor\User; |
| 12 | 11 | use Elementor\Utils; |
| 13 | 12 | |
| @@ -610,15 +609,16 @@ | ||
| 610 | 609 | remove_filter( 'elementor/files/allow-file-type/json', [ $this, 'enable_json_template_upload' ] ); |
| 611 | 610 | remove_filter( 'elementor/files/allow_unfiltered_upload', [ $this, 'enable_json_template_upload' ] ); |
| 612 | 611 | |
| 613 | 612 | if ( is_wp_error( $upload_result ) ) { |
| 613 | + Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $upload_result['tmp_name'] ) ); | |
| 614 | + | |
| 614 | 615 | return $upload_result; |
| 615 | 616 | } |
| 616 | 617 | |
| 617 | 618 | $source = $this->get_source( $data['source'] ?? 'local' ); |
| 618 | 619 | |
| 619 | - $import_mode = $data['import_mode'] ?? 'match_site'; | |
| 620 | - $import_result = $source->import_template( $upload_result['name'], $upload_result['tmp_name'], $import_mode ); | |
| 620 | + $import_result = $source->import_template( $upload_result['name'], $upload_result['tmp_name'] ); | |
| 621 | 621 | |
| 622 | 622 | // Remove the temporary directory generated for the stream-uploaded file. |
| 623 | 623 | Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $upload_result['tmp_name'] ) ); |
| 624 | 624 | |
| @@ -678,103 +678,11 @@ | ||
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | $import_data = $document->get_import_data( [ 'content' => $elements ] ); |
| 681 | 681 | |
| 682 | - $content = $document::on_import_update_dynamic_content( | |
| 683 | - $import_data['content'], | |
| 684 | - [ 'post_ids' => [] ] | |
| 685 | - ); | |
| 686 | - | |
| 687 | - return Plugin::$instance->db->iterate_data( $content, function( $element_data ) { | |
| 688 | - unset( $element_data['htmlCache'] ); | |
| 689 | - return $element_data; | |
| 690 | - } ); | |
| 682 | + return $import_data['content']; | |
| 691 | 683 | } |
| 692 | 684 | |
| 693 | - public function process_global_styles( array $args ) { | |
| 694 | - $validate_args = $this->ensure_args( [ 'content', 'import_mode' ], $args ); | |
| 695 | - | |
| 696 | - if ( is_wp_error( $validate_args ) ) { | |
| 697 | - return $validate_args; | |
| 698 | - } | |
| 699 | - | |
| 700 | - $import_mode = Template_Library_Import_Export_Utils::sanitize_import_mode( $args['import_mode'] ); | |
| 701 | - | |
| 702 | - $content = $this->get_validated_json_arg( $args, 'content' ); | |
| 703 | - if ( is_wp_error( $content ) ) { | |
| 704 | - return $content; | |
| 705 | - } | |
| 706 | - | |
| 707 | - $global_classes = $this->get_validated_json_arg( $args, 'global_classes', true ); | |
| 708 | - if ( is_wp_error( $global_classes ) ) { | |
| 709 | - return $global_classes; | |
| 710 | - } | |
| 711 | - | |
| 712 | - $global_variables = $this->get_validated_json_arg( $args, 'global_variables', true ); | |
| 713 | - if ( is_wp_error( $global_variables ) ) { | |
| 714 | - return $global_variables; | |
| 715 | - } | |
| 716 | - | |
| 717 | - $data = [ | |
| 718 | - 'global_classes' => $global_classes, | |
| 719 | - 'global_variables' => $global_variables, | |
| 720 | - ]; | |
| 721 | - | |
| 722 | - $result = apply_filters( | |
| 723 | - 'elementor/template_library/import/process_content', | |
| 724 | - [ 'content' => $content ], | |
| 725 | - $import_mode, | |
| 726 | - $data, | |
| 727 | - null | |
| 728 | - ); | |
| 729 | - | |
| 730 | - $response = [ | |
| 731 | - 'content' => $result['content'], | |
| 732 | - ]; | |
| 733 | - | |
| 734 | - if ( ! empty( $result['updated_global_classes'] ) ) { | |
| 735 | - $response['updated_global_classes'] = $result['updated_global_classes']; | |
| 736 | - } | |
| 737 | - | |
| 738 | - if ( ! empty( $result['updated_global_variables'] ) ) { | |
| 739 | - $response['updated_global_variables'] = $result['updated_global_variables']; | |
| 740 | - } | |
| 741 | - | |
| 742 | - $classes_to_flatten = $result['classes_to_flatten'] ?? []; | |
| 743 | - $variables_to_flatten = $result['variables_to_flatten'] ?? []; | |
| 744 | - | |
| 745 | - if ( ! empty( $classes_to_flatten ) ) { | |
| 746 | - $response['flattened_classes_count'] = count( $classes_to_flatten ); | |
| 747 | - } | |
| 748 | - | |
| 749 | - if ( ! empty( $variables_to_flatten ) ) { | |
| 750 | - $response['flattened_variables_count'] = count( $variables_to_flatten ); | |
| 751 | - } | |
| 752 | - | |
| 753 | - return $response; | |
| 754 | - } | |
| 755 | - | |
| 756 | - private function get_validated_json_arg( array $args, string $key, bool $is_optional = false ) { | |
| 757 | - if ( ! array_key_exists( $key, $args ) || null === $args[ $key ] || '' === $args[ $key ] ) { | |
| 758 | - return $is_optional ? null : new \WP_Error( "invalid_$key", "Invalid $key." ); | |
| 759 | - } | |
| 760 | - | |
| 761 | - $value = $args[ $key ]; | |
| 762 | - if ( is_string( $value ) ) { | |
| 763 | - $decoded = json_decode( $value, true ); | |
| 764 | - if ( JSON_ERROR_NONE !== json_last_error() ) { | |
| 765 | - return new \WP_Error( "invalid_$key", "Invalid JSON $key." ); | |
| 766 | - } | |
| 767 | - return $decoded; | |
| 768 | - } | |
| 769 | - | |
| 770 | - if ( ! is_array( $value ) ) { | |
| 771 | - return new \WP_Error( "invalid_$key", "Invalid $key format." ); | |
| 772 | - } | |
| 773 | - | |
| 774 | - return $value; | |
| 775 | - } | |
| 776 | - | |
| 777 | 685 | public function get_item_children( array $args ) { |
| 778 | 686 | $validate_args = $this->ensure_args( [ 'source', 'template_id' ], $args ); |
| 779 | 687 | |
| 780 | 688 | if ( is_wp_error( $validate_args ) ) { |
| @@ -1021,9 +929,8 @@ | ||
| 1021 | 929 | 'bulk_copy_templates', |
| 1022 | 930 | 'bulk_undo_delete_items', |
| 1023 | 931 | 'get_templates_quota', |
| 1024 | 932 | 'template_screenshot_failed', |
| 1025 | - 'process_global_styles', | |
| 1026 | 933 | ]; |
| 1027 | 934 | |
| 1028 | 935 | foreach ( $library_ajax_requests as $ajax_request ) { |
| 1029 | 936 | $ajax->register_ajax_action( $ajax_request, function( $data ) use ( $ajax_request ) { |
| @@ -1156,15 +1063,15 @@ | ||
| 1156 | 1063 | |
| 1157 | 1064 | $bulk_args = $from_source->format_args_for_bulk_action( $args ); |
| 1158 | 1065 | |
| 1159 | 1066 | if ( $source->supports_quota() && ! $this->is_action_to_same_source( $args ) ) { |
| 1160 | - $quota_validation = $source->validate_quota( $bulk_args ); | |
| 1067 | + $is_quota_valid = $source->validate_quota( $bulk_args ); | |
| 1161 | 1068 | |
| 1162 | - if ( is_wp_error( $quota_validation ) ) { | |
| 1163 | - return $quota_validation; | |
| 1069 | + if ( is_wp_error( $is_quota_valid ) ) { | |
| 1070 | + return $is_quota_valid; | |
| 1164 | 1071 | } |
| 1165 | 1072 | |
| 1166 | - if ( false === $quota_validation ) { | |
| 1073 | + if ( ! $is_quota_valid ) { | |
| 1167 | 1074 | return new \WP_Error( 'quota_error', 'The moving failed because it will pass the maximum templates you can save.' ); |
| 1168 | 1075 | } |
| 1169 | 1076 | } |
| 1170 | 1077 | |
| @@ -1207,15 +1114,15 @@ | ||
| 1207 | 1114 | |
| 1208 | 1115 | $bulk_args = $from_source->format_args_for_bulk_action( $args ); |
| 1209 | 1116 | |
| 1210 | 1117 | if ( $source->supports_quota() && ! $this->is_action_to_same_source( $args ) ) { |
| 1211 | - $quota_validation = $source->validate_quota( $bulk_args ); | |
| 1118 | + $is_quota_valid = $source->validate_quota( $bulk_args ); | |
| 1212 | 1119 | |
| 1213 | - if ( is_wp_error( $quota_validation ) ) { | |
| 1214 | - return $quota_validation; | |
| 1120 | + if ( is_wp_error( $is_quota_valid ) ) { | |
| 1121 | + return $is_quota_valid; | |
| 1215 | 1122 | } |
| 1216 | 1123 | |
| 1217 | - if ( false === $quota_validation ) { | |
| 1124 | + if ( ! $is_quota_valid ) { | |
| 1218 | 1125 | return new \WP_Error( 'quota_error', 'The copying failed because it will pass the maximum templates you can save.' ); |
| 1219 | 1126 | } |
| 1220 | 1127 | } |
| 1221 | 1128 | |