WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#44494 closed feature request (fixed)

Add option to hide en_US in wp_dropdown_languages()

Reported by: swissspidy Owned by: swissspidy
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

While working on the Preferred Languages project I noticed that it's not possible to hide the English (United States) option in wp_dropdown_languages().

In my case, I do not need the en_US because of the way the UI works: When I do not pick a language from the dropdown, en_US will be the default. Screenshot: https://cloudup.com/cXhxw4KPqFc

While I added a workaround using JavaScript, I think there should be a) a show_option_en_US parameter or b) a filter (e.g. $output = apply_filters( 'wp_dropdown_languages', $output, $languages, $parsed_args )) at the end of the function. Or perhaps even both.

Attachments (3)

44494.diff (1005 bytes) - added by danieltj 3 years ago.
44494.2.diff (2.5 KB) - added by swissspidy 3 years ago.
44494.3.diff (2.8 KB) - added by swissspidy 3 years ago.
Updates docs

Download all attachments as: .zip

Change History (13)

#1 @danieltj
3 years ago

wp_dropdown_languages() already supports $args so I'm in favour of supporting another argument in that array to exclude certain locales by slug or something.

languages is also already supported though; I suppose you could reverse engineer it so you get the full list list of locales, then remove en_US and then use the updated list (minus en_US) to request as those specific locales. Not ideal, but serves as a better work around than JavaScript perhaps.

Ref: https://developer.wordpress.org/reference/functions/wp_dropdown_languages/

@danieltj
3 years ago

#2 @danieltj
3 years ago

  • Keywords has-patch needs-testing added; needs-patch good-first-bug removed
  • Type changed from defect (bug) to feature request

I've changed the ticket type to feature as it's not really a bug as nothing is broken here.

I've added a patch which adds an extra argument for en_US. Simple, but does the job.

#3 @Luciano Croce
3 years ago

Great, I agree this!

#4 @swissspidy
3 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 5.0

Needs updated docs and probably an other name (I'd really use show_option_... for consistency), otherwise 👍

#5 @swissspidy
3 years ago

  • Milestone changed from 5.0 to 5.1

#6 @pento
3 years ago

@swissspidy: Do you still need this?

#7 @swissspidy
3 years ago

  • Owner set to swissspidy
  • Status changed from new to accepted

@pento Yep. Happy to land it for 5.1.

@swissspidy
3 years ago

#8 @swissspidy
3 years ago

  • Keywords has-unit-tests added; needs-testing needs-refresh removed

@swissspidy
3 years ago

Updates docs

#9 @swissspidy
3 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 44514:

I18N: Add option to hide en_US locale in wp_dropdown_languages().

Props danieltj for initial patch.
Fixes #44494.

#10 @swissspidy
3 years ago

In 44516:

Build/Test Tools: Fix coding standards issues after [44515] and [44514].

See #44494, #43743.

Note: See TracTickets for help on using tickets.