Make WordPress Core

Opened 3 years ago

Last modified 6 months ago

#58284 new defect (bug)

Add in wp_dropdown_languages en_US as selected value when 'explicit_option_en_us' is set to true

Reported by: ekaliva's profile ekaliva Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

When in the function "wp_dropdown_languages" the option "explicit_option_en_us" is set to true and the locale-value of the User is "en_us" the option is still not selected. The value in the selected function (l10n.php, L. 1591) is empty:

<?php
selected( '', $parsed_args['selected'], false )

This cause problems when the default language of the WMPU network is set from english to another language.

The bugfix could be the following (l10n.php L. 1586 - L.1593):

<?php
if ( $parsed_args['show_option_en_us'] ) {
                $value       = ( $parsed_args['explicit_option_en_us'] ) ? 'en_US' : '';
                $structure[] = sprintf(
                        '<option value="%s" lang="en" data-installed="1"%s>English (United States)</option>',
                        esc_attr( $value ),
                        selected( $value, $parsed_args['selected'], false )
                );
        }

Thank you very much

Change History (2)

#1 @SirLouen
6 months ago

  • Keywords has-patch needs-testing removed

This ticket was mentioned in PR #9598 on WordPress/wordpress-develop by @iamadisingh.


6 months ago
#2

  • Keywords has-patch has-unit-tests added

This PR fixes a bug in wp_dropdown_languages() where the English (United States) option would not be properly selected when using explicit_option_en_us=true and selected='en_US'.

Trac ticket: https://core.trac.wordpress.org/ticket/58284

---
### Tests

Added test coverage for the specific bug scenario

npm run test:php -- tests/phpunit/tests/l10n.php --filter test_wp_dropdown_languages
  • test_wp_dropdown_languages_explicit_option_en_us_selected() - Tests the specific bug scenario where explicit_option_en_us=true and selected='en_US'
Note: See TracTickets for help on using tickets.