Skip to content

Commit 24c21fd

Browse files
authored
gpnf-gv-auto-approve-child-entries-with-parent-entry.php: Added snippet to auto approve nested entries when parent entry is approved.
1 parent 6c471e6 commit 24c21fd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Nested Forms // Auto-appprove Child Entries when its Parent Entry is approved with GravityView
4+
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
5+
*
6+
* Instruction Video: https://www.loom.com/share/a8ab5395a91d437eb1b393d7ba5b50c4
7+
*
8+
* Auto-appprove Child Entries when its Parent Entry is approved with GravityView
9+
*/
10+
add_action( 'gravityview/approve_entries/approved', function( $entry_id ) {
11+
12+
$parent_entry = GFAPI::get_entry( $entry_id );
13+
$parent_form = GFAPI::get_form( $parent_entry['form_id'] );
14+
$nested_entries = array();
15+
16+
foreach ( $parent_form['fields'] as $field ) {
17+
if ( $field instanceof GP_Field_Nested_Form ) {
18+
$_entries = explode( ',', $parent_entry[ $field->id ] );
19+
$nested_entries = array_merge( $nested_entries, $_entries );
20+
}
21+
}
22+
23+
foreach ( $nested_entries as $nested_entry_id ) {
24+
$nested_entry = GFAPI::get_entry( $nested_entry_id );
25+
$nested_entry['is_approved'] = '1';
26+
GFAPI::update_entry( $nested_entry );
27+
}
28+
}, 10, 1 );

0 commit comments

Comments
 (0)