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 +83 -0 2.7.14 → 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']) {
@@ -127,6 +135,81 @@
127 135
128 136 public function set_records($records)
129 137 {
130 138 $this->items = $records;
139 + }
140 +
141 + public function modify_custom_field_data($custom_fields, $type)
142 + {
143 + $custom_file_fields = apply_filters('iwp/exporter/' . $type . '/custom_file_id_fields', []);
144 + if (!empty($custom_file_fields)) {
145 + foreach ($custom_file_fields as $custom_field) {
146 +
147 + if (!isset($custom_fields[$custom_field]) && !empty($custom_fields[$custom_field])) {
148 + continue;
149 + }
150 +
151 + $data = [
152 + 'id' => [],
153 + 'url' => [],
154 + 'title' => [],
155 + 'alt' => [],
156 + 'caption' => [],
157 + 'description' => [],
158 + ];
159 +
160 + foreach ($custom_fields[$custom_field] as $custom_field_value) {
161 +
162 + $custom_field_data = maybe_unserialize($custom_field_value);
163 + if (is_string($custom_field_data)) {
164 + $custom_field_data = explode(',', $custom_field_data);
165 + }
166 +
167 + if (empty($custom_field_data)) {
168 + continue;
169 + }
170 +
171 + foreach ($custom_field_data as $possible_attachment_id) {
172 +
173 + $attachment_id = intval($possible_attachment_id);
174 + if ($attachment_id === 0) {
175 + continue;
176 + }
177 +
178 + $attachment = get_post($attachment_id, ARRAY_A);
179 + $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
180 +
181 + $data['id'][] = $attachment_id;
182 + $data['url'][] = wp_get_attachment_url($attachment_id);
183 + $data['title'][] = $attachment['post_title'];
184 + $data['alt'][] = $alt;
185 + $data['caption'][] = $attachment['post_excerpt'];
186 + $data['description'][] = $attachment['post_content'];
187 + }
188 + }
189 +
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'];
196 + }
197 + }
198 +
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;
131 214 }
132 215 }