Created
May 21, 2021 21:08
-
-
Save tripflex/db58fdcbb790ff4641f2b1e19c9f8883 to your computer and use it in GitHub Desktop.
Verify age is over 18 when using WP Job Manager Field Editor (Resume/Candidate)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'submit_resume_form_validate_fields', 'smyles_verify_age_field_over_18' ); | |
function smyles_verify_age_field_over_18( $no_errors, $fields, $values ) { | |
// Return true if this field doesn't exist (to prevent errors if you dont have field created) | |
if ( ! isset( $values['resume_fields']['candidate_age'] ) ) { | |
return $no_errors; | |
} | |
if ( empty( $values['resume_fields']['candidate_age'] ) || absint( $values['resume_fields']['candidate_age'] ) < 18 ) { | |
throw new Exception( __( 'You must be 18 years or older to submit a listing.' ) ); | |
} | |
return $no_errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to use a date picker for the "birthday" instead, use this code:
https://gist.github.com/tripflex/7a5e6e83879f0910ceaeab16b27c67a0