Make WordPress Core

Ticket #25393: wp-login.diff

File wp-login.diff, 16.7 KB (added by ShinichiN, 12 years ago)
  • .php

    old new  
    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 that are to shake the login form.
     54         *
     55         * @since 3.0.0
     56         *
     57         * @param array $shake_error_codes Error codes that will 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 timig of enqueing scripts and styles on the login page.
     89         *
     90         * The proper hook to use when enqueuing scripts and styles that are meant to 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() ) {
     
    87106                $login_header_url   = __( 'http://wordpress.org/' );
    88107                $login_header_title = __( 'Powered by WordPress' );
    89108        }
    90 
     109        /**
     110         * Filter the 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         */
    91116        $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         */
    92124        $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
    93125
    94126        $classes = array( 'login-action-' . $action, 'wp-core-ui' );
     
    105137                if ( 'success' ===  $interim_login )
    106138                        $classes[] = 'interim-login-success';
    107139        }
    108 
     140        /**
     141         * Filter the classes of login page <body>.
     142         *
     143         * @since 3.5.0
     144         *
     145         * @param array $classes Classes to be added to the <body>.
     146         * @param string $action The action user took before coming to the login page.
     147         */
    109148        $classes = apply_filters( 'login_body_class', $classes, $action );
    110149
    111150        ?>
     
    116155        <?php
    117156
    118157        unset( $login_header_url, $login_header_title );
    119 
    120         $message = apply_filters('login_message', $message);
     158        /**
     159         * Filter the message to display in header above login form.
     160         *
     161         * @since 2.1.0
     162         *
     163         * @param string $message Message text.
     164         */
     165        $message = apply_filters( 'login_message', $message );
    121166        if ( !empty( $message ) )
    122167                echo $message . "\n";
    123168
     
    140185                        }
    141186                }
    142187                if ( !empty($errors) )
    143                         echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
     188                        /**
     189                         * Filter the error message above the login form.
     190                         *
     191                         * @since 2.1.0
     192                         *
     193                         * @param string $errors Error message.
     194                         */
     195                        echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
    144196                if ( !empty($messages) )
    145                         echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
     197                        /**
     198                         * Filter the message above the login form.
     199                         *
     200                         * @since 2.5.0
     201                         *
     202                         * @param string $messages Login message.
     203                         */
     204                        echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
    146205        }
    147206} // End of login_header()
    148207
     
    168227        </script>
    169228        <?php endif; ?>
    170229
    171         <?php do_action('login_footer'); ?>
     230        <?php
     231        /**
     232         * Fires at the end of the html on the login page.
     233         *
     234         * @since 3.1.0
     235         */     
     236        do_action( 'login_footer' ); ?>
    172237        <div class="clear"></div>
    173238        </body>
    174239        </html>
     
    212277                $user_data = get_user_by('login', $login);
    213278        }
    214279
    215         do_action('lostpassword_post');
     280        /**
     281         * Fires before returning WP Error in password retrieving process.
     282         *
     283         * @since 2.1.0
     284         */     
     285        do_action( 'lostpassword_post' );
    216286
    217287        if ( $errors->get_error_code() )
    218288                return $errors;
     
    226296        $user_login = $user_data->user_login;
    227297        $user_email = $user_data->user_email;
    228298
    229         do_action('retreive_password', $user_login);  // Misspelled and deprecated
     299        // Misspelled and deprecated
     300        do_action( 'retreive_password', $user_login );
     301        /**
     302         * Fires after redefing user login from the user data object.
     303         *
     304         * @since 1.5.2
     305         *
     306         * @param string $user_login User name to login.
     307         */             
    230308        do_action('retrieve_password', $user_login);
    231 
    232         $allow = apply_filters('allow_password_reset', true, $user_data->ID);
     309        /**
     310         * Filter password reset restriction boolean.
     311         *
     312         * @since 2.7.0
     313         *
     314         * @param boolean True as default.
     315         * @param int $user_data->ID The ID of the user who is retrieving new password.
     316         */
     317        $allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
    233318
    234319        if ( ! $allow )
    235320                return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
     
    240325        if ( empty($key) ) {
    241326                // Generate something random for a key...
    242327                $key = wp_generate_password(20, false);
    243                 do_action('retrieve_password_key', $user_login, $key);
     328                /**
     329                 * Fires before inserting the new md5 key into database.
     330                 *
     331                 * @since 2.5.0
     332                 *
     333                 * @param string $user_login User name to login.
     334                 * @param string $key Activation key.
     335                 */
     336                do_action( 'retrieve_password_key', $user_login, $key );
    244337                // Now insert the new md5 key into the db
    245338                $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
    246339        }
     
    259352                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    260353
    261354        $title = sprintf( __('[%s] Password Reset'), $blogname );
    262 
    263         $title = apply_filters('retrieve_password_title', $title);
    264         $message = apply_filters('retrieve_password_message', $message, $key);
     355        /**
     356         * Filter the title of the password reset mail.
     357         *
     358         * @since 2.8.0
     359         *
     360         * @param string $title Default mail title.
     361         */
     362        $title = apply_filters( 'retrieve_password_title', $title );
     363        /**
     364         * Filter the body message of the password reset mail.
     365         *
     366         * @since 2.8.0
     367         *
     368         * @param string $message Default mail message.
     369         * @param string $key The activation key.
     370         */
     371        $message = apply_filters( 'retrieve_password_message', $message, $key );
    265372
    266373        if ( $message && !wp_mail($user_email, $title, $message) )
    267374                wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
     
    304411 * @param string $new_pass New password for the user in plaintext
    305412 */
    306413function reset_password($user, $new_pass) {
    307         do_action('password_reset', $user, $new_pass);
     414        /**
     415         * Runs before the user's password is reset to a random new password.
     416         *
     417         * @since 1.5.2
     418         *
     419         * @param string $user The user.
     420         * @param string $new_pass New password for the user in plaintext.
     421         */             
     422        do_action( 'password_reset', $user, $new_pass );
    308423
    309424        wp_set_password($new_pass, $user->ID);
    310425
     
    322437        $errors = new WP_Error();
    323438
    324439        $sanitized_user_login = sanitize_user( $user_login );
     440        /**
     441         * Filter the user email address on user registration.
     442         *
     443         * @since 2.1.0
     444         *
     445         * @param string $user_email User's email address to send password and add.
     446         */
    325447        $user_email = apply_filters( 'user_registration_email', $user_email );
    326448
    327449        // Check the username
     
    344466                $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
    345467        }
    346468
     469        /**
     470         * Fires before registering a new user.
     471         *
     472         * @since 2.1.0
     473         *
     474         * @param string $sanitized_user_login Sanitized user's username for logging in.
     475         * @param string $user_email New user email.
     476         * @param object $errors WP Error object.
     477         */             
    347478        do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
    348 
     479        /**
     480         * Filter the errors of register validation.
     481         *
     482         * @since 2.1.0
     483         *
     484         * @param array $errors WP Error object.
     485         * @param string $sanitized_user_login Sanitized user's username for logging in.
     486         * @param string $user_email New user email.
     487         */
    349488        $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
    350489
    351490        if ( $errors->get_error_code() )
     
    397536if ( SITECOOKIEPATH != COOKIEPATH )
    398537        setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
    399538
    400 // allow plugins to override the default actions, and to add extra actions if they want
     539/**
     540 * Fires before running the main action of wp-login.php.
     541 *
     542 * Allow plugins to override the default actions, and to add extra actions if they want.
     543 *
     544 * @since 3.2.0
     545 *
     546 */             
    401547do_action( 'login_init' );
     548/**
     549 * Fires before running the main action of wp-login.php depending on the $action.
     550 *
     551 * @since Unknown
     552 *
     553 */             
    402554do_action( 'login_form_' . $action );
    403555
    404556$http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
     
    441593        }
    442594
    443595        if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
     596        /**
     597         * Filtering the redirect url after submitting the lostpassword/retrievepassword form.
     598         *
     599         * @since 3.0.0
     600         *
     601         * @param string The redirect destination url.
     602         */
    444603        $redirect_to = apply_filters( 'lostpassword_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
    445604
    446         do_action('lost_password');
     605        /**
     606         * Fires before the lost password and retrieving password form
     607         *
     608         * @since 1.5.2
     609         *
     610         */     
     611        do_action( 'lost_password' );
    447612        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);
    448613
    449614        $user_login = isset($_POST['user_login']) ? wp_unslash($_POST['user_login']) : '';
     
    455620                <label for="user_login" ><?php _e('Username or E-mail:') ?><br />
    456621                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
    457622        </p>
    458 <?php do_action('lostpassword_form'); ?>
     623<?php
     624/**
     625 * Fires in the lostpassword form.
     626 *
     627 * @since 2.1.0
     628 *
     629 */             
     630do_action( 'lostpassword_form' ); ?>
    459631        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
    460632        <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>
    461633</form>
    462634
    463635<p id="nav">
    464636<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
    465 <?php if ( get_option( 'users_can_register' ) ) : ?>
    466  | <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?>
    467 <?php endif; ?>
    468 </p>
     637<?php
     638        if ( get_option( 'users_can_register' ) ) :
     639                /**
     640                 * Filter the Register link text below the login form.
     641                 *
     642                 * @since 1.5.2
     643                 *
     644                 * @param string Register ink text.
     645                 */
     646                echo ' | ' . apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) );
     647        endif;
     648?></p>
    469649
    470650<?php
    471651login_footer('user_login');
     
    485665        if ( isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2'] )
    486666                $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
    487667
     668        /**
     669         * Fires before the validation in the reset password precedure.
     670         *
     671         * @since 3.5.0
     672         *
     673         * @param object $errors WP Error object.
     674         * @param string $user User data.
     675         */     
    488676        do_action( 'validate_password_reset', $errors, $user );
    489677
    490678        if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
     
    521709
    522710<p id="nav">
    523711<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
    524 <?php if ( get_option( 'users_can_register' ) ) : ?>
    525  | <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?>
    526 <?php endif; ?>
    527 </p>
     712<?php
     713        if ( get_option( 'users_can_register' ) ) :
     714                //duplicate_hook
     715                echo ' | ' . apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) );
     716        endif;
     717?></p>
     718
    528719
    529720<?php
    530721login_footer('user_pass');
     
    532723
    533724case 'register' :
    534725        if ( is_multisite() ) {
    535                 // Multisite uses wp-signup.php
     726                /**
     727                 * Filter the redirect destination url for the Multi Site installation.
     728                 *
     729                 * @since 3.0.0
     730                 *
     731                 * @param string Signup url of the multisite.
     732                 */
    536733                wp_redirect( apply_filters( 'wp_signup_location', network_site_url('wp-signup.php') ) );
    537734                exit;
    538735        }
     
    554751                        exit();
    555752                }
    556753        }
    557 
     754        /**
     755         * Filter the redirect destination url after user registration.
     756         *
     757         * @since 3.0.0
     758         *
     759         * @param string The redirect destination url.
     760         */
    558761        $redirect_to = apply_filters( 'registration_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
    559762        login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
    560763?>
     
    568771                <label for="user_email"><?php _e('E-mail') ?><br />
    569772                <input type="text" name="user_email" id="user_email" class="input" value="<?php echo esc_attr(wp_unslash($user_email)); ?>" size="25" /></label>
    570773        </p>
    571 <?php do_action('register_form'); ?>
     774<?php
     775/**
     776 * Fires in the registration form.
     777 *
     778 * @since 2.1.0
     779 *
     780 */     
     781do_action( 'register_form' ); ?>
    572782        <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
    573783        <br class="clear" />
    574784        <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
     
    621831
    622832        $user = wp_signon('', $secure_cookie);
    623833
    624         $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);
     834        /**
     835         * Filtering the redirect url after login.
     836         *
     837         * @since 3.0.0
     838         *
     839         * @param string $redirect_to The redirect destination url.
     840         * @param string The redirect destination url which was passed as a parameter.
     841         * @param object $user User data object.
     842         */
     843        $redirect_to = apply_filters( 'login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user );
    625844
    626845        if ( !is_wp_error($user) && !$reauth ) {
    627846                if ( $interim_login ) {
     
    629848                        $interim_login = 'success';
    630849                        login_header( '', $message ); ?>
    631850                        </div>
    632                         <?php do_action( 'login_footer' ); ?>
     851                        <?php
     852                        /**
     853                         * Fires at the end of the html on the login page.
     854                         *
     855                         * @since 3.5.0
     856                         *
     857                         * @param object $errors WP Error object.
     858                         * @param string $user User data.
     859                         */     
     860                        do_action( 'login_footer' ); ?>
    633861                        <?php if ( $customize_login ) : ?>
    634862                                <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
    635863                        <?php endif; ?>
     
    677905                elseif ( strpos( $redirect_to, 'about.php?updated' ) )
    678906                        $errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
    679907        }
    680 
     908        /**
     909         * Filter the WP Error object.
     910         *
     911         * @since 3.6.0
     912         *
     913         * @param object $errors WP Error object.
     914         * @param string $redirect_to Redirect destination url.
     915         */
    681916        $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
    682917
    683918        // Clear any stale cookies.
     
    700935                <label for="user_pass"><?php _e('Password') ?><br />
    701936                <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
    702937        </p>
    703 <?php do_action('login_form'); ?>
     938<?php
     939/**
     940 * Fires in the login form.
     941 *
     942 * @since 2.1.0
     943 *
     944 */     
     945do_action( 'login_form' ); ?>
    704946        <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>
    705947        <p class="submit">
    706948                <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
     
    718960
    719961<?php if ( ! $interim_login ) { ?>
    720962<p id="nav">
    721 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) : ?>
    722         <?php if ( get_option( 'users_can_register' ) ) : ?>
    723                 <?php echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?> |
    724         <?php endif; ?>
     963<?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
     964        if ( get_option( 'users_can_register' ) ) :
     965                //duplicate_hook
     966                echo apply_filters( 'register', sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ) . ' | ';
     967        endif;
     968?>
    725969        <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
    726970<?php endif; ?>
    727971</p>