On this page
mu_dropdown_languages( string[] $lang_files = array(), string $current = '' )
Generates and displays a drop-down of available languages.
Parameters
$lang_filesstring[] Optional-
An array of the language files.
Default:
array() $currentstring Optional-
The current language code.
Default:
''
Source
File: wp-admin/includes/ms.php. View all references
function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
$flag = false;
$output = array();
foreach ( (array) $lang_files as $val ) {
$code_lang = basename( $val, '.mo' );
if ( 'en_US' === $code_lang ) { // American English.
$flag = true;
$ae = __( 'American English' );
$output[ $ae ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
} elseif ( 'en_GB' === $code_lang ) { // British English.
$flag = true;
$be = __( 'British English' );
$output[ $be ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
} else {
$translated = format_code_lang( $code_lang );
$output[ $translated ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html( $translated ) . '</option>';
}
}
if ( false === $flag ) { // WordPress English.
$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . '</option>';
}
// Order by name.
uksort( $output, 'strnatcasecmp' );
/**
* Filters the languages available in the dropdown.
*
* @since MU (3.0.0)
*
* @param string[] $output Array of HTML output for the dropdown.
* @param string[] $lang_files Array of available language files.
* @param string $current The current language code.
*/
$output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
echo implode( "\n\t", $output );
}
Hooks
- apply_filters( 'mu_dropdown_languages',
string[] $output ,string[] $lang_files ,string $current ) -
Filters the languages available in the dropdown.
Related
Uses
| Uses | Description |
|---|---|
| format_code_lang() wp-admin/includes/ms.php | Returns the language for a language code. |
| selected() wp-includes/general-template.php | Outputs the HTML selected attribute. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| esc_html() wp-includes/formatting.php | Escaping for HTML blocks. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/mu_dropdown_languages