Version Description
- 14th December 2022 =
- Fix - Improved importing
Download this release
Release Info
Developer | cyberchimps |
Plugin | Responsive Add Ons |
Version | 2.7.1 |
Comparing to | |
See all releases |
Code changes from version 2.7.0 to 2.7.1
- includes/importers/wxr-importer/class-wxr-importer.php +513 -745
- readme.txt +4 -1
- responsive-add-ons.php +2 -2
includes/importers/wxr-importer/class-wxr-importer.php
CHANGED
@@ -1,29 +1,11 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
* @package WXR Importer
|
6 |
-
*
|
7 |
-
* WordPress Importer
|
8 |
-
* https://github.com/humanmade/WordPress-Importer
|
9 |
-
*
|
10 |
-
* Released under the GNU General Public License v2.0
|
11 |
-
* https://github.com/humanmade/WordPress-Importer/blob/master/LICENSE
|
12 |
-
*/
|
13 |
-
|
14 |
-
/**
|
15 |
-
* WXR Importer
|
16 |
-
*/
|
17 |
-
if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
18 |
-
|
19 |
-
/**
|
20 |
-
* WXR Importer
|
21 |
-
*/
|
22 |
class WXR_Importer extends WP_Importer {
|
23 |
/**
|
24 |
* Maximum supported WXR version
|
25 |
*/
|
26 |
-
const MAX_WXR_VERSION =
|
27 |
|
28 |
/**
|
29 |
* Regular expression for checking if a post references an attachment
|
@@ -38,7 +20,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
38 |
|
|
39 |
# Match anything that looks like an upload URL
|
40 |
src=[\'"][^\'"]*(
|
41 |
-
[0-9]{4}/[0-9]{2}/[^\'"]+\.(jpg|jpeg|png|gif
|
42 |
|
|
43 |
content/uploads[^\'"]+
|
44 |
)[\'"]
|
@@ -54,110 +36,27 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
54 |
*/
|
55 |
protected $version = '1.0';
|
56 |
|
57 |
-
// information to import from WXR file
|
58 |
-
/**
|
59 |
-
* Categories
|
60 |
-
*
|
61 |
-
* @var array
|
62 |
-
*/
|
63 |
protected $categories = array();
|
64 |
-
|
65 |
-
/**
|
66 |
-
* Tags
|
67 |
-
*
|
68 |
-
* @var array
|
69 |
-
*/
|
70 |
protected $tags = array();
|
71 |
-
|
72 |
-
/**
|
73 |
-
* Base Url
|
74 |
-
*
|
75 |
-
* @var string
|
76 |
-
*/
|
77 |
protected $base_url = '';
|
78 |
|
79 |
-
// TODO: REMOVE THESE
|
80 |
-
/**
|
81 |
-
* Processed Terms
|
82 |
-
*
|
83 |
-
* @var array
|
84 |
-
*/
|
85 |
protected $processed_terms = array();
|
86 |
-
|
87 |
-
/**
|
88 |
-
* Processed Posts
|
89 |
-
*
|
90 |
-
* @var array
|
91 |
-
*/
|
92 |
protected $processed_posts = array();
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Processed Menu Items
|
96 |
-
*
|
97 |
-
* @var array
|
98 |
-
*/
|
99 |
protected $processed_menu_items = array();
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Menu Item Orphans
|
103 |
-
*
|
104 |
-
* @var array
|
105 |
-
*/
|
106 |
protected $menu_item_orphans = array();
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Missing Menu Items
|
110 |
-
*
|
111 |
-
* @var array
|
112 |
-
*/
|
113 |
protected $missing_menu_items = array();
|
114 |
|
115 |
-
|
116 |
-
// NEW STYLE.
|
117 |
-
/**
|
118 |
-
* Mapping
|
119 |
-
*
|
120 |
-
* @var array
|
121 |
-
*/
|
122 |
protected $mapping = array();
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Requires Remapping
|
126 |
-
*
|
127 |
-
* @var array
|
128 |
-
*/
|
129 |
protected $requires_remapping = array();
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Exists
|
133 |
-
*
|
134 |
-
* @var array
|
135 |
-
*/
|
136 |
protected $exists = array();
|
137 |
-
|
138 |
-
/**
|
139 |
-
* User Slug Override
|
140 |
-
*
|
141 |
-
* @var array
|
142 |
-
*/
|
143 |
protected $user_slug_override = array();
|
144 |
|
145 |
-
|
146 |
-
/**
|
147 |
-
* Url Remap
|
148 |
-
*
|
149 |
-
* @var array
|
150 |
-
*/
|
151 |
protected $url_remap = array();
|
152 |
-
|
153 |
-
/**
|
154 |
-
* Featured Images
|
155 |
-
*
|
156 |
-
* @var array
|
157 |
-
*/
|
158 |
protected $featured_images = array();
|
159 |
|
160 |
-
|
161 |
/**
|
162 |
* Logger instance.
|
163 |
*
|
@@ -168,18 +67,18 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
168 |
/**
|
169 |
* Constructor
|
170 |
*
|
171 |
-
* @param array $options {
|
172 |
-
* @var bool $prefill_existing_posts Should we prefill `post_exists` calls? (True prefills and uses more memory, false checks once per imported post and takes longer. Default is true.)
|
173 |
-
* @var bool $prefill_existing_comments Should we prefill `comment_exists` calls? (True prefills and uses more memory, false checks once per imported comment and takes longer. Default is true.)
|
174 |
-
* @var bool $prefill_existing_terms Should we prefill `term_exists` calls? (True prefills and uses more memory, false checks once per imported term and takes longer. Default is true.)
|
175 |
-
* @var bool $update_attachment_guids Should attachment GUIDs be updated to the new URL? (True updates the GUID, which keeps compatibility with v1, false doesn't update, and allows deduplication and reimporting. Default is false.)
|
176 |
-
* @var bool $fetch_attachments Fetch attachments from the remote server. (True fetches and creates attachment posts, false skips attachments. Default is false.)
|
177 |
-
* @var bool $aggressive_url_search Should we search/replace for URLs aggressively? (True searches all posts' content for old URLs and replaces, false checks for `<img class="wp-image-*">` only. Default is false.)
|
178 |
-
* @var int $default_author User ID to use if author is missing or invalid. (Default is null, which leaves posts unassigned.)
|
179 |
* }
|
180 |
*/
|
181 |
public function __construct( $options = array() ) {
|
182 |
-
// Initialize some important variables
|
183 |
$empty_types = array(
|
184 |
'post' => array(),
|
185 |
'comment' => array(),
|
@@ -187,31 +86,23 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
187 |
'user' => array(),
|
188 |
);
|
189 |
|
190 |
-
$this->mapping
|
191 |
$this->mapping['user_slug'] = array();
|
192 |
-
$this->mapping['term_id']
|
193 |
-
$this->requires_remapping
|
194 |
-
$this->exists
|
195 |
-
|
196 |
-
$this->options = wp_parse_args(
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
'default_author' => null,
|
206 |
-
)
|
207 |
-
);
|
208 |
}
|
209 |
|
210 |
-
/**
|
211 |
-
* Set Logger
|
212 |
-
*
|
213 |
-
* @param object $logger Logger object.
|
214 |
-
*/
|
215 |
public function set_logger( $logger ) {
|
216 |
$this->logger = $logger;
|
217 |
}
|
@@ -223,12 +114,19 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
223 |
* @return XMLReader|WP_Error Reader instance on success, error otherwise.
|
224 |
*/
|
225 |
protected function get_reader( $file ) {
|
226 |
-
// Avoid loading external entities for security
|
227 |
$old_value = null;
|
|
|
|
|
|
|
228 |
|
229 |
$reader = new XMLReader();
|
230 |
$status = $reader->open( $file );
|
231 |
|
|
|
|
|
|
|
|
|
232 |
if ( ! $status ) {
|
233 |
return new WP_Error( 'wxr_importer.cannot_parse', __( 'Could not open the file for parsing', 'wordpress-importer' ) );
|
234 |
}
|
@@ -239,43 +137,40 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
239 |
/**
|
240 |
* The main controller for the actual import stage.
|
241 |
*
|
242 |
-
* @param string $file Path to the WXR file for importing
|
243 |
*/
|
244 |
public function get_preliminary_information( $file ) {
|
245 |
-
// Let's run the actual importer now, woot
|
246 |
$reader = $this->get_reader( $file );
|
247 |
if ( is_wp_error( $reader ) ) {
|
248 |
return $reader;
|
249 |
}
|
250 |
|
251 |
-
// Set the version to compatibility mode first
|
252 |
$this->version = '1.0';
|
253 |
|
254 |
// Start parsing!
|
255 |
$data = new WXR_Import_Info();
|
256 |
while ( $reader->read() ) {
|
257 |
-
// Only deal with element opens
|
258 |
-
if (
|
259 |
continue;
|
260 |
}
|
261 |
|
262 |
switch ( $reader->name ) {
|
263 |
case 'wp:wxr_version':
|
264 |
-
// Upgrade to the correct version
|
265 |
$this->version = $reader->readString();
|
266 |
|
267 |
if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
|
268 |
-
$this->logger->warning(
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
self::MAX_WXR_VERSION
|
274 |
-
)
|
275 |
-
);
|
276 |
}
|
277 |
|
278 |
-
// Handled everything in this node, move on to the next
|
279 |
$reader->next();
|
280 |
break;
|
281 |
|
@@ -306,36 +201,36 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
306 |
if ( is_wp_error( $parsed ) ) {
|
307 |
$this->log_error( $parsed );
|
308 |
|
309 |
-
// Skip the rest of this post
|
310 |
$reader->next();
|
311 |
break;
|
312 |
}
|
313 |
|
314 |
$data->users[] = $parsed;
|
315 |
|
316 |
-
// Handled everything in this node, move on to the next
|
317 |
$reader->next();
|
318 |
break;
|
319 |
|
320 |
case 'item':
|
321 |
-
$node
|
322 |
$parsed = $this->parse_post_node( $node );
|
323 |
if ( is_wp_error( $parsed ) ) {
|
324 |
$this->log_error( $parsed );
|
325 |
|
326 |
-
// Skip the rest of this post
|
327 |
$reader->next();
|
328 |
break;
|
329 |
}
|
330 |
|
331 |
-
if (
|
332 |
$data->media_count++;
|
333 |
} else {
|
334 |
$data->post_count++;
|
335 |
}
|
336 |
$data->comment_count += count( $parsed['comments'] );
|
337 |
|
338 |
-
// Handled everything in this node, move on to the next
|
339 |
$reader->next();
|
340 |
break;
|
341 |
|
@@ -344,11 +239,11 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
344 |
case 'wp:term':
|
345 |
$data->term_count++;
|
346 |
|
347 |
-
// Handled everything in this node, move on to the next
|
348 |
$reader->next();
|
349 |
break;
|
350 |
-
}
|
351 |
-
}
|
352 |
|
353 |
$data->version = $this->version;
|
354 |
|
@@ -358,43 +253,40 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
358 |
/**
|
359 |
* The main controller for the actual import stage.
|
360 |
*
|
361 |
-
* @param string $file Path to the WXR file for importing
|
362 |
*/
|
363 |
public function parse_authors( $file ) {
|
364 |
-
// Let's run the actual importer now, woot
|
365 |
$reader = $this->get_reader( $file );
|
366 |
if ( is_wp_error( $reader ) ) {
|
367 |
return $reader;
|
368 |
}
|
369 |
|
370 |
-
// Set the version to compatibility mode first
|
371 |
$this->version = '1.0';
|
372 |
|
373 |
// Start parsing!
|
374 |
$authors = array();
|
375 |
while ( $reader->read() ) {
|
376 |
-
// Only deal with element opens
|
377 |
-
if (
|
378 |
continue;
|
379 |
}
|
380 |
|
381 |
switch ( $reader->name ) {
|
382 |
case 'wp:wxr_version':
|
383 |
-
// Upgrade to the correct version
|
384 |
$this->version = $reader->readString();
|
385 |
|
386 |
if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
|
387 |
-
$this->logger->warning(
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
self::MAX_WXR_VERSION
|
393 |
-
)
|
394 |
-
);
|
395 |
}
|
396 |
|
397 |
-
// Handled everything in this node, move on to the next
|
398 |
$reader->next();
|
399 |
break;
|
400 |
|
@@ -405,18 +297,18 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
405 |
if ( is_wp_error( $parsed ) ) {
|
406 |
$this->log_error( $parsed );
|
407 |
|
408 |
-
// Skip the rest of this post
|
409 |
$reader->next();
|
410 |
break;
|
411 |
}
|
412 |
|
413 |
$authors[] = $parsed;
|
414 |
|
415 |
-
// Handled everything in this node, move on to the next
|
416 |
$reader->next();
|
417 |
break;
|
418 |
}
|
419 |
-
}
|
420 |
|
421 |
return $authors;
|
422 |
}
|
@@ -424,7 +316,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
424 |
/**
|
425 |
* The main controller for the actual import stage.
|
426 |
*
|
427 |
-
* @param string $file Path to the WXR file for importing
|
428 |
*/
|
429 |
public function import( $file ) {
|
430 |
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
|
@@ -435,66 +327,63 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
435 |
return $result;
|
436 |
}
|
437 |
|
438 |
-
// Let's run the actual importer now, woot
|
439 |
$reader = $this->get_reader( $file );
|
440 |
if ( is_wp_error( $reader ) ) {
|
441 |
return $reader;
|
442 |
}
|
443 |
|
444 |
-
// Set the version to compatibility mode first
|
445 |
$this->version = '1.0';
|
446 |
|
447 |
-
// Reset other variables
|
448 |
$this->base_url = '';
|
449 |
|
450 |
// Start parsing!
|
451 |
while ( $reader->read() ) {
|
452 |
-
// Only deal with element opens
|
453 |
-
if (
|
454 |
continue;
|
455 |
}
|
456 |
|
457 |
switch ( $reader->name ) {
|
458 |
case 'wp:wxr_version':
|
459 |
-
// Upgrade to the correct version
|
460 |
$this->version = $reader->readString();
|
461 |
|
462 |
if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
|
463 |
-
$this->logger->warning(
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
self::MAX_WXR_VERSION
|
469 |
-
)
|
470 |
-
);
|
471 |
}
|
472 |
|
473 |
-
// Handled everything in this node, move on to the next
|
474 |
$reader->next();
|
475 |
break;
|
476 |
|
477 |
case 'wp:base_site_url':
|
478 |
$this->base_url = $reader->readString();
|
479 |
|
480 |
-
// Handled everything in this node, move on to the next
|
481 |
$reader->next();
|
482 |
break;
|
483 |
|
484 |
case 'item':
|
485 |
-
$node
|
486 |
$parsed = $this->parse_post_node( $node );
|
487 |
if ( is_wp_error( $parsed ) ) {
|
488 |
$this->log_error( $parsed );
|
489 |
|
490 |
-
// Skip the rest of this post
|
491 |
$reader->next();
|
492 |
break;
|
493 |
}
|
494 |
|
495 |
$this->process_post( $parsed['data'], $parsed['meta'], $parsed['comments'], $parsed['terms'] );
|
496 |
|
497 |
-
// Handled everything in this node, move on to the next
|
498 |
$reader->next();
|
499 |
break;
|
500 |
|
@@ -505,7 +394,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
505 |
if ( is_wp_error( $parsed ) ) {
|
506 |
$this->log_error( $parsed );
|
507 |
|
508 |
-
// Skip the rest of this post
|
509 |
$reader->next();
|
510 |
break;
|
511 |
}
|
@@ -515,7 +404,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
515 |
$this->log_error( $status );
|
516 |
}
|
517 |
|
518 |
-
// Handled everything in this node, move on to the next
|
519 |
$reader->next();
|
520 |
break;
|
521 |
|
@@ -526,14 +415,14 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
526 |
if ( is_wp_error( $parsed ) ) {
|
527 |
$this->log_error( $parsed );
|
528 |
|
529 |
-
// Skip the rest of this post
|
530 |
$reader->next();
|
531 |
break;
|
532 |
}
|
533 |
|
534 |
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
|
535 |
|
536 |
-
// Handled everything in this node, move on to the next
|
537 |
$reader->next();
|
538 |
break;
|
539 |
|
@@ -544,14 +433,14 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
544 |
if ( is_wp_error( $parsed ) ) {
|
545 |
$this->log_error( $parsed );
|
546 |
|
547 |
-
// Skip the rest of this post
|
548 |
$reader->next();
|
549 |
break;
|
550 |
}
|
551 |
|
552 |
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
|
553 |
|
554 |
-
// Handled everything in this node, move on to the next
|
555 |
$reader->next();
|
556 |
break;
|
557 |
|
@@ -562,22 +451,22 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
562 |
if ( is_wp_error( $parsed ) ) {
|
563 |
$this->log_error( $parsed );
|
564 |
|
565 |
-
// Skip the rest of this post
|
566 |
$reader->next();
|
567 |
break;
|
568 |
}
|
569 |
|
570 |
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
|
571 |
|
572 |
-
// Handled everything in this node, move on to the next
|
573 |
$reader->next();
|
574 |
break;
|
575 |
|
576 |
default:
|
577 |
-
// Skip this node, probably handled by something already
|
578 |
break;
|
579 |
-
}
|
580 |
-
}
|
581 |
|
582 |
// Now that we've done the main processing, do any required
|
583 |
// post-processing and remapping.
|
@@ -586,9 +475,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
586 |
if ( $this->options['aggressive_url_search'] ) {
|
587 |
$this->replace_attachment_urls_in_content();
|
588 |
}
|
589 |
-
// phpcs:disable
|
590 |
// $this->remap_featured_images();
|
591 |
-
// phpcs:enable
|
592 |
$this->import_end();
|
593 |
}
|
594 |
|
@@ -600,29 +487,29 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
600 |
protected function log_error( WP_Error $error ) {
|
601 |
$this->logger->warning( $error->get_error_message() );
|
602 |
|
603 |
-
// Log the data as debug info too
|
604 |
$data = $error->get_error_data();
|
605 |
if ( ! empty( $data ) ) {
|
606 |
-
$this->logger->debug( var_export( $data, true ) );
|
607 |
}
|
608 |
}
|
609 |
|
610 |
/**
|
611 |
* Parses the WXR file and prepares us for the task of processing parsed data
|
612 |
*
|
613 |
-
* @param string $file Path to the WXR file for importing
|
614 |
*/
|
615 |
protected function import_start( $file ) {
|
616 |
if ( ! is_file( $file ) ) {
|
617 |
return new WP_Error( 'wxr_importer.file_missing', __( 'The file does not exist, please try again.', 'wordpress-importer' ) );
|
618 |
}
|
619 |
|
620 |
-
// Suspend bunches of stuff in WP core
|
621 |
wp_defer_term_counting( true );
|
622 |
wp_defer_comment_counting( true );
|
623 |
wp_suspend_cache_invalidation( true );
|
624 |
|
625 |
-
// Prefill exists calls if told to
|
626 |
if ( $this->options['prefill_existing_posts'] ) {
|
627 |
$this->prefill_existing_posts();
|
628 |
}
|
@@ -646,7 +533,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
646 |
* Performs post-import cleanup of files and the cache
|
647 |
*/
|
648 |
protected function import_end() {
|
649 |
-
// Re-enable stuff in core
|
650 |
wp_suspend_cache_invalidation( false );
|
651 |
wp_cache_flush();
|
652 |
foreach ( get_taxonomies() as $tax ) {
|
@@ -669,13 +556,13 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
669 |
/**
|
670 |
* Set the user mapping.
|
671 |
*
|
672 |
-
* @param array $mapping List of map arrays (containing `old_slug`, `old_id`, `new_id`)
|
673 |
*/
|
674 |
public function set_user_mapping( $mapping ) {
|
675 |
foreach ( $mapping as $map ) {
|
676 |
if ( empty( $map['old_slug'] ) || empty( $map['old_id'] ) || empty( $map['new_id'] ) ) {
|
677 |
$this->logger->warning( __( 'Invalid author mapping', 'wordpress-importer' ) );
|
678 |
-
$this->logger->debug( var_export( $map, true ) );
|
679 |
continue;
|
680 |
}
|
681 |
|
@@ -708,71 +595,71 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
708 |
* @return array|WP_Error Post data array on success, error otherwise.
|
709 |
*/
|
710 |
protected function parse_post_node( $node ) {
|
711 |
-
$data
|
712 |
-
$meta
|
713 |
$comments = array();
|
714 |
-
$terms
|
715 |
|
716 |
-
foreach ( $node->childNodes as $child ) {
|
717 |
-
// We only care about child elements
|
718 |
-
if (
|
719 |
continue;
|
720 |
}
|
721 |
|
722 |
-
switch ( $child->tagName ) {
|
723 |
case 'wp:post_type':
|
724 |
-
$data['post_type'] = $child->textContent;
|
725 |
break;
|
726 |
|
727 |
case 'title':
|
728 |
-
$data['post_title'] = $child->textContent;
|
729 |
break;
|
730 |
|
731 |
case 'guid':
|
732 |
-
$data['guid'] = $child->textContent;
|
733 |
break;
|
734 |
|
735 |
case 'dc:creator':
|
736 |
-
$data['post_author'] = $child->textContent;
|
737 |
break;
|
738 |
|
739 |
case 'content:encoded':
|
740 |
-
$data['post_content'] = $child->textContent;
|
741 |
break;
|
742 |
|
743 |
case 'excerpt:encoded':
|
744 |
-
$data['post_excerpt'] = $child->textContent;
|
745 |
break;
|
746 |
|
747 |
case 'wp:post_id':
|
748 |
-
$data['post_id'] = $child->textContent;
|
749 |
break;
|
750 |
|
751 |
case 'wp:post_date':
|
752 |
-
$data['post_date'] = $child->textContent;
|
753 |
break;
|
754 |
|
755 |
case 'wp:post_date_gmt':
|
756 |
-
$data['post_date_gmt'] = $child->textContent;
|
757 |
break;
|
758 |
|
759 |
case 'wp:comment_status':
|
760 |
-
$data['comment_status'] = $child->textContent;
|
761 |
break;
|
762 |
|
763 |
case 'wp:ping_status':
|
764 |
-
$data['ping_status'] = $child->textContent;
|
765 |
break;
|
766 |
|
767 |
case 'wp:post_name':
|
768 |
-
$data['post_name'] = $child->textContent;
|
769 |
break;
|
770 |
|
771 |
case 'wp:status':
|
772 |
-
$data['post_status'] = $child->textContent;
|
773 |
|
774 |
-
if (
|
775 |
-
// Bail now
|
776 |
return new WP_Error(
|
777 |
'wxr_importer.post.cannot_import_draft',
|
778 |
__( 'Cannot import auto-draft posts' ),
|
@@ -782,23 +669,23 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
782 |
break;
|
783 |
|
784 |
case 'wp:post_parent':
|
785 |
-
$data['post_parent'] = $child->textContent;
|
786 |
break;
|
787 |
|
788 |
case 'wp:menu_order':
|
789 |
-
$data['menu_order'] = $child->textContent;
|
790 |
break;
|
791 |
|
792 |
case 'wp:post_password':
|
793 |
-
$data['post_password'] = $child->textContent;
|
794 |
break;
|
795 |
|
796 |
case 'wp:is_sticky':
|
797 |
-
$data['is_sticky'] = $child->textContent;
|
798 |
break;
|
799 |
|
800 |
case 'wp:attachment_url':
|
801 |
-
$data['attachment_url'] = $child->textContent;
|
802 |
break;
|
803 |
|
804 |
case 'wp:postmeta':
|
@@ -821,8 +708,8 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
821 |
$terms[] = $term_item;
|
822 |
}
|
823 |
break;
|
824 |
-
}
|
825 |
-
}
|
826 |
|
827 |
return compact( 'data', 'meta', 'comments', 'terms' );
|
828 |
}
|
@@ -834,11 +721,6 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
834 |
* Doesn't create a new post if: the post type doesn't exist, the given post ID
|
835 |
* is already noted as imported or a post with the same title and date already exists.
|
836 |
* Note that new/updated terms, comments and meta are imported for the last of the above.
|
837 |
-
*
|
838 |
-
* @param array $data Post data. (Return empty to skip.).
|
839 |
-
* @param array $meta Meta data.
|
840 |
-
* @param array $comments Comments on the post.
|
841 |
-
* @param array $terms Terms on the post.
|
842 |
*/
|
843 |
protected function process_post( $data, $meta, $comments, $terms ) {
|
844 |
/**
|
@@ -849,12 +731,12 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
849 |
* @param array $comments Comments on the post.
|
850 |
* @param array $terms Terms on the post.
|
851 |
*/
|
852 |
-
$data = apply_filters( 'wxr_importer.pre_process.post', $data, $meta, $comments, $terms );
|
853 |
if ( empty( $data ) ) {
|
854 |
return false;
|
855 |
}
|
856 |
|
857 |
-
$original_id = isset( $data['post_id'] )
|
858 |
$parent_id = isset( $data['post_parent'] ) ? (int) $data['post_parent'] : 0;
|
859 |
$author_id = isset( $data['post_author'] ) ? (int) $data['post_author'] : 0;
|
860 |
|
@@ -863,58 +745,47 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
863 |
return;
|
864 |
}
|
865 |
|
866 |
-
// If post status as 'dp-rewrite-republish' OR trash OR draft then skip.
|
867 |
-
if ( 'dp-rewrite-republish' === $data['post_status'] || 'draft' === $data['post_status'] || 'trash' === $data['post_status'] ) {
|
868 |
-
return;
|
869 |
-
}
|
870 |
-
|
871 |
$post_type_object = get_post_type_object( $data['post_type'] );
|
872 |
|
873 |
// Is this type even valid?
|
874 |
if ( ! $post_type_object ) {
|
875 |
-
$this->logger->warning(
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
$data['post_type']
|
881 |
-
)
|
882 |
-
);
|
883 |
return false;
|
884 |
}
|
885 |
|
886 |
$post_exists = $this->post_exists( $data );
|
887 |
if ( $post_exists ) {
|
888 |
-
$
|
889 |
-
/* translators: %1$s single post type, %2$s is post title. */
|
890 |
__( '%1$s "%2$s" already exists.', 'wordpress-importer' ),
|
891 |
$post_type_object->labels->singular_name,
|
892 |
$data['post_title']
|
893 |
-
);
|
894 |
-
|
895 |
-
$this->logger->info( $message );
|
896 |
|
897 |
/**
|
898 |
* Post processing already imported.
|
899 |
*
|
900 |
* @param array $data Raw data imported for the post.
|
901 |
*/
|
902 |
-
do_action( 'wxr_importer.process_already_imported.post', $data );
|
903 |
|
904 |
-
// Even though this post already exists, new comments might need importing
|
905 |
$this->process_comments( $comments, $original_id, $data, $post_exists );
|
906 |
|
907 |
return false;
|
908 |
}
|
909 |
|
910 |
-
// Map the parent post, or mark it as one we need to fix
|
911 |
$requires_remapping = false;
|
912 |
if ( $parent_id ) {
|
913 |
if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
|
914 |
$data['post_parent'] = $this->mapping['post'][ $parent_id ];
|
915 |
} else {
|
916 |
-
$meta[]
|
917 |
-
'key'
|
918 |
'value' => $parent_id,
|
919 |
);
|
920 |
$requires_remapping = true;
|
@@ -923,7 +794,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
923 |
}
|
924 |
}
|
925 |
|
926 |
-
// Map the author, or mark it as one we need to fix
|
927 |
$author = sanitize_user( $data['post_author'], true );
|
928 |
if ( empty( $author ) ) {
|
929 |
// Missing or invalid author, use default if available.
|
@@ -931,8 +802,8 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
931 |
} elseif ( isset( $this->mapping['user_slug'][ $author ] ) ) {
|
932 |
$data['post_author'] = $this->mapping['user_slug'][ $author ];
|
933 |
} else {
|
934 |
-
$meta[]
|
935 |
-
'key'
|
936 |
'value' => $author,
|
937 |
);
|
938 |
$requires_remapping = true;
|
@@ -942,18 +813,18 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
942 |
|
943 |
// Does the post look like it contains attachment images?
|
944 |
if ( preg_match( self::REGEX_HAS_ATTACHMENT_REFS, $data['post_content'] ) ) {
|
945 |
-
$meta[]
|
946 |
-
'key'
|
947 |
'value' => true,
|
948 |
);
|
949 |
$requires_remapping = true;
|
950 |
}
|
951 |
|
952 |
-
// Whitelist to just the keys we allow
|
953 |
$postdata = array(
|
954 |
'import_id' => $data['post_id'],
|
955 |
);
|
956 |
-
$allowed
|
957 |
'post_author' => true,
|
958 |
'post_date' => true,
|
959 |
'post_date_gmt' => true,
|
@@ -982,38 +853,32 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
982 |
|
983 |
if ( 'attachment' === $postdata['post_type'] ) {
|
984 |
if ( ! $this->options['fetch_attachments'] ) {
|
985 |
-
$this->logger->notice(
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
$data['post_title']
|
990 |
-
)
|
991 |
-
);
|
992 |
/**
|
993 |
* Post processing skipped.
|
994 |
*
|
995 |
* @param array $data Raw data imported for the post.
|
996 |
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
|
997 |
*/
|
998 |
-
do_action( 'wxr_importer.process_skipped.post', $data, $meta );
|
999 |
return false;
|
1000 |
}
|
1001 |
$remote_url = ! empty( $data['attachment_url'] ) ? $data['attachment_url'] : $data['guid'];
|
1002 |
-
$post_id
|
1003 |
} else {
|
1004 |
$post_id = wp_insert_post( $postdata, true );
|
1005 |
do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
|
1006 |
}
|
1007 |
|
1008 |
if ( is_wp_error( $post_id ) ) {
|
1009 |
-
$this->logger->error(
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
$post_type_object->labels->singular_name
|
1015 |
-
)
|
1016 |
-
);
|
1017 |
$this->logger->debug( $post_id->get_error_message() );
|
1018 |
|
1019 |
/**
|
@@ -1025,53 +890,47 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1025 |
* @param array $comments Raw comment data, already processed by {@see process_comments}.
|
1026 |
* @param array $terms Raw term data, already processed.
|
1027 |
*/
|
1028 |
-
do_action( 'wxr_importer.process_failed.post', $post_id, $data, $meta, $comments, $terms );
|
1029 |
return false;
|
1030 |
}
|
1031 |
|
1032 |
-
// Ensure stickiness is handled correctly too
|
1033 |
-
if (
|
1034 |
stick_post( $post_id );
|
1035 |
}
|
1036 |
|
1037 |
-
// map pre-import ID to local ID
|
1038 |
$this->mapping['post'][ $original_id ] = (int) $post_id;
|
1039 |
if ( $requires_remapping ) {
|
1040 |
$this->requires_remapping['post'][ $post_id ] = true;
|
1041 |
}
|
1042 |
$this->mark_post_exists( $data, $post_id );
|
1043 |
|
1044 |
-
$this->logger->info(
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
)
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
$original_id,
|
1057 |
-
$post_id
|
1058 |
-
)
|
1059 |
-
);
|
1060 |
-
|
1061 |
-
// Handle the terms too.
|
1062 |
$terms = apply_filters( 'wp_import_post_terms', $terms, $post_id, $data );
|
1063 |
|
1064 |
if ( ! empty( $terms ) ) {
|
1065 |
$term_ids = array();
|
1066 |
foreach ( $terms as $term ) {
|
1067 |
$taxonomy = $term['taxonomy'];
|
1068 |
-
$key
|
1069 |
|
1070 |
if ( isset( $this->mapping['term'][ $key ] ) ) {
|
1071 |
$term_ids[ $taxonomy ][] = (int) $this->mapping['term'][ $key ];
|
1072 |
} else {
|
1073 |
-
$meta[]
|
1074 |
-
'key'
|
1075 |
'value' => $term,
|
1076 |
);
|
1077 |
$requires_remapping = true;
|
@@ -1100,7 +959,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1100 |
* @param array $comments Raw comment data, already processed by {@see process_comments}.
|
1101 |
* @param array $terms Raw term data, already processed.
|
1102 |
*/
|
1103 |
-
do_action( 'wxr_importer.processed.post', $post_id, $data, $meta, $comments, $terms );
|
1104 |
}
|
1105 |
|
1106 |
/**
|
@@ -1111,15 +970,13 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1111 |
* represents doesn't exist then the menu item will not be imported (waits until the
|
1112 |
* end of the import to retry again before discarding).
|
1113 |
*
|
1114 |
-
* @param
|
1115 |
-
* @param array $data Raw data imported for the post.
|
1116 |
-
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
|
1117 |
*/
|
1118 |
protected function process_menu_item_meta( $post_id, $data, $meta ) {
|
1119 |
|
1120 |
-
$item_type
|
1121 |
$original_object_id = get_post_meta( $post_id, '_menu_item_object_id', true );
|
1122 |
-
$object_id
|
1123 |
|
1124 |
$this->logger->debug( sprintf( 'Processing menu item %s', $item_type ) );
|
1125 |
|
@@ -1149,7 +1006,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1149 |
break;
|
1150 |
|
1151 |
default:
|
1152 |
-
// associated object is missing or not imported yet, we'll retry later
|
1153 |
$this->missing_menu_items[] = $item;
|
1154 |
$this->logger->debug( 'Unknown menu item type' );
|
1155 |
break;
|
@@ -1171,17 +1028,16 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1171 |
/**
|
1172 |
* If fetching attachments is enabled then attempt to create a new attachment
|
1173 |
*
|
1174 |
-
* @param array $post Attachment post details from WXR
|
1175 |
-
* @param string $
|
1176 |
-
* @
|
1177 |
-
* @return int|WP_Error Post ID on success, WP_Error otherwise.
|
1178 |
*/
|
1179 |
protected function process_attachment( $post, $meta, $remote_url ) {
|
1180 |
// try to use _wp_attached file for upload folder placement to ensure the same location as the export site
|
1181 |
-
// e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
|
1182 |
$post['upload_date'] = $post['post_date'];
|
1183 |
foreach ( $meta as $meta_item ) {
|
1184 |
-
if (
|
1185 |
continue;
|
1186 |
}
|
1187 |
|
@@ -1191,7 +1047,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1191 |
break;
|
1192 |
}
|
1193 |
|
1194 |
-
// if the URL is absolute, but does not contain address, then upload it assuming base_site_url
|
1195 |
if ( preg_match( '|^/[\w\W]+$|', $remote_url ) ) {
|
1196 |
$remote_url = rtrim( $this->base_url, '/' ) . $remote_url;
|
1197 |
}
|
@@ -1209,11 +1065,12 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1209 |
$post['post_mime_type'] = $info['type'];
|
1210 |
|
1211 |
// WP really likes using the GUID for display. Allow updating it.
|
1212 |
-
// See https://core.trac.wordpress.org/ticket/33386
|
1213 |
if ( $this->options['update_attachment_guids'] ) {
|
1214 |
$post['guid'] = $upload['url'];
|
1215 |
}
|
1216 |
|
|
|
1217 |
$post_id = wp_insert_attachment( $post, $upload['file'] );
|
1218 |
if ( is_wp_error( $post_id ) ) {
|
1219 |
return $post_id;
|
@@ -1222,15 +1079,29 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1222 |
$attachment_metadata = wp_generate_attachment_metadata( $post_id, $upload['file'] );
|
1223 |
wp_update_attachment_metadata( $post_id, $attachment_metadata );
|
1224 |
|
1225 |
-
// Map this image URL later if we need to
|
1226 |
$this->url_remap[ $remote_url ] = $upload['url'];
|
1227 |
|
1228 |
-
// If we have a HTTPS URL, ensure the HTTP URL gets replaced too
|
1229 |
if ( substr( $remote_url, 0, 8 ) === 'https://' ) {
|
1230 |
-
$insecure_url
|
1231 |
$this->url_remap[ $insecure_url ] = $upload['url'];
|
1232 |
}
|
1233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1234 |
return $post_id;
|
1235 |
}
|
1236 |
|
@@ -1241,19 +1112,19 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1241 |
* @return array|null Meta data array on success, or null on error.
|
1242 |
*/
|
1243 |
protected function parse_meta_node( $node ) {
|
1244 |
-
foreach ( $node->childNodes as $child ) {
|
1245 |
-
// We only care about child elements
|
1246 |
-
if (
|
1247 |
continue;
|
1248 |
}
|
1249 |
|
1250 |
-
switch ( $child->tagName ) {
|
1251 |
case 'wp:meta_key':
|
1252 |
-
$key = $child->textContent;
|
1253 |
break;
|
1254 |
|
1255 |
case 'wp:meta_value':
|
1256 |
-
$value = $child->textContent;
|
1257 |
break;
|
1258 |
}
|
1259 |
}
|
@@ -1268,9 +1139,9 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1268 |
/**
|
1269 |
* Process and import post meta items.
|
1270 |
*
|
1271 |
-
* @param array $meta List of meta data arrays
|
1272 |
-
* @param int $post_id Post to associate with
|
1273 |
-
* @param array $post Post data
|
1274 |
* @return int|WP_Error Number of meta items imported on success, error otherwise.
|
1275 |
*/
|
1276 |
protected function process_post_meta( $meta, $post_id, $post ) {
|
@@ -1285,12 +1156,12 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1285 |
* @param array $meta_item Meta data. (Return empty to skip.)
|
1286 |
* @param int $post_id Post the meta is attached to.
|
1287 |
*/
|
1288 |
-
$meta_item = apply_filters( 'wxr_importer.pre_process.post_meta', $meta_item, $post_id );
|
1289 |
if ( empty( $meta_item ) ) {
|
1290 |
return false;
|
1291 |
}
|
1292 |
|
1293 |
-
$key
|
1294 |
$value = false;
|
1295 |
|
1296 |
if ( '_edit_last' === $key ) {
|
@@ -1304,7 +1175,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1304 |
}
|
1305 |
|
1306 |
if ( $key ) {
|
1307 |
-
// export gets meta straight from the DB so could have a serialized string
|
1308 |
if ( ! $value ) {
|
1309 |
$value = maybe_unserialize( $meta_item['value'] );
|
1310 |
}
|
@@ -1312,12 +1183,12 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1312 |
add_post_meta( $post_id, $key, $value );
|
1313 |
do_action( 'import_post_meta', $post_id, $key, $value );
|
1314 |
|
1315 |
-
// if the post has a featured image, take note of this in case of remap
|
1316 |
if ( '_thumbnail_id' === $key ) {
|
1317 |
$this->featured_images[ $post_id ] = (int) $value;
|
1318 |
}
|
1319 |
}
|
1320 |
-
}
|
1321 |
|
1322 |
return true;
|
1323 |
}
|
@@ -1333,58 +1204,58 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1333 |
'commentmeta' => array(),
|
1334 |
);
|
1335 |
|
1336 |
-
foreach ( $node->childNodes as $child ) {
|
1337 |
-
// We only care about child elements
|
1338 |
-
if (
|
1339 |
continue;
|
1340 |
}
|
1341 |
|
1342 |
-
switch ( $child->tagName ) {
|
1343 |
case 'wp:comment_id':
|
1344 |
-
$data['comment_id'] = $child->textContent;
|
1345 |
break;
|
1346 |
case 'wp:comment_author':
|
1347 |
-
$data['comment_author'] = $child->textContent;
|
1348 |
break;
|
1349 |
|
1350 |
case 'wp:comment_author_email':
|
1351 |
-
$data['comment_author_email'] = $child->textContent;
|
1352 |
break;
|
1353 |
|
1354 |
case 'wp:comment_author_IP':
|
1355 |
-
$data['comment_author_IP'] = $child->textContent;
|
1356 |
break;
|
1357 |
|
1358 |
case 'wp:comment_author_url':
|
1359 |
-
$data['comment_author_url'] = $child->textContent;
|
1360 |
break;
|
1361 |
|
1362 |
case 'wp:comment_user_id':
|
1363 |
-
$data['comment_user_id'] = $child->textContent;
|
1364 |
break;
|
1365 |
|
1366 |
case 'wp:comment_date':
|
1367 |
-
$data['comment_date'] = $child->textContent;
|
1368 |
break;
|
1369 |
|
1370 |
case 'wp:comment_date_gmt':
|
1371 |
-
$data['comment_date_gmt'] = $child->textContent;
|
1372 |
break;
|
1373 |
|
1374 |
case 'wp:comment_content':
|
1375 |
-
$data['comment_content'] = $child->textContent;
|
1376 |
break;
|
1377 |
|
1378 |
case 'wp:comment_approved':
|
1379 |
-
$data['comment_approved'] = $child->textContent;
|
1380 |
break;
|
1381 |
|
1382 |
case 'wp:comment_type':
|
1383 |
-
$data['comment_type'] = $child->textContent;
|
1384 |
break;
|
1385 |
|
1386 |
case 'wp:comment_parent':
|
1387 |
-
$data['comment_parent'] = $child->textContent;
|
1388 |
break;
|
1389 |
|
1390 |
case 'wp:commentmeta':
|
@@ -1393,8 +1264,8 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1393 |
$data['commentmeta'][] = $meta_item;
|
1394 |
}
|
1395 |
break;
|
1396 |
-
}
|
1397 |
-
}
|
1398 |
|
1399 |
return $data;
|
1400 |
}
|
@@ -1402,10 +1273,9 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1402 |
/**
|
1403 |
* Process and import comment data.
|
1404 |
*
|
1405 |
-
* @param array
|
1406 |
-
* @param int
|
1407 |
-
* @param array
|
1408 |
-
* @param boolean $post_exists Post exist status.
|
1409 |
* @return int|WP_Error Number of comments imported on success, error otherwise.
|
1410 |
*/
|
1411 |
protected function process_comments( $comments, $post_id, $post, $post_exists = false ) {
|
@@ -1417,7 +1287,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1417 |
|
1418 |
$num_comments = 0;
|
1419 |
|
1420 |
-
// Sort by ID to avoid excessive remapping later
|
1421 |
usort( $comments, array( $this, 'sort_comments_by_id' ) );
|
1422 |
|
1423 |
foreach ( $comments as $key => $comment ) {
|
@@ -1427,17 +1297,17 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1427 |
* @param array $comment Comment data. (Return empty to skip.)
|
1428 |
* @param int $post_id Post the comment is attached to.
|
1429 |
*/
|
1430 |
-
$comment = apply_filters( 'wxr_importer.pre_process.comment', $comment, $post_id );
|
1431 |
if ( empty( $comment ) ) {
|
1432 |
return false;
|
1433 |
}
|
1434 |
|
1435 |
-
$original_id = isset( $comment['comment_id'] )
|
1436 |
-
$parent_id = isset( $comment['comment_parent'] )
|
1437 |
$author_id = isset( $comment['comment_user_id'] ) ? (int) $comment['comment_user_id'] : 0;
|
1438 |
|
1439 |
// if this is a new post we can skip the comment_exists() check
|
1440 |
-
// TODO: Check comment_exists for performance
|
1441 |
if ( $post_exists ) {
|
1442 |
$existing = $this->comment_exists( $comment );
|
1443 |
if ( $existing ) {
|
@@ -1447,58 +1317,58 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1447 |
*
|
1448 |
* @param array $comment Raw data imported for the comment.
|
1449 |
*/
|
1450 |
-
do_action( 'wxr_importer.process_already_imported.comment', $comment );
|
1451 |
|
1452 |
$this->mapping['comment'][ $original_id ] = $existing;
|
1453 |
continue;
|
1454 |
}
|
1455 |
}
|
1456 |
|
1457 |
-
// Remove meta from the main array
|
1458 |
$meta = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
|
1459 |
unset( $comment['commentmeta'] );
|
1460 |
|
1461 |
-
// Map the parent comment, or mark it as one we need to fix
|
1462 |
$requires_remapping = false;
|
1463 |
if ( $parent_id ) {
|
1464 |
if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
|
1465 |
$comment['comment_parent'] = $this->mapping['comment'][ $parent_id ];
|
1466 |
} else {
|
1467 |
-
// Prepare for remapping later
|
1468 |
-
$meta[]
|
1469 |
-
'key'
|
1470 |
'value' => $parent_id,
|
1471 |
);
|
1472 |
$requires_remapping = true;
|
1473 |
|
1474 |
-
// Wipe the parent for now
|
1475 |
$comment['comment_parent'] = 0;
|
1476 |
}
|
1477 |
}
|
1478 |
|
1479 |
-
// Map the author, or mark it as one we need to fix
|
1480 |
if ( $author_id ) {
|
1481 |
if ( isset( $this->mapping['user'][ $author_id ] ) ) {
|
1482 |
$comment['user_id'] = $this->mapping['user'][ $author_id ];
|
1483 |
} else {
|
1484 |
-
// Prepare for remapping later
|
1485 |
-
$meta[]
|
1486 |
-
'key'
|
1487 |
'value' => $author_id,
|
1488 |
);
|
1489 |
$requires_remapping = true;
|
1490 |
|
1491 |
-
// Wipe the user for now
|
1492 |
$comment['user_id'] = 0;
|
1493 |
}
|
1494 |
}
|
1495 |
|
1496 |
-
// Run standard core filters
|
1497 |
$comment['comment_post_ID'] = $post_id;
|
1498 |
-
$comment
|
1499 |
|
1500 |
-
// wp_insert_comment expects slashed data
|
1501 |
-
$comment_id
|
1502 |
$this->mapping['comment'][ $original_id ] = $comment_id;
|
1503 |
if ( $requires_remapping ) {
|
1504 |
$this->requires_remapping['comment'][ $comment_id ] = true;
|
@@ -1515,7 +1385,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1515 |
*/
|
1516 |
do_action( 'wp_import_insert_comment', $comment_id, $comment, $post_id, $post );
|
1517 |
|
1518 |
-
// Process the meta items
|
1519 |
foreach ( $meta as $meta_item ) {
|
1520 |
$value = maybe_unserialize( $meta_item['value'] );
|
1521 |
add_comment_meta( $comment_id, wp_slash( $meta_item['key'] ), wp_slash( $value ) );
|
@@ -1529,23 +1399,17 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1529 |
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
|
1530 |
* @param array $post_id Parent post ID.
|
1531 |
*/
|
1532 |
-
do_action( 'wxr_importer.processed.comment', $comment_id, $comment, $meta, $post_id );
|
1533 |
|
1534 |
$num_comments++;
|
1535 |
-
}
|
1536 |
|
1537 |
return $num_comments;
|
1538 |
}
|
1539 |
|
1540 |
-
/**
|
1541 |
-
* Parse Category Node
|
1542 |
-
*
|
1543 |
-
* @param object $node Category Node.
|
1544 |
-
* @return array
|
1545 |
-
*/
|
1546 |
protected function parse_category_node( $node ) {
|
1547 |
$data = array(
|
1548 |
-
// Default taxonomy to "category", since this is a `<category>` tag
|
1549 |
'taxonomy' => 'category',
|
1550 |
);
|
1551 |
$meta = array();
|
@@ -1557,14 +1421,14 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1557 |
$data['slug'] = $node->getAttribute( 'nicename' );
|
1558 |
}
|
1559 |
|
1560 |
-
$data['name'] = $node->textContent;
|
1561 |
|
1562 |
if ( empty( $data['slug'] ) ) {
|
1563 |
return null;
|
1564 |
}
|
1565 |
|
1566 |
-
// Just for extra compatibility
|
1567 |
-
if (
|
1568 |
$data['taxonomy'] = 'post_tag';
|
1569 |
}
|
1570 |
|
@@ -1574,8 +1438,8 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1574 |
/**
|
1575 |
* Callback for `usort` to sort comments by ID
|
1576 |
*
|
1577 |
-
* @param array $a Comment data for the first comment
|
1578 |
-
* @param array $b Comment data for the second comment
|
1579 |
* @return int
|
1580 |
*/
|
1581 |
public static function sort_comments_by_id( $a, $b ) {
|
@@ -1590,44 +1454,38 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1590 |
return $a['comment_id'] - $b['comment_id'];
|
1591 |
}
|
1592 |
|
1593 |
-
/**
|
1594 |
-
* Parse Author Node
|
1595 |
-
*
|
1596 |
-
* @param object $node Author Node.
|
1597 |
-
* @return array
|
1598 |
-
*/
|
1599 |
protected function parse_author_node( $node ) {
|
1600 |
$data = array();
|
1601 |
$meta = array();
|
1602 |
-
foreach ( $node->childNodes as $child ) {
|
1603 |
-
// We only care about child elements
|
1604 |
-
if (
|
1605 |
continue;
|
1606 |
}
|
1607 |
|
1608 |
-
switch ( $child->tagName ) {
|
1609 |
case 'wp:author_login':
|
1610 |
-
$data['user_login'] = $child->textContent;
|
1611 |
break;
|
1612 |
|
1613 |
case 'wp:author_id':
|
1614 |
-
$data['ID'] = $child->textContent;
|
1615 |
break;
|
1616 |
|
1617 |
case 'wp:author_email':
|
1618 |
-
$data['user_email'] = $child->textContent;
|
1619 |
break;
|
1620 |
|
1621 |
case 'wp:author_display_name':
|
1622 |
-
$data['display_name'] = $child->textContent;
|
1623 |
break;
|
1624 |
|
1625 |
case 'wp:author_first_name':
|
1626 |
-
$data['first_name'] = $child->textContent;
|
1627 |
break;
|
1628 |
|
1629 |
case 'wp:author_last_name':
|
1630 |
-
$data['last_name'] = $child->textContent;
|
1631 |
break;
|
1632 |
}
|
1633 |
}
|
@@ -1635,13 +1493,6 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1635 |
return compact( 'data', 'meta' );
|
1636 |
}
|
1637 |
|
1638 |
-
/**
|
1639 |
-
* Process Author
|
1640 |
-
*
|
1641 |
-
* @param array $data User data. (Return empty to skip.).
|
1642 |
-
* @param array $meta Meta data.
|
1643 |
-
* @return boolean
|
1644 |
-
*/
|
1645 |
protected function process_author( $data, $meta ) {
|
1646 |
/**
|
1647 |
* Pre-process user data.
|
@@ -1649,19 +1500,19 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1649 |
* @param array $data User data. (Return empty to skip.)
|
1650 |
* @param array $meta Meta data.
|
1651 |
*/
|
1652 |
-
$data = apply_filters( 'wxr_importer.pre_process.user', $data, $meta );
|
1653 |
if ( empty( $data ) ) {
|
1654 |
return false;
|
1655 |
}
|
1656 |
|
1657 |
// Have we already handled this user?
|
1658 |
-
$original_id
|
1659 |
$original_slug = $data['user_login'];
|
1660 |
|
1661 |
if ( isset( $this->mapping['user'][ $original_id ] ) ) {
|
1662 |
$existing = $this->mapping['user'][ $original_id ];
|
1663 |
|
1664 |
-
// Note the slug mapping if we need to too
|
1665 |
if ( ! isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
|
1666 |
$this->mapping['user_slug'][ $original_slug ] = $existing;
|
1667 |
}
|
@@ -1672,21 +1523,21 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1672 |
if ( isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
|
1673 |
$existing = $this->mapping['user_slug'][ $original_slug ];
|
1674 |
|
1675 |
-
// Ensure we note the mapping too
|
1676 |
$this->mapping['user'][ $original_id ] = $existing;
|
1677 |
|
1678 |
return false;
|
1679 |
}
|
1680 |
|
1681 |
-
// Allow overriding the user's slug
|
1682 |
$login = $original_slug;
|
1683 |
if ( isset( $this->user_slug_override[ $login ] ) ) {
|
1684 |
$login = $this->user_slug_override[ $login ];
|
1685 |
}
|
1686 |
|
1687 |
$userdata = array(
|
1688 |
-
'user_login'
|
1689 |
-
'user_pass'
|
1690 |
);
|
1691 |
|
1692 |
$allowed = array(
|
@@ -1705,13 +1556,10 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1705 |
|
1706 |
$user_id = wp_insert_user( wp_slash( $userdata ) );
|
1707 |
if ( is_wp_error( $user_id ) ) {
|
1708 |
-
$this->logger->error(
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
$userdata['user_login']
|
1713 |
-
)
|
1714 |
-
);
|
1715 |
$this->logger->debug( $user_id->get_error_message() );
|
1716 |
|
1717 |
/**
|
@@ -1720,7 +1568,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1720 |
* @param WP_Error $user_id Error object.
|
1721 |
* @param array $userdata Raw data imported for the user.
|
1722 |
*/
|
1723 |
-
do_action( 'wxr_importer.process_failed.user', $user_id, $userdata );
|
1724 |
return false;
|
1725 |
}
|
1726 |
|
@@ -1729,39 +1577,26 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1729 |
}
|
1730 |
$this->mapping['user_slug'][ $original_slug ] = $user_id;
|
1731 |
|
1732 |
-
$this->logger->info(
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
)
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
$original_id,
|
1744 |
-
$user_id
|
1745 |
-
)
|
1746 |
-
);
|
1747 |
-
|
1748 |
-
// TODO: Implement meta handling once WXR includes it.
|
1749 |
/**
|
1750 |
* User processing completed.
|
1751 |
*
|
1752 |
* @param int $user_id New user ID.
|
1753 |
* @param array $userdata Raw data imported for the user.
|
1754 |
*/
|
1755 |
-
do_action( 'wxr_importer.processed.user', $user_id, $userdata );
|
1756 |
}
|
1757 |
|
1758 |
-
/**
|
1759 |
-
* Process Term
|
1760 |
-
*
|
1761 |
-
* @param object $node Term node.
|
1762 |
-
* @param string $type Term type.
|
1763 |
-
* @return array
|
1764 |
-
*/
|
1765 |
protected function parse_term_node( $node, $type = 'term' ) {
|
1766 |
$data = array();
|
1767 |
$meta = array();
|
@@ -1773,6 +1608,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1773 |
'parent' => 'wp:term_parent',
|
1774 |
'name' => 'wp:term_name',
|
1775 |
'description' => 'wp:term_description',
|
|
|
1776 |
);
|
1777 |
$taxonomy = null;
|
1778 |
|
@@ -1799,15 +1635,35 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1799 |
break;
|
1800 |
}
|
1801 |
|
1802 |
-
foreach ( $node->childNodes as $child ) {
|
1803 |
-
// We only care about child elements
|
1804 |
-
if (
|
1805 |
continue;
|
1806 |
}
|
1807 |
|
1808 |
-
$key = array_search( $child->tagName, $tag_name );
|
|
|
1809 |
if ( $key ) {
|
1810 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1811 |
}
|
1812 |
}
|
1813 |
|
@@ -1815,21 +1671,14 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1815 |
return null;
|
1816 |
}
|
1817 |
|
1818 |
-
// Compatibility with WXR 1.0
|
1819 |
-
if (
|
1820 |
$data['taxonomy'] = 'post_tag';
|
1821 |
}
|
1822 |
|
1823 |
return compact( 'data', 'meta' );
|
1824 |
}
|
1825 |
|
1826 |
-
/**
|
1827 |
-
* Process Term
|
1828 |
-
*
|
1829 |
-
* @param array $data Term data. (Return empty to skip.).
|
1830 |
-
* @param array $meta Meta data.
|
1831 |
-
* @return boolean
|
1832 |
-
*/
|
1833 |
protected function process_term( $data, $meta ) {
|
1834 |
/**
|
1835 |
* Pre-process term data.
|
@@ -1837,16 +1686,16 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1837 |
* @param array $data Term data. (Return empty to skip.)
|
1838 |
* @param array $meta Meta data.
|
1839 |
*/
|
1840 |
-
$data = apply_filters( 'wxr_importer.pre_process.term', $data, $meta );
|
1841 |
if ( empty( $data ) ) {
|
1842 |
return false;
|
1843 |
}
|
1844 |
|
1845 |
-
$original_id = isset( $data['id'] )
|
1846 |
-
$parent_id = isset( $data['parent'] )
|
1847 |
|
1848 |
$mapping_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
|
1849 |
-
$existing
|
1850 |
if ( $existing ) {
|
1851 |
|
1852 |
/**
|
@@ -1854,27 +1703,26 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1854 |
*
|
1855 |
* @param array $data Raw data imported for the term.
|
1856 |
*/
|
1857 |
-
do_action( 'wxr_importer.process_already_imported.term', $data );
|
1858 |
|
1859 |
-
$this->mapping['term'][ $mapping_key ]
|
1860 |
$this->mapping['term_id'][ $original_id ] = $existing;
|
1861 |
return false;
|
1862 |
}
|
1863 |
|
1864 |
-
// WP really likes to repeat itself in export files
|
1865 |
if ( isset( $this->mapping['term'][ $mapping_key ] ) ) {
|
1866 |
return false;
|
1867 |
}
|
1868 |
|
1869 |
$termdata = array();
|
1870 |
-
$allowed
|
1871 |
-
'slug'
|
1872 |
'description' => true,
|
1873 |
);
|
1874 |
|
1875 |
// Map the parent comment, or mark it as one we need to fix
|
1876 |
-
// TODO: add parent mapping and remapping
|
1877 |
-
// phpcs:disable
|
1878 |
/*
|
1879 |
$requires_remapping = false;
|
1880 |
if ( $parent_id ) {
|
@@ -1889,7 +1737,6 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1889 |
$data['parent'] = 0;
|
1890 |
}
|
1891 |
}*/
|
1892 |
-
// phpcs:enable
|
1893 |
|
1894 |
foreach ( $data as $key => $value ) {
|
1895 |
if ( ! isset( $allowed[ $key ] ) ) {
|
@@ -1901,14 +1748,11 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1901 |
|
1902 |
$result = wp_insert_term( $data['name'], $data['taxonomy'], $termdata );
|
1903 |
if ( is_wp_error( $result ) ) {
|
1904 |
-
$this->logger->warning(
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
$data['name']
|
1910 |
-
)
|
1911 |
-
);
|
1912 |
$this->logger->debug( $result->get_error_message() );
|
1913 |
do_action( 'wp_import_insert_term_failed', $result, $data );
|
1914 |
|
@@ -1919,31 +1763,29 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1919 |
* @param array $data Raw data imported for the term.
|
1920 |
* @param array $meta Meta data supplied for the term.
|
1921 |
*/
|
1922 |
-
do_action( 'wxr_importer.process_failed.term', $result, $data, $meta );
|
1923 |
return false;
|
1924 |
}
|
1925 |
|
1926 |
$term_id = $result['term_id'];
|
1927 |
|
1928 |
-
$
|
|
|
|
|
|
|
|
|
1929 |
$this->mapping['term_id'][ $original_id ] = $term_id;
|
1930 |
|
1931 |
-
$this->logger->info(
|
1932 |
-
|
1933 |
-
|
1934 |
-
|
1935 |
-
|
1936 |
-
|
1937 |
-
)
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
/* translators: %1$s is term original id, %2$s is term id. */
|
1942 |
-
__( 'Term %1$d remapped to %2$d', 'wordpress-importer' ),
|
1943 |
-
$original_id,
|
1944 |
-
$term_id
|
1945 |
-
)
|
1946 |
-
);
|
1947 |
|
1948 |
do_action( 'wp_import_insert_term', $term_id, $data );
|
1949 |
|
@@ -1953,36 +1795,33 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1953 |
* @param int $term_id New term ID.
|
1954 |
* @param array $data Raw data imported for the term.
|
1955 |
*/
|
1956 |
-
do_action( 'wxr_importer.processed.term', $term_id, $data );
|
1957 |
}
|
1958 |
|
1959 |
/**
|
1960 |
* Attempt to download a remote file attachment
|
1961 |
*
|
1962 |
-
* @param string $url URL of item to fetch
|
1963 |
-
* @param array $post Attachment details
|
1964 |
-
* @return array|WP_Error Local file location details on success, WP_Error otherwise
|
1965 |
*/
|
1966 |
protected function fetch_remote_file( $url, $post ) {
|
1967 |
-
// extract the file name and extension from the url
|
1968 |
$file_name = basename( $url );
|
1969 |
|
1970 |
-
// get placeholder file in the upload dir with a unique, sanitized filename
|
1971 |
-
$upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
|
1972 |
if ( $upload['error'] ) {
|
1973 |
return new WP_Error( 'upload_dir_error', $upload['error'] );
|
1974 |
}
|
1975 |
|
1976 |
-
// fetch the remote url and write it to the placeholder file
|
1977 |
-
$response = wp_remote_get(
|
1978 |
-
|
1979 |
-
|
1980 |
-
|
1981 |
-
'filename' => $upload['file'],
|
1982 |
-
)
|
1983 |
-
);
|
1984 |
|
1985 |
-
// request failed
|
1986 |
if ( is_wp_error( $response ) ) {
|
1987 |
unlink( $upload['file'] );
|
1988 |
return $response;
|
@@ -1990,13 +1829,12 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
1990 |
|
1991 |
$code = (int) wp_remote_retrieve_response_code( $response );
|
1992 |
|
1993 |
-
// make sure the fetch was successful
|
1994 |
-
if (
|
1995 |
unlink( $upload['file'] );
|
1996 |
return new WP_Error(
|
1997 |
'import_file_error',
|
1998 |
sprintf(
|
1999 |
-
/* translators: %1$s is error code, %2$s is error code header, %3$s is url. */
|
2000 |
__( 'Remote server returned %1$d %2$s for %3$s', 'wordpress-importer' ),
|
2001 |
$code,
|
2002 |
get_status_header_desc( $code ),
|
@@ -2006,7 +1844,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2006 |
}
|
2007 |
|
2008 |
$filesize = filesize( $upload['file'] );
|
2009 |
-
$headers
|
2010 |
|
2011 |
if ( isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) {
|
2012 |
unlink( $upload['file'] );
|
@@ -2021,7 +1859,6 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2021 |
$max_size = (int) $this->max_attachment_size();
|
2022 |
if ( ! empty( $max_size ) && $filesize > $max_size ) {
|
2023 |
unlink( $upload['file'] );
|
2024 |
-
/* translators: %s max file size. */
|
2025 |
$message = sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) );
|
2026 |
return new WP_Error( 'import_file_error', $message );
|
2027 |
}
|
@@ -2029,36 +1866,28 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2029 |
return $upload;
|
2030 |
}
|
2031 |
|
2032 |
-
/**
|
2033 |
-
* Post process
|
2034 |
-
*/
|
2035 |
protected function post_process() {
|
2036 |
-
// Time to tackle any left-over bits
|
2037 |
if ( ! empty( $this->requires_remapping['post'] ) ) {
|
2038 |
$this->post_process_posts( $this->requires_remapping['post'] );
|
2039 |
}
|
2040 |
if ( ! empty( $this->requires_remapping['comment'] ) ) {
|
2041 |
$this->post_process_comments( $this->requires_remapping['comment'] );
|
2042 |
}
|
|
|
|
|
|
|
|
|
2043 |
}
|
2044 |
|
2045 |
-
/**
|
2046 |
-
* Post Process Posts
|
2047 |
-
*
|
2048 |
-
* @param array $todo Todo items.
|
2049 |
-
* @return void
|
2050 |
-
*/
|
2051 |
protected function post_process_posts( $todo ) {
|
2052 |
foreach ( $todo as $post_id => $_ ) {
|
2053 |
-
$this->logger->debug(
|
2054 |
-
|
2055 |
-
|
2056 |
-
|
2057 |
-
|
2058 |
-
|
2059 |
-
$post_id
|
2060 |
-
)
|
2061 |
-
);
|
2062 |
|
2063 |
$data = array();
|
2064 |
|
@@ -2068,22 +1897,16 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2068 |
if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
|
2069 |
$data['post_parent'] = $this->mapping['post'][ $parent_id ];
|
2070 |
} else {
|
2071 |
-
$this->logger->warning(
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
2075 |
-
|
2076 |
-
|
2077 |
-
)
|
2078 |
-
|
2079 |
-
|
2080 |
-
|
2081 |
-
/* translators: %1$d is post id, %2$d is parent post id. */
|
2082 |
-
__( 'Post %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
|
2083 |
-
$post_id,
|
2084 |
-
$parent_id
|
2085 |
-
)
|
2086 |
-
);
|
2087 |
}
|
2088 |
}
|
2089 |
|
@@ -2093,31 +1916,25 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2093 |
if ( isset( $this->mapping['user_slug'][ $author_slug ] ) ) {
|
2094 |
$data['post_author'] = $this->mapping['user_slug'][ $author_slug ];
|
2095 |
} else {
|
2096 |
-
$this->logger->warning(
|
2097 |
-
|
2098 |
-
|
2099 |
-
|
2100 |
-
|
2101 |
-
|
2102 |
-
)
|
2103 |
-
|
2104 |
-
|
2105 |
-
|
2106 |
-
/* translators: %1$d is post id, %2$s is author slug. */
|
2107 |
-
__( 'Post %1$d was imported with author "%2$s", but could not be found', 'wordpress-importer' ),
|
2108 |
-
$post_id,
|
2109 |
-
$author_slug
|
2110 |
-
)
|
2111 |
-
);
|
2112 |
}
|
2113 |
}
|
2114 |
|
2115 |
$has_attachments = get_post_meta( $post_id, '_wxr_import_has_attachment_refs', true );
|
2116 |
if ( ! empty( $has_attachments ) ) {
|
2117 |
-
$post
|
2118 |
$content = $post->post_content;
|
2119 |
|
2120 |
-
// Replace all the URLs we've got
|
2121 |
$new_content = str_replace( array_keys( $this->url_remap ), $this->url_remap, $content );
|
2122 |
if ( $new_content !== $content ) {
|
2123 |
$data['post_content'] = $new_content;
|
@@ -2130,48 +1947,33 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2130 |
|
2131 |
// Do we have updates to make?
|
2132 |
if ( empty( $data ) ) {
|
2133 |
-
$this->logger->debug(
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
$post_id
|
2138 |
-
)
|
2139 |
-
);
|
2140 |
continue;
|
2141 |
}
|
2142 |
|
2143 |
-
// Run the update
|
2144 |
$data['ID'] = $post_id;
|
2145 |
-
|
2146 |
-
$data = wp_slash( $data );
|
2147 |
-
|
2148 |
$result = wp_update_post( $data, true );
|
2149 |
if ( is_wp_error( $result ) ) {
|
2150 |
-
$this->logger->warning(
|
2151 |
-
|
2152 |
-
|
2153 |
-
|
2154 |
-
|
2155 |
-
$post_id
|
2156 |
-
)
|
2157 |
-
);
|
2158 |
$this->logger->debug( $result->get_error_message() );
|
2159 |
continue;
|
2160 |
}
|
2161 |
|
2162 |
-
// Clear out our temporary meta keys
|
2163 |
delete_post_meta( $post_id, '_wxr_import_parent' );
|
2164 |
delete_post_meta( $post_id, '_wxr_import_user_slug' );
|
2165 |
delete_post_meta( $post_id, '_wxr_import_has_attachment_refs' );
|
2166 |
-
}
|
2167 |
}
|
2168 |
|
2169 |
-
/**
|
2170 |
-
* Post process menu item
|
2171 |
-
*
|
2172 |
-
* @param int $post_id Post id.
|
2173 |
-
* @return mixed
|
2174 |
-
*/
|
2175 |
protected function post_process_menu_item( $post_id ) {
|
2176 |
$menu_object_id = get_post_meta( $post_id, '_wxr_import_menu_item', true );
|
2177 |
if ( empty( $menu_object_id ) ) {
|
@@ -2201,35 +2003,23 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2201 |
if ( ! empty( $menu_object ) ) {
|
2202 |
update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $menu_object ) );
|
2203 |
} else {
|
2204 |
-
$this->logger->warning(
|
2205 |
-
|
2206 |
-
|
2207 |
-
|
2208 |
-
|
2209 |
-
|
2210 |
-
)
|
2211 |
-
|
2212 |
-
|
2213 |
-
|
2214 |
-
|
2215 |
-
__( 'Post %1$d was imported with object "%2$d" of type "%3$s", but could not be found', 'wordpress-importer' ),
|
2216 |
-
$post_id,
|
2217 |
-
$menu_object_id,
|
2218 |
-
$menu_item_type
|
2219 |
-
)
|
2220 |
-
);
|
2221 |
}
|
2222 |
|
2223 |
delete_post_meta( $post_id, '_wxr_import_menu_item' );
|
2224 |
}
|
2225 |
|
2226 |
|
2227 |
-
/**
|
2228 |
-
* Post process comments
|
2229 |
-
*
|
2230 |
-
* @param array $todo Todo items.
|
2231 |
-
* @return void
|
2232 |
-
*/
|
2233 |
protected function post_process_comments( $todo ) {
|
2234 |
foreach ( $todo as $comment_id => $_ ) {
|
2235 |
$data = array();
|
@@ -2240,21 +2030,15 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2240 |
if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
|
2241 |
$data['comment_parent'] = $this->mapping['comment'][ $parent_id ];
|
2242 |
} else {
|
2243 |
-
$this->logger->warning(
|
2244 |
-
|
2245 |
-
|
2246 |
-
|
2247 |
-
|
2248 |
-
)
|
2249 |
-
|
2250 |
-
|
2251 |
-
|
2252 |
-
/* translators: %1$s is comment id, %2$s is parent comment id. */
|
2253 |
-
__( 'Comment %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
|
2254 |
-
$comment_id,
|
2255 |
-
$parent_id
|
2256 |
-
)
|
2257 |
-
);
|
2258 |
}
|
2259 |
}
|
2260 |
|
@@ -2264,21 +2048,15 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2264 |
if ( isset( $this->mapping['user'][ $author_id ] ) ) {
|
2265 |
$data['user_id'] = $this->mapping['user'][ $author_id ];
|
2266 |
} else {
|
2267 |
-
$this->logger->warning(
|
2268 |
-
|
2269 |
-
|
2270 |
-
|
2271 |
-
|
2272 |
-
)
|
2273 |
-
|
2274 |
-
|
2275 |
-
|
2276 |
-
/* translators: %1$d is comment id, %2$d is author id. */
|
2277 |
-
__( 'Comment %1$d was imported with author %2$d, but could not be found', 'wordpress-importer' ),
|
2278 |
-
$comment_id,
|
2279 |
-
$author_id
|
2280 |
-
)
|
2281 |
-
);
|
2282 |
}
|
2283 |
}
|
2284 |
|
@@ -2287,24 +2065,21 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2287 |
continue;
|
2288 |
}
|
2289 |
|
2290 |
-
// Run the update
|
2291 |
-
$data['comment_ID'] = $comment_ID;
|
2292 |
-
$result
|
2293 |
if ( empty( $result ) ) {
|
2294 |
-
$this->logger->warning(
|
2295 |
-
|
2296 |
-
|
2297 |
-
|
2298 |
-
$comment_id
|
2299 |
-
)
|
2300 |
-
);
|
2301 |
continue;
|
2302 |
}
|
2303 |
|
2304 |
-
// Clear out our temporary meta keys
|
2305 |
delete_comment_meta( $comment_id, '_wxr_import_parent' );
|
2306 |
delete_comment_meta( $comment_id, '_wxr_import_user' );
|
2307 |
-
}
|
2308 |
}
|
2309 |
|
2310 |
/**
|
@@ -2312,30 +2087,30 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2312 |
*/
|
2313 |
protected function replace_attachment_urls_in_content() {
|
2314 |
global $wpdb;
|
2315 |
-
// make sure we do the longest urls first, in case one is a substring of another
|
2316 |
uksort( $this->url_remap, array( $this, 'cmpr_strlen' ) );
|
2317 |
|
2318 |
foreach ( $this->url_remap as $from_url => $to_url ) {
|
2319 |
-
// remap urls in post_content
|
2320 |
$query = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url );
|
2321 |
-
$wpdb->query( $query );
|
2322 |
|
2323 |
-
// remap enclosure urls
|
2324 |
-
$query
|
2325 |
-
$result = $wpdb->query( $query );
|
2326 |
}
|
2327 |
}
|
2328 |
|
2329 |
/**
|
2330 |
* Update _thumbnail_id meta to new, imported attachment IDs
|
2331 |
*/
|
2332 |
-
|
2333 |
-
// cycle through posts that have a featured image
|
2334 |
foreach ( $this->featured_images as $post_id => $value ) {
|
2335 |
if ( isset( $this->processed_posts[ $value ] ) ) {
|
2336 |
$new_id = $this->processed_posts[ $value ];
|
2337 |
|
2338 |
-
// only update if there's a difference
|
2339 |
if ( $new_id !== $value ) {
|
2340 |
update_post_meta( $post_id, '_thumbnail_id', $new_id );
|
2341 |
}
|
@@ -2346,13 +2121,13 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2346 |
/**
|
2347 |
* Decide if the given meta key maps to information we will want to import
|
2348 |
*
|
2349 |
-
* @param string $key The meta key to check
|
2350 |
-
* @return string|bool The key if we do want to import, false if not
|
2351 |
*/
|
2352 |
public function is_valid_meta_key( $key ) {
|
2353 |
// skip attachment metadata since we'll regenerate it from scratch
|
2354 |
-
// skip _edit_lock as not relevant for import
|
2355 |
-
if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) {
|
2356 |
return false;
|
2357 |
}
|
2358 |
|
@@ -2372,22 +2147,15 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2372 |
/**
|
2373 |
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
2374 |
*
|
2375 |
-
* @
|
2376 |
-
* @access public
|
2377 |
* @return int 60
|
2378 |
*/
|
2379 |
-
|
2380 |
return 60;
|
2381 |
}
|
2382 |
|
2383 |
-
|
2384 |
-
|
2385 |
-
*
|
2386 |
-
* @param string $a String one.
|
2387 |
-
* @param string $b String two.
|
2388 |
-
* @return string
|
2389 |
-
*/
|
2390 |
-
public function cmpr_strlen( $a, $b ) {
|
2391 |
return strlen( $b ) - strlen( $a );
|
2392 |
}
|
2393 |
|
@@ -2419,20 +2187,20 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2419 |
* @return int|bool Existing post ID if it exists, false otherwise.
|
2420 |
*/
|
2421 |
protected function post_exists( $data ) {
|
2422 |
-
// Constant-time lookup if we prefilled
|
2423 |
$exists_key = $data['guid'];
|
2424 |
|
2425 |
if ( $this->options['prefill_existing_posts'] ) {
|
2426 |
return isset( $this->exists['post'][ $exists_key ] ) ? $this->exists['post'][ $exists_key ] : false;
|
2427 |
}
|
2428 |
|
2429 |
-
// No prefilling, but might have already handled it
|
2430 |
if ( isset( $this->exists['post'][ $exists_key ] ) ) {
|
2431 |
return $this->exists['post'][ $exists_key ];
|
2432 |
}
|
2433 |
|
2434 |
-
// Still nothing, try post_exists, and cache it
|
2435 |
-
$exists
|
2436 |
$this->exists['post'][ $exists_key ] = $exists;
|
2437 |
|
2438 |
return $exists;
|
@@ -2445,7 +2213,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2445 |
* @param int $post_id Post ID.
|
2446 |
*/
|
2447 |
protected function mark_post_exists( $data, $post_id ) {
|
2448 |
-
$exists_key
|
2449 |
$this->exists['post'][ $exists_key ] = $post_id;
|
2450 |
}
|
2451 |
|
@@ -2459,7 +2227,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2459 |
$posts = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_date FROM {$wpdb->comments}" );
|
2460 |
|
2461 |
foreach ( $posts as $item ) {
|
2462 |
-
$exists_key
|
2463 |
$this->exists['comment'][ $exists_key ] = $item->comment_ID;
|
2464 |
}
|
2465 |
}
|
@@ -2473,18 +2241,18 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2473 |
protected function comment_exists( $data ) {
|
2474 |
$exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
|
2475 |
|
2476 |
-
// Constant-time lookup if we prefilled
|
2477 |
if ( $this->options['prefill_existing_comments'] ) {
|
2478 |
return isset( $this->exists['comment'][ $exists_key ] ) ? $this->exists['comment'][ $exists_key ] : false;
|
2479 |
}
|
2480 |
|
2481 |
-
// No prefilling, but might have already handled it
|
2482 |
if ( isset( $this->exists['comment'][ $exists_key ] ) ) {
|
2483 |
return $this->exists['comment'][ $exists_key ];
|
2484 |
}
|
2485 |
|
2486 |
-
// Still nothing, try comment_exists, and cache it
|
2487 |
-
$exists
|
2488 |
$this->exists['comment'][ $exists_key ] = $exists;
|
2489 |
|
2490 |
return $exists;
|
@@ -2497,7 +2265,7 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2497 |
* @param int $comment_id Comment ID.
|
2498 |
*/
|
2499 |
protected function mark_comment_exists( $data, $comment_id ) {
|
2500 |
-
$exists_key
|
2501 |
$this->exists['comment'][ $exists_key ] = $comment_id;
|
2502 |
}
|
2503 |
|
@@ -2508,12 +2276,12 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2508 |
*/
|
2509 |
protected function prefill_existing_terms() {
|
2510 |
global $wpdb;
|
2511 |
-
$query
|
2512 |
$query .= " JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id";
|
2513 |
-
$terms
|
2514 |
|
2515 |
foreach ( $terms as $item ) {
|
2516 |
-
$exists_key
|
2517 |
$this->exists['term'][ $exists_key ] = $item->term_id;
|
2518 |
}
|
2519 |
}
|
@@ -2527,17 +2295,17 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2527 |
protected function term_exists( $data ) {
|
2528 |
$exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
|
2529 |
|
2530 |
-
// Constant-time lookup if we prefilled
|
2531 |
if ( $this->options['prefill_existing_terms'] ) {
|
2532 |
return isset( $this->exists['term'][ $exists_key ] ) ? $this->exists['term'][ $exists_key ] : false;
|
2533 |
}
|
2534 |
|
2535 |
-
// No prefilling, but might have already handled it
|
2536 |
if ( isset( $this->exists['term'][ $exists_key ] ) ) {
|
2537 |
return $this->exists['term'][ $exists_key ];
|
2538 |
}
|
2539 |
|
2540 |
-
// Still nothing, try comment_exists, and cache it
|
2541 |
$exists = term_exists( $data['slug'], $data['taxonomy'] );
|
2542 |
if ( is_array( $exists ) ) {
|
2543 |
$exists = $exists['term_id'];
|
@@ -2555,8 +2323,8 @@ if ( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
2555 |
* @param int $term_id Term ID.
|
2556 |
*/
|
2557 |
protected function mark_term_exists( $data, $term_id ) {
|
2558 |
-
$exists_key
|
2559 |
$this->exists['term'][ $exists_key ] = $term_id;
|
2560 |
}
|
2561 |
}
|
2562 |
-
endif;
|
1 |
<?php
|
2 |
+
|
3 |
+
if( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
class WXR_Importer extends WP_Importer {
|
5 |
/**
|
6 |
* Maximum supported WXR version
|
7 |
*/
|
8 |
+
const MAX_WXR_VERSION = 1.2;
|
9 |
|
10 |
/**
|
11 |
* Regular expression for checking if a post references an attachment
|
20 |
|
|
21 |
# Match anything that looks like an upload URL
|
22 |
src=[\'"][^\'"]*(
|
23 |
+
[0-9]{4}/[0-9]{2}/[^\'"]+\.(jpg|jpeg|png|gif)
|
24 |
|
|
25 |
content/uploads[^\'"]+
|
26 |
)[\'"]
|
36 |
*/
|
37 |
protected $version = '1.0';
|
38 |
|
39 |
+
// information to import from WXR file
|
|
|
|
|
|
|
|
|
|
|
40 |
protected $categories = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
protected $tags = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
protected $base_url = '';
|
43 |
|
44 |
+
// TODO: REMOVE THESE
|
|
|
|
|
|
|
|
|
|
|
45 |
protected $processed_terms = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
protected $processed_posts = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
protected $processed_menu_items = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
protected $menu_item_orphans = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
protected $missing_menu_items = array();
|
50 |
|
51 |
+
// NEW STYLE
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
protected $mapping = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
protected $requires_remapping = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
protected $exists = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
protected $user_slug_override = array();
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
protected $url_remap = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
protected $featured_images = array();
|
59 |
|
|
|
60 |
/**
|
61 |
* Logger instance.
|
62 |
*
|
67 |
/**
|
68 |
* Constructor
|
69 |
*
|
70 |
+
* @param array $options {
|
71 |
+
* @var bool $prefill_existing_posts Should we prefill `post_exists` calls? (True prefills and uses more memory, false checks once per imported post and takes longer. Default is true.)
|
72 |
+
* @var bool $prefill_existing_comments Should we prefill `comment_exists` calls? (True prefills and uses more memory, false checks once per imported comment and takes longer. Default is true.)
|
73 |
+
* @var bool $prefill_existing_terms Should we prefill `term_exists` calls? (True prefills and uses more memory, false checks once per imported term and takes longer. Default is true.)
|
74 |
+
* @var bool $update_attachment_guids Should attachment GUIDs be updated to the new URL? (True updates the GUID, which keeps compatibility with v1, false doesn't update, and allows deduplication and reimporting. Default is false.)
|
75 |
+
* @var bool $fetch_attachments Fetch attachments from the remote server. (True fetches and creates attachment posts, false skips attachments. Default is false.)
|
76 |
+
* @var bool $aggressive_url_search Should we search/replace for URLs aggressively? (True searches all posts' content for old URLs and replaces, false checks for `<img class="wp-image-*">` only. Default is false.)
|
77 |
+
* @var int $default_author User ID to use if author is missing or invalid. (Default is null, which leaves posts unassigned.)
|
78 |
* }
|
79 |
*/
|
80 |
public function __construct( $options = array() ) {
|
81 |
+
// Initialize some important variables
|
82 |
$empty_types = array(
|
83 |
'post' => array(),
|
84 |
'comment' => array(),
|
86 |
'user' => array(),
|
87 |
);
|
88 |
|
89 |
+
$this->mapping = $empty_types;
|
90 |
$this->mapping['user_slug'] = array();
|
91 |
+
$this->mapping['term_id'] = array();
|
92 |
+
$this->requires_remapping = $empty_types;
|
93 |
+
$this->exists = $empty_types;
|
94 |
+
|
95 |
+
$this->options = wp_parse_args( $options, array(
|
96 |
+
'prefill_existing_posts' => true,
|
97 |
+
'prefill_existing_comments' => true,
|
98 |
+
'prefill_existing_terms' => true,
|
99 |
+
'update_attachment_guids' => false,
|
100 |
+
'fetch_attachments' => false,
|
101 |
+
'aggressive_url_search' => false,
|
102 |
+
'default_author' => null,
|
103 |
+
) );
|
|
|
|
|
|
|
104 |
}
|
105 |
|
|
|
|
|
|
|
|
|
|
|
106 |
public function set_logger( $logger ) {
|
107 |
$this->logger = $logger;
|
108 |
}
|
114 |
* @return XMLReader|WP_Error Reader instance on success, error otherwise.
|
115 |
*/
|
116 |
protected function get_reader( $file ) {
|
117 |
+
// Avoid loading external entities for security
|
118 |
$old_value = null;
|
119 |
+
if ( function_exists( 'libxml_disable_entity_loader' ) ) {
|
120 |
+
// $old_value = libxml_disable_entity_loader( true );
|
121 |
+
}
|
122 |
|
123 |
$reader = new XMLReader();
|
124 |
$status = $reader->open( $file );
|
125 |
|
126 |
+
if ( ! is_null( $old_value ) ) {
|
127 |
+
// libxml_disable_entity_loader( $old_value );
|
128 |
+
}
|
129 |
+
|
130 |
if ( ! $status ) {
|
131 |
return new WP_Error( 'wxr_importer.cannot_parse', __( 'Could not open the file for parsing', 'wordpress-importer' ) );
|
132 |
}
|
137 |
/**
|
138 |
* The main controller for the actual import stage.
|
139 |
*
|
140 |
+
* @param string $file Path to the WXR file for importing
|
141 |
*/
|
142 |
public function get_preliminary_information( $file ) {
|
143 |
+
// Let's run the actual importer now, woot
|
144 |
$reader = $this->get_reader( $file );
|
145 |
if ( is_wp_error( $reader ) ) {
|
146 |
return $reader;
|
147 |
}
|
148 |
|
149 |
+
// Set the version to compatibility mode first
|
150 |
$this->version = '1.0';
|
151 |
|
152 |
// Start parsing!
|
153 |
$data = new WXR_Import_Info();
|
154 |
while ( $reader->read() ) {
|
155 |
+
// Only deal with element opens
|
156 |
+
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
|
157 |
continue;
|
158 |
}
|
159 |
|
160 |
switch ( $reader->name ) {
|
161 |
case 'wp:wxr_version':
|
162 |
+
// Upgrade to the correct version
|
163 |
$this->version = $reader->readString();
|
164 |
|
165 |
if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
|
166 |
+
$this->logger->warning( sprintf(
|
167 |
+
__( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
|
168 |
+
$this->version,
|
169 |
+
self::MAX_WXR_VERSION
|
170 |
+
) );
|
|
|
|
|
|
|
171 |
}
|
172 |
|
173 |
+
// Handled everything in this node, move on to the next
|
174 |
$reader->next();
|
175 |
break;
|
176 |
|
201 |
if ( is_wp_error( $parsed ) ) {
|
202 |
$this->log_error( $parsed );
|
203 |
|
204 |
+
// Skip the rest of this post
|
205 |
$reader->next();
|
206 |
break;
|
207 |
}
|
208 |
|
209 |
$data->users[] = $parsed;
|
210 |
|
211 |
+
// Handled everything in this node, move on to the next
|
212 |
$reader->next();
|
213 |
break;
|
214 |
|
215 |
case 'item':
|
216 |
+
$node = $reader->expand();
|
217 |
$parsed = $this->parse_post_node( $node );
|
218 |
if ( is_wp_error( $parsed ) ) {
|
219 |
$this->log_error( $parsed );
|
220 |
|
221 |
+
// Skip the rest of this post
|
222 |
$reader->next();
|
223 |
break;
|
224 |
}
|
225 |
|
226 |
+
if ( $parsed['data']['post_type'] === 'attachment' ) {
|
227 |
$data->media_count++;
|
228 |
} else {
|
229 |
$data->post_count++;
|
230 |
}
|
231 |
$data->comment_count += count( $parsed['comments'] );
|
232 |
|
233 |
+
// Handled everything in this node, move on to the next
|
234 |
$reader->next();
|
235 |
break;
|
236 |
|
239 |
case 'wp:term':
|
240 |
$data->term_count++;
|
241 |
|
242 |
+
// Handled everything in this node, move on to the next
|
243 |
$reader->next();
|
244 |
break;
|
245 |
+
}// End switch().
|
246 |
+
}// End while().
|
247 |
|
248 |
$data->version = $this->version;
|
249 |
|
253 |
/**
|
254 |
* The main controller for the actual import stage.
|
255 |
*
|
256 |
+
* @param string $file Path to the WXR file for importing
|
257 |
*/
|
258 |
public function parse_authors( $file ) {
|
259 |
+
// Let's run the actual importer now, woot
|
260 |
$reader = $this->get_reader( $file );
|
261 |
if ( is_wp_error( $reader ) ) {
|
262 |
return $reader;
|
263 |
}
|
264 |
|
265 |
+
// Set the version to compatibility mode first
|
266 |
$this->version = '1.0';
|
267 |
|
268 |
// Start parsing!
|
269 |
$authors = array();
|
270 |
while ( $reader->read() ) {
|
271 |
+
// Only deal with element opens
|
272 |
+
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
|
273 |
continue;
|
274 |
}
|
275 |
|
276 |
switch ( $reader->name ) {
|
277 |
case 'wp:wxr_version':
|
278 |
+
// Upgrade to the correct version
|
279 |
$this->version = $reader->readString();
|
280 |
|
281 |
if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
|
282 |
+
$this->logger->warning( sprintf(
|
283 |
+
__( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
|
284 |
+
$this->version,
|
285 |
+
self::MAX_WXR_VERSION
|
286 |
+
) );
|
|
|
|
|
|
|
287 |
}
|
288 |
|
289 |
+
// Handled everything in this node, move on to the next
|
290 |
$reader->next();
|
291 |
break;
|
292 |
|
297 |
if ( is_wp_error( $parsed ) ) {
|
298 |
$this->log_error( $parsed );
|
299 |
|
300 |
+
// Skip the rest of this post
|
301 |
$reader->next();
|
302 |
break;
|
303 |
}
|
304 |
|
305 |
$authors[] = $parsed;
|
306 |
|
307 |
+
// Handled everything in this node, move on to the next
|
308 |
$reader->next();
|
309 |
break;
|
310 |
}
|
311 |
+
}// End while().
|
312 |
|
313 |
return $authors;
|
314 |
}
|
316 |
/**
|
317 |
* The main controller for the actual import stage.
|
318 |
*
|
319 |
+
* @param string $file Path to the WXR file for importing
|
320 |
*/
|
321 |
public function import( $file ) {
|
322 |
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
|
327 |
return $result;
|
328 |
}
|
329 |
|
330 |
+
// Let's run the actual importer now, woot
|
331 |
$reader = $this->get_reader( $file );
|
332 |
if ( is_wp_error( $reader ) ) {
|
333 |
return $reader;
|
334 |
}
|
335 |
|
336 |
+
// Set the version to compatibility mode first
|
337 |
$this->version = '1.0';
|
338 |
|
339 |
+
// Reset other variables
|
340 |
$this->base_url = '';
|
341 |
|
342 |
// Start parsing!
|
343 |
while ( $reader->read() ) {
|
344 |
+
// Only deal with element opens
|
345 |
+
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
|
346 |
continue;
|
347 |
}
|
348 |
|
349 |
switch ( $reader->name ) {
|
350 |
case 'wp:wxr_version':
|
351 |
+
// Upgrade to the correct version
|
352 |
$this->version = $reader->readString();
|
353 |
|
354 |
if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
|
355 |
+
$this->logger->warning( sprintf(
|
356 |
+
__( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
|
357 |
+
$this->version,
|
358 |
+
self::MAX_WXR_VERSION
|
359 |
+
) );
|
|
|
|
|
|
|
360 |
}
|
361 |
|
362 |
+
// Handled everything in this node, move on to the next
|
363 |
$reader->next();
|
364 |
break;
|
365 |
|
366 |
case 'wp:base_site_url':
|
367 |
$this->base_url = $reader->readString();
|
368 |
|
369 |
+
// Handled everything in this node, move on to the next
|
370 |
$reader->next();
|
371 |
break;
|
372 |
|
373 |
case 'item':
|
374 |
+
$node = $reader->expand();
|
375 |
$parsed = $this->parse_post_node( $node );
|
376 |
if ( is_wp_error( $parsed ) ) {
|
377 |
$this->log_error( $parsed );
|
378 |
|
379 |
+
// Skip the rest of this post
|
380 |
$reader->next();
|
381 |
break;
|
382 |
}
|
383 |
|
384 |
$this->process_post( $parsed['data'], $parsed['meta'], $parsed['comments'], $parsed['terms'] );
|
385 |
|
386 |
+
// Handled everything in this node, move on to the next
|
387 |
$reader->next();
|
388 |
break;
|
389 |
|
394 |
if ( is_wp_error( $parsed ) ) {
|
395 |
$this->log_error( $parsed );
|
396 |
|
397 |
+
// Skip the rest of this post
|
398 |
$reader->next();
|
399 |
break;
|
400 |
}
|
404 |
$this->log_error( $status );
|
405 |
}
|
406 |
|
407 |
+
// Handled everything in this node, move on to the next
|
408 |
$reader->next();
|
409 |
break;
|
410 |
|
415 |
if ( is_wp_error( $parsed ) ) {
|
416 |
$this->log_error( $parsed );
|
417 |
|
418 |
+
// Skip the rest of this post
|
419 |
$reader->next();
|
420 |
break;
|
421 |
}
|
422 |
|
423 |
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
|
424 |
|
425 |
+
// Handled everything in this node, move on to the next
|
426 |
$reader->next();
|
427 |
break;
|
428 |
|
433 |
if ( is_wp_error( $parsed ) ) {
|
434 |
$this->log_error( $parsed );
|
435 |
|
436 |
+
// Skip the rest of this post
|
437 |
$reader->next();
|
438 |
break;
|
439 |
}
|
440 |
|
441 |
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
|
442 |
|
443 |
+
// Handled everything in this node, move on to the next
|
444 |
$reader->next();
|
445 |
break;
|
446 |
|
451 |
if ( is_wp_error( $parsed ) ) {
|
452 |
$this->log_error( $parsed );
|
453 |
|
454 |
+
// Skip the rest of this post
|
455 |
$reader->next();
|
456 |
break;
|
457 |
}
|
458 |
|
459 |
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
|
460 |
|
461 |
+
// Handled everything in this node, move on to the next
|
462 |
$reader->next();
|
463 |
break;
|
464 |
|
465 |
default:
|
466 |
+
// Skip this node, probably handled by something already
|
467 |
break;
|
468 |
+
}// End switch().
|
469 |
+
}// End while().
|
470 |
|
471 |
// Now that we've done the main processing, do any required
|
472 |
// post-processing and remapping.
|
475 |
if ( $this->options['aggressive_url_search'] ) {
|
476 |
$this->replace_attachment_urls_in_content();
|
477 |
}
|
|
|
478 |
// $this->remap_featured_images();
|
|
|
479 |
$this->import_end();
|
480 |
}
|
481 |
|
487 |
protected function log_error( WP_Error $error ) {
|
488 |
$this->logger->warning( $error->get_error_message() );
|
489 |
|
490 |
+
// Log the data as debug info too
|
491 |
$data = $error->get_error_data();
|
492 |
if ( ! empty( $data ) ) {
|
493 |
+
$this->logger->debug( var_export( $data, true ) );
|
494 |
}
|
495 |
}
|
496 |
|
497 |
/**
|
498 |
* Parses the WXR file and prepares us for the task of processing parsed data
|
499 |
*
|
500 |
+
* @param string $file Path to the WXR file for importing
|
501 |
*/
|
502 |
protected function import_start( $file ) {
|
503 |
if ( ! is_file( $file ) ) {
|
504 |
return new WP_Error( 'wxr_importer.file_missing', __( 'The file does not exist, please try again.', 'wordpress-importer' ) );
|
505 |
}
|
506 |
|
507 |
+
// Suspend bunches of stuff in WP core
|
508 |
wp_defer_term_counting( true );
|
509 |
wp_defer_comment_counting( true );
|
510 |
wp_suspend_cache_invalidation( true );
|
511 |
|
512 |
+
// Prefill exists calls if told to
|
513 |
if ( $this->options['prefill_existing_posts'] ) {
|
514 |
$this->prefill_existing_posts();
|
515 |
}
|
533 |
* Performs post-import cleanup of files and the cache
|
534 |
*/
|
535 |
protected function import_end() {
|
536 |
+
// Re-enable stuff in core
|
537 |
wp_suspend_cache_invalidation( false );
|
538 |
wp_cache_flush();
|
539 |
foreach ( get_taxonomies() as $tax ) {
|
556 |
/**
|
557 |
* Set the user mapping.
|
558 |
*
|
559 |
+
* @param array $mapping List of map arrays (containing `old_slug`, `old_id`, `new_id`)
|
560 |
*/
|
561 |
public function set_user_mapping( $mapping ) {
|
562 |
foreach ( $mapping as $map ) {
|
563 |
if ( empty( $map['old_slug'] ) || empty( $map['old_id'] ) || empty( $map['new_id'] ) ) {
|
564 |
$this->logger->warning( __( 'Invalid author mapping', 'wordpress-importer' ) );
|
565 |
+
$this->logger->debug( var_export( $map, true ) );
|
566 |
continue;
|
567 |
}
|
568 |
|
595 |
* @return array|WP_Error Post data array on success, error otherwise.
|
596 |
*/
|
597 |
protected function parse_post_node( $node ) {
|
598 |
+
$data = array();
|
599 |
+
$meta = array();
|
600 |
$comments = array();
|
601 |
+
$terms = array();
|
602 |
|
603 |
+
foreach ( $node->childNodes as $child ) {
|
604 |
+
// We only care about child elements
|
605 |
+
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
|
606 |
continue;
|
607 |
}
|
608 |
|
609 |
+
switch ( $child->tagName ) {
|
610 |
case 'wp:post_type':
|
611 |
+
$data['post_type'] = $child->textContent;
|
612 |
break;
|
613 |
|
614 |
case 'title':
|
615 |
+
$data['post_title'] = $child->textContent;
|
616 |
break;
|
617 |
|
618 |
case 'guid':
|
619 |
+
$data['guid'] = $child->textContent;
|
620 |
break;
|
621 |
|
622 |
case 'dc:creator':
|
623 |
+
$data['post_author'] = $child->textContent;
|
624 |
break;
|
625 |
|
626 |
case 'content:encoded':
|
627 |
+
$data['post_content'] = $child->textContent;
|
628 |
break;
|
629 |
|
630 |
case 'excerpt:encoded':
|
631 |
+
$data['post_excerpt'] = $child->textContent;
|
632 |
break;
|
633 |
|
634 |
case 'wp:post_id':
|
635 |
+
$data['post_id'] = $child->textContent;
|
636 |
break;
|
637 |
|
638 |
case 'wp:post_date':
|
639 |
+
$data['post_date'] = $child->textContent;
|
640 |
break;
|
641 |
|
642 |
case 'wp:post_date_gmt':
|
643 |
+
$data['post_date_gmt'] = $child->textContent;
|
644 |
break;
|
645 |
|
646 |
case 'wp:comment_status':
|
647 |
+
$data['comment_status'] = $child->textContent;
|
648 |
break;
|
649 |
|
650 |
case 'wp:ping_status':
|
651 |
+
$data['ping_status'] = $child->textContent;
|
652 |
break;
|
653 |
|
654 |
case 'wp:post_name':
|
655 |
+
$data['post_name'] = $child->textContent;
|
656 |
break;
|
657 |
|
658 |
case 'wp:status':
|
659 |
+
$data['post_status'] = $child->textContent;
|
660 |
|
661 |
+
if ( $data['post_status'] === 'auto-draft' ) {
|
662 |
+
// Bail now
|
663 |
return new WP_Error(
|
664 |
'wxr_importer.post.cannot_import_draft',
|
665 |
__( 'Cannot import auto-draft posts' ),
|
669 |
break;
|
670 |
|
671 |
case 'wp:post_parent':
|
672 |
+
$data['post_parent'] = $child->textContent;
|
673 |
break;
|
674 |
|
675 |
case 'wp:menu_order':
|
676 |
+
$data['menu_order'] = $child->textContent;
|
677 |
break;
|
678 |
|
679 |
case 'wp:post_password':
|
680 |
+
$data['post_password'] = $child->textContent;
|
681 |
break;
|
682 |
|
683 |
case 'wp:is_sticky':
|
684 |
+
$data['is_sticky'] = $child->textContent;
|
685 |
break;
|
686 |
|
687 |
case 'wp:attachment_url':
|
688 |
+
$data['attachment_url'] = $child->textContent;
|
689 |
break;
|
690 |
|
691 |
case 'wp:postmeta':
|
708 |
$terms[] = $term_item;
|
709 |
}
|
710 |
break;
|
711 |
+
}// End switch().
|
712 |
+
}// End foreach().
|
713 |
|
714 |
return compact( 'data', 'meta', 'comments', 'terms' );
|
715 |
}
|
721 |
* Doesn't create a new post if: the post type doesn't exist, the given post ID
|
722 |
* is already noted as imported or a post with the same title and date already exists.
|
723 |
* Note that new/updated terms, comments and meta are imported for the last of the above.
|
|
|
|
|
|
|
|
|
|
|
724 |
*/
|
725 |
protected function process_post( $data, $meta, $comments, $terms ) {
|
726 |
/**
|
731 |
* @param array $comments Comments on the post.
|
732 |
* @param array $terms Terms on the post.
|
733 |
*/
|
734 |
+
$data = apply_filters( 'wxr_importer.pre_process.post', $data, $meta, $comments, $terms );
|
735 |
if ( empty( $data ) ) {
|
736 |
return false;
|
737 |
}
|
738 |
|
739 |
+
$original_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
|
740 |
$parent_id = isset( $data['post_parent'] ) ? (int) $data['post_parent'] : 0;
|
741 |
$author_id = isset( $data['post_author'] ) ? (int) $data['post_author'] : 0;
|
742 |
|
745 |
return;
|
746 |
}
|
747 |
|
|
|
|
|
|
|
|
|
|
|
748 |
$post_type_object = get_post_type_object( $data['post_type'] );
|
749 |
|
750 |
// Is this type even valid?
|
751 |
if ( ! $post_type_object ) {
|
752 |
+
$this->logger->warning( sprintf(
|
753 |
+
__( 'Failed to import "%1$s": Invalid post type %2$s', 'wordpress-importer' ),
|
754 |
+
$data['post_title'],
|
755 |
+
$data['post_type']
|
756 |
+
) );
|
|
|
|
|
|
|
757 |
return false;
|
758 |
}
|
759 |
|
760 |
$post_exists = $this->post_exists( $data );
|
761 |
if ( $post_exists ) {
|
762 |
+
$this->logger->info( sprintf(
|
|
|
763 |
__( '%1$s "%2$s" already exists.', 'wordpress-importer' ),
|
764 |
$post_type_object->labels->singular_name,
|
765 |
$data['post_title']
|
766 |
+
) );
|
|
|
|
|
767 |
|
768 |
/**
|
769 |
* Post processing already imported.
|
770 |
*
|
771 |
* @param array $data Raw data imported for the post.
|
772 |
*/
|
773 |
+
do_action( 'wxr_importer.process_already_imported.post', $data );
|
774 |
|
775 |
+
// Even though this post already exists, new comments might need importing
|
776 |
$this->process_comments( $comments, $original_id, $data, $post_exists );
|
777 |
|
778 |
return false;
|
779 |
}
|
780 |
|
781 |
+
// Map the parent post, or mark it as one we need to fix
|
782 |
$requires_remapping = false;
|
783 |
if ( $parent_id ) {
|
784 |
if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
|
785 |
$data['post_parent'] = $this->mapping['post'][ $parent_id ];
|
786 |
} else {
|
787 |
+
$meta[] = array(
|
788 |
+
'key' => '_wxr_import_parent',
|
789 |
'value' => $parent_id,
|
790 |
);
|
791 |
$requires_remapping = true;
|
794 |
}
|
795 |
}
|
796 |
|
797 |
+
// Map the author, or mark it as one we need to fix
|
798 |
$author = sanitize_user( $data['post_author'], true );
|
799 |
if ( empty( $author ) ) {
|
800 |
// Missing or invalid author, use default if available.
|
802 |
} elseif ( isset( $this->mapping['user_slug'][ $author ] ) ) {
|
803 |
$data['post_author'] = $this->mapping['user_slug'][ $author ];
|
804 |
} else {
|
805 |
+
$meta[] = array(
|
806 |
+
'key' => '_wxr_import_user_slug',
|
807 |
'value' => $author,
|
808 |
);
|
809 |
$requires_remapping = true;
|
813 |
|
814 |
// Does the post look like it contains attachment images?
|
815 |
if ( preg_match( self::REGEX_HAS_ATTACHMENT_REFS, $data['post_content'] ) ) {
|
816 |
+
$meta[] = array(
|
817 |
+
'key' => '_wxr_import_has_attachment_refs',
|
818 |
'value' => true,
|
819 |
);
|
820 |
$requires_remapping = true;
|
821 |
}
|
822 |
|
823 |
+
// Whitelist to just the keys we allow
|
824 |
$postdata = array(
|
825 |
'import_id' => $data['post_id'],
|
826 |
);
|
827 |
+
$allowed = array(
|
828 |
'post_author' => true,
|
829 |
'post_date' => true,
|
830 |
'post_date_gmt' => true,
|
853 |
|
854 |
if ( 'attachment' === $postdata['post_type'] ) {
|
855 |
if ( ! $this->options['fetch_attachments'] ) {
|
856 |
+
$this->logger->notice( sprintf(
|
857 |
+
__( 'Skipping attachment "%s", fetching attachments disabled' ),
|
858 |
+
$data['post_title']
|
859 |
+
) );
|
|
|
|
|
|
|
860 |
/**
|
861 |
* Post processing skipped.
|
862 |
*
|
863 |
* @param array $data Raw data imported for the post.
|
864 |
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
|
865 |
*/
|
866 |
+
do_action( 'wxr_importer.process_skipped.post', $data, $meta );
|
867 |
return false;
|
868 |
}
|
869 |
$remote_url = ! empty( $data['attachment_url'] ) ? $data['attachment_url'] : $data['guid'];
|
870 |
+
$post_id = $this->process_attachment( $postdata, $meta, $remote_url );
|
871 |
} else {
|
872 |
$post_id = wp_insert_post( $postdata, true );
|
873 |
do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
|
874 |
}
|
875 |
|
876 |
if ( is_wp_error( $post_id ) ) {
|
877 |
+
$this->logger->error( sprintf(
|
878 |
+
__( 'Failed to import "%1$s" (%2$s)', 'wordpress-importer' ),
|
879 |
+
$data['post_title'],
|
880 |
+
$post_type_object->labels->singular_name
|
881 |
+
) );
|
|
|
|
|
|
|
882 |
$this->logger->debug( $post_id->get_error_message() );
|
883 |
|
884 |
/**
|
890 |
* @param array $comments Raw comment data, already processed by {@see process_comments}.
|
891 |
* @param array $terms Raw term data, already processed.
|
892 |
*/
|
893 |
+
do_action( 'wxr_importer.process_failed.post', $post_id, $data, $meta, $comments, $terms );
|
894 |
return false;
|
895 |
}
|
896 |
|
897 |
+
// Ensure stickiness is handled correctly too
|
898 |
+
if ( $data['is_sticky'] === '1' ) {
|
899 |
stick_post( $post_id );
|
900 |
}
|
901 |
|
902 |
+
// map pre-import ID to local ID
|
903 |
$this->mapping['post'][ $original_id ] = (int) $post_id;
|
904 |
if ( $requires_remapping ) {
|
905 |
$this->requires_remapping['post'][ $post_id ] = true;
|
906 |
}
|
907 |
$this->mark_post_exists( $data, $post_id );
|
908 |
|
909 |
+
$this->logger->info( sprintf(
|
910 |
+
__( 'Imported "%1$s" (%2$s)', 'wordpress-importer' ),
|
911 |
+
$data['post_title'],
|
912 |
+
$post_type_object->labels->singular_name
|
913 |
+
) );
|
914 |
+
$this->logger->debug( sprintf(
|
915 |
+
__( 'Post %1$d remapped to %2$d', 'wordpress-importer' ),
|
916 |
+
$original_id,
|
917 |
+
$post_id
|
918 |
+
) );
|
919 |
+
|
920 |
+
// Handle the terms too
|
|
|
|
|
|
|
|
|
|
|
|
|
921 |
$terms = apply_filters( 'wp_import_post_terms', $terms, $post_id, $data );
|
922 |
|
923 |
if ( ! empty( $terms ) ) {
|
924 |
$term_ids = array();
|
925 |
foreach ( $terms as $term ) {
|
926 |
$taxonomy = $term['taxonomy'];
|
927 |
+
$key = sha1( $taxonomy . ':' . $term['slug'] );
|
928 |
|
929 |
if ( isset( $this->mapping['term'][ $key ] ) ) {
|
930 |
$term_ids[ $taxonomy ][] = (int) $this->mapping['term'][ $key ];
|
931 |
} else {
|
932 |
+
$meta[] = array(
|
933 |
+
'key' => '_wxr_import_term',
|
934 |
'value' => $term,
|
935 |
);
|
936 |
$requires_remapping = true;
|
959 |
* @param array $comments Raw comment data, already processed by {@see process_comments}.
|
960 |
* @param array $terms Raw term data, already processed.
|
961 |
*/
|
962 |
+
do_action( 'wxr_importer.processed.post', $post_id, $data, $meta, $comments, $terms );
|
963 |
}
|
964 |
|
965 |
/**
|
970 |
* represents doesn't exist then the menu item will not be imported (waits until the
|
971 |
* end of the import to retry again before discarding).
|
972 |
*
|
973 |
+
* @param array $item Menu item details from WXR file
|
|
|
|
|
974 |
*/
|
975 |
protected function process_menu_item_meta( $post_id, $data, $meta ) {
|
976 |
|
977 |
+
$item_type = get_post_meta( $post_id, '_menu_item_type', true );
|
978 |
$original_object_id = get_post_meta( $post_id, '_menu_item_object_id', true );
|
979 |
+
$object_id = null;
|
980 |
|
981 |
$this->logger->debug( sprintf( 'Processing menu item %s', $item_type ) );
|
982 |
|
1006 |
break;
|
1007 |
|
1008 |
default:
|
1009 |
+
// associated object is missing or not imported yet, we'll retry later
|
1010 |
$this->missing_menu_items[] = $item;
|
1011 |
$this->logger->debug( 'Unknown menu item type' );
|
1012 |
break;
|
1028 |
/**
|
1029 |
* If fetching attachments is enabled then attempt to create a new attachment
|
1030 |
*
|
1031 |
+
* @param array $post Attachment post details from WXR
|
1032 |
+
* @param string $url URL to fetch attachment from
|
1033 |
+
* @return int|WP_Error Post ID on success, WP_Error otherwise
|
|
|
1034 |
*/
|
1035 |
protected function process_attachment( $post, $meta, $remote_url ) {
|
1036 |
// try to use _wp_attached file for upload folder placement to ensure the same location as the export site
|
1037 |
+
// e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
|
1038 |
$post['upload_date'] = $post['post_date'];
|
1039 |
foreach ( $meta as $meta_item ) {
|
1040 |
+
if ( $meta_item['key'] !== '_wp_attached_file' ) {
|
1041 |
continue;
|
1042 |
}
|
1043 |
|
1047 |
break;
|
1048 |
}
|
1049 |
|
1050 |
+
// if the URL is absolute, but does not contain address, then upload it assuming base_site_url
|
1051 |
if ( preg_match( '|^/[\w\W]+$|', $remote_url ) ) {
|
1052 |
$remote_url = rtrim( $this->base_url, '/' ) . $remote_url;
|
1053 |
}
|
1065 |
$post['post_mime_type'] = $info['type'];
|
1066 |
|
1067 |
// WP really likes using the GUID for display. Allow updating it.
|
1068 |
+
// See https://core.trac.wordpress.org/ticket/33386
|
1069 |
if ( $this->options['update_attachment_guids'] ) {
|
1070 |
$post['guid'] = $upload['url'];
|
1071 |
}
|
1072 |
|
1073 |
+
// as per wp-admin/includes/upload.php
|
1074 |
$post_id = wp_insert_attachment( $post, $upload['file'] );
|
1075 |
if ( is_wp_error( $post_id ) ) {
|
1076 |
return $post_id;
|
1079 |
$attachment_metadata = wp_generate_attachment_metadata( $post_id, $upload['file'] );
|
1080 |
wp_update_attachment_metadata( $post_id, $attachment_metadata );
|
1081 |
|
1082 |
+
// Map this image URL later if we need to
|
1083 |
$this->url_remap[ $remote_url ] = $upload['url'];
|
1084 |
|
1085 |
+
// If we have a HTTPS URL, ensure the HTTP URL gets replaced too
|
1086 |
if ( substr( $remote_url, 0, 8 ) === 'https://' ) {
|
1087 |
+
$insecure_url = 'http' . substr( $remote_url, 5 );
|
1088 |
$this->url_remap[ $insecure_url ] = $upload['url'];
|
1089 |
}
|
1090 |
|
1091 |
+
if ( $this->options['aggressive_url_search'] ) {
|
1092 |
+
// remap resized image URLs, works by stripping the extension and remapping the URL stub.
|
1093 |
+
/*
|
1094 |
+
if ( preg_match( '!^image/!', $info['type'] ) ) {
|
1095 |
+
$parts = pathinfo( $remote_url );
|
1096 |
+
$name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
|
1097 |
+
|
1098 |
+
$parts_new = pathinfo( $upload['url'] );
|
1099 |
+
$name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
|
1100 |
+
|
1101 |
+
$this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
|
1102 |
+
}*/
|
1103 |
+
}
|
1104 |
+
|
1105 |
return $post_id;
|
1106 |
}
|
1107 |
|
1112 |
* @return array|null Meta data array on success, or null on error.
|
1113 |
*/
|
1114 |
protected function parse_meta_node( $node ) {
|
1115 |
+
foreach ( $node->childNodes as $child ) {
|
1116 |
+
// We only care about child elements
|
1117 |
+
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
|
1118 |
continue;
|
1119 |
}
|
1120 |
|
1121 |
+
switch ( $child->tagName ) {
|
1122 |
case 'wp:meta_key':
|
1123 |
+
$key = $child->textContent;
|
1124 |
break;
|
1125 |
|
1126 |
case 'wp:meta_value':
|
1127 |
+
$value = $child->textContent;
|
1128 |
break;
|
1129 |
}
|
1130 |
}
|
1139 |
/**
|
1140 |
* Process and import post meta items.
|
1141 |
*
|
1142 |
+
* @param array $meta List of meta data arrays
|
1143 |
+
* @param int $post_id Post to associate with
|
1144 |
+
* @param array $post Post data
|
1145 |
* @return int|WP_Error Number of meta items imported on success, error otherwise.
|
1146 |
*/
|
1147 |
protected function process_post_meta( $meta, $post_id, $post ) {
|
1156 |
* @param array $meta_item Meta data. (Return empty to skip.)
|
1157 |
* @param int $post_id Post the meta is attached to.
|
1158 |
*/
|
1159 |
+
$meta_item = apply_filters( 'wxr_importer.pre_process.post_meta', $meta_item, $post_id );
|
1160 |
if ( empty( $meta_item ) ) {
|
1161 |
return false;
|
1162 |
}
|
1163 |
|
1164 |
+
$key = apply_filters( 'import_post_meta_key', $meta_item['key'], $post_id, $post );
|
1165 |
$value = false;
|
1166 |
|
1167 |
if ( '_edit_last' === $key ) {
|
1175 |
}
|
1176 |
|
1177 |
if ( $key ) {
|
1178 |
+
// export gets meta straight from the DB so could have a serialized string
|
1179 |
if ( ! $value ) {
|
1180 |
$value = maybe_unserialize( $meta_item['value'] );
|
1181 |
}
|
1183 |
add_post_meta( $post_id, $key, $value );
|
1184 |
do_action( 'import_post_meta', $post_id, $key, $value );
|
1185 |
|
1186 |
+
// if the post has a featured image, take note of this in case of remap
|
1187 |
if ( '_thumbnail_id' === $key ) {
|
1188 |
$this->featured_images[ $post_id ] = (int) $value;
|
1189 |
}
|
1190 |
}
|
1191 |
+
}// End foreach().
|
1192 |
|
1193 |
return true;
|
1194 |
}
|
1204 |
'commentmeta' => array(),
|
1205 |
);
|
1206 |
|
1207 |
+
foreach ( $node->childNodes as $child ) {
|
1208 |
+
// We only care about child elements
|
1209 |
+
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
|
1210 |
continue;
|
1211 |
}
|
1212 |
|
1213 |
+
switch ( $child->tagName ) {
|
1214 |
case 'wp:comment_id':
|
1215 |
+
$data['comment_id'] = $child->textContent;
|
1216 |
break;
|
1217 |
case 'wp:comment_author':
|
1218 |
+
$data['comment_author'] = $child->textContent;
|
1219 |
break;
|
1220 |
|
1221 |
case 'wp:comment_author_email':
|
1222 |
+
$data['comment_author_email'] = $child->textContent;
|
1223 |
break;
|
1224 |
|
1225 |
case 'wp:comment_author_IP':
|
1226 |
+
$data['comment_author_IP'] = $child->textContent;
|
1227 |
break;
|
1228 |
|
1229 |
case 'wp:comment_author_url':
|
1230 |
+
$data['comment_author_url'] = $child->textContent;
|
1231 |
break;
|
1232 |
|
1233 |
case 'wp:comment_user_id':
|
1234 |
+
$data['comment_user_id'] = $child->textContent;
|
1235 |
break;
|
1236 |
|
1237 |
case 'wp:comment_date':
|
1238 |
+
$data['comment_date'] = $child->textContent;
|
1239 |
break;
|
1240 |
|
1241 |
case 'wp:comment_date_gmt':
|
1242 |
+
$data['comment_date_gmt'] = $child->textContent;
|
1243 |
break;
|
1244 |
|
1245 |
case 'wp:comment_content':
|
1246 |
+
$data['comment_content'] = $child->textContent;
|
1247 |
break;
|
1248 |
|
1249 |
case 'wp:comment_approved':
|
1250 |
+
$data['comment_approved'] = $child->textContent;
|
1251 |
break;
|
1252 |
|
1253 |
case 'wp:comment_type':
|
1254 |
+
$data['comment_type'] = $child->textContent;
|
1255 |
break;
|
1256 |
|
1257 |
case 'wp:comment_parent':
|
1258 |
+
$data['comment_parent'] = $child->textContent;
|
1259 |
break;
|
1260 |
|
1261 |
case 'wp:commentmeta':
|
1264 |
$data['commentmeta'][] = $meta_item;
|
1265 |
}
|
1266 |
break;
|
1267 |
+
}// End switch().
|
1268 |
+
}// End foreach().
|
1269 |
|
1270 |
return $data;
|
1271 |
}
|
1273 |
/**
|
1274 |
* Process and import comment data.
|
1275 |
*
|
1276 |
+
* @param array $comments List of comment data arrays.
|
1277 |
+
* @param int $post_id Post to associate with.
|
1278 |
+
* @param array $post Post data.
|
|
|
1279 |
* @return int|WP_Error Number of comments imported on success, error otherwise.
|
1280 |
*/
|
1281 |
protected function process_comments( $comments, $post_id, $post, $post_exists = false ) {
|
1287 |
|
1288 |
$num_comments = 0;
|
1289 |
|
1290 |
+
// Sort by ID to avoid excessive remapping later
|
1291 |
usort( $comments, array( $this, 'sort_comments_by_id' ) );
|
1292 |
|
1293 |
foreach ( $comments as $key => $comment ) {
|
1297 |
* @param array $comment Comment data. (Return empty to skip.)
|
1298 |
* @param int $post_id Post the comment is attached to.
|
1299 |
*/
|
1300 |
+
$comment = apply_filters( 'wxr_importer.pre_process.comment', $comment, $post_id );
|
1301 |
if ( empty( $comment ) ) {
|
1302 |
return false;
|
1303 |
}
|
1304 |
|
1305 |
+
$original_id = isset( $comment['comment_id'] ) ? (int) $comment['comment_id'] : 0;
|
1306 |
+
$parent_id = isset( $comment['comment_parent'] ) ? (int) $comment['comment_parent'] : 0;
|
1307 |
$author_id = isset( $comment['comment_user_id'] ) ? (int) $comment['comment_user_id'] : 0;
|
1308 |
|
1309 |
// if this is a new post we can skip the comment_exists() check
|
1310 |
+
// TODO: Check comment_exists for performance
|
1311 |
if ( $post_exists ) {
|
1312 |
$existing = $this->comment_exists( $comment );
|
1313 |
if ( $existing ) {
|
1317 |
*
|
1318 |
* @param array $comment Raw data imported for the comment.
|
1319 |
*/
|
1320 |
+
do_action( 'wxr_importer.process_already_imported.comment', $comment );
|
1321 |
|
1322 |
$this->mapping['comment'][ $original_id ] = $existing;
|
1323 |
continue;
|
1324 |
}
|
1325 |
}
|
1326 |
|
1327 |
+
// Remove meta from the main array
|
1328 |
$meta = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
|
1329 |
unset( $comment['commentmeta'] );
|
1330 |
|
1331 |
+
// Map the parent comment, or mark it as one we need to fix
|
1332 |
$requires_remapping = false;
|
1333 |
if ( $parent_id ) {
|
1334 |
if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
|
1335 |
$comment['comment_parent'] = $this->mapping['comment'][ $parent_id ];
|
1336 |
} else {
|
1337 |
+
// Prepare for remapping later
|
1338 |
+
$meta[] = array(
|
1339 |
+
'key' => '_wxr_import_parent',
|
1340 |
'value' => $parent_id,
|
1341 |
);
|
1342 |
$requires_remapping = true;
|
1343 |
|
1344 |
+
// Wipe the parent for now
|
1345 |
$comment['comment_parent'] = 0;
|
1346 |
}
|
1347 |
}
|
1348 |
|
1349 |
+
// Map the author, or mark it as one we need to fix
|
1350 |
if ( $author_id ) {
|
1351 |
if ( isset( $this->mapping['user'][ $author_id ] ) ) {
|
1352 |
$comment['user_id'] = $this->mapping['user'][ $author_id ];
|
1353 |
} else {
|
1354 |
+
// Prepare for remapping later
|
1355 |
+
$meta[] = array(
|
1356 |
+
'key' => '_wxr_import_user',
|
1357 |
'value' => $author_id,
|
1358 |
);
|
1359 |
$requires_remapping = true;
|
1360 |
|
1361 |
+
// Wipe the user for now
|
1362 |
$comment['user_id'] = 0;
|
1363 |
}
|
1364 |
}
|
1365 |
|
1366 |
+
// Run standard core filters
|
1367 |
$comment['comment_post_ID'] = $post_id;
|
1368 |
+
$comment = wp_filter_comment( $comment );
|
1369 |
|
1370 |
+
// wp_insert_comment expects slashed data
|
1371 |
+
$comment_id = wp_insert_comment( wp_slash( $comment ) );
|
1372 |
$this->mapping['comment'][ $original_id ] = $comment_id;
|
1373 |
if ( $requires_remapping ) {
|
1374 |
$this->requires_remapping['comment'][ $comment_id ] = true;
|
1385 |
*/
|
1386 |
do_action( 'wp_import_insert_comment', $comment_id, $comment, $post_id, $post );
|
1387 |
|
1388 |
+
// Process the meta items
|
1389 |
foreach ( $meta as $meta_item ) {
|
1390 |
$value = maybe_unserialize( $meta_item['value'] );
|
1391 |
add_comment_meta( $comment_id, wp_slash( $meta_item['key'] ), wp_slash( $value ) );
|
1399 |
* @param array $meta Raw meta data, already processed by {@see process_post_meta}.
|
1400 |
* @param array $post_id Parent post ID.
|
1401 |
*/
|
1402 |
+
do_action( 'wxr_importer.processed.comment', $comment_id, $comment, $meta, $post_id );
|
1403 |
|
1404 |
$num_comments++;
|
1405 |
+
}// End foreach().
|
1406 |
|
1407 |
return $num_comments;
|
1408 |
}
|
1409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1410 |
protected function parse_category_node( $node ) {
|
1411 |
$data = array(
|
1412 |
+
// Default taxonomy to "category", since this is a `<category>` tag
|
1413 |
'taxonomy' => 'category',
|
1414 |
);
|
1415 |
$meta = array();
|
1421 |
$data['slug'] = $node->getAttribute( 'nicename' );
|
1422 |
}
|
1423 |
|
1424 |
+
$data['name'] = $node->textContent;
|
1425 |
|
1426 |
if ( empty( $data['slug'] ) ) {
|
1427 |
return null;
|
1428 |
}
|
1429 |
|
1430 |
+
// Just for extra compatibility
|
1431 |
+
if ( $data['taxonomy'] === 'tag' ) {
|
1432 |
$data['taxonomy'] = 'post_tag';
|
1433 |
}
|
1434 |
|
1438 |
/**
|
1439 |
* Callback for `usort` to sort comments by ID
|
1440 |
*
|
1441 |
+
* @param array $a Comment data for the first comment
|
1442 |
+
* @param array $b Comment data for the second comment
|
1443 |
* @return int
|
1444 |
*/
|
1445 |
public static function sort_comments_by_id( $a, $b ) {
|
1454 |
return $a['comment_id'] - $b['comment_id'];
|
1455 |
}
|
1456 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1457 |
protected function parse_author_node( $node ) {
|
1458 |
$data = array();
|
1459 |
$meta = array();
|
1460 |
+
foreach ( $node->childNodes as $child ) {
|
1461 |
+
// We only care about child elements
|
1462 |
+
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
|
1463 |
continue;
|
1464 |
}
|
1465 |
|
1466 |
+
switch ( $child->tagName ) {
|
1467 |
case 'wp:author_login':
|
1468 |
+
$data['user_login'] = $child->textContent;
|
1469 |
break;
|
1470 |
|
1471 |
case 'wp:author_id':
|
1472 |
+
$data['ID'] = $child->textContent;
|
1473 |
break;
|
1474 |
|
1475 |
case 'wp:author_email':
|
1476 |
+
$data['user_email'] = $child->textContent;
|
1477 |
break;
|
1478 |
|
1479 |
case 'wp:author_display_name':
|
1480 |
+
$data['display_name'] = $child->textContent;
|
1481 |
break;
|
1482 |
|
1483 |
case 'wp:author_first_name':
|
1484 |
+
$data['first_name'] = $child->textContent;
|
1485 |
break;
|
1486 |
|
1487 |
case 'wp:author_last_name':
|
1488 |
+
$data['last_name'] = $child->textContent;
|
1489 |
break;
|
1490 |
}
|
1491 |
}
|
1493 |
return compact( 'data', 'meta' );
|
1494 |
}
|
1495 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1496 |
protected function process_author( $data, $meta ) {
|
1497 |
/**
|
1498 |
* Pre-process user data.
|
1500 |
* @param array $data User data. (Return empty to skip.)
|
1501 |
* @param array $meta Meta data.
|
1502 |
*/
|
1503 |
+
$data = apply_filters( 'wxr_importer.pre_process.user', $data, $meta );
|
1504 |
if ( empty( $data ) ) {
|
1505 |
return false;
|
1506 |
}
|
1507 |
|
1508 |
// Have we already handled this user?
|
1509 |
+
$original_id = isset( $data['ID'] ) ? $data['ID'] : 0;
|
1510 |
$original_slug = $data['user_login'];
|
1511 |
|
1512 |
if ( isset( $this->mapping['user'][ $original_id ] ) ) {
|
1513 |
$existing = $this->mapping['user'][ $original_id ];
|
1514 |
|
1515 |
+
// Note the slug mapping if we need to too
|
1516 |
if ( ! isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
|
1517 |
$this->mapping['user_slug'][ $original_slug ] = $existing;
|
1518 |
}
|
1523 |
if ( isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
|
1524 |
$existing = $this->mapping['user_slug'][ $original_slug ];
|
1525 |
|
1526 |
+
// Ensure we note the mapping too
|
1527 |
$this->mapping['user'][ $original_id ] = $existing;
|
1528 |
|
1529 |
return false;
|
1530 |
}
|
1531 |
|
1532 |
+
// Allow overriding the user's slug
|
1533 |
$login = $original_slug;
|
1534 |
if ( isset( $this->user_slug_override[ $login ] ) ) {
|
1535 |
$login = $this->user_slug_override[ $login ];
|
1536 |
}
|
1537 |
|
1538 |
$userdata = array(
|
1539 |
+
'user_login' => sanitize_user( $login, true ),
|
1540 |
+
'user_pass' => wp_generate_password(),
|
1541 |
);
|
1542 |
|
1543 |
$allowed = array(
|
1556 |
|
1557 |
$user_id = wp_insert_user( wp_slash( $userdata ) );
|
1558 |
if ( is_wp_error( $user_id ) ) {
|
1559 |
+
$this->logger->error( sprintf(
|
1560 |
+
__( 'Failed to import user "%s"', 'wordpress-importer' ),
|
1561 |
+
$userdata['user_login']
|
1562 |
+
) );
|
|
|
|
|
|
|
1563 |
$this->logger->debug( $user_id->get_error_message() );
|
1564 |
|
1565 |
/**
|
1568 |
* @param WP_Error $user_id Error object.
|
1569 |
* @param array $userdata Raw data imported for the user.
|
1570 |
*/
|
1571 |
+
do_action( 'wxr_importer.process_failed.user', $user_id, $userdata );
|
1572 |
return false;
|
1573 |
}
|
1574 |
|
1577 |
}
|
1578 |
$this->mapping['user_slug'][ $original_slug ] = $user_id;
|
1579 |
|
1580 |
+
$this->logger->info( sprintf(
|
1581 |
+
__( 'Imported user "%s"', 'wordpress-importer' ),
|
1582 |
+
$userdata['user_login']
|
1583 |
+
) );
|
1584 |
+
$this->logger->debug( sprintf(
|
1585 |
+
__( 'User %1$d remapped to %2$d', 'wordpress-importer' ),
|
1586 |
+
$original_id,
|
1587 |
+
$user_id
|
1588 |
+
) );
|
1589 |
+
|
1590 |
+
// TODO: Implement meta handling once WXR includes it
|
|
|
|
|
|
|
|
|
|
|
|
|
1591 |
/**
|
1592 |
* User processing completed.
|
1593 |
*
|
1594 |
* @param int $user_id New user ID.
|
1595 |
* @param array $userdata Raw data imported for the user.
|
1596 |
*/
|
1597 |
+
do_action( 'wxr_importer.processed.user', $user_id, $userdata );
|
1598 |
}
|
1599 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1600 |
protected function parse_term_node( $node, $type = 'term' ) {
|
1601 |
$data = array();
|
1602 |
$meta = array();
|
1608 |
'parent' => 'wp:term_parent',
|
1609 |
'name' => 'wp:term_name',
|
1610 |
'description' => 'wp:term_description',
|
1611 |
+
'termmeta' => 'wp:termmeta',
|
1612 |
);
|
1613 |
$taxonomy = null;
|
1614 |
|
1635 |
break;
|
1636 |
}
|
1637 |
|
1638 |
+
foreach ( $node->childNodes as $child ) {
|
1639 |
+
// We only care about child elements
|
1640 |
+
if ( $child->nodeType !== XML_ELEMENT_NODE ) {
|
1641 |
continue;
|
1642 |
}
|
1643 |
|
1644 |
+
$key = array_search( $child->tagName, $tag_name );
|
1645 |
+
|
1646 |
if ( $key ) {
|
1647 |
+
if ('wp:termmeta' === $child->tagName) {
|
1648 |
+
$key = '';
|
1649 |
+
$value = '';
|
1650 |
+
|
1651 |
+
foreach ($child->childNodes as $metadata) {
|
1652 |
+
if ( $metadata->nodeType !== XML_ELEMENT_NODE ) {
|
1653 |
+
continue;
|
1654 |
+
}
|
1655 |
+
|
1656 |
+
if ('wp:meta_key' === $metadata->tagName) {
|
1657 |
+
$key = $metadata->textContent;
|
1658 |
+
} else if ('wp:meta_value' === $metadata->tagName) {
|
1659 |
+
$value = $metadata->textContent;
|
1660 |
+
}
|
1661 |
+
}
|
1662 |
+
|
1663 |
+
$meta[$key] = $value;
|
1664 |
+
} else {
|
1665 |
+
$data[ $key ] = $child->textContent;
|
1666 |
+
}
|
1667 |
}
|
1668 |
}
|
1669 |
|
1671 |
return null;
|
1672 |
}
|
1673 |
|
1674 |
+
// Compatibility with WXR 1.0
|
1675 |
+
if ( $data['taxonomy'] === 'tag' ) {
|
1676 |
$data['taxonomy'] = 'post_tag';
|
1677 |
}
|
1678 |
|
1679 |
return compact( 'data', 'meta' );
|
1680 |
}
|
1681 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1682 |
protected function process_term( $data, $meta ) {
|
1683 |
/**
|
1684 |
* Pre-process term data.
|
1686 |
* @param array $data Term data. (Return empty to skip.)
|
1687 |
* @param array $meta Meta data.
|
1688 |
*/
|
1689 |
+
$data = apply_filters( 'wxr_importer.pre_process.term', $data, $meta );
|
1690 |
if ( empty( $data ) ) {
|
1691 |
return false;
|
1692 |
}
|
1693 |
|
1694 |
+
$original_id = isset( $data['id'] ) ? (int) $data['id'] : 0;
|
1695 |
+
$parent_id = isset( $data['parent'] ) ? (int) $data['parent'] : 0;
|
1696 |
|
1697 |
$mapping_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
|
1698 |
+
$existing = $this->term_exists( $data );
|
1699 |
if ( $existing ) {
|
1700 |
|
1701 |
/**
|
1703 |
*
|
1704 |
* @param array $data Raw data imported for the term.
|
1705 |
*/
|
1706 |
+
do_action( 'wxr_importer.process_already_imported.term', $data );
|
1707 |
|
1708 |
+
$this->mapping['term'][ $mapping_key ] = $existing;
|
1709 |
$this->mapping['term_id'][ $original_id ] = $existing;
|
1710 |
return false;
|
1711 |
}
|
1712 |
|
1713 |
+
// WP really likes to repeat itself in export files
|
1714 |
if ( isset( $this->mapping['term'][ $mapping_key ] ) ) {
|
1715 |
return false;
|
1716 |
}
|
1717 |
|
1718 |
$termdata = array();
|
1719 |
+
$allowed = array(
|
1720 |
+
'slug' => true,
|
1721 |
'description' => true,
|
1722 |
);
|
1723 |
|
1724 |
// Map the parent comment, or mark it as one we need to fix
|
1725 |
+
// TODO: add parent mapping and remapping
|
|
|
1726 |
/*
|
1727 |
$requires_remapping = false;
|
1728 |
if ( $parent_id ) {
|
1737 |
$data['parent'] = 0;
|
1738 |
}
|
1739 |
}*/
|
|
|
1740 |
|
1741 |
foreach ( $data as $key => $value ) {
|
1742 |
if ( ! isset( $allowed[ $key ] ) ) {
|
1748 |
|
1749 |
$result = wp_insert_term( $data['name'], $data['taxonomy'], $termdata );
|
1750 |
if ( is_wp_error( $result ) ) {
|
1751 |
+
$this->logger->warning( sprintf(
|
1752 |
+
__( 'Failed to import %1$s %2$s', 'wordpress-importer' ),
|
1753 |
+
$data['taxonomy'],
|
1754 |
+
$data['name']
|
1755 |
+
) );
|
|
|
|
|
|
|
1756 |
$this->logger->debug( $result->get_error_message() );
|
1757 |
do_action( 'wp_import_insert_term_failed', $result, $data );
|
1758 |
|
1763 |
* @param array $data Raw data imported for the term.
|
1764 |
* @param array $meta Meta data supplied for the term.
|
1765 |
*/
|
1766 |
+
do_action( 'wxr_importer.process_failed.term', $result, $data, $meta );
|
1767 |
return false;
|
1768 |
}
|
1769 |
|
1770 |
$term_id = $result['term_id'];
|
1771 |
|
1772 |
+
foreach ( $meta as $key => $value ) {
|
1773 |
+
add_term_meta( $term_id, $key, $value );
|
1774 |
+
}
|
1775 |
+
|
1776 |
+
$this->mapping['term'][ $mapping_key ] = $term_id;
|
1777 |
$this->mapping['term_id'][ $original_id ] = $term_id;
|
1778 |
|
1779 |
+
$this->logger->info( sprintf(
|
1780 |
+
__( 'Imported "%1$s" (%2$s)', 'wordpress-importer' ),
|
1781 |
+
$data['name'],
|
1782 |
+
$data['taxonomy']
|
1783 |
+
) );
|
1784 |
+
$this->logger->debug( sprintf(
|
1785 |
+
__( 'Term %1$d remapped to %2$d', 'wordpress-importer' ),
|
1786 |
+
$original_id,
|
1787 |
+
$term_id
|
1788 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
1789 |
|
1790 |
do_action( 'wp_import_insert_term', $term_id, $data );
|
1791 |
|
1795 |
* @param int $term_id New term ID.
|
1796 |
* @param array $data Raw data imported for the term.
|
1797 |
*/
|
1798 |
+
do_action( 'wxr_importer.processed.term', $term_id, $data );
|
1799 |
}
|
1800 |
|
1801 |
/**
|
1802 |
* Attempt to download a remote file attachment
|
1803 |
*
|
1804 |
+
* @param string $url URL of item to fetch
|
1805 |
+
* @param array $post Attachment details
|
1806 |
+
* @return array|WP_Error Local file location details on success, WP_Error otherwise
|
1807 |
*/
|
1808 |
protected function fetch_remote_file( $url, $post ) {
|
1809 |
+
// extract the file name and extension from the url
|
1810 |
$file_name = basename( $url );
|
1811 |
|
1812 |
+
// get placeholder file in the upload dir with a unique, sanitized filename
|
1813 |
+
$upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
|
1814 |
if ( $upload['error'] ) {
|
1815 |
return new WP_Error( 'upload_dir_error', $upload['error'] );
|
1816 |
}
|
1817 |
|
1818 |
+
// fetch the remote url and write it to the placeholder file
|
1819 |
+
$response = wp_remote_get( $url, array(
|
1820 |
+
'stream' => true,
|
1821 |
+
'filename' => $upload['file'],
|
1822 |
+
) );
|
|
|
|
|
|
|
1823 |
|
1824 |
+
// request failed
|
1825 |
if ( is_wp_error( $response ) ) {
|
1826 |
unlink( $upload['file'] );
|
1827 |
return $response;
|
1829 |
|
1830 |
$code = (int) wp_remote_retrieve_response_code( $response );
|
1831 |
|
1832 |
+
// make sure the fetch was successful
|
1833 |
+
if ( $code !== 200 ) {
|
1834 |
unlink( $upload['file'] );
|
1835 |
return new WP_Error(
|
1836 |
'import_file_error',
|
1837 |
sprintf(
|
|
|
1838 |
__( 'Remote server returned %1$d %2$s for %3$s', 'wordpress-importer' ),
|
1839 |
$code,
|
1840 |
get_status_header_desc( $code ),
|
1844 |
}
|
1845 |
|
1846 |
$filesize = filesize( $upload['file'] );
|
1847 |
+
$headers = wp_remote_retrieve_headers( $response );
|
1848 |
|
1849 |
if ( isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) {
|
1850 |
unlink( $upload['file'] );
|
1859 |
$max_size = (int) $this->max_attachment_size();
|
1860 |
if ( ! empty( $max_size ) && $filesize > $max_size ) {
|
1861 |
unlink( $upload['file'] );
|
|
|
1862 |
$message = sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) );
|
1863 |
return new WP_Error( 'import_file_error', $message );
|
1864 |
}
|
1866 |
return $upload;
|
1867 |
}
|
1868 |
|
|
|
|
|
|
|
1869 |
protected function post_process() {
|
1870 |
+
// Time to tackle any left-over bits
|
1871 |
if ( ! empty( $this->requires_remapping['post'] ) ) {
|
1872 |
$this->post_process_posts( $this->requires_remapping['post'] );
|
1873 |
}
|
1874 |
if ( ! empty( $this->requires_remapping['comment'] ) ) {
|
1875 |
$this->post_process_comments( $this->requires_remapping['comment'] );
|
1876 |
}
|
1877 |
+
|
1878 |
+
if ( ! empty( $this->mapping['term_id'] ) && current_user_can( 'activate_plugins' ) ) {
|
1879 |
+
update_option( 'responsive_sites_term_ids_mapping', $this->mapping['term_id'] );
|
1880 |
+
}
|
1881 |
}
|
1882 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1883 |
protected function post_process_posts( $todo ) {
|
1884 |
foreach ( $todo as $post_id => $_ ) {
|
1885 |
+
$this->logger->debug( sprintf(
|
1886 |
+
// Note: title intentionally not used to skip extra processing
|
1887 |
+
// for when debug logging is off
|
1888 |
+
__( 'Running post-processing for post %d', 'wordpress-importer' ),
|
1889 |
+
$post_id
|
1890 |
+
) );
|
|
|
|
|
|
|
1891 |
|
1892 |
$data = array();
|
1893 |
|
1897 |
if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
|
1898 |
$data['post_parent'] = $this->mapping['post'][ $parent_id ];
|
1899 |
} else {
|
1900 |
+
$this->logger->warning( sprintf(
|
1901 |
+
__( 'Could not find the post parent for "%1$s" (post #%2$d)', 'wordpress-importer' ),
|
1902 |
+
get_the_title( $post_id ),
|
1903 |
+
$post_id
|
1904 |
+
) );
|
1905 |
+
$this->logger->debug( sprintf(
|
1906 |
+
__( 'Post %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
|
1907 |
+
$post_id,
|
1908 |
+
$parent_id
|
1909 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
1910 |
}
|
1911 |
}
|
1912 |
|
1916 |
if ( isset( $this->mapping['user_slug'][ $author_slug ] ) ) {
|
1917 |
$data['post_author'] = $this->mapping['user_slug'][ $author_slug ];
|
1918 |
} else {
|
1919 |
+
$this->logger->warning( sprintf(
|
1920 |
+
__( 'Could not find the author for "%1$s" (post #%2$d)', 'wordpress-importer' ),
|
1921 |
+
get_the_title( $post_id ),
|
1922 |
+
$post_id
|
1923 |
+
) );
|
1924 |
+
$this->logger->debug( sprintf(
|
1925 |
+
__( 'Post %1$d was imported with author "%2$s", but could not be found', 'wordpress-importer' ),
|
1926 |
+
$post_id,
|
1927 |
+
$author_slug
|
1928 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
1929 |
}
|
1930 |
}
|
1931 |
|
1932 |
$has_attachments = get_post_meta( $post_id, '_wxr_import_has_attachment_refs', true );
|
1933 |
if ( ! empty( $has_attachments ) ) {
|
1934 |
+
$post = get_post( $post_id );
|
1935 |
$content = $post->post_content;
|
1936 |
|
1937 |
+
// Replace all the URLs we've got
|
1938 |
$new_content = str_replace( array_keys( $this->url_remap ), $this->url_remap, $content );
|
1939 |
if ( $new_content !== $content ) {
|
1940 |
$data['post_content'] = $new_content;
|
1947 |
|
1948 |
// Do we have updates to make?
|
1949 |
if ( empty( $data ) ) {
|
1950 |
+
$this->logger->debug( sprintf(
|
1951 |
+
__( 'Post %d was marked for post-processing, but none was required.', 'wordpress-importer' ),
|
1952 |
+
$post_id
|
1953 |
+
) );
|
|
|
|
|
|
|
1954 |
continue;
|
1955 |
}
|
1956 |
|
1957 |
+
// Run the update
|
1958 |
$data['ID'] = $post_id;
|
|
|
|
|
|
|
1959 |
$result = wp_update_post( $data, true );
|
1960 |
if ( is_wp_error( $result ) ) {
|
1961 |
+
$this->logger->warning( sprintf(
|
1962 |
+
__( 'Could not update "%1$s" (post #%2$d) with mapped data', 'wordpress-importer' ),
|
1963 |
+
get_the_title( $post_id ),
|
1964 |
+
$post_id
|
1965 |
+
) );
|
|
|
|
|
|
|
1966 |
$this->logger->debug( $result->get_error_message() );
|
1967 |
continue;
|
1968 |
}
|
1969 |
|
1970 |
+
// Clear out our temporary meta keys
|
1971 |
delete_post_meta( $post_id, '_wxr_import_parent' );
|
1972 |
delete_post_meta( $post_id, '_wxr_import_user_slug' );
|
1973 |
delete_post_meta( $post_id, '_wxr_import_has_attachment_refs' );
|
1974 |
+
}// End foreach().
|
1975 |
}
|
1976 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1977 |
protected function post_process_menu_item( $post_id ) {
|
1978 |
$menu_object_id = get_post_meta( $post_id, '_wxr_import_menu_item', true );
|
1979 |
if ( empty( $menu_object_id ) ) {
|
2003 |
if ( ! empty( $menu_object ) ) {
|
2004 |
update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $menu_object ) );
|
2005 |
} else {
|
2006 |
+
$this->logger->warning( sprintf(
|
2007 |
+
__( 'Could not find the menu object for "%1$s" (post #%2$d)', 'wordpress-importer' ),
|
2008 |
+
get_the_title( $post_id ),
|
2009 |
+
$post_id
|
2010 |
+
) );
|
2011 |
+
$this->logger->debug( sprintf(
|
2012 |
+
__( 'Post %1$d was imported with object "%2$d" of type "%3$s", but could not be found', 'wordpress-importer' ),
|
2013 |
+
$post_id,
|
2014 |
+
$menu_object_id,
|
2015 |
+
$menu_item_type
|
2016 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
2017 |
}
|
2018 |
|
2019 |
delete_post_meta( $post_id, '_wxr_import_menu_item' );
|
2020 |
}
|
2021 |
|
2022 |
|
|
|
|
|
|
|
|
|
|
|
|
|
2023 |
protected function post_process_comments( $todo ) {
|
2024 |
foreach ( $todo as $comment_id => $_ ) {
|
2025 |
$data = array();
|
2030 |
if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
|
2031 |
$data['comment_parent'] = $this->mapping['comment'][ $parent_id ];
|
2032 |
} else {
|
2033 |
+
$this->logger->warning( sprintf(
|
2034 |
+
__( 'Could not find the comment parent for comment #%d', 'wordpress-importer' ),
|
2035 |
+
$comment_id
|
2036 |
+
) );
|
2037 |
+
$this->logger->debug( sprintf(
|
2038 |
+
__( 'Comment %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
|
2039 |
+
$comment_id,
|
2040 |
+
$parent_id
|
2041 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
2042 |
}
|
2043 |
}
|
2044 |
|
2048 |
if ( isset( $this->mapping['user'][ $author_id ] ) ) {
|
2049 |
$data['user_id'] = $this->mapping['user'][ $author_id ];
|
2050 |
} else {
|
2051 |
+
$this->logger->warning( sprintf(
|
2052 |
+
__( 'Could not find the author for comment #%d', 'wordpress-importer' ),
|
2053 |
+
$comment_id
|
2054 |
+
) );
|
2055 |
+
$this->logger->debug( sprintf(
|
2056 |
+
__( 'Comment %1$d was imported with author %2$d, but could not be found', 'wordpress-importer' ),
|
2057 |
+
$comment_id,
|
2058 |
+
$author_id
|
2059 |
+
) );
|
|
|
|
|
|
|
|
|
|
|
|
|
2060 |
}
|
2061 |
}
|
2062 |
|
2065 |
continue;
|
2066 |
}
|
2067 |
|
2068 |
+
// Run the update
|
2069 |
+
$data['comment_ID'] = $comment_ID;
|
2070 |
+
$result = wp_update_comment( wp_slash( $data ) );
|
2071 |
if ( empty( $result ) ) {
|
2072 |
+
$this->logger->warning( sprintf(
|
2073 |
+
__( 'Could not update comment #%d with mapped data', 'wordpress-importer' ),
|
2074 |
+
$comment_id
|
2075 |
+
) );
|
|
|
|
|
|
|
2076 |
continue;
|
2077 |
}
|
2078 |
|
2079 |
+
// Clear out our temporary meta keys
|
2080 |
delete_comment_meta( $comment_id, '_wxr_import_parent' );
|
2081 |
delete_comment_meta( $comment_id, '_wxr_import_user' );
|
2082 |
+
}// End foreach().
|
2083 |
}
|
2084 |
|
2085 |
/**
|
2087 |
*/
|
2088 |
protected function replace_attachment_urls_in_content() {
|
2089 |
global $wpdb;
|
2090 |
+
// make sure we do the longest urls first, in case one is a substring of another
|
2091 |
uksort( $this->url_remap, array( $this, 'cmpr_strlen' ) );
|
2092 |
|
2093 |
foreach ( $this->url_remap as $from_url => $to_url ) {
|
2094 |
+
// remap urls in post_content
|
2095 |
$query = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url );
|
2096 |
+
$wpdb->query( $query );
|
2097 |
|
2098 |
+
// remap enclosure urls
|
2099 |
+
$query = $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url );
|
2100 |
+
$result = $wpdb->query( $query );
|
2101 |
}
|
2102 |
}
|
2103 |
|
2104 |
/**
|
2105 |
* Update _thumbnail_id meta to new, imported attachment IDs
|
2106 |
*/
|
2107 |
+
function remap_featured_images() {
|
2108 |
+
// cycle through posts that have a featured image
|
2109 |
foreach ( $this->featured_images as $post_id => $value ) {
|
2110 |
if ( isset( $this->processed_posts[ $value ] ) ) {
|
2111 |
$new_id = $this->processed_posts[ $value ];
|
2112 |
|
2113 |
+
// only update if there's a difference
|
2114 |
if ( $new_id !== $value ) {
|
2115 |
update_post_meta( $post_id, '_thumbnail_id', $new_id );
|
2116 |
}
|
2121 |
/**
|
2122 |
* Decide if the given meta key maps to information we will want to import
|
2123 |
*
|
2124 |
+
* @param string $key The meta key to check
|
2125 |
+
* @return string|bool The key if we do want to import, false if not
|
2126 |
*/
|
2127 |
public function is_valid_meta_key( $key ) {
|
2128 |
// skip attachment metadata since we'll regenerate it from scratch
|
2129 |
+
// skip _edit_lock as not relevant for import
|
2130 |
+
if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) {
|
2131 |
return false;
|
2132 |
}
|
2133 |
|
2147 |
/**
|
2148 |
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
2149 |
*
|
2150 |
+
* @access protected
|
|
|
2151 |
* @return int 60
|
2152 |
*/
|
2153 |
+
function bump_request_timeout( $val ) {
|
2154 |
return 60;
|
2155 |
}
|
2156 |
|
2157 |
+
// return the difference in length between two strings
|
2158 |
+
function cmpr_strlen( $a, $b ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
2159 |
return strlen( $b ) - strlen( $a );
|
2160 |
}
|
2161 |
|
2187 |
* @return int|bool Existing post ID if it exists, false otherwise.
|
2188 |
*/
|
2189 |
protected function post_exists( $data ) {
|
2190 |
+
// Constant-time lookup if we prefilled
|
2191 |
$exists_key = $data['guid'];
|
2192 |
|
2193 |
if ( $this->options['prefill_existing_posts'] ) {
|
2194 |
return isset( $this->exists['post'][ $exists_key ] ) ? $this->exists['post'][ $exists_key ] : false;
|
2195 |
}
|
2196 |
|
2197 |
+
// No prefilling, but might have already handled it
|
2198 |
if ( isset( $this->exists['post'][ $exists_key ] ) ) {
|
2199 |
return $this->exists['post'][ $exists_key ];
|
2200 |
}
|
2201 |
|
2202 |
+
// Still nothing, try post_exists, and cache it
|
2203 |
+
$exists = post_exists( $data['post_title'], $data['post_content'], $data['post_date'] );
|
2204 |
$this->exists['post'][ $exists_key ] = $exists;
|
2205 |
|
2206 |
return $exists;
|
2213 |
* @param int $post_id Post ID.
|
2214 |
*/
|
2215 |
protected function mark_post_exists( $data, $post_id ) {
|
2216 |
+
$exists_key = $data['guid'];
|
2217 |
$this->exists['post'][ $exists_key ] = $post_id;
|
2218 |
}
|
2219 |
|
2227 |
$posts = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_date FROM {$wpdb->comments}" );
|
2228 |
|
2229 |
foreach ( $posts as $item ) {
|
2230 |
+
$exists_key = sha1( $item->comment_author . ':' . $item->comment_date );
|
2231 |
$this->exists['comment'][ $exists_key ] = $item->comment_ID;
|
2232 |
}
|
2233 |
}
|
2241 |
protected function comment_exists( $data ) {
|
2242 |
$exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
|
2243 |
|
2244 |
+
// Constant-time lookup if we prefilled
|
2245 |
if ( $this->options['prefill_existing_comments'] ) {
|
2246 |
return isset( $this->exists['comment'][ $exists_key ] ) ? $this->exists['comment'][ $exists_key ] : false;
|
2247 |
}
|
2248 |
|
2249 |
+
// No prefilling, but might have already handled it
|
2250 |
if ( isset( $this->exists['comment'][ $exists_key ] ) ) {
|
2251 |
return $this->exists['comment'][ $exists_key ];
|
2252 |
}
|
2253 |
|
2254 |
+
// Still nothing, try comment_exists, and cache it
|
2255 |
+
$exists = comment_exists( $data['comment_author'], $data['comment_date'] );
|
2256 |
$this->exists['comment'][ $exists_key ] = $exists;
|
2257 |
|
2258 |
return $exists;
|
2265 |
* @param int $comment_id Comment ID.
|
2266 |
*/
|
2267 |
protected function mark_comment_exists( $data, $comment_id ) {
|
2268 |
+
$exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
|
2269 |
$this->exists['comment'][ $exists_key ] = $comment_id;
|
2270 |
}
|
2271 |
|
2276 |
*/
|
2277 |
protected function prefill_existing_terms() {
|
2278 |
global $wpdb;
|
2279 |
+
$query = "SELECT t.term_id, tt.taxonomy, t.slug FROM {$wpdb->terms} AS t";
|
2280 |
$query .= " JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id";
|
2281 |
+
$terms = $wpdb->get_results( $query );
|
2282 |
|
2283 |
foreach ( $terms as $item ) {
|
2284 |
+
$exists_key = sha1( $item->taxonomy . ':' . $item->slug );
|
2285 |
$this->exists['term'][ $exists_key ] = $item->term_id;
|
2286 |
}
|
2287 |
}
|
2295 |
protected function term_exists( $data ) {
|
2296 |
$exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
|
2297 |
|
2298 |
+
// Constant-time lookup if we prefilled
|
2299 |
if ( $this->options['prefill_existing_terms'] ) {
|
2300 |
return isset( $this->exists['term'][ $exists_key ] ) ? $this->exists['term'][ $exists_key ] : false;
|
2301 |
}
|
2302 |
|
2303 |
+
// No prefilling, but might have already handled it
|
2304 |
if ( isset( $this->exists['term'][ $exists_key ] ) ) {
|
2305 |
return $this->exists['term'][ $exists_key ];
|
2306 |
}
|
2307 |
|
2308 |
+
// Still nothing, try comment_exists, and cache it
|
2309 |
$exists = term_exists( $data['slug'], $data['taxonomy'] );
|
2310 |
if ( is_array( $exists ) ) {
|
2311 |
$exists = $exists['term_id'];
|
2323 |
* @param int $term_id Term ID.
|
2324 |
*/
|
2325 |
protected function mark_term_exists( $data, $term_id ) {
|
2326 |
+
$exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
|
2327 |
$this->exists['term'][ $exists_key ] = $term_id;
|
2328 |
}
|
2329 |
}
|
2330 |
+
endif;
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: elementor templates, block templates, one click demo import, readymade web
|
|
5 |
Requires at least: 5.0
|
6 |
Tested up to: 6.1.1
|
7 |
Requires PHP: 5.6
|
8 |
-
Stable tag: 2.7.
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -194,6 +194,9 @@ With the Pro version you will get Premium templates, Priority support and automa
|
|
194 |
|
195 |
== Changelog ==
|
196 |
|
|
|
|
|
|
|
197 |
= 2.7.0 - 5th December 2022 =
|
198 |
* Fix - Fixed issues related to forms
|
199 |
|
5 |
Requires at least: 5.0
|
6 |
Tested up to: 6.1.1
|
7 |
Requires PHP: 5.6
|
8 |
+
Stable tag: 2.7.1
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
194 |
|
195 |
== Changelog ==
|
196 |
|
197 |
+
= 2.7.1 - 14th December 2022 =
|
198 |
+
* Fix - Improved importing
|
199 |
+
|
200 |
= 2.7.0 - 5th December 2022 =
|
201 |
* Fix - Fixed issues related to forms
|
202 |
|
responsive-add-ons.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Responsive Starter Templates
|
4 |
* Plugin URI: http://wordpress.org/plugins/responsive-add-ons/
|
5 |
* Description: Responsive Starter Templates offers you a library of premium Elementor and block templates so you can launch your website quickly. Just select your favorite website template, click import and launch your website.
|
6 |
-
* Version: 2.7.
|
7 |
* Author: CyberChimps
|
8 |
* Author URI: https://cyberchimps.com
|
9 |
* License: GPL2
|
@@ -46,7 +46,7 @@ if ( ! defined( 'RESPONSIVE_ADDONS_URI' ) ) {
|
|
46 |
}
|
47 |
|
48 |
if ( ! defined( 'RESPONSIVE_ADDONS_VER' ) ) {
|
49 |
-
define( 'RESPONSIVE_ADDONS_VER', '2.7.
|
50 |
}
|
51 |
|
52 |
/**
|
3 |
* Plugin Name: Responsive Starter Templates
|
4 |
* Plugin URI: http://wordpress.org/plugins/responsive-add-ons/
|
5 |
* Description: Responsive Starter Templates offers you a library of premium Elementor and block templates so you can launch your website quickly. Just select your favorite website template, click import and launch your website.
|
6 |
+
* Version: 2.7.1
|
7 |
* Author: CyberChimps
|
8 |
* Author URI: https://cyberchimps.com
|
9 |
* License: GPL2
|
46 |
}
|
47 |
|
48 |
if ( ! defined( 'RESPONSIVE_ADDONS_VER' ) ) {
|
49 |
+
define( 'RESPONSIVE_ADDONS_VER', '2.7.1' );
|
50 |
}
|
51 |
|
52 |
/**
|