PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.9
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.9
6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 All 152 releases
poll-maker / includes / class-poll-maker-feedback.php

class-poll-maker-feedback.php in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.4.9, at includes/class-poll-maker-feedback.php

256 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 class Poll_Maker_Feedback {
8
9 /**
10 * API feedback URL.
11 *
12 * Holds the URL of the feedback API.
13 *
14 * @access private
15 * @static
16 *
17 * @var string API feedback URL.
18 */
19 private static $api_feedback_url = 'https://poll-plugin.com/poll-maker/feedback/';
20
21 /**
22 * @since 1.0.0
23 * @access public
24 */
25 public function __construct() {
26 add_action( 'current_screen', function () {
27 if ( ! $this->is_plugins_screen() ) {
28 return;
29 }
30
31 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_feedback_dialog_scripts' ) );
32 } );
33
34 // Ajax.
35 add_action( 'wp_ajax_ays_poll_deactivate_feedback', array( $this, 'ays_poll_deactivate_feedback' ) );
36 add_action( 'wp_ajax_nopriv_ays_poll_deactivate_feedback', array( $this, 'ays_poll_deactivate_feedback' ) );
37 }
38
39 /**
40 * Get module name.
41 *
42 * Retrieve the module name.
43 *
44 * @since 1.0.0
45 * @access public
46 *
47 * @return string Module name.
48 */
49 public function get_name() {
50 return 'feedback';
51 }
52
53 /**
54 * Enqueue feedback dialog scripts.
55 *
56 * Registers the feedback dialog scripts and enqueues them.
57 *
58 * @since 1.0.0
59 * @access public
60 */
61 public function enqueue_feedback_dialog_scripts() {
62 add_action( 'admin_footer', array( $this, 'print_deactivate_feedback_dialog' ) );
63 }
64
65 /**
66 * Print deactivate feedback dialog.
67 *
68 * Display a dialog box to ask the user why he deactivated Poll Maker.
69 *
70 * Fired by `admin_footer` filter.
71 *
72 * @since 1.0.0
73 * @access public
74 */
75 public function print_deactivate_feedback_dialog() {
76 $deactivate_reasons = array(
77 'no_longer_needed' => array(
78 'title' => esc_html__( 'I no longer need the plugin', 'poll-maker' ),
79 'input_placeholder' => '',
80 ),
81 'found_a_better_plugin' => array(
82 'title' => esc_html__( 'I found a better alternative', 'poll-maker' ),
83 'input_placeholder' => esc_html__( 'Other', 'poll-maker' ),
84 'sub_reason' => array(
85 'forminator_forms' => esc_html__( 'Forminator Forms', 'poll-maker' ),
86 'wp_polls' => esc_html__( 'WP-Polls', 'poll-maker' ),
87 'formidable_forms' => esc_html__( 'Formidable Forms', 'poll-maker' ),
88 'ts_poll' => esc_html__( 'TS Poll', 'poll-maker' ),
89 'yop_poll' => esc_html__( 'YOP Poll', 'poll-maker' ),
90 ),
91 ),
92 'couldnt_get_the_plugin_to_work' => array(
93 'title' => esc_html__( "The plugin didn’t work as expected", 'poll-maker' ),
94 'input_placeholder' => '',
95 ),
96 'missing_features' => array(
97 'title' => esc_html__( 'Missing essential features', 'poll-maker' ),
98 'input_placeholder' => esc_html__( 'Please share which features', 'poll-maker' ),
99 ),
100 'temporary_deactivation' => array(
101 'title' => esc_html__( "I only needed it temporarily", 'poll-maker' ),
102 'input_placeholder' => '',
103 ),
104 'plugin_or_theme_conflict' => array(
105 'title' => esc_html__( "Conflicts with other plugins or themes", 'poll-maker' ),
106 // 'input_placeholder' => esc_html__( 'Please share which plugin or theme', 'poll-maker' ),
107 'input_placeholder' => '',
108 'alert' => sprintf( __("Contact our %s support team %s to find and fix the issue.", 'poll-maker'),
109 "<a href='https://ays-pro.com/contact' target='_blank'>",
110 "</a>"
111 ),
112 ),
113 'poll_pro' => array(
114 'title' => esc_html__( 'I’m using the premium version now', 'poll-maker' ),
115 'input_placeholder' => '',
116 // 'alert' => esc_html__( "Wait! Don't deactivate Poll Maker. You have to activate both Poll Maker and Poll Maker Pro in order for the plugin to work.", 'poll-maker' ),
117 ),
118 'other' => array(
119 'title' => esc_html__( 'Other', 'poll-maker' ),
120 'input_placeholder' => esc_html__( 'Please share the reason', 'poll-maker' ),
121 ),
122 );
123
124 $poll_deactivate_feedback_nonce = wp_create_nonce( 'ays_poll_deactivate_feedback_nonce' );
125
126 ?>
127 <div class="ays-poll-dialog-widget ays-poll-dialog-lightbox-widget ays-poll-dialog-type-buttons ays-poll-dialog-type-lightbox" id="ays-poll-deactivate-feedback-modal" aria-modal="true" role="document" tabindex="0" style="display: none;">
128 <div class="ays-poll-dialog-widget-content ays-poll-dialog-lightbox-widget-content">
129 <div class="ays-poll-dialog-header ays-poll-dialog-lightbox-header">
130 <div id="ays-poll-deactivate-feedback-dialog-header">
131 <img class="ays-poll-dialog-logo" src="<?php echo esc_url( POLL_MAKER_AYS_ADMIN_URL . '/images/icons/icon-poll-128x128.png' ); ?>" alt="<?php echo esc_attr( __( "Poll Maker", 'poll-maker' ) ); ?>" title="<?php echo esc_attr( __( "Poll Maker", 'poll-maker' ) ); ?>" width="20" height="20"/>
132 <span id="ays-poll-deactivate-feedback-dialog-header-title"><?php echo esc_html__( 'Quick Feedback', 'poll-maker' ); ?></span>
133 </div>
134 </div>
135 <div class="ays-poll-dialog-message ays-poll-dialog-lightbox-message">
136 <form id="ays-poll-deactivate-feedback-dialog-form" method="post">
137 <input type="hidden" id="ays_poll_deactivate_feedback_nonce" name="ays_poll_deactivate_feedback_nonce" value="<?php echo esc_attr($poll_deactivate_feedback_nonce) ; ?>">
138 <input type="hidden" name="action" value="ays_poll_deactivate_feedback" />
139
140 <div id="ays-poll-deactivate-feedback-dialog-form-caption"><?php echo esc_html__( 'If you have a moment, please share why you are deactivating Poll Maker:', 'poll-maker' ); ?></div>
141 <div id="ays-poll-deactivate-feedback-dialog-form-body">
142 <?php foreach ( $deactivate_reasons as $reason_key => $reason ) : ?>
143 <div class="ays-poll-deactivate-feedback-dialog-input-wrapper">
144 <input id="ays-poll-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="ays-poll-deactivate-feedback-dialog-input" type="radio" name="ays_poll_reason_key" value="<?php echo esc_attr( $reason_key ); ?>" />
145 <label for="ays-poll-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="ays-poll-deactivate-feedback-dialog-label"><?php echo esc_html( $reason['title'] ); ?>
146 <?php if ( ! empty( $reason['input_placeholder'] ) && empty( $reason['sub_reason'] ) ) : ?>
147 <input class="ays-poll-feedback-text" type="text" name="ays_poll_reason_<?php echo esc_attr( $reason_key ); ?>" placeholder="<?php echo esc_attr( $reason['input_placeholder'] ); ?>" />
148 <?php endif; ?>
149 <?php if ( ! empty( $reason['alert'] ) ) : ?>
150 <div class="ays-poll-feedback-text ays-poll-feedback-text-color"><?php echo wp_kses_post( $reason['alert'] ); ?></div>
151 <?php endif; ?>
152 <?php if ( ! empty( $reason['sub_reason'] ) && is_array($reason['sub_reason']) ) : ?>
153 <div class="ays-poll-deactivate-feedback-sub-dialog-input-wrapper">
154 <?php foreach ( $reason['sub_reason'] as $sub_reason_key => $sub_reason ) : ?>
155 <div class="ays-poll-deactivate-feedback-dialog-input-wrapper">
156 <input id="ays-poll-deactivate-feedback-sub-<?php echo esc_attr( $sub_reason_key ); ?>" class="ays-poll-deactivate-feedback-dialog-input" type="radio" name="ays_poll_sub_reason_key" value="<?php echo esc_attr( $sub_reason_key ); ?>" />
157 <label for="ays-poll-deactivate-feedback-sub-<?php echo esc_attr( $sub_reason_key ); ?>" class="ays-poll-deactivate-feedback-dialog-label"><?php echo esc_html( $sub_reason ); ?>
158 </label>
159 </div>
160 <?php endforeach; ?>
161 </div>
162 <?php if ( ! empty( $reason['input_placeholder'] ) ) : ?>
163 <input class="ays-poll-feedback-text" type="text" name="ays_poll_reason_<?php echo esc_attr( $reason_key ); ?>" placeholder="<?php echo esc_attr( $reason['input_placeholder'] ); ?>" />
164 <?php endif; ?>
165 <?php endif; ?>
166 </label>
167 </div>
168 <?php endforeach; ?>
169 </div>
170 </form>
171 </div>
172 <div class="ays-poll-dialog-buttons-wrapper ays-poll-dialog-lightbox-buttons-wrapper">
173 <button class="ays-poll-dialog-button ays-poll-dialog-skip ays-poll-dialog-lightbox-skip" data-type="skip"><?php echo esc_html__( 'Skip &amp; Deactivate', 'poll-maker' ); ?></button>
174 <button class="ays-poll-dialog-button ays-poll-dialog-submit ays-poll-dialog-lightbox-submit" data-type="submit"><?php echo esc_html__( 'Submit &amp; Deactivate', 'poll-maker' ); ?></button>
175 </div>
176 </div>
177 </div>
178 <?php
179 }
180
181 /**
182 * Ajax Poll Maker deactivate feedback.
183 *
184 * Send the user feedback when Poll Maker is deactivated.
185 *
186 * Fired by `wp_ajax_ays_poll_deactivate_feedback` action.
187 *
188 * @since 1.0.0
189 * @access public
190 */
191 public function ays_poll_deactivate_feedback() {
192
193 if ( empty($_REQUEST['ays_poll_deactivate_feedback_nonce']) ) {
194 wp_send_json_error();
195 }
196
197 // Run a security check.
198 check_ajax_referer( 'ays_poll_deactivate_feedback_nonce', sanitize_key( $_REQUEST['_ajax_nonce'] ) );
199
200 if ( ! current_user_can( 'activate_plugins' ) ) {
201 wp_send_json_error( 'Permission denied' );
202 }
203
204 if (empty($_REQUEST['action']) || (isset($_REQUEST['action']) && $_REQUEST['action'] != 'ays_poll_deactivate_feedback')) {
205 wp_send_json_error( 'Action error' );
206 }
207
208 $reason_key = !empty($_REQUEST['ays_poll_reason_key']) ? sanitize_text_field($_REQUEST['ays_poll_reason_key']) : "";
209 $sub_reason_key = !empty($_REQUEST['ays_poll_sub_reason_key']) ? sanitize_text_field($_REQUEST['ays_poll_sub_reason_key']) : "";
210 $reason_text = !empty($_REQUEST["ays_poll_reason_{$reason_key}"]) ? sanitize_text_field($_REQUEST["ays_poll_reason_{$reason_key}"]) : "";
211 $type = !empty($_REQUEST["type"]) ? sanitize_text_field($_REQUEST["type"]) : "";
212
213 self::send_feedback( $reason_key, $sub_reason_key, $reason_text, $type );
214
215 wp_send_json_success();
216 }
217
218 /**
219 * @since 1.0.0
220 * @access private
221 */
222 private function is_plugins_screen() {
223 return in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ) );
224 }
225
226 /**
227 * Send Feedback.
228 *
229 * Fires a request to Poll Maker server with the feedback data.
230 *
231 * @since 1.0.0
232 * @access public
233 * @static
234 *
235 * @param string $feedback_key Feedback key.
236 * @param string $feedback_text Feedback text.
237 *
238 * @return array The response of the request.
239 */
240 public static function send_feedback( $feedback_key, $sub_feedback_key, $feedback_text, $type ) {
241 return wp_remote_post( self::$api_feedback_url, array(
242 'timeout' => 30,
243 'body' => wp_json_encode(array(
244 'type' => 'poll-maker',
245 'version' => POLL_MAKER_AYS_VERSION,
246 'site_lang' => get_bloginfo( 'language' ),
247 'button' => $type,
248 'feedback_key' => $feedback_key,
249 'sub_feedback_key' => $sub_feedback_key,
250 'feedback' => $feedback_text,
251 )),
252 ) );
253 }
254 }
255 new Poll_Maker_Feedback();
256