← All changes
|
app/modules/import-export-customization/module.php
+21
-67
4.2.2
→
3.33.0-dev1
View file →
| @@ -6,12 +6,9 @@ | ||
| 6 | 6 | use Elementor\App\Modules\ImportExportCustomization\Processes\Revert; |
| 7 | 7 | use Elementor\Core\Base\Module as BaseModule; |
| 8 | 8 | use Elementor\Core\Files\Uploads_Manager; |
| 9 | 9 | use Elementor\Modules\CloudKitLibrary\Module as CloudKitLibrary; |
| 10 | -use Elementor\Modules\GlobalClasses\Global_Classes_REST_API; | |
| 11 | 10 | use Elementor\Modules\System_Info\Reporters\Server; |
| 12 | -use Elementor\Modules\Variables\Storage\Constants; | |
| 13 | -use Elementor\Modules\Variables\Storage\Variables_Collection; | |
| 14 | 11 | use Elementor\Plugin; |
| 15 | 12 | use Elementor\Tools; |
| 16 | 13 | use Elementor\Utils as ElementorUtils; |
| 17 | 14 | use Elementor\App\Modules\ImportExportCustomization\Utils as ImportExportUtils; |
| @@ -160,15 +157,10 @@ | ||
| 160 | 157 | ], |
| 161 | 158 | ]; |
| 162 | 159 | |
| 163 | 160 | if ( $is_cloud_kits_available ) { |
| 164 | - $return_to_url = Tools::get_url() . '#tab-import-export-kit'; | |
| 165 | - $kit_library_url = add_query_arg( | |
| 166 | - [ 'return_to' => rawurlencode( $return_to_url ) ], | |
| 167 | - Plugin::$instance->app->get_base_url() . '#/kit-library/cloud' | |
| 168 | - ); | |
| 169 | 161 | $content_data['import']['button_secondary'] = [ |
| 170 | - 'url' => $kit_library_url, | |
| 162 | + 'url' => Plugin::$instance->app->get_base_url() . '#/kit-library/cloud', | |
| 171 | 163 | 'text' => esc_html__( 'Import from library', 'elementor' ), |
| 172 | 164 | 'id' => 'elementor-import-export__import_from_library', |
| 173 | 165 | ]; |
| 174 | 166 | } |
| @@ -248,11 +240,10 @@ | ||
| 248 | 240 | <?php |
| 249 | 241 | } |
| 250 | 242 | |
| 251 | 243 | private function print_item_content( $data ) { |
| 252 | - $container_classes = 'tab-import-export-kit__container e-editor-one'; | |
| 253 | 244 | ?> |
| 254 | - <div class="<?php echo esc_attr( $container_classes ); ?>"> | |
| 245 | + <div class="tab-import-export-kit__container"> | |
| 255 | 246 | <div class="tab-import-export-kit__box"> |
| 256 | 247 | <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2> |
| 257 | 248 | </div> |
| 258 | 249 | <p class="description"><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p> |
| @@ -274,10 +265,11 @@ | ||
| 274 | 265 | <?php |
| 275 | 266 | } |
| 276 | 267 | |
| 277 | 268 | private function get_revert_href(): string { |
| 278 | - $current_url = add_query_arg( null, null ); | |
| 279 | - return $this->maybe_add_referrer_param( $current_url ); | |
| 269 | + $admin_post_url = admin_url( 'admin-post.php?action=elementor_revert_kit' ); | |
| 270 | + $nonced_admin_post_url = wp_nonce_url( $admin_post_url, 'elementor_revert_kit' ); | |
| 271 | + return $this->maybe_add_referrer_param( $nonced_admin_post_url ); | |
| 280 | 272 | } |
| 281 | 273 | |
| 282 | 274 | /** |
| 283 | 275 | * Checks if referred by a kit and adds the referrer ID to the href |
| @@ -296,18 +288,8 @@ | ||
| 296 | 288 | return add_query_arg( $param_name, sanitize_key( $_GET[ $param_name ] ), $href ); |
| 297 | 289 | } |
| 298 | 290 | |
| 299 | 291 | /** |
| 300 | - * Get referrer kit ID from current request | |
| 301 | - * | |
| 302 | - * @return string | |
| 303 | - */ | |
| 304 | - private function get_referrer_kit_id_from_request(): string { | |
| 305 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Called via REST API with its own authentication | |
| 306 | - return sanitize_key( $_GET['referrer_kit'] ?? '' ); | |
| 307 | - } | |
| 308 | - | |
| 309 | - /** | |
| 310 | 292 | * Render the last kit thumbnail if exists |
| 311 | 293 | * |
| 312 | 294 | * @param $last_imported_kit |
| 313 | 295 | * |
| @@ -355,10 +337,8 @@ | ||
| 355 | 337 | 'referrer' => $referrer, |
| 356 | 338 | 'id' => $kit_id, |
| 357 | 339 | ] ); |
| 358 | 340 | |
| 359 | - $this->save_upload_session_data(); | |
| 360 | - | |
| 361 | 341 | return [ |
| 362 | 342 | 'session' => $this->import->get_session_id(), |
| 363 | 343 | 'manifest' => $this->import->get_manifest(), |
| 364 | 344 | 'conflicts' => $this->import->get_settings_conflicts(), |
| @@ -403,12 +383,8 @@ | ||
| 403 | 383 | |
| 404 | 384 | return $this->import->run(); |
| 405 | 385 | } |
| 406 | 386 | |
| 407 | - private function save_upload_session_data(): void { | |
| 408 | - $this->import->init_import_session(); | |
| 409 | - } | |
| 410 | - | |
| 411 | 387 | /** |
| 412 | 388 | * Resuming import process by re-creating the import instance and running the specific runner. |
| 413 | 389 | * |
| 414 | 390 | * @param string $session_id The id off the import session. |
| @@ -455,36 +431,30 @@ | ||
| 455 | 431 | return $this->export->run(); |
| 456 | 432 | } |
| 457 | 433 | |
| 458 | 434 | /** |
| 459 | - * Handle revert kit request. | |
| 435 | + * Handle revert kit ajax request. | |
| 460 | 436 | */ |
| 461 | - public function revert_last_imported_kit(): array { | |
| 437 | + public function revert_last_imported_kit() { | |
| 462 | 438 | $this->revert = new Revert(); |
| 463 | 439 | $this->revert->register_default_runners(); |
| 464 | 440 | |
| 465 | - $import_sessions = Revert::get_import_sessions(); | |
| 441 | + do_action( 'elementor/import-export-customization/revert-kit', $this->revert ); | |
| 466 | 442 | |
| 467 | - if ( empty( $import_sessions ) ) { | |
| 468 | - return [ | |
| 469 | - 'revert_completed' => false, | |
| 470 | - 'message' => __( 'No import sessions available to revert.', 'elementor' ), | |
| 471 | - 'referrer_kit_id' => $this->get_referrer_kit_id_from_request(), | |
| 472 | - 'show_referrer_dialog' => false, | |
| 473 | - ]; | |
| 474 | - } | |
| 443 | + $this->revert->run(); | |
| 444 | + } | |
| 475 | 445 | |
| 476 | - do_action( 'elementor/import-export-customization/revert-kit', $this->revert ); | |
| 477 | 446 | |
| 478 | - $this->revert->run(); | |
| 447 | + /** | |
| 448 | + * Handle revert last imported kit ajax request. | |
| 449 | + */ | |
| 450 | + public function handle_revert_last_imported_kit() { | |
| 451 | + check_admin_referer( 'elementor_revert_kit' ); | |
| 479 | 452 | |
| 480 | - $referrer_kit_id = $this->get_referrer_kit_id_from_request(); | |
| 453 | + $this->revert_last_imported_kit(); | |
| 481 | 454 | |
| 482 | - return [ | |
| 483 | - 'revert_completed' => true, | |
| 484 | - 'referrer_kit_id' => $referrer_kit_id, | |
| 485 | - 'show_referrer_dialog' => ! empty( $referrer_kit_id ), | |
| 486 | - ]; | |
| 455 | + wp_safe_redirect( admin_url( 'admin.php?page=' . Tools::PAGE_ID . '#tab-import-export-kit' ) ); | |
| 456 | + die; | |
| 487 | 457 | } |
| 488 | 458 | |
| 489 | 459 | /** |
| 490 | 460 | * Register appropriate actions. |
| @@ -489,8 +459,10 @@ | ||
| 489 | 459 | /** |
| 490 | 460 | * Register appropriate actions. |
| 491 | 461 | */ |
| 492 | 462 | private function register_actions() { |
| 463 | + add_action( 'admin_post_elementor_revert_kit', [ $this, 'handle_revert_last_imported_kit' ] ); | |
| 464 | + | |
| 493 | 465 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 494 | 466 | |
| 495 | 467 | $page_id = Tools::PAGE_ID; |
| 496 | 468 | |
| @@ -584,9 +556,9 @@ | ||
| 584 | 556 | |
| 585 | 557 | wp_enqueue_script( |
| 586 | 558 | 'import-export-customization-admin', |
| 587 | 559 | $this->get_js_assets_url( 'import-export-customization-admin' ), |
| 588 | - [ 'elementor-common', 'wp-api-fetch' ], | |
| 560 | + [ 'elementor-common' ], | |
| 589 | 561 | ELEMENTOR_VERSION, |
| 590 | 562 | true |
| 591 | 563 | ); |
| 592 | 564 | } |
| @@ -626,16 +598,13 @@ | ||
| 626 | 598 | 'importSessions' => Revert::get_import_sessions(), |
| 627 | 599 | 'lastImportedSession' => $this->revert->get_last_import_session(), |
| 628 | 600 | 'kitPreviewNonce' => wp_create_nonce( 'kit_thumbnail' ), |
| 629 | 601 | 'restApiBaseUrl' => Controller::get_base_url(), |
| 630 | - 'restNonce' => wp_create_nonce( 'wp_rest' ), | |
| 631 | - 'restUrl' => rest_url(), | |
| 632 | 602 | 'uiTheme' => $this->get_elementor_ui_theme_preference(), |
| 633 | 603 | 'exportGroups' => $this->get_export_groups(), |
| 634 | 604 | 'manifestVersion' => self::FORMAT_VERSION, |
| 635 | 605 | 'elementorVersion' => ELEMENTOR_VERSION, |
| 636 | 606 | 'upgradeVersionUrl' => admin_url( 'plugins.php' ), |
| 637 | - 'limits' => $this->get_limits(), | |
| 638 | 607 | ]; |
| 639 | 608 | } |
| 640 | 609 | |
| 641 | 610 | private function get_elementor_ui_theme_preference() { |
| @@ -652,23 +621,8 @@ | ||
| 652 | 621 | $export_groups[ $name ] = defined( $document_type . '::EXPORT_GROUP' ) ? $document_type::EXPORT_GROUP : ''; |
| 653 | 622 | } |
| 654 | 623 | |
| 655 | 624 | return $export_groups; |
| 656 | - } | |
| 657 | - | |
| 658 | - private function get_limits() { | |
| 659 | - $classes_limit = class_exists( Global_Classes_REST_API::class ) | |
| 660 | - ? Global_Classes_REST_API::MAX_ITEMS | |
| 661 | - : 100; | |
| 662 | - | |
| 663 | - $variables_limit = class_exists( Constants::class ) | |
| 664 | - ? Constants::TOTAL_VARIABLES_COUNT | |
| 665 | - : 100; | |
| 666 | - | |
| 667 | - return [ | |
| 668 | - 'classes' => $classes_limit, | |
| 669 | - 'variables' => $variables_limit, | |
| 670 | - ]; | |
| 671 | 625 | } |
| 672 | 626 | |
| 673 | 627 | /** |
| 674 | 628 | * Get labels of Elementor document types, Elementor Post types, WordPress Post types and Custom Post types. |