PluginProbe
Import Social Events / 1.8.5
Import Social Events v1.8.5
1.9.1 1.9.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 All 61 releases
import-facebook-events / includes / class-ife-plugin-deactivation.php

class-ife-plugin-deactivation.php in Import Social Events 1.8.5, at includes/class-ife-plugin-deactivation.php

289 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Deactivation Class
4 * Collects Feedback from user about deactivation
5 *
6 * @package Xylus_Plugin_Deactivation
7 * @copyright Copyright (c) 2021, Xylus Themes
8 * @since 1.0.0
9 */
10
11 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * The admin-specific functionality of the plugin.
18 *
19 * @package Import_Eventbrite_Events
20 * @subpackage Import_Eventbrite_Events/admin
21 * @author Dharmesh Patel <dspatel44@gmail.com>
22 */
23 if ( ! class_exists( 'IFE_Plugin_Deactivation' ) ) {
24 class IFE_Plugin_Deactivation {
25
26 private $prefix = 'ife_';
27 private $slug = 'import-facebook-events';
28 private $plugin_version = '1.0.0';
29 private $api_url = 'https://api.xylusthemes.com/api/v1/';
30
31 /**
32 * Initialize the class and set its properties.
33 *
34 * @since 1.0.0
35 */
36 public function __construct() {
37 if ( defined( 'IFE_VERSION' ) ) {
38 $this->plugin_version = IFE_VERSION;
39 }
40
41 add_action( 'admin_footer', array( $this, 'deactivation_feedback_form') );
42 add_action( 'wp_ajax_'.$this->prefix.'plugin_deactivation_feedback', array( $this, 'submit_plugin_deactivation_feedback') );
43 }
44
45 public function get_deactivation_reasons() {
46 return array(
47 'confusing' => esc_attr__('I couldn\'t understand how to make it work', 'import-facebook-events' ),
48 'better_plugin' => esc_attr__('I found a better plugin', 'import-facebook-events' ),
49 'feature_request' => esc_attr__('The plugin is great, but I need a specific feature that you don\'t support', 'import-facebook-events' ),
50 'buggy' => esc_attr__('Plugin has bugs and it\'s not working', 'import-facebook-events' ),
51 'wrong_plugin' => esc_attr__('It\'s not what I was looking for', 'import-facebook-events' ),
52 'not_working' => esc_attr__('Plugin didn\'t work as expected', 'import-facebook-events' ),
53 'temporary' => esc_attr__('It\'s temporary deactivation, for debugging an issue', 'import-facebook-events' ),
54 'other' => esc_attr__('Other reasons', 'import-facebook-events' ),
55 );
56 }
57
58 function generate_ticket(){
59 $url = $this->api_url.'generateTicket';
60 $user = wp_get_current_user();
61 $headers = array( 'Content-Type' => 'application/json' );
62 $args = array(
63 'method' =>'POST',
64 'body' => json_encode(array('customer_email' => $user->user_email )),
65 'blocking' => true,
66 'headers' => $headers,
67 );
68
69 $response = wp_remote_post( $url, $args );
70 if ( is_wp_error( $response ) ) {
71 return false;
72 }
73
74 return wp_remote_retrieve_body($response);
75 }
76
77 function submit_plugin_deactivation_feedback(){
78 if ( !wp_verify_nonce( $_REQUEST['nonce'], $this->prefix.'plugin_deactivation_feedback')) {
79 exit("nonce verification failed");
80 }
81
82 $url = $this->api_url.'feedback';
83 $credentials = $this->generate_ticket();
84 if(!$credentials){
85 die();
86 }
87
88 $credentials = json_decode($credentials);
89 $user = wp_get_current_user();
90 $timestamp = $credentials->timestamp;
91 $client_id = $credentials->client_id;
92 $client_secret = $credentials->client_secret;
93 $customer_email = $user->user_email;
94 $customer_name = $user->user_firstname. ' '.$user->user_lastname;
95 $deactivation_reason = sanitize_text_field( $_REQUEST['reason'] );
96 $deactivation_reason_message = $this->get_deactivation_reasons()[$deactivation_reason];
97 $customer_query = sanitize_text_field( $_REQUEST['customerQuery'] );
98
99 $data = array(
100 "type" => "plugin_deactivation",
101 "site_url" => get_site_url(),
102 "customer_name" => $customer_name,
103 "customer_email" => $customer_email,
104 "plugin" => $this->slug,
105 "plugin_name" => 'Import Social Events',
106 "plugin_version" => $this->plugin_version,
107 "plugin_version" => $this->plugin_version,
108 "deactivation_reason" => $deactivation_reason,
109 "deactivation_reason_message" => $deactivation_reason_message,
110 "query" => $customer_query
111 );
112
113 $plain_string = $customer_email . $timestamp . $client_secret;
114 $sha512_hash = hash("sha512", $plain_string);
115
116 $body = json_encode($data);
117 $headers = array( 'Content-Type' => 'application/json');
118 $headers['Client-Id'] = $client_id;
119 $headers['Timestamp'] = $timestamp;
120 $headers['Authorization'] = $sha512_hash;
121 $args = array(
122 'method' =>'POST',
123 'body' => $body,
124 'blocking' => true,
125 'headers' => $headers
126 );
127 $response = wp_remote_post( $url, $args );
128 if ( is_wp_error( $response ) ) {
129 $error_message = $response->get_error_message();
130 echo "Something went wrong: $error_message";
131 exit();
132 }
133
134 die(true);
135 }
136
137 public function deactivation_feedback_form() {
138 $wp_screen = get_current_screen();
139 $page_id = $wp_screen->id;
140
141 // Load only for WP admin plugins page
142 if($page_id !== 'plugins'){
143 return;
144 }
145 wp_enqueue_style( 'wp-jquery-ui-dialog');
146 wp_enqueue_script( 'jquery-ui-dialog');
147
148 $deactivate_reasons = $this->get_deactivation_reasons();
149 ?>
150
151 <script>
152 jQuery(document).ready(function() {
153 var dataReason = jQuery('input:radio[name="<?php echo $this->prefix; ?>deactivatation_reason_radio"]').val();
154 jQuery('a#deactivate-<?php echo $this->slug; ?>').click(function (e) {
155 e.preventDefault();
156 var pluginDeactivateURL = jQuery(this).attr('href');
157 jQuery('#<?php echo $this->slug; ?>-deactivate-dialog' ).dialog({
158 'dialogClass' : '<?php echo $this->slug . "-deactivate-dialog"; ?>',
159 'modal' : true,
160 'closeOnEscape' : true,
161 width: 600,
162 'buttons' : [
163 {
164 text: "<?php _e('Submit & Deactivate', 'import-facebook-events' ); ?>",
165 class: 'button button-primary',
166 click: function() {
167 var that = this;
168 var dataQuery = jQuery('#<?php echo $this->prefix; ?>customer_query').val();
169 if(dataReason == 'other' && !dataQuery){
170 jQuery('#<?php echo $this->prefix; ?>customer_query').focus();
171 return false;
172 }
173 jQuery('#<?php echo $this->prefix; ?>deactivatation_form').hide();
174 jQuery('.<?php echo $this->prefix; ?>deactivatation_loading').show();
175 jQuery.ajax({
176 type : "post",
177 dataType : "json",
178 url : "<?php echo admin_url('admin-ajax.php?action='.$this->prefix.'plugin_deactivation_feedback&nonce='.wp_create_nonce($this->prefix.'plugin_deactivation_feedback')); ?>",
179 data : {
180 action: "<?php echo $this->prefix; ?>plugin_deactivation_feedback",
181 reason: dataReason,
182 customerQuery: dataQuery
183 },
184 }).always( function(){
185 jQuery( that ).dialog( "close" );
186 window.location.href=pluginDeactivateURL;
187 });
188 }
189 },
190 {
191 text: "<?php _e('Skip & Deactivate', 'import-facebook-events' ); ?>",
192 class: 'button',
193 click: function() {
194 jQuery( this ).dialog( "close" );
195 window.location.href=pluginDeactivateURL;
196 }
197 }
198 ]
199 });
200 });
201
202 jQuery('input:radio[name="<?php echo $this->prefix; ?>deactivatation_reason_radio"]').click(function () {
203 var reason = jQuery(this).val();
204 dataReason = jQuery(this).val();
205 var customerQuery = jQuery('#<?php echo $this->prefix; ?>customer_query');
206 customerQuery.removeAttr('required');
207 if (reason === "confusing") {
208 customerQuery.attr("placeholder", "<?php _e('Finding it confusing? let us know so that we can improve the interface', 'import-facebook-events' ); ?>");
209
210 } else if (reason === "other") {
211 customerQuery.attr("placeholder", "<?php _e('Can you let us know the reason for deactivation (Required)', 'import-facebook-events' ); ?>");
212 customerQuery.prop('required', true);
213
214 } else if (reason === "buggy" || reason === 'not_working') {
215 customerQuery.attr("placeholder", "<?php _e('Can you please let us know about the bug/issue in detail?', 'import-facebook-events' ); ?>");
216
217 } else if (reason === "better_plugin") {
218 customerQuery.attr("placeholder", "<?php _e('Can you please let us know which plugin you found helpful', 'import-facebook-events' ); ?>");
219
220 } else if (reason === "feature_request") {
221 customerQuery.attr("placeholder", "<?php _e('Can you please let us know more about the feature you want', 'import-facebook-events' ); ?>");
222
223 } else if (reason === "wrong_plugins") {
224 customerQuery.attr("placeholder", "<?php _e('Can you please let us know more about your requirement', 'import-facebook-events' ); ?>");
225
226 } else if (reason === "temporary") {
227 customerQuery.attr("placeholder", "<?php _e('Write your query here', 'import-facebook-events'); ?>");
228 }
229 });
230 });
231 </script>
232 <style>
233 <?php echo '.'.$this->slug; ?>-deactivate-dialog .ui-dialog-titlebar{
234 display: none;
235 }
236 .ui-widget.<?php echo $this->slug; ?>-deactivate-dialog{
237 font-family: inherit;
238 font-size: 14px;
239 font-weight: inherit;
240 line-height: inherit;
241 }
242 .ui-widget.<?php echo $this->slug; ?>-deactivate-dialog textarea{
243 font-family: inherit;
244 font-size: 14px;
245 width: 100%;
246 }
247 <?php echo '#'.$this->slug; ?>-deactivate-dialog {
248 display : none;
249 }
250 </style>
251 <div id="<?php echo $this->slug; ?>-deactivate-dialog">
252 <div class="ui-dialog-headerbar" >
253 <div>
254 <h2 style="margin: 0 0 15px 0;"><?php esc_html_e('Quick Feedback', 'import-facebook-events'); ?></h2>
255 </div>
256 </div>
257 <div style="border-top: 1px solid #dcdcde;"></div>
258 <h3 style="font-size: 14px;" ><?php esc_html_e('Could you please share why you are deactivating Import Facebook Events plugin ?', 'import-facebook-events'); ?></h3>
259 <form method="post" action="" id="<?php echo $this->prefix; ?>deactivatation_form">
260 <div>
261 <?php
262 foreach ( $deactivate_reasons as $key => $deactivate_reason ) {
263 ?>
264 <div class="radio" style="padding:1px;margin-left:2%">
265 <label for="<?php echo $key; ?>">
266 <input type="radio" name="<?php echo $this->prefix; ?>deactivatation_reason_radio" id="<?php echo $key; ?>" value="<?php echo $key; ?>" required <?php if($key === 'confusing') { echo "checked"; } ?>> <?php echo $deactivate_reason; ?>
267 </label>
268 </div>
269 <?php } ?>
270 <br>
271 <textarea id="<?php echo $this->prefix; ?>customer_query" name="<?php echo $this->prefix; ?>customer_query" rows="4" placeholder="<?php _e('Write your query here', 'import-facebook-events'); ?>"></textarea>
272 </div>
273 <div style="text-align: center;">
274 <p style="font-size: 12px;margin: 2px 0 -10px 0;">
275 <?php echo esc_attr__( '* By submitting this form, you will also be sending us your email address &amp; website URL.', 'import-facebook-events' ); ?>
276 </p>
277 </div>
278 </form>
279 <div class="<?php echo $this->prefix; ?>deactivatation_loading" style="width: 100%;text-align: center; display:none;">
280 <img src="<?php echo admin_url('images/spinner.gif'); ?>" />
281 </div>
282 </div>
283 <?php
284 }
285 }
286 }
287
288 new IFE_Plugin_Deactivation();
289