Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spivurno/e33b669590160bb3d1df to your computer and use it in GitHub Desktop.
Save spivurno/e33b669590160bb3d1df to your computer and use it in GitHub Desktop.
Gravity Perks // GP Limit Choices // Hide Form if Choices Exhausted
/**
* Gravity Perks // GP Limit Choices // Hide Form if Choices Exhausted
* http://gravitywiz.com/documentation/gp-limit-choices/
*
* Hide the form and display a message when the limit has been reached for a Limit-enabled field. This example will hide the form
* if *any* choice is exhausted so it is best used if there is only one field with limits enabled.
*/
add_filter( 'gform_pre_render', 'gw_disable_form_if_choices_exhausted', 12 );
function gw_disable_form_if_choices_exhausted( $form ) {
$message = 'This event is closed.';
$has_choiceless_field = isset( gp_limit_choices()->choiceless[$form['id']] );
if( $has_choiceless_field ) {
add_filter( 'gform_get_form_filter_' . $form['id'], create_function( '', 'return \'' . $message . '\';' ) );
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment