PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / deactivation-feedback / class-psm-dfr-ajax.php

class-psm-dfr-ajax.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.4, at deactivation-feedback/class-psm-dfr-ajax.php

83 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AJAX handler.
4 *
5 * @package PSM_DFR
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class PSM_DFR_Ajax {
13
14 /**
15 * Init.
16 *
17 * @return void
18 */
19 public static function init() {
20 add_action( 'wp_ajax_psm_dfr_submit', array( __CLASS__, 'submit' ) );
21 }
22
23 /**
24 * Submit feedback.
25 *
26 * @return void
27 */
28 public static function submit() {
29
30 check_ajax_referer( 'psm_dfr_nonce', 'nonce' );
31
32 if ( ! current_user_can( 'activate_plugins' ) ) {
33 wp_send_json_error();
34 }
35
36 $plugin_file = isset( $_POST['plugin_file'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_file'] ) ) : '';
37 $reason = isset( $_POST['reason'] ) ? sanitize_text_field( wp_unslash( $_POST['reason'] ) ) : '';
38 $note = isset( $_POST['note'] ) ? sanitize_textarea_field( wp_unslash( $_POST['note'] ) ) : '';
39
40 $plugins = PSM_DFR::get_plugins();
41
42 if ( empty( $plugins[ $plugin_file ] ) ) {
43 wp_send_json_error();
44 }
45
46 $config = $plugins[ $plugin_file ];
47
48 $payload = array(
49 'plugin_file' => $config['plugin_file'],
50 'plugin_name' => $config['plugin_name'],
51 'plugin_version' => $config['plugin_version'],
52 'reason' => $reason,
53 'note' => $note,
54 'wp_version' => get_bloginfo( 'version' ),
55 'php_version' => PHP_VERSION,
56 'website' => '',
57 );
58
59 $signature = hash_hmac(
60 'sha256',
61 wp_json_encode( $payload ),
62 $config['api_key']
63 );
64
65 $response = wp_remote_post(
66 esc_url_raw( $config['endpoint'] ),
67 array(
68 'timeout' => 3,
69 'blocking' => true,
70 'headers' => array(
71 'Content-Type' => 'application/json',
72 'X-PSMDF-API-KEY' => $config['api_key'],
73 'X-PSMDF-SIGNATURE' => $signature,
74 ),
75 'body' => wp_json_encode( $payload ),
76 )
77 );
78
79 wp_send_json_success();
80 }
81 }
82 PSM_DFR_Ajax::init();
83