Opened 20 months ago
Closed 13 days ago
#63009 closed defect (bug) (fixed)
setup-config errors are not localised
| Reported by: | johnbillion | Owned by: | johnbillion |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Upgrade/Install | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description (last modified by )
There are two error messages shown in setup-config.php that are not localised.
- If
wp-config-sample.phpis missing during the initial installation, the error message stating this is always shown in English rather than the language chosen in the first step of installation (from$_REQUEST['language']).- To reproduce, delete or rename both
wp-config.phpandwp-config-sample.phpand then attempt tp proceed through the installation steps.
- To reproduce, delete or rename both
- Manually visiting wp-admin/setup-config.php during normal site operation will show an error message stating that the
wp-config.phpfile already exists. This is always shown in English rather than the installed site language (from theWPLANGoption).- To reproduce, visit
wp-admin/setup-config.phpduring normal site operation.
- To reproduce, visit
Affected error messages: https://github.com/WordPress/wordpress-develop/blob/fc96319aa770050d22cfdc1bbab437154017bcf7/src/wp-admin/setup-config.php#L43-L82
Change History (12)
#3
@
20 months ago
Looks like I got confused while testing this. The wp-config-sample.php error message is correctly localised when you attempt to install a localised package, for example the de_DE package from https://de.wordpress.org/latest-de_DE.zip:
Die Datei wp-config-sample.php ist erforderlich. Bitte lade diese erneut zu deiner WordPress-Installation hoch.
There doesn't appear to be a way to reach this error message in the standard package, unless you manually delete wp-config-sample.php after you've selected a language.
So it looks like the only actual issue is the second one, whereby visiting wp-admin/setup-config.php during normal site operation always shows the message in English.
#4
@
20 months ago
The wp-config-sample.php error message is correctly localised when you attempt to install a localised package
Huh, I wonder why that is though.
#5
@
20 months ago
Probably due to the $wp_local_package = 'de_DE'; line in wp-includes/version.php.
#6
@
18 months ago
Really not sure what would be the best way to address (2), additional suggestions welcome.
#7
@
2 weeks ago
Replying to @swissspidy in comment:6. I built a working fix for (2) and then talked myself out of attaching it. Posting what I found instead, since the constraints seem more useful than the patch.
Why the straightforward approaches do not work
The file has changed since this ticket was opened, so a couple of these are worth recording:
setup-config.phpnow requireswp-settings.phpdirectly near the top, so loadingwp-config.phpafter that point does nothing for the bootstrap (require_once), andSHORTINIThas no effect either.get_option()returnsfalseunconditionally whileWP_SETUP_CONFIGis defined (wp-includes/option.php), so the locale has to be read with a direct query.- The
wpdbconstructor returns beforedb_connect()underWP_SETUP_CONFIG, so the connection has to be made by hand, as the existing code already does further down when validating submitted credentials. - Loading
wp-config.phpafterwp-settings.phpemitsConstant WP_DEBUG already defined, becausewp_initial_constants()has already run andwp-config-sample.phpdefines it unguarded.
That leaves loading wp-config.php before wp-settings.php as the only place it can happen cleanly. That works: I tested it on trunk with PHP 8.3 and a non-default table prefix, and the message renders in the site language with the 409 preserved and a clean error log. Plugins and themes stay unloaded, since WP_INSTALLING is defined before anything and both wp_get_active_and_valid_plugins() and wp_get_active_and_valid_themes() bail while installing.
The problems with doing that
Four, and together I do not think they are worth one string:
- A malformed
wp-config.phpbreaks the page.error_reporting( 0 )at the top of the file swallows the E_PARSE, so under PHP-FPM you get HTTP 200 with an empty body and nothing logged anywhere. Under other SAPIs you get a 500. Todaysetup-config.phprenders its notice regardless of what is in that file. - On a site with
WP_DEBUGenabled and stale credentials in the config, the manual connect surfacesmysqli_real_connect(): Access deniedfrom the unsilenced branch atclass-wpdb.php:1999. Silencing it works, but it means adding anotherphpcs:ignore WordPress.PHP.NoSilencedErrors.Discouragedto core. - Mu-plugins and drop-ins such as
object-cache.phpwould start loading from the site's realWP_CONTENT_DIRon this path, where today they load from the default. - It only covers half the problem anyway. WordPress supports
wp-config.phpone directory above ABSPATH, and that layout hits the secondwp_die()further down, which would still be in English. Covering both means loading a config from either location, which widens the blast radius again.
Suggestion
Given (1) and (4) in particular, wontfix looks reasonable to me, or narrowing the ticket to something achievable. If you think the trade is worth making I am happy to clean up the patch and attach it, including the dirname( ABSPATH ) case, but I did not want to put a patch on the ticket that quietly makes a broken config harder to diagnose.
This ticket was mentioned in PR #13631 on WordPress/wordpress-develop by @swissspidy.
2 weeks ago
#8
- Keywords has-patch added; needs-patch removed
Previously, wp-admin/setup-config.php always bootstrapped WordPress without a configuration file (WP_SETUP_CONFIG), even when a wp-config.php file already existed. As a result, the "already exists" error message could not be translated into the site's language, because the table prefix and thus the WPLANG option were unknown.
Check for an existing configuration file first, mirroring the lookup in wp-load.php, and if one is found, load WordPress through it like any other request would. The site's locale is then known and the message is displayed in the site language, both for a wp-config.php file in the WordPress root and for one located one level above it.
Trac ticket: https://core.trac.wordpress.org/ticket/63009
Use of AI Tools
Used Claude Code
@swissspidy commented on PR #13631:
2 weeks ago
#9
Some trade-offs/notes:
- A broken wp-config.php now breaks setup-config.php the way it breaks every other page. I think that is correct, since the old notice told people with a broken config to delete it and reinstall, but it is a behavior change.
- mu-plugins and drop-ins load in that branch like on any request. Plugins and themes do not, because of WP_INSTALLING.
- Not tested on multisite. install.php uses the identical bootstrap there, so I expect no difference.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
For (1):
When I rename/delete both
wp-config.phpwp-config-sample.php, I don't even get to the language chooser. I immediately get redirected tosetup-config.phpwith "Sorry, I need awp-config-sample.phpfile to work from.". In this case no language information is available of course and this will always be in English.Can you perhaps clarify this part?
For (2):
The main issue here seems to be that the found
wp-config.phpfile isn't actually loaded, sowp-settings.php(which was loaded earlier by itself) andwpdbdon't know the actual table prefix, so the locale information can't be loaded from the database.To change the behavior here, I think the file would need to be refactored quite a bit so that if a config file already exists, it is actually loaded. Then the locale information is known and the translation could be loaded.