@@ -25,6 +25,10 @@ class Import_Command extends WP_CLI_Command {
2525 * [--skip=<data-type>]
2626 * : Skip importing specific data. Supported options are: 'attachment' and 'image_resize' (skip time-consuming thumbnail generation).
2727 *
28+ * [--rewrite_urls]
29+ * : Change all imported URLs that currently link to the previous site so that they now link to this site
30+ * Requires WordPress Importer version 0.9.1 or newer.
31+ *
2832 * ## EXAMPLES
2933 *
3034 * # Import content from a WXR file
@@ -38,8 +42,9 @@ class Import_Command extends WP_CLI_Command {
3842 */
3943 public function __invoke ( $ args , $ assoc_args ) {
4044 $ defaults = array (
41- 'authors ' => null ,
42- 'skip ' => array (),
45+ 'authors ' => null ,
46+ 'skip ' => array (),
47+ 'rewrite_urls ' => null ,
4348 );
4449 $ assoc_args = wp_parse_args ( $ assoc_args , $ defaults );
4550
@@ -195,7 +200,25 @@ private function import_wxr( $file, $args ) {
195200 }
196201
197202 $ GLOBALS ['wpcli_import_current_file ' ] = basename ( $ file );
198- $ wp_import ->import ( $ file );
203+
204+ $ reflection = new \ReflectionMethod ( $ wp_import , 'import ' );
205+ $ number_of_arguments = $ reflection ->getNumberOfParameters ();
206+
207+ if ( null !== $ args ['rewrite_urls ' ] && $ number_of_arguments < 2 ) {
208+ WP_CLI ::error ( 'URL rewriting requires WordPress Importer version 0.9.1 or newer. ' );
209+ }
210+
211+ if ( $ number_of_arguments > 1 ) {
212+ $ wp_import ->import (
213+ $ file ,
214+ [
215+ 'rewrite_urls ' => $ args ['rewrite_urls ' ],
216+ ]
217+ );
218+ } else {
219+ $ wp_import ->import ( $ file );
220+ }
221+
199222 $ this ->processed_posts += $ wp_import ->processed_posts ;
200223
201224 return true ;
0 commit comments