PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.3
Elementor Website Builder – more than just a page builder v3.34.3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | includes/template-library/manager.php +11 -96 4.0.73.34.3 View file →
@@ -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
@@ -681,92 +681,8 @@
681 681
682 682 return $import_data['content'];
683 683 }
684 684
685 - public function process_global_styles( array $args ) {
686 - $validate_args = $this->ensure_args( [ 'content', 'import_mode' ], $args );
687 -
688 - if ( is_wp_error( $validate_args ) ) {
689 - return $validate_args;
690 - }
691 -
692 - $import_mode = Template_Library_Import_Export_Utils::sanitize_import_mode( $args['import_mode'] );
693 -
694 - $content = $this->get_validated_json_arg( $args, 'content' );
695 - if ( is_wp_error( $content ) ) {
696 - return $content;
697 - }
698 -
699 - $global_classes = $this->get_validated_json_arg( $args, 'global_classes', true );
700 - if ( is_wp_error( $global_classes ) ) {
701 - return $global_classes;
702 - }
703 -
704 - $global_variables = $this->get_validated_json_arg( $args, 'global_variables', true );
705 - if ( is_wp_error( $global_variables ) ) {
706 - return $global_variables;
707 - }
708 -
709 - $data = [
710 - 'global_classes' => $global_classes,
711 - 'global_variables' => $global_variables,
712 - ];
713 -
714 - $result = apply_filters(
715 - 'elementor/template_library/import/process_content',
716 - [ 'content' => $content ],
717 - $import_mode,
718 - $data,
719 - null
720 - );
721 -
722 - $response = [
723 - 'content' => $result['content'],
724 - ];
725 -
726 - if ( ! empty( $result['updated_global_classes'] ) ) {
727 - $response['updated_global_classes'] = $result['updated_global_classes'];
728 - }
729 -
730 - if ( ! empty( $result['updated_global_variables'] ) ) {
731 - $response['updated_global_variables'] = $result['updated_global_variables'];
732 - }
733 -
734 - $classes_to_flatten = $result['classes_to_flatten'] ?? [];
735 - $variables_to_flatten = $result['variables_to_flatten'] ?? [];
736 -
737 - if ( ! empty( $classes_to_flatten ) ) {
738 - $response['flattened_classes_count'] = count( $classes_to_flatten );
739 - }
740 -
741 - if ( ! empty( $variables_to_flatten ) ) {
742 - $response['flattened_variables_count'] = count( $variables_to_flatten );
743 - }
744 -
745 - return $response;
746 - }
747 -
748 - private function get_validated_json_arg( array $args, string $key, bool $is_optional = false ) {
749 - if ( ! array_key_exists( $key, $args ) || null === $args[ $key ] || '' === $args[ $key ] ) {
750 - return $is_optional ? null : new \WP_Error( "invalid_$key", "Invalid $key." );
751 - }
752 -
753 - $value = $args[ $key ];
754 - if ( is_string( $value ) ) {
755 - $decoded = json_decode( $value, true );
756 - if ( JSON_ERROR_NONE !== json_last_error() ) {
757 - return new \WP_Error( "invalid_$key", "Invalid JSON $key." );
758 - }
759 - return $decoded;
760 - }
761 -
762 - if ( ! is_array( $value ) ) {
763 - return new \WP_Error( "invalid_$key", "Invalid $key format." );
764 - }
765 -
766 - return $value;
767 - }
768 -
769 685 public function get_item_children( array $args ) {
770 686 $validate_args = $this->ensure_args( [ 'source', 'template_id' ], $args );
771 687
772 688 if ( is_wp_error( $validate_args ) ) {
@@ -1013,9 +929,8 @@
1013 929 'bulk_copy_templates',
1014 930 'bulk_undo_delete_items',
1015 931 'get_templates_quota',
1016 932 'template_screenshot_failed',
1017 - 'process_global_styles',
1018 933 ];
1019 934
1020 935 foreach ( $library_ajax_requests as $ajax_request ) {
1021 936 $ajax->register_ajax_action( $ajax_request, function( $data ) use ( $ajax_request ) {
@@ -1148,15 +1063,15 @@
1148 1063
1149 1064 $bulk_args = $from_source->format_args_for_bulk_action( $args );
1150 1065
1151 1066 if ( $source->supports_quota() && ! $this->is_action_to_same_source( $args ) ) {
1152 - $quota_validation = $source->validate_quota( $bulk_args );
1067 + $is_quota_valid = $source->validate_quota( $bulk_args );
1153 1068
1154 - if ( is_wp_error( $quota_validation ) ) {
1155 - return $quota_validation;
1069 + if ( is_wp_error( $is_quota_valid ) ) {
1070 + return $is_quota_valid;
1156 1071 }
1157 1072
1158 - if ( false === $quota_validation ) {
1073 + if ( ! $is_quota_valid ) {
1159 1074 return new \WP_Error( 'quota_error', 'The moving failed because it will pass the maximum templates you can save.' );
1160 1075 }
1161 1076 }
1162 1077
@@ -1199,15 +1114,15 @@
1199 1114
1200 1115 $bulk_args = $from_source->format_args_for_bulk_action( $args );
1201 1116
1202 1117 if ( $source->supports_quota() && ! $this->is_action_to_same_source( $args ) ) {
1203 - $quota_validation = $source->validate_quota( $bulk_args );
1118 + $is_quota_valid = $source->validate_quota( $bulk_args );
1204 1119
1205 - if ( is_wp_error( $quota_validation ) ) {
1206 - return $quota_validation;
1120 + if ( is_wp_error( $is_quota_valid ) ) {
1121 + return $is_quota_valid;
1207 1122 }
1208 1123
1209 - if ( false === $quota_validation ) {
1124 + if ( ! $is_quota_valid ) {
1210 1125 return new \WP_Error( 'quota_error', 'The copying failed because it will pass the maximum templates you can save.' );
1211 1126 }
1212 1127 }
1213 1128