PluginProbe
QuadMenu – Mega Menu / 3.3.6
QuadMenu – Mega Menu v3.3.6
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 / AjaxHandler.php

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

59 lines 2.0 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 AjaxHandler
6 {
7
8 public static $instance;
9
10 private function __construct()
11 {
12 add_action('wp_ajax_quadlayers_send_feedback', [self::class, 'send_feedback']);
13 }
14
15 public static function instance()
16 {
17 if (is_null(self::$instance)) {
18 self::$instance = new self();
19 }
20 return self::$instance;
21 }
22
23 /**
24 * Sends feedback from the deactivation survey via AJAX.
25 */
26 public static function send_feedback()
27 {
28 // Check nonce for security
29 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'quadlayers_send_feedback_nonce')) {
30 wp_send_json_error(['message' => __('Invalid nonce.', 'wp-plugin-feedback')], 400);
31 return;
32 }
33
34 // Validate required fields
35 $pluginBasename = sanitize_text_field($_POST['plugin_basename'] ?? '');
36 $feedbackReason = sanitize_text_field($_POST['feedback_reason'] ?? '');
37 $feedbackDetails = sanitize_textarea_field($_POST['feedback_details'] ?? '');
38 $isAnonymous = filter_var($_POST['is_anonymous'] ?? false, FILTER_VALIDATE_BOOLEAN);
39 $hasFeedback = filter_var($_POST['has_feedback'] ?? false, FILTER_VALIDATE_BOOLEAN);
40
41 if (empty($pluginBasename)) {
42 wp_send_json_error(['message' => __('Missing required fields.', 'wp-plugin-feedback')], 400);
43 return;
44 }
45
46 // Create a transient with the hash as the key and set the expiration time to 7 days
47 set_transient('ql_plugin_feedback_' . $pluginBasename, true, 7 * DAY_IN_SECONDS);
48
49 // Send feedback (handling anonymous option)
50 $result = (new Client($pluginBasename))->sendFeedback($feedbackReason, $feedbackDetails, $isAnonymous, $hasFeedback);
51
52 if ($result) {
53 wp_send_json_success(['message' => __('Feedback submitted successfully.', 'wp-plugin-feedback')]);
54 } else {
55 wp_send_json_error(['message' => __('Error sending feedback.', 'wp-plugin-feedback')], 500);
56 }
57 }
58 }
59