Make WordPress Core

Ticket #53226: 53226.4.diff

File 53226.4.diff, 12.5 KB (added by kapilpaul, 5 years ago)

Updated patch. add support for wp_lang in whole login screen

  • src/wp-login.php

    diff --git a/src/wp-login.php b/src/wp-login.php
    index 5f1e8bc10d..e119d37c2c 100644
    a b function login_footer( $input_id = '' ) { 
    286286                        <?php
    287287                        $html_link = sprintf(
    288288                                '<a href="%s">%s</a>',
    289                                 esc_url( home_url( '/' ) ),
     289                                esc_url( maybe_add_wp_lang_query_arg( home_url( '/' ) ) ),
    290290                                sprintf(
    291291                                        /* translators: %s: Site title. */
    292292                                        _x( '&larr; Go to %s', 'site' ),
    switch ( $action ) { 
    472472                 * However this action runs on a redirect after logging in.
    473473                 */
    474474                if ( ! is_user_logged_in() ) {
    475                         wp_safe_redirect( wp_login_url() );
     475                        wp_safe_redirect( maybe_add_wp_lang_query_arg( wp_login_url() ) );
    476476                        exit;
    477477                }
    478478
    switch ( $action ) { 
    485485                if ( current_user_can( 'manage_options' ) ) {
    486486                        $admin_email = get_option( 'admin_email' );
    487487                } else {
    488                         wp_safe_redirect( $redirect_to );
     488                        wp_safe_redirect( maybe_add_wp_lang_query_arg( $redirect_to ) );
    489489                        exit;
    490490                }
    491491
    switch ( $action ) { 
    502502
    503503                if ( ! empty( $_GET['remind_me_later'] ) ) {
    504504                        if ( ! wp_verify_nonce( $_GET['remind_me_later'], 'remind_me_later_nonce' ) ) {
    505                                 wp_safe_redirect( wp_login_url() );
     505                                wp_safe_redirect( maybe_add_wp_lang_query_arg( wp_login_url() ) );
    506506                                exit;
    507507                        }
    508508
    switch ( $action ) { 
    510510                                update_option( 'admin_email_lifespan', time() + $remind_interval );
    511511                        }
    512512
    513                         $redirect_to = add_query_arg( 'admin_email_remind_later', 1, $redirect_to );
     513                        $redirect_to = maybe_add_wp_lang_query_arg( add_query_arg( 'admin_email_remind_later', 1, $redirect_to ) );
    514514                        wp_safe_redirect( $redirect_to );
    515515                        exit;
    516516                }
    517517
    518518                if ( ! empty( $_POST['correct-admin-email'] ) ) {
    519519                        if ( ! check_admin_referer( 'confirm_admin_email', 'confirm_admin_email_nonce' ) ) {
    520                                 wp_safe_redirect( wp_login_url() );
     520                                wp_safe_redirect( maybe_add_wp_lang_query_arg( wp_login_url() ) );
    521521                                exit;
    522522                        }
    523523
    switch ( $action ) { 
    536536                                update_option( 'admin_email_lifespan', time() + $admin_email_check_interval );
    537537                        }
    538538
    539                         wp_safe_redirect( $redirect_to );
     539                        wp_safe_redirect( maybe_add_wp_lang_query_arg( $redirect_to ) );
    540540                        exit;
    541541                }
    542542
    switch ( $action ) { 
    554554
    555555                ?>
    556556
    557                 <form class="admin-email-confirm-form" name="admin-email-confirm-form" action="<?php echo esc_url( site_url( 'wp-login.php?action=confirm_admin_email', 'login_post' ) ); ?>" method="post">
     557                <form class="admin-email-confirm-form" name="admin-email-confirm-form" action="<?php echo esc_url( maybe_add_wp_lang_query_arg( site_url( 'wp-login.php?action=confirm_admin_email', 'login_post' ) ) ); ?>" method="post">
    558558                        <?php
    559559                        /**
    560560                         * Fires inside the admin-email-confirm-form form tags, before the hidden fields.
    switch ( $action ) { 
    566566                        wp_nonce_field( 'confirm_admin_email', 'confirm_admin_email_nonce' );
    567567
    568568                        ?>
    569                         <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     569                        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( maybe_add_wp_lang_query_arg( $redirect_to ) ); ?>" />
    570570
    571571                        <h1 class="admin-email__heading">
    572572                                <?php _e( 'Administration email verification' ); ?>
    switch ( $action ) { 
    630630                                                );
    631631
    632632                                                ?>
    633                                                 <a href="<?php echo esc_url( $remind_me_link ); ?>"><?php _e( 'Remind me later' ); ?></a>
     633                                                <a href="<?php echo esc_url( maybe_add_wp_lang_query_arg( $remind_me_link ) ); ?>"><?php _e( 'Remind me later' ); ?></a>
    634634                                        </div>
    635635                                <?php endif; ?>
    636636                        </div>
    switch ( $action ) { 
    707707                 */
    708708                $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );
    709709
    710                 wp_safe_redirect( $redirect_to );
     710                wp_safe_redirect( maybe_add_wp_lang_query_arg( $redirect_to ) );
    711711                exit;
    712712
    713713        case 'lostpassword':
    switch ( $action ) { 
    717717
    718718                        if ( ! is_wp_error( $errors ) ) {
    719719                                $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm';
    720                                 wp_safe_redirect( $redirect_to );
     720                                wp_safe_redirect( maybe_add_wp_lang_query_arg( $redirect_to ) );
    721721                                exit;
    722722                        }
    723723                }
    switch ( $action ) { 
    759759                        $user_login = wp_unslash( $_POST['user_login'] );
    760760                }
    761761
    762                 $action_url          = network_site_url( 'wp-login.php?action=lostpassword', 'login_post' );
    763                 $login_url           = wp_login_url();
    764                 $wp_registration_url = wp_registration_url();
    765 
    766                 if ( ! empty( $_GET['wp_lang'] ) ) {
    767                         $wp_lang = sanitize_text_field( $_GET['wp_lang'] );
    768 
    769                         $action_url          = add_query_arg( 'wp_lang', $wp_lang, $action_url );
    770                         $login_url           = add_query_arg( 'wp_lang', $wp_lang, $login_url );
    771                         $wp_registration_url = add_query_arg( 'wp_lang', $wp_lang, $wp_registration_url );
    772                 }
     762                $action_url          = maybe_add_wp_lang_query_arg( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) );
     763                $login_url           = maybe_add_wp_lang_query_arg( wp_login_url() );
     764                $wp_registration_url = maybe_add_wp_lang_query_arg( wp_registration_url() );
    773765
    774766                ?>
    775767
    switch ( $action ) { 
    788780                        do_action( 'lostpassword_form' );
    789781
    790782                        ?>
    791                         <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     783                        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( maybe_add_wp_lang_query_arg( $redirect_to ) ); ?>" />
    792784                        <p class="submit">
    793785                                <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Get New Password' ); ?>" />
    794786                        </p>
    switch ( $action ) { 
    880872
    881873                login_header( __( 'Reset Password' ), '<p class="message reset-pass">' . __( 'Enter your new password below or generate one.' ) . '</p>', $errors );
    882874
     875                $action_url = maybe_add_wp_lang_query_arg( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) );
    883876                ?>
    884                 <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
     877                <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( $action_url ); ?>" method="post" autocomplete="off">
    885878                        <input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
    886879
    887880                        <div class="user-pass1-wrap">
    switch ( $action ) { 
    935928                        <?php
    936929
    937930                        if ( get_option( 'users_can_register' ) ) {
    938                                 $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     931                                $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( maybe_add_wp_lang_query_arg( wp_registration_url() ) ), __( 'Register' ) );
    939932
    940933                                echo esc_html( $login_link_separator );
    941934
    switch ( $action ) { 
    964957                }
    965958
    966959                if ( ! get_option( 'users_can_register' ) ) {
    967                         wp_redirect( site_url( 'wp-login.php?registration=disabled' ) );
     960                        wp_redirect( maybe_add_wp_lang_query_arg( site_url( 'wp-login.php?registration=disabled' ) ) );
    968961                        exit;
    969962                }
    970963
    switch ( $action ) { 
    984977
    985978                        if ( ! is_wp_error( $errors ) ) {
    986979                                $redirect_to = ! empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
    987                                 wp_safe_redirect( $redirect_to );
     980                                wp_safe_redirect( maybe_add_wp_lang_query_arg( $redirect_to ) );
    988981                                exit;
    989982                        }
    990983                }
    switch ( $action ) { 
    1003996                login_header( __( 'Registration Form' ), '<p class="message register">' . __( 'Register For This Site' ) . '</p>', $errors );
    1004997
    1005998                ?>
    1006                 <form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
     999                <form name="registerform" id="registerform" action="<?php echo esc_url( maybe_add_wp_lang_query_arg( site_url( 'wp-login.php?action=register', 'login_post' ) ) ); ?>" method="post" novalidate="novalidate">
    10071000                        <p>
    10081001                                <label for="user_login"><?php _e( 'Username' ); ?></label>
    10091002                                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( wp_unslash( $user_login ) ); ?>" size="20" autocapitalize="off" />
    switch ( $action ) { 
    10261019                                <?php _e( 'Registration confirmation will be emailed to you.' ); ?>
    10271020                        </p>
    10281021                        <br class="clear" />
    1029                         <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     1022                        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( maybe_add_wp_lang_query_arg( $redirect_to ) ); ?>" />
    10301023                        <p class="submit">
    10311024                                <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Register' ); ?>" />
    10321025                        </p>
    10331026                </form>
    10341027
     1028                <?php
     1029                $login_url        = maybe_add_wp_lang_query_arg( wp_login_url() );
     1030                $lostpassword_url = maybe_add_wp_lang_query_arg( wp_lostpassword_url() );
     1031                ?>
     1032
    10351033                <p id="nav">
    1036                         <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
     1034                        <a href="<?php echo esc_url( $login_url ); ?>"><?php _e( 'Log in' ); ?></a>
    10371035                                <?php echo esc_html( $login_link_separator ); ?>
    1038                         <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
     1036                        <a href="<?php echo esc_url( $lostpassword_url ); ?>"><?php _e( 'Lost your password?' ); ?></a>
    10391037                </p>
    10401038                <?php
    10411039
    switch ( $action ) { 
    10521050                                sprintf(
    10531051                                        /* translators: %s: Link to the login page. */
    10541052                                        __( 'Check your email for the confirmation link, then visit the <a href="%s">login page</a>.' ),
    1055                                         wp_login_url()
     1053                                        maybe_add_wp_lang_query_arg( wp_login_url() )
    10561054                                ),
    10571055                                'message'
    10581056                        );
    switch ( $action ) { 
    10621060                                sprintf(
    10631061                                        /* translators: %s: Link to the login page. */
    10641062                                        __( 'Registration complete. Please check your email, then visit the <a href="%s">login page</a>.' ),
    1065                                         wp_login_url()
     1063                                        maybe_add_wp_lang_query_arg( wp_login_url() )
    10661064                                ),
    10671065                                'message'
    10681066                        );
    switch ( $action ) { 
    12451243                                        $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
    12461244                                }
    12471245
    1248                                 wp_redirect( $redirect_to );
     1246                                wp_redirect( maybe_add_wp_lang_query_arg( $redirect_to ) );
    12491247                                exit;
    12501248                        }
    12511249
    1252                         wp_safe_redirect( $redirect_to );
     1250                        wp_safe_redirect( maybe_add_wp_lang_query_arg( $redirect_to ) );
    12531251                        exit;
    12541252                }
    12551253
    switch ( $action ) { 
    13251323                wp_enqueue_script( 'user-profile' );
    13261324                ?>
    13271325
    1328                 <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
     1326                <form name="loginform" id="loginform" action="<?php echo esc_url( maybe_add_wp_lang_query_arg( site_url( 'wp-login.php', 'login_post' ) ) ); ?>" method="post">
    13291327                        <p>
    13301328                                <label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
    13311329                                <input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" />
    switch ( $action ) { 
    13611359                                        <?php
    13621360                                } else {
    13631361                                        ?>
    1364                                         <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     1362                                        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( maybe_add_wp_lang_query_arg( $redirect_to ) ); ?>" />
    13651363                                        <?php
    13661364                                }
    13671365
    switch ( $action ) { 
    13831381                        <p id="nav">
    13841382                                <?php
    13851383
     1384                                $wp_registration_url = maybe_add_wp_lang_query_arg( wp_registration_url() );
     1385                                $lostpassword_url    = maybe_add_wp_lang_query_arg( wp_lostpassword_url() );
     1386
    13861387                                if ( get_option( 'users_can_register' ) ) {
    1387                                         $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     1388                                        $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( $wp_registration_url ), __( 'Register' ) );
    13881389
    13891390                                        /** This filter is documented in wp-includes/general-template.php */
    13901391                                        echo apply_filters( 'register', $registration_url );
    switch ( $action ) { 
    13931394                                }
    13941395
    13951396                                ?>
    1396                                 <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
     1397                                <a href="<?php echo esc_url( $lostpassword_url ); ?>"><?php _e( 'Lost your password?' ); ?></a>
    13971398                        </p>
    13981399                        <?php
    13991400                }
    switch ( $action ) { 
    14581459                login_footer();
    14591460                break;
    14601461} // End action switch.
     1462
     1463/**
     1464 * Add wp_lang query arg in the url if its exists on the GET param.
     1465 *
     1466 * @param string $url URL of the specific page.
     1467 *
     1468 * @since 5.8.0
     1469 *
     1470 * @return string;
     1471 */
     1472function maybe_add_wp_lang_query_arg( $url ) {
     1473        if ( ! empty( $_GET['wp_lang'] ) && ! empty( $url ) ) {
     1474                $wp_lang = sanitize_text_field( $_GET['wp_lang'] );
     1475
     1476                $url = add_query_arg( 'wp_lang', $wp_lang, $url );
     1477        }
     1478
     1479        return $url;
     1480}