From 2d09bfde4b7ee2b47a9c95d7062b06f5f4a1014c Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 14 Apr 2025 18:37:04 +0530 Subject: [PATCH 1/4] `gw-display-html-field-on-entry-detail.php`: Added a snippet to display HTML field content on Entry Details page. --- .../gw-display-html-field-on-entry-detail.php | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 gravity-forms/gw-display-html-field-on-entry-detail.php diff --git a/gravity-forms/gw-display-html-field-on-entry-detail.php b/gravity-forms/gw-display-html-field-on-entry-detail.php new file mode 100644 index 00000000..b361b032 --- /dev/null +++ b/gravity-forms/gw-display-html-field-on-entry-detail.php @@ -0,0 +1,123 @@ +_args = wp_parse_args( + $args, + array( + 'form_id' => false, + 'field_id' => false, + ) + ); + + add_action( 'init', array( $this, 'init' ) ); + } + + public function init() { + + add_filter( 'gform_entry_post_save', array( $this, 'save_html_field_content' ), 10, 1 ); + add_action( 'gform_entry_detail', array( $this, 'display_html_field_content' ), 10, 2 ); + } + + public function is_applicable_form( $form ) { + $form_id = is_array( $form ) && isset( $form['id'] ) ? $form['id'] : (int) $form; + + return empty( $this->_args['form_id'] ) || (int) $form_id === (int) $this->_args['form_id']; + } + + /** + * Save HTML field content to entry meta. + * + * @param array $entry The entry object. + * @return array + */ + public function save_html_field_content( $entry ) { + + $form = GFAPI::get_form( rgar( $entry, 'form_id' ) ); + + if ( ! $this->is_applicable_form( $form ) ) { + return $entry; + } + + foreach ( $form['fields'] as $field ) { + if ( $field->get_input_type() === 'html' ) { + + // Only process matching field_id if defined. + if ( ! empty( $this->_args['field_id'] ) && (int) $field->id !== (int) $this->_args['field_id'] ) { + continue; + } + + gform_update_meta( $entry['id'], 'html_field_' . $field->id, $field->content ); + } + } + + return $entry; + } + + /** + * Display HTML content on entry detail page. + * + * @param array $form The form object. + * @param array $entry The entry object. + */ + public function display_html_field_content( $form, $entry ) { + + if ( ! $this->is_applicable_form( $form ) ) { + return; + } + + foreach ( $form['fields'] as $field ) { + + if ( $field->get_input_type() !== 'html' ) { + continue; + } + + // Only process matching field_id if defined. + if ( ! empty( $this->_args['field_id'] ) && (int) $field->id !== (int) $this->_args['field_id'] ) { + continue; + } + + $content = gform_get_meta( $entry['id'], 'html_field_' . $field->id ); + + // Process GPPA Live Merge Tags if present. + if ( + method_exists( 'GP_Populate_Anything_Live_Merge_Tags', 'has_live_merge_tag' ) + && GP_Populate_Anything_Live_Merge_Tags::get_instance()->has_live_merge_tag( $content ) + ) { + $content = gp_populate_anything()->live_merge_tags->replace_live_merge_tags_static( $content, $form, $entry ); + } + + // Process shortcodes. + $content = do_shortcode( $content ); + + if ( ! empty( $content ) ) { + printf( + '

%s

%s

', + esc_html( $field->label ), + wp_kses_post( $content ) + ); + } + } + } +} + +# Configuration +new GW_Display_HTML_Field_Entry_Detail( array( + 'form_id' => 846, // Replace with your form ID or leave false for all. + 'field_id' => 4, // Replace with your HTML field ID or leave false to process all HTML fields. +) ); From 24a9e2677c7663ed81fdb23a8c6918a570246a63 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 14 Apr 2025 18:42:54 +0530 Subject: [PATCH 2/4] `gw-display-html-field-on-entry-detail.php`: Added a snippet to display HTML field content on Entry Details page. --- gravity-forms/gw-display-html-field-on-entry-detail.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gravity-forms/gw-display-html-field-on-entry-detail.php b/gravity-forms/gw-display-html-field-on-entry-detail.php index b361b032..01582941 100644 --- a/gravity-forms/gw-display-html-field-on-entry-detail.php +++ b/gravity-forms/gw-display-html-field-on-entry-detail.php @@ -2,6 +2,8 @@ /** * Gravity Wiz // Gravity Forms // Display HTML Field on Entry Details * + * Instruction Video: https://www.loom.com/share/fa4b49240b6447c7839392af69476bf2 + * * Save and display HTML field content (including Live Merge Tags and shortcodes) in the entry detail view. * Useful for retaining dynamic HTML field output as it appeared when the entry was submitted. * From 576d84923002a9b8baa6b7ddefa77095ca86507d Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 14 Apr 2025 22:19:26 +0530 Subject: [PATCH 3/4] `gw-display-html-field-on-entry-detail.php`: Added a snippet to display HTML field content on Entry Details page. --- gravity-forms/gw-display-html-field-on-entry-detail.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gravity-forms/gw-display-html-field-on-entry-detail.php b/gravity-forms/gw-display-html-field-on-entry-detail.php index 01582941..d6a5cd87 100644 --- a/gravity-forms/gw-display-html-field-on-entry-detail.php +++ b/gravity-forms/gw-display-html-field-on-entry-detail.php @@ -104,6 +104,9 @@ public function display_html_field_content( $form, $entry ) { $content = gp_populate_anything()->live_merge_tags->replace_live_merge_tags_static( $content, $form, $entry ); } + // Process static merge tags. + $content = GFCommon::replace_variables( $content, $form, $entry ); + // Process shortcodes. $content = do_shortcode( $content ); From 50ff4df38d6c0aa91aeefc3496251603d6434684 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 14 Apr 2025 22:52:16 +0530 Subject: [PATCH 4/4] `gw-display-html-field-on-entry-detail.php`: Added a snippet to display HTML field content on Entry Details page. --- .../gw-display-html-field-on-entry-detail.php | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/gravity-forms/gw-display-html-field-on-entry-detail.php b/gravity-forms/gw-display-html-field-on-entry-detail.php index d6a5cd87..e8207845 100644 --- a/gravity-forms/gw-display-html-field-on-entry-detail.php +++ b/gravity-forms/gw-display-html-field-on-entry-detail.php @@ -31,25 +31,38 @@ public function __construct( $args = array() ) { } public function init() { - add_filter( 'gform_entry_post_save', array( $this, 'save_html_field_content' ), 10, 1 ); - add_action( 'gform_entry_detail', array( $this, 'display_html_field_content' ), 10, 2 ); + add_action( 'gform_entry_detail', array( $this, 'display_html_field_content_entry_detail' ), 10, 2 ); + add_filter( 'gform_get_input_value', array( $this, 'display_html_field_content_entry_list' ), 10, 4 ); } - public function is_applicable_form( $form ) { + private function is_applicable_form( $form ) { $form_id = is_array( $form ) && isset( $form['id'] ) ? $form['id'] : (int) $form; - return empty( $this->_args['form_id'] ) || (int) $form_id === (int) $this->_args['form_id']; } - /** - * Save HTML field content to entry meta. - * - * @param array $entry The entry object. - * @return array - */ - public function save_html_field_content( $entry ) { + private function is_applicable_field( $field ) { + return $field->get_input_type() === 'html' && + ( empty( $this->_args['field_id'] ) || (int) $field->id === (int) $this->_args['field_id'] ); + } + + private function process_html_content( $content, $form, $entry ) { + // Process Live Merge Tags. + if ( + method_exists( 'GP_Populate_Anything_Live_Merge_Tags', 'has_live_merge_tag' ) && + GP_Populate_Anything_Live_Merge_Tags::get_instance()->has_live_merge_tag( $content ) + ) { + $content = gp_populate_anything()->live_merge_tags->replace_live_merge_tags_static( $content, $form, $entry ); + } + + // Replace merge tags and shortcodes. + $content = GFCommon::replace_variables( $content, $form, $entry ); + $content = do_shortcode( $content ); + return ! empty( $content ) ? wp_kses_post( $content ) : ''; + } + + public function save_html_field_content( $entry ) { $form = GFAPI::get_form( rgar( $entry, 'form_id' ) ); if ( ! $this->is_applicable_form( $form ) ) { @@ -57,13 +70,7 @@ public function save_html_field_content( $entry ) { } foreach ( $form['fields'] as $field ) { - if ( $field->get_input_type() === 'html' ) { - - // Only process matching field_id if defined. - if ( ! empty( $this->_args['field_id'] ) && (int) $field->id !== (int) $this->_args['field_id'] ) { - continue; - } - + if ( $this->is_applicable_field( $field ) ) { gform_update_meta( $entry['id'], 'html_field_' . $field->id, $field->content ); } } @@ -71,53 +78,46 @@ public function save_html_field_content( $entry ) { return $entry; } - /** - * Display HTML content on entry detail page. - * - * @param array $form The form object. - * @param array $entry The entry object. - */ - public function display_html_field_content( $form, $entry ) { - + public function display_html_field_content_entry_detail( $form, $entry ) { if ( ! $this->is_applicable_form( $form ) ) { return; } foreach ( $form['fields'] as $field ) { - - if ( $field->get_input_type() !== 'html' ) { - continue; - } - - // Only process matching field_id if defined. - if ( ! empty( $this->_args['field_id'] ) && (int) $field->id !== (int) $this->_args['field_id'] ) { - continue; + if ( $this->is_applicable_field( $field ) ) { + $content = gform_get_meta( $entry['id'], 'html_field_' . $field->id ); + $content = $this->process_html_content( $content, $form, $entry ); + + if ( $content ) { + printf( + '

%s

%s

', + esc_html( $field->label ), + $content + ); + } } + } + } - $content = gform_get_meta( $entry['id'], 'html_field_' . $field->id ); + public function display_html_field_content_entry_list( $value, $entry, $field, $input_id ) { + static $is_running = false; - // Process GPPA Live Merge Tags if present. - if ( - method_exists( 'GP_Populate_Anything_Live_Merge_Tags', 'has_live_merge_tag' ) - && GP_Populate_Anything_Live_Merge_Tags::get_instance()->has_live_merge_tag( $content ) - ) { - $content = gp_populate_anything()->live_merge_tags->replace_live_merge_tags_static( $content, $form, $entry ); - } + if ( $is_running || rgget( 'page' ) !== 'gf_entries' || ! $this->is_applicable_field( $field ) ) { + return $value; + } - // Process static merge tags. - $content = GFCommon::replace_variables( $content, $form, $entry ); + $form = GFAPI::get_form( $field->formId ); + if ( ! $this->is_applicable_form( $form ) ) { + return $value; + } - // Process shortcodes. - $content = do_shortcode( $content ); + $is_running = true; + $entry = GFAPI::get_entry( $entry['id'] ); + $content = gform_get_meta( $entry['id'], 'html_field_' . $field->id ); + $content = $this->process_html_content( $content, $form, $entry ); + $is_running = false; - if ( ! empty( $content ) ) { - printf( - '

%s

%s

', - esc_html( $field->label ), - wp_kses_post( $content ) - ); - } - } + return $content ?: $value; } }