你好,stackoverflow社区,我需要帮助解决WordPress登录验证的问题。所以我安装了CAPATCHA by Best。。。为了将capatcha放入自定义wp_login_form中,我需要添加验证。所以我创建了这个:
add_filter( 'wp_authenticate_user', 'my_custom_authenticate', 10, 3 );
function my_custom_authenticate( $user, $username, $password ){
//Get POSTED value
if ( ( function_exists( 'cptch_check_custom_form' ) && cptch_check_custom_form() !== true ) || ( function_exists( 'cptchpr_check_custom_form' ) && cptchpr_check_custom_form() !== true ) ) {
remove_action('authenticate', 'wp_authenticate_username_password', 20);
$user = new WP_Error( 'denied', __("<strong>ERROR</strong>: You're CAPTCHA field was wrong.") );
}
return $user;
}
但它总是以错误的形式返回。我添加了capatcha字段:
add_filter( 'login_form_middle','cptch_custom_form' );
你有没有遇到过这个问题,我该怎么解决?
采用"尝试并失败"的方法。
使用var_dump()
检查if
语句中每个条件的值。
类似这样的东西:
add_filter( 'wp_authenticate_user', 'my_custom_authenticate', 10, 3 );
function my_custom_authenticate( $user, $username, $password ){
/** THIS IS THE DEBUGGING PART */
var_dump(function_exists( 'cptch_check_custom_form' ));
var_dump(cptch_check_custom_form()));
var_dump(function_exists( 'cptchpr_check_custom_form' ));
var_dump(cptchpr_check_custom_form() !== true);
/** END DEBUGGING PART */
//Get POSTED value
if (
( function_exists( 'cptch_check_custom_form' ) && true !== cptch_check_custom_form() )
|| ( function_exists( 'cptchpr_check_custom_form' ) && true !== cptchpr_check_custom_form() ) )
{
remove_action('authenticate', 'wp_authenticate_username_password', 20);
$user = new WP_Error( 'denied', __("<strong>ERROR</strong>: You're CAPTCHA field was wrong.") );
}
return $user;
}
注意:我已经使用Yoda的表示法更改了条件,它使用起来更安全。