- This topic has 0 replies, 1 voice, and was last updated 1 year, 9 months ago by .
Viewing 0 reply threads
Viewing 0 reply threads
- You must be logged in to reply to this topic.
Welcome › mkmcst community Forum › Web programming › WordPress › Ultimate Member Code Examples › Restrict registration for under 18 years old
This code snippet restricts registration for under 18 years old using the custom validation applied to the Birth Date field.
Just add this code to the functions.php file in the active theme directory.
<?php
/**
* Restrict registration for under 18 years old.
*
* @param array $args Form Arguments.
*/
function um_custom_validate_birth_date( $args ) {
if ( ! empty( $args['birth_date'] ) ) {
// Birth date as a Unix timestamp.
$then = strtotime( $args['birth_date'] );
// A person 18'th birthday as a Unix timestamp.
$adulthood = strtotime( '+18 years', $then );
// Current time.
$now = time();
if ( $now < $adulthood ) {
UM()->form()->add_error( 'birth_date', __( 'You should be over 17 years old.', 'ultimate-member' ) );
}
}
}
add_action( 'um_submit_form_errors_hook_', 'um_custom_validate_birth_date', 30, 1 );
https://docs.ultimatemember.com/article/1781-restrict-registration-for-under-18-years-old