-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooks.php
105 lines (88 loc) · 3.32 KB
/
hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
add_action( 'profile_update', 'user_profile_update', 10, 2 );
function user_profile_update( $user_id, $old_user_data ) {
// Retrieve api key
$options = get_option('ossn_options');
$api_key = $options['ossn_field_api_key'];
// Retrieve updated WP user email
$user = get_user_by('id', $user_id);
$new_email = $user->user_email;
$username = $old_user_data->user_login;
//get the ossn user
$ossn_user = get_ossn_user($api_key, $username);
//update the ossn user email
$update_ossn_user_response = update_ossn_user_email($api_key, $ossn_user, $new_email);
if ($update_ossn_user_response->code != '100') {
global $wpdb;
$sql = "UPDATE hth_users SET user_email='{$old_user_data->user_email}' WHERE ID={$user_id}";
$results = $wpdb->get_results($sql);
$error_message = $update_ossn_user_response->message;
?>
<script type="text/javascript">
jQuery(window).load(function() {
jQuery('#mepr-account-welcome-message').nextAll('.mp_wrapper').first().children('.mepr_updated').remove();
jQuery('#mepr-account-welcome-message').remove();
});
</script>
<div class="mepr_error" id="mepr_jump">
<ul>
<li>
<strong>Error</strong>: There was an error updating your email address! Please contact the <a href="mailto:haden@howtohockey.com?subject=There%20was%20an%20error%20while%20updating%20my%20email%20address&body=The%20error%20message%20was%3A%20<?=$error_message?>">system administrator</a>.
<?php
if (!empty($update_ossn_user_response->message)) {
?>
<br />
<small style="font-size: 10px;">Error message: <?=$update_ossn_user_response->message?></small>
<?php
}
?>
</li>
</ul>
</div>
<?php
}
}
function get_ossn_user($api_key, $username) {
// get ossn user data based on email
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://thepond.howtohockey.com/squad/api/v1.0/user_details?api_key_token={$api_key}&username={$username}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
));
$response = curl_exec($curl);
curl_close($curl);
$ossn_user = json_decode($response);
return $ossn_user->payload;
}
function update_ossn_user_email($api_key, $user, $new_email) {
if (empty($user) || empty($api_key) || empty($new_email)) {
return false;
}
// Update the ossn email address for that user
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://thepond.howtohockey.com/squad/api/v1.0/user_update_email",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array(
'api_key_token' => $api_key,
'guid' => $user->guid,
'new_email' => $new_email)
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response);
return $response;
}
?>