PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / vendor / franmastromarino / wp-plugin-feedback / src / Request.php

Request.php in QuadMenu – Mega Menu 3.3.8, at vendor/franmastromarino/wp-plugin-feedback/src/Request.php

53 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace QuadLayers\PluginFeedback;
4
5 class Request
6 {
7 /**
8 * Sends the feedback data to the remote server.
9 *
10 * @param array $data The collected data.
11 * @return bool True if the data was sent successfully, False otherwise.
12 */
13 public function send(array $data): bool
14 {
15
16 $body = json_encode($data);
17
18 // Create unique hash to prevent duplicate submissions
19 $hash = md5($body);
20
21 if (get_transient('ql_plugin_feedback_' . $hash)) {
22 return true;
23 }
24
25 // Create a transient with the hash as the key and set the expiration time to 7 days
26 set_transient('ql_plugin_feedback_' . $hash, true, 30 * DAY_IN_SECONDS);
27
28 $response = wp_remote_post(
29 'https://feedback.quadlayers.com/',
30 array(
31 'body' => $body,
32 'headers' => array(
33 'Content-Type' => 'application/json',
34 ),
35 'headers' => [
36 'Content-Type' => 'application/json',
37 'Content-Length' => strlen($body),
38 'User-Agent' => 'WordPress/QuadLayers', // Set a custom User-Agent
39 ],
40 )
41 );
42
43 if (is_wp_error($response)) {
44 return false;
45 }
46
47 $statusCode = wp_remote_retrieve_response_code($response);
48
49 // Return true if the status code is 200 (OK)
50 return $statusCode === 200;
51 }
52 }
53