-
Notifications
You must be signed in to change notification settings - Fork 91
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
base: master
Are you sure you want to change the base?
gw-display-html-field-on-entry-detail.php
: Added a snippet to display HTML field content on Entry Details page.
#1074
Conversation
…ay HTML field content on Entry Details page.
…ay HTML field content on Entry Details page.
WalkthroughA new PHP class, Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant GF as Gravity Forms Engine
participant GW as GW_Display_HTML_Field_Entry_Detail
User->>GF: Submit form entry
GF->>GW: Trigger save_html_field_content hook
GW->>GW: Validate form ID and process HTML fields
GW->>GF: Save HTML field content to entry metadata
sequenceDiagram
participant User
participant GF as Gravity Forms Engine
participant GW as GW_Display_HTML_Field_Entry_Detail
User->>GF: Request entry detail view
GF->>GW: Trigger display_html_field_content hook
GW->>GW: Retrieve and process saved HTML content<br/>(apply merge tags & shortcodes)
GW->>GF: Return formatted HTML content
GF->>User: Render entry detail page with HTML content
Suggested reviewers
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
gravity-forms/gw-display-html-field-on-entry-detail.php (1)
80-118
: Secure processing and display of HTML content.The method properly:
- Retrieves saved content
- Conditionally processes Live Merge Tags
- Processes shortcodes
- Securely outputs content with proper escaping via
esc_html()
andwp_kses_post()
Consider making the HTML output structure more customizable for different display requirements.
- printf( - '<h4>%s</h4><div>%s</div><hr>', - esc_html( $field->label ), - wp_kses_post( $content ) - ); + // Add a filter to allow customization of the HTML output structure + $output_template = apply_filters( + 'gw_display_html_field_template', + '<h4>%1$s</h4><div class="gw-html-field-content">%2$s</div><hr>', + $field, + $entry + ); + printf( + $output_template, + esc_html( $field->label ), + wp_kses_post( $content ) + );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gravity-forms/gw-display-html-field-on-entry-detail.php
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
gravity-forms/gw-display-html-field-on-entry-detail.php (1)
gravity-forms/gw-calculated-shipping.php (1)
field
(91-117)
🔇 Additional comments (6)
gravity-forms/gw-display-html-field-on-entry-detail.php (6)
1-16
: Well-structured plugin header with clear documentation.The header includes a descriptive title, purpose explanation, and instruction video link, which are excellent for helping users understand the snippet's functionality.
19-31
: Clean implementation of constructor with proper default values.The constructor properly uses
wp_parse_args()
to merge user arguments with defaults, providing a flexible API for customization.
33-37
: Good use of WordPress hooks for integration with Gravity Forms.The initialization method properly hooks into the Gravity Forms lifecycle at appropriate points - after entry save and during entry detail display.
39-43
: Appropriate form validation logic.The helper method handles both array and integer input formats, with proper type casting for comparison.
51-72
: Safe implementation of HTML field content saving.The method correctly validates the form, iterates through fields, and saves HTML content to entry metadata. It properly uses Gravity Forms API functions and applies appropriate conditions.
121-125
: Update hardcoded IDs in the configuration.The snippet includes specific form and field IDs in the instantiation that need to be updated for your specific use case.
Make sure to replace the hardcoded IDs (form_id: 846, field_id: 4) with your actual form and field IDs before using this snippet in production. Alternatively, you could set these to
false
to process HTML fields across all forms: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. + 'form_id' => false, // Set your specific form ID or leave as false for all forms + 'field_id' => false, // Set your specific HTML field ID or leave as false for all HTML fields ) );
@saifsultanc Just a note this should support the Entry List as well. 🙏 |
…ay HTML field content on Entry Details page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
gravity-forms/gw-display-html-field-on-entry-detail.php (3)
35-36
: Consider extending support to the Entry List page.
At present, the snippet only hooks intogform_entry_detail
. Per the PR discussion, you may also wish to display the HTML field on the Entry List. Gravity Forms offers filters (e.g.,gform_entries_list_columns
orgform_entries_list_column_value
) for customizing column output in listing views.Here's a starting point if you decide to pursue this:
add_action( 'gform_entry_detail', array( $this, 'display_html_field_content' ), 10, 2 ); +// Consider hooking into the entries list to display HTML field content in the listing view as well. +add_filter( 'gform_entries_list_column_value', array( $this, 'display_html_field_in_list' ), 10, 4 );
100-105
: Check for the class existence before invoking methods.
method_exists( 'GP_Populate_Anything_Live_Merge_Tags', 'has_live_merge_tag' )
will returnfalse
if the class does not exist, but referencingGP_Populate_Anything_Live_Merge_Tags::get_instance()
could still cause an error if the class is not loaded. Consider adding aclass_exists()
check for complete safety.
113-118
: Use a different heading level or remove the<hr>
for a cleaner layout.
Using<h4>
and<hr>
for each field might be visually cluttered on certain admin pages. If multiple HTML fields exist, consider a simpler heading or a refined stylistic approach.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gravity-forms/gw-display-html-field-on-entry-detail.php
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
gravity-forms/gw-display-html-field-on-entry-detail.php (1)
gravity-forms/gw-calculated-shipping.php (1)
field
(91-117)
🔇 Additional comments (1)
gravity-forms/gw-display-html-field-on-entry-detail.php (1)
124-129
: Configuration appears correct.
Current instantiation targets form ID 846 and field ID 4. This is fine for a single form and field setup. If you want to process multiple fields or multiple forms, consider leaving ‘field_id’ or ‘form_id’ asfalse
.
…ay HTML field content on Entry Details page.
Yup. Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
gravity-forms/gw-display-html-field-on-entry-detail.php (1)
66-72
:⚠️ Potential issueValidate
$form
before referencing$form['fields']
.
IfGFAPI::get_form()
returnsfalse
,$form
will not be an array and$form['fields']
will trigger an error. This repeats a concern raised in previous reviews. Consider adding a guard clause to prevent potential PHP notices or fatal errors.$form = GFAPI::get_form( rgar( $entry, 'form_id' ) ); +if ( ! is_array( $form ) ) { + return $entry; +} if ( ! $this->is_applicable_form( $form ) ) { return $entry; }
🧹 Nitpick comments (1)
gravity-forms/gw-display-html-field-on-entry-detail.php (1)
102-121
: Consider unifying or documenting your display logic for Entry Detail and Entry List.
Both methods share similar steps (fetch and process content). Creating a reusable helper or adding docblocks could improve maintainability and clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gravity-forms/gw-display-html-field-on-entry-detail.php
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
gravity-forms/gw-display-html-field-on-entry-detail.php (1)
gravity-forms/gw-calculated-shipping.php (1)
field
(91-117)
🔇 Additional comments (2)
gravity-forms/gw-display-html-field-on-entry-detail.php (2)
81-100
: Entry Detail Rendering Logic Looks Good.
This section correctly retrieves the saved HTML content for each applicable field and processes it for display. Great job ensuring that only valid HTML fields are processed.
124-129
: Configuration Instantiation is Straightforward!
Everything looks good here. This is a clear and minimal setup for specifying the form and field IDs.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2901917754/81943/
Summary
Allow HTML field content to displayed on Entry Details page.
https://www.loom.com/share/fa4b49240b6447c7839392af69476bf2