Created
August 30, 2023 08:32
-
-
Save KevinGraham-com/21606cbfeafbd7e92de886ad611012cd to your computer and use it in GitHub Desktop.
WHMCS - Sync User and Client Email on Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('WHMCS')) { | |
exit('This file cannot be accessed directly'); | |
} | |
add_hook('UserEdit', 5, 'sync_user_to_client'); | |
add_hook('ClientEdit', 5, 'sync_client_to_user'); | |
function sync_user_to_client($vars) { | |
// gather the data | |
$newmail=$vars['email']; | |
$oldmail=$vars['olddata']['email']; | |
// check to see if email address updated | |
if ($newmail != $oldmail) { | |
//find the client account | |
$command0 = 'UpdateClient'; | |
$postData0 = array( | |
'clientemail' => $oldmail, | |
'email' => $newmail, | |
); | |
$results0 = localAPI($command0, $postData0); | |
if ($results0['result']=="success") { | |
logActivity('Sync User to Client Update - Client ID ' . $results0['clientid'] . ' updated email from (' . $oldmail . ') to ('.$newmail.')'); | |
} | |
} | |
} | |
function sync_client_to_user($vars) { | |
// gather the data | |
$newmail=$vars['email']; | |
$oldmail=$vars['olddata']['email']; | |
// check to see if email address updated | |
if ($newmail != $oldmail) { | |
// find the user account | |
$command = 'GetUsers'; | |
$postData = array( | |
'search' => $oldmail, | |
); | |
$results = localAPI($command, $postData); | |
$command2 = 'UpdateUser'; | |
$postData2 = array( | |
'user_id' => $results['users'][0]['id'], | |
'email' => $newmail, | |
); | |
$results2 = localAPI($command2, $postData2); | |
if ($results2['result']=="success") { | |
logActivity('Sync Client to User Update - User ID ' . $results['users'][0]['id'] . ' updated email from (' . $oldmail . ') to ('.$newmail.')'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment