我有一个名为User Registration的插件,该过程运行良好,但它在验证字段时会导致问题。
在使用不正确的电子邮件登录后,我会收到一条错误消息,但如果密码不正确,我将不会收到任何消息。
我检查了我的插件中的代码,发现下面的函数不起作用,但我不知道为什么。
任何帮助都是非常感谢的。
// 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;
}发布于 2019-07-21 07:34:47
我假设这是一个filter for Wordpress login_errors。
在上面的链接示例中,“不正确”指的是密码,而“无效”指的是用户名-使用它们的($pos和£pos2),而使用另一个(错误?)在你的函数中。
还可以尝试将代码中的strpos (区分大小写)替换为stripos (不区分大小写)。
正如Dave在评论中所说,最好不要指出是用户名还是密码出错。因此,您还可以用一个if - print块替换2个if-print块
if ( (is_int( $pos ) || is_int( $pos2 ) ) && isset( $_POST['username'] ) ) {
$error = # printf some "either username or password is invalid" message here
}https://stackoverflow.com/questions/57124392
复制相似问题