-
Notifications
You must be signed in to change notification settings - Fork 92
gw-display-html-field-on-entry-detail.php
: Added a snippet to display HTML field content on Entry Details page.
#1074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saifsultanc
merged 5 commits into
master
from
saif/add/81943-display-html-field-entry-detail
Jun 27, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2d09bfd
`gw-display-html-field-on-entry-detail.php`: Added a snippet to displ…
saifsultanc 24a9e26
`gw-display-html-field-on-entry-detail.php`: Added a snippet to displ…
saifsultanc 576d849
`gw-display-html-field-on-entry-detail.php`: Added a snippet to displ…
saifsultanc 50ff4df
`gw-display-html-field-on-entry-detail.php`: Added a snippet to displ…
saifsultanc bddad13
`gw-display-html-field-on-entry-detail.php`: Added a snippet to displ…
saifsultanc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
gravity-forms/gw-display-html-field-on-entry-detail.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
/** | ||
* 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. | ||
* | ||
* Plugin Name: Display HTML Field on Entry Details | ||
* Plugin URI: http://gravitywiz.com/ | ||
* Description: Save and display HTML field content (including Live Merge Tags and shortcodes) in the entry detail view. | ||
* Author: Gravity Wiz | ||
* Version: 0.1 | ||
* Author URI: http://gravitywiz.com | ||
*/ | ||
class GW_Display_HTML_Field_Entry_Detail { | ||
|
||
private $_args = array(); | ||
|
||
public function __construct( $args = array() ) { | ||
$this->_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( | ||
'<h4>%s</h4><div>%s</div><hr>', | ||
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. | ||
) ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.