Make WordPress Core

Ticket #25393: wp-login-5.diff

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

New patch including the Changeset r25619

  • wp-login.php

     
    5252
    5353        // Shake it!
    5454        $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
     55        /**
     56         * Filter the error codes array for shaking the login form.
     57         *
     58         * @since 3.0.0
     59         *
     60         * @param array $shake_error_codes Error codes that shake the login form.
     61         */
    5562        $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
    5663
    5764        if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
     
    7683                <?php
    7784        }
    7885
     86        /**
     87         * Fires at the time of enqueueing scripts and styles on the login page.
     88         *
     89         * The proper hook to use when enqueueing scripts and styles that will appear on the login page.
     90         *
     91         * @since 3.1.0
     92         */
    7993        do_action( 'login_enqueue_scripts' );
     94        /**
     95         * Fires before </head> on the login page.
     96         *
     97         * @since 2.1.0
     98         */
    8099        do_action( 'login_head' );
    81100
    82101        if ( is_multisite() ) {
     
    87106                $login_header_title = __( 'Powered by WordPress' );
    88107        }
    89108
    90         $login_header_url   = apply_filters( 'login_headerurl',   $login_header_url   );
     109        /**
     110         * Filter link URL of the header logo above login form.
     111         *
     112         * @since 2.1.0
     113         *
     114         * @param string $login_header_url Default URL.
     115         */
     116        $login_header_url   = apply_filters( 'login_headerurl', $login_header_url );
     117        /**
     118         * Filter the title of the header logo above login form.
     119         *
     120         * @since 2.1.0
     121         *
     122         * @param string $login_header_title Default title.
     123         */
    91124        $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
    92125
    93126        $classes = array( 'login-action-' . $action, 'wp-core-ui' );
     
    105138                        $classes[] = 'interim-login-success';
    106139        }
    107140
     141        /**
     142         * Filter the classes of login page <body> tag.
     143         *
     144         * @since 3.5.0
     145         *
     146         * @param array  $classes Classes to be added to the <body>.
     147         * @param string $action  The action user took before coming to the login page.
     148         */
    108149        $classes = apply_filters( 'login_body_class', $classes, $action );
    109150
    110151        ?>
     
    116157
    117158        unset( $login_header_url, $login_header_title );
    118159
    119         $message = apply_filters('login_message', $message);
     160        /**
     161         * Filter the message to display above the login form.
     162         *
     163         * @since 2.1.0
     164         *
     165         * @param string $message Default message text.
     166         */
     167        $message = apply_filters( 'login_message', $message );
    120168        if ( !empty( $message ) )
    121169                echo $message . "\n";
    122170
     
    139187                        }
    140188                }
    141189                if ( !empty($errors) )
    142                         echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
     190                        /**
     191                         * Filter the error message above the login form.
     192                         *
     193                         * @since 2.1.0
     194                         *
     195                         * @param string $errors Error message.
     196                         */
     197                        echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
    143198                if ( !empty($messages) )
    144                         echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
     199                        /**
     200                         * Filter the login message above the login form.
     201                         *
     202                         * @since 2.5.0
     203                         *
     204                         * @param string $messages Login message.
     205                         */
     206                        echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
    145207        }
    146208} // End of login_header()
    147209
     
    167229        </script>
    168230        <?php endif; ?>
    169231
    170         <?php do_action('login_footer'); ?>
     232        <?php
     233        /**
     234         * Fires at the end of the login page HTML.
     235         *
     236         * @since 3.1.0
     237         */
     238        do_action( 'login_footer' ); ?>
    171239        <div class="clear"></div>
    172240        </body>
    173241        </html>
     
    199267 *
    200268 * @uses $wpdb WordPress Database object
    201269 *
    202  * @return bool|WP_Error True: when finish. WP_Error on error
     270 * @return bool|WP_Error True: when finished. WP_Error on error.
    203271 */
    204272function retrieve_password() {
    205273        global $wpdb, $current_site;
     
    217285                $user_data = get_user_by('login', $login);
    218286        }
    219287
    220         do_action('lostpassword_post');
     288        /**
     289         * Fires before returning WP Error in password retrieval process.
     290         *
     291         * @since 2.1.0
     292         */
     293        do_action( 'lostpassword_post' );
    221294
    222295        if ( $errors->get_error_code() )
    223296                return $errors;
     
    231304        $user_login = $user_data->user_login;
    232305        $user_email = $user_data->user_email;
    233306
    234         do_action('retreive_password', $user_login);  // Misspelled and deprecated
    235         do_action('retrieve_password', $user_login);
     307        /**
     308         * Fires within the password retrieval process.
     309         *
     310         * Misspelled and deprecated
     311         *
     312         * @since 1.5.2
     313         *
     314         * @param string $user_login User name to login.
     315         */
     316        do_action( 'retreive_password', $user_login );
     317        /**
     318         * Fires within the password retrieval process.
     319         *
     320         * @since 1.5.2
     321         *
     322         * @param string $user_login User name to login.
     323         */
     324        do_action( 'retrieve_password', $user_login );
    236325
    237         $allow = apply_filters('allow_password_reset', true, $user_data->ID);
     326        /**
     327         * Filter password reset restriction condition boolean to disallow password reset.
     328         *
     329         * @since 2.7.0
     330         *
     331         * @param boolean            Allow/Disallow user to reset password, true as default.
     332         * @param int $user_data->ID The ID of the user who is retrieving new password.
     333         */
     334        $allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
    238335
    239336        if ( ! $allow )
    240337                return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
     
    245342        if ( empty($key) ) {
    246343                // Generate something random for a key...
    247344                $key = wp_generate_password(20, false);
    248                 do_action('retrieve_password_key', $user_login, $key);
     345                /**
     346                 * Fires before inserting the activation key into database.
     347                 *
     348                 * @since 2.5.0
     349                 *
     350                 * @param string $user_login User name to login.
     351                 * @param string $key        Activation key.
     352                 */
     353                do_action( 'retrieve_password_key', $user_login, $key );
    249354                // Now insert the new md5 key into the db
    250355                $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
    251356        }
     
    265370
    266371        $title = sprintf( __('[%s] Password Reset'), $blogname );
    267372
    268         $title = apply_filters('retrieve_password_title', $title);
    269         $message = apply_filters('retrieve_password_message', $message, $key);
     373        /**
     374         * Filter title of the password reset email.
     375         *
     376         * @since 2.8.0
     377         *
     378         * @param string $title Default email title.
     379         */
     380        $title = apply_filters( 'retrieve_password_title', $title );
     381        /**
     382         * Filter body message of the password reset mail.
     383         *
     384         * @since 2.8.0
     385         *
     386         * @param string $message Default mail message.
     387         * @param string $key     The activation key.
     388         */
     389        $message = apply_filters( 'retrieve_password_message', $message, $key );
    270390
    271391        if ( $message && !wp_mail($user_email, $title, $message) )
    272392                wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
     
    306426if ( SITECOOKIEPATH != COOKIEPATH )
    307427        setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
    308428
    309 // allow plugins to override the default actions, and to add extra actions if they want
     429/**
     430 * Fires before running the actions such as showing forms and logout etc.
     431 *
     432 * Allow plugins to override the default actions, and add extra actions if they want.
     433 *
     434 * @since 3.2.0
     435 *
     436 */
    310437do_action( 'login_init' );
     438/**
     439 * Fires before running the actions such as showing forms and logout etc. depending on the $action.
     440 *
     441 * @since 2.8.0
     442 *
     443 */
    311444do_action( 'login_form_' . $action );
    312445
    313446$http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
     
    326459         * To turn this into a session cookie, return 0.
    327460         *
    328461         * @since 3.7.0
     462         *
    329463         * @param int $expires The expiry time, as passed to setcookie().
    330464         */
    331465        $expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
     
    359493        }
    360494
    361495        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'] : '' );
     496       
     497        $lostpassword_redirect = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
     498        /**
     499         * Filter the redirect URL after submitting the lostpassword/retrievepassword form.
     500         *
     501         * @since 3.0.0
     502         *
     503         * @param string $lostpassword_redirect The redirect destination URL.
     504         */
     505        $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
    363506
    364         do_action('lost_password');
     507        /**
     508         * Fires before the lost password and retrieve password form.
     509         *
     510         * @since 1.5.2
     511         */
     512        do_action( 'lost_password' );
    365513        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);
    366514
    367515        $user_login = isset($_POST['user_login']) ? wp_unslash($_POST['user_login']) : '';
     
    373521                <label for="user_login" ><?php _e('Username or E-mail:') ?><br />
    374522                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
    375523        </p>
    376 <?php do_action('lostpassword_form'); ?>
     524<?php
     525/**
     526 * Fires in the lostpassword form before the hidden fields.
     527 *
     528 * @since 2.1.0
     529 */
     530do_action( 'lostpassword_form' ); ?>
    377531        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
    378532        <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>
    379533</form>
     
    380534
    381535<p id="nav">
    382536<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; ?>
     537<?php if ( get_option( 'users_can_register' ) ) :
     538        $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     539        /**
     540         * Filter the register link text below the login form.
     541         *
     542         * @since 1.5.2
     543         *
     544         * @param string $registration_url Register link text.
     545         */
     546        echo ' | ' . apply_filters( 'register', $registration_url );
     547endif; ?>
    386548</p>
    387549
    388550<?php
     
    403565        if ( isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2'] )
    404566                $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
    405567
     568        /**
     569         * Fires before the validation in the password reset procedure.
     570         *
     571         * @since 3.5.0
     572         *
     573         * @param object $errors WP Error object.
     574         * @param string $user   User data.
     575         */
    406576        do_action( 'validate_password_reset', $errors, $user );
    407577
    408578        if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
     
    439609
    440610<p id="nav">
    441611<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; ?>
     612<?php if ( get_option( 'users_can_register' ) ) :
     613        $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     614        //duplicate_hook
     615        echo ' | ' . apply_filters( 'register', $registration_url );
     616endif; ?>
    445617</p>
    446618
    447619<?php
     
    450622
    451623case 'register' :
    452624        if ( is_multisite() ) {
    453                 // Multisite uses wp-signup.php
     625                /**
     626                 * Filter the redirect destination URL for Multisite.
     627                 *
     628                 * @since 3.0.0
     629                 *
     630                 * @param string Signup URL for Multisite.
     631                 */
    454632                wp_redirect( apply_filters( 'wp_signup_location', network_site_url('wp-signup.php') ) );
    455633                exit;
    456634        }
     
    473651                }
    474652        }
    475653
     654        /**
     655         * Filter the redirect destination URL after user registration.
     656         *
     657         * @since 3.0.0
     658         *
     659         * @param string The redirect destination URL.
     660         */
    476661        $redirect_to = apply_filters( 'registration_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
    477662        login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
    478663?>
     
    486671                <label for="user_email"><?php _e('E-mail') ?><br />
    487672                <input type="text" name="user_email" id="user_email" class="input" value="<?php echo esc_attr(wp_unslash($user_email)); ?>" size="25" /></label>
    488673        </p>
    489 <?php do_action('register_form'); ?>
     674<?php
     675/**
     676 * Fires in the registration form to add extra inputs.
     677 *
     678 * @since 2.1.0
     679 */
     680do_action( 'register_form' ); ?>
    490681        <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
    491682        <br class="clear" />
    492683        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     
    543734        else
    544735                $user = wp_signon('', $secure_cookie);
    545736
    546         $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);
     737        $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
     738        /**
     739         * Filtering the redirect URL after login.
     740         *
     741         * @since 3.0.0
     742         *
     743         * @param string $redirect_to                   The redirect destination URL.
     744         * @param string $requested_redirect_to The redirect destination URL passed as a parameter.
     745         * @param object $user                                  User data object.
     746         */
     747        $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
    547748
    548749        if ( !is_wp_error($user) && !$reauth ) {
    549750                if ( $interim_login ) {
     
    551752                        $interim_login = 'success';
    552753                        login_header( '', $message ); ?>
    553754                        </div>
    554                         <?php do_action( 'login_footer' ); ?>
     755                        <?php
     756                        /**
     757                         * Fires at the end of the login page HTML.
     758                         *
     759                         * @since 3.1.0
     760                         */
     761                        do_action( 'login_footer' ); ?>
    555762                        <?php if ( $customize_login ) : ?>
    556763                                <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
    557764                        <?php endif; ?>
     
    596803                        $errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
    597804        }
    598805
     806        /**
     807         * Filter the WP Error object of the login page.
     808         *
     809         * @since 3.6.0
     810         *
     811         * @param object $errors      WP Error object.
     812         * @param string $redirect_to Redirect destination URL.
     813         */
    599814        $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
    600815
    601816        // Clear any stale cookies.
     
    618833                <label for="user_pass"><?php _e('Password') ?><br />
    619834                <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
    620835        </p>
    621 <?php do_action('login_form'); ?>
     836<?php
     837/**
     838 * Fires in the login form to add extra input.
     839 *
     840 * @since 2.1.0
     841 */
     842do_action( 'login_form' ); ?>
    622843        <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>
    623844        <p class="submit">
    624845                <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
     
    636857
    637858<?php if ( ! $interim_login ) { ?>
    638859<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; ?>
     860<?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
     861        if ( get_option( 'users_can_register' ) ) :
     862                $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
     863                //duplicate_hook
     864                echo apply_filters( 'register', $registration_url ) . ' | ';
     865        endif;
     866?>
    643867        <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
    644868<?php endif; ?>
    645869</p>