I made a birthday field in the register form of the user… I need help on where (in which files) can I put the check for the age, if it is 18 years and older, I have the implementation of this check, but I don’t know exactly where to put this to make the check when the user registers…
i added this code to make the field for the birthday in the register form inside user_register.php file:
'birthday' => [ 'label' => esc_html__( 'Birthday', 'hivepress' ),
'type' => 'date', // Use 'date' type for a date picker
'required' => true,
'max_length' => 64,
'_order' => 40,
],
I have the implementation for the check:
// Custom validation for the birthday field add_filter
( 'hivepress/v1/models/user/validate',
function( $errors, $fields, $values ) {
if ( isset( $values['birthday'] ) ) {
// Convert the birthday to a timestamp
$birthday = strtotime( $values['birthday'] );
// Check if the date conversion failed
if ( !$birthday ) {
$errors[] = esc_html__( 'Invalid birthday format.', 'hivepress' ); }
else {
// Calculate the age
$age = ( time() - $birthday ) / ( 60 * 60 * 24 * 365.25 );
// Check if the age is less than 18
if ( $age < 18 ) {
$errors[] = esc_html__( 'You must be at least 18 years old.', 'hivepress' );
}
}
}
return $errors;
}
I think this is not correct ‘hivepress/v1/models/user/validate’ and i need help on where to put this code to make the check when the user registers.
Thank you,
George Kyritsis.