The built-in Webhooks feature provides an easy way to automate notifications based on events logged by the plugin. When enabled, the plugin sends a detailed JSON object to a specified listener URL, containing all relevant information about the logged event.
You can activate Webhook functionality via the Statistics tab under Log Events → Webhook Endpoint URL. This allows you to stay updated on plugin activities and seamlessly integrate with other systems.
{"total":1,"events": [ {"timestamp":"2022-05-01T00:05:00+00:00","type":"useyourdrive_previewed_entry","description":"John Johnson previewed the file UK Festival Market Report.pdf","data": {"entry": {"id":"1-y9psKPDJCycz38c2sN_a3lRoO9S","name":"UK Festival Market Report.pdf","mimetype":"application/pdf","size":"2 MB","icon":"https://...","description":"Festival Insights and the UK Festival Awards are proud to release the UK Festival Market Report 2017.","thumbnail":"https://...","preview_url":"https://...","download_url":"https://...","is_dir":false,"parent_id":"0By3zfuC9ZTdGZCT1pUd0E","parent_path":"/Path/To/Folder" },"account": {"id":"1030123322434145","name":"Your Account name","email":"info@example.com","image":"https://..." } },"user": {"id":"3","user_login":"John Johnson","user_nicename":"john-johnson","user_email":"info@example.com","display_name":"John Johnson" },"page":"https://yoursite.com/page" }, {"timestamp":"2022-05-01T00:05:01+00:00","type":"useyourdrive_deleted_entry", ... } ]}
Example listener (PHP)
// Optional: Prevent replay attacks by ensuring this request has been signed// recently (+/- 5 minutes). The request timestamp is in ms!$time_difference =abs((time()- intval($_SERVER['HTTP_X_WPCP_TIMESTAMP'])) /1000);if ($time_difference >300) {exit('Invalid request timestamp');}// Calculate challenge hash by concatenating the request timestamp with the// webhook secret with a semicolon in between: "timestamp;secret".// Hash is created with SHA256 encoded as hexdecimal lowercase string.$secret ='your_secret';$challenge =hash('sha256', $req_timestamp.';'.$secret);// Calculate request body signature using the challenge hash as secret.// Signature is a HMAC SHA256 hash encoded as hexdecimal lowercase string.$req_raw_body =file_get_contents('php://input');$expected_signature ='sha256='.hash_hmac('sha256', $req_raw_body, $challenge);// Compare expected with received signature.$req_signature = $_SERVER['HTTP_X_WPCP_SIGNATURE'];if ($expected_signature !== $req_signature) {exit('Invalid signature');}// Finally, parse the JSON request body and process the received events.$data =json_decode($req_raw_body, true);