From 2861232ac1a4d34a2d4c637241e0a0fdb8299de5 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Fri, 1 Nov 2024 01:12:57 +0530 Subject: [PATCH 1/2] `gw-all-fields-template.php`: Added `:updated` modifier for All Fields Template to display only the updated fields. --- gravity-forms/gw-all-fields-template.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/gravity-forms/gw-all-fields-template.php b/gravity-forms/gw-all-fields-template.php index 33a6249ec..0e1ee063e 100644 --- a/gravity-forms/gw-all-fields-template.php +++ b/gravity-forms/gw-all-fields-template.php @@ -8,7 +8,7 @@ * Plugin URI: https://gravitywiz.com/gravity-forms-all-fields-template/ * Description: Modify the {all_fields} merge tag output via a template file. * Author: Gravity Wiz - * Version: 0.10 + * Version: 0.11 * Author URI: http://gravitywiz.com * * Usage: @@ -60,11 +60,18 @@ * `{all_fields:exclude[5]}` * `{all_fields:exclude[5,6]}` * `{all_fields:exclude[5],include[3,4]}` + * + * - **`:updated`** + * + * Only show fields that were most recently updated. + * + * `{all_fields:updated}` * */ class GW_All_Fields_Template { private static $instance = null; + private $original_entry = array(); public static function get_instance() { if ( self::$instance == null ) { @@ -83,7 +90,7 @@ public function init() { add_filter( 'gform_pre_replace_merge_tags', array( $this, 'replace_merge_tags' ), 9, 7 ); add_filter( 'gform_merge_tag_filter', array( $this, 'all_fields_extra_options' ), 21, 6 ); - + add_action( 'gform_post_update_entry', array( $this, 'save_original_entry' ), 10, 2 ); } /** @@ -111,7 +118,7 @@ public function all_fields_extra_options( $value, $merge_tag, $modifiers, $field } $modifiers = $this->parse_modifiers( $modifiers ); - $whitelist = array( 'filter', 'include', 'exclude', 'nopricingfields' ); + $whitelist = array( 'filter', 'include', 'exclude', 'nopricingfields', 'updated' ); $context = rgar( $modifiers, 'context', false ); foreach ( $modifiers as $modifier => $mod_values ) { @@ -255,6 +262,12 @@ public function all_fields_extra_options( $value, $merge_tag, $modifiers, $field } } break; + case 'updated': + // If current value matches original value, it was not changed so we skip it. + if ( $this->original_entry[ $field['id'] ] == $value ) { + $value = false; + } + break; } } @@ -265,6 +278,10 @@ public function all_fields_extra_options( $value, $merge_tag, $modifiers, $field return $value; } + public function save_original_entry( $entry, $original_entry ) { + $this->original_entry = $original_entry; + } + public function replace_merge_tags( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) { $matches = array(); From c27417252a298effccfbc778afdbb730ff66fe50 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Fri, 1 Nov 2024 01:18:51 +0530 Subject: [PATCH 2/2] `gw-all-fields-template.php`: Added `:updated` modifier for All Fields Template to display only the updated fields. --- gravity-forms/gw-all-fields-template.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity-forms/gw-all-fields-template.php b/gravity-forms/gw-all-fields-template.php index 0e1ee063e..a0c97682c 100644 --- a/gravity-forms/gw-all-fields-template.php +++ b/gravity-forms/gw-all-fields-template.php @@ -60,7 +60,7 @@ * `{all_fields:exclude[5]}` * `{all_fields:exclude[5,6]}` * `{all_fields:exclude[5],include[3,4]}` - * + * * - **`:updated`** * * Only show fields that were most recently updated. @@ -71,7 +71,7 @@ class GW_All_Fields_Template { private static $instance = null; - private $original_entry = array(); + private $original_entry = array(); public static function get_instance() { if ( self::$instance == null ) {