Skip to content

Commit f572929

Browse files
authored
gpnf-child-entry-id-modifier.php: Added new snippet to include child entry ID in {all_fields} and Nested Form field merge tag output when the :gpnf_child_entry_id modifier is applied.
1 parent 859e55f commit f572929

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Nested Forms // Display Child Entry ID in Merge Tag Output
4+
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
5+
*
6+
* Instructions
7+
*
8+
* 1. Add the `:gpnf_child_entry_id` modifier to any {all_fields} or Nested Form field merge tag.
9+
*
10+
* Result
11+
*
12+
* ![Screenshot of {all_fields} and Nested Form field merge tag output with modifier applied.](https://gwiz.io/3DqJjYa)
13+
*/
14+
add_filter( 'gpnf_all_entries_nested_entry_markup', function( $markup, $field, $nested_form, $entry, $args ) {
15+
16+
$modifiers = rgar( $args, 'modifiers' );
17+
if ( strpos( $modifiers, 'gpnf_child_entry_id' ) === false ) {
18+
return $markup;
19+
}
20+
21+
$dom = new DOMDocument();
22+
$dom->loadHTML( $markup );
23+
24+
$first_row = $dom->getElementsByTagName( 'tr' )->item( 1 );
25+
$header_row = clone $first_row;
26+
$value_row = clone $dom->getElementsByTagName( 'tr' )->item( 2 );
27+
28+
$header_row->getElementsByTagName( 'strong' )->item( 0 )->nodeValue = 'Entry ID';
29+
$value_row->getElementsByTagName( 'font' )->item( 0 )->nodeValue = $entry['id'];
30+
31+
$table = $dom->getElementsByTagName( 'table' )->item( 1 );
32+
$table->insertBefore( $header_row, $first_row );
33+
$table->insertBefore( $value_row, $first_row );
34+
35+
$markup = $dom->saveHTML();
36+
37+
return $markup;
38+
}, 10, 5 );

0 commit comments

Comments
 (0)