From 6f328df996b99e715fab67325edca23e14a062bb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 09:15:50 +0000 Subject: [PATCH 1/3] Initial plan From b784d35b8042e196177d5d876a4d4486d0d77540 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 09:21:37 +0000 Subject: [PATCH 2/3] Fix: Limit export filename sitename to 50 chars to prevent long filename errors Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/export.feature | 14 ++++++++++++++ src/Export_Command.php | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/features/export.feature b/features/export.feature index 8415ddea..9050fa6a 100644 --- a/features/export.feature +++ b/features/export.feature @@ -648,6 +648,20 @@ Feature: Export content. 000.xml """ + Scenario: Export a site with a very long site name produces a filename within a reasonable length + Given a WP install + And I run `wp option update blogname 'This is a very long site name that exceeds fifty characters and should be truncated in the export filename'` + + When I run `wp export` + Then STDOUT should contain: + """ + thisisaverylongsitenamethatexceedsfiftycharactersa.wordpress. + """ + And STDOUT should not contain: + """ + thisisaverylongsitenamethatexceedsfiftycharactersandshouldbetruncated + """ + @require-wp-5.2 @require-mysql Scenario: Export a site and skip the comments Given a WP install diff --git a/src/Export_Command.php b/src/Export_Command.php index ea25ca74..c9241ece 100644 --- a/src/Export_Command.php +++ b/src/Export_Command.php @@ -20,6 +20,11 @@ */ class Export_Command extends WP_CLI_Command { + /** + * Maximum length of the site name component in the export filename. + */ + const MAX_FILENAME_SITENAME_LENGTH = 50; + /** * Initialize the array of arguments that will be eventually be passed to export_wp. * @@ -222,6 +227,7 @@ private static function get_filename_template( $filename_format ) { if ( empty( $sitename ) ) { $sitename = 'site'; } + $sitename = substr( $sitename, 0, self::MAX_FILENAME_SITENAME_LENGTH ); return str_replace( [ '{site}', '{date}', '{n}' ], [ $sitename, date( 'Y-m-d' ), '%03d' ], $filename_format ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date } From 2e8c53a71995203600fba27909d8c9b59237bcf4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 09:48:30 +0000 Subject: [PATCH 3/3] Use mb_substr when available for sitename truncation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Export_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Export_Command.php b/src/Export_Command.php index c9241ece..184bfa6f 100644 --- a/src/Export_Command.php +++ b/src/Export_Command.php @@ -227,7 +227,7 @@ private static function get_filename_template( $filename_format ) { if ( empty( $sitename ) ) { $sitename = 'site'; } - $sitename = substr( $sitename, 0, self::MAX_FILENAME_SITENAME_LENGTH ); + $sitename = function_exists( 'mb_substr' ) ? mb_substr( $sitename, 0, self::MAX_FILENAME_SITENAME_LENGTH ) : substr( $sitename, 0, self::MAX_FILENAME_SITENAME_LENGTH ); return str_replace( [ '{site}', '{date}', '{n}' ], [ $sitename, date( 'Y-m-d' ), '%03d' ], $filename_format ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date }