PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.0
3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.6.1 All 66 releases
logtivity / Services / Logtivity_Log_API.php

Logtivity_Log_API.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.0, at Services/Logtivity_Log_API.php

78 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Log_API
4 {
5 public $logtivityStoreLogEndpoint = 'https://api.logtivity.io/logs/store';
6
7 /**
8 * Option class to access the plugin settings
9 *
10 * @var object
11 */
12 protected $options;
13
14 public function __construct()
15 {
16 $this->options = new Logtivity_Options;
17 }
18
19 /**
20 * Get the endpoint we post to with the log data to store
21 *
22 * @return string
23 */
24 public function getStoreUrl()
25 {
26 if (defined('Logtivity_Store_Endpoint')) {
27 return Logtivity_Store_Endpoint;
28 }
29
30 return $this->logtivityStoreLogEndpoint;
31 }
32
33 /**
34 * Make a request to the Logtivity API
35 *
36 * @param string $url
37 * @param array $body
38 * @param string $method
39 * @return mixed $response
40 */
41 public function makeRequest($url, $body, $method = 'POST')
42 {
43 $api_key = logtivity_get_api_key();
44
45 if (!$api_key)
46 {
47 return;
48 }
49
50 $shouldLogLatestResponse = $this->options->shouldLogLatestResponse();
51
52 $response = wp_remote_post( $url, [
53 'method' => $method,
54 'timeout' => ( $shouldLogLatestResponse ? 45 : 0.01),
55 'blocking' => ( $shouldLogLatestResponse ? true : false),
56 'redirection' => 5,
57 'httpversion' => '1.0',
58 'headers' => array(),
59 'body' => array_merge(['api_key' => $api_key], $body),
60 'cookies' => array()
61 ]);
62
63 $response = wp_remote_retrieve_body($response);
64
65 if ($shouldLogLatestResponse) {
66
67 $this->options->update([
68 'logtivity_latest_response' => [
69 'date' => date("Y-m-d H:i:s"),
70 'response' => print_r($response, true)
71 ]
72 ]);
73
74 }
75
76 return $response;
77 }
78 }