Skip to content

Commit bbb2c91

Browse files
committed
functions added to link gforms entries from one account to another
1 parent 8701605 commit bbb2c91

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

plugins/cc-global-network/includes/gravityforms-interaction.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,53 @@ function ccgn_entries_referring_to_user (
432432
)
433433
);
434434
}
435-
435+
/*
436+
This two function were made in a special case
437+
If there is an user that has a new account and wants to link his/her old entries to the new account
438+
It should be used with wp-cli (eval command)
439+
Be careful with this
440+
*/
441+
function ccgn_link_refering_entries_to_new_user(
442+
$user_id,
443+
$form_name,
444+
$field_id,
445+
$new_user_id
446+
) {
447+
$entries = ccgn_entries_referring_to_user($user_id,$form_name,$field_id);
448+
if (!empty($entries)) {
449+
foreach ($entries as $entry) {
450+
$entry_id = $entry['id'];
451+
$change_user_result = GFAPI::update_entry_field($entry_id, $field_id, $new_user_id);
452+
if ($change_user_result) {
453+
echo 'Entry id: '.$entry_id.' changed from user ID: '.$user_id.' to '.$new_user_id."\n";
454+
}
455+
}
456+
}
457+
}
458+
function ccgn_link_entries_by_user_to_new_user(
459+
$user_id,
460+
$form_name,
461+
$new_user_id
462+
) {
463+
$entries = ccgn_entries_created_by_user($user_id,$form_name);
464+
if (!empty($entries)) {
465+
foreach($entries as $entry) {
466+
global $wpdb;
467+
$entry_id = $entry['id'];
468+
$entry_table_name = $wpdb->prefix.'gf_entry';
469+
/*
470+
I have to make it with an SQL query because the GForms function does not change the created_by value
471+
*/
472+
$result = $wpdb->update($entry_table_name, array('created_by' => $new_user_id),array('id' => $entry_id),array('%d'),array('%d'));
473+
if (false === $result) {
474+
echo 'ERROR updating entry id: ' . $entry_id . "\n";
475+
echo '<pre>'; print_r($wpdb->show_errors()); echo '</pre>';
476+
} else {
477+
echo 'Entry id: ' . $entry_id . ' changed from user ID: ' . $user_id . ' to ' . $new_user_id . "\n";
478+
}
479+
}
480+
}
481+
}
436482

437483
////////////////////////////////////////////////////////////////////////////////
438484
// Vouching form

0 commit comments

Comments
 (0)