WordPress
To integrate Trust Swiftly with Wordpress it can be done in a similar manner as the HTML integration and link. Full plugin coming soon!

Sample WordPress Code

Example code can be copied into functions.php which allows for using a shortcode to generate a verification link [trustlink]
1
add_shortcode('trustlink', 'generate_trustlink');
2
function generate_trustlink(){
3
if ( is_user_logged_in() ) {
4
$user_id=get_current_user_id();
5
$metaData=json_decode(get_user_meta($user_id,'trust_user_data',true));
6
$endpoint = 'https://test.trustswiftly.com/account/api/v1/users/'.$metaData->id.'/verify-url';
7
$user_info = get_userdata($user_id);
8
$user_email = $user_info->user_email;
9
$body = [
10
'email' => $user_email,
11
];
12
13
$body = wp_json_encode($body);
14
15
$options = [
16
'body' => $body,
17
'headers' => [
18
'Authorization' => 'Bearer $api_key',
19
'Content-Type' => 'application/json',
20
],
21
'returntranser' => true,
22
'timeout' => 60,
23
'redirection' => 10,
24
'data_format' => 'body',
25
];
26
27
$response = wp_remote_post($endpoint, $options);
28
$responseData=json_decode($response['body']);
29
return $responseData->short_url;
30
}else{
31
return false;
32
}
33
}
34
add_action('user_register', function ( $user_id ) {
35
$endpoint = 'https://test.trustswiftly.com/account/api/v1/users';
36
$user_info = get_userdata($user_id);
37
$user_email = $user_info->user_email;
38
$body = [
39
'email' => $user_email,
40
];
41
42
$body = wp_json_encode( $body );
43
44
$options = [
45
'body' => $body,
46
'headers' => [
47
'Authorization'=>'Bearer $api_key',
48
'Content-Type' => 'application/json',
49
],
50
'returntranser'=>true,
51
'timeout' => 60,
52
'redirection' => 10,
53
'data_format' => 'body',
54
];
55
56
$response =wp_remote_post( $endpoint, $options );
57
58
add_user_meta( $user_id, 'trust_user_data', $response['body'],true);
59
});
Copied!
Last modified 6mo ago
Copy link