Skip to content

Commit 905f889

Browse files
authored
gpnf-set-created-by-property-on-child-entries-after-user-registration.php: Added new snippet for GP Nested Forms that sets the created by property on the child entries after user account is created.
1 parent f8e48ac commit 905f889

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Nested Forms // Set Created By Propery on Child Entries After User Account Registration.
4+
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
5+
*
6+
* Set the created by property of the child entries that is embedded on a user registration form
7+
* with the user id of the account that is created after the parent form is submittted.
8+
*
9+
* Instructions:
10+
* 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
11+
* 2. Configure the snippet based on inline instructions.
12+
*/
13+
add_action( 'gform_user_registered', 'add_created_by_property', 10, 4 );
14+
function add_created_by_property( $user_id, $feed, $entry, $user_pass ) {
15+
// Update '123' with the Id of the form.
16+
if ( $entry['form_id'] !== '123' ) {
17+
return;
18+
}
19+
20+
$parent_entry = new GPNF_Entry( $entry );
21+
$child_entries = $parent_entry->get_child_entries();
22+
23+
foreach ( $child_entries as $child_entry ) {
24+
GFAPI::update_entry_property( $child_entry['id'], 'created_by', $user_id );
25+
$child_entry['created_by'] = $user_id;
26+
}
27+
}

0 commit comments

Comments
 (0)