Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created May 21, 2021 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/db58fdcbb790ff4641f2b1e19c9f8883 to your computer and use it in GitHub Desktop.
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)
<?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;
}
@tripflex
Copy link
Author

If you want to use a date picker for the "birthday" instead, use this code:
https://gist.github.com/tripflex/7a5e6e83879f0910ceaeab16b27c67a0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment