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/AbstractMapper.php +32 -10 2.8.0 → 2.15.0 View file →
@@ -10,8 +10,10 @@
10 10 public $items = [];
11 11
12 12 public function get_value($column, $template_data = null)
13 13 {
14 + // TODO: template_data should be class with arrayaccess to load data on demand.
15 +
14 16 if (is_null($template_data)) {
15 17 $template_data = $this->record();
16 18 }
17 19
@@ -64,8 +66,14 @@
64 66
65 67 foreach ($group as $row) {
66 68
67 69 $left = $this->get_value($row['left']);
70 +
71 + // left should always be a string
72 + if (is_array($left)) {
73 + $left = implode(',', $left);
74 + }
75 +
68 76 $right = $row['right'];
69 77 $right_parts = array_map('trim', explode(',', $right));
70 78
71 79 switch ($row['condition']) {
@@ -129,15 +137,15 @@
129 137 {
130 138 $this->items = $records;
131 139 }
132 140
133 - public function modify_custom_field_data($record, $type)
141 + public function modify_custom_field_data($custom_fields, $type)
134 142 {
135 143 $custom_file_fields = apply_filters('iwp/exporter/' . $type . '/custom_file_id_fields', []);
136 144 if (!empty($custom_file_fields)) {
137 145 foreach ($custom_file_fields as $custom_field) {
138 146
139 - if (!isset($record['custom_fields'][$custom_field]) && !empty($record['custom_fields'][$custom_field])) {
147 + if (!isset($custom_fields[$custom_field]) && !empty($custom_fields[$custom_field])) {
140 148 continue;
141 149 }
142 150
143 151 $data = [
@@ -148,9 +156,9 @@
148 156 'caption' => [],
149 157 'description' => [],
150 158 ];
151 159
152 - foreach ($record['custom_fields'][$custom_field] as $custom_field_value) {
160 + foreach ($custom_fields[$custom_field] as $custom_field_value) {
153 161
154 162 $custom_field_data = maybe_unserialize($custom_field_value);
155 163 if (is_string($custom_field_data)) {
156 164 $custom_field_data = explode(',', $custom_field_data);
@@ -178,16 +186,30 @@
178 186 $data['description'][] = $attachment['post_content'];
179 187 }
180 188 }
181 189
182 - $record['custom_fields'][$custom_field . '::id'] = $data['id'];
183 - $record['custom_fields'][$custom_field . '::url'] = $data['url'];
184 - $record['custom_fields'][$custom_field . '::title'] = $data['title'];
185 - $record['custom_fields'][$custom_field . '::alt'] = $data['alt'];
186 - $record['custom_fields'][$custom_field . '::caption'] = $data['caption'];
187 - $record['custom_fields'][$custom_field . '::description'] = $data['description'];
190 + $custom_fields[$custom_field . '::id'] = $data['id'];
191 + $custom_fields[$custom_field . '::url'] = $data['url'];
192 + $custom_fields[$custom_field . '::title'] = $data['title'];
193 + $custom_fields[$custom_field . '::alt'] = $data['alt'];
194 + $custom_fields[$custom_field . '::caption'] = $data['caption'];
195 + $custom_fields[$custom_field . '::description'] = $data['description'];
188 196 }
189 197 }
190 198
191 - return $record;
199 + return $custom_fields;
200 + }
201 +
202 + public function parse_fields($fields)
203 + {
204 + $fields['fields'] = isset($fields['fields']) ? array_values($fields['fields']) : [];
205 +
206 + if (isset($fields['children']) && !empty($fields['fields'])) {
207 +
208 + foreach ($fields['children'] as $child_id => $child_data) {
209 + $fields['children'][$child_id] = $this->parse_fields($child_data);
210 + }
211 + }
212 +
213 + return $fields;
192 214 }
193 215 }