PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev5
Elementor Website Builder – more than just a page builder v4.0.0-dev5
4.3.0-beta3 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 All 452 releases
elementor / app / modules / import-export-customization / runners / import / wp-content.php

wp-content.php in Elementor Website Builder – more than just a page builder 4.0.0-dev5, at app/modules/import-export-customization/runners/import/wp-content.php

135 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\App\Modules\ImportExportCustomization\Runners\Import;
4
5 use Elementor\App\Modules\ImportExportCustomization\Utils as ImportExportUtils;
6 use Elementor\Core\Utils\ImportExport\WP_Import;
7
8 class Wp_Content extends Import_Runner_Base {
9
10 private $import_session_id;
11
12 /**
13 * @var array
14 */
15 private $selected_custom_post_types = [];
16
17 public static function get_name(): string {
18 return 'wp-content';
19 }
20
21 public function should_import( array $data ) {
22 return (
23 isset( $data['include'] ) &&
24 in_array( 'content', $data['include'], true ) &&
25 ! empty( $data['extracted_directory_path'] ) &&
26 ! empty( $data['manifest']['wp-content'] )
27 );
28 }
29
30 public function import( array $data, array $imported_data ) {
31 $this->import_session_id = $data['session_id'];
32
33 $path = $data['extracted_directory_path'] . 'wp-content/';
34
35 $post_types = $this->filter_post_types( $data );
36
37 $taxonomies = $imported_data['taxonomies'] ?? [];
38 $imported_terms = ImportExportUtils::map_old_new_term_ids( $imported_data );
39
40 $result['wp-content'] = [];
41
42 foreach ( $post_types as $post_type ) {
43 $import = $this->import_wp_post_type(
44 $path,
45 $post_type,
46 $imported_data,
47 $taxonomies,
48 $imported_terms,
49 $data['customization']['content'] ?? null
50 );
51
52 if ( empty( $import ) ) {
53 continue;
54 }
55
56 $result['wp-content'][ $post_type ] = $import;
57 $imported_data = array_merge( $imported_data, $result );
58 }
59
60 return $result;
61 }
62
63 private function import_wp_post_type( $path, $post_type, array $imported_data, array $taxonomies, array $imported_terms, $customization ) {
64 $args = [
65 'fetch_attachments' => true,
66 'posts' => ImportExportUtils::map_old_new_post_ids( $imported_data ),
67 'terms' => $imported_terms,
68 'taxonomies' => ! empty( $taxonomies[ $post_type ] ) ? $taxonomies[ $post_type ] : [],
69 'posts_meta' => [
70 static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID => $this->import_session_id,
71 ],
72 'terms_meta' => [
73 static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID => $this->import_session_id,
74 ],
75 'include' => 'page' === $post_type ? $customization['pages'] ?? null : null,
76 ];
77
78 $args = apply_filters( 'elementor/import-export-customization/import/wp-content/query-args/customization', $args, $post_type, $customization );
79
80 $file = $path . $post_type . '/' . $post_type . '.xml';
81
82 if ( ! file_exists( $file ) ) {
83 return [];
84 }
85
86 $wp_importer = new WP_Import( $file, $args );
87 $result = $wp_importer->run();
88
89 return $result['summary']['posts'];
90 }
91
92 private function filter_post_types( $data ) {
93 $selected_custom_post_types = $data['selected_custom_post_types'];
94 $customization = $data['customization']['content'] ?? null;
95
96 $wp_builtin_post_types = ImportExportUtils::get_builtin_wp_post_types( [ 'post' ] );
97
98 foreach ( $selected_custom_post_types as $custom_post_type ) {
99 if ( post_type_exists( $custom_post_type ) ) {
100 $this->selected_custom_post_types[] = $custom_post_type;
101 }
102 }
103
104 $post_types = array_merge( $wp_builtin_post_types, $this->selected_custom_post_types );
105
106 $post_types = apply_filters( 'elementor/import-export-customization/wp-content/post-types/customization', $post_types, $data, $customization );
107
108 $post_types = array_unique( $this->force_element_to_be_last_by_value( $post_types, 'nav_menu_item' ) );
109
110 return $post_types;
111 }
112
113 public function get_import_session_metadata(): array {
114 return [
115 'custom_post_types' => $this->selected_custom_post_types,
116 ];
117 }
118
119 /**
120 * @param array $base_array The array we want to relocate his element.
121 * @param mixed $element The value of the element in the array we want to shift to end of the array.
122 * @return mixed
123 */
124 private function force_element_to_be_last_by_value( array $base_array, $element ) {
125 $index = array_search( $element, $base_array, true );
126
127 if ( false !== $index ) {
128 unset( $base_array[ $index ] );
129 $base_array[] = $element;
130 }
131
132 return $base_array;
133 }
134 }
135