PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.3.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.3.0
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / core / admin / feedback.php

feedback.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 2.3.0, at includes/core/admin/feedback.php

182 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Core\Admin;
4
5 defined( 'ABSPATH' ) || die();
6
7 /**
8 * Class Feedback.
9 *
10 * @since 1.1.0
11 */
12 class Feedback {
13
14 /**
15 * Install constructor.
16 *
17 * @since 1.1.0
18 */
19 public function __construct() {
20 add_action( 'current_screen', function () {
21 if ( ! $this->is_plugins_screen() ) {
22 return;
23 }
24
25 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_feedback_dialog_scripts' ] );
26 } );
27
28 add_action( 'wp_ajax_sellkit_deactivate_feedback', [ $this, 'send_feedback_data' ] );
29 }
30
31 /**
32 * Sends feedback data
33 *
34 * @since 1.1.0
35 */
36 public function send_feedback_data() {
37 $nonce = sellkit_htmlspecialchars( INPUT_POST, '_wpnonce' );
38 $reason_key = sellkit_htmlspecialchars( INPUT_POST, 'reason_key' );
39 $description = sellkit_htmlspecialchars( INPUT_POST, 'description' );
40
41 if ( empty( wp_verify_nonce( $nonce, 'sellkit_deactivate_feedback_nonce' ) ) ) {
42 wp_send_json_error( __( 'Nonce is wrong.', 'sellkit' ) );
43 }
44
45 $remote = wp_remote_post(
46 'https://my.getsellkit.com/wp-json/sellkit/v1/customer/feedback',
47 [
48 'timeout' => 10,
49 'body' => [
50 'intent' => 'Plugin Deactivation',
51 'answer_id' => $reason_key,
52 'answer_desc' => $description, // For other reason description.
53 ],
54 ]
55 );
56
57 if ( is_wp_error( $remote ) ) {
58 wp_send_json_error( __( 'Something went wrong.', 'sellkit' ) );
59 }
60
61 wp_send_json_success( __( 'Deactivation feedback is sent.', 'sellkit' ) );
62 }
63
64 /**
65 * Checks if current screen is plugin.
66 *
67 * @since 1.1.0
68 */
69 private function is_plugins_screen() {
70 return in_array( get_current_screen()->id, [ 'plugins', 'plugins-network' ], true );
71 }
72
73 /**
74 * Enqueue feedback dialog scripts.
75 * Registers the feedback dialog scripts and enqueues them.
76 *
77 * @since 1.1.0
78 * @access public
79 */
80 public function enqueue_feedback_dialog_scripts() {
81 add_action( 'admin_footer', [ $this, 'print_deactivate_feedback_dialog' ] );
82
83 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
84
85 wp_register_script(
86 'sellkit-admin-feedback',
87 sellkit()->plugin_url() . 'assets/dist/js/admin-feedback' . $suffix . '.js',
88 [ 'jquery', 'wp-util' ],
89 sellkit()->version(),
90 true
91 );
92
93 wp_enqueue_script( 'sellkit-admin-feedback' );
94
95 wp_localize_script( 'sellkit-admin-feedback', 'sellkit_feedback', [
96 'spinIcon' => site_url( '/wp-admin/images/wpspin_light.gif' ),
97 ] );
98
99 wp_enqueue_style(
100 'sellkit-feedback',
101 sellkit()->plugin_url() . 'assets/dist/css/admin-feedback' . $suffix . '.css',
102 [],
103 sellkit()->version()
104 );
105 }
106
107 /**
108 * Print deactivate feedback dialog.
109 *
110 * @since 1.1.0
111 */
112 public function print_deactivate_feedback_dialog() {
113 $deactivate_reasons = [
114 '1' => [
115 'title' => esc_html__( 'It is a temporary deactivation, I am just debugging an issue', 'sellkit' ),
116 ],
117 '2' => [
118 'title' => esc_html__( 'I need more feature', 'sellkit' ),
119 ],
120 '3' => [
121 'title' => esc_html__( 'I no longer need it', 'sellkit' ),
122 ],
123 '4' => [
124 'title' => esc_html__( 'Customer service was less than expected', 'sellkit' ),
125 ],
126 '5' => [
127 'title' => esc_html__( 'Ease of use was less than expected', 'sellkit' ),
128 ],
129 '6' => [
130 'title' => esc_html__( 'Quality was less than expected', 'sellkit' ),
131 ],
132 '7' => [
133 'title' => esc_html__( 'Lack of integration with my tools', 'sellkit' ),
134 ],
135 '8' => [
136 'title' => esc_html__( 'Other reason', 'sellkit' ),
137 'input_placeholder' => esc_html__( 'Please share the reason', 'sellkit' ),
138 ],
139 ];
140
141 ?>
142 <div id="sellkit-deactivate-feedback-dialog-wrapper">
143 <div id="sellkit-deactivate-feedback-dialog-header">
144 <img src="<?php echo esc_url( sellkit()->plugin_url() . 'assets/img/icons/sellkit-logo.svg' ); ?>">
145 <span id="sellkit-deactivate-feedback-dialog-header-title"><?php echo esc_html__( 'Sellkit Feedback', 'sellkit' ); ?></span>
146 </div>
147 <form id="sellkit-deactivate-feedback-dialog-form" method="post">
148 <?php
149 wp_nonce_field( 'sellkit_deactivate_feedback_nonce' );
150 ?>
151 <input type="hidden" name="action" value="sellkit_deactivate_feedback" />
152
153 <div id="sellkit-deactivate-feedback-dialog-form-caption"><?php echo esc_html__( 'May we have a little info about why you are deactivating?', 'sellkit' ); ?></div>
154 <div id="sellkit-deactivate-feedback-dialog-form-body">
155 <?php foreach ( $deactivate_reasons as $reason_key => $reason ) : ?>
156 <div class="sellkit-deactivate-feedback-dialog-input-wrapper">
157 <input id="sellkit-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="sellkit-deactivate-feedback-dialog-input" <?php echo 1 === $reason_key ? 'checked' : ''; ?> type="radio" name="reason_key" value="<?php echo esc_attr( $reason_key ); ?>" />
158 <label for="sellkit-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="sellkit-deactivate-feedback-dialog-label"><?php echo esc_html( $reason['title'] ); ?></label>
159 <?php if ( ! empty( $reason['input_placeholder'] ) ) : ?>
160 <input class="sellkit-feedback-text" type="text" name="description" placeholder="<?php echo esc_attr( $reason['input_placeholder'] ); ?>" />
161 <?php endif; ?>
162 <?php if ( ! empty( $reason['alert'] ) ) : ?>
163 <div class="sellkit-feedback-text-alert"><?php echo esc_html( $reason['alert'] ); ?></div>
164 <?php endif; ?>
165 </div>
166 <?php endforeach; ?>
167 </div>
168 <div class="sellkit-deactivate-feedback-footer wp-core-ui">
169 <input type="button" class="button action sellkit-deactivate-feedback-cancel-button" value="<?php echo esc_html__( 'Discard', 'sellkit' ); ?>">
170 <div>
171 <img class="sellkit-deactivate-feedback-footer-spinner-icon sellkit-hide" src="<?php echo esc_url( site_url( '/wp-admin/images/wpspin_light.gif' ) ); ?>">
172 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php echo esc_html__( 'Submit & Deactivate', 'sellkit' ); ?>">
173 </div>
174 </div>
175 </form>
176 </div>
177 <?php
178 }
179 }
180
181 new Feedback();
182