From 581419d39477ba89ba3ea7c6c41f24aad676a7ff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:24:24 +0000 Subject: [PATCH 1/7] Initial plan From 8e6f6179efb48bca83203d2597fc61678a3e00ea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 13:27:47 +0000 Subject: [PATCH 2/7] Add --importer argument to specify alternative importer class Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/import.feature | 50 +++++++++++++++++++++++++++++++++++++++++ src/Import_Command.php | 21 ++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/features/import.feature b/features/import.feature index 9dc099a4..e3c214f5 100644 --- a/features/import.feature +++ b/features/import.feature @@ -400,3 +400,53 @@ Feature: Import content. https://newsite.com/ """ + @require-wp-5.2 @require-mysql + Scenario: Specifying a non-existent importer class produces an error + Given a WP install + And I run `wp plugin install wordpress-importer --activate` + + When I run `wp export` + Then save STDOUT 'Writing to file %s' as {EXPORT_FILE} + + When I try `wp import {EXPORT_FILE} --authors=skip --importer=NonExistentImporterClass` + Then STDERR should contain: + """ + Error: Importer class 'NonExistentImporterClass' does not exist. + """ + And the return code should be 1 + + @require-wp-5.2 @require-mysql + Scenario: Specifying an importer class that is not a subclass of WP_Import produces an error + Given a WP install + And I run `wp plugin install wordpress-importer --activate` + + When I run `wp export` + Then save STDOUT 'Writing to file %s' as {EXPORT_FILE} + + When I try `wp import {EXPORT_FILE} --authors=skip --importer=WP_CLI_Command` + Then STDERR should contain: + """ + Error: Importer class 'WP_CLI_Command' must be a subclass of WP_Import. + """ + And the return code should be 1 + + @require-wp-5.2 @require-mysql + Scenario: Specifying a valid custom importer subclass succeeds + Given a WP install + And I run `wp plugin install wordpress-importer --activate` + And a wp-content/mu-plugins/custom-importer.php file: + """ + ] + * : Use a custom importer class instead of the default WP_Import. The class must exist and be a subclass of WP_Import. + * * ## EXAMPLES * * # Import content from a WXR file @@ -45,6 +48,7 @@ public function __invoke( $args, $assoc_args ) { 'authors' => null, 'skip' => [], 'rewrite_urls' => null, + 'importer' => 'WP_Import', ); $assoc_args = wp_parse_args( $assoc_args, $defaults ); @@ -57,6 +61,19 @@ public function __invoke( $args, $assoc_args ) { WP_CLI::error( $importer ); } + $importer_class = $assoc_args['importer']; + if ( 'WP_Import' !== $importer_class ) { + if ( ! preg_match( '/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff\\\\]*$/', $importer_class ) ) { + WP_CLI::error( "Importer class '$importer_class' is not a valid class name." ); + } + if ( ! class_exists( $importer_class ) ) { + WP_CLI::error( "Importer class '$importer_class' does not exist." ); + } + if ( ! is_subclass_of( $importer_class, 'WP_Import' ) ) { + WP_CLI::error( "Importer class '$importer_class' must be a subclass of WP_Import." ); + } + } + $this->add_wxr_filters(); WP_CLI::log( 'Starting the import process...' ); @@ -117,7 +134,9 @@ public function __invoke( $args, $assoc_args ) { */ private function import_wxr( $file, $args ) { - $wp_import = new WP_Import(); + $importer_class = $args['importer']; + /** @var WP_Import $wp_import */ + $wp_import = new $importer_class(); $wp_import->processed_posts = $this->processed_posts; $import_data = $wp_import->parse( $file ); From 604d177d8f6b5458c25e7f15a6ebe00dc11c6c26 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 16 Mar 2026 10:42:33 +0100 Subject: [PATCH 3/7] Fix test --- features/import.feature | 12 ++++++++++++ src/Import_Command.php | 3 --- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/features/import.feature b/features/import.feature index e3c214f5..ec9714a2 100644 --- a/features/import.feature +++ b/features/import.feature @@ -437,6 +437,18 @@ Feature: Import content. And a wp-content/mu-plugins/custom-importer.php file: """ Date: Mon, 16 Mar 2026 10:53:18 +0100 Subject: [PATCH 4/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- features/import.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/import.feature b/features/import.feature index ec9714a2..8ada1278 100644 --- a/features/import.feature +++ b/features/import.feature @@ -445,7 +445,7 @@ Feature: Import content. require_once ABSPATH . 'wp-admin/includes/class-wp-importer.php'; } - if ( ! class_exists( 'WP_IMPORT' ) ) { + if ( ! class_exists( 'WP_Import' ) ) { require_once WP_PLUGIN_DIR . '/wordpress-importer/class-wp-import.php'; } From 2e967f70cefca919ac6c6cf2ea3b1136c7f410a2 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 16 Mar 2026 10:53:25 +0100 Subject: [PATCH 5/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Import_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index 9090b331..9978005c 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -63,10 +63,10 @@ public function __invoke( $args, $assoc_args ) { $importer_class = $assoc_args['importer']; if ( 'WP_Import' !== $importer_class ) { - if ( ! class_exists( $importer_class ) ) { + if ( ! class_exists( $importer_class, false ) ) { WP_CLI::error( "Importer class '$importer_class' does not exist." ); } - if ( ! is_subclass_of( $importer_class, 'WP_Import' ) ) { + if ( ! is_subclass_of( $importer_class, 'WP_Import', false ) ) { WP_CLI::error( "Importer class '$importer_class' must be a subclass of WP_Import." ); } } From 75bd90d102c326d068067a33a500a96bbe46e17d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 12:09:29 +0000 Subject: [PATCH 6/7] Fix test: remove WP_LOAD_IMPORTERS guard from custom importer mu-plugin Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/import.feature | 4 ---- 1 file changed, 4 deletions(-) diff --git a/features/import.feature b/features/import.feature index 8ada1278..bc640983 100644 --- a/features/import.feature +++ b/features/import.feature @@ -437,10 +437,6 @@ Feature: Import content. And a wp-content/mu-plugins/custom-importer.php file: """ Date: Mon, 16 Mar 2026 14:45:18 +0000 Subject: [PATCH 7/7] Fix is_subclass_of: remove incorrect false argument that disabled string class names Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Import_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index 9978005c..b6cf7c41 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -66,7 +66,7 @@ public function __invoke( $args, $assoc_args ) { if ( ! class_exists( $importer_class, false ) ) { WP_CLI::error( "Importer class '$importer_class' does not exist." ); } - if ( ! is_subclass_of( $importer_class, 'WP_Import', false ) ) { + if ( ! is_subclass_of( $importer_class, 'WP_Import' ) ) { WP_CLI::error( "Importer class '$importer_class' must be a subclass of WP_Import." ); } }