Skip to content

Instantly share code, notes, and snippets.

@spivurno
spivurno / gp-populate-anything-set-current-form-on-duplicate.php
Last active October 7, 2021 15:11
Gravity Perks // Populate Anything // Auto-update Form ID on Form Duplication
<?php
/**
* Gravity Perks // Populate Anything // Auto-update Form ID on Form Duplication
* http://gravitywiz.com/documentation/gravity-forms-populate-anything/
*
* When populating Gravity Forms Entries via Populate Anything, it can save time to automatically update the selected
* form ID to the new form ID when duplicating an existing form. To enable on any field, just set the
* "gppa-set-current-form" class on the CSS Class Name setting.
*/
add_action( 'gform_post_form_duplicated', function( $form_id, $new_id ) {
@spivurno
spivurno / wp-sessions-gf-out-of-the-box.php
Created April 21, 2020 12:55
WP Sessions // Gravity Forms Out of the Box // Bed & Breakfast Demo
<?php
/**
* WP Sessions // Gravity Forms Out of the Box // Bed & Breakfast Demo
* http://wpsessions.com/sessions/gravity-forms-out-of-the-box/
* http://gravitywiz.com
*/
add_action( 'init', 'register_bnb_room_post_type', 0 );
function register_bnb_room_post_type() {
@spivurno
spivurno / gp-populate-anything-force-dyn-pop-on-gv-edit.php
Created April 6, 2020 00:12
Gravity Perks // Populate Anything // Force Dynamic Population When Editing via Gravity View
<?php
/**
* Gravity Perks // Populate Anything // Force Dynamic Population When Editing via Gravity View
* http://gravitywiz.com/documentation/gravity-forms-populate-anything/
*/
add_filter( 'gravityview/edit_entry/field_value', function( $field_value, $field ) {
// Update "123" to your form ID and "4" to your field ID.
if ( $field->formId == 123 && $field->id == 4 ) {
if ( isset( $GLOBALS['gppa-field-values'] ) ) {
$hydrated_field = gp_populate_anything()->hydrate_field( $field, GFAPI::get_form( $field->formId ), array(), null, false );
<?php
/**
* Gravity Perks // Multi-page Navigation + Easy Passthrough // Make Pages Navigable When Editing Entry
* http://gravitywiz.com/documentation/gravity-forms-multi-page-navigation/
* http://gravitywiz.com/documentation/gravity-forms-easy-passthrough/
*
* When repopulating an entry into a form for editing via Easy Passthrough and
* [this snippet](https://gravitywiz.com/edit-gravity-forms-entries-on-the-front-end/), make all pages navigable if
* Multi-page Navigation is enabled for the given form and configured to allow navigating to any completed page.
*/
<?php
/**
* Gravity Perks // Limit Submissions + Nested Forms // Scope Limit Feeds to Current Parent Entry
* http://gravitywiz.com/documentation/gravity-forms-limit-submissions/
*/
add_action( 'gpls_before_query', function( $ruletest ) {
global $wpdb;
// Update "123" to your child form ID.
if( $ruletest->form_id == 123 && class_exists( 'GPNF_Session' ) && $parent_form_id = rgpost( 'gpnf_parent_form_id' ) ) {
<?php
/**
* Gravity Perks // eCommerce Fields // Show GPECF Fields in WooCommerce Cart Item Description
* http://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
*/
add_action( 'init', function() {
remove_filter( 'gform_pre_render', array( gp_ecommerce_fields(), 'add_wc_class_to_hide_fields_in_cart_description' ) );
}, 11 );
<?php
/**
* Gravity Perks // Media Library // Set Upload Directory
* http://gravitywiz.com/documentation/gravity-forms-media-library/
*/
add_filter( 'gpml_media_data', function( $return ) {
add_filter( 'upload_dir', 'gpml_set_upload_dir' );
if( ! function_exists( 'gpml_set_upload_dir' ) ) {
function gpml_set_upload_dir( $upload_dir ) {
$upload_dir['path'] = ABSPATH . 'wp-content/uploads/paramountregistry';
<?php
/**
* Gravity Wiz // Gravity Forms // Email Header to Identify Notification Source
*
* You've installed Gravity Forms on a ton of sites and now you're getting a ton of notifications. The problem is there
* is no clear indicator which site is sending the notification. How frustrating!
*
* This simple plugin automatically adds a custom header that identifies the URL that generated the Gravity Forms notification.
* This is most useful when installed as an MU plugin at the start of development on each site.
*
/**
* Gravity Perks // Pay Per Word // Surprise, Pay Per Character!
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*/
gform.addFilter( 'gpppw_word_count', function( wordCount, text, gwppw, ppwField, formId ) {
// Pay per character instead of words.
var words = text.split( '' );
return words == null ? 0 : words.length;
} );
<?php
/**
* Gravity Wiz // Gravity Forms // Default Form List to Active Forms
* http://gravitywiz.com/
*/
add_action( 'plugins_loaded', function() {
if( is_callable( array( 'GFForms', 'get_page' ) ) && GFForms::get_page() == 'form_list' ) {
if ( ! isset( $_GET['filter'] ) ) {
wp_redirect( add_query_arg( array( 'filter' => 'active' ) ) );
exit;