Skip to content

Commit 7606302

Browse files
sbassahsaifsultanc
authored andcommitted
gpnf-set-created-by-property-on-child-entries-after-user-registration.php: Added new snippet.
~ Fix.
1 parent 23bf3d1 commit 7606302

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

gp-nested-forms/gpnf-set-created-by-property-on-child-entries-after-user-registration.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
* Gravity Perks // Nested Forms // Set Created By Propery on Child Entries After User Account Registration.
44
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
55
*
6-
* Set the created by property of the child entries that is embedded on a user registration form
6+
* Set the created by property of the child entries that is embedded on a user registration form
77
* with the user id of the account that is created after the parent form is submittted.
88
*
99
* Instructions:
1010
* 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
1111
* 2. Configure the snippet based on inline instructions.
1212
*/
13-
add_action( 'gform_user_registered', 'add_custom_user_meta', 10, 4 );
14-
function add_custom_user_meta( $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();
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+
}
2219

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-
}
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+
}
2727
}

0 commit comments

Comments
 (0)