Forked from spivurno/gp-populate-anything-plus-gp-limit-choices.php
Created
June 27, 2020 21:17
-
-
Save claygriffiths/08423b84c372efb473bf2d815bbe466e to your computer and use it in GitHub Desktop.
Gravity Perks // GP Populate Anything + GP Limit Choices
This file contains 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_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