Add --skip-locale-check flag to wp core download for locale fallback#322
Add --skip-locale-check flag to wp core download for locale fallback#322swissspidy merged 4 commits intomainfrom
--skip-locale-check flag to wp core download for locale fallback#322Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…version Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
--skip-locale-check flag to wp core download for locale fallback
There was a problem hiding this comment.
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-checktowp core downloadto 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 queryhttps://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.
| 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. | ||
| """ |
There was a problem hiding this comment.
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).
| use WP_CLI\Extractor; | ||
| use WP_CLI\Iterators\Table as TableIterator; | ||
| use WP_CLI\Utils; | ||
| use WP_CLI\Path; |
There was a problem hiding this comment.
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).
| use WP_CLI\Path; |
| // 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'; | ||
| } |
There was a problem hiding this comment.
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).
| 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}"; | ||
|
|
There was a problem hiding this comment.
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.
| } | ||
| $abspath_realpath_trailing = Utils\trailingslashit( $abspath_realpath ); | ||
| $abspath_realpath_trailing = Path::trailingslashit( $abspath_realpath ); | ||
|
|
There was a problem hiding this comment.
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.
When a new WordPress release hasn't been translated yet,
wp core download --locale=fr_FRcrashes because the version-check API returns onlyen_USoffers, causingget_core_download_offer()to returnfalse.As an opt-in behavior, a new
--skip-locale-checkflag falls back to the latest version that is available for the requested locale rather than erroring.How it works
get_core_download_offer($locale)returnsfalseand--skip-locale-checkis set, the newfind_latest_offer_for_locale()method querieshttps://api.wordpress.org/translations/core/1.0/to find the locale's latest translated versionget_download_url()helper and emits a warningChanges
src/Core_Command.php: Added[--skip-locale-check]option; extractedWpOrgApiinstantiation to a named variable; added privatefind_latest_offer_for_locale(string $locale, bool $insecure): array|falsehelperfeatures/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
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.