Merge lp:~paulgear/wordpress/wp-plugin-wordpress-importer-0.6.3 into lp:~canonical-sysadmins/wordpress/wp-plugin-wordpress-importer

Proposed by Paul Gear on 2017-09-20
Status: Merged
Merged at revision: 2
Proposed branch: lp:~paulgear/wordpress/wp-plugin-wordpress-importer-0.6.3
Merge into: lp:~canonical-sysadmins/wordpress/wp-plugin-wordpress-importer
Diff against target: 586 lines (+193/-64)
4 files modified
languages/wordpress-importer.pot (+56/-48)
parsers.php (+36/-9)
readme.txt (+11/-3)
wordpress-importer.php (+90/-4)
To merge this branch: bzr merge lp:~paulgear/wordpress/wp-plugin-wordpress-importer-0.6.3
Reviewer Review Type Date Requested Status
The Canonical Sysadmins 2017-09-20 Pending
Review via email: mp+331035@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'languages/wordpress-importer.pot'
2--- languages/wordpress-importer.pot 2015-05-07 02:17:14 +0000
3+++ languages/wordpress-importer.pot 2017-09-20 05:06:40 +0000
4@@ -1,18 +1,19 @@
5-# Copyright (C) 2011 WordPress Importer
6+# Copyright (C) 2016 WordPress Importer
7 # This file is distributed under the same license as the WordPress Importer package.
8 msgid ""
9 msgstr ""
10-"Project-Id-Version: WordPress Importer 0.5\n"
11-"Report-Msgid-Bugs-To: http://wordpress.org/tag/wordpress-importer\n"
12-"POT-Creation-Date: 2011-07-16 15:45:12+00:00\n"
13+"Project-Id-Version: WordPress Importer 0.6.3\n"
14+"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wordpress-"
15+"importer\n"
16+"POT-Creation-Date: 2016-08-19 13:28:24+00:00\n"
17 "MIME-Version: 1.0\n"
18 "Content-Type: text/plain; charset=UTF-8\n"
19 "Content-Transfer-Encoding: 8bit\n"
20-"PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
21+"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
22 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
23 "Language-Team: LANGUAGE <LL@li.org>\n"
24
25-#: parsers.php:42 parsers.php:63
26+#: parsers.php:42 parsers.php:72 parsers.php:80
27 msgid "There was an error when reading this WXR file"
28 msgstr ""
29
30@@ -22,49 +23,56 @@
31 "parser..."
32 msgstr ""
33
34-#: parsers.php:67 parsers.php:72 parsers.php:262 parsers.php:451
35+#: parsers.php:84 parsers.php:89 parsers.php:306 parsers.php:495
36 msgid ""
37 "This does not appear to be a WXR file, missing/invalid WXR version number"
38 msgstr ""
39
40-#: wordpress-importer.php:134 wordpress-importer.php:143
41-#: wordpress-importer.php:194 wordpress-importer.php:202
42+#: wordpress-importer.php:132 wordpress-importer.php:141
43+#: wordpress-importer.php:192 wordpress-importer.php:196
44+#: wordpress-importer.php:205
45 msgid "Sorry, there has been an error."
46 msgstr ""
47
48-#: wordpress-importer.php:135
49+#: wordpress-importer.php:133
50 msgid "The file does not exist, please try again."
51 msgstr ""
52
53-#: wordpress-importer.php:178
54+#: wordpress-importer.php:176
55 msgid "All done."
56 msgstr ""
57
58-#: wordpress-importer.php:178
59+#: wordpress-importer.php:176
60 msgid "Have fun!"
61 msgstr ""
62
63-#: wordpress-importer.php:179
64+#: wordpress-importer.php:177
65 msgid "Remember to update the passwords and roles of imported users."
66 msgstr ""
67
68-#: wordpress-importer.php:210
69+#: wordpress-importer.php:197
70+msgid ""
71+"The export file could not be found at <code>%s</code>. It is likely that "
72+"this was caused by a permissions problem."
73+msgstr ""
74+
75+#: wordpress-importer.php:213
76 msgid ""
77 "This WXR file (version %s) may not be supported by this version of the "
78 "importer. Please consider updating."
79 msgstr ""
80
81-#: wordpress-importer.php:235
82+#: wordpress-importer.php:238
83 msgid ""
84 "Failed to import author %s. Their posts will be attributed to the current "
85 "user."
86 msgstr ""
87
88-#: wordpress-importer.php:261
89+#: wordpress-importer.php:264
90 msgid "Assign Authors"
91 msgstr ""
92
93-#: wordpress-importer.php:262
94+#: wordpress-importer.php:265
95 msgid ""
96 "To make it easier for you to edit and save the imported content, you may "
97 "want to reassign the author of the imported item to an existing user of this "
98@@ -72,137 +80,137 @@
99 "code>s entries."
100 msgstr ""
101
102-#: wordpress-importer.php:264
103+#: wordpress-importer.php:267
104 msgid ""
105 "If a new user is created by WordPress, a new password will be randomly "
106 "generated and the new user&#8217;s role will be set as %s. Manually changing "
107 "the new user&#8217;s details will be necessary."
108 msgstr ""
109
110-#: wordpress-importer.php:274
111+#: wordpress-importer.php:277
112 msgid "Import Attachments"
113 msgstr ""
114
115-#: wordpress-importer.php:277
116+#: wordpress-importer.php:280
117 msgid "Download and import file attachments"
118 msgstr ""
119
120-#: wordpress-importer.php:281
121+#: wordpress-importer.php:284
122 msgid "Submit"
123 msgstr ""
124
125-#: wordpress-importer.php:294
126+#: wordpress-importer.php:297
127 msgid "Import author:"
128 msgstr ""
129
130-#: wordpress-importer.php:305
131+#: wordpress-importer.php:308
132 msgid "or create new user with login name:"
133 msgstr ""
134
135-#: wordpress-importer.php:308
136+#: wordpress-importer.php:311
137 msgid "as a new user:"
138 msgstr ""
139
140-#: wordpress-importer.php:316
141+#: wordpress-importer.php:319
142 msgid "assign posts to an existing user:"
143 msgstr ""
144
145-#: wordpress-importer.php:318
146+#: wordpress-importer.php:321
147 msgid "or assign posts to an existing user:"
148 msgstr ""
149
150-#: wordpress-importer.php:319
151+#: wordpress-importer.php:322
152 msgid "- Select -"
153 msgstr ""
154
155-#: wordpress-importer.php:369
156+#: wordpress-importer.php:372
157 msgid ""
158 "Failed to create new user for %s. Their posts will be attributed to the "
159 "current user."
160 msgstr ""
161
162-#: wordpress-importer.php:418
163+#: wordpress-importer.php:424
164 msgid "Failed to import category %s"
165 msgstr ""
166
167-#: wordpress-importer.php:456
168+#: wordpress-importer.php:467
169 msgid "Failed to import post tag %s"
170 msgstr ""
171
172-#: wordpress-importer.php:500 wordpress-importer.php:626
173+#: wordpress-importer.php:516 wordpress-importer.php:738
174 msgid "Failed to import %s %s"
175 msgstr ""
176
177-#: wordpress-importer.php:522
178+#: wordpress-importer.php:605
179 msgid "Failed to import &#8220;%s&#8221;: Invalid post type %s"
180 msgstr ""
181
182-#: wordpress-importer.php:543
183+#: wordpress-importer.php:642
184 msgid "%s &#8220;%s&#8221; already exists."
185 msgstr ""
186
187-#: wordpress-importer.php:598
188+#: wordpress-importer.php:704
189 msgid "Failed to import %s &#8220;%s&#8221;"
190 msgstr ""
191
192-#: wordpress-importer.php:744
193+#: wordpress-importer.php:869
194 msgid "Menu item skipped due to missing menu slug"
195 msgstr ""
196
197-#: wordpress-importer.php:751
198+#: wordpress-importer.php:876
199 msgid "Menu item skipped due to invalid menu slug: %s"
200 msgstr ""
201
202-#: wordpress-importer.php:814
203+#: wordpress-importer.php:939
204 msgid "Fetching attachments is not enabled"
205 msgstr ""
206
207-#: wordpress-importer.php:827
208+#: wordpress-importer.php:952
209 msgid "Invalid file type"
210 msgstr ""
211
212-#: wordpress-importer.php:871
213+#: wordpress-importer.php:996
214 msgid "Remote server did not respond"
215 msgstr ""
216
217-#: wordpress-importer.php:877
218+#: wordpress-importer.php:1002
219 msgid "Remote server returned error response %1$d %2$s"
220 msgstr ""
221
222-#: wordpress-importer.php:884
223+#: wordpress-importer.php:1009
224 msgid "Remote file is incorrect size"
225 msgstr ""
226
227-#: wordpress-importer.php:889
228+#: wordpress-importer.php:1014
229 msgid "Zero size file downloaded"
230 msgstr ""
231
232-#: wordpress-importer.php:895
233+#: wordpress-importer.php:1020
234 msgid "Remote file is too large, limit is %s"
235 msgstr ""
236
237-#: wordpress-importer.php:994
238+#: wordpress-importer.php:1119
239 msgid "Import WordPress"
240 msgstr ""
241
242-#: wordpress-importer.php:1001
243+#: wordpress-importer.php:1126
244 msgid ""
245 "A new version of this importer is available. Please update to version %s to "
246 "ensure compatibility with newer export files."
247 msgstr ""
248
249-#: wordpress-importer.php:1016
250+#: wordpress-importer.php:1141
251 msgid ""
252 "Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import "
253 "the posts, pages, comments, custom fields, categories, and tags into this "
254 "site."
255 msgstr ""
256
257-#: wordpress-importer.php:1017
258+#: wordpress-importer.php:1142
259 msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
260 msgstr ""
261
262-#: wordpress-importer.php:1091
263+#: wordpress-importer.php:1216
264 msgid ""
265 "Import <strong>posts, pages, comments, custom fields, categories, and tags</"
266 "strong> from a WordPress export file."
267
268=== modified file 'parsers.php'
269--- parsers.php 2015-05-07 02:17:14 +0000
270+++ parsers.php 2017-09-20 05:06:40 +0000
271@@ -114,28 +114,46 @@
272 // grab cats, tags and terms
273 foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) {
274 $t = $term_arr->children( $namespaces['wp'] );
275- $categories[] = array(
276+ $category = array(
277 'term_id' => (int) $t->term_id,
278 'category_nicename' => (string) $t->category_nicename,
279 'category_parent' => (string) $t->category_parent,
280 'cat_name' => (string) $t->cat_name,
281 'category_description' => (string) $t->category_description
282 );
283+
284+ foreach ( $t->termmeta as $meta ) {
285+ $category['termmeta'][] = array(
286+ 'key' => (string) $meta->meta_key,
287+ 'value' => (string) $meta->meta_value
288+ );
289+ }
290+
291+ $categories[] = $category;
292 }
293
294 foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) {
295 $t = $term_arr->children( $namespaces['wp'] );
296- $tags[] = array(
297+ $tag = array(
298 'term_id' => (int) $t->term_id,
299 'tag_slug' => (string) $t->tag_slug,
300 'tag_name' => (string) $t->tag_name,
301 'tag_description' => (string) $t->tag_description
302 );
303+
304+ foreach ( $t->termmeta as $meta ) {
305+ $tag['termmeta'][] = array(
306+ 'key' => (string) $meta->meta_key,
307+ 'value' => (string) $meta->meta_value
308+ );
309+ }
310+
311+ $tags[] = $tag;
312 }
313
314 foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) {
315 $t = $term_arr->children( $namespaces['wp'] );
316- $terms[] = array(
317+ $term = array(
318 'term_id' => (int) $t->term_id,
319 'term_taxonomy' => (string) $t->term_taxonomy,
320 'slug' => (string) $t->term_slug,
321@@ -143,6 +161,15 @@
322 'term_name' => (string) $t->term_name,
323 'term_description' => (string) $t->term_description
324 );
325+
326+ foreach ( $t->termmeta as $meta ) {
327+ $term['termmeta'][] = array(
328+ 'key' => (string) $meta->meta_key,
329+ 'value' => (string) $meta->meta_value
330+ );
331+ }
332+
333+ $terms[] = $term;
334 }
335
336 // grab posts
337@@ -204,7 +231,7 @@
338 );
339 }
340 }
341-
342+
343 $post['comments'][] = array(
344 'comment_id' => (int) $comment->comment_id,
345 'comment_author' => (string) $comment->comment_author,
346@@ -324,7 +351,11 @@
347 if ( ! trim( $cdata ) )
348 return;
349
350- $this->cdata .= trim( $cdata );
351+ if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
352+ $this->cdata .= $cdata;
353+ } else {
354+ $this->cdata .= trim( $cdata );
355+ }
356 }
357
358 function tag_close( $parser, $tag ) {
359@@ -401,10 +432,6 @@
360 var $terms = array();
361 var $base_url = '';
362
363- function WXR_Parser_Regex() {
364- $this->__construct();
365- }
366-
367 function __construct() {
368 $this->has_gzip = is_callable( 'gzopen' );
369 }
370
371=== modified file 'readme.txt'
372--- readme.txt 2015-05-07 02:17:14 +0000
373+++ readme.txt 2017-09-20 05:06:40 +0000
374@@ -1,10 +1,9 @@
375 === WordPress Importer ===
376 Contributors: wordpressdotorg
377-Donate link:
378 Tags: importer, wordpress
379 Requires at least: 3.0
380-Tested up to: 4.1
381-Stable tag: 0.6.1
382+Tested up to: 4.6
383+Stable tag: 0.6.3
384 License: GPLv2 or later
385 License URI: http://www.gnu.org/licenses/gpl-2.0.html
386
387@@ -39,6 +38,15 @@
388
389 == Changelog ==
390
391+= 0.6.3 =
392+* Add support for import term metadata.
393+* Fix bug that caused slashes to be stripped from imported content.
394+* Fix bug that caused characters to be stripped inside of CDATA in some cases.
395+* Fix PHP notices.
396+
397+= 0.6.2 =
398+* Add wp_import_existing_post filter. See: https://core.trac.wordpress.org/ticket/33721
399+
400 = 0.6 =
401 * Support for WXR 1.2 and multiple CDATA sections
402 * Post aren't duplicates if their post_type's are different
403
404=== modified file 'wordpress-importer.php'
405--- wordpress-importer.php 2015-05-07 02:17:14 +0000
406+++ wordpress-importer.php 2017-09-20 05:06:40 +0000
407@@ -5,7 +5,7 @@
408 Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
409 Author: wordpressdotorg
410 Author URI: http://wordpress.org/
411-Version: 0.6.1
412+Version: 0.6.3
413 Text Domain: wordpress-importer
414 License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
415 */
416@@ -63,8 +63,6 @@
417 var $url_remap = array();
418 var $featured_images = array();
419
420- function WP_Import() { /* nothing */ }
421-
422 /**
423 * Registered callback function for the WordPress Importer
424 *
425@@ -416,6 +414,7 @@
426 'cat_name' => $cat['cat_name'],
427 'category_description' => $category_description
428 );
429+ $catarr = wp_slash( $catarr );
430
431 $id = wp_insert_category( $catarr );
432 if ( ! is_wp_error( $id ) ) {
433@@ -428,6 +427,8 @@
434 echo '<br />';
435 continue;
436 }
437+
438+ $this->process_termmeta( $cat, $id['term_id'] );
439 }
440
441 unset( $this->categories );
442@@ -454,6 +455,7 @@
443 continue;
444 }
445
446+ $tag = wp_slash( $tag );
447 $tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
448 $tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc );
449
450@@ -468,6 +470,8 @@
451 echo '<br />';
452 continue;
453 }
454+
455+ $this->process_termmeta( $tag, $id['term_id'] );
456 }
457
458 unset( $this->tags );
459@@ -500,6 +504,7 @@
460 $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
461 if ( is_array( $parent ) ) $parent = $parent['term_id'];
462 }
463+ $term = wp_slash( $term );
464 $description = isset( $term['term_description'] ) ? $term['term_description'] : '';
465 $termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent) );
466
467@@ -514,12 +519,75 @@
468 echo '<br />';
469 continue;
470 }
471+
472+ $this->process_termmeta( $term, $id['term_id'] );
473 }
474
475 unset( $this->terms );
476 }
477
478 /**
479+ * Add metadata to imported term.
480+ *
481+ * @since 0.6.2
482+ *
483+ * @param array $term Term data from WXR import.
484+ * @param int $term_id ID of the newly created term.
485+ */
486+ protected function process_termmeta( $term, $term_id ) {
487+ if ( ! isset( $term['termmeta'] ) ) {
488+ $term['termmeta'] = array();
489+ }
490+
491+ /**
492+ * Filters the metadata attached to an imported term.
493+ *
494+ * @since 0.6.2
495+ *
496+ * @param array $termmeta Array of term meta.
497+ * @param int $term_id ID of the newly created term.
498+ * @param array $term Term data from the WXR import.
499+ */
500+ $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term );
501+
502+ if ( empty( $term['termmeta'] ) ) {
503+ return;
504+ }
505+
506+ foreach ( $term['termmeta'] as $meta ) {
507+ /**
508+ * Filters the meta key for an imported piece of term meta.
509+ *
510+ * @since 0.6.2
511+ *
512+ * @param string $meta_key Meta key.
513+ * @param int $term_id ID of the newly created term.
514+ * @param array $term Term data from the WXR import.
515+ */
516+ $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term );
517+ if ( ! $key ) {
518+ continue;
519+ }
520+
521+ // Export gets meta straight from the DB so could have a serialized string
522+ $value = maybe_unserialize( $meta['value'] );
523+
524+ add_term_meta( $term_id, $key, $value );
525+
526+ /**
527+ * Fires after term meta is imported.
528+ *
529+ * @since 0.6.2
530+ *
531+ * @param int $term_id ID of the newly created term.
532+ * @param string $key Meta key.
533+ * @param mixed $value Meta value.
534+ */
535+ do_action( 'import_term_meta', $term_id, $key, $value );
536+ }
537+ }
538+
539+ /**
540 * Create new posts based on import information
541 *
542 * Posts marked as having a parent which doesn't exist will become top level items.
543@@ -555,10 +623,26 @@
544 $post_type_object = get_post_type_object( $post['post_type'] );
545
546 $post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
547+
548+ /**
549+ * Filter ID of the existing post corresponding to post currently importing.
550+ *
551+ * Return 0 to force the post to be imported. Filter the ID to be something else
552+ * to override which existing post is mapped to the imported post.
553+ *
554+ * @see post_exists()
555+ * @since 0.6.2
556+ *
557+ * @param int $post_exists Post ID, or 0 if post did not exist.
558+ * @param array $post The post array to be inserted.
559+ */
560+ $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );
561+
562 if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) {
563 printf( __('%s &#8220;%s&#8221; already exists.', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']) );
564 echo '<br />';
565 $comment_post_ID = $post_id = $post_exists;
566+ $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists );
567 } else {
568 $post_parent = (int) $post['post_parent'];
569 if ( $post_parent ) {
570@@ -592,6 +676,8 @@
571 $original_post_ID = $post['post_id'];
572 $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
573
574+ $postdata = wp_slash( $postdata );
575+
576 if ( 'attachment' == $postdata['post_type'] ) {
577 $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
578
579@@ -1107,7 +1193,7 @@
580 * Added to http_request_timeout filter to force timeout at 60 seconds during import
581 * @return int 60
582 */
583- function bump_request_timeout() {
584+ function bump_request_timeout( $val ) {
585 return 60;
586 }
587

Subscribers

People subscribed via source and target branches