gpls_before_query
Description
Do something (like modify the GPLS_RuleTest object) before the query is executed.
Usage
add_action( 'gpls_before_query', 'my_custom_function' );
Parameters
gpls_rule_test \GPLS_RuleTest
The current instance of the GPLS_RuleTest object.
Since
This action is available since Gravity Forms Limit Submissions 1.0-beta-1.20.
Examples
Set Limit Period by User Meta
<?php
/**
* Gravity Perks // Limit Submissions // Set Limit Period by User Meta
* https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
*/
add_action( 'gpls_before_query', function( $ruletest ) {
global $wpdb;
// Update "123" to your form ID.
if ( $ruletest->form_id != 123 ) {
return;
}
// Update "subscription_start_date" to your user meta key.
$subscription_start_date = get_user_meta( get_current_user_id(), 'subscription_start_date', true );
$time_period_sql = $wpdb->prepare( 'date_created BETWEEN %s AND DATE_ADD( CURDATE(), INTERVAL 1 DAY )', $subscription_start_date );
$ruletest->where[] = $time_period_sql;
} );
Scope Feeds to the Current Nested Forms Parent Entry
Configure a Limit Submissions feed for a child form and then scope that feed to only apply to child entries submitted for the same parent entry.
For example, if we create a Limit Submissions feed that limits by the field value of a Name field, “David Smiff” could not be specified in this field for two child entries of the same parent entry. However, if I submitted a second parent entry, I could enter “David Smiff” as a child entry again.
<?php
/**
* Gravity Perks // Limit Submissions // Scope Feeds to the Current Nested Forms Parent Entry.
* https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
*
* Set GP Limit Submissions feed to only apply to child entries submitted for the same parent entry.
*/
add_action( 'gpls_before_query', function( $ruletest ) {
global $wpdb;
$parent_form_id = rgpost( 'gpnf_parent_form_id' );
// Update "123" to your child form ID.
if ( $ruletest->form_id == 123 && class_exists( 'GPNF_Session' ) && $parent_form_id ) {
$gpnf_session = new GPNF_Session( $parent_form_id );
$ruletest->join[] = "INNER JOIN {$wpdb->prefix}gf_entry_meta em_gpnf ON em_gpnf.entry_id = e.id";
$ruletest->where[] = sprintf( "\n( em_gpnf.meta_key = '%s' AND em_gpnf.meta_value = '%s' )", GPNF_Entry::ENTRY_PARENT_KEY, $gpnf_session->get( 'hash' ) );
}
} );
All Connections
All Perks
- GF Address Autocomplete
- GF Advanced Calculations
- GF Advanced Phone Field
- GF Advanced Save & Continue
- GF Advanced Select
- GF Auto List Field
- GF Auto Login
- GF Better User Activation
- GF Blocklist
- GF Bookings
- GF Conditional Logic Dates
- GF Conditional Pricing
- GF Copy Cat
- GF Date Time Calculator
- GF Disable Entry Creation
- GF Easy Passthrough
- GF eCommerce Fields
- GF Email Users
- GF Email Validator
- GF Entry Blocks
- GF Expand Textareas
- GF File Renamer
- GF File Upload Pro
- GF Inventory
- GF Limit Checkboxes
- GF Limit Dates
- GF Limit Submissions
- GF Live Preview
- GF Media Library
- GF Multi-Page Navigation
- GF Nested Forms
- GF Notification Scheduler
- GF Page Transitions
- GF Pay Per Word
- GF Populate Anything
- GF Post Content Merge Tags
- GF Preview Submission
- GF Price Range
- GF QR Code
- GF Randomizer
- GF Read Only
- GF Reload Form
- GF Submit to Access
- GF Terms Of Service
- GF Unique ID
- GF Word Count