From 9119396df855757e62f1baf2ae385e0fa0078c1f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 17:36:48 +0000 Subject: [PATCH 01/11] Initial plan From db738978fd9c9bd3c918c746fadf768217daa72b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 17:45:54 +0000 Subject: [PATCH 02/11] Add HTTP URL and STDIN support to wp import command Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/import.feature | 90 +++++++++++++++++++++++++++++++++++++++++ src/Import_Command.php | 86 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 170 insertions(+), 6 deletions(-) diff --git a/features/import.feature b/features/import.feature index bc640983..a210fdc2 100644 --- a/features/import.feature +++ b/features/import.feature @@ -458,3 +458,93 @@ Feature: Import content. Then STDOUT should not be empty And STDERR should be empty + @require-wp-5.2 @require-mysql + Scenario: Import from STDIN + Given a WP install + And I run `wp plugin install wordpress-importer --activate` + And I run `wp site empty --yes` + And I run `wp post generate --post_type=post --count=2` + + When I run `wp post list --post_type=post --format=count` + Then STDOUT should be: + """ + 2 + """ + + When I run `wp export` + Then save STDOUT 'Writing to file %s' as {EXPORT_FILE} + + When I run `wp site empty --yes` + Then STDOUT should not be empty + + When I run `wp post list --post_type=post --format=count` + Then STDOUT should be: + """ + 0 + """ + + When I run `cat {EXPORT_FILE} | wp import - --authors=skip` + Then STDOUT should contain: + """ + Starting the import process... + """ + And STDOUT should contain: + """ + Finished importing from 'STDIN' file. + """ + And STDERR should be empty + + When I run `wp post list --post_type=post --format=count` + Then STDOUT should be: + """ + 2 + """ + + @require-wp-5.2 @require-mysql + Scenario: Import from a URL + Given a WP install + And I run `wp plugin install wordpress-importer --activate` + And I run `wp site empty --yes` + And I run `wp post generate --post_type=post --count=2` + + When I run `wp post list --post_type=post --format=count` + Then STDOUT should be: + """ + 2 + """ + + When I run `wp export` + Then save STDOUT 'Writing to file %s' as {EXPORT_FILE} + + When I run `wp site empty --yes` + Then STDOUT should not be empty + + When I run `wp post list --post_type=post --format=count` + Then STDOUT should be: + """ + 0 + """ + + Given a PHP built-in web server + + When I run `wp import http://localhost:8080/{EXPORT_FILE} --authors=skip` + Then STDOUT should contain: + """ + Starting the import process... + """ + And STDOUT should contain: + """ + Downloading 'http://localhost:8080/ + """ + And STDOUT should contain: + """ + Finished importing from 'http://localhost:8080/ + """ + And STDERR should be empty + + When I run `wp post list --post_type=post --format=count` + Then STDOUT should be: + """ + 2 + """ + diff --git a/src/Import_Command.php b/src/Import_Command.php index b6cf7c41..7ed19265 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -18,6 +18,7 @@ class Import_Command extends WP_CLI_Command { * * ... * : Path to one or more valid WXR files for importing. Directories are also accepted. + * A URL to a WXR file is also accepted. Use '-' to import from STDIN. * * --authors= * : How the author mapping should be handled. Options are 'create', 'mapping.csv', or 'skip'. The first will create any non-existent users from the WXR file. The second will read author mapping associations from a CSV, or create a CSV for editing if the file path doesn't exist. The CSV requires two columns, and a header row like "old_user_login,new_user_login". The last option will skip any author mapping. @@ -42,6 +43,17 @@ class Import_Command extends WP_CLI_Command { * -- Tue, 21 Jun 2016 05:31:12 +0000 * -- Imported post as post_id #1 * Success: Finished importing from 'example.wordpress.2016-06-21.xml' file. + * + * # Import content from a WXR file via HTTP + * $ wp import https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml --authors=import + * Starting the import process... + * Downloading 'https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml'... + * Success: Finished importing from 'https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml' file. + * + * # Import content from STDIN + * $ wp export --stdout | wp import - --authors=skip + * Starting the import process... + * Success: Finished importing from 'STDIN' file. */ public function __invoke( $args, $assoc_args ) { $defaults = array( @@ -75,8 +87,50 @@ public function __invoke( $args, $assoc_args ) { WP_CLI::log( 'Starting the import process...' ); - $new_args = []; + $new_args = []; + $temp_files = []; // Map of temp_file_path => original source (URL or 'STDIN') + foreach ( $args as $arg ) { + // Handle STDIN input + if ( '-' === $arg ) { + if ( ! \WP_CLI\Utils\has_stdin() ) { + WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); + continue; + } + + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + $stdin_content = file_get_contents( 'php://stdin' ); + if ( false === $stdin_content || '' === $stdin_content ) { + WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); + continue; + } + + $temp_file = wp_tempnam( 'wp-import-stdin' ); + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents + if ( false === file_put_contents( $temp_file, $stdin_content ) ) { + WP_CLI::warning( 'Unable to import from STDIN. Could not write to temporary file.' ); + continue; + } + + $new_args[] = $temp_file; + $temp_files[ $temp_file ] = 'STDIN'; + continue; + } + + // Handle HTTP/HTTPS/FTP URLs + $scheme = wp_parse_url( $arg, PHP_URL_SCHEME ); + if ( $scheme && in_array( strtolower( $scheme ), [ 'http', 'https', 'ftp', 'ftps' ], true ) ) { + WP_CLI::log( "Downloading '{$arg}'..." ); + $temp_file = download_url( $arg ); + if ( is_wp_error( $temp_file ) ) { + WP_CLI::warning( sprintf( "Unable to import from URL '%s'. %s", $arg, $temp_file->get_error_message() ) ); + continue; + } + $new_args[] = $temp_file; + $temp_files[ $temp_file ] = $arg; + continue; + } + if ( is_dir( $arg ) ) { $dir = WP_CLI\Utils\trailingslashit( $arg ); $files = glob( $dir . '*.wxr' ); @@ -114,22 +168,28 @@ public function __invoke( $args, $assoc_args ) { $args = $new_args; foreach ( $args as $file ) { - - $ret = $this->import_wxr( $file, $assoc_args ); + $display_name = isset( $temp_files[ $file ] ) ? $temp_files[ $file ] : null; + $ret = $this->import_wxr( $file, $assoc_args, $display_name ); if ( is_wp_error( $ret ) ) { + $this->cleanup_temp_files( $temp_files ); WP_CLI::error( $ret ); } else { WP_CLI::log( '' ); // WXR import ends with HTML, so make sure message is on next line - WP_CLI::success( "Finished importing from '$file' file." ); + $source = null !== $display_name ? $display_name : $file; + WP_CLI::success( "Finished importing from '$source' file." ); } } + + $this->cleanup_temp_files( $temp_files ); } /** * Imports a WXR file. + * + * @param string $display_name Optional display name for the source (e.g. URL or 'STDIN'). */ - private function import_wxr( $file, $args ) { + private function import_wxr( $file, $args, $display_name = null ) { $importer_class = $args['importer']; /** @var WP_Import $wp_import */ @@ -218,7 +278,7 @@ private function import_wxr( $file, $args ) { add_filter( 'intermediate_image_sizes_advanced', array( $this, 'filter_set_image_sizes' ) ); } - $GLOBALS['wpcli_import_current_file'] = basename( $file ); + $GLOBALS['wpcli_import_current_file'] = null !== $display_name ? basename( $display_name ) : basename( $file ); $reflection = new \ReflectionMethod( $wp_import, 'import' ); $number_of_arguments = $reflection->getNumberOfParameters(); @@ -248,6 +308,20 @@ public function filter_set_image_sizes( $sizes ) { return null; } + /** + * Removes temporary files created during import. + * + * @param array $temp_files Map of temp_file_path => original source. + */ + private function cleanup_temp_files( array $temp_files ) { + foreach ( $temp_files as $temp_file => $_ ) { + if ( file_exists( $temp_file ) ) { + // phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink + unlink( $temp_file ); + } + } + } + /** * Defines useful verbosity filters for the WXR importer. */ From 8c48eec0310285d6dc89e3b27f94af5809dd1fa2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:18:00 +0000 Subject: [PATCH 03/11] Update HTTP example URL to WordPress/theme-test-data Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Import_Command.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index 7ed19265..8963d14f 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -45,10 +45,10 @@ class Import_Command extends WP_CLI_Command { * Success: Finished importing from 'example.wordpress.2016-06-21.xml' file. * * # Import content from a WXR file via HTTP - * $ wp import https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml --authors=import + * $ wp import https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml --authors=skip * Starting the import process... - * Downloading 'https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml'... - * Success: Finished importing from 'https://raw.githubusercontent.com/WPTRT/theme-unit-test/master/themeunittestdata.wordpress.xml' file. + * Downloading 'https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml'... + * Success: Finished importing from 'https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml' file. * * # Import content from STDIN * $ wp export --stdout | wp import - --authors=skip From e79f550dcd2ff220d9f96e31a1ddb1d82e951d4f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 22:43:25 +0000 Subject: [PATCH 04/11] Simplify URL import test to use GitHub remote URL directly Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/import.feature | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/features/import.feature b/features/import.feature index a210fdc2..0f3c3794 100644 --- a/features/import.feature +++ b/features/import.feature @@ -504,47 +504,19 @@ Feature: Import content. Scenario: Import from a URL Given a WP install And I run `wp plugin install wordpress-importer --activate` - And I run `wp site empty --yes` - And I run `wp post generate --post_type=post --count=2` - - When I run `wp post list --post_type=post --format=count` - Then STDOUT should be: - """ - 2 - """ - - When I run `wp export` - Then save STDOUT 'Writing to file %s' as {EXPORT_FILE} - - When I run `wp site empty --yes` - Then STDOUT should not be empty - When I run `wp post list --post_type=post --format=count` - Then STDOUT should be: - """ - 0 - """ - - Given a PHP built-in web server - - When I run `wp import http://localhost:8080/{EXPORT_FILE} --authors=skip` + When I run `wp import https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml --authors=skip` Then STDOUT should contain: """ Starting the import process... """ And STDOUT should contain: """ - Downloading 'http://localhost:8080/ + Downloading 'https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml'... """ And STDOUT should contain: """ - Finished importing from 'http://localhost:8080/ + Finished importing from 'https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml' file. """ And STDERR should be empty - When I run `wp post list --post_type=post --format=count` - Then STDOUT should be: - """ - 2 - """ - From 984f042bf50dc6c7432f37d6c457381222c884e4 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 20 Mar 2026 09:56:15 +0100 Subject: [PATCH 05/11] Update src/Import_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Import_Command.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index 8963d14f..27cbf5cb 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -187,7 +187,9 @@ public function __invoke( $args, $assoc_args ) { /** * Imports a WXR file. * - * @param string $display_name Optional display name for the source (e.g. URL or 'STDIN'). + * @param string $file Path or URL to the WXR file being imported. + * @param array{authors: ?string, skip: array, rewrite_urls: ?bool, importer: class-string} $args Arguments controlling the import behavior. + * @param string|null $display_name Optional display name for the source (e.g. URL or 'STDIN'). */ private function import_wxr( $file, $args, $display_name = null ) { From f137b7796ad6e338cb99d942472c72779651476d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 20 Mar 2026 09:58:05 +0100 Subject: [PATCH 06/11] Update features/import.feature Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- features/import.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/import.feature b/features/import.feature index 0f3c3794..c53ab503 100644 --- a/features/import.feature +++ b/features/import.feature @@ -505,18 +505,18 @@ Feature: Import content. Given a WP install And I run `wp plugin install wordpress-importer --activate` - When I run `wp import https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml --authors=skip` + When I run `wp import https://raw.githubusercontent.com/WordPress/theme-test-data/b47acf980696897936265182cb684dca648476c7/theme-preview.xml --authors=skip` Then STDOUT should contain: """ Starting the import process... """ And STDOUT should contain: """ - Downloading 'https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml'... + Downloading 'https://raw.githubusercontent.com/WordPress/theme-test-data/b47acf980696897936265182cb684dca648476c7/theme-preview.xml'... """ And STDOUT should contain: """ - Finished importing from 'https://raw.githubusercontent.com/WordPress/theme-test-data/refs/heads/master/theme-preview.xml' file. + Finished importing from 'https://raw.githubusercontent.com/WordPress/theme-test-data/b47acf980696897936265182cb684dca648476c7/theme-preview.xml' file. """ And STDERR should be empty From 6beb3a9382c68dbb401fe94f6dc61ecf579fd321 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 20 Mar 2026 09:58:44 +0100 Subject: [PATCH 07/11] Update src/Import_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Import_Command.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index 27cbf5cb..e58ec55b 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -98,20 +98,34 @@ public function __invoke( $args, $assoc_args ) { continue; } - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - $stdin_content = file_get_contents( 'php://stdin' ); - if ( false === $stdin_content || '' === $stdin_content ) { - WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); + $stdin_handle = fopen( 'php://stdin', 'rb' ); + if ( false === $stdin_handle ) { + WP_CLI::warning( 'Unable to import from STDIN. Could not open STDIN stream.' ); continue; } $temp_file = wp_tempnam( 'wp-import-stdin' ); - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents - if ( false === file_put_contents( $temp_file, $stdin_content ) ) { - WP_CLI::warning( 'Unable to import from STDIN. Could not write to temporary file.' ); + if ( ! $temp_file ) { + fclose( $stdin_handle ); + WP_CLI::warning( 'Unable to import from STDIN. Could not create temporary file.' ); + continue; + } + + $temp_handle = fopen( $temp_file, 'wb' ); + if ( false === $temp_handle ) { + fclose( $stdin_handle ); + WP_CLI::warning( 'Unable to import from STDIN. Could not open temporary file for writing.' ); continue; } + $bytes_copied = stream_copy_to_stream( $stdin_handle, $temp_handle ); + fclose( $stdin_handle ); + fclose( $temp_handle ); + + if ( false === $bytes_copied || 0 === $bytes_copied ) { + WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); + continue; + } $new_args[] = $temp_file; $temp_files[ $temp_file ] = 'STDIN'; continue; From 228725e86a7922737c38b70e1f053e911701ce3e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 20 Mar 2026 12:25:17 +0100 Subject: [PATCH 08/11] Update dependency, lint fixes --- composer.json | 2 +- src/Import_Command.php | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 2e1b1940..35d1434e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "wp-cli/wp-cli": "^2.12" + "wp-cli/wp-cli": "^2.13" }, "require-dev": { "wordpress/wordpress-importer": "^0.9", diff --git a/src/Import_Command.php b/src/Import_Command.php index e58ec55b..c0192f0f 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -54,6 +54,9 @@ class Import_Command extends WP_CLI_Command { * $ wp export --stdout | wp import - --authors=skip * Starting the import process... * Success: Finished importing from 'STDIN' file. + * + * @param array $args Positional arguments. + * @param array{authors: 'create'|'mappings.csv'|'skip', skip?: string, rewrite_urls?: bool, importer?: string} $assoc_args Associative arguments. */ public function __invoke( $args, $assoc_args ) { $defaults = array( @@ -68,6 +71,10 @@ public function __invoke( $args, $assoc_args ) { $assoc_args['skip'] = explode( ',', $assoc_args['skip'] ); } + /** + * @var array{authors: 'create'|'mappings.csv'|'skip', skip: array, rewrite_urls: bool, importer: class-string} $assoc_args + */ + $importer = $this->is_importer_available(); if ( is_wp_error( $importer ) ) { WP_CLI::error( $importer ); @@ -201,9 +208,9 @@ public function __invoke( $args, $assoc_args ) { /** * Imports a WXR file. * - * @param string $file Path or URL to the WXR file being imported. - * @param array{authors: ?string, skip: array, rewrite_urls: ?bool, importer: class-string} $args Arguments controlling the import behavior. - * @param string|null $display_name Optional display name for the source (e.g. URL or 'STDIN'). + * @param string $file Path or URL to the WXR file being imported. + * @param array{authors: string, skip: array, rewrite_urls: ?bool, importer: class-string} $args Arguments controlling the import behavior. + * @param string|null $display_name Optional display name for the source (e.g. URL or 'STDIN'). */ private function import_wxr( $file, $args, $display_name = null ) { @@ -495,10 +502,12 @@ private function process_author_mapping( $authors_arg, $author_data ) { private function read_author_mapping_file( $file ) { $author_mapping = []; + /** + * @var array{old_user_login?: \WP_User, new_user_login?: \WP_User} $author + */ + // TODO: Fix type upstream. + // @phpstan-ignore varTag.nativeType foreach ( new \WP_CLI\Iterators\CSV( $file ) as $i => $author ) { - /** - * @var array $author - */ if ( ! array_key_exists( 'old_user_login', $author ) || ! array_key_exists( 'new_user_login', $author ) ) { return new WP_Error( 'invalid-author-mapping', "Author mapping file isn't properly formatted." ); } @@ -530,8 +539,6 @@ private function create_author_mapping_file( $file, $author_data ) { return new WP_Error( 'author-mapping-error', "Couldn't create author mapping file." ); } - // TODO: Fix $rows type upstream in write_csv() - // @phpstan-ignore argument.type \WP_CLI\Utils\write_csv( $file_resource, $author_mapping, array( 'old_user_login', 'new_user_login' ) ); return new WP_Error( 'author-mapping-error', sprintf( 'Please update author mapping file before continuing: %s', $file ) ); From ecd5391c39e58594ab8523174e4fc3a0b3386b8b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 20 Mar 2026 12:29:36 +0100 Subject: [PATCH 09/11] Update src/Import_Command.php --- src/Import_Command.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index c0192f0f..f532f38f 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -129,10 +129,11 @@ public function __invoke( $args, $assoc_args ) { fclose( $stdin_handle ); fclose( $temp_handle ); - if ( false === $bytes_copied || 0 === $bytes_copied ) { - WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); - continue; - } + if ( false === $bytes_copied || 0 === $bytes_copied ) { + unlink( $temp_file ); + WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); + continue; + } $new_args[] = $temp_file; $temp_files[ $temp_file ] = 'STDIN'; continue; From df1ae73ecec0d04e08ad5bbddca0a070a7ee30ff Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 20 Mar 2026 12:29:53 +0100 Subject: [PATCH 10/11] Update src/Import_Command.php --- src/Import_Command.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index f532f38f..fd76655f 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -119,11 +119,12 @@ public function __invoke( $args, $assoc_args ) { } $temp_handle = fopen( $temp_file, 'wb' ); - if ( false === $temp_handle ) { - fclose( $stdin_handle ); - WP_CLI::warning( 'Unable to import from STDIN. Could not open temporary file for writing.' ); - continue; - } + if ( false === $temp_handle ) { + fclose( $stdin_handle ); + unlink( $temp_file ); + WP_CLI::warning( 'Unable to import from STDIN. Could not open temporary file for writing.' ); + continue; + } $bytes_copied = stream_copy_to_stream( $stdin_handle, $temp_handle ); fclose( $stdin_handle ); From 1be2078c1c10e0b2351b52d8561b3d8b531392dc Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 20 Mar 2026 12:36:26 +0100 Subject: [PATCH 11/11] Lint fix --- src/Import_Command.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index fd76655f..361b32b1 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -119,22 +119,22 @@ public function __invoke( $args, $assoc_args ) { } $temp_handle = fopen( $temp_file, 'wb' ); - if ( false === $temp_handle ) { - fclose( $stdin_handle ); - unlink( $temp_file ); - WP_CLI::warning( 'Unable to import from STDIN. Could not open temporary file for writing.' ); - continue; - } + if ( false === $temp_handle ) { + fclose( $stdin_handle ); + unlink( $temp_file ); + WP_CLI::warning( 'Unable to import from STDIN. Could not open temporary file for writing.' ); + continue; + } $bytes_copied = stream_copy_to_stream( $stdin_handle, $temp_handle ); fclose( $stdin_handle ); fclose( $temp_handle ); - if ( false === $bytes_copied || 0 === $bytes_copied ) { - unlink( $temp_file ); - WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); - continue; - } + if ( false === $bytes_copied || 0 === $bytes_copied ) { + unlink( $temp_file ); + WP_CLI::warning( 'Unable to import from STDIN. No data provided.' ); + continue; + } $new_args[] = $temp_file; $temp_files[ $temp_file ] = 'STDIN'; continue;