PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.11
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.11
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / library / appsero / Insights.php

Insights.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.6.11, at includes/library/appsero/Insights.php

876 lines 27.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Appsero;
3
4 /**
5 * Appsero Insights
6 *
7 * This is a tracker class to track plugin usage based on if the customer has opted in.
8 * No personal information is being tracked by this class, only general settings, active plugins, environment details
9 * and admin email.
10 */
11 class Insights {
12
13 /**
14 * The notice text
15 *
16 * @var string
17 */
18 public $notice;
19
20 /**
21 * Wheather to the notice or not
22 *
23 * @var boolean
24 */
25 protected $show_notice = true;
26
27 /**
28 * If extra data needs to be sent
29 *
30 * @var array
31 */
32 protected $extra_data = array();
33
34 /**
35 * AppSero\Client
36 *
37 * @var object
38 */
39 protected $client;
40
41 /**
42 * Initialize the class
43 *
44 * @param AppSero\Client
45 */
46 public function __construct( $client, $name = null, $file = null ) {
47
48 if ( is_string( $client ) && ! empty( $name ) && ! empty( $file ) ) {
49 $client = new Client( $client, $name, $file );
50 }
51
52 if ( is_object( $client ) && is_a( $client, 'Appsero\Client' ) ) {
53 $this->client = $client;
54 }
55 }
56
57 /**
58 * Don't show the notice
59 *
60 * @return \self
61 */
62 public function hide_notice() {
63 $this->show_notice = false;
64
65 return $this;
66 }
67
68 /**
69 * Add extra data if needed
70 *
71 * @param array $data
72 *
73 * @return \self
74 */
75 public function add_extra( $data = array() ) {
76 $this->extra_data = $data;
77
78 return $this;
79 }
80
81 /**
82 * Set custom notice text
83 *
84 * @param string $text
85 *
86 * @return \self
87 */
88 public function notice( $text ) {
89 $this->notice = $text;
90
91 return $this;
92 }
93
94 /**
95 * Initialize insights
96 *
97 * @return void
98 */
99 public function init() {
100 if ( $this->client->type == 'plugin' ) {
101 $this->init_plugin();
102 } else if ( $this->client->type == 'theme' ) {
103 $this->init_theme();
104 }
105 }
106
107 /**
108 * Initialize theme hooks
109 *
110 * @return void
111 */
112 public function init_theme() {
113 $this->init_common();
114
115 add_action( 'switch_theme', array( $this, 'deactivation_cleanup' ) );
116 add_action( 'switch_theme', array( $this, 'theme_deactivated' ), 12, 3 );
117 }
118
119 /**
120 * Initialize plugin hooks
121 *
122 * @return void
123 */
124 public function init_plugin() {
125 // plugin deactivate popup
126 if ( ! $this->is_local_server() ) {
127 add_filter( 'plugin_action_links_' . $this->client->basename, array( $this, 'plugin_action_links' ) );
128 add_action( 'admin_footer', array( $this, 'deactivate_scripts' ) );
129 }
130
131 $this->init_common();
132
133 register_activation_hook( $this->client->file, array( $this, 'activate_plugin' ) );
134 register_deactivation_hook( $this->client->file, array( $this, 'deactivation_cleanup' ) );
135 }
136
137 /**
138 * Initialize common hooks
139 *
140 * @return void
141 */
142 protected function init_common() {
143 add_action( 'admin_init', array( $this, 'handle_optin_optout' ) );
144
145 // uninstall reason
146 add_action( 'wp_ajax_' . $this->client->slug . '_submit-uninstall-reason', array( $this, 'uninstall_reason_submission' ) );
147
148 // cron events
149 add_filter( 'cron_schedules', array( $this, 'add_weekly_schedule' ) );
150 add_action( $this->client->slug . '_tracker_send_event', array( $this, 'send_tracking_data' ) );
151 // add_action( 'admin_init', array( $this, 'send_tracking_data' ) ); // test
152 }
153
154 /**
155 * Send tracking data to AppSero server
156 *
157 * @param boolean $override
158 *
159 * @return void
160 */
161 public function send_tracking_data( $override = false ) {
162 // skip on AJAX Requests
163 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
164 return;
165 }
166
167 if ( ! $this->tracking_allowed() && ! $override ) {
168 return;
169 }
170
171 // Send a maximum of once per week
172 $last_send = $this->get_last_send();
173
174 if ( $last_send && $last_send > strtotime( '-1 week' ) ) {
175 return;
176 }
177
178 $response = $this->client->send_request( $this->get_tracking_data(), 'track' );
179
180 update_option( $this->client->slug . '_tracking_last_send', time() );
181 }
182
183 /**
184 * Get the tracking data points
185 *
186 * @return array
187 */
188 protected function get_tracking_data() {
189 $all_plugins = $this->get_all_plugins();
190
191 $users = get_users( array(
192 'role' => 'administrator',
193 'orderby' => 'ID',
194 'order' => 'ASC',
195 'number' => 1,
196 'paged' => 1,
197 ) );
198
199 $admin_user = ( is_array( $users ) && ! empty( $users ) ) ? $users[0] : false;
200 $first_name = $last_name = '';
201
202 if ( $admin_user ) {
203 $first_name = $admin_user->first_name ? $admin_user->first_name : $admin_user->display_name;
204 $last_name = $admin_user->last_name;
205 }
206
207 $data = array(
208 'version' => $this->client->project_version,
209 'url' => esc_url( home_url() ),
210 'site' => $this->get_site_name(),
211 'admin_email' => get_option( 'admin_email' ),
212 'first_name' => $first_name,
213 'last_name' => $last_name,
214 'hash' => $this->client->hash,
215 'server' => $this->get_server_info(),
216 'wp' => $this->get_wp_info(),
217 'users' => $this->get_user_counts(),
218 'active_plugins' => count( $all_plugins['active_plugins'] ),
219 'inactive_plugins' => count( $all_plugins['inactive_plugins'] ),
220 'ip_address' => $this->get_user_ip_address(),
221 'theme' => get_stylesheet(),
222 'version' => $this->client->project_version,
223 );
224
225 // Add metadata
226 if ( $extra = $this->get_extra_data() ) {
227 $data['extra'] = $extra;
228 }
229
230 return apply_filters( $this->client->slug . '_tracker_data', $data );
231 }
232
233 /**
234 * If a child class wants to send extra data
235 *
236 * @return mixed
237 */
238 protected function get_extra_data() {
239 if ( is_callable( $this->extra_data ) ) {
240 return call_user_func( $this->extra_data );
241 }
242
243 if ( is_array( $this->extra_data ) ) {
244 return $this->extra_data;
245 }
246
247 return array();
248 }
249
250 /**
251 * Explain the user which data we collect
252 *
253 * @return string
254 */
255 protected function data_we_collect() {
256 $data = array(
257 'Server environment details (php, mysql, server, WordPress versions)',
258 'Number of users in your site',
259 'Site language',
260 'Number of active and inactive plugins',
261 'Site name and url',
262 'Your name and email address',
263 );
264
265 return $data;
266 }
267
268 /**
269 * Check if the user has opted into tracking
270 *
271 * @return bool
272 */
273 public function tracking_allowed() {
274 $allow_tracking = get_option( $this->client->slug . '_allow_tracking', 'no' );
275
276 return $allow_tracking == 'yes';
277 }
278
279 /**
280 * Get the last time a tracking was sent
281 *
282 * @return false|string
283 */
284 private function get_last_send() {
285 return get_option( $this->client->slug . '_tracking_last_send', false );
286 }
287
288 /**
289 * Check if the notice has been dismissed or enabled
290 *
291 * @return boolean
292 */
293 private function notice_dismissed() {
294 $version = get_option( $this->client->slug . '_hide_fortressdb_version', null );
295 $current_version = get_option( 'weforms_version' );
296
297 if ( $version && version_compare( $current_version, $version, '<=' ) ) {
298 return true;
299 }
300
301 return false;
302 }
303
304 /**
305 * Check if the current server is localhost
306 *
307 * @return boolean
308 */
309 private function is_local_server() {
310 return false;
311
312 $is_local = in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ) );
313
314 return apply_filters( 'appsero_is_local', $is_local );
315 }
316
317 /**
318 * Schedule the event weekly
319 *
320 * @return void
321 */
322 private function schedule_event() {
323 $hook_name = $this->client->slug . '_tracker_send_event';
324
325 if ( ! wp_next_scheduled( $hook_name ) ) {
326 wp_schedule_event( time(), 'weekly', $hook_name );
327 }
328 }
329
330 /**
331 * Clear any scheduled hook
332 *
333 * @return void
334 */
335 private function clear_schedule_event() {
336 wp_clear_scheduled_hook( $this->client->slug . '_tracker_send_event' );
337 }
338
339 /**
340 * handle the optin/optout
341 *
342 * @return void
343 */
344 public function handle_optin_optout() {
345
346 if ( isset( $_GET[ $this->client->slug . '_hide_fortressdb' ] ) && $_GET[ $this->client->slug . '_hide_fortressdb' ] == 'true' ) {
347 $current_version = get_option( 'weforms_version' );
348 update_option( $this->client->slug . '_hide_fortressdb_version', $current_version );
349
350 wp_redirect( remove_query_arg( $this->client->slug . '_hide_fortressdb' ) );
351 exit;
352 }
353 }
354
355 /**
356 * Get the number of post counts
357 *
358 * @param string $post_type
359 *
360 * @return integer
361 */
362 public function get_post_count( $post_type ) {
363 global $wpdb;
364
365 return (int) $wpdb->get_var( "SELECT count(ID) FROM $wpdb->posts WHERE post_type = '$post_type' and post_status = 'publish'");
366 }
367
368 /**
369 * Get server related info.
370 *
371 * @return array
372 */
373 private static function get_server_info() {
374 global $wpdb;
375
376 $server_data = array();
377
378 if ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
379 $server_data['software'] = $_SERVER['SERVER_SOFTWARE'];
380 }
381
382 if ( function_exists( 'phpversion' ) ) {
383 $server_data['php_version'] = phpversion();
384 }
385
386 $server_data['mysql_version'] = $wpdb->db_version();
387
388 $server_data['php_max_upload_size'] = size_format( wp_max_upload_size() );
389 $server_data['php_default_timezone'] = date_default_timezone_get();
390 $server_data['php_soap'] = class_exists( 'SoapClient' ) ? 'Yes' : 'No';
391 $server_data['php_fsockopen'] = function_exists( 'fsockopen' ) ? 'Yes' : 'No';
392 $server_data['php_curl'] = function_exists( 'curl_init' ) ? 'Yes' : 'No';
393
394 return $server_data;
395 }
396
397 /**
398 * Get WordPress related data.
399 *
400 * @return array
401 */
402 private function get_wp_info() {
403 $wp_data = array();
404
405 $wp_data['memory_limit'] = WP_MEMORY_LIMIT;
406 $wp_data['debug_mode'] = ( defined('WP_DEBUG') && WP_DEBUG ) ? 'Yes' : 'No';
407 $wp_data['locale'] = get_locale();
408 $wp_data['version'] = get_bloginfo( 'version' );
409 $wp_data['multisite'] = is_multisite() ? 'Yes' : 'No';
410
411 return $wp_data;
412 }
413
414 /**
415 * Get the list of active and inactive plugins
416 *
417 * @return array
418 */
419 private function get_all_plugins() {
420 // Ensure get_plugins function is loaded
421 if ( ! function_exists( 'get_plugins' ) ) {
422 include ABSPATH . '/wp-admin/includes/plugin.php';
423 }
424
425 $plugins = get_plugins();
426 $active_plugins_keys = get_option( 'active_plugins', array() );
427 $active_plugins = array();
428
429 foreach ( $plugins as $k => $v ) {
430 // Take care of formatting the data how we want it.
431 $formatted = array();
432 $formatted['name'] = strip_tags( $v['Name'] );
433
434 if ( isset( $v['Version'] ) ) {
435 $formatted['version'] = strip_tags( $v['Version'] );
436 }
437
438 if ( isset( $v['Author'] ) ) {
439 $formatted['author'] = strip_tags( $v['Author'] );
440 }
441
442 if ( isset( $v['Network'] ) ) {
443 $formatted['network'] = strip_tags( $v['Network'] );
444 }
445
446 if ( isset( $v['PluginURI'] ) ) {
447 $formatted['plugin_uri'] = strip_tags( $v['PluginURI'] );
448 }
449
450 if ( in_array( $k, $active_plugins_keys ) ) {
451 // Remove active plugins from list so we can show active and inactive separately
452 unset( $plugins[$k] );
453 $active_plugins[$k] = $formatted;
454 } else {
455 $plugins[$k] = $formatted;
456 }
457 }
458
459 return array( 'active_plugins' => $active_plugins, 'inactive_plugins' => $plugins );
460 }
461
462 /**
463 * Get user totals based on user role.
464 *
465 * @return array
466 */
467 public function get_user_counts() {
468 $user_count = array();
469 $user_count_data = count_users();
470 $user_count['total'] = $user_count_data['total_users'];
471
472 // Get user count based on user role
473 foreach ( $user_count_data['avail_roles'] as $role => $count ) {
474 $user_count[ $role ] = $count;
475 }
476
477 return $user_count;
478 }
479
480 /**
481 * Add weekly cron schedule
482 *
483 * @param array $schedules
484 *
485 * @return array
486 */
487 public function add_weekly_schedule( $schedules ) {
488
489 $schedules['weekly'] = array(
490 'interval' => DAY_IN_SECONDS * 7,
491 'display' => 'Once Weekly',
492 );
493
494 return $schedules;
495 }
496
497 /**
498 * Plugin activation hook
499 *
500 * @return void
501 */
502 public function activate_plugin() {
503 $allowed = get_option( $this->client->slug . '_allow_tracking', 'no' );
504
505 // if it wasn't allowed before, do nothing
506 if ( 'yes' !== $allowed ) {
507 return;
508 }
509
510 // re-schedule and delete the last sent time so we could force send again
511 $hook_name = $this->client->slug . '_tracker_send_event';
512 if ( ! wp_next_scheduled( $hook_name ) ) {
513 wp_schedule_event( time(), 'weekly', $hook_name );
514 }
515
516 delete_option( $this->client->slug . '_tracking_last_send' );
517
518 $this->send_tracking_data( true );
519 }
520
521 /**
522 * Clear our options upon deactivation
523 *
524 * @return void
525 */
526 public function deactivation_cleanup() {
527 $this->clear_schedule_event();
528
529 if ( 'theme' == $this->client->type ) {
530 delete_option( $this->client->slug . '_tracking_last_send' );
531 delete_option( $this->client->slug . '_allow_tracking' );
532 }
533
534 delete_option( $this->client->slug . '_tracking_notice' );
535 }
536
537 /**
538 * Hook into action links and modify the deactivate link
539 *
540 * @param array $links
541 *
542 * @return array
543 */
544 public function plugin_action_links( $links ) {
545
546 if ( array_key_exists( 'deactivate', $links ) ) {
547 $links['deactivate'] = str_replace( '<a', '<a class="' . $this->client->slug . '-deactivate-link"', $links['deactivate'] );
548 }
549
550 return $links;
551 }
552
553 private function get_uninstall_reasons() {
554 $reasons = array(
555 array(
556 'id' => 'could-not-understand',
557 'text' => 'I couldn\'t understand how to make it work',
558 'type' => 'textarea',
559 'placeholder' => 'Would you like us to assist you?'
560 ),
561 array(
562 'id' => 'found-better-plugin',
563 'text' => 'I found a better plugin',
564 'type' => 'text',
565 'placeholder' => 'Which plugin?'
566 ),
567 array(
568 'id' => 'not-have-that-feature',
569 'text' => 'The plugin is great, but I need specific feature that you don\'t support',
570 'type' => 'textarea',
571 'placeholder' => 'Could you tell us more about that feature?'
572 ),
573 array(
574 'id' => 'is-not-working',
575 'text' => 'The plugin is not working',
576 'type' => 'textarea',
577 'placeholder' => 'Could you tell us a bit more whats not working?'
578 ),
579 array(
580 'id' => 'looking-for-other',
581 'text' => 'It\'s not what I was looking for',
582 'type' => '',
583 'placeholder' => ''
584 ),
585 array(
586 'id' => 'did-not-work-as-expected',
587 'text' => 'The plugin didn\'t work as expected',
588 'type' => 'textarea',
589 'placeholder' => 'What did you expect?'
590 ),
591 array(
592 'id' => 'other',
593 'text' => 'Other',
594 'type' => 'textarea',
595 'placeholder' => 'Could you tell us a bit more?'
596 ),
597 );
598
599 return $reasons;
600 }
601
602 /**
603 * Plugin deactivation uninstall reason submission
604 *
605 * @return void
606 */
607 public function uninstall_reason_submission() {
608
609 if ( ! isset( $_POST['reason_id'] ) ) {
610 wp_send_json_error();
611 }
612
613 $current_user = wp_get_current_user();
614
615 $data = array(
616 'hash' => $this->client->hash,
617 'reason_id' => sanitize_text_field( $_POST['reason_id'] ),
618 'reason_info' => isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '',
619 'site' => $this->get_site_name(),
620 'url' => esc_url( home_url() ),
621 'admin_email' => get_option( 'admin_email' ),
622 'user_email' => $current_user->user_email,
623 'first_name' => $current_user->first_name,
624 'last_name' => $current_user->last_name,
625 'server' => $this->get_server_info(),
626 'wp' => $this->get_wp_info(),
627 'ip_address' => $this->get_user_ip_address(),
628 'theme' => get_stylesheet(),
629 'version' => $this->client->project_version,
630 );
631
632 // Add metadata
633 if ( $extra = $this->get_extra_data() ) {
634 $data['extra'] = $extra;
635 }
636
637 $this->client->send_request( $data, 'deactivate' );
638
639 wp_send_json_success();
640 }
641
642 /**
643 * Handle the plugin deactivation feedback
644 *
645 * @return void
646 */
647 public function deactivate_scripts() {
648 global $pagenow;
649
650 if ( 'plugins.php' != $pagenow ) {
651 return;
652 }
653
654 $reasons = $this->get_uninstall_reasons();
655 ?>
656
657 <div class="wd-dr-modal" id="<?php echo $this->client->slug; ?>-wd-dr-modal">
658 <div class="wd-dr-modal-wrap">
659 <div class="wd-dr-modal-header">
660 <h3><?php _e( 'If you have a moment, please let us know why you are deactivating:', $this->client->textdomain, 'weforms' ); ?></h3>
661 </div>
662
663 <div class="wd-dr-modal-body">
664 <ul class="reasons">
665 <?php foreach ($reasons as $reason) { ?>
666 <li data-type="<?php echo esc_attr( $reason['type'] ); ?>" data-placeholder="<?php echo esc_attr( $reason['placeholder'] ); ?>">
667 <label><input type="radio" name="selected-reason" value="<?php echo $reason['id']; ?>"> <?php echo $reason['text']; ?></label>
668 </li>
669 <?php } ?>
670 </ul>
671 <p class="wd-dr-modal-reasons-bottom">We share your data with <a href="https://appsero.com/">Appsero</a> to troubleshoot problems &amp; make product improvements. <a href="https://appsero.com/privacy-policy/">Learn more</a> about how Appsero handles your data.</p>
672 </div>
673
674 <div class="wd-dr-modal-footer">
675 <a href="#" class="dont-bother-me"><?php _e( 'I rather wouldn\'t say', $this->client->textdomain, 'weforms' ); ?></a>
676 <button class="button-secondary"><?php _e( 'Submit & Deactivate', $this->client->textdomain, 'weforms' ); ?></button>
677 <button class="button-primary"><?php _e( 'Cancel', $this->client->textdomain, 'weforms' ); ?></button>
678 </div>
679 </div>
680 </div>
681
682 <style type="text/css">
683 .wd-dr-modal {
684 position: fixed;
685 z-index: 99999;
686 top: 0;
687 right: 0;
688 bottom: 0;
689 left: 0;
690 background: rgba(0,0,0,0.5);
691 display: none;
692 }
693
694 .wd-dr-modal.modal-active {
695 display: block;
696 }
697
698 .wd-dr-modal-wrap {
699 width: 475px;
700 position: relative;
701 margin: 10% auto;
702 background: #fff;
703 }
704
705 .wd-dr-modal-header {
706 border-bottom: 1px solid #eee;
707 padding: 8px 20px;
708 }
709
710 .wd-dr-modal-header h3 {
711 line-height: 150%;
712 margin: 0;
713 }
714
715 .wd-dr-modal-body {
716 padding: 5px 20px 20px 20px;
717 }
718
719 .wd-dr-modal-body .reason-input {
720 margin-top: 5px;
721 margin-left: 20px;
722 }
723 .wd-dr-modal-footer {
724 border-top: 1px solid #eee;
725 padding: 12px 20px;
726 text-align: right;
727 }
728 .wd-dr-modal-reasons-bottom {
729 margin: 15px 0 0 0;
730 }
731 </style>
732
733 <script type="text/javascript">
734 (function($) {
735 $(function() {
736 var modal = $( '#<?php echo $this->client->slug; ?>-wd-dr-modal' );
737 var deactivateLink = '';
738
739 $( '#the-list' ).on('click', 'a.<?php echo $this->client->slug; ?>-deactivate-link', function(e) {
740 e.preventDefault();
741
742 modal.addClass('modal-active');
743 deactivateLink = $(this).attr('href');
744 modal.find('a.dont-bother-me').attr('href', deactivateLink).css('float', 'left');
745 });
746
747 modal.on('click', 'button.button-primary', function(e) {
748 e.preventDefault();
749
750 modal.removeClass('modal-active');
751 });
752
753 modal.on('click', 'input[type="radio"]', function () {
754 var parent = $(this).parents('li:first');
755
756 modal.find('.reason-input').remove();
757
758 var inputType = parent.data('type'),
759 inputPlaceholder = parent.data('placeholder'),
760 reasonInputHtml = '<div class="reason-input">' + ( ( 'text' === inputType ) ? '<input type="text" size="40" />' : '<textarea rows="5" cols="45"></textarea>' ) + '</div>';
761
762 if ( inputType !== '' ) {
763 parent.append( $(reasonInputHtml) );
764 parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
765 }
766 });
767
768 modal.on('click', 'button.button-secondary', function(e) {
769 e.preventDefault();
770
771 var button = $(this);
772
773 if ( button.hasClass('disabled') ) {
774 return;
775 }
776
777 var $radio = $( 'input[type="radio"]:checked', modal );
778
779 var $selected_reason = $radio.parents('li:first'),
780 $input = $selected_reason.find('textarea, input[type="text"]');
781
782 $.ajax({
783 url: ajaxurl,
784 type: 'POST',
785 data: {
786 action: '<?php echo $this->client->slug; ?>_submit-uninstall-reason',
787 reason_id: ( 0 === $radio.length ) ? 'none' : $radio.val(),
788 reason_info: ( 0 !== $input.length ) ? $input.val().trim() : ''
789 },
790 beforeSend: function() {
791 button.addClass('disabled');
792 button.text('Processing...');
793 },
794 complete: function() {
795 window.location.href = deactivateLink;
796 }
797 });
798 });
799 });
800 }(jQuery));
801 </script>
802
803 <?php
804 }
805
806 /**
807 * Run after theme deactivated
808 * @param string $new_name
809 * @param object $new_theme
810 * @param object $old_theme
811 * @return void
812 */
813 public function theme_deactivated( $new_name, $new_theme, $old_theme ) {
814 // Make sure this is appsero theme
815 if ( $old_theme->get_template() == $this->client->slug ) {
816 $current_user = wp_get_current_user();
817
818 $data = array(
819 'hash' => $this->client->hash,
820 'reason_id' => 'none',
821 'reason_info' => '',
822 'site' => $this->get_site_name(),
823 'url' => esc_url( home_url() ),
824 'admin_email' => get_option( 'admin_email' ),
825 'user_email' => $current_user->user_email,
826 'first_name' => $current_user->first_name,
827 'last_name' => $current_user->last_name,
828 'server' => $this->get_server_info(),
829 'wp' => $this->get_wp_info(),
830 'ip_address' => $this->get_user_ip_address(),
831 'theme' => get_stylesheet(),
832 'version' => $this->client->project_version,
833 );
834
835 $this->client->send_request( $data, 'deactivate' );
836 }
837 }
838
839 /**
840 * Get user IP Address
841 */
842 private function get_user_ip_address() {
843 $response = wp_remote_get( 'https://icanhazip.com/' );
844
845 if ( is_wp_error( $response ) ) {
846 return '';
847 }
848
849 $ip = trim( wp_remote_retrieve_body( $response ) );
850
851 if ( ! filter_var( $ip, FILTER_VALIDATE_IP ) ) {
852 return '';
853 }
854
855 return $ip;
856 }
857
858 /**
859 * Get site name
860 */
861 private function get_site_name() {
862 $site_name = get_bloginfo( 'name' );
863
864 if ( empty( $site_name ) ) {
865 $site_name = get_bloginfo( 'description' );
866 $site_name = wp_trim_words( $site_name, 3, '' );
867 }
868
869 if ( empty( $site_name ) ) {
870 $site_name = get_bloginfo( 'url' );
871 }
872
873 return $site_name;
874 }
875 }
876