Created
September 16, 2014 04:29
-
-
Save spivurno/e33b669590160bb3d1df to your computer and use it in GitHub Desktop.
Gravity Perks // GP Limit Choices // Hide Form if Choices Exhausted
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
/** | |
* 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