Last active
June 6, 2016 20:58
-
-
Save spivurno/4024503 to your computer and use it in GitHub Desktop.
Gravity Wiz // Usage Examples for Limit Submissions Per Time Period (https://gist.github.com/spivurno/4024361)
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 | |
$safe_ips = array( '75.74.153.104', '127.0.0.1' ); | |
if( is_callable( array( 'GFFormsModel', 'get_ip' ) ) && ! in_array( GFFormsModel::get_ip(), $safe_ips ) ) { | |
# Global Limit Across ALL Forms | |
new GW_Submission_Limit( array( | |
'limit' => 1, | |
'limit_message' => 'Aha! You have been limited.', | |
'apply_limit_per_form' => false, | |
'time_period' => 60 * 1, | |
'enable_notifications' => true | |
) ); | |
# Limit Applied to Specific Form | |
new GW_Submission_Limit( array( | |
'form_id' => 602, | |
'limit' => 2, | |
'limit_message' => 'Check it! No more for you.', | |
'time_period' => 60 * 1, | |
'enable_notifications' => true | |
) ); | |
} |
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 | |
// standard usage | |
new GW_Submission_Limit( array( | |
'form_id' => 86, | |
'limit' => 2, | |
) ); | |
// all options | |
new GW_Submission_Limit( array( | |
'form_id' => 2, | |
'limit' => 5, | |
'time_period' => 60 * 60 * 24 * 2, // two days in seconds; also supports 'per_day', 'per_month', 'per_year' | |
'limit_message' => 'You are all maxed out! Try again in a couple days.', | |
'limit_by' => 'ip', // default is 'ip', also supports 'user_id', 'embed_url', 'role'; can alternately provide an array of limitations: array( 'ip', 'embed_url' ) | |
) ); | |
// apply to ALL forms | |
new GW_Submission_Limit( array( | |
'limit' => 5 | |
) ); | |
// apply multiple limiters | |
new GW_Submission_Limit( array( | |
'form_id' => 2, | |
'limit' => 1, | |
'limit_message' => 'Aha! You have been limited.', | |
'limit_by' => array( 'embed_url', 'user_id' ) | |
) ); | |
// limit by roles | |
new GW_Submission_Limit( array( | |
'form_id' => 2, | |
'limit_by' => 'role', | |
// when "limit_by" is set to "role", "limit" must be provided as array with roles and their corresponding limits | |
'limit' => array( | |
'administrator' => 20, | |
'contributor' => 5 | |
) | |
) ); | |
// limit by calendar time period | |
new GW_Submission_Limit( array( | |
'form_id' => 3, | |
'time_period' => 'per_month' | |
) ); | |
// Limit by Field Value (with no time period) | |
new GW_Submission_Limit( array( | |
'form_id' => 1, | |
'limit_by' => 'field_value', | |
'limit' => array( | |
// "2" is your field ID, "6" is your limit for this field ID | |
2 => 6 | |
), | |
'time_period' => false // forever! | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment