Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenmasters/5e18da455b907135c89a5f6069cc252a to your computer and use it in GitHub Desktop.
Save kenmasters/5e18da455b907135c89a5f6069cc252a to your computer and use it in GitHub Desktop.
# References:
# https://docs.gravityforms.com/dynamically-populating-drop-down-fields/
# https://docs.gravityforms.com/gf_field_select/
add_filter( 'gform_pre_render_45', 'disable_ADA_ACA_transactions' );
add_filter( 'gform_pre_validation_45', 'disable_ADA_ACA_transactions' );
add_filter( 'gform_pre_submission_filter_45', 'disable_ADA_ACA_transactions' );
add_filter( 'gform_admin_pre_render_45', 'disable_ADA_ACA_transactions' );
function disable_ADA_ACA_transactions( $form ) {
$field = GFFormsModel::get_field( $form, 7 ); // 7 here is the ID of the select field I want to alter.
$exclude = ['ADA', 'ACA'];
$choices = [];
// What Im doing here is - removing specific choices for currently loggedin user
foreach ($field->choices as $key => $choice) {
if ( current_user_can('support-gta-link') && in_array($choice['value'], $exclude)) continue;
$choices[] = [
'text' => $choice['text'],
'value' => $choice['value']
];
}
// Update/Assign the new choices base from logic perform above
$field->choices = $choices;
// Return the form
return $form;
}
# IMPORTANT NOTE: Form ID: 45 <change accdg. to your specific form id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment