PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.15.0
Import WP – CSV & XML Import Export for WordPress v2.15.0
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
← All changes | class/Common/Exporter/Mapper/TaxMapper.php +74 -42 2.7.14 → 2.15.0 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 namespace ImportWP\Common\Exporter\Mapper;
4 4
5 +use ImportWP\Common\Exporter\ExporterRecord;
5 6 use ImportWP\Common\Exporter\MapperInterface;
6 7
7 8 class TaxMapper extends AbstractMapper implements MapperInterface
8 9 {
@@ -25,8 +26,10 @@
25 26
26 27 public function __construct($taxonomy)
27 28 {
28 29 $this->taxonomy = $taxonomy;
30 +
31 + add_filter('iwp/exporter_record/tax', [$this, 'get_record_data'], 10, 3);
29 32 }
30 33
31 34 public function get_fields()
32 35 {
@@ -42,9 +45,9 @@
42 45 'fields' => [],
43 46 'children' => [
44 47 'parent' => [
45 48 'key' => 'parent',
46 - 'label' => 'Parent',
49 + 'label' => __('Parent', 'jc-importer'),
47 50 'loop' => false,
48 51 'fields' => [],
49 52 'children' => []
50 53 ],
@@ -49,9 +52,9 @@
49 52 'children' => []
50 53 ],
51 54 'anscestors' => [
52 55 'key' => 'anscestors',
53 - 'label' => 'Anscestors',
56 + 'label' => __('Anscestors', 'jc-importer'),
54 57 'loop' => true,
55 58 'fields' => [],
56 59 'children' => []
57 60 ],
@@ -56,9 +59,9 @@
56 59 'children' => []
57 60 ],
58 61 'custom_fields' => [
59 62 'key' => 'custom_fields',
60 - 'label' => 'Custom Fields',
63 + 'label' => __('Custom Fields', 'jc-importer'),
61 64 'loop' => true,
62 65 'loop_fields' => ['meta_key', 'meta_value'],
63 66 'fields' => [],
64 67 'children' => []
@@ -71,10 +74,20 @@
71 74
72 75 // get taxonomy custom fields
73 76 global $wpdb;
74 77 $meta_fields = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_key FROM " . $wpdb->termmeta . " as tm INNER JOIN " . $wpdb->term_taxonomy . " as tt ON tm.term_id = tt.term_id WHERE tt.taxonomy = %s", [$this->taxonomy]));
78 + $custom_file_fields = apply_filters('iwp/exporter/taxonomy/custom_file_id_fields', []);
75 79 foreach ($meta_fields as $field) {
76 80 $fields['children']['custom_fields']['fields'][] = $field;
81 +
82 + if (in_array($field, $custom_file_fields)) {
83 + $fields['children']['custom_fields']['fields'][] = $field . '::id';
84 + $fields['children']['custom_fields']['fields'][] = $field . '::url';
85 + $fields['children']['custom_fields']['fields'][] = $field . '::title';
86 + $fields['children']['custom_fields']['fields'][] = $field . '::alt';
87 + $fields['children']['custom_fields']['fields'][] = $field . '::caption';
88 + $fields['children']['custom_fields']['fields'][] = $field . '::description';
89 + }
77 90 }
78 91
79 92 $fields['children']['parent']['fields'] = [
80 93 'term_id',
@@ -90,10 +103,11 @@
90 103 'parent'
91 104 ];
92 105
93 106 $fields['children']['custom_fields']['fields'] = apply_filters('iwp/exporter/taxonomy/custom_field_list', $fields['children']['custom_fields']['fields'], $this->taxonomy);
107 + $fields = apply_filters('iwp/exporter/taxonomy/fields', $fields, $this->taxonomy);
94 108
95 - return $fields;
109 + return $this->parse_fields($fields);
96 110 }
97 111
98 112 public function have_records($exporter_id)
99 113 {
@@ -126,48 +140,16 @@
126 140 }
127 141
128 142 public function setup($i)
129 143 {
130 - $this->record = get_term($this->items[$i], '', ARRAY_A);
131 - $this->record['custom_fields'] = get_term_meta($this->record['term_id']);
144 + $term = get_term($this->items[$i], '', ARRAY_A);
132 145
133 - $parent = get_term($this->record['parent'], $this->taxonomy);
134 - if (!is_wp_error($parent)) {
135 - $this->record['parent'] = [
136 - 'term_id' => $parent->term_id,
137 - 'slug' => $parent->slug,
138 - 'name' => $parent->name,
139 - 'parent' => $parent->parent
140 - ];
141 - } else {
142 - $this->record['parent'] = [
143 - 'term_id' => '',
144 - 'slug' => '',
145 - 'name' => '',
146 - 'parent' => ''
147 - ];
148 - }
146 + // Remove WP_Term attribute name conflict
147 + $term['_parent'] = $term['parent'];
148 + unset($term['parent']);
149 149
150 - $ancestor_ids = get_ancestors($this->record['term_id'], $this->taxonomy, 'taxonomy');
151 - $ancestor_ids = array_reverse($ancestor_ids);
152 -
153 - $this->record['anscestors'] = [];
154 -
155 - if ($ancestor_ids) {
156 - foreach ($ancestor_ids as $ancestor_id) {
157 -
158 - $ancestor = get_term($ancestor_id, $this->taxonomy);
159 - if (!is_wp_error($ancestor)) {
160 - $this->record['anscestors'][] = [
161 - 'term_id' => $ancestor->term_id,
162 - 'slug' => $ancestor->slug,
163 - 'name' => $ancestor->name,
164 - 'parent' => $ancestor->parent
165 - ];
166 - }
167 - }
168 - }
169 -
150 + $this->record = new ExporterRecord($term, 'tax');
151 + $this->record = apply_filters('iwp/exporter/taxonomy/setup_data', $this->record, $this->taxonomy);
170 152 return true;
171 153 }
172 154
173 155 public function get_field($column, $record, $meta)
@@ -236,6 +218,56 @@
236 218 }
237 219
238 220 $output = apply_filters('iwp/exporter/taxonomy/value', $output, $column, $record, $meta);
239 221 return $output;
222 + }
223 +
224 + public function get_record_data($value, $key, $record)
225 + {
226 + switch ($key) {
227 + case 'custom_fields':
228 + $value = get_term_meta($record['term_id']);
229 + $value = $this->modify_custom_field_data($value, 'taxonomy');
230 + break;
231 + case 'parent':
232 + $parent = get_term($record['_parent'], $this->taxonomy);
233 + if (!is_wp_error($parent)) {
234 + $value = [
235 + 'term_id' => $parent->term_id,
236 + 'slug' => $parent->slug,
237 + 'name' => $parent->name,
238 + 'parent' => $parent->parent
239 + ];
240 + } else {
241 + $value = [
242 + 'term_id' => '',
243 + 'slug' => '',
244 + 'name' => '',
245 + 'parent' => ''
246 + ];
247 + }
248 + break;
249 + case 'anscestors':
250 + $ancestor_ids = get_ancestors($record['term_id'], $this->taxonomy, 'taxonomy');
251 + $ancestor_ids = array_reverse($ancestor_ids);
252 +
253 + $value = [];
254 +
255 + if ($ancestor_ids) {
256 + foreach ($ancestor_ids as $ancestor_id) {
257 + $ancestor = get_term($ancestor_id, $this->taxonomy);
258 + if (!is_wp_error($ancestor)) {
259 + $value[] = [
260 + 'term_id' => $ancestor->term_id,
261 + 'slug' => $ancestor->slug,
262 + 'name' => $ancestor->name,
263 + 'parent' => $ancestor->parent
264 + ];
265 + }
266 + }
267 + }
268 + break;
269 + }
270 +
271 + return $value;
240 272 }
241 273 }