Skip to content

Add --skip-locale-check flag to wp core download for locale fallback#322

Merged
swissspidy merged 4 commits intomainfrom
copilot/fix-wp-core-download-crash
Mar 20, 2026
Merged

Add --skip-locale-check flag to wp core download for locale fallback#322
swissspidy merged 4 commits intomainfrom
copilot/fix-wp-core-download-crash

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

When a new WordPress release hasn't been translated yet, wp core download --locale=fr_FR crashes because the version-check API returns only en_US offers, causing get_core_download_offer() to return false.

As an opt-in behavior, a new --skip-locale-check flag falls back to the latest version that is available for the requested locale rather than erroring.

How it works

  • When get_core_download_offer($locale) returns false and --skip-locale-check is set, the new find_latest_offer_for_locale() method queries https://api.wordpress.org/translations/core/1.0/ to find the locale's latest translated version
  • Constructs a download offer using the existing get_download_url() helper and emits a warning
  • If the locale has no translations at all, the original error is preserved
# Previously crashed with: Error: The requested locale (fr_FR) was not found.
$ wp core download --locale=fr_FR --skip-locale-check
Warning: The latest WordPress version is not yet available in the fr_FR locale. Downloading version 6.2.2 instead.
...
Success: WordPress downloaded.

Changes

  • src/Core_Command.php: Added [--skip-locale-check] option; extracted WpOrgApi instantiation to a named variable; added private find_latest_offer_for_locale(string $locale, bool $insecure): array|false helper
  • features/core-download.feature: Three new scenarios covering: locale unavailable without flag (error), locale unavailable with flag (fallback success + warning), and flag set but locale has no translation at all (error)
Original prompt

This section details on the original issue you should resolve

<issue_title>wp core download crash when latest WP version is not in the desired locale</issue_title>
<issue_description>## Bug Report

wp core download --locale=xx_XX crash when lastest WP version is not in the desired locale

wp core download && wp language core install fr_FR --activate
is broken too (install ok but not the lang, switching to FR in admin break the website with sql errors)

Example

wp --allow-root core download --locale=fr_FR --force
crash with :
Error: The requested locale (fr_FR ) was not found.

Temp fix force previous version

wp --allow-root core download --locale=fr_FR --version=6.2.2 --force

Solution
allow this command to download the lastest version (6.2.2, instead of 6.3 in the example) to use the desired locale.
wp --allow-root core download --locale=fr_FR --force

or add a flag to allow downloading the previous working version.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Thanks for the report, @neoteknic !

This is a known issue that unfortunately occurs until the locale release is ready.

allow this command to download the lastest version (6.2.2, instead of 6.3 in the example) to use the desired locale. wp --allow-root core download --locale=fr_FR --force

or add a flag to allow downloading the previous working version.

I don't think we should automatically downgrade. Making it a specific opt-in behavior with a flag seems fine, though.

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 86.48649% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Core_Command.php 86.48% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

…version

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix wp core download crash for unsupported locale Add --skip-locale-check flag to wp core download for locale fallback Mar 20, 2026
Copilot AI requested a review from swissspidy March 20, 2026 11:55
@swissspidy swissspidy marked this pull request as ready for review March 20, 2026 21:46
@swissspidy swissspidy requested a review from a team as a code owner March 20, 2026 21:46
Copilot AI review requested due to automatic review settings March 20, 2026 21:46
@swissspidy swissspidy added this to the 2.1.26 milestone Mar 20, 2026
@swissspidy swissspidy merged commit 1f518df into main Mar 20, 2026
62 checks passed
@swissspidy swissspidy deleted the copilot/fix-wp-core-download-crash branch March 20, 2026 21:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in fallback for wp core download --locale=… when the latest WordPress release isn’t yet translated for the requested locale, via a new --skip-locale-check flag that consults the WordPress.org translations API.

Changes:

  • Adds --skip-locale-check to wp core download to fall back to the latest available translated version when the locale isn’t offered for the latest release.
  • Introduces find_latest_offer_for_locale() to query https://api.wordpress.org/translations/core/1.0/ and construct a usable download offer.
  • Adds Behat scenarios covering the error case, fallback + warning case, and “no translations exist” case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/Core_Command.php Implements the --skip-locale-check fallback behavior and translations API lookup helper.
features/core-download.feature Adds Behat coverage for locale-unavailable behavior with and without the new flag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +90 to +95
When I try `wp core download --locale=de_DE --skip-locale-check`
Then the wp-settings.php file should exist
And STDERR should contain:
"""
Warning: The latest WordPress version is not yet available in the de_DE locale. Downloading version 4.4.2 instead.
"""
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario expects a successful download, but it uses When I try ... and doesn’t assert a zero exit code. To make the test reliably fail when the command fails, use When I run ... (or explicitly assert Then the return code should be 0).

Copilot uses AI. Check for mistakes.
use WP_CLI\Extractor;
use WP_CLI\Iterators\Table as TableIterator;
use WP_CLI\Utils;
use WP_CLI\Path;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use WP_CLI\Path; introduces a WP_CLI\Path dependency, but this package doesn’t define that class anywhere (and the rest of this file uses the WP_CLI\Utils\… function helpers). Unless WP_CLI\Path is guaranteed to exist in the supported wp-cli/wp-cli versions, this will cause a fatal error. Consider reverting these changes back to Utils\trailingslashit() / Utils\phar_safe_path() (or importing the correct helper namespace/class if a Path helper is intended).

Suggested change
use WP_CLI\Path;

Copilot uses AI. Check for mistakes.
Comment on lines 717 to 720
// Set SCRIPT_FILENAME to the actual WordPress index.php if available.
if ( file_exists( Utils\trailingslashit( ABSPATH ) . 'index.php' ) ) {
$_SERVER['SCRIPT_FILENAME'] = Utils\trailingslashit( ABSPATH ) . 'index.php';
if ( file_exists( Path::trailingslashit( ABSPATH ) . 'index.php' ) ) {
$_SERVER['SCRIPT_FILENAME'] = Path::trailingslashit( ABSPATH ) . 'index.php';
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path::trailingslashit() is used here, but this file previously relied on the Utils\trailingslashit() function. If WP_CLI\Path is not available (or doesn’t provide trailingslashit()), this will fatal at runtime. Please keep this consistent with the rest of the command by using the existing Utils\trailingslashit() helper (or confirm the correct Path helper import and API).

Copilot uses AI. Check for mistakes.
Comment on lines 1077 to 1080
private static function get_template_path( $template ) {
$command_root = Utils\phar_safe_path( dirname( __DIR__ ) );
$command_root = Path::phar_safe( dirname( __DIR__ ) );
$template_path = "{$command_root}/templates/{$template}";

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path::phar_safe() appears to replace the existing Utils\phar_safe_path() helper. If WP_CLI\Path/phar_safe() isn’t part of the supported WP-CLI API, this will break template resolution at runtime. Consider reverting to Utils\phar_safe_path() or updating to the correct, verified helper name/namespace.

Copilot uses AI. Check for mistakes.
Comment on lines 2092 to 2094
}
$abspath_realpath_trailing = Utils\trailingslashit( $abspath_realpath );
$abspath_realpath_trailing = Path::trailingslashit( $abspath_realpath );

Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same Path::trailingslashit() concern applies here: if WP_CLI\Path isn’t available (or doesn’t implement trailingslashit()), file cleanup will fatal. Using the existing Utils\trailingslashit() helper keeps this consistent with the rest of the codebase and avoids introducing an unverified dependency.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:core-download Related to 'core download' command state:unconfirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp core download crash when latest WP version is not in the desired locale

3 participants