验证功能在Wordpress中不起作用

时间:2019-07-20 11:46:48

标签: php mysql wordpress authentication

我有一个名为“用户注册插件”的插件,该过程运行良好,但是在验证字段时会引起问题。

使用不正确的电子邮件登录后,我会收到一条错误消息,但是如果密码不正确,我将不会收到任何错误消息。

我检查了插件中的代码,结果发现下面的功能不起作用,但我不知道为什么。

感谢您的帮助。

    // Modify error message on invalid username or password.
    function ur_login_error_message( $error ) {
        // Don't change login error messages on admin site .
        if ( isset( $_POST['redirect_to'] ) && false !== strpos( $_POST['redirect_to'], network_admin_url() ) ) {
            return $error;
        }

        $pos  = strpos( $error, 'incorrect' );     // Check if the error contains incorrect string.
        $pos2 = strpos( $error, 'Invalid' );       // Check if the error contains Invalid string.

        // Its the correct username with incorrect password.
        if ( is_int( $pos ) && isset( $_POST['username'] ) ) {

            $error = sprintf( '<strong>' . __( 'ERROR:', 'user-registration' ) . '</strong>' . __( 'The password you entered for username %1$1s is incorrect. %2$2s', 'user-registration' ), $_POST['username'], "<a href='" . esc_url( wp_lostpassword_url() ) . "'>" . __( 'Lost Your Password?', 'user-registration' ) . '</a>' );
        } // It's invalid username.
        elseif ( is_int( $pos2 ) && isset( $_POST['username'] ) ) {
            $error = sprintf( '<strong>' . __( 'ERROR:', 'user-registration' ) . '</strong>' . __( 'Invalid username. %1s', 'user-registration' ), "<a href='" . esc_url( wp_lostpassword_url() ) . "'>" . __( 'Lost Your Password?', 'user-registration' ) . '</a>' );
        }

        return $error;
    }

1 个答案:

答案 0 :(得分:0)

我认为这是filter for Wordpress login_errors

在上述链接的示例中,“ invalid ”指的是密码,“ Invalid ”指的是用户名-它们使用($ pos和£pos2)

还尝试用strpos(不区分大小写)替换代码中的stripos(区分大小写)。

正如戴夫(Dave)在评论中所说,最好不要指出是用户名还是密码错误。因此,您也可以将2个if-打印块替换为一个

if (  (is_int( $pos ) || is_int( $pos2 ) ) && isset( $_POST['username'] ) ) {
    $error =  # printf some "either username or password is invalid" message here
}