我假设您所说的“我需要帮助来验证/连接新的自定义字段到中的数据列wp_users 你的意思是“连续剧”wp_usermeta 元键为“serials”的字段。
要验证作为登录的一部分的任何其他字段,请使用wp_authenticate_user filter.
首先检查$user 是一个WP错误,如果是,由于登录失败,因此没有必要继续。如果不是错误,请继续检查自定义字段是否为空,因为您需要确保它已填写。如果字段为空,则返回错误。
最后,如果它是一个有效的用户,并且字段中给出了值,则检索db值(如上所述,假设这是wp\\U usermeta中的用户元键,因为wp\\U users中没有自定义字段)。如果比较值失败,则返回错误。
add_filter( \'wp_authenticate_user\', \'my_validate_pin\', 10, 2 );
function my_validate_pin( $user, $password ) {
// Validate PIN if we\'re not already in an error.
if ( ! is_wp_error( $user ) ) {
$pin = get_user_meta( $user->ID, \'serials\', true );
// Error if field is empty.
if ( ! isset( $_POST[\'my_extra_field_name\'] ) ) {
remove_action( \'authenticate\', \'wp_authenticate_username_password\', 20 );
$user = new WP_Error( \'failed\', __("<strong>ERROR</strong>: Must include PIN") );
}
// Assuming you\'re looking for form value to match the db value.
if ( $pin != $_POST[\'my_extra_field_name\'] ) {
// If values don\'t match, return error
remove_action( \'authenticate\', \'wp_authenticate_username_password\', 20 );
$user = new WP_Error( \'failed\', __("<strong>ERROR</strong>: Invalid PIN") );
}
}
return $user;
}