Make WordPress Core

Ticket #25393: wp-login-4.diff

File wp-login-4.diff, 15.9 KB (added by ShinichiN, 12 years ago)

I modified wp-login.php following DrewAPicture's review.

  • wp-login.php

     
    4949
    5050        // Shake it!
    5151        $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
     52        /**
     53         * Filter the error codes array for shaking the login form.
     54         *
     55         * @since 3.0.0
     56         *
     57         * @param array $shake_error_codes Error codes that shake the login form.
     58         */
    5259        $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
    5360
    5461        if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
     
    7784                <?php
    7885        }
    7986
     87        /**
     88         * Fires at the time of enqueueing scripts and styles on the login page.
     89         *
     90         * The proper hook to use when enqueueing scripts and styles that will appear on the login page.
     91         *
     92         * @since 3.1.0
     93         */
    8094        do_action( 'login_enqueue_scripts' );
     95        /**
     96         * Fires before </head> on the login page.
     97         *
     98         * @since 2.1.0
     99         */
    81100        do_action( 'login_head' );
    82101
    83102        if ( is_multisite() ) {
     
    88107                $login_header_title = __( 'Powered by WordPress' );
    89108        }
    90109
    91         $login_header_url   = apply_filters( 'login_headerurl',   $login_header_url   );
     110        /**
     111         * Filter link URL of the header logo above login form.
     112         *
     113         * @since 2.1.0
     114         *
     115         * @param string $login_header_url Default URL.
     116         */
     117        $login_header_url   = apply_filters( 'login_headerurl', $login_header_url );
     118        /**
     119         * Filter the title of the header logo above login form.
     120         *
     121         * @since 2.1.0
     122         *
     123         * @param string $login_header_title Default title.
     124         */
    92125        $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
    93126
    94127        $classes = array( 'login-action-' . $action, 'wp-core-ui' );
     
    106139                        $classes[] = 'interim-login-success';
    107140        }
    108141
     142        /**
     143         * Filter the classes of login page <body> tag.
     144         *
     145         * @since 3.5.0
     146         *
     147         * @param array  $classes Classes to be added to the <body>.
     148         * @param string $action  The action user took before coming to the login page.
     149         */
    109150        $classes = apply_filters( 'login_body_class', $classes, $action );
    110151
    111152        ?>
     
    117158
    118159        unset( $login_header_url, $login_header_title );
    119160
    120         $message = apply_filters('login_message', $message);
     161        /**
     162         * Filter the message to display above the login form.
     163         *
     164         * @since 2.1.0
     165         *
     166         * @param string $message Default message text.
     167         */
     168        $message = apply_filters( 'login_message', $message );
    121169        if ( !empty( $message ) )
    122170                echo $message . "\n";
    123171
     
    140188                        }
    141189                }
    142190                if ( !empty($errors) )
    143                         echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
     191                        /**
     192                         * Filter the error message above the login form.
     193                         *
     194                         * @since 2.1.0
     195                         *
     196                         * @param string $errors Error message.
     197                         */
     198                        echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
    144199                if ( !empty($messages) )
    145                         echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
     200                        /**
     201                         * Filter the login message above the login form.
     202                         *
     203                         * @since 2.5.0
     204                         *
     205                         * @param string $messages Login message.
     206                         */
     207                        echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
    146208        }
    147209} // End of login_header()
    148210
     
    168230        </script>
    169231        <?php endif; ?>
    170232
    171         <?php do_action('login_footer'); ?>
     233        <?php
     234        /**
     235         * Fires at the end of the login page HTML.
     236         *
     237         * @since 3.1.0
     238         */
     239        do_action( 'login_footer' ); ?>
    172240        <div class="clear"></div>
    173241        </body>
    174242        </html>
     
    194262 *
    195263 * @uses $wpdb WordPress Database object
    196264 *
    197  * @return bool|WP_Error True: when finish. WP_Error on error
     265 * @return bool|WP_Error True: when finished. WP_Error on error.
    198266 */
    199267function retrieve_password() {
    200268        global $wpdb, $current_site;
     
    212280                $user_data = get_user_by('login', $login);
    213281        }
    214282
    215         do_action('lostpassword_post');
     283        /**
     284         * Fires before returning WP Error in password retrieval process.
     285         *
     286         * @since 2.1.0
     287         */
     288        do_action( 'lostpassword_post' );
    216289
    217290        if ( $errors->get_error_code() )
    218291                return $errors;
     
    226299        $user_login = $user_data->user_login;
    227300        $user_email = $user_data->user_email;
    228301
    229         do_action('retreive_password', $user_login);  // Misspelled and deprecated
    230         do_action('retrieve_password', $user_login);
     302        /**
     303         * Fires within the password retrieval process.
     304         *
     305         * Misspelled and deprecated
     306         *
     307         * @since 1.5.2
     308         *
     309         * @param string $user_login User name to login.
     310         */
     311        do_action( 'retreive_password', $user_login );
     312        /**
     313         * Fires within the password retrieval process.
     314         *
     315         * @since 1.5.2
     316         *
     317         * @param string $user_login User name to login.
     318         */
     319        do_action( 'retrieve_password', $user_login );
    231320
    232         $allow = apply_filters('allow_password_reset', true, $user_data->ID);
     321        /**
     322         * Filter password reset restriction condition boolean to disallow password reset.
     323         *
     324         * @since 2.7.0
     325         *
     326         * @param boolean            Allow/Disallow user to reset password, true as default.
     327         * @param int $user_data->ID The ID of the user who is retrieving new password.
     328         */
     329        $allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
    233330
    234331        if ( ! $allow )
    235332                return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
     
    240337        if ( empty($key) ) {
    241338                // Generate something random for a key...
    242339                $key = wp_generate_password(20, false);
    243                 do_action('retrieve_password_key', $user_login, $key);
     340                /**
     341                 * Fires before inserting the activation key into database.
     342                 *
     343                 * @since 2.5.0
     344                 *
     345                 * @param string $user_login User name to login.
     346                 * @param string $key        Activation key.
     347                 */
     348                do_action( 'retrieve_password_key', $user_login, $key );
    244349                // Now insert the new md5 key into the db
    245350                $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
    246351        }
     
    260365
    261366        $title = sprintf( __('[%s] Password Reset'), $blogname );
    262367
    263         $title = apply_filters('retrieve_password_title', $title);
    264         $message = apply_filters('retrieve_password_message', $message, $key);
     368        /**
     369         * Filter title of the password reset email.
     370         *
     371         * @since 2.8.0
     372         *
     373         * @param string $title Default email title.
     374         */
     375        $title = apply_filters( 'retrieve_password_title', $title );
     376        /**
     377         * Filter body message of the password reset mail.
     378         *
     379         * @since 2.8.0
     380         *
     381         * @param string $message Default mail message.
     382         * @param string $key     The activation key.
     383         */
     384        $message = apply_filters( 'retrieve_password_message', $message, $key );
    265385
    266386        if ( $message && !wp_mail($user_email, $title, $message) )
    267387                wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
     
    301421if ( SITECOOKIEPATH != COOKIEPATH )
    302422        setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
    303423
    304 // allow plugins to override the default actions, and to add extra actions if they want
     424/**
     425 * Fires before running the actions such as showing forms and logout etc.
     426 *
     427 * Allow plugins to override the default actions, and add extra actions if they want.
     428 *
     429 * @since 3.2.0
     430 *
     431 */
    305432do_action( 'login_init' );
     433/**
     434 * Fires before running the actions such as showing forms and logout etc. depending on the $action.
     435 *
     436 * @since 2.8.0
     437 *
     438 */
    306439do_action( 'login_form_' . $action );
    307440
    308441$http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
     
    321454         * To turn this into a session cookie, return 0.
    322455         *
    323456         * @since 3.7.0
     457         *
    324458         * @param int $expires The expiry time, as passed to setcookie().
    325459         */
    326460        $expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
     
    354488        }
    355489
    356490        if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
    357         $redirect_to = apply_filters( 'lostpassword_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
     491       
     492        $lostpassword_redirect = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
     493        /**
     494         * Filter the redirect URL after submitting the lostpassword/retrievepassword form.
     495         *
     496         * @since 3.0.0
     497         *
     498         * @param string $lostpassword_redirect The redirect destination URL.
     499         */
     500        $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
    358501
    359         do_action('lost_password');
     502        /**
     503         * Fires before the lost password and retrieve password form.
     504         *
     505         * @since 1.5.2
     506         */
     507        do_action( 'lost_password' );
    360508        login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username or email address. You will receive a link to create a new password via email.') . '</p>', $errors);
    361509
    362510        $user_login = isset($_POST['user_login']) ? wp_unslash($_POST['user_login']) : '';
     
    368516                <label for="user_login" ><?php _e('Username or E-mail:') ?><br />
    369517                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
    370518        </p>
    371 <?php do_action('lostpassword_form'); ?>
     519<?php
     520/**
     521 * Fires in the lostpassword form before the hidden fields.
     522 *
     523 * @since 2.1.0
     524 */
     525do_action( 'lostpassword_form' ); ?>
    372526        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
    373527        <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Get New Password'); ?>" /></p>
    374528</form>
     
    375529
    376530<p id="nav">
    377531<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
    378 <?php if ( get_option( 'users_can_register' ) ) : ?>
    379  | <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?>
    380 <?php endif; ?>
     532<?php if ( get_option( 'users_can_register' ) ) :
     533        $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     534        /**
     535         * Filter the register link text below the login form.
     536         *
     537         * @since 1.5.2
     538         *
     539         * @param string $registration_url Register link text.
     540         */
     541        echo ' | ' . apply_filters( 'register', $registration_url );
     542endif; ?>
    381543</p>
    382544
    383545<?php
     
    398560        if ( isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2'] )
    399561                $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
    400562
     563        /**
     564         * Fires before the validation in the password reset procedure.
     565         *
     566         * @since 3.5.0
     567         *
     568         * @param object $errors WP Error object.
     569         * @param string $user   User data.
     570         */
    401571        do_action( 'validate_password_reset', $errors, $user );
    402572
    403573        if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
     
    434604
    435605<p id="nav">
    436606<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
    437 <?php if ( get_option( 'users_can_register' ) ) : ?>
    438  | <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?>
    439 <?php endif; ?>
     607<?php if ( get_option( 'users_can_register' ) ) :
     608        $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     609        //duplicate_hook
     610        echo ' | ' . apply_filters( 'register', $registration_url );
     611endif; ?>
    440612</p>
    441613
    442614<?php
     
    445617
    446618case 'register' :
    447619        if ( is_multisite() ) {
    448                 // Multisite uses wp-signup.php
     620                /**
     621                 * Filter the redirect destination URL for Multisite.
     622                 *
     623                 * @since 3.0.0
     624                 *
     625                 * @param string Signup URL for Multisite.
     626                 */
    449627                wp_redirect( apply_filters( 'wp_signup_location', network_site_url('wp-signup.php') ) );
    450628                exit;
    451629        }
     
    468646                }
    469647        }
    470648
     649        /**
     650         * Filter the redirect destination URL after user registration.
     651         *
     652         * @since 3.0.0
     653         *
     654         * @param string The redirect destination URL.
     655         */
    471656        $redirect_to = apply_filters( 'registration_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
    472657        login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
    473658?>
     
    481666                <label for="user_email"><?php _e('E-mail') ?><br />
    482667                <input type="text" name="user_email" id="user_email" class="input" value="<?php echo esc_attr(wp_unslash($user_email)); ?>" size="25" /></label>
    483668        </p>
    484 <?php do_action('register_form'); ?>
     669<?php
     670/**
     671 * Fires in the registration form to add extra inputs.
     672 *
     673 * @since 2.1.0
     674 */
     675do_action( 'register_form' ); ?>
    485676        <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
    486677        <br class="clear" />
    487678        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     
    538729        else
    539730                $user = wp_signon('', $secure_cookie);
    540731
    541         $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);
     732        $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
     733        /**
     734         * Filtering the redirect URL after login.
     735         *
     736         * @since 3.0.0
     737         *
     738         * @param string $redirect_to                   The redirect destination URL.
     739         * @param string $requested_redirect_to The redirect destination URL passed as a parameter.
     740         * @param object $user                                  User data object.
     741         */
     742        $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
    542743
    543744        if ( !is_wp_error($user) && !$reauth ) {
    544745                if ( $interim_login ) {
     
    546747                        $interim_login = 'success';
    547748                        login_header( '', $message ); ?>
    548749                        </div>
    549                         <?php do_action( 'login_footer' ); ?>
     750                        <?php
     751                        /**
     752                         * Fires at the end of the login page HTML.
     753                         *
     754                         * @since 3.1.0
     755                         */
     756                        do_action( 'login_footer' ); ?>
    550757                        <?php if ( $customize_login ) : ?>
    551758                                <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
    552759                        <?php endif; ?>
     
    591798                        $errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
    592799        }
    593800
     801        /**
     802         * Filter the WP Error object of the login page.
     803         *
     804         * @since 3.6.0
     805         *
     806         * @param object $errors      WP Error object.
     807         * @param string $redirect_to Redirect destination URL.
     808         */
    594809        $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
    595810
    596811        // Clear any stale cookies.
     
    613828                <label for="user_pass"><?php _e('Password') ?><br />
    614829                <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
    615830        </p>
    616 <?php do_action('login_form'); ?>
     831<?php
     832/**
     833 * Fires in the login form to add extra input.
     834 *
     835 * @since 2.1.0
     836 */
     837do_action( 'login_form' ); ?>
    617838        <p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <?php esc_attr_e('Remember Me'); ?></label></p>
    618839        <p class="submit">
    619840                <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
     
    631852
    632853<?php if ( ! $interim_login ) { ?>
    633854<p id="nav">
    634 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) : ?>
    635         <?php if ( get_option( 'users_can_register' ) ) : ?>
    636                 <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?> |
    637         <?php endif; ?>
     855<?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
     856        if ( get_option( 'users_can_register' ) ) :
     857                $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     858                //duplicate_hook
     859                echo apply_filters( 'register', $registration_url ) . ' | ';
     860        endif;
     861?>
    638862        <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
    639863<?php endif; ?>
    640864</p>