Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpnf-set-created-by-property-on-child-entries-after-user-registration.php: Added snippet for GP Nested Forms that sets the created by property on the child entries after user account is created. #900

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Gravity Perks // Nested Forms // Set Created By Propery on Child Entries After User Account Registration.
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
*
* Set the created by property of the child entries that is embedded on a user registration form
* with the user id of the account that is created after the parent form is submittted.
*
* Instructions:
* 1. Install per https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
* 2. Configure the snippet based on inline instructions.
*/
add_action( 'gform_user_registered', 'add_created_by_property', 10, 4 );
function add_created_by_property( $user_id, $feed, $entry, $user_pass ) {
// Update '123' with the Id of the form.
if ( $entry['form_id'] !== '123' ) {
return;
}

$parent_entry = new GPNF_Entry( $entry );
$child_entries = $parent_entry->get_child_entries();

foreach ( $child_entries as $child_entry ) {
GFAPI::update_entry_property( $child_entry['id'], 'created_by', $user_id );
$child_entry['created_by'] = $user_id;
}
}
Loading