Make WordPress Core

Changeset 47516


Ignore:
Timestamp:
03/27/2020 09:56:24 PM (6 years ago)
Author:
johnbillion
Message:

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

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/user.php

    r47219 r47516  
    113113        }
    114114
     115        if ( isset( $_POST['locale'] ) ) {
     116                $locale = sanitize_text_field( $_POST['locale'] );
     117                if ( 'site-default' === $locale ) {
     118                        $locale = '';
     119                } elseif ( '' === $locale ) {
     120                        $locale = 'en_US';
     121                } elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
     122                        $locale = '';
     123                }
     124
     125                $user->locale = $locale;
     126        }
     127
    115128        if ( $update ) {
    116129                $user->rich_editing         = isset( $_POST['rich_editing'] ) && 'false' === $_POST['rich_editing'] ? 'false' : 'true';
     
    119132                $user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
    120133                $user->locale               = '';
    121 
    122                 if ( isset( $_POST['locale'] ) ) {
    123                         $locale = sanitize_text_field( $_POST['locale'] );
    124                         if ( 'site-default' === $locale ) {
    125                                 $locale = '';
    126                         } elseif ( '' === $locale ) {
    127                                 $locale = 'en_US';
    128                         } elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
    129                                 $locale = '';
    130                         }
    131 
    132                         $user->locale = $locale;
    133                 }
    134134        }
    135135
  • trunk/src/wp-admin/user-new.php

    r47218 r47516  
    499499                <td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td>
    500500        </tr>
     501        <?php
     502        $languages = get_available_languages();
     503        if ( $languages ) : ?>
     504                <tr class="form-field user-language-wrap">
     505                        <th scope="row">
     506                                <label for="locale">
     507                                        <?php /* translators: The user language selection field label */ ?>
     508                                        <?php _e( 'Language' ); ?><span class="dashicons dashicons-translation" aria-hidden="true"></span>
     509                                </label>
     510                        </th>
     511                        <td>
     512                                <?php
     513                                wp_dropdown_languages( array(
     514                                        'name'                        => 'locale',
     515                                        'id'                          => 'locale',
     516                                        'selected'                    => 'site-default',
     517                                        'languages'                   => $languages,
     518                                        'show_available_translations' => false,
     519                                        'show_option_site_default'    => true,
     520                                ) );
     521                                ?>
     522                        </td>
     523                </tr>
     524        <?php
     525        endif;
     526        ?>
    501527        <tr class="form-field form-required user-pass1-wrap">
    502528                <th scope="row">
Note: See TracChangeset for help on using the changeset viewer.