Created
March 25, 2020 12:43
-
-
Save vfontjr/b9d195d6551ebe70001f2b4ed58d03e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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( '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