Created
September 17, 2018 09:53
-
-
Save kenmasters/5e18da455b907135c89a5f6069cc252a 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
# 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