Add max_date to be date 18 years before current date

There is a option to set maximum date and minimum date in custom user attribute in hivepress but only absolute values are accepted. I want to create a filter so that maximum date that can be set to ‘dob’ attribute of user = (current date - 18) .

I want to add age restriction so that only users need to be over 16.

i tried this code but didnt work:

add_filter('hivepress/v1/models/user_attributes', function($attributes) {
    // Find the user attribute with field name 'dob'
    foreach ($attributes as &$attribute) {
        if ($attribute['field'] === 'dob') {
            // Set the minimum and maximum dates for the 'dob' field
            $attribute['min_date'] = '1935-01-01'; // Minimum date: January 1, 1935
            $attribute['max_date'] = date('Y-m-d', strtotime('-18 years')); // Maximum date: 18 years before today
        }
    }
    return $attributes;
});

Sorry for the delay.

There’s no such filter hook so this code snippet will not work, but I recommend using the hivepress/v1/forms/user_update/errors filter hook, this way you can check any form details and add custom validation errors.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.