-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook-handler.php
More file actions
61 lines (53 loc) · 1.73 KB
/
webhook-handler.php
File metadata and controls
61 lines (53 loc) · 1.73 KB
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
<?php
// Include WordPress functionality
define('WP_USE_THEMES', false);
require_once('../../../wp-load.php'); // Adjust the path as necessary
// Get the raw POST data
$rawPostData = file_get_contents('php://input');
// Decode the JSON data
$data = json_decode($rawPostData, true);
if (json_last_error() !== JSON_ERROR_NONE) {
error_log('Invalid JSON data received.');
http_response_code(400);
echo 'Invalid JSON data.';
exit;
}
// Check if 'values' and 'sessionId' are present
if (isset($data['values']) && isset($data['sessionId'])) {
$values = $data['values'];
$session_id = sanitize_text_field($data['sessionId']);
// Store values in the database associated with the session ID
global $wpdb;
$table_name = $wpdb->prefix . 'sharering_link_data';
// Insert the values into the database
$json_values = wp_json_encode($values);
$inserted = $wpdb->insert(
$table_name,
array(
'session_id' => $session_id,
'user_data' => $json_values,
'time' => current_time('mysql'),
),
array(
'%s',
'%s',
'%s',
)
);
if ($inserted === false) {
error_log('Failed to insert data into the database.');
http_response_code(500);
echo 'Failed to save data.';
exit;
} else {
error_log('Data saved successfully for session ID: ' . $session_id);
http_response_code(200);
echo 'Data saved successfully.';
exit;
}
} else {
error_log('No values or session ID found in the webhook data.');
http_response_code(400);
echo 'No values or session ID found in the data.';
exit;
}