我需要帮助解决问题。我正在使用 Ultimate Member 插件进行出生日期验证。我想检查用户从数据选择中输入的年份,并检查他们是否年满 13 岁。我试过用钩子解决它,但它不允许在日期选择器上进行自定义验证。这是我的代码:
add_action('um_submit_form_errors_hook_student_birthdate','um_custom_validate_birthdate', 999, 1);
function um_custom_validate_birthdate( $args ) {
$birthDate = $args['birth_date'];
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[1], $birthDate[2], $birthDate[0]))) > date("md")
? ((date("Y") - $birthDate[0]) - 1)
: (date("Y") - $birthDate[0]));
if ( isset( $args['birth_date'] ) && $age < 13 ) {
UM()->form()->add_error( 'birth_date', "You must be atleast 13 years old to create an account." );
}
}