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 +62 -43 2.8.0 → 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' => []
@@ -102,9 +105,9 @@
102 105
103 106 $fields['children']['custom_fields']['fields'] = apply_filters('iwp/exporter/taxonomy/custom_field_list', $fields['children']['custom_fields']['fields'], $this->taxonomy);
104 107 $fields = apply_filters('iwp/exporter/taxonomy/fields', $fields, $this->taxonomy);
105 108
106 - return $fields;
109 + return $this->parse_fields($fields);
107 110 }
108 111
109 112 public function have_records($exporter_id)
110 113 {
@@ -137,49 +140,15 @@
137 140 }
138 141
139 142 public function setup($i)
140 143 {
141 - $this->record = get_term($this->items[$i], '', ARRAY_A);
142 - $this->record['custom_fields'] = get_term_meta($this->record['term_id']);
143 - $this->record = $this->modify_custom_field_data($this->record, 'taxonomy');
144 + $term = get_term($this->items[$i], '', ARRAY_A);
144 145
145 - $parent = get_term($this->record['parent'], $this->taxonomy);
146 - if (!is_wp_error($parent)) {
147 - $this->record['parent'] = [
148 - 'term_id' => $parent->term_id,
149 - 'slug' => $parent->slug,
150 - 'name' => $parent->name,
151 - 'parent' => $parent->parent
152 - ];
153 - } else {
154 - $this->record['parent'] = [
155 - 'term_id' => '',
156 - 'slug' => '',
157 - 'name' => '',
158 - 'parent' => ''
159 - ];
160 - }
146 + // Remove WP_Term attribute name conflict
147 + $term['_parent'] = $term['parent'];
148 + unset($term['parent']);
161 149
162 - $ancestor_ids = get_ancestors($this->record['term_id'], $this->taxonomy, 'taxonomy');
163 - $ancestor_ids = array_reverse($ancestor_ids);
164 -
165 - $this->record['anscestors'] = [];
166 -
167 - if ($ancestor_ids) {
168 - foreach ($ancestor_ids as $ancestor_id) {
169 -
170 - $ancestor = get_term($ancestor_id, $this->taxonomy);
171 - if (!is_wp_error($ancestor)) {
172 - $this->record['anscestors'][] = [
173 - 'term_id' => $ancestor->term_id,
174 - 'slug' => $ancestor->slug,
175 - 'name' => $ancestor->name,
176 - 'parent' => $ancestor->parent
177 - ];
178 - }
179 - }
180 - }
181 -
150 + $this->record = new ExporterRecord($term, 'tax');
182 151 $this->record = apply_filters('iwp/exporter/taxonomy/setup_data', $this->record, $this->taxonomy);
183 152 return true;
184 153 }
185 154
@@ -249,6 +218,56 @@
249 218 }
250 219
251 220 $output = apply_filters('iwp/exporter/taxonomy/value', $output, $column, $record, $meta);
252 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;
253 272 }
254 273 }