错误撤退' 0'而不是定义的消息

时间:2016-06-15 13:05:10

标签: php

我有一个发送密码重置电子邮件的字段表单。如果用户输入正确的用户名/电子邮件,则验证有效,但如果他们输入了错误的用户名/电子邮件或将该字段留空,则错误消息为“0”。但它应该是所述消息之一。下面是验证码。我不确定我错过了什么。

function lost_pass_callback() {

    global $wpdb, $wp_hasher;

    $nonce = $_POST['nonce'];

    if ( ! wp_verify_nonce( $nonce, 'rs_user_lost_password_action' ) )
        die ( 'Security checked!');     
$user_login = $_POST['user_login'];

        $errors = new WP_Error();

        if ( empty( $user_login ) ) {
            $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
        } else if ( strpos( $user_login, '@' ) ) {
            $user_data = get_user_by( 'email', trim( $user_login ) );
            if ( empty( $user_data ) )
                $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
        } else {
            $login = trim( $user_login );
            $user_data = get_user_by('login', $login);
        }

        /**
         * Fires before errors are returned from a password reset request.
         *
         * @since 2.1.0
         * @since 4.4.0 Added the `$errors` parameter.
         *
         * @param WP_Error $errors A WP_Error object containing any errors generated
         *                         by using invalid credentials.
         */
        do_action( 'lostpassword_post', $errors );

        if ( $errors->get_error_code() )
            return $errors;

        if ( !$user_data ) {
            $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or email.'));
            return $errors;
        }

if ( wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
        $errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
    else
        $errors->add('could_not_sent', __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.'), 'message');


    // display error message
    if ( $errors->get_error_code() )
        echo '<p class="error">'. $errors->get_error_message( $errors->get_error_code() ) .'</p>';

0 个答案:

没有答案