PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.1
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Utils / Insights.php

Insights.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.8.1, at includes/Utils/Insights.php

1,128 lines 48.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPDeveloper\BetterDocs\Utils;
3
4 use AllowDynamicProperties;
5
6 /**
7 * Exit if accessed directly
8 */
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 #[AllowDynamicProperties]
14
15 class Insights {
16 /**
17 * WP Insights Version
18 */
19 const WPINS_VERSION = '3.0.1';
20 /**
21 * API URL
22 */
23 const API_URL = 'https://send.wpinsight.com/process-plugin-data';
24 /**
25 * Installed Plugin File
26 *
27 * @var string
28 */
29 private $plugin_file = null;
30 /**
31 * Installed Plugin Name
32 *
33 * @var string
34 */
35 private $plugin_name = null;
36 /**
37 * How often the event should subsequently
38 *
39 * @var string
40 */
41 public $recurrence = 'daily';
42 private $event_hook = null;
43 private $has_notice = false;
44 private $disabled_wp_cron = false;
45 private $enable_self_cron = false;
46 private $require_optin = false;
47 private $include_goodbye_form = false;
48 private $marketing = false;
49 private $options = [];
50 private $notice_options = [];
51 private $item_id = false;
52 /**
53 * Instace of BetterDocs_Plugin_Usage_Tracker
54 *
55 * @var BetterDocs_Plugin_Usage_Tracker
56 */
57 private static $_instance = null;
58 /**
59 * Get Instance of BetterDocs_Plugin_Usage_Tracker
60 *
61 * @return BetterDocs_Plugin_Usage_Tracker
62 */
63 public static function get_instance( $plugin_file, $args = [] ) {
64 if ( is_null( static::$_instance ) ) {
65 static::$_instance = new static( $plugin_file, $args );
66 }
67 return static::$_instance;
68 }
69 /**
70 * Automatically Invoked when initialized.
71 *
72 * @param array $args
73 */
74 public function __construct( $plugin_file, $args = [] ) {
75 $this->plugin_file = $plugin_file;
76 $this->plugin_name = basename( $this->plugin_file, '.php' );
77 $this->disabled_wp_cron = defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON == true;
78 $this->enable_self_cron = $this->disabled_wp_cron == true ? true : false;
79
80 $this->event_hook = 'put_do_weekly_action';
81
82 $this->require_optin = isset( $args['opt_in'] ) ? $args['opt_in'] : true;
83 $this->include_goodbye_form = isset( $args['goodbye_form'] ) ? $args['goodbye_form'] : true;
84 $this->marketing = isset( $args['email_marketing'] ) ? $args['email_marketing'] : true;
85 $this->options = isset( $args['options'] ) ? $args['options'] : [];
86 $this->item_id = isset( $args['item_id'] ) ? $args['item_id'] : false;
87 /**
88 * Activation Hook
89 */
90 register_activation_hook( $this->plugin_file, array( $this, 'activate_this_plugin' ) );
91 /**
92 * Deactivation Hook
93 */
94 register_deactivation_hook( $this->plugin_file, array( $this, 'deactivate_this_plugin' ) );
95 }
96 /**
97 * When user agreed to opt-in tracking schedule is enabled.
98 *
99 * @since 2.5.0
100 */
101 public function schedule_tracking() {
102 if ( $this->disabled_wp_cron ) {
103 return;
104 }
105 if ( ! wp_next_scheduled( $this->event_hook ) ) {
106 wp_schedule_event( time(), $this->recurrence, $this->event_hook );
107 }
108 }
109 /**
110 * Add the schedule event if the plugin is tracked.
111 *
112 * @return void
113 */
114 public function activate_this_plugin() {
115 $allow_tracking = $this->is_tracking_allowed();
116 if ( ! $allow_tracking ) {
117 return;
118 }
119 $this->schedule_tracking();
120 }
121 /**
122 * Remove the schedule event when plugin is deactivated and send the deactivated reason to inishghts if user submitted.
123 *
124 * @since 2.5.0
125 */
126 public function deactivate_this_plugin() {
127 /**
128 * Check tracking is allowed or not.
129 */
130 $allow_tracking = $this->is_tracking_allowed();
131 if ( ! $allow_tracking ) {
132 return;
133 }
134 $body = $this->get_data();
135 $body['status'] = 'Deactivated';
136 $body['deactivated_date'] = time();
137
138 // Check deactivation reason and add for insights data.
139 if ( false !== get_option( 'wpins_deactivation_reason_' . $this->plugin_name ) ) {
140 $body['deactivation_reason'] = get_option( 'wpins_deactivation_reason_' . $this->plugin_name );
141 }
142 if ( false !== get_option( 'wpins_deactivation_details_' . $this->plugin_name ) ) {
143 $body['deactivation_details'] = get_option( 'wpins_deactivation_details_' . $this->plugin_name );
144 }
145
146 $this->send_data( $body );
147 delete_option( 'wpins_deactivation_reason_' . $this->plugin_name );
148 delete_option( 'wpins_deactivation_details_' . $this->plugin_name );
149 /**
150 * Clear the event schedule.
151 */
152 if ( ! $this->disabled_wp_cron ) {
153 wp_clear_scheduled_hook( $this->event_hook );
154 }
155 }
156 /**
157 * Initial Method to Hook Everything.
158 *
159 * @return void
160 */
161 public function init() {
162 // $this->clicked();
163 add_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name, array( $this, 'clicked' ) );
164 add_action( $this->event_hook, array( $this, 'do_tracking' ) );
165 // For Test
166 // add_action( 'admin_init', array( $this, 'force_tracking' ) );
167 // add_action( 'admin_notices', array( $this, 'notice' ) );
168 add_action( 'wpdeveloper_optin_notice_for_' . $this->plugin_name, array( $this, 'notice' ) );
169 /**
170 * Deactivation Reason Form and Submit Data to Insights.
171 */
172 add_filter( 'plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'deactivate_action_links' ) );
173 add_action( 'admin_print_footer_scripts', array( $this, 'notice_script' ) );
174 add_action( 'admin_footer-plugins.php', array( $this, 'deactivate_reasons_form' ) );
175 add_action( 'wp_ajax_deactivation_form_' . esc_attr( $this->plugin_name ), array( $this, 'deactivate_reasons_form_submit' ) );
176 }
177 /**
178 * For Redirecting Current Page without Arguments!
179 *
180 * @return string
181 */
182 private function redirect_to() {
183 $request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
184 $query_string = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY );
185 parse_str( $query_string, $current_url );
186
187 $unset_array = array( 'dismiss', 'plugin', '_wpnonce', 'later', 'plugin_action', 'marketing_optin' );
188
189 foreach ( $unset_array as $value ) {
190 if ( isset( $current_url[ $value ] ) ) {
191 unset( $current_url[ $value ] );
192 }
193 }
194
195 $current_url = http_build_query( $current_url );
196 $redirect_url = $request_uri . '?' . $current_url;
197 return $redirect_url;
198 }
199 /**
200 * This method forcing the do_tracking method to execute instant.
201 *
202 * @return void
203 */
204 public function force_tracking() {
205 $this->do_tracking( true );
206 }
207 /**
208 * This method is responsible for all the magic from the front of the plugin.
209 *
210 * @since 2.5.0
211 * @param $force Force tracking if it's not the correct time to track/
212 */
213 public function do_tracking( $force = false ) {
214 /**
215 * Check URL is set or not.
216 */
217 if ( empty( self::API_URL ) ) {
218 return;
219 }
220 /**
221 * Check is tracking allowed or not.
222 */
223 if ( ! $this->is_tracking_allowed() ) {
224 return;
225 }
226 /**
227 * Check is this the correct time to track or not.
228 * or Force to track.
229 */
230 if ( ! $this->is_time_to_track() && ! $force ) {
231 return;
232 }
233 /**
234 * Get All Data.
235 */
236 $body = $this->get_data();
237 /**
238 * Send all data.
239 */
240 return $this->send_data( $body );
241 }
242 /**
243 * Is tracking allowed?
244 *
245 * @since 1.0.0
246 */
247 private function is_tracking_allowed() {
248 // First, check if the user has changed their mind and opted out of tracking
249 if ( $this->has_user_opted_out() ) {
250 $this->set_is_tracking_allowed( false, $this->plugin_name );
251 return false;
252 }
253 // The wpins_allow_tracking option is an array of plugins that are being tracked
254 $allow_tracking = get_option( 'wpins_allow_tracking' );
255 // If this plugin is in the array, then tracking is allowed
256 if ( isset( $allow_tracking[ $this->plugin_name ] ) ) {
257 return true;
258 }
259 return false;
260 }
261 /**
262 * Set a flag in DB If tracking is allowed.
263 *
264 * @since 2.5.0
265 * @param $is_allowed Boolean true if is allowed.
266 */
267 public function set_is_tracking_allowed( $is_allowed, $plugin = null ) {
268 if ( empty( $plugin ) ) {
269 $plugin = $this->plugin_name;
270 }
271 /**
272 * Get All Tracked Plugin List using this Tracker.
273 */
274 $allow_tracking = get_option( 'wpins_allow_tracking' );
275 /**
276 * Check user is opted out for tracking or not.
277 */
278 if ( $this->has_user_opted_out() ) {
279 if ( isset( $allow_tracking[ $plugin ] ) ) {
280 unset( $allow_tracking[ $plugin ] );
281 }
282 } elseif ( $is_allowed || ! $this->require_optin ) {
283 /**
284 * If user has agreed to allow tracking
285 */
286 if ( empty( $allow_tracking ) || ! is_array( $allow_tracking ) ) {
287 $allow_tracking = array( $plugin => $plugin );
288 } else {
289 $allow_tracking[ $plugin ] = $plugin;
290 }
291 } else {
292 if ( isset( $allow_tracking[ $plugin ] ) ) {
293 unset( $allow_tracking[ $plugin ] );
294 }
295 }
296 update_option( 'wpins_allow_tracking', $allow_tracking, 'no' );
297 }
298
299 /**
300 * Check the user has opted out or not.
301 *
302 * @since 2.5.0
303 * @return boolean
304 */
305 protected function has_user_opted_out() {
306 if ( ! empty( $this->options ) ) {
307 foreach ( $this->options as $option_name ) {
308 $options = get_option( $option_name );
309 if ( ! empty( $options['wpins_opt_out'] ) ) {
310 return true;
311 }
312 }
313 }
314 return false;
315 }
316 /**
317 * Check if it's time to track
318 *
319 * @since 2.5.0
320 */
321 public function is_time_to_track() {
322 $track_times = get_option( 'wpins_last_track_time', array() );
323 return ! isset( $track_times[ $this->plugin_name ] ) ? true :
324 ( ( isset( $track_times[ $this->plugin_name ] ) && $track_times[ $this->plugin_name ] ) < strtotime( '-1 day' ) ? true : false );
325 }
326 /**
327 * Set tracking time.
328 *
329 * @since 2.5.0
330 */
331 public function set_track_time() {
332 $track_times = get_option( 'wpins_last_track_time', array() );
333 $track_times[ $this->plugin_name ] = time();
334 update_option( 'wpins_last_track_time', $track_times, 'no' );
335 }
336 /**
337 * This method is responsible for collecting all data.
338 *
339 * @since 2.5.0
340 */
341 public function get_data() {
342 $body = array(
343 'plugin_slug' => sanitize_text_field( $this->plugin_name ),
344 'url' => get_bloginfo( 'url' ),
345 'site_name' => get_bloginfo( 'name' ),
346 'site_version' => get_bloginfo( 'version' ),
347 'site_language' => get_bloginfo( 'language' ),
348 'charset' => get_bloginfo( 'charset' ),
349 'wpins_version' => self::WPINS_VERSION,
350 'php_version' => phpversion(),
351 'multisite' => is_multisite(),
352 'file_location' => __FILE__,
353 );
354
355 // Collect the email if the correct option has been set
356 if ( $this->marketing ) {
357 if ( ! function_exists( 'wp_get_current_user' ) ) {
358 include ABSPATH . 'wp-includes/pluggable.php';
359 }
360 $current_user = wp_get_current_user();
361 $email = $current_user->user_email;
362 if ( is_email( $email ) ) {
363 $body['email'] = $email;
364 }
365 }
366 $body['marketing_method'] = $this->marketing;
367 $body['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
368
369 /**
370 * Collect all active and inactive plugins
371 */
372 if ( ! function_exists( 'get_plugins' ) ) {
373 include ABSPATH . '/wp-admin/includes/plugin.php';
374 }
375 $plugins = array_keys( get_plugins() );
376 $active_plugins = is_network_admin() ? array_keys( get_site_option( 'active_sitewide_plugins', array() ) ) : get_option( 'active_plugins', array() );
377 foreach ( $plugins as $key => $plugin ) {
378 if ( in_array( $plugin, $active_plugins ) ) {
379 unset( $plugins[ $key ] );
380 }
381 }
382 $body['active_plugins'] = $active_plugins;
383 $body['inactive_plugins'] = $plugins;
384
385 /**
386 * Text Direction.
387 */
388 $body['text_direction'] = ( function_exists( 'is_rtl' ) ? ( is_rtl() ? 'RTL' : 'LTR' ) : 'NOT SET' );
389 /**
390 * Get Our Plugin Data.
391 *
392 * @since 2.5.0
393 */
394 $plugin = $this->plugin_data();
395 if ( empty( $plugin ) ) {
396 $body['message'] .= __( 'We can\'t detect any plugin information. This is most probably because you have not included the code in the plugin main file.', 'plugin-usage-tracker' );
397 $body['status'] = 'NOT FOUND';
398 } else {
399 if ( isset( $plugin['Name'] ) ) {
400 $body['plugin'] = sanitize_text_field( $plugin['Name'] );
401 }
402 if ( isset( $plugin['Version'] ) ) {
403 $body['version'] = sanitize_text_field( $plugin['Version'] );
404 }
405 $body['status'] = 'Active';
406 }
407
408 /**
409 * Get active theme name and version
410 *
411 * @since 2.5.0
412 */
413 $theme = wp_get_theme();
414 if ( $theme->Name ) {
415 $body['theme'] = sanitize_text_field( $theme->Name );
416 }
417 if ( $theme->Version ) {
418 $body['theme_version'] = sanitize_text_field( $theme->Version );
419 }
420 return $body;
421 }
422
423 /**
424 * Collect plugin data,
425 * Retrieve current plugin information
426 *
427 * @since 2.5.0
428 */
429 public function plugin_data() {
430 if ( ! function_exists( 'get_plugin_data' ) ) {
431 include ABSPATH . '/wp-admin/includes/plugin.php';
432 }
433 $plugin = get_plugin_data( $this->plugin_file );
434 return $plugin;
435 }
436 /**
437 * Send the data to insights.
438 *
439 * @since 2.5.0
440 */
441 public function send_data( $body ) {
442 /**
443 * Get SITE ID
444 */
445 $site_id_key = "wpins_{$this->plugin_name}_site_id";
446 $site_id = get_option( $site_id_key, false );
447 $failed_data = [];
448 $site_url = get_bloginfo( 'url' );
449 $original_site_url = get_option( "wpins_{$this->plugin_name}_original_url", false );
450 if ( $original_site_url === false && version_compare( $body['wpins_version'], '3.0.1', '==' ) ) {
451 $site_id = false;
452 }
453 /**
454 * Send Initial Data to API
455 */
456 if ( $site_id == false && $this->item_id !== false && $original_site_url === false ) {
457 if ( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] && $_SERVER['REMOTE_ADDR'] != '127.0.0.1' ) ) {
458 $country_request = wp_remote_get( 'http://ip-api.com/json/' . $_SERVER['REMOTE_ADDR'] . '?fields=country' );
459 if ( ! is_wp_error( $country_request ) && $country_request['response']['code'] == 200 ) {
460 $ip_data = json_decode( $country_request['body'] );
461 $body['country'] = isset( $ip_data->country ) ? $ip_data->country : 'NOT SET';
462 }
463 }
464
465 $body['plugin_slug'] = $this->plugin_name;
466 $body['url'] = $site_url;
467 $body['item_id'] = $this->item_id;
468
469 $request = $this->remote_post( $body );
470 if ( ! is_wp_error( $request ) && $request['response']['code'] == 200 ) {
471 $retrieved_body = json_decode( wp_remote_retrieve_body( $request ), true );
472 if ( is_array( $retrieved_body ) && isset( $retrieved_body['siteId'] ) ) {
473 update_option( $site_id_key, $retrieved_body['siteId'], 'no' );
474 update_option( "wpins_{$this->plugin_name}_original_url", $site_url, 'no' );
475 update_option( "wpins_{$this->plugin_name}_{$retrieved_body['siteId']}", $body, 'no' );
476 }
477 } else {
478 $failed_data = $body;
479 }
480 }
481
482 $site_id_data_key = "wpins_{$this->plugin_name}_{$site_id}";
483 $site_id_data_failed_key = "wpins_{$this->plugin_name}_{$site_id}_send_failed";
484
485 if ( $site_id != false ) {
486 $old_sent_data = get_option( $site_id_data_key, [] );
487 $diff_data = $this->diff( $body, $old_sent_data );
488 $failed_data = get_option( $site_id_data_failed_key, [] );
489 if ( ! empty( $failed_data ) && $diff_data != $failed_data ) {
490 $failed_data = array_merge( $failed_data, $diff_data );
491 }
492 }
493
494 if ( ! empty( $failed_data ) && $site_id != false ) {
495 $failed_data['plugin_slug'] = $this->plugin_name;
496 $failed_data['url'] = $site_url;
497 $failed_data['site_id'] = $site_id;
498 if ( $original_site_url != false ) {
499 $failed_data['original_url'] = $original_site_url;
500 }
501
502 $request = $this->remote_post( $failed_data );
503 if ( ! is_wp_error( $request ) ) {
504 delete_option( $site_id_data_failed_key );
505 $replaced_data = array_merge( $old_sent_data, $failed_data );
506 update_option( $site_id_data_key, $replaced_data, 'no' );
507 }
508 }
509
510 if ( ! empty( $diff_data ) && $site_id != false && empty( $failed_data ) ) {
511 $diff_data['plugin_slug'] = $this->plugin_name;
512 $diff_data['url'] = $site_url;
513 $diff_data['site_id'] = $site_id;
514 if ( $original_site_url != false ) {
515 $diff_data['original_url'] = $original_site_url;
516 }
517
518 $request = $this->remote_post( $diff_data );
519 if ( is_wp_error( $request ) ) {
520 update_option( $site_id_data_failed_key, $diff_data, 'no' );
521 } else {
522 $replaced_data = array_merge( $old_sent_data, $diff_data );
523 update_option( $site_id_data_key, $replaced_data, 'no' );
524 }
525 }
526
527 $this->set_track_time();
528
529 if ( isset( $request ) && is_wp_error( $request ) ) {
530 return $request;
531 }
532
533 if ( isset( $request ) ) {
534 return true;
535 }
536 return false;
537 }
538 /**
539 * WP_REMOTE_POST method responsible for send data to the API_URL
540 *
541 * @param array $data
542 * @param array $args
543 * @return \WP_Error|array|null
544 */
545 protected function remote_post( $data = array(), $args = array() ) {
546 if ( empty( $data ) ) {
547 return;
548 }
549
550 $args = wp_parse_args( $args, array(
551 'method' => 'POST',
552 'timeout' => 30,
553 'redirection' => 5,
554 'httpversion' => '1.1',
555 'blocking' => true,
556 'body' => $data,
557 'user-agent' => 'PUT/1.0.0; ' . get_bloginfo( 'url' ),
558 )
559 );
560
561 $request = wp_remote_post( esc_url( self::API_URL ), $args );
562 if ( is_wp_error( $request ) || ( isset( $request['response'], $request['response']['code'] ) && $request['response']['code'] != 200 ) ) {
563 return new \WP_Error( 500, 'Something went wrong.' );
564 }
565
566 return $request;
567 }
568 /**
569 * Difference between old and new data
570 *
571 * @param array $new_data
572 * @param array $old_data
573 * @return array
574 */
575 protected function diff( $new_data, $old_data ) {
576 $data = [];
577 if ( ! empty( $new_data ) ) {
578 foreach ( $new_data as $key => $value ) {
579 if ( isset( $old_data[ $key ] ) ) {
580 if ( $old_data[ $key ] == $value ) {
581 continue;
582 }
583 }
584 $data[ $key ] = $value;
585 }
586 }
587 return $data;
588 }
589 /**
590 * Display the admin notice to users to allow them to opt in
591 *
592 * @since 2.5.0
593 */
594 public function notice() {
595 /**
596 * Return if notice is not set.
597 */
598 if ( ! isset( $this->notice_options['notice'] ) ) {
599 return;
600 }
601 /**
602 * Check is allowed or blocked for notice.
603 */
604 $block_notice = get_option( 'wpins_block_notice' );
605 if ( isset( $block_notice[ $this->plugin_name ] ) ) {
606 return;
607 }
608 if ( ! current_user_can( 'manage_options' ) ) {
609 return;
610 }
611
612 $this->has_notice = true;
613
614 $url_yes = add_query_arg( [
615 'plugin' => $this->plugin_name,
616 'plugin_action' => 'yes',
617 ]);
618
619 $url_no = add_query_arg([
620 'plugin' => $this->plugin_name,
621 'plugin_action' => 'no',
622 ]);
623
624 $url_yes = wp_nonce_url( $url_yes, '_wpnonce_optin_' . $this->plugin_name );
625 $url_no = wp_nonce_url( $url_no, '_wpnonce_optin_' . $this->plugin_name );
626
627 // Decide on notice text
628 $notice_text = $this->notice_options['notice'] . ' <a href="#" class="wpinsights-' . esc_attr( $this->plugin_name ) . '-collect" >' . $this->notice_options['consent_button_text'] . '</a>';
629 $extra_notice_text = $this->notice_options['extra_notice'];
630
631 ?>
632
633 <div class="nx-optin">
634 <p><?php echo wp_kses_post( $notice_text ); ?></p>
635 <div class="wpinsights-data" style="display: none;">
636 <p><?php echo wp_kses_post( $extra_notice_text ); ?></p>
637 </div>
638 <p>
639 <a href="<?php echo esc_url( $url_yes ); ?>" class="button-primary">
640 <?php echo esc_html( $this->notice_options['yes'] ); ?>
641 </a>&nbsp;
642 <a href="<?php echo esc_url( $url_no ); ?>" class="button-secondary">
643 <?php echo esc_html( $this->notice_options['no'] ); ?>
644 </a>
645 </p>
646 </div>
647
648 <?php
649 }
650
651 public function notice_script() {
652 if ( $this->has_notice ) {
653 echo "<script type='text/javascript'>jQuery('.wpinsights-" . esc_attr( $this->plugin_name ) . "-collect').on('click', function(e) {e.preventDefault();jQuery('.wpinsights-data').slideToggle('fast');});</script>";
654 }
655 }
656 /**
657 * Set all notice options to customized notice.
658 *
659 * @since 2.5.0
660 * @param array $options
661 * @return void
662 */
663 public function set_notice_options( $options = [] ) {
664 $default_options = [
665 'consent_button_text' => __( 'What we collect.', 'wpinsight' ),
666 'yes' => __( 'Sure, I\'d like to help', 'wpinsight' ),
667 'no' => __( 'No Thanks.', 'wpinsight' ),
668 ];
669 $options = wp_parse_args( $options, $default_options );
670 $this->notice_options = $options;
671 }
672 /**
673 * Responsible for track the click from Notice.
674 *
675 * @return void
676 */
677 public function clicked( $notice = null ) {
678 if ( isset( $_GET[ '_wpnonce' ] ) && isset( $_GET['plugin'] ) && isset( $_GET['plugin_action'] ) ) {
679 if ( isset( $_GET['tab'] ) && $_GET['tab'] === 'plugin-information' ) {
680 return;
681 }
682
683
684 if( ! wp_verify_nonce( $_GET[ '_wpnonce' ], '_wpnonce_optin_' . $this->plugin_name ) ) {
685 return;
686 }
687
688 $plugin = sanitize_text_field( $_GET['plugin'] );
689 $action = sanitize_text_field( $_GET['plugin_action'] );
690 if ( $action == 'yes' ) {
691 $this->schedule_tracking();
692 $this->set_is_tracking_allowed( true, $plugin );
693 if ( $this->do_tracking( true ) ) {
694 $this->update_block_notice( $plugin );
695 }
696 } else {
697 $this->set_is_tracking_allowed( false, $plugin );
698 $this->update_block_notice( $plugin );
699 }
700
701 if( ! is_null ( $notice ) ) {
702 $notice->dismiss->dismiss_notice();
703 }
704
705 /**
706 * Redirect User To the Current URL, but without set query arguments.
707 */
708 wp_safe_redirect( $this->redirect_to() );
709 }
710 }
711 /**
712 * Set if we should block the opt-in notice for this plugin
713 *
714 * @since 2.5.0
715 */
716 public function update_block_notice( $plugin = null ) {
717 if ( empty( $plugin ) ) {
718 $plugin = $this->plugin_name;
719 }
720 $block_notice = get_option( 'wpins_block_notice' );
721 if ( empty( $block_notice ) || ! is_array( $block_notice ) ) {
722 $block_notice = array( $plugin => $plugin );
723 } else {
724 $block_notice[ $plugin ] = $plugin;
725 }
726 update_option( 'wpins_block_notice', $block_notice, 'no' );
727 }
728 /**
729 * AJAX callback when the deactivated form is submitted.
730 *
731 * @since 2.5.0
732 */
733 public function deactivate_reasons_form_submit() {
734 check_ajax_referer( 'wpins_deactivation_nonce', 'security' );
735 if( isset( $_POST['values'] ) ) {
736 $values = sanitize_text_field( $_POST['values'] );
737 update_option( 'wpins_deactivation_reason_' . $this->plugin_name, $values );
738 }
739 if( isset( $_POST['details'] ) ) {
740 $details = sanitize_text_field( $_POST['details'] );
741 update_option( 'wpins_deactivation_details_' . $this->plugin_name, $details );
742 }
743 echo 'success';
744 wp_die();
745 }
746 /**
747 * Filter the deactivation link to allow us to present a form when the user deactivates the plugin
748 *
749 * @since 2.5.0
750 */
751 public function deactivate_action_links( $links ) {
752 /**
753 * Check is tracking allowed or not.
754 */
755 if ( ! $this->is_tracking_allowed() ) {
756 return $links;
757 }
758 if ( isset( $links['deactivate'] ) && $this->include_goodbye_form ) {
759 $deactivation_link = $links['deactivate'];
760 /**
761 * Change the default deactivate button link.
762 */
763 $deactivation_link = str_replace( '<a ', '<div class="wpinsights-goodbye-form-wrapper-' . esc_attr( $this->plugin_name ) . '"><div class="wpinsights-goodbye-form-bg"></div><span class="wpinsights-goodbye-form" id="wpinsights-goodbye-form"></span></div><a onclick="javascript:event.preventDefault();" id="wpinsights-goodbye-link-' . esc_attr( $this->plugin_name ) . '" ', $deactivation_link );
764 $links['deactivate'] = $deactivation_link;
765 }
766 return $links;
767 }
768 /**
769 * ALL Deactivate Reasons.
770 *
771 * @since 2.5.0
772 */
773 public function deactivation_reasons() {
774 $form = array();
775 $form['heading'] = __( 'We Value Your Feedback', 'disable-comments' );
776 $form['body'] = __( "Could you please tell us why you're deactivating our plugin? Your insights will help us to improve.", 'disable-comments' );
777
778 $form['options'] = array(
779 __( 'I no longer need the plugin', 'disable-comments' ),
780 [
781 'label' => __( 'I found a better plugin', 'disable-comments' ),
782 'extra_field' => __( 'Please share which plugin', 'disable-comments' )
783 ],
784 __( "I couldn't get the plugin to work", 'disable-comments' ),
785 __( 'It\'s a temporary deactivation', 'disable-comments' ),
786 [
787 'label' => __( 'Other', 'disable-comments' ),
788 'extra_field' => __( 'Please share the reason', 'disable-comments' ),
789 'type' => 'textarea'
790 ]
791 );
792 return apply_filters( 'wpins_form_text_' . $this->plugin_name, $form );
793 }
794
795 /**
796 * Deactivate Reasons Form.
797 * This form will appears when user wants to deactivate the plugin to send you deactivated reasons.
798 *
799 * @since 3.0.0
800 */
801 public function deactivate_reasons_form() {
802 $form = $this->deactivation_reasons();
803 $class_plugin_name = esc_attr( $this->plugin_name );
804 $html = '<div class="betterdocs__modal-close-btn"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166 4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166 19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289 17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z"/></svg></div><div class="wpinsights-goodbye-form-head"><span><svg width="65" height="64" viewBox="0 0 65 64" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="0.5" width="64" height="64" rx="16" fill="#e0fff6"/><path d="M41.8346 22.668L45.8346 18.668M19.168 45.3346L23.168 41.3346M26.5013 34.0013L29.8346 30.668M30.5013 38.0013L33.8346 34.668M24.9013 43.068C25.1986 43.3663 25.5518 43.603 25.9408 43.7645C26.3298 43.926 26.7468 44.0092 27.168 44.0092C27.5891 44.0092 28.0062 43.926 28.3951 43.7645C28.7841 43.603 29.1373 43.3663 29.4346 43.068L32.5013 40.0013L24.5013 32.0013L21.4346 35.068C21.1363 35.3653 20.8996 35.7185 20.7381 36.1075C20.5766 36.4964 20.4934 36.9135 20.4934 37.3346C20.4934 37.7558 20.5766 38.1728 20.7381 38.5618C20.8996 38.9508 21.1363 39.304 21.4346 39.6013L24.9013 43.068ZM32.5013 24.0013L40.5013 32.0013L43.568 28.9346C43.8663 28.6373 44.103 28.2841 44.2645 27.8951C44.426 27.5062 44.5092 27.0891 44.5092 26.668C44.5092 26.2468 44.426 25.8298 44.2645 25.4408C44.103 25.0518 43.8663 24.6986 43.568 24.4013L40.1013 20.9346C39.804 20.6363 39.4508 20.3996 39.0618 20.2381C38.6728 20.0766 38.2558 19.9934 37.8346 19.9934C37.4135 19.9934 36.9964 20.0766 36.6075 20.2381C36.2185 20.3996 35.8653 20.6363 35.568 20.9346L32.5013 24.0013Z" stroke="#00b884" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></span><h1>' . $form['heading'] . '</h1></div>';
805 $html .= '<div class="wpinsights-goodbye-form-body"><p class="wpinsights-goodbye-form-caption">' . esc_html( $form['body'] ) . '</p>';
806 if( is_array( $form['options'] ) ) {
807 $html .= '<div id="wpinsights-goodbye-options" class="wpinsights-goodbye-options"><ul>';
808 foreach( $form['options'] as $option ) {
809 if( is_array( $option ) ) {
810 $id = strtolower( str_replace( " ", "_", esc_attr( $option['label'] ) ) );
811 $id = $id . '_' . $class_plugin_name;
812 $html .= '<li class="has-goodbye-extra">';
813 $html .= '<input type="radio" name="wpinsights-'. esc_attr( $class_plugin_name ) .'-goodbye-options" id="' . esc_attr( $id ) . '" value="' . esc_attr( $option['label'] ) . '">';
814 $html .= '<div><label for="' . $id . '">' . esc_attr( $option['label'] ) . '</label>';
815 if( isset( $option[ 'extra_field' ] ) && ! isset( $option['type'] )) {
816 $html .= '<input type="text" style="display: none" name="'. esc_attr( $id ) .'" id="' . str_replace( " ", "", esc_attr( $option['extra_field'] ) ) . '" placeholder="' . esc_attr( $option['extra_field'] ) . '">';
817 }
818 if( isset( $option[ 'extra_field' ] ) && isset( $option['type'] )) {
819 $html .= '<'. $option['type'] .' style="display: none" type="text" name="'. esc_attr( $id ) .'" id="' . str_replace( " ", "", esc_attr( $option['extra_field'] ) ) . '" placeholder="' . esc_attr( $option['extra_field'] ) . '"></' . $option['type'] . '>';
820 }
821 $html .= '</div></li>';
822 } else {
823 $id = strtolower( str_replace( " ", "_", esc_attr( $option ) ) );
824 $id = $id . '_' . $class_plugin_name;
825 $html .= '<li><input type="radio" name="wpinsights-'. $class_plugin_name .'-goodbye-options" id="' . esc_attr( $id ) . '" value="' . esc_attr( $option ) . '"> <label for="' . $id . '">' . esc_attr( $option ) . '</label></li>';
826 }
827 }
828 $html .= '</ul></div><!-- .wpinsights-'. $class_plugin_name .'-goodbye-options -->';
829 }
830 $html .= '</div><!-- .wpinsights-goodbye-form-body -->';
831 $html .= '<p class="deactivating-spinner"><span class="spinner"></span> ' . __( 'Submitting form', 'disable-comments' ) . '</p>';
832
833 $wrapper_class = '.wpinsights-goodbye-form-wrapper-'. $class_plugin_name;
834
835 $styles = '';
836 $styles .= '<style type="text/css">';
837 $styles .= '.wpinsights-form-active-' . $class_plugin_name . ' .wpinsights-goodbye-form-bg {';
838 $styles .= 'background: rgba( 0, 0, 0, .8 );position: fixed;top: 0;left: 0;width: 100%;height: 100%;z-index: 9;';
839 $styles .= '}';
840 $styles .= $wrapper_class . '{';
841 $styles .= 'position: relative; display: none;';
842 $styles .= '}';
843 $styles .= '.wpinsights-form-active-' . $class_plugin_name . ' ' . $wrapper_class . '{';
844 $styles .= 'display: flex !important; position: fixed;top: 0;left: 0;width: 100%;height: 100%; justify-content: center; align-items: center;';
845 $styles .= '}';
846 $styles .= $wrapper_class . ' .wpinsights-goodbye-form { display: none; }';
847 $styles .= '.wpinsights-form-active-' . $class_plugin_name . ' .wpinsights-goodbye-form {';
848 $styles .= 'position: relative !important; width: 550px; max-width: 80%; background: #fff; box-shadow: 2px 8px 23px 3px rgba(0,0,0,.2); border-radius: 3px; white-space: normal; overflow: hidden; display: block; z-index: 999999;';
849 $styles .= '}';
850 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-head {';
851 $styles .= 'background: #fff; color: #495157; padding: 18px; box-shadow: 0 0 8px rgba(0,0,0,.1); font-size: 15px;';
852 $styles .= '}';
853 $styles .= $wrapper_class . ' .wpinsights-goodbye-form .wpinsights-goodbye-form-head strong { font-size: 15px; }';
854 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-body { padding: 8px 18px; color: #333; }';
855 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-body label { padding-left: 5px; color: #6d7882; }';
856 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-body .wpinsights-goodbye-form-caption {';
857 $styles .= 'font-weight: 500; font-size: 15px; color: #495157; line-height: 1.4;';
858 $styles .= '}';
859 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options { padding-top: 5px; }';
860 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li { margin-bottom: 15px; }';
861 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div { display: inline; padding-left: 3px; }';
862 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > input, '. $wrapper_class .' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > textarea {';
863 $styles .= 'margin: 10px 18px; padding: 8px; width: 80%;';
864 $styles .= '}';
865 $styles .= $wrapper_class . ' .deactivating-spinner { display: none; padding-bottom: 20px !important; }';
866 $styles .= $wrapper_class . ' .deactivating-spinner .spinner { float: none; margin: 4px 4px 0 18px; vertical-align: bottom; visibility: visible; }';
867 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer { padding: 8px 18px; margin-bottom: 15px; }';
868 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer > .wpinsights-goodbye-form-buttons { display: flex; align-items: center; justify-content: space-between; }';
869 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-submit-btn {';
870 $styles .= 'background-color: #f3bafd; -webkit-border-radius: 3px; border-radius: 3px; color: #0c0d0e; line-height: 1; padding: 10px 20px; font-size: 13px; font-weight: 500; text-transform: uppercase; transition: .3s;';
871 $styles .= '}';
872 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-submit-btn:hover {';
873 $styles .= 'background-color: #f5d0fe;';
874 $styles .= '}';
875 $styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-deactivate-btn {';
876 $styles .= 'font-size: 13px; color: #a4afb7; background: none; float: right; padding-right: 10px; width: auto; text-decoration: underline;';
877 $styles .= '}';
878 $styles .= $wrapper_class . ' .test {';
879 $styles .= '}';
880 $styles .= '
881
882 .wpinsights-form-active-betterdocs .wpinsights-goodbye-form-wrapper-betterdocs {
883 display: flex !important;
884 position: fixed;
885 top: 0;
886 left: 0;
887 right: 0;
888 bottom: 0;
889 width: 100%;
890 z-index: 9999;
891 height: 100%;
892 justify-content: center;
893 align-items: center;
894 }
895 .wpinsights-form-active-betterdocs .wpinsights-goodbye-form {
896 border-radius: 8px;
897 width: 563px;
898 overflow: visible;
899 position: relative;
900 }
901 .wpinsights-goodbye-form .betterdocs__modal-close-btn {
902 position: absolute;
903 top: 0;
904 right: -55px;
905 width: 40px;
906 height: 40px;
907 background: #fff;
908 border-radius: 50%;
909 display: flex;
910 justify-content: center;
911 align-items: center;
912 font-size: 12px;
913 font-weight: 500;
914 color: #475467;
915 cursor: pointer;
916 }
917 .wpinsights-goodbye-form .betterdocs__modal-close-btn svg {
918 width: 20px;
919 }
920 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-head {
921 background: #fff;
922 color: #495157;
923 padding: 24px;
924 border-radius: 8px 8px 0 0;
925 box-shadow: none;
926 border-bottom: 1px solid #EAECF0;
927 display: flex;
928 flex-direction: column;
929 gap: 16px;
930 align-items: center;
931 }
932 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-head > span {
933 display: inline-flex;
934 }
935 .wpinsights-goodbye-form-head h1 {
936 font-size: 22px;
937 font-weight: 450;
938 color: #1D2939;
939 padding: 0;
940 }
941 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body {
942 padding: 32px 40px;
943 max-height: calc(70vh - 230px);
944 overflow: auto;
945 }
946 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body .wpinsights-goodbye-form-caption {
947 font-size: 18px;
948 color: #1D2939;
949 margin: 0;
950 padding-bottom: 16px;
951 font-weight: 400;
952 }
953 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body #wpinsights-goodbye-options {
954 padding-top: 0px;
955 }
956 .wpinsights-goodbye-form-wrapper-betterdocs .widefat td ul {
957 font-size: 14px;
958 margin: 0;
959 color: #475467;
960 line-height: 1.4em;
961 }
962 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li:not(:last-child) {
963 margin-bottom: 16px;
964 }
965 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li:last-child {
966 margin-bottom: 0;
967 }
968 .wpinsights-goodbye-form-wrapper-betterdocs input[type=radio] {
969 border-radius: 50%;
970 margin-right: .25rem;
971 line-height: .71428571;
972 margin: 0;
973 }
974 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body label {
975 padding-left: 4px;
976 color: #475467;
977 font-size: 14px;
978 }
979 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > input, .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > textarea {
980 padding: 10px 16px;
981 border-radius: 8px;
982 width: 100%;
983 border: 1px solid #D0D5DD;
984 margin: 0;
985 margin-top: 16px;
986 color: #1D2939;
987 font-size: 14px;
988 line-height: 1.5em;
989 resize: none;
990 max-height: 44px;
991 }
992 .wpinsights-goodbye-form-wrapper-betterdocs input[type=radio] {
993 border: 1px solid #D0D5DD;
994 box-shadow: none;
995 }
996 .wpinsights-goodbye-form-wrapper-betterdocs input[type=radio]:checked::before {
997 content: "";
998 border-radius: 50%;
999 width: .88rem;
1000 height: .88rem;
1001 margin: -.95px;
1002 background-color: #00b884;
1003 border: 1px solid #e0fff6;
1004 line-height: 1.14285714;
1005 outline: 0;
1006 }
1007 .wpinsights-goodbye-form-wrapper-betterdocs input[type=radio]:focus {
1008 border-color: #D0D5DD;
1009 box-shadow: none;
1010 outline: 0;
1011 }
1012 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > input::placeholder,
1013 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > textarea::placeholder{
1014 color: #C6CBD2 !important;
1015 }
1016 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-footer {
1017 padding: 16px 36px;
1018 margin-bottom: 0;
1019 border-top: 1px solid #EAECF0;
1020 }
1021 .wpinsights-goodbye-form-wrapper-betterdocs input:focus,
1022 .wpinsights-goodbye-form-wrapper-betterdocs textarea:focus {
1023 box-shadow: none !important;
1024 outline: 0 !important;
1025 }
1026 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-footer > .wpinsights-goodbye-form-buttons {
1027 display: flex;
1028 align-items: center;
1029 justify-content: flex-start;
1030 }
1031 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-footer .wpinsights-submit-btn {
1032 background-color: #00b884;
1033 -webkit-border-radius: 8px;
1034 border-radius: 8px;
1035 color: #fff;
1036 padding: 8px 16px;
1037 font-size: 14px;
1038 font-weight: 500;
1039 line-height: 1.5em;
1040 text-transform: capitalize;
1041 transition: .3s;
1042 }
1043 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-footer .wpinsights-submit-btn:hover {
1044 background: #00b884;
1045 }
1046
1047 .wpinsights-goodbye-form-wrapper-betterdocs .wpinsights-goodbye-form-footer .wpsp-put-deactivate-btn {
1048 font-size: 14px;
1049 font-weight: 500;
1050 color: #344054;
1051 margin-left: 10px;
1052 }
1053 .wp-person a:focus .gravatar, a:focus, a:focus .media-icon img, a:focus .plugin-icon {
1054 color: #043959;
1055 box-shadow: none;
1056 outline: 0;
1057 }
1058
1059 ';
1060 $styles .= '</style>';
1061 $styles .= '';
1062
1063
1064
1065 echo $styles;
1066 ?>
1067 <script type="text/javascript">
1068 jQuery(document).ready(function($){
1069 $("#wpinsights-goodbye-link-<?php echo $class_plugin_name; ?>").on("click",function(){
1070 // We'll send the user to this deactivation link when they've completed or dismissed the form
1071 var url = document.getElementById("wpinsights-goodbye-link-<?php echo $class_plugin_name; ?>");
1072 $('body').toggleClass('wpinsights-form-active-<?php echo $class_plugin_name; ?>');
1073 $(".wpinsights-goodbye-form-wrapper-<?php echo $class_plugin_name; ?> #wpinsights-goodbye-form").fadeIn();
1074 $(".wpinsights-goodbye-form-wrapper-<?php echo $class_plugin_name; ?> #wpinsights-goodbye-form").html( '<?php echo $html; ?>' + '<div class="wpinsights-goodbye-form-footer"><div class="wpinsights-goodbye-form-buttons"><a id="wpinsights-submit-form-<?php echo $class_plugin_name; ?>" class="wpinsights-submit-btn" href="#"><?php _e( 'Submit and Deactivate', 'disable-comments' ); ?></a>&nbsp;<a class="wpsp-put-deactivate-btn" href="'+url+'"><?php _e( 'Just Deactivate', 'disable-comments' ); ?></a></div></div>');
1075 $('#wpinsights-submit-form-<?php echo $class_plugin_name; ?>').on('click', function(e){
1076 // As soon as we click, the body of the form should disappear
1077 $("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .wpinsights-goodbye-form-body").fadeOut();
1078 $("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .wpinsights-goodbye-form-footer").fadeOut();
1079 // Fade in spinner
1080 $("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .deactivating-spinner").fadeIn();
1081 e.preventDefault();
1082 var checkedInput = $("input[name='wpinsights-<?php echo esc_attr( $class_plugin_name ); ?>-goodbye-options']:checked"),
1083 checkedInputVal, details;
1084 if( checkedInput.length > 0 ) {
1085 checkedInputVal = checkedInput.val();
1086 details = $('input[name="'+ checkedInput[0].id +'"], textarea[name="'+ checkedInput[0].id +'"]').val();
1087 }
1088
1089 if( typeof details === 'undefined' ) {
1090 details = '';
1091 }
1092 if( typeof checkedInputVal === 'undefined' ) {
1093 checkedInputVal = 'No Reason';
1094 }
1095
1096 var data = {
1097 'action': 'deactivation_form_<?php echo esc_attr( $class_plugin_name ); ?>',
1098 'values': checkedInputVal,
1099 'details': details,
1100 'security': "<?php echo wp_create_nonce ( 'wpins_deactivation_nonce' ); ?>",
1101 'dataType': "json"
1102 }
1103
1104 $.post(
1105 ajaxurl,
1106 data,
1107 function(response){
1108 // Redirect to original deactivation URL
1109 window.location.href = url;
1110 }
1111 );
1112 });
1113 $('#wpinsights-goodbye-options > ul ').on('click', 'li label, li > input', function( e ){
1114 var parent = $(this).parents('li');
1115 parent.siblings().find('label').next('input, textarea').css('display', 'none');
1116 parent.find('label').next('input, textarea').css('display', 'block');
1117 });
1118 // If we click outside the form, the form will close
1119 $('.wpinsights-goodbye-form-bg, #wpinsights-goodbye-form > .betterdocs__modal-close-btn').on('click',function(){
1120 $("#wpinsights-goodbye-form").fadeOut();
1121 $('body').removeClass('wpinsights-form-active-<?php echo esc_attr( $class_plugin_name ); ?>');
1122 });
1123 });
1124 });
1125 </script>
1126 <?php }
1127 }
1128