Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save claygriffiths/08423b84c372efb473bf2d815bbe466e to your computer and use it in GitHub Desktop.
Save claygriffiths/08423b84c372efb473bf2d815bbe466e to your computer and use it in GitHub Desktop.
Gravity Perks // GP Populate Anything + GP Limit Choices
<?php
add_action( 'init', function() {
$gplc_form_id = 123;
$gplc_field_id = 4;
if( is_callable( 'gp_limit_choices' ) ) {
add_filter( "gform_pre_process_{$gplc_form_id}", function( $form ) {
global $gplc_field_id;
foreach( $form['fields'] as $field ) {
if( $field->id == $gplc_field_id ) {
$field->{gp_limit_choices()->key( 'enableLimits' )} = true;
}
}
return $form;
} );
add_filter( "gppa_input_choices_{$gplc_form_id}_{$gplc_field_id}", function( $choices, $field ) {
foreach( $choices as &$choice ) {
$choice['limit'] = 1;
}
$choices = gp_limit_choices()->apply_choice_limits( $choices, $field, GFAPI::get_form( $field->formId ) );
return $choices;
}, 10, 2 );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment