Bypass Required Fields

By: Michael Clark | Asked: 05/31/2022
ForumsCategory: General questionsBypass Required Fields
Michael ClarkMichael Clark asked 2 years ago
I'd like a consistent and simple way to bypass required fields without making the fields not required. Anybody have a good workaround?
Rob LeVineRob LeVine replied 2 years ago

I use a snippet that goes something like this:

add_filter('frm_validate_entry', 'validate_my_form', 20, 2);
function validate_my_form($errors, $values){
$formId = $values['form_id'];
If ($formId == ) {
return array();
}
return $errors;
}

Michael ClarkMichael Clark replied 2 years ago

Thanks, Rob. Looks like this turns off required fields for everyone. Any hints on how to ensure this is only for a given user or role?

Rob LeVineRob LeVine replied 2 years ago

You can do anything in that function that you can do in PHP. If you want a certain user, you can use:
if (wp_get_current_user() == )
and if you want a certain role you can do something like this:
$user = wp_get_current_user();
$allowed_roles = array();

$allowed = !empty(array_intersect($allowed_roles, $user->roles));

Michael ClarkMichael Clark replied 2 years ago

OK. Thanks.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right