|
3 | 3 | * Gravity Perks // Nested Forms // Set Created By Propery on Child Entries After User Account Registration. |
4 | 4 | * https://gravitywiz.com/documentation/gravity-forms-nested-forms/ |
5 | 5 | * |
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 |
7 | 7 | * with the user id of the account that is created after the parent form is submittted. |
8 | 8 | * |
9 | 9 | * Instructions: |
10 | 10 | * 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/ |
11 | 11 | * 2. Configure the snippet based on inline instructions. |
12 | 12 | */ |
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 | + } |
22 | 19 |
|
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 | + } |
27 | 27 | } |
0 commit comments