Language selection field on registration form

Question

Can someone help to adjust this code? It was meant for the backend, bu I would like to add it edit it to add to the registration form on the frontend.

The goal is to add a custom registration field where user can select their preferred language from a dropdown in which they will also receive emails. Currently using TranslatePress as a translation plugin.

Code:

/**
 * Display available language dropdown
 */
function wpse_user_language( $user ) 
{
    // Only display for non-admins, but allow admins to edit for other users
    if( current_user_can( 'manage_options' ) && $user->ID == get_current_user_id() )
        return;

    // Get the current 'wp_lang' settings
    $lang = get_user_meta( $user->ID, 'wpse_lang', true ); 
    ?>
    <table class="form-table">
        <tr id="wpse-lang-selection">
            <th scope="row">
               <label for="wpse_lang">
                   <?php _e( 'WPSE' ); ?> - <?php _e( 'Site Language' ); ?>
               </label>
            </th>
            <td><?php wp_dropdown_languages( 
                    [
                        'id'                          => 'wpse_lang',
                        'name'                        => 'wpse_lang',
                        'languages'                   => get_available_languages(),
                        'translations'                => [],
                        'selected'                    => $lang,
                        'show_available_translations' => false,
                    ] 
                );
            ?></td>
        </tr>
    </table>
    <?php
}
add_action( 'show_user_profile', 'wpse_user_language' );
add_action( 'edit_user_profile', 'wpse_user_language' );
0
, , , , Sanfe 1 year 2020-07-16T02:10:31-05:00 0 Answers 68 views 0

Leave an answer

Browse
Browse