Users: Add a user language preference option to the "Add New User" form.

This uses the same language selection control as the user editing screen and allows new users to be invited to a site in their own language.

Props barryceelen, johnbillion

Fixes #38665
Built from https://develop.svn.wordpress.org/trunk@47516


git-svn-id: http://core.svn.wordpress.org/trunk@47291 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2020-03-27 21:58:05 +00:00
parent 38e37b83df
commit 41ae74f7b4
3 changed files with 40 additions and 14 deletions

View File

@ -112,25 +112,25 @@ function edit_user( $user_id = 0 ) {
}
}
if ( isset( $_POST['locale'] ) ) {
$locale = sanitize_text_field( $_POST['locale'] );
if ( 'site-default' === $locale ) {
$locale = '';
} elseif ( '' === $locale ) {
$locale = 'en_US';
} elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
$locale = '';
}
$user->locale = $locale;
}
if ( $update ) {
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
$user->syntax_highlighting = isset( $_POST['syntax_highlighting'] ) && 'false' === $_POST['syntax_highlighting'] ? 'false' : 'true';
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
$user->locale = '';
if ( isset( $_POST['locale'] ) ) {
$locale = sanitize_text_field( $_POST['locale'] );
if ( 'site-default' === $locale ) {
$locale = '';
} elseif ( '' === $locale ) {
$locale = 'en_US';
} elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
$locale = '';
}
$user->locale = $locale;
}
}
$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' == $_POST['comment_shortcuts'] ? 'true' : '';

View File

@ -498,6 +498,32 @@ if ( current_user_can( 'create_users' ) ) {
<th scope="row"><label for="url"><?php _e( 'Website' ); ?></label></th>
<td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td>
</tr>
<?php
$languages = get_available_languages();
if ( $languages ) : ?>
<tr class="form-field user-language-wrap">
<th scope="row">
<label for="locale">
<?php /* translators: The user language selection field label */ ?>
<?php _e( 'Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span>
</label>
</th>
<td>
<?php
wp_dropdown_languages( array(
'name' => 'locale',
'id' => 'locale',
'selected' => 'site-default',
'languages' => $languages,
'show_available_translations' => false,
'show_option_site_default' => true,
) );
?>
</td>
</tr>
<?php
endif;
?>
<tr class="form-field form-required user-pass1-wrap">
<th scope="row">
<label for="pass1">

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-47515';
$wp_version = '5.5-alpha-47516';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.