PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.2
Elementor Website Builder – more than just a page builder v3.32.2
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 3.32.2, at app/modules/import-export-customization/runners/import/wp-content.php

140 lines 4.0 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 $exclude = [];
96
97 if ( ! empty( $selected_custom_post_types ) && in_array( 'post', $selected_custom_post_types, true ) ) {
98 $exclude[] = 'post';
99 }
100
101 $wp_builtin_post_types = ImportExportUtils::get_builtin_wp_post_types( $exclude );
102
103 foreach ( $selected_custom_post_types as $custom_post_type ) {
104 if ( post_type_exists( $custom_post_type ) ) {
105 $this->selected_custom_post_types[] = $custom_post_type;
106 }
107 }
108
109 $post_types = array_merge( $wp_builtin_post_types, $this->selected_custom_post_types );
110
111 $post_types = apply_filters( 'elementor/import-export-customization/wp-content/post-types/customization', $post_types, $data, $customization );
112
113 $post_types = $this->force_element_to_be_last_by_value( $post_types, 'nav_menu_item' );
114
115 return $post_types;
116 }
117
118 public function get_import_session_metadata(): array {
119 return [
120 'custom_post_types' => $this->selected_custom_post_types,
121 ];
122 }
123
124 /**
125 * @param $array array The array we want to relocate his element.
126 * @param $element mixed The value of the element in the array we want to shift to end of the array.
127 * @return mixed
128 */
129 private function force_element_to_be_last_by_value( array $array, $element ) {
130 $index = array_search( $element, $array, true );
131
132 if ( false !== $index ) {
133 unset( $array[ $index ] );
134 $array[] = $element;
135 }
136
137 return $array;
138 }
139 }
140