| @@ -80,17 +80,8 @@ | ||
| 80 | 80 | if ( ! empty( $args['with_page_settings'] ) ) { |
| 81 | 81 | $data['page_settings'] = $decoded_data['page_settings']; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $snapshots = apply_filters( | |
| 85 | - 'elementor/template_library/get_data/extract_snapshots', | |
| 86 | - [], | |
| 87 | - $decoded_data, | |
| 88 | - $data | |
| 89 | - ); | |
| 90 | - | |
| 91 | - static::attach_global_styles_to_data_static( $data, $snapshots ); | |
| 92 | - | |
| 93 | 84 | // After the upload complete, set the elementor upload state back to false |
| 94 | 85 | Plugin::$instance->uploads_manager->set_elementor_upload_state( false ); |
| 95 | 86 | |
| 96 | 87 | return $data; |
| @@ -110,23 +101,17 @@ | ||
| 110 | 101 | return (int) $response['id']; |
| 111 | 102 | } |
| 112 | 103 | |
| 113 | 104 | private function format_resource_item_for_create( $template_data ) { |
| 114 | - $content_payload = [ | |
| 115 | - 'content' => $template_data['content'], | |
| 116 | - 'page_settings' => $template_data['page_settings'], | |
| 117 | - ]; | |
| 118 | - | |
| 119 | - if ( is_array( $template_data['content'] ?? null ) ) { | |
| 120 | - $this->attach_global_styles_to_data( $content_payload, $template_data['content'], 0 ); | |
| 121 | - } | |
| 122 | - | |
| 123 | 105 | return [ |
| 124 | 106 | 'title' => $template_data['title'] ?? esc_html__( '(no title)', 'elementor' ), |
| 125 | 107 | 'type' => self::TEMPLATE_RESOURCE_TYPE, |
| 126 | 108 | 'templateType' => $template_data['type'], |
| 127 | 109 | 'parentId' => ! empty( $template_data['parentId'] ) ? (int) $template_data['parentId'] : null, |
| 128 | - 'content' => wp_json_encode( $content_payload ), | |
| 110 | + 'content' => wp_json_encode( [ | |
| 111 | + 'content' => $template_data['content'], | |
| 112 | + 'page_settings' => $template_data['page_settings'], | |
| 113 | + ] ), | |
| 129 | 114 | 'hasPageSettings' => ! empty( $template_data['page_settings'] ), |
| 130 | 115 | ]; |
| 131 | 116 | } |
| 132 | 117 | |
| @@ -156,9 +141,9 @@ | ||
| 156 | 141 | public function export_template( $id ) { |
| 157 | 142 | $data = $this->get_app()->get_resource( [ 'id' => $id ] ); |
| 158 | 143 | |
| 159 | 144 | if ( is_wp_error( $data ) ) { |
| 160 | - return new \WP_Error( 'export_template_error', 'An error has occurred' ); | |
| 145 | + return new \WP_Error( 'export_template_error', 'An error has occured' ); | |
| 161 | 146 | } |
| 162 | 147 | |
| 163 | 148 | if ( static::TEMPLATE_RESOURCE_TYPE === $data['type'] ) { |
| 164 | 149 | $this->handle_export_file( $data ); |
| @@ -211,18 +196,8 @@ | ||
| 211 | 196 | 'title' => $data['title'], |
| 212 | 197 | 'type' => $data['templateType'], |
| 213 | 198 | ]; |
| 214 | 199 | |
| 215 | - $this->attach_global_styles_to_data( | |
| 216 | - $export_data, | |
| 217 | - $export_data['content'], | |
| 218 | - (int) ( $data['id'] ?? 0 ), | |
| 219 | - [ | |
| 220 | - 'global_classes' => $data['content']['global_classes'] ?? null, | |
| 221 | - 'global_variables' => $data['content']['global_variables'] ?? null, | |
| 222 | - ] | |
| 223 | - ); | |
| 224 | - | |
| 225 | 200 | return [ |
| 226 | 201 | 'name' => 'elementor-' . $data['id'] . '-' . gmdate( 'Y-m-d' ) . '.json', |
| 227 | 202 | 'content' => wp_json_encode( $export_data ), |
| 228 | 203 | ]; |
| @@ -322,9 +297,9 @@ | ||
| 322 | 297 | |
| 323 | 298 | /** |
| 324 | 299 | * @param int $template_id |
| 325 | 300 | * @return Document|\WP_Error |
| 326 | - * @throws \Exception If the user has no permission or the post is not found. | |
| 301 | + * @throws \Exception | |
| 327 | 302 | */ |
| 328 | 303 | public function create_document_for_preview( int $template_id ) { |
| 329 | 304 | if ( ! current_user_can( 'edit_posts' ) ) { |
| 330 | 305 | return new \WP_Error( Exceptions::FORBIDDEN, esc_html__( 'You do not have permission to create preview documents.', 'elementor' ) ); |
| @@ -406,9 +381,9 @@ | ||
| 406 | 381 | public function get_quota() { |
| 407 | 382 | return $this->get_app()->get_quota(); |
| 408 | 383 | } |
| 409 | 384 | |
| 410 | - public function import_template( $name, $path, $import_mode = 'match_site' ) { | |
| 385 | + public function import_template( $name, $path ) { | |
| 411 | 386 | if ( empty( $path ) ) { |
| 412 | 387 | return new \WP_Error( 'file_error', 'Please upload a file to import' ); |
| 413 | 388 | } |
| 414 | 389 | |
| @@ -437,18 +412,14 @@ | ||
| 437 | 412 | |
| 438 | 413 | $items_to_save = []; |
| 439 | 414 | |
| 440 | 415 | foreach ( $extracted_files['files'] as $file_path ) { |
| 441 | - // Skip macOS metadata files and folders | |
| 442 | - if ( false !== strpos( $file_path, '__MACOSX' ) || '.' === basename( $file_path )[0] ) { | |
| 443 | - continue; | |
| 444 | - } | |
| 416 | + $prepared = $this->prepare_import_template_data( $file_path ); | |
| 445 | 417 | |
| 446 | - $prepared = $this->prepare_import_template_data( $file_path, $import_mode ); | |
| 418 | + if ( is_wp_error( $prepared ) ) { | |
| 419 | + Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] ); | |
| 447 | 420 | |
| 448 | - if ( is_wp_error( $prepared ) ) { | |
| 449 | - // Skip failed templates | |
| 450 | - continue; | |
| 421 | + return $prepared; | |
| 451 | 422 | } |
| 452 | 423 | |
| 453 | 424 | $items_to_save[] = $this->format_resource_item_for_create( $prepared ); |
| 454 | 425 | } |
| @@ -466,9 +437,9 @@ | ||
| 466 | 437 | $items = $this->get_app()->post_bulk_resources( $items_to_save ); |
| 467 | 438 | |
| 468 | 439 | Plugin::$instance->uploads_manager->remove_file_or_dir( $extracted_files['extraction_directory'] ); |
| 469 | 440 | } else { |
| 470 | - $prepared = $this->prepare_import_template_data( $path, $import_mode ); | |
| 441 | + $prepared = $this->prepare_import_template_data( $path ); | |
| 471 | 442 | |
| 472 | 443 | if ( is_wp_error( $prepared ) ) { |
| 473 | 444 | return $prepared; |
| 474 | 445 | } |
| @@ -502,41 +473,6 @@ | ||
| 502 | 473 | return $quota; |
| 503 | 474 | } |
| 504 | 475 | |
| 505 | 476 | return $quota['currentUsage'] + count( $items ) <= $quota['threshold']; |
| 506 | - } | |
| 507 | - | |
| 508 | - public function format_args_for_bulk_action( $args ) { | |
| 509 | - $templates = $this->get_bulk_items( $args ); | |
| 510 | - $bulk_args = []; | |
| 511 | - | |
| 512 | - foreach ( $templates as $template ) { | |
| 513 | - $content = json_decode( $template['content'], true ); | |
| 514 | - | |
| 515 | - $bulk_args[] = array_merge( | |
| 516 | - $args, | |
| 517 | - [ | |
| 518 | - 'title' => $template['title'], | |
| 519 | - 'type' => $template['type'], | |
| 520 | - 'content' => $content['content'], | |
| 521 | - 'page_settings' => $content['page_settings'], | |
| 522 | - ] | |
| 523 | - ); | |
| 524 | - } | |
| 525 | - | |
| 526 | - return $bulk_args; | |
| 527 | - } | |
| 528 | - | |
| 529 | - public function format_args_for_single_action( $args ) { | |
| 530 | - $data = $this->get_item( $args['from_template_id'] ); | |
| 531 | - | |
| 532 | - if ( is_wp_error( $data ) || empty( $data['content'] ) ) { | |
| 533 | - return new \WP_Error( 'template_error', 'Unable to format template args.' ); | |
| 534 | - } | |
| 535 | - | |
| 536 | - $decoded_data = json_decode( $data['content'], true ); | |
| 537 | - $args['content'] = $decoded_data['content']; | |
| 538 | - $args['page_settings'] = $decoded_data['page_settings']; | |
| 539 | - | |
| 540 | - return $args; | |
| 541 | 477 | } |
| 542 | 478 | } |