PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.3
Elementor Website Builder – more than just a page builder v3.13.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 | app/modules/import-export/module.php +93 -258 4.2.23.13.3 View file →
@@ -11,12 +11,11 @@
11 11 use Elementor\Plugin;
12 12 use Elementor\Tools;
13 13 use Elementor\Utils as ElementorUtils;
14 14 use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils;
15 -use Elementor\Modules\CloudKitLibrary\Module as CloudKitLibrary;
16 15
17 16 if ( ! defined( 'ABSPATH' ) ) {
18 - exit; // Exit if accessed directly.
17 + exit; // Exit if accessed directly
19 18 }
20 19
21 20 /**
22 21 * Import Export Module
@@ -37,10 +36,8 @@
37 36 const REFERRER_KIT_LIBRARY = 'kit-library';
38 37
39 38 const REFERRER_LOCAL = 'local';
40 39
41 - const REFERRER_CLOUD = 'cloud';
42 -
43 40 const PLUGIN_PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error';
44 41
45 42 const KIT_LIBRARY_ERROR_KEY = 'invalid-kit-library-zip-error';
46 43
@@ -45,12 +42,8 @@
45 42 const KIT_LIBRARY_ERROR_KEY = 'invalid-kit-library-zip-error';
46 43
47 44 const NO_WRITE_PERMISSIONS_KEY = 'no-write-permissions';
48 45
49 - const THIRD_PARTY_ERROR = 'third-party-error';
50 -
51 - const DOMDOCUMENT_MISSING = 'domdocument-missing';
52 -
53 46 const OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS = 'elementor_import_sessions';
54 47
55 48 const OPTION_KEY_ELEMENTOR_REVERT_SESSIONS = 'elementor_revert_sessions';
56 49
@@ -56,11 +49,8 @@
56 49
57 50 const META_KEY_ELEMENTOR_IMPORT_SESSION_ID = '_elementor_import_session_id';
58 51
59 52 const META_KEY_ELEMENTOR_EDIT_MODE = '_elementor_edit_mode';
60 - const IMPORT_PLUGINS_ACTION = 'import-plugins';
61 - const EXPORT_SOURCE_CLOUD = 'cloud';
62 - const EXPORT_SOURCE_FILE = 'file';
63 53
64 54 /**
65 55 * Assigning the export process to a property, so we can use the process from outside the class.
66 56 *
@@ -117,12 +107,12 @@
117 107 * Register the import/export tab in elementor tools.
118 108 */
119 109 public function register_settings_tab( Tools $tools ) {
120 110 $tools->add_tab( 'import-export-kit', [
121 - 'label' => esc_html__( 'Website Templates', 'elementor' ),
111 + 'label' => esc_html__( 'Import / Export Kit', 'elementor' ),
122 112 'sections' => [
123 113 'intro' => [
124 - 'label' => esc_html__( 'Website Templates', 'elementor' ),
114 + 'label' => esc_html__( 'Template Kits', 'elementor' ),
125 115 'callback' => function() {
126 116 $this->render_import_export_tab_content();
127 117 },
128 118 'fields' => [],
@@ -134,39 +124,44 @@
134 124 /**
135 125 * Render the import/export tab content.
136 126 */
137 127 private function render_import_export_tab_content() {
138 - $is_cloud_kits_available = CloudKitLibrary::get_app()->check_eligibility()['is_eligible'];
128 + $intro_text_link = sprintf( '<a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%s</a>', esc_html__( 'Learn more', 'elementor' ) );
139 129
130 + $intro_text = sprintf(
131 + /* translators: 1: New line break, 2: Learn More link. */
132 + __( 'Design sites faster with a template kit that contains some or all components of a complete site, like templates, content & site settings.%1$sYou can import a kit and apply it to your site, or export the elements from this site to be used anywhere else. %2$s', 'elementor' ),
133 + '<br>',
134 + $intro_text_link
135 + );
136 +
140 137 $content_data = [
141 138 'export' => [
142 - 'title' => esc_html__( 'Export this website', 'elementor' ),
139 + 'title' => esc_html__( 'Export a Template Kit', 'elementor' ),
143 140 'button' => [
144 141 'url' => Plugin::$instance->app->get_base_url() . '#/export',
145 - 'text' => esc_html__( 'Export', 'elementor' ),
146 - 'id' => 'elementor-import-export__export',
142 + 'text' => esc_html__( 'Start Export', 'elementor' ),
147 143 ],
148 - 'description' => esc_html__( 'You can download this website as a .zip file, or upload it to the library.', 'elementor' ),
144 + 'description' => esc_html__( 'Bundle your whole site - or just some of its elements - to be used for another website.', 'elementor' ),
145 + 'link' => [
146 + 'url' => 'https://go.elementor.com/wp-dash-import-export-export-flow/',
147 + 'text' => esc_html__( 'Learn More', 'elementor' ),
148 + ],
149 149 ],
150 150 'import' => [
151 - 'title' => esc_html__( 'Import website templates', 'elementor' ),
151 + 'title' => esc_html__( 'Import a Template Kit', 'elementor' ),
152 152 'button' => [
153 153 'url' => Plugin::$instance->app->get_base_url() . '#/import',
154 - 'text' => esc_html__( 'Import', 'elementor' ),
155 - 'id' => 'elementor-import-export__import',
154 + 'text' => esc_html__( 'Start Import', 'elementor' ),
156 155 ],
157 - 'description' => esc_html__( 'You can import design and settings from a .zip file or choose from the library.', 'elementor' ),
156 + 'description' => esc_html__( 'Apply the design and settings of another site to this one.', 'elementor' ),
157 + 'link' => [
158 + 'url' => 'https://go.elementor.com/wp-dash-import-export-import-flow/',
159 + 'text' => esc_html__( 'Learn More', 'elementor' ),
160 + ],
158 161 ],
159 162 ];
160 163
161 - if ( $is_cloud_kits_available ) {
162 - $content_data['import']['button_secondary'] = [
163 - 'url' => Plugin::$instance->app->get_base_url() . '#/kit-library/cloud',
164 - 'text' => esc_html__( 'Import from library', 'elementor' ),
165 - 'id' => 'elementor-import-export__import_from_library',
166 - ];
167 - }
168 -
169 164 $last_imported_kit = $this->revert->get_last_import_session();
170 165 $penultimate_imported_kit = $this->revert->get_penultimate_import_session();
171 166
172 167 $user_date_format = get_option( 'date_format' );
@@ -177,9 +172,8 @@
177 172
178 173 if ( $should_show_revert_section ) {
179 174 if ( ! empty( $penultimate_imported_kit ) ) {
180 175 $revert_text = sprintf(
181 - /* translators: 1: Last imported kit title, 2: Last imported kit date, 3: Line break <br>, 4: Penultimate imported kit title, 5: Penultimate imported kit date. */
182 176 esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s %3$s and revert to the site setting that came with "%4$s" on %5$s.', 'elementor' ),
183 177 ! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ),
184 178 gmdate( $date_format, $last_imported_kit['start_timestamp'] ),
185 179 '<br>',
@@ -187,9 +181,8 @@
187 181 gmdate( $date_format, $penultimate_imported_kit['start_timestamp'] )
188 182 );
189 183 } else {
190 184 $revert_text = sprintf(
191 - /* translators: 1: Last imported kit title, 2: Last imported kit date, 3: Line break <br>. */
192 185 esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s.%3$s Your original site settings will be restored.', 'elementor' ),
193 186 ! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ),
194 187 gmdate( $date_format, $last_imported_kit['start_timestamp'] ),
195 188 '<br>'
@@ -198,22 +191,23 @@
198 191 }
199 192 ?>
200 193
201 194 <div class="tab-import-export-kit__content">
202 - <p class="tab-import-export-kit__info">
203 - <?php
204 - printf(
205 - '%1$s <a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%2$s</a>',
206 - esc_html__( 'Here’s where you can export this website as a .zip file, upload it to the cloud, or start the process of applying an existing template to your site.', 'elementor' ),
207 - esc_html__( 'Learn more', 'elementor' ),
208 - );
209 - ?>
210 - </p>
195 + <p class="tab-import-export-kit__info"><?php ElementorUtils::print_unescaped_internal_string( $intro_text ); ?></p>
211 196
212 197 <div class="tab-import-export-kit__wrapper">
213 - <?php foreach ( $content_data as $data ) {
214 - $this->print_item_content( $data );
215 - } ?>
198 + <?php foreach ( $content_data as $data ) { ?>
199 + <div class="tab-import-export-kit__container">
200 + <div class="tab-import-export-kit__box">
201 + <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2>
202 + <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button e-primary">
203 + <?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?>
204 + </a>
205 + </div>
206 + <p><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p>
207 + <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a>
208 + </div>
209 + <?php } ?>
216 210 </div>
217 211
218 212 <?php
219 213 if ( $should_show_revert_section ) {
@@ -225,9 +219,9 @@
225 219 ];
226 220 ?>
227 221 <div class="tab-import-export-kit__revert">
228 222 <h2>
229 - <?php echo esc_html__( 'Remove the most recent Website Template', 'elementor' ); ?>
223 + <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove the most recent Kit', 'elementor' ) ); ?>
230 224 </h2>
231 225 <p class="tab-import-export-kit__info">
232 226 <?php ElementorUtils::print_unescaped_internal_string( $revert_text ); ?>
233 227 </p>
@@ -232,9 +226,9 @@
232 226 <?php ElementorUtils::print_unescaped_internal_string( $revert_text ); ?>
233 227 </p>
234 228 <?php $this->render_last_kit_thumbnail( $last_imported_kit ); ?>
235 229 <a <?php ElementorUtils::print_html_attributes( $link_attributes ); ?> >
236 - <?php echo esc_html__( 'Remove Website Template', 'elementor' ); ?>
230 + <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove Kit', 'elementor' ) ); ?>
237 231 </a>
238 232 </div>
239 233 <?php } ?>
240 234 </div>
@@ -240,33 +234,8 @@
240 234 </div>
241 235 <?php
242 236 }
243 237
244 - private function print_item_content( $data ) {
245 - ?>
246 - <div class="tab-import-export-kit__container">
247 - <div class="tab-import-export-kit__box">
248 - <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2>
249 - </div>
250 - <p class="description"><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p>
251 -
252 - <?php if ( ! empty( $data['link'] ) ) : ?>
253 - <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a>
254 - <?php endif; ?>
255 - <div class="tab-import-export-kit__box action-buttons">
256 - <?php if ( ! empty( $data['button_secondary'] ) ) : ?>
257 - <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['url'] ); ?>" class="elementor-button e-btn-txt e-btn-txt-border">
258 - <?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['text'] ); ?>
259 - </a>
260 - <?php endif; ?>
261 - <a <?php ElementorUtils::print_html_attributes( [ 'id' => $data['button']['id'] ] ); ?> href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button e-primary">
262 - <?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?>
263 - </a>
264 - </div>
265 - </div>
266 - <?php
267 - }
268 -
269 238 private function get_revert_href(): string {
270 239 $admin_post_url = admin_url( 'admin-post.php?action=elementor_revert_kit' );
271 240 $nonced_admin_post_url = wp_nonce_url( $admin_post_url, 'elementor_revert_kit' );
272 241 return $this->maybe_add_referrer_param( $nonced_admin_post_url );
@@ -326,19 +295,15 @@
326 295 * so it will be available to use in different places such as: WP_Cli, Pro, etc.
327 296 *
328 297 * @param string $file Path to the file.
329 298 * @param string $referrer Referrer of the file 'local' or 'kit-library'.
330 - * @param string $kit_id
331 299 * @return array
332 - * @throws \Exception If export validation fails or processing errors occur.
300 + * @throws \Exception
333 301 */
334 - public function upload_kit( $file, $referrer, $kit_id = null ) {
302 + public function upload_kit( $file, $referrer ) {
335 303 $this->ensure_writing_permissions();
336 304
337 - $this->import = new Import( $file, [
338 - 'referrer' => $referrer,
339 - 'id' => $kit_id,
340 - ] );
305 + $this->import = new Import( $file, [ 'referrer' => $referrer ] );
341 306
342 307 return [
343 308 'session' => $this->import->get_session_id(),
344 309 'manifest' => $this->import->get_manifest(),
@@ -356,22 +321,20 @@
356 321 * Assigning the Import process to the 'import' property,
357 322 * so it will be available to use in different places such as: WP_Cli, Pro, etc.
358 323 *
359 324 * @param string $path Path to the file or session_id.
360 - * @param array $settings Settings the import use to determine which content to import.
361 - * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.)
362 - * @param bool $split_to_chunks Determine if the import process should be split into chunks.
325 + * @param array $settings Settings the import use to determine which content to import.
326 + * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.)
327 + * @param bool $split_to_chunks Determine if the import process should be split into chunks.
363 328 * @return array
364 - * @throws \Exception If export configuration is invalid or processing fails.
329 + * @throws \Exception
365 330 */
366 331 public function import_kit( string $path, array $settings, bool $split_to_chunks = false ): array {
367 332 $this->ensure_writing_permissions();
368 - $this->ensure_DOMDocument_exists();
369 333
370 334 $this->import = new Import( $path, $settings );
371 335 $this->import->register_default_runners();
372 336
373 - remove_filter( 'elementor/document/save/data', [ Plugin::$instance->modules_manager->get_modules( 'content-sanitizer' ), 'sanitize_content' ] );
374 337 do_action( 'elementor/import-export/import-kit', $this->import );
375 338
376 339 if ( $split_to_chunks ) {
377 340 $this->import->init_import_session( true );
@@ -393,9 +356,9 @@
393 356 *
394 357 * @return array Two types of response.
395 358 * 1. The status and the runner name.
396 359 * 2. The imported data. (Only if the runner is the last one in the import process)
397 - * @throws \Exception If import configuration is invalid or processing fails.
360 + * @throws \Exception
398 361 */
399 362 public function import_kit_by_runner( string $session_id, string $runner_name ): array {
400 363 // Check session_id
401 364 $this->import = Import::from_session( $session_id );
@@ -418,9 +381,9 @@
418 381 *
419 382 * @param array $settings Settings the export use to determine which content to export.
420 383 * (e.g: include, kit_info, selected_plugins, selected_cpt, etc.)
421 384 * @return array
422 - * @throws \Exception If import/export process fails or validation errors occur.
385 + * @throws \Exception
423 386 */
424 387 public function export_kit( array $settings ) {
425 388 $this->ensure_writing_permissions();
426 389
@@ -474,44 +437,13 @@
474 437 add_action( 'admin_post_elementor_revert_kit', [ $this, 'handle_revert_last_imported_kit' ] );
475 438
476 439 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
477 440
478 - if ( ! Plugin::$instance->experiments->is_feature_active( 'import-export-customization' ) ) {
479 - $page_id = Tools::PAGE_ID;
441 + $page_id = Tools::PAGE_ID;
480 442
481 - add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] );
482 - }
483 -
484 - // TODO 18/04/2023 : This needs to be moved to the runner itself after https://elementor.atlassian.net/browse/HTS-434 is done.
485 - if ( self::IMPORT_PLUGINS_ACTION === ElementorUtils::get_super_global_value( $_SERVER, 'HTTP_X_ELEMENTOR_ACTION' ) ) {
486 - add_filter( 'woocommerce_create_pages', [ $this, 'empty_pages' ], 10, 0 );
487 - }
488 - // TODO ^^^
489 -
490 - add_filter( 'elementor/import/kit/result', function( $result ) {
491 - if ( ! empty( $result['file_url'] ) ) {
492 - return [
493 - 'file_name' => $this->get_remote_kit_zip( $result['file_url'] ),
494 - 'referrer' => static::REFERRER_KIT_LIBRARY,
495 - 'file_url' => $result['file_url'],
496 - ];
497 - }
498 -
499 - return $result;
500 - } );
443 + add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] );
501 444 }
502 445
503 - /**
504 - * Prevent the creation of the default WooCommerce pages (Cart, Checkout, etc.)
505 - *
506 - * TODO 18/04/2023 : This needs to be moved to the runner itself after https://elementor.atlassian.net/browse/HTS-434 is done.
507 - *
508 - * @return array
509 - */
510 - public function empty_pages(): array {
511 - return [];
512 - }
513 -
514 446 private function ensure_writing_permissions() {
515 447 $server = new Server();
516 448
517 449 $paths_to_check = [
@@ -523,14 +455,14 @@
523 455 $permissions = $server->get_paths_permissions( $paths_to_check );
524 456
525 457 // WP Content dir has to be exists and writable.
526 458 if ( ! $permissions[ Server::KEY_PATH_WP_CONTENT_DIR ]['write'] ) {
527 - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
459 + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY );
528 460 }
529 461
530 462 // WP Uploads dir has to be exists and writable.
531 463 if ( ! $permissions[ Server::KEY_PATH_UPLOADS_DIR ]['write'] ) {
532 - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
464 + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY );
533 465 }
534 466
535 467 // Elementor uploads dir permissions is divided to 2 cases:
536 468 // 1. If the dir exists, it has to be writable.
@@ -535,18 +467,12 @@
535 467 // Elementor uploads dir permissions is divided to 2 cases:
536 468 // 1. If the dir exists, it has to be writable.
537 469 // 2. If the dir doesn't exist, the parent dir has to be writable (wp uploads dir), so we can create it.
538 470 if ( $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) {
539 - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
471 + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY );
540 472 }
541 473 }
542 474
543 - private function ensure_DOMDocument_exists() {
544 - if ( ! class_exists( 'DOMDocument' ) ) {
545 - throw new \Error( self::DOMDOCUMENT_MISSING ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
546 - }
547 - }
548 -
549 475 /**
550 476 * Enqueue admin scripts
551 477 */
552 478 public function enqueue_scripts() {
@@ -596,22 +522,13 @@
596 522 default:
597 523 break;
598 524 }
599 525 } catch ( \Error $e ) {
600 - if ( isset( $this->import ) ) {
601 - $this->import->finalize_import_session_option();
602 - }
603 -
604 526 Plugin::$instance->logger->get_logger()->error( $e->getMessage(), [
605 527 'meta' => [
606 528 'trace' => $e->getTraceAsString(),
607 529 ],
608 530 ] );
609 -
610 - if ( isset( $this->import ) && $this->is_third_party_class( $e->getTrace()[0]['class'] ) ) {
611 - wp_send_json_error( self::THIRD_PARTY_ERROR, 500 );
612 - }
613 -
614 531 wp_send_json_error( $e->getMessage(), 500 );
615 532 }
616 533 }
617 534
@@ -616,10 +533,8 @@
616 533 }
617 534
618 535 /**
619 536 * Handle upload kit ajax request.
620 - *
621 - * @throws \Error If operation validation fails or processing errors occur.
622 537 */
623 538 private function handle_upload_kit() {
624 539 // PHPCS - A URL that should contain special chars (auth headers information).
625 540 $file_url = isset( $_POST['e_import_file'] )
@@ -626,15 +541,10 @@
626 541 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
627 542 ? wp_unslash( $_POST['e_import_file'] )
628 543 : '';
629 544
630 - // PHPCS - Already validated in caller function
631 - $kit_id = ElementorUtils::get_super_global_value( $_POST, 'kit_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
632 - $source = ElementorUtils::get_super_global_value( $_POST, 'source' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
633 -
634 - $is_import_from_library = ! empty( $file_url );
635 -
636 - if ( $is_import_from_library ) {
545 + // Import from kit library
546 + if ( ! empty( $file_url ) ) {
637 547 if (
638 548 ! wp_verify_nonce( ElementorUtils::get_super_global_value( $_POST, 'e_kit_library_nonce' ), 'kit-library-import' )
639 549 ) {
640 550 throw new \Error( 'Invalid kit library nonce.' );
@@ -640,59 +550,57 @@
640 550 throw new \Error( 'Invalid kit library nonce.' );
641 551 }
642 552
643 553 if ( ! filter_var( $file_url, FILTER_VALIDATE_URL ) || 0 !== strpos( $file_url, 'http' ) ) {
644 - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
554 + throw new \Error( static::KIT_LIBRARY_ERROR_KEY );
645 555 }
646 556
647 - $import_result = apply_filters( 'elementor/import/kit/result', [ 'file_url' => $file_url ] );
648 - } elseif ( ! empty( $source ) ) {
649 - $import_result = apply_filters( 'elementor/import/kit/result/' . $source, [
650 - 'kit_id' => $kit_id,
651 - 'source' => $source,
652 - ] );
557 + $remote_zip_request = wp_remote_get( $file_url );
558 +
559 + if ( is_wp_error( $remote_zip_request ) ) {
560 + Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() );
561 + throw new \Error( static::KIT_LIBRARY_ERROR_KEY );
562 + }
563 +
564 + if ( 200 !== $remote_zip_request['response']['code'] ) {
565 + Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] );
566 + throw new \Error( static::KIT_LIBRARY_ERROR_KEY );
567 + }
568 +
569 + $file_name = Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' );
570 + $referrer = static::REFERRER_KIT_LIBRARY;
653 571 } else {
654 - $import_result = [
655 - 'file_name' => ElementorUtils::get_super_global_value( $_FILES, 'e_import_file' )['tmp_name'],
656 - 'referrer' => static::REFERRER_LOCAL,
657 - ];
572 + // PHPCS - Already validated in caller function.
573 + $file_name = ElementorUtils::get_super_global_value( $_FILES, 'e_import_file' )['tmp_name'];
574 + $referrer = static::REFERRER_LOCAL;
658 575 }
659 576
660 577 Plugin::$instance->logger->get_logger()->info( 'Uploading Kit: ', [
661 578 'meta' => [
662 - 'kit_id' => $kit_id,
663 - 'referrer' => $import_result['referrer'],
579 + 'kit_id' => ElementorUtils::get_super_global_value( $_POST, 'kit_id' ),
580 + 'referrer' => $referrer,
664 581 ],
665 582 ] );
666 583
667 - if ( is_wp_error( $import_result ) ) {
668 - wp_send_json_error( $import_result->get_error_message() );
669 - }
584 + $uploaded_kit = $this->upload_kit( $file_name, $referrer );
670 585
671 - $uploaded_kit = $this->upload_kit( $import_result['file_name'], $import_result['referrer'], $kit_id );
672 -
673 586 $session_dir = $uploaded_kit['session'];
674 587 $manifest = $uploaded_kit['manifest'];
675 588 $conflicts = $uploaded_kit['conflicts'];
676 589
677 - if ( $is_import_from_library || ! empty( $source ) ) {
678 - Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $import_result['file_name'] ) );
590 + if ( ! empty( $file_url ) ) {
591 + Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) );
679 592 }
680 593
681 594 if ( isset( $manifest['plugins'] ) && ! current_user_can( 'install_plugins' ) ) {
682 - throw new \Error( static::PLUGIN_PERMISSIONS_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
595 + throw new \Error( static::PLUGIN_PERMISSIONS_ERROR_KEY );
683 596 }
684 597
685 598 $result = [
686 599 'session' => $session_dir,
687 600 'manifest' => $manifest,
688 - 'file_url' => $import_result['file_url'],
689 601 ];
690 602
691 - if ( ! empty( $import_result['kit'] ) ) {
692 - $result['uploaded_kit'] = $import_result['kit'];
693 - }
694 -
695 603 if ( ! empty( $conflicts ) ) {
696 604 $result['conflicts'] = $conflicts;
697 605 } else {
698 606 // Moved into the IE process \Elementor\App\Modules\ImportExport\Processes\Import::get_default_settings_conflicts
@@ -702,24 +610,8 @@
702 610
703 611 wp_send_json_success( $result );
704 612 }
705 613
706 - protected function get_remote_kit_zip( $url ) {
707 - $remote_zip_request = wp_safe_remote_get( $url );
708 -
709 - if ( is_wp_error( $remote_zip_request ) ) {
710 - Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() );
711 - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
712 - }
713 -
714 - if ( 200 !== $remote_zip_request['response']['code'] ) {
715 - Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] );
716 - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
717 - }
718 -
719 - return Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' );
720 - }
721 -
722 614 /**
723 615 * Handle import kit ajax request.
724 616 */
725 617 private function handle_import_kit() {
@@ -731,14 +623,8 @@
731 623
732 624 // get_settings_config() added manually because the frontend Ajax request doesn't trigger the get_init_settings().
733 625 $import['configData'] = $this->get_config_data();
734 626
735 - Plugin::$instance->logger->get_logger()->info(
736 - sprintf( 'Selected import runners: %1$s',
737 - implode( ', ', $import['runners'] )
738 - )
739 - );
740 -
741 627 wp_send_json_success( $import );
742 628 }
743 629
744 630 /**
@@ -754,36 +640,20 @@
754 640
755 641 // get_settings_config() added manually because the frontend Ajax request doesn't trigger the get_init_settings().
756 642 $import['configData'] = $this->get_config_data();
757 643
758 - if ( ! empty( $import['status'] ) ) {
759 - Plugin::$instance->logger->get_logger()->info(
760 - sprintf( 'Import runner completed: %1$s %2$s',
761 - $import['runner'],
762 - ( 'success' === $import['status'] ? '✓' : '✗' )
763 - )
764 - );
765 - }
766 -
767 - do_action( 'elementor/import-export/import-kit/runner/after-run', $import );
768 -
769 644 wp_send_json_success( $import );
770 645 }
771 646
772 647 /**
773 648 * Handle export kit ajax request.
774 - *
775 - * @throws \Error If cleanup process fails or file system errors occur.
776 649 */
777 650 private function handle_export_kit() {
778 651 // PHPCS - Already validated in caller function
779 652 $settings = json_decode( ElementorUtils::get_super_global_value( $_POST, 'data' ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
780 - $source = $settings['kitInfo']['source'];
781 -
782 653 $export = $this->export_kit( $settings );
783 654
784 655 $file_name = $export['file_name'];
785 - $file_size = filesize( $file_name );
786 656 $file = ElementorUtils::file_get_contents( $file_name );
787 657
788 658 if ( ! $file ) {
789 659 throw new \Error( 'Could not read the exported file.' );
@@ -790,25 +660,13 @@
790 660 }
791 661
792 662 Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) );
793 663
794 - $result = apply_filters(
795 - 'elementor/export/kit/export-result',
796 - [
797 - 'manifest' => $export['manifest'],
798 - 'file' => base64_encode( $file ),
799 - ],
800 - $source,
801 - $export,
802 - $settings,
803 - $file,
804 - $file_size,
805 - );
664 + $result = [
665 + 'manifest' => $export['manifest'],
666 + 'file' => base64_encode( $file ),
667 + ];
806 668
807 - if ( is_wp_error( $result ) ) {
808 - wp_send_json_error( $result );
809 - }
810 -
811 669 wp_send_json_success( $result );
812 670 }
813 671
814 672 /**
@@ -828,9 +686,8 @@
828 686 'recentlyEditedElementorPageUrl' => $this->get_recently_edited_elementor_page_url(),
829 687 'tools_url' => Tools::get_url(),
830 688 'importSessions' => Revert::get_import_sessions(),
831 689 'lastImportedSession' => $this->revert->get_last_import_session(),
832 - 'kitPreviewNonce' => wp_create_nonce( 'kit_thumbnail' ),
833 690 ];
834 691 }
835 692
836 693 /**
@@ -855,10 +712,10 @@
855 712 foreach ( $post_types as $post_type ) {
856 713 $post_type_object = get_post_type_object( $post_type );
857 714
858 715 $summary_titles['content'][ $post_type ] = [
859 - 'single' => $post_type_object->labels->singular_name ?? '',
860 - 'plural' => $post_type_object->label ?? '',
716 + 'single' => $post_type_object->labels->singular_name,
717 + 'plural' => $post_type_object->label,
861 718 ];
862 719 }
863 720
864 721 $custom_post_types = ImportExportUtils::get_registered_cpt_names();
@@ -868,16 +725,16 @@
868 725 $custom_post_types_object = get_post_type_object( $custom_post_type );
869 726 // CPT data appears in two arrays:
870 727 // 1. content object: in order to show the export summary when completed in getLabel function
871 728 $summary_titles['content'][ $custom_post_type ] = [
872 - 'single' => $custom_post_types_object->labels->singular_name ?? '',
873 - 'plural' => $custom_post_types_object->label ?? '',
729 + 'single' => $custom_post_types_object->labels->singular_name,
730 + 'plural' => $custom_post_types_object->label,
874 731 ];
875 732
876 733 // 2. customPostTypes object: in order to actually export the data
877 734 $summary_titles['content']['customPostTypes'][ $custom_post_type ] = [
878 - 'single' => $custom_post_types_object->labels->singular_name ?? '',
879 - 'plural' => $custom_post_types_object->label ?? '',
735 + 'single' => $custom_post_types_object->labels->singular_name,
736 + 'plural' => $custom_post_types_object->label,
880 737 ];
881 738 }
882 739 }
883 740
@@ -895,11 +752,11 @@
895 752 return false;
896 753 }
897 754
898 755 // TODO: BC - remove in the future
899 - // The 'templates' runner was in core and moved to the Pro plugin. (Part of it still exits in the Core for BC)
900 - // The runner that is in the core version is missing the revert functionality,
901 - // therefore we shouldn't display the revert section if the import process done with the core version.
756 + // The 'templates' runner was in core and moved to the Pro plugin. (Part of it still exits in the Core for BC)
757 + // The runner that is in the core version is missing the revert functionality,
758 + // therefore we shouldn't display the revert section if the import process done with the core version.
902 759 $is_import_templates_ran = isset( $last_imported_kit['runners']['templates'] );
903 760 if ( $this->has_pro() && $is_import_templates_ran ) {
904 761 $has_imported_templates = ! empty( $last_imported_kit['runners']['templates'] );
905 762
@@ -972,28 +829,6 @@
972 829 private function get_elementor_editor_page_url( $page_id ) {
973 830 $document = $this->get_elementor_document( $page_id );
974 831
975 832 return $document ? $document->get_edit_url() : '';
976 - }
977 -
978 - /**
979 - * @param string $class_name
980 - *
981 - * @return bool
982 - */
983 - public function is_third_party_class( $class_name ) {
984 - $allowed_classes = [
985 - 'Elementor\\',
986 - 'ElementorPro\\',
987 - 'WP_',
988 - 'wp_',
989 - ];
990 -
991 - foreach ( $allowed_classes as $allowed_class ) {
992 - if ( str_starts_with( $class_name, $allowed_class ) ) {
993 - return false;
994 - }
995 - }
996 -
997 - return true;
998 833 }
999 834 }