/var/www/html_us/wp-content/plugins/elementor/app/modules/import-export/processes/import.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
<?php

namespace Elementor\App\Modules\ImportExport\Processes;

use 
Elementor\App\Modules\ImportExport\Compatibility\Base_Adapter;
use 
Elementor\App\Modules\ImportExport\Compatibility\Envato;
use 
Elementor\App\Modules\ImportExport\Compatibility\Kit_Library;
use 
Elementor\App\Modules\ImportExport\Utils;
use 
Elementor\Core\Base\Document;
use 
Elementor\Core\Kits\Documents\Kit;
use 
Elementor\Plugin;

use 
Elementor\App\Modules\ImportExport\Runners\Import\Elementor_Content;
use 
Elementor\App\Modules\ImportExport\Runners\Import\Import_Runner_Base;
use 
Elementor\App\Modules\ImportExport\Runners\Import\Plugins;
use 
Elementor\App\Modules\ImportExport\Runners\Import\Site_Settings;
use 
Elementor\App\Modules\ImportExport\Runners\Import\Taxonomies;
use 
Elementor\App\Modules\ImportExport\Runners\Import\Templates;
use 
Elementor\App\Modules\ImportExport\Runners\Import\Wp_Content;
use 
Elementor\App\Modules\ImportExport\Module;
use 
Elementor\App\Modules\KitLibrary\Connect\Kit_Library as Kit_Library_Api;

class 
Import {
    const 
MANIFEST_ERROR_KEY 'manifest-error';

    const 
ZIP_FILE_ERROR_KEY 'invalid-zip-file';

    const 
ZIP_ARCHIVE_ERROR_KEY 'zip-archive-module-missing';

    
/**
     * @var Import_Runner_Base[]
     */
    
protected $runners = [];

    
/**
     * The session ID of the import process.
     * This ID is uniquely generated for each import process (by the temp folder which contains the extracted kit files).
     *
     * @var string
     */
    
private $session_id;

    
/**
     * The Kit ID.
     *
     * @var string
     */
    
private $kit_id;

    
/**
     * Adapter for the kit compatibility.
     *
     * @var Base_Adapter[]
     */
    
private $adapters;

    
/**
     * Document's data (elements and settings) that was imported during the process.
     *
     * @var array { [document_id] => { "elements": array , "settings": array } }
     */
    
private $documents_data = [];

    
/**
     * Path to the extracted kit files.
     *
     * @var string
     */
    
private $extracted_directory_path;

    
/**
     * Imported kit manifest.
     *
     * @var array
     */
    
private $manifest;

    
/**
     * Imported kit site settings. (e.g: custom_colors, custom_typography, etc.)
     *
     * @var array
     */
    
private $site_settings;

    
/**
     * Selected content types to import.
     *
     * @var array
     */
    
private $settings_include;

    
/**
     * Referer of the import. (e.g: kit-library, local, etc.)
     *
     * @var string
     */
    
private $settings_referrer;

    
/**
     * All the conflict between the exited templates and the kit templates.
     *
     * @var array
     */
    
private $settings_conflicts;

    
/**
     * Selected elementor templates conditions to override.
     *
     * @var array
     */
    
private $settings_selected_override_conditions;

    
/**
     * Selected custom post types to import.
     *
     * @var array
     */
    
private $settings_selected_custom_post_types;

    
/**
     * Selected plugins to import.
     *
     * @var array
     */
    
private $settings_selected_plugins;

    
/**
     * The imported data output.
     *
     * @var array
     */
    
private $imported_data = [];

    
/**
     * The metadata output of the import runners.
     * Will be saved in the import_session and will be used to revert the import process.
     *
     * @var array
     */
    
private $runners_import_metadata = [];

    
/**
     * @param string $path session_id | zip_file_path
     * @param array $settings Use to determine which content to import.
     *      (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.)
     * @param array|null $old_instance An array of old instance parameters that will be used for creating new instance.
     *      We are using it for quick creation of the instance when the import process is being split into chunks.
     * @throws \Exception
     */
    
public function __constructstring $path, array $settings = [], array $old_instance null ) {
        if ( ! empty( 
$old_instance ) ) {
            
$this->set_import_object$old_instance );
        } else {
            if ( 
is_file$path ) ) {
                
$this->extracted_directory_path $this->extract_zip$path );
            } else {
                
$elementor_tmp_directory Plugin::$instance->uploads_manager->get_temp_dir();
                
$path $elementor_tmp_directory basename$path );

                if ( ! 
is_dir$path ) ) {
                    throw new 
\Exception'Couldn’t execute the import process because the import session does not exist.' );
                }

                
$this->extracted_directory_path $path '/';
            }

            
$this->session_id basename$this->extracted_directory_path );
            
$this->kit_id $settings['id'] ?? '';
            
$this->settings_referrer = ! empty( $settings['referrer'] ) ? $settings['referrer'] : 'local';
            
$this->settings_include = ! empty( $settings['include'] ) ? $settings['include'] : null;

            
// Using isset and not empty is important since empty array is valid option.
            
$this->settings_selected_override_conditions $settings['overrideConditions'] ?? null;
            
$this->settings_selected_custom_post_types $settings['selectedCustomPostTypes'] ?? null;
            
$this->settings_selected_plugins $settings['plugins'] ?? null;

            
$this->manifest $this->read_manifest_json();
            
$this->site_settings $this->read_site_settings_json();

            
$this->set_default_settings();
        }

        
add_filter'wp_php_error_args', function ( $args$error ) {
            return 
$this->filter_php_error_args$args$error );
        }, 
10);
    }

    
/**
     * Set the import object parameters.
     *
     * @param array $instance
     * @return void
     */
    
private function set_import_object( array $instance ) {
        
$this->session_id $instance['session_id'];

        
$instance_data $instance['instance_data'];

        
$this->extracted_directory_path $instance_data['extracted_directory_path'];
        
$this->runners $instance_data['runners'];
        
$this->adapters $instance_data['adapters'];

        
$this->manifest $instance_data['manifest'];
        
$this->site_settings $instance_data['site_settings'];

        
$this->settings_include $instance_data['settings_include'];
        
$this->settings_referrer $instance_data['settings_referrer'];
        
$this->settings_conflicts $instance_data['settings_conflicts'];
        
$this->settings_selected_override_conditions $instance_data['settings_selected_override_conditions'];
        
$this->settings_selected_custom_post_types $instance_data['settings_selected_custom_post_types'];
        
$this->settings_selected_plugins $instance_data['settings_selected_plugins'];

        
$this->documents_data $instance_data['documents_data'];
        
$this->imported_data $instance_data['imported_data'];
        
$this->runners_import_metadata $instance_data['runners_import_metadata'];
    }

    
/**
     * Creating a new instance of the import process by the id of the old import session.
     *
     * @param string $session_id
     *
     * @return Import
     * @throws \Exception
     */
    
public static function from_sessionstring $session_id ): Import {
        
$import_sessions Utils::get_import_sessions();

        if ( ! 
$import_sessions || ! isset( $import_sessions$session_id ] ) ) {
            throw new 
\Exception'Couldn’t execute the import process because the import session does not exist.' );
        }

        
$import_session $import_sessions$session_id ];

        return new 
self$session_id, [], $import_session );
    }

    
/**
     * Register a runner.
     * Be aware that the runner will be executed in the order of registration, the order is crucial for the import process.
     *
     * @param Import_Runner_Base $runner_instance
     */
    
public function registerImport_Runner_Base $runner_instance ) {
        
$this->runners$runner_instance::get_name() ] = $runner_instance;
    }

    public function 
register_default_runners() {
        
$this->register( new Site_Settings() );
        
$this->register( new Plugins() );
        
$this->register( new Templates() );
        
$this->register( new Taxonomies() );
        
$this->register( new Elementor_Content() );
        
$this->register( new Wp_Content() );
    }

    
/**
     * Set default settings for the import.
     */
    
private function set_default_settings() {
        if ( ! 
is_array$this->get_settings_include() ) ) {
            
$this->settings_include$this->get_default_settings_include() );
        }

        if ( ! 
is_array$this->get_settings_conflicts() ) ) {
            
$this->settings_conflicts$this->get_default_settings_conflicts() );
        }

        if ( ! 
is_array$this->get_settings_selected_override_conditions() ) ) {
            
$this->settings_selected_override_conditions$this->get_default_settings_override_conditions() );
        }

        if ( ! 
is_array$this->get_settings_selected_custom_post_types() ) ) {
            
$this->settings_selected_custom_post_types$this->get_default_settings_custom_post_types() );
        }

        if ( ! 
is_array$this->get_settings_selected_plugins() ) ) {
            
$this->settings_selected_plugins$this->get_default_settings_plugins() );
        }
    }

    
/**
     * Execute the import process.
     *
     * @return array The imported data output.
     *
     * @throws \Exception If no import runners have been specified.
     */
    
public function run() {
        if ( empty( 
$this->runners ) ) {
            throw new 
\Exception'Couldn’t execute the import process because no import runners have been specified. Try again by specifying import runners.' );
        }

        
$data = [
            
'session_id' => $this->session_id,
            
'include' => $this->settings_include,
            
'manifest' => $this->manifest,
            
'site_settings' => $this->site_settings,
            
'selected_plugins' => $this->settings_selected_plugins,
            
'extracted_directory_path' => $this->extracted_directory_path,
            
'selected_custom_post_types' => $this->settings_selected_custom_post_types,
        ];

        
$this->init_import_session();

        
remove_filter'elementor/document/save/data', [ Plugin::$instance->modules_manager->get_modules'content-sanitizer' ), 'sanitize_content' ] );
        
add_filter'elementor/document/save/data', [ $this'prevent_saving_elements_on_post_creation' ], 10);

        
// Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads.
        
Plugin::$instance->uploads_manager->set_elementor_upload_statetrue );

        foreach ( 
$this->runners as $runner ) {
            if ( 
$runner->should_import$data ) ) {
                
$import $runner->import$data$this->imported_data );
                
$this->imported_data array_merge_recursive$this->imported_data$import );

                
$this->runners_import_metadata$runner::get_name() ] = $runner->get_import_session_metadata();
            }
        }

        
// After the upload complete, set the elementor upload state back to false.
        
Plugin::$instance->uploads_manager->set_elementor_upload_statefalse );

        
remove_filter'elementor/document/save/data', [ $this'prevent_saving_elements_on_post_creation' ], 10 );

        
$this->finalize_import_session_option();

        
$this->save_elements_of_imported_posts();

        
Plugin::$instance->uploads_manager->remove_file_or_dir$this->extracted_directory_path );
        return 
$this->imported_data;
    }

    
/**
     * Run specific runner by runner_name
     *
     * @param string $runner_name
     *
     * @return array
     *
     * @throws \Exception If no export runners have been specified.
     */
    
public function run_runnerstring $runner_name ): array {
        if ( empty( 
$this->runners ) ) {
            throw new 
\Exception'Couldn’t execute the import process because no import runners have been specified. Try again by specifying import runners.' );
        }

        
$data = [
            
'session_id' => $this->session_id,
            
'include' => $this->settings_include,
            
'manifest' => $this->manifest,
            
'site_settings' => $this->site_settings,
            
'selected_plugins' => $this->settings_selected_plugins,
            
'extracted_directory_path' => $this->extracted_directory_path,
            
'selected_custom_post_types' => $this->settings_selected_custom_post_types,
        ];

        
add_filter'elementor/document/save/data', [ $this'prevent_saving_elements_on_post_creation' ], 10);

        
// Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads.
        
Plugin::$instance->uploads_manager->set_elementor_upload_statetrue );

        
$runner $this->runners$runner_name ];

        if ( empty( 
$runner ) ) {
            throw new 
\Exception'Couldn’t execute the import process because the import runner was not found. Try again by specifying an import runner.' );
        }

        if ( 
$runner->should_import$data ) ) {
            
$import $runner->import$data$this->imported_data );
            
$this->imported_data array_merge_recursive$this->imported_data$import );

            
$this->runners_import_metadata$runner::get_name() ] = $runner->get_import_session_metadata();
        }

        
// After the upload complete, set the elementor upload state back to false.
        
Plugin::$instance->uploads_manager->set_elementor_upload_statefalse );

        
remove_filter'elementor/document/save/data', [ $this'prevent_saving_elements_on_post_creation' ], 10 );

        
$is_last_runner keyarray_slice$this->runners, -11true ) ) === $runner_name;
        if ( 
$is_last_runner ) {
            
$this->finalize_import_session_option();
            
$this->save_elements_of_imported_posts();
        } else {
            
$this->update_instance_data_in_import_session_option();
        }

        return [
            
'status' => 'success',
            
'runner' => $runner_name,
        ];
    }

    
/**
     * Create and save all the instance data to the import sessions option.
     *
     * @return void
     */
    
public function init_import_session$save_instance_data false ) {
        
$import_sessions Utils::get_import_sessionstrue );

        
$import_sessions$this->session_id ] = [
            
'session_id' => $this->session_id,
            
'kit_title' => $this->manifest['title'] ?? '',
            
'kit_name' => $this->manifest['name'] ?? '',
            
'kit_thumbnail' => $this->get_kit_thumbnail(),
            
'kit_source' => $this->settings_referrer,
            
'user_id' => get_current_user_id(),
            
'start_timestamp' => current_time'timestamp' ),
        ];

        if ( 
$save_instance_data ) {
            
$import_sessions$this->session_id ]['instance_data'] = [
                
'extracted_directory_path' => $this->extracted_directory_path,
                
'runners' => $this->runners,
                
'adapters' => $this->adapters,

                
'manifest' => $this->manifest,
                
'site_settings' => $this->site_settings,

                
'settings_include' => $this->settings_include,
                
'settings_referrer' => $this->settings_referrer,
                
'settings_conflicts' => $this->settings_conflicts,
                
'settings_selected_override_conditions' => $this->settings_selected_override_conditions,
                
'settings_selected_custom_post_types' => $this->settings_selected_custom_post_types,
                
'settings_selected_plugins' => $this->settings_selected_plugins,

                
'documents_data' => $this->documents_data,
                
'imported_data' => $this->imported_data,
                
'runners_import_metadata' => $this->runners_import_metadata,
            ];
        }

        
update_optionModule::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS$import_sessionsfalse );
    }

    
/**
     * Get the Kit thumbnail, goes to the home page thumbnail if main doesn't exist
     *
     * @return string
     */
    
private function get_kit_thumbnail(): string {
        if ( ! empty( 
$this->manifest['thumbnail'] ) ) {
            return 
$this->manifest['thumbnail'];
        }

        if ( empty( 
$this->kit_id ) ) {
            return 
'';
        }

        
$api = new Kit_Library_Api();
        
$kit $api->get_by_id$this->kit_id );

        if ( 
is_wp_error$kit ) ) {
            return 
'';
        }

        return 
$kit->thumbnail;
    }

    public function 
get_runners_name(): array {
        return 
array_keys$this->runners );
    }

    public function 
get_manifest() {
        return 
$this->manifest;
    }

    public function 
get_extracted_directory_path() {
        return 
$this->extracted_directory_path;
    }

    public function 
get_session_id() {
        return 
$this->session_id;
    }

    public function 
get_adapters() {
        return 
$this->adapters;
    }

    public function 
get_imported_data() {
        return 
$this->imported_data;
    }

    
/**
     * Get settings by key.
     * Used for backward compatibility.
     *
     * @param string $key The key of the setting.
     */
    
public function get_settings$key ) {
        switch ( 
$key ) {
            case 
'include':
                return 
$this->get_settings_include();

            case 
'overrideConditions':
                return 
$this->get_settings_selected_override_conditions();

            case 
'selectedCustomPostTypes':
                return 
$this->get_settings_selected_custom_post_types();

            case 
'plugins':
                return 
$this->get_settings_selected_plugins();

            default:
                return [];
        }
    }

    public function 
settings_include( array $settings_include ) {
        
$this->settings_include $settings_include;

        return 
$this;
    }

    public function 
get_settings_include() {
        return 
$this->settings_include;
    }

    public function 
settings_referrer$settings_referrer ) {
        
$this->settings_referrer $settings_referrer;

        return 
$this;
    }

    public function 
get_settings_referrer() {
        return 
$this->settings_referrer;
    }

    public function 
settings_conflicts( array $settings_conflicts ) {
        
$this->settings_conflicts $settings_conflicts;

        return 
$this;
    }

    public function 
get_settings_conflicts() {
        return 
$this->settings_conflicts;
    }

    public function 
settings_selected_override_conditions( array $settings_selected_override_conditions ) {
        
$this->settings_selected_override_conditions $settings_selected_override_conditions;

        return 
$this;
    }

    public function 
get_settings_selected_override_conditions() {
        return 
$this->settings_selected_override_conditions;
    }

    public function 
settings_selected_custom_post_types( array $settings_selected_custom_post_types ) {
        
$this->settings_selected_custom_post_types $settings_selected_custom_post_types;

        return 
$this;
    }

    public function 
get_settings_selected_custom_post_types() {
        return 
$this->settings_selected_custom_post_types;
    }

    public function 
settings_selected_plugins( array $settings_selected_plugins ) {
        
$this->settings_selected_plugins $settings_selected_plugins;

        return 
$this;
    }

    public function 
get_settings_selected_plugins() {
        return 
$this->settings_selected_plugins;
    }

    
/**
     * Prevent saving elements on elementor post creation.
     *
     * @param array $data
     * @param Document $document
     *
     * @return array
     */
    
public function prevent_saving_elements_on_post_creation( array $dataDocument $document ) {
        if ( isset( 
$data['elements'] ) ) {
            
$this->documents_data$document->get_main_id() ] = [ 'elements' => $data['elements'] ];

            
$data['elements'] = [];
        }

        if ( isset( 
$data['settings'] ) ) {
            
$this->documents_data$document->get_main_id() ]['settings'] = $data['settings'];

        }

        return 
$data;
    }

    
/**
     * Extract the zip file.
     *
     * @param string $zip_path The path to the zip file.
     * @return string The extracted directory path.
     */
    
private function extract_zip$zip_path ) {
        
$extraction_result Plugin::$instance->uploads_manager->extract_and_validate_zip$zip_path, [ 'json''xml' ] );

        if ( 
is_wp_error$extraction_result ) ) {
            if ( isset( 
$extraction_result->errors['zip_error'] ) ) {
                throw new 
\Error( static::ZIP_ARCHIVE_ERROR_KEY );
            }

            throw new 
\Error( static::ZIP_FILE_ERROR_KEY );
        }

        return 
$extraction_result['extraction_directory'];
    }

    
/**
     * Get the manifest file from the extracted directory and adapt it if needed.
     *
     * @return string The manifest file content.
     */
    
private function read_manifest_json() {
        
$manifest Utils::read_json_file$this->extracted_directory_path 'manifest' );

        if ( ! 
$manifest ) {
            
Plugin::$instance->logger->get_logger()->error( static::MANIFEST_ERROR_KEY );
            throw new 
\Error( static::ZIP_FILE_ERROR_KEY );
        }

        
$this->init_adapters$manifest );

        foreach ( 
$this->adapters as $adapter ) {
            
$manifest $adapter->adapt_manifest$manifest );
        }

        return 
$manifest;
    }

    
/**
     * Init the adapters and determine which ones to use.
     *
     * @param array $manifest_data The manifest file content.
     */
    
private function init_adapters( array $manifest_data ) {
        
$this->adapters = [];

        
/** @var Base_Adapter[] $adapter_types */
        
$adapter_types = [ Envato::class, Kit_Library::class ];

        foreach ( 
$adapter_types as $adapter_type ) {
            if ( 
$adapter_type::is_compatibility_needed$manifest_data, [ 'referrer' => $this->get_settings_referrer() ] ) ) {
                
$this->adapters[] = new $adapter_type$this );
            }
        }
    }

    
/**
     * Get the site settings file from the extracted directory and adapt it if needed.
     *
     * @return string The site settings file content.
     */
    
private function read_site_settings_json() {
        
$site_settings Utils::read_json_file$this->extracted_directory_path 'site-settings' );

        foreach ( 
$this->adapters as $adapter ) {
            
$site_settings $adapter->adapt_site_settings$site_settings$this->manifest$this->extracted_directory_path );
        }

        return 
$site_settings;
    }

    
/**
     * Get all the custom post types in the kit.
     *
     * @return array Custom post types names.
     */
    
private function get_default_settings_custom_post_types() {
        if ( empty( 
$this->manifest['custom-post-type-title'] ) ) {
            return [];
        }

        
$manifest_post_types array_keys$this->manifest['custom-post-type-title'] );

        return 
array_diff$manifest_post_typesUtils::get_builtin_wp_post_types() );
    }

    
/**
     * Get the default settings of elementor templates conditions to override.
     *
     * @return array
     */
    
private function get_default_settings_conflicts() {
        if ( empty( 
$this->manifest['templates'] ) ) {
            return [];
        }

        return 
apply_filters'elementor/import/get_default_settings_conflicts', [], $this->manifest['templates'] );
    }

    
/**
     * Get the default settings of elementor templates conditions to override.
     *
     * @return array
     */
    
private function get_default_settings_override_conditions() {
        if ( empty( 
$this->settings_conflicts ) ) {
            return [];
        }

        return 
array_keys$this->settings_conflicts );
    }

    
/**
     * Get the default settings of the plugins that should be imported.
     *
     * @return array
     */
    
private function get_default_settings_plugins() {
        return ! empty( 
$this->manifest['plugins'] ) ? $this->manifest['plugins'] : [];
    }

    
/**
     * Get the default settings of which content types should be imported.
     *
     * @return array
     */
    
private function get_default_settings_include() {
        return [ 
'templates''plugins''content''settings' ];
    }

    
/**
     * Get the data that requires updating/replacement when imported.
     *
     * @return array{post_ids: array, term_ids: array}
     */
    
private function get_imported_data_replacements() : array {
        return [
            
'post_ids' => Utils::map_old_new_post_ids$this->imported_data ),
            
'term_ids' => Utils::map_old_new_term_ids$this->imported_data ),
        ];
    }

    
/**
     * Save the prevented elements on elementor post creation elements.
     * Handle the replacement of all the dynamic content of the elements that probably have been changed during the import.
     */
    
private function save_elements_of_imported_posts() {
        
$imported_data_replacements $this->get_imported_data_replacements();

        foreach ( 
$this->documents_data as $new_id => $data ) {
            
$document Plugin::$instance->documents->get$new_id );

            if ( isset( 
$data['elements'] ) ) {
                
$data['elements'] = $document->on_import_update_dynamic_content$data['elements'], $imported_data_replacements );
            }

            if ( isset( 
$data['settings'] ) ) {

                if ( 
$document instanceof Kit ) {
                    
// Without post_status certain tabs in the Kit will not save properly.
                    
$data['settings']['post_status'] = get_post_status$new_id );
                }

                
$data['settings'] = $document->on_import_update_settings$data['settings'], $imported_data_replacements );
            }

            
$document->save$data );
        }
    }

    private function 
update_instance_data_in_import_session_option() {
        
$import_sessions Utils::get_import_sessions();

        
$import_sessions$this->session_id ]['instance_data']['documents_data'] = $this->documents_data;
        
$import_sessions$this->session_id ]['instance_data']['imported_data'] = $this->imported_data;
        
$import_sessions$this->session_id ]['instance_data']['runners_import_metadata'] = $this->runners_import_metadata;

        
update_optionModule::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS$import_sessionsfalse );
    }

    public function 
finalize_import_session_option() {
        
$import_sessions Utils::get_import_sessions();

        if ( ! isset( 
$import_sessions$this->session_id ] ) ) {
            return;
        }

        unset( 
$import_sessions$this->session_id ]['instance_data'] );

        
$import_sessions$this->session_id ]['end_timestamp'] = current_time'timestamp' );
        
$import_sessions$this->session_id ]['runners'] = $this->runners_import_metadata;

        
update_optionModule::OPTION_KEY_ELEMENTOR_IMPORT_SESSIONS$import_sessionsfalse );
    }

    
/**
     * Filter the php error args and return 408 status code if the error is a timeout.
     *
     * @param array $args
     * @param array $error
     * @return array
     */
    
private function filter_php_error_args$args$error ) {
        if ( 
strpos$error['message'], 'Maximum execution time' ) !== false ) {
            
$args['response'] = 408;
        }

        return 
$args;
    }
}