From 9c18a5c6e942b424e894de2e575b96b7a385025f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 27 Mar 2020 21:56:24 +0000 Subject: [PATCH] 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 git-svn-id: https://develop.svn.wordpress.org/trunk@47516 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/user.php | 26 +++++++++++++------------- src/wp-admin/user-new.php | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index 4411880768..f99c50d85c 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -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' : ''; diff --git a/src/wp-admin/user-new.php b/src/wp-admin/user-new.php index be4b5083bc..9e36e2a6e0 100644 --- a/src/wp-admin/user-new.php +++ b/src/wp-admin/user-new.php @@ -498,6 +498,32 @@ if ( current_user_can( 'create_users' ) ) { + + + + + + + 'locale', + 'id' => 'locale', + 'selected' => 'site-default', + 'languages' => $languages, + 'show_available_translations' => false, + 'show_option_site_default' => true, + ) ); + ?> + + +