Skip to content

Instantly share code, notes, and snippets.

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 vfontjr/b9d195d6551ebe70001f2b4ed58d03e2 to your computer and use it in GitHub Desktop.
Save vfontjr/b9d195d6551ebe70001f2b4ed58d03e2 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'frm_validate_field_entry', 'conditionally_require_a_field', 10, 3 );
function conditionally_require_a_field( $errors, $field, $value ) {
if ( $field->id == 25 && trim( $value ) == '' ) { //change 25 to the ID of the field to require
/* get the current user object */
$current_user = wp_get_current_user();
/* */
if ( in_array('administrator', $current_user->roles ) ) { // change 'administrator' to the role you want to make this requireed
$errors[ 'field'. $field->id ] = 'That field is required';
}
}
return $errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment