Created
February 19, 2015 12:27
-
-
Save spivurno/2b3839548318449da7dc to your computer and use it in GitHub Desktop.
Gravity Perks // GP Limit Choices // Daily Limit
This file contains hidden or 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 | |
/** | |
* Gravity Perks // GP Limit Choices // Daily Limit | |
* | |
* By default, GP Limit Choices limits choices forever. This snippet will allow you to make that limit apply only to the current day. | |
* | |
* @author David Smith <david@gravitywiz.com> | |
* @license GPL-2.0+ | |
* @link http://gravityperks.com | |
* @copyright 2015 Gravity Wiz | |
*/ | |
class GWLimitChoicesDailyLimit { | |
function __construct( $args ) { | |
$this->_args = wp_parse_args( $args, array( | |
'form_id' => false, | |
'field_ids' => array() | |
) ); | |
add_filter( "gwlc_choice_counts_query_{$this->_args['form_id']}", array( $this, 'modify_choice_counts_query' ), 10, 2 ); | |
} | |
function modify_choice_counts_query( $query, $field ) { | |
$form = GFAPI::get_form( $field['formId'] ); | |
foreach( $form['fields'] as $field ) { | |
if( ! in_array( $field['id'], $this->_args['field_ids'] ) ) { | |
continue; | |
} | |
$time_period_sql = 'DATE( date_created ) = DATE( utc_timestamp() )'; | |
$query['where'] .= ' AND ' . $time_period_sql; | |
} | |
return $query; | |
} | |
} | |
new GWLimitChoicesDailyLimit( array( | |
'form_id' => 436, | |
'field_ids' => array( 4 ) | |
) ); |
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-limit-choices/gplc-daily-limit.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi David
I have a question