PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.0-dev3
Elementor Website Builder – more than just a page builder v4.0.0-dev3
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 / export / taxonomies.php

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

152 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App\Modules\ImportExportCustomization\Runners\Export;
3
4 use Elementor\App\Modules\ImportExportCustomization\Utils as ImportExportUtils;
5
6 class Taxonomies extends Export_Runner_Base {
7
8 public static function get_name(): string {
9 return 'taxonomies';
10 }
11
12 public function should_export( array $data ) {
13 return (
14 isset( $data['include'] ) &&
15 in_array( 'content', $data['include'], true )
16 );
17 }
18
19 public function export( array $data ) {
20 $customization = $data['customization']['content'] ?? null;
21 if ( $customization ) {
22 return $this->export_customization( $data, $customization );
23 }
24
25 return $this->export_all( $data );
26 }
27
28 public function export_customization( array $data, array $customization ) {
29 $result = apply_filters( 'elementor/import-export-customization/export/taxonomies/customization', null, $data, $customization, $this );
30
31 if ( is_array( $result ) ) {
32 return $result;
33 }
34
35 return $this->export_all( $data );
36 }
37
38 public function export_all( array $data ) {
39 $selected_custom_post_types = $data['customization']['content']['customPostTypes'] ?? null;
40 $exclude_post_types = [];
41
42 if ( is_array( $selected_custom_post_types ) && ! in_array( 'post', $selected_custom_post_types, true ) ) {
43 $exclude_post_types[] = 'post';
44 }
45
46 $wp_builtin_post_types = ImportExportUtils::get_builtin_wp_post_types( $exclude_post_types );
47
48 $post_types = is_array( $selected_custom_post_types )
49 ? array_merge( $wp_builtin_post_types, $selected_custom_post_types )
50 : $wp_builtin_post_types;
51
52 $export = $this->export_taxonomies( $post_types );
53
54 $manifest_data['taxonomies'] = $export['manifest'];
55
56 return [
57 'files' => $export['files'],
58 'manifest' => [
59 $manifest_data,
60 ],
61 ];
62 }
63
64 private function export_taxonomies( array $post_types ) {
65 $files = [];
66 $manifest = [];
67
68 $taxonomies = get_taxonomies();
69
70 foreach ( $taxonomies as $taxonomy ) {
71 $taxonomy_obj = get_taxonomy( $taxonomy );
72 $taxonomy_post_types = $taxonomy_obj->object_type;
73 $intersected_post_types = array_intersect( $taxonomy_post_types, $post_types );
74
75 if ( empty( $intersected_post_types ) ) {
76 continue;
77 }
78
79 $data = $this->export_terms( $taxonomy );
80
81 if ( empty( $data ) ) {
82 continue;
83 }
84
85 foreach ( $intersected_post_types as $post_type ) {
86 $manifest[ $post_type ][] = [
87 'name' => $taxonomy,
88 'label' => $taxonomy_obj->label,
89 ];
90 }
91
92 $files[] = [
93 'path' => 'taxonomies/' . $taxonomy,
94 'data' => $data,
95 ];
96 }
97
98 return [
99 'files' => $files,
100 'manifest' => $manifest,
101 ];
102 }
103
104 public function export_terms( $taxonomy ) {
105 $terms = get_terms( [
106 'taxonomy' => (array) $taxonomy,
107 'hide_empty' => false,
108 'get' => 'all',
109 ] );
110
111 $ordered_terms = $this->order_terms( $terms );
112
113 if ( empty( $ordered_terms ) ) {
114 return [];
115 }
116
117 $data = [];
118
119 foreach ( $ordered_terms as $term ) {
120 $data[] = [
121 'term_id' => $term->term_id,
122 'name' => $term->name,
123 'slug' => $term->slug,
124 'taxonomy' => $term->taxonomy,
125 'description' => $term->description,
126 'parent' => $term->parent,
127 ];
128 }
129
130 return $data;
131 }
132 /**
133 * Put terms in order with no child going before its parent.
134 */
135 private function order_terms( array $terms ) {
136 $ordered_terms = [];
137
138 while ( $term = array_shift( $terms ) ) {
139 $is_top_level = 0 === $term->parent;
140 $is_parent_exits = isset( $ordered_terms[ $term->parent ] );
141
142 if ( $is_top_level || $is_parent_exits ) {
143 $ordered_terms[ $term->term_id ] = $term;
144 } else {
145 $terms[] = $term;
146 }
147 }
148
149 return $ordered_terms;
150 }
151 }
152