Make WordPress Core

Ticket #25393: 25393.diff

File 25393.diff, 16.5 KB (added by DrewAPicture, 13 years ago)

Iterating on .5

  • src/wp-login.php

     
    2525/**
    2626 * Outputs the header for the login page.
    2727 *
    28  * @uses do_action() Calls the 'login_head' for outputting HTML in the Log In
    29  *              header.
    30  * @uses apply_filters() Calls 'login_headerurl' for the top login link.
    31  * @uses apply_filters() Calls 'login_headertitle' for the top login title.
    32  * @uses apply_filters() Calls 'login_message' on the message to display in the
    33  *              header.
    34  * @uses $error The error global, which is checked for displaying errors.
    35  *
    3628 * @param string $title Optional. WordPress Log In Page title to display in
    3729 *              <title/> element.
    3830 * @param string $message Optional. Message to display in header.
     
    5244
    5345        // Shake it!
    5446        $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
     47        /**
     48         * Filter the error codes array for shaking the login form.
     49         *
     50         * @since 3.0.0
     51         *
     52         * @param array $shake_error_codes Error codes that shake the login form.
     53         */
    5554        $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
    5655
    5756        if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
     
    7675                <?php
    7776        }
    7877
     78        /**
     79         * Enqueue scripts and styles for the login page.
     80         *
     81         * @since 3.1.0
     82         */
    7983        do_action( 'login_enqueue_scripts' );
     84        /**
     85         * Fires in the login page header after scripts are enqueued.
     86         *
     87         * @since 2.1.0
     88         */
    8089        do_action( 'login_head' );
    8190
    8291        if ( is_multisite() ) {
     
    8796                $login_header_title = __( 'Powered by WordPress' );
    8897        }
    8998
    90         $login_header_url   = apply_filters( 'login_headerurl',   $login_header_url   );
     99        /**
     100         * Filter link URL of the header logo above login form.
     101         *
     102         * @since 2.1.0
     103         *
     104         * @param string $login_header_url Default URL.
     105         */
     106        $login_header_url = apply_filters( 'login_headerurl', $login_header_url );
     107        /**
     108         * Filter the title attribute of the header logo above login form.
     109         *
     110         * @since 2.1.0
     111         *
     112         * @param string $login_header_title Default title.
     113         */
    91114        $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
    92115
    93116        $classes = array( 'login-action-' . $action, 'wp-core-ui' );
     
    105128                        $classes[] = 'interim-login-success';
    106129        }
    107130
     131        /**
     132         * Filter the login page body classes.
     133         *
     134         * @since 3.5.0
     135         *
     136         * @param array  $classes An array of body classes.
     137         * @param string $action  The action that brought the visitor to the login page.
     138         */
    108139        $classes = apply_filters( 'login_body_class', $classes, $action );
    109140
    110141        ?>
     
    116147
    117148        unset( $login_header_url, $login_header_title );
    118149
    119         $message = apply_filters('login_message', $message);
     150        /**
     151         * Filter the message to display above the login form.
     152         *
     153         * @since 2.1.0
     154         *
     155         * @param string $message Default message text.
     156         */
     157        $message = apply_filters( 'login_message', $message );
    120158        if ( !empty( $message ) )
    121159                echo $message . "\n";
    122160
     
    138176                                        $errors .= '    ' . $error . "<br />\n";
    139177                        }
    140178                }
    141                 if ( !empty($errors) )
    142                         echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
    143                 if ( !empty($messages) )
    144                         echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
     179                if ( ! empty( $errors ) ) {
     180                        /**
     181                         * Filter the error messages displayed above the login.
     182                         *
     183                         * @since 2.1.0
     184                         *
     185                         * @param string $errors Error message.
     186                         */
     187                        echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
     188                }
     189                if ( ! empty( $messages ) ) {
     190                        /**
     191                         * Filter instructional messages displayed above the login form.
     192                         *
     193                         * @since 2.5.0
     194                         *
     195                         * @param string $messages Login message.
     196                         */
     197                        echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
     198                }
    145199        }
    146200} // End of login_header()
    147201
     
    167221        </script>
    168222        <?php endif; ?>
    169223
    170         <?php do_action('login_footer'); ?>
     224        <?php
     225        /**
     226         * Fires in the login page footer.
     227         *
     228         * @since 3.1.0
     229         */
     230        do_action( 'login_footer' ); ?>
    171231        <div class="clear"></div>
    172232        </body>
    173233        </html>
     
    217277                $user_data = get_user_by('login', $login);
    218278        }
    219279
    220         do_action('lostpassword_post');
     280        /**
     281         * Fires before errors are returned from a password reset request.
     282         *
     283         * @since 2.1.0
     284         */
     285        do_action( 'lostpassword_post' );
    221286
    222287        if ( $errors->get_error_code() )
    223288                return $errors;
     
    231296        $user_login = $user_data->user_login;
    232297        $user_email = $user_data->user_email;
    233298
    234         do_action('retreive_password', $user_login);  // Misspelled and deprecated
    235         do_action('retrieve_password', $user_login);
     299        /**
     300         * Fires before a new password is retrieved.
     301         *
     302         * Misspelled and deprecated
     303         *
     304         * @since 1.5.2
     305         *
     306         * @param string $user_login The user login name.
     307         */
     308        do_action( 'retreive_password', $user_login );
     309        /**
     310         * Fires before a new password is retrieved.
     311         *
     312         * @since 1.5.2
     313         *
     314         * @param string $user_login The user login name
     315         */
     316        do_action( 'retrieve_password', $user_login );
    236317
    237         $allow = apply_filters('allow_password_reset', true, $user_data->ID);
     318        /**
     319         * Filter whether to allow a password to be reset.
     320         *
     321         * @since 2.7.0
     322         *
     323         * @param bool true           Whether to allow the password to be reset. Default true.
     324         * @param int  $user_data->ID The ID of the user attempting to reset a password.
     325         */
     326        $allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
    238327
    239328        if ( ! $allow )
    240329                return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
     
    245334        if ( empty($key) ) {
    246335                // Generate something random for a key...
    247336                $key = wp_generate_password(20, false);
    248                 do_action('retrieve_password_key', $user_login, $key);
     337                /**
     338                 * Fires before inserting the activation key into the database.
     339                 *
     340                 * @since 2.5.0
     341                 *
     342                 * @param string $user_login User username to log in.
     343                 * @param string $key        Activation key.
     344                 */
     345                do_action( 'retrieve_password_key', $user_login, $key );
    249346                // Now insert the new md5 key into the db
    250347                $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
    251348        }
     
    265362
    266363        $title = sprintf( __('[%s] Password Reset'), $blogname );
    267364
    268         $title = apply_filters('retrieve_password_title', $title);
    269         $message = apply_filters('retrieve_password_message', $message, $key);
     365        /**
     366         * Filter the subject of the password reset email.
     367         *
     368         * @since 2.8.0
     369         *
     370         * @param string $title Default email title.
     371         */
     372        $title = apply_filters( 'retrieve_password_title', $title );
     373        /**
     374         * Filter the message body of the password reset mail.
     375         *
     376         * @since 2.8.0
     377         *
     378         * @param string $message Default mail message.
     379         * @param string $key     The activation key.
     380         */
     381        $message = apply_filters( 'retrieve_password_message', $message, $key );
    270382
    271383        if ( $message && !wp_mail($user_email, $title, $message) )
    272384                wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
     
    306418if ( SITECOOKIEPATH != COOKIEPATH )
    307419        setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
    308420
    309 // allow plugins to override the default actions, and to add extra actions if they want
     421/**
     422 * Fires when the login form is initialized.
     423 *
     424 * @since 3.2.0
     425 *
     426 */
    310427do_action( 'login_init' );
     428/**
     429 * Fires before a specified login form action.
     430 *
     431 * The dynamic portion of the hook name, $action, refers to the action that brought the visitor
     432 * to the login form. Actions include 'postpass', 'logout', 'lostpassword', etc.
     433 *
     434 * @since 2.8.0
     435 *
     436 */
    311437do_action( 'login_form_' . $action );
    312438
    313439$http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
     
    322448        /**
    323449         * Filter the life of the post password cookie.
    324450         *
    325          * By default, the cookie expires 10 days from now.
     451         * By default, the cookie expires 10 days from creation.
    326452         * To turn this into a session cookie, return 0.
    327453         *
    328454         * @since 3.7.0
     455         *
    329456         * @param int $expires The expiry time, as passed to setcookie().
    330457         */
    331458        $expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
     
    359486        }
    360487
    361488        if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
    362         $redirect_to = apply_filters( 'lostpassword_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
     489       
     490        $lostpassword_redirect = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
     491        /**
     492         * Filter the URL redirected to after submitting the lostpassword/retrievepassword form.
     493         *
     494         * @since 3.0.0
     495         *
     496         * @param string $lostpassword_redirect The redirect destination URL.
     497         */
     498        $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
    363499
    364         do_action('lost_password');
     500        /**
     501         * Fires before the lost password form.
     502         *
     503         * @since 1.5.2
     504         */
     505        do_action( 'lost_password' );
    365506        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);
    366507
    367508        $user_login = isset($_POST['user_login']) ? wp_unslash($_POST['user_login']) : '';
     
    373514                <label for="user_login" ><?php _e('Username or E-mail:') ?><br />
    374515                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
    375516        </p>
    376 <?php do_action('lostpassword_form'); ?>
     517<?php
     518/**
     519 * Fires inside the lostpassword <form> tags, before the hidden fields.
     520 *
     521 * @since 2.1.0
     522 */
     523do_action( 'lostpassword_form' ); ?>
    377524        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
    378525        <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>
    379526</form>
    380527
    381528<p id="nav">
    382529<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
    383 <?php if ( get_option( 'users_can_register' ) ) : ?>
    384  | <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?>
    385 <?php endif; ?>
     530<?php if ( get_option( 'users_can_register' ) ) :
     531        $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     532        /**
     533         * Filter the registration URL below the login form.
     534         *
     535         * @since 1.5.2
     536         *
     537         * @param string $registration_url Register link text.
     538         */
     539        echo ' | ' . apply_filters( 'register', $registration_url );
     540endif; ?>
    386541</p>
    387542
    388543<?php
     
    403558        if ( isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2'] )
    404559                $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
    405560
     561        /**
     562         * Fires before the validation in the password reset procedure.
     563         *
     564         * @since 3.5.0
     565         *
     566         * @param object $errors WP Error object.
     567         * @param string $user   User data.
     568         */
    406569        do_action( 'validate_password_reset', $errors, $user );
    407570
    408571        if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
     
    439602
    440603<p id="nav">
    441604<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
    442 <?php if ( get_option( 'users_can_register' ) ) : ?>
    443  | <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?>
    444 <?php endif; ?>
     605<?php if ( get_option( 'users_can_register' ) ) :
     606        $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     607        //duplicate_hook
     608        echo ' | ' . apply_filters( 'register', $registration_url );
     609endif; ?>
    445610</p>
    446611
    447612<?php
     
    450615
    451616case 'register' :
    452617        if ( is_multisite() ) {
    453                 // Multisite uses wp-signup.php
    454                 wp_redirect( apply_filters( 'wp_signup_location', network_site_url('wp-signup.php') ) );
     618                $sign_up_url = network_site_url( 'wp-signup.php' );
     619                /**
     620                 * Filter the Multisite sign up redirect URL.
     621                 *
     622                 * @since 3.0.0
     623                 *
     624                 * @param string $sign_up_url The sign up URL for Multisite.
     625                 */
     626                wp_redirect( apply_filters( 'wp_signup_location', $sign_up_url ) );
    455627                exit;
    456628        }
    457629
     
    473645                }
    474646        }
    475647
     648        /**
     649         * Filter the registration redirect URL.
     650         *
     651         * @since 3.0.0
     652         *
     653         * @param string The redirect destination URL.
     654         */
    476655        $redirect_to = apply_filters( 'registration_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
    477656        login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
    478657?>
     
    486665                <label for="user_email"><?php _e('E-mail') ?><br />
    487666                <input type="text" name="user_email" id="user_email" class="input" value="<?php echo esc_attr(wp_unslash($user_email)); ?>" size="25" /></label>
    488667        </p>
    489 <?php do_action('register_form'); ?>
     668<?php
     669/**
     670 * Fires following the 'E-mail' field in the user registration form.
     671 *
     672 * @since 2.1.0
     673 */
     674do_action( 'register_form' ); ?>
    490675        <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
    491676        <br class="clear" />
    492677        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     
    543728        else
    544729                $user = wp_signon('', $secure_cookie);
    545730
    546         $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);
     731        $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
     732        /**
     733         * Filter the login redirect URL.
     734         *
     735         * @since 3.0.0
     736         *
     737         * @param string $redirect_to                   The redirect destination URL.
     738         * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
     739         * @param object $user                                  User data object.
     740         */
     741        $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
    547742
    548743        if ( !is_wp_error($user) && !$reauth ) {
    549744                if ( $interim_login ) {
     
    551746                        $interim_login = 'success';
    552747                        login_header( '', $message ); ?>
    553748                        </div>
    554                         <?php do_action( 'login_footer' ); ?>
     749                        <?php
     750                        //duplicate_hook
     751                        do_action( 'login_footer' ); ?>
    555752                        <?php if ( $customize_login ) : ?>
    556753                                <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
    557754                        <?php endif; ?>
     
    596793                        $errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
    597794        }
    598795
     796        /**
     797         * Filter the login page errors.
     798         *
     799         * @since 3.6.0
     800         *
     801         * @param object $errors      WP Error object.
     802         * @param string $redirect_to Redirect destination URL.
     803         */
    599804        $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
    600805
    601806        // Clear any stale cookies.
     
    618823                <label for="user_pass"><?php _e('Password') ?><br />
    619824                <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
    620825        </p>
    621 <?php do_action('login_form'); ?>
     826<?php
     827/**
     828 * Fires following the 'Password' field in the login form.
     829 *
     830 * @since 2.1.0
     831 */
     832do_action( 'login_form' ); ?>
    622833        <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>
    623834        <p class="submit">
    624835                <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
     
    636847
    637848<?php if ( ! $interim_login ) { ?>
    638849<p id="nav">
    639 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) : ?>
    640         <?php if ( get_option( 'users_can_register' ) ) : ?>
    641                 <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?> |
    642         <?php endif; ?>
     850<?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
     851        if ( get_option( 'users_can_register' ) ) :
     852                $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     853                //duplicate_hook
     854                echo apply_filters( 'register', $registration_url ) . ' | ';
     855        endif;
     856?>
    643857        <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
    644858<?php endif; ?>
    645859</p>