PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.8
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / vendor / codeinwp / themeisle-sdk / src / Modules / Uninstall_feedback.php

Uninstall_feedback.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.8, at vendor/codeinwp/themeisle-sdk/src/Modules/Uninstall_feedback.php

853 lines 23.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The deactivate feedback model class for ThemeIsle SDK
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Feedback
7 * @copyright Copyright (c) 2017, Marius Cristea
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 1.0.0
10 */
11
12 namespace ThemeisleSDK\Modules;
13
14 use ThemeisleSDK\Common\Abstract_Module;
15 use ThemeisleSDK\Product;
16
17 // Exit if accessed directly.
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Uninstall feedback module for ThemeIsle SDK.
24 */
25 class Uninstall_Feedback extends Abstract_Module {
26 /**
27 * How many seconds before the deactivation window is triggered for themes?
28 *
29 * @var int Number of days.
30 */
31 const AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS = 3;
32 /**
33 * How many days before the deactivation window pops up again for the theme?
34 *
35 * @var int Number of days.
36 */
37 const PAUSE_DEACTIVATE_WINDOW_DAYS = 100;
38 /**
39 * Where to send the data.
40 *
41 * @var string Endpoint url.
42 */
43 const FEEDBACK_ENDPOINT = 'https://api.themeisle.com/tracking/uninstall';
44
45 /**
46 * Default options for plugins.
47 *
48 * @var array $options_plugin The main options list for plugins.
49 */
50 private $options_plugin = array(
51 'I found a better plugin' => array(
52 'id' => 3,
53 'type' => 'text',
54 'placeholder' => 'What\'s the plugin\'s name?',
55 ),
56 'I could not get the plugin to work' => array(
57 'type' => 'textarea',
58 'placeholder' => 'What problem are you experiencing?',
59 'id' => 4,
60 ),
61 'I no longer need the plugin' => array(
62 'id' => 5,
63 'type' => 'textarea',
64 'placeholder' => 'If you could improve one thing about our product, what would it be?',
65 ),
66 'It\'s a temporary deactivation. I\'m just debugging an issue.' => array(
67 'type' => 'textarea',
68 'placeholder' => 'What problem are you experiencing?',
69 'id' => 6,
70 ),
71 );
72 /**
73 * Default options for theme.
74 *
75 * @var array $options_theme The main options list for themes.
76 */
77 private $options_theme = array(
78 'I don\'t know how to make it look like demo' => array(
79 'id' => 7,
80 ),
81 'It lacks options' => array(
82 'placeholder' => 'What option is missing?',
83 'type' => 'text',
84 'id' => 8,
85 ),
86 'Is not working with a plugin that I need' => array(
87 'id' => 9,
88 'type' => 'text',
89 'placeholder' => 'What is the name of the plugin',
90 ),
91 'I want to try a new design, I don\'t like {theme} style' => array(
92 'id' => 10,
93 ),
94 );
95 /**
96 * Default other option.
97 *
98 * @var array $other The other option
99 */
100 private $other = array(
101 'Other' => array(
102 'id' => 999,
103 'type' => 'textarea',
104 'placeholder' => 'What can we do better?',
105 ),
106 );
107 /**
108 * Default heading for plugin.
109 *
110 * @var string $heading_plugin The heading of the modal
111 */
112 private $heading_plugin = 'What\'s wrong?';
113 /**
114 * Default heading for theme.
115 *
116 * @var string $heading_theme The heading of the modal
117 */
118 private $heading_theme = 'What does not work for you in {theme}?';
119 /**
120 * Default submit button action text.
121 *
122 * @var string $button_submit The text of the deactivate button
123 */
124 private $button_submit = 'Submit &amp; Deactivate';
125 /**
126 * Default cancel button.
127 *
128 * @var string $button_cancel The text of the cancel button
129 */
130 private $button_cancel = 'Skip &amp; Deactivate';
131
132 /**
133 * Loads the additional resources
134 */
135 function load_resources() {
136 $screen = get_current_screen();
137
138 if ( ! $screen || ! in_array( $screen->id, array( 'theme-install', 'plugins' ) ) ) {
139 return;
140 }
141
142 $this->add_feedback_popup_style();
143
144 if ( $this->product->get_type() === 'theme' ) {
145 $this->add_theme_feedback_drawer_js();
146 $this->render_theme_feedback_popup();
147
148 return;
149 }
150 $this->add_plugin_feedback_popup_js();
151 $this->render_plugin_feedback_popup();
152 }
153
154 /**
155 * Render theme feedback drawer.
156 */
157 private function render_theme_feedback_popup() {
158 $heading = str_replace( '{theme}', $this->product->get_name(), $this->heading_theme );
159 $button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', 'Submit' );
160 $options = $this->options_theme;
161 $options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $options ) );
162 $info_disclosure_link = '<a href="#" class="info-disclosure-link">' . apply_filters( $this->product->get_slug() . '_themeisle_sdk_info_collect_cta', 'What info do we collect?' ) . '</a>';
163
164 $options += $this->other;
165
166 ?>
167 <div class="ti-theme-uninstall-feedback-drawer ti-feedback">
168 <div class="popup--header">
169 <h5><?php echo wp_kses( $heading, array( 'span' => true ) ); ?> </h5>
170 <button class="toggle"><span>&times;</span></button>
171 </div><!--/.popup--header-->
172 <div class="popup--body">
173 <?php $this->render_options_list( $options ); ?>
174 </div><!--/.popup--body-->
175 <div class="popup--footer">
176 <div class="actions">
177 <?php
178 echo wp_kses_post( $info_disclosure_link );
179 echo wp_kses_post( $this->get_disclosure_labels() );
180 echo '<div class="buttons">';
181 echo get_submit_button(
182 $button_submit,
183 'secondary',
184 $this->product->get_key() . 'ti-deactivate-yes',
185 false,
186 array(
187 'data-after-text' => $button_submit,
188 'disabled' => true,
189 )
190 );
191 echo '</div>';
192 ?>
193 </div><!--/.actions-->
194 </div><!--/.popup--footer-->
195 </div>
196 <?php
197 }
198
199 /**
200 * Add feedback styles.
201 */
202 private function add_feedback_popup_style() {
203 ?>
204 <style>
205 .ti-feedback {
206 background: #fff;
207 max-width: 400px;
208 z-index: 10000;
209 box-shadow: 0 0 15px -5px rgba(0, 0, 0, .5);
210 transition: all .3s ease-out;
211 }
212
213
214 .ti-feedback .popup--header {
215 position: relative;
216 background-color: #23A1CE;
217 }
218
219 .ti-feedback .popup--header h5 {
220 margin: 0;
221 font-size: 16px;
222 padding: 15px;
223 color: #fff;
224 font-weight: 600;
225 text-align: center;
226 letter-spacing: .3px;
227 }
228
229 .ti-feedback .popup--body {
230 padding: 15px;
231 }
232
233 .ti-feedback .popup--form {
234 margin: 0;
235 font-size: 13px;
236 }
237
238 .ti-feedback .popup--form input[type="radio"] {
239 margin: 0 10px 0 0;
240 }
241
242 .ti-feedback .popup--form input[type="radio"]:checked ~ textarea {
243 display: block;
244 }
245
246 .ti-feedback .popup--form textarea {
247 width: 100%;
248 margin: 10px 0 0;
249 display: none;
250 max-height: 150px;
251 }
252
253 .ti-feedback li {
254 display: flex;
255 align-items: center;
256 margin-bottom: 15px;
257 flex-wrap: wrap;
258 }
259
260 .ti-feedback li label {
261 max-width: 90%;
262 }
263
264 .ti-feedback li:last-child {
265 margin-bottom: 0;
266 }
267
268 .ti-feedback .popup--footer {
269 padding: 0 15px 15px;
270 }
271
272 .ti-feedback .actions {
273 display: flex;
274 flex-wrap: wrap;
275 }
276
277 .info-disclosure-link {
278 width: 100%;
279 margin-bottom: 15px;
280 }
281
282 .ti-feedback .info-disclosure-content {
283 max-height: 0;
284 overflow: hidden;
285 width: 100%;
286 transition: .3s ease;
287 }
288
289 .ti-feedback .info-disclosure-content.active {
290 max-height: 300px;
291 }
292
293 .ti-feedback .info-disclosure-content p {
294 margin: 0;
295 }
296
297 .ti-feedback .info-disclosure-content ul {
298 margin: 10px 0;
299 border-radius: 3px;
300 }
301
302 .ti-feedback .info-disclosure-content ul li {
303 display: flex;
304 align-items: center;
305 justify-content: space-between;
306 margin-bottom: 0;
307 padding: 5px 0;
308 border-bottom: 1px solid #ccc;
309 }
310
311 .ti-feedback .buttons {
312 display: flex;
313 width: 100%;
314 }
315
316 .ti-feedback .buttons input:last-child {
317 margin-left: auto;
318 }
319
320 .ti-theme-uninstall-feedback-drawer {
321 border-top-left-radius: 5px;
322 position: fixed;
323 top: 100%;
324 right: 15px;
325 }
326
327 .ti-theme-uninstall-feedback-drawer.active {
328 transform: translateY(-100%);
329 }
330
331 .ti-theme-uninstall-feedback-drawer .popup--header {
332 border-top-left-radius: 5px;
333 }
334
335 .ti-theme-uninstall-feedback-drawer .popup--header .toggle {
336 position: absolute;
337 padding: 3px 0;
338 width: 30px;
339 top: -26px;
340 right: 0;
341 cursor: pointer;
342 border-top-left-radius: 5px;
343 border-top-right-radius: 5px;
344 font-size: 20px;
345 background-color: #23A1CE;
346 color: #fff;
347 border: none;
348 line-height: 20px;
349 }
350
351 .ti-theme-uninstall-feedback-drawer .toggle span {
352 margin: 0;
353 display: inline-block;
354 }
355
356 .ti-theme-uninstall-feedback-drawer:not(.active) .toggle span {
357 transform: rotate(45deg);
358 }
359
360 .ti-theme-uninstall-feedback-drawer .popup--header .toggle:hover {
361 background-color: #1880a5;
362 }
363
364
365 .ti-plugin-uninstall-feedback-popup .popup--header:before {
366 content: "";
367 display: block;
368 position: absolute;
369 border: 20px solid #23A1CE;
370 left: -10px;
371 top: 50%;
372 border-top: 20px solid transparent;
373 border-bottom: 20px solid transparent;
374 border-left: 0;
375 transform: translateY(-50%);
376 }
377
378 .ti-plugin-uninstall-feedback-popup {
379 display: none;
380 position: absolute;
381 white-space: normal;
382 width: 400px;
383 left: 100%;
384 top: -15px;
385 }
386
387 .ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i {
388 animation: rotation 2s infinite linear;
389 display: block;
390 float: none;
391 align-items: center;
392 width: 100%;
393 margin: 0 auto;
394 height: 100%;
395 background: transparent;
396 padding: 0;
397 }
398
399 .ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i:before {
400 padding: 0;
401 background: transparent;
402 box-shadow: none;
403 color: #b4b9be
404 }
405
406
407 .ti-plugin-uninstall-feedback-popup.active {
408 display: block;
409 }
410
411 tr[data-plugin^="<?php echo $this->product->get_slug(); ?>"] .deactivate {
412 position: relative;
413 }
414
415 body.ti-feedback-open .ti-feedback-overlay {
416 content: "";
417 display: block;
418 background-color: rgba(0, 0, 0, 0.5);
419 top: 0;
420 bottom: 0;
421 right: 0;
422 left: 0;
423 z-index: 10000;
424 position: fixed;
425 }
426
427 @media (max-width: 768px) {
428 .ti-plugin-uninstall-feedback-popup {
429 position: fixed;
430 max-width: 100%;
431 margin: 0 auto;
432 left: 50%;
433 top: 50px;
434 transform: translateX(-50%);
435 }
436
437 .ti-plugin-uninstall-feedback-popup .popup--header:before {
438 display: none;
439 }
440 }
441 </style>
442 <?php
443 }
444
445 /**
446 * Theme feedback drawer JS.
447 */
448 private function add_theme_feedback_drawer_js() {
449 $key = $this->product->get_key();
450 ?>
451 <script type="text/javascript" id="ti-deactivate-js">
452 (function ($) {
453 $(document).ready(function () {
454 setTimeout(function () {
455 $('.ti-theme-uninstall-feedback-drawer').addClass('active');
456 }, <?php echo absint( self::AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS * 1000 ); ?> );
457
458 $('.ti-theme-uninstall-feedback-drawer .toggle').on('click', function (e) {
459 e.preventDefault();
460 $('.ti-theme-uninstall-feedback-drawer').toggleClass('active');
461 });
462
463 $('.info-disclosure-link').on('click', function (e) {
464 e.preventDefault();
465 $('.info-disclosure-content').toggleClass('active');
466 });
467
468 $('.ti-theme-uninstall-feedback-drawer input[type="radio"]').on('change', function () {
469 var radio = $(this);
470 if (radio.parent().find('textarea').length > 0 &&
471 radio.parent().find('textarea').val().length === 0) {
472 $('#<?php echo $key; ?>ti-deactivate-yes').attr('disabled', 'disabled');
473 radio.parent().find('textarea').on('keyup', function (e) {
474 if ($(this).val().length === 0) {
475 $('#<?php echo $key; ?>ti-deactivate-yes').attr('disabled', 'disabled');
476 } else {
477 $('#<?php echo $key; ?>ti-deactivate-yes').removeAttr('disabled');
478 }
479 });
480 } else {
481 $('#<?php echo $key; ?>ti-deactivate-yes').removeAttr('disabled');
482 }
483 });
484
485 $('#<?php echo $key; ?>ti-deactivate-yes').on('click', function (e) {
486 e.preventDefault();
487 e.stopPropagation();
488
489 var selectedOption = $(
490 '.ti-theme-uninstall-feedback-drawer input[name="ti-deactivate-option"]:checked');
491 $.post(ajaxurl, {
492 'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>',
493 'nonce': '<?php echo wp_create_nonce( (string) __CLASS__ ); ?>',
494 'id': selectedOption.parent().attr('ti-option-id'),
495 'msg': selectedOption.parent().find('textarea').val(),
496 'type': 'theme',
497 'key': '<?php echo esc_attr( $key ); ?>'
498 });
499 $('.ti-theme-uninstall-feedback-drawer').fadeOut();
500 });
501 });
502 })(jQuery);
503
504 </script>
505 <?php
506 do_action( $this->product->get_key() . '_uninstall_feedback_after_js' );
507 }
508
509 /**
510 * Render the options list.
511 *
512 * @param array $options the options for the feedback form.
513 */
514 private function render_options_list( $options ) {
515 $key = $this->product->get_key();
516 $inputs_row_map = [
517 'text' => 1,
518 'textarea' => 2,
519 ];
520 ?>
521 <ul class="popup--form">
522 <?php foreach ( $options as $title => $attributes ) { ?>
523 <li ti-option-id="<?php echo esc_attr( $attributes['id'] ); ?>">
524 <input type="radio" name="ti-deactivate-option" id="<?php echo esc_attr( $key . $attributes['id'] ); ?>">
525 <label for="<?php echo esc_attr( $key . $attributes['id'] ); ?>">
526 <?php echo str_replace( '{theme}', $this->product->get_name(), $title ); ?>
527 </label>
528 <?php
529 if ( array_key_exists( 'type', $attributes ) ) {
530 $placeholder = array_key_exists( 'placeholder', $attributes ) ? $attributes['placeholder'] : '';
531 echo '<textarea width="100%" rows="' . $inputs_row_map[ $attributes['type'] ] . '" name="comments" placeholder="' . esc_attr( $placeholder ) . '"></textarea>';
532 }
533 ?>
534 </li>
535 <?php } ?>
536 </ul>
537 <?php
538 }
539
540 /**
541 * Render plugin feedback popup.
542 */
543 private function render_plugin_feedback_popup() {
544 $button_cancel = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_cancel', $this->button_cancel );
545 $button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', $this->button_submit );
546 $options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $this->options_plugin ) );
547 $info_disclosure_link = '<a href="#" class="info-disclosure-link">' . apply_filters( $this->product->get_slug() . '_themeisle_sdk_info_collect_cta', 'What info do we collect?' ) . '</a>';
548
549 $options += $this->other;
550 ?>
551 <div class="ti-plugin-uninstall-feedback-popup ti-feedback" id="<?php echo esc_attr( $this->product->get_slug() . '_uninstall_feedback_popup' ); ?>">
552 <div class="popup--header">
553 <h5><?php echo wp_kses( $this->heading_plugin, array( 'span' => true ) ); ?> </h5>
554 </div><!--/.popup--header-->
555 <div class="popup--body">
556 <?php $this->render_options_list( $options ); ?>
557 </div><!--/.popup--body-->
558 <div class="popup--footer">
559 <div class="actions">
560 <?php
561 echo wp_kses_post( $info_disclosure_link );
562 echo wp_kses_post( $this->get_disclosure_labels() );
563 echo '<div class="buttons">';
564 echo get_submit_button(
565 $button_cancel,
566 'secondary',
567 $this->product->get_key() . 'ti-deactivate-no',
568 false
569 );
570 echo get_submit_button(
571 $button_submit,
572 'primary',
573 $this->product->get_key() . 'ti-deactivate-yes',
574 false,
575 array(
576 'data-after-text' => $button_submit,
577 'disabled' => true,
578 )
579 );
580 echo '</div>';
581 ?>
582 </div><!--/.actions-->
583 </div><!--/.popup--footer-->
584 </div>
585
586 <?php
587 }
588
589 /**
590 * Add plugin feedback popup JS
591 */
592 private function add_plugin_feedback_popup_js() {
593 $popup_id = '#' . $this->product->get_slug() . '_uninstall_feedback_popup';
594 $key = $this->product->get_key();
595 ?>
596 <script type="text/javascript" id="ti-deactivate-js">
597 (function ($) {
598 $(document).ready(function () {
599 var targetElement = 'tr[data-plugin^="<?php echo $this->product->get_slug(); ?>/"] span.deactivate a';
600 var redirectUrl = $(targetElement).attr('href');
601 if ($('.ti-feedback-overlay').length === 0) {
602 $('body').prepend('<div class="ti-feedback-overlay"></div>');
603 }
604 $('<?php echo esc_attr( $popup_id ); ?> ').appendTo($(targetElement).parent());
605
606 $(targetElement).on('click', function (e) {
607 e.preventDefault();
608 $('<?php echo esc_attr( $popup_id ); ?> ').addClass('active');
609 $('body').addClass('ti-feedback-open');
610 $('.ti-feedback-overlay').on('click', function () {
611 $('<?php echo esc_attr( $popup_id ); ?> ').removeClass('active');
612 $('body').removeClass('ti-feedback-open');
613 });
614 });
615
616 $('<?php echo esc_attr( $popup_id ); ?> .info-disclosure-link').on('click', function (e) {
617 e.preventDefault();
618 $(this).parent().find('.info-disclosure-content').toggleClass('active');
619 });
620
621 $('<?php echo esc_attr( $popup_id ); ?> input[type="radio"]').on('change', function () {
622 var radio = $(this);
623 if (radio.parent().find('textarea').length > 0 &&
624 radio.parent().find('textarea').val().length === 0) {
625 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo $key; ?>ti-deactivate-yes').attr('disabled', 'disabled');
626 radio.parent().find('textarea').on('keyup', function (e) {
627 if ($(this).val().length === 0) {
628 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo $key; ?>ti-deactivate-yes').attr('disabled', 'disabled');
629 } else {
630 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo $key; ?>ti-deactivate-yes').removeAttr('disabled');
631 }
632 });
633 } else {
634 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo $key; ?>ti-deactivate-yes').removeAttr('disabled');
635 }
636 });
637
638 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo $key; ?>ti-deactivate-no').on('click', function (e) {
639 e.preventDefault();
640 e.stopPropagation();
641 $(targetElement).unbind('click');
642 $('body').removeClass('ti-feedback-open');
643 $('<?php echo esc_attr( $popup_id ); ?>').remove();
644 if (redirectUrl !== '') {
645 location.href = redirectUrl;
646 }
647 });
648
649 $('<?php echo esc_attr( $popup_id ); ?> #<?php echo $key; ?>ti-deactivate-yes').on('click', function (e) {
650 e.preventDefault();
651 e.stopPropagation();
652 $(targetElement).unbind('click');
653 var selectedOption = $(
654 '<?php echo esc_attr( $popup_id ); ?> input[name="ti-deactivate-option"]:checked');
655 var data = {
656 'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>',
657 'nonce': '<?php echo wp_create_nonce( (string) __CLASS__ ); ?>',
658 'id': selectedOption.parent().attr('ti-option-id'),
659 'msg': selectedOption.parent().find('textarea').val(),
660 'type': 'plugin',
661 'key': '<?php echo esc_attr( $key ); ?>'
662 };
663 $.ajax({
664 type: 'POST',
665 url: ajaxurl,
666 data: data,
667 complete() {
668 $('body').removeClass('ti-feedback-open');
669 $('<?php echo esc_attr( $popup_id ); ?>').remove();
670 if (redirectUrl !== '') {
671 location.href = redirectUrl;
672 }
673 },
674 beforeSend() {
675 $('<?php echo esc_attr( $popup_id ); ?>').addClass('sending-feedback');
676 $('<?php echo esc_attr( $popup_id ); ?> .popup--footer').remove();
677 $('<?php echo esc_attr( $popup_id ); ?> .popup--body').html('<i class="dashicons dashicons-update-alt"></i>');
678 }
679 });
680 });
681 });
682 })(jQuery);
683
684 </script>
685 <?php
686 do_action( $this->product->get_key() . '_uninstall_feedback_after_js' );
687 }
688
689 /**
690 * Get the disclosure labels markup.
691 *
692 * @return string
693 */
694 private function get_disclosure_labels() {
695 $disclosure_new_labels = apply_filters( $this->product->get_slug() . '_themeisle_sdk_disclosure_content_labels', [], $this->product );
696 $disclosure_labels = array_merge(
697 [
698 'title' => 'Below is a detailed view of all data that ThemeIsle will receive if you fill in this survey. No domain name, email address or IP addresses are transmited after you submit the survey.',
699 'items' => [
700 sprintf( '%s %s version %s %s %s %s', '<strong>', ucwords( $this->product->get_type() ), '</strong>', '<code>', $this->product->get_version(), '</code>' ),
701 sprintf( '%sCurrent website:%s %s %s %s', '<strong>', '</strong>', '<code>', get_site_url(), '</code>' ),
702 sprintf( '%s Uninstall reason %s %s Selected reason from the above survey %s ', '<strong>', '</strong>', '<i>', '</i>' ),
703 ],
704 ],
705 $disclosure_new_labels
706 );
707
708 $info_disclosure_content = '<div class="info-disclosure-content"><p>' . wp_kses_post( $disclosure_labels['title'] ) . '</p><ul>';
709 foreach ( $disclosure_labels['items'] as $disclosure_item ) {
710 $info_disclosure_content .= sprintf( '<li>%s</li>', wp_kses_post( $disclosure_item ) );
711 }
712 $info_disclosure_content .= '</ul></div>';
713
714 return $info_disclosure_content;
715 }
716
717 /**
718 * Randomizes the options array.
719 *
720 * @param array $options The options array.
721 */
722 function randomize_options( $options ) {
723 $new = array();
724 $keys = array_keys( $options );
725 shuffle( $keys );
726
727 foreach ( $keys as $key ) {
728 $new[ $key ] = $options[ $key ];
729 }
730
731 return $new;
732 }
733
734 /**
735 * Called when the deactivate button is clicked.
736 */
737 function post_deactivate() {
738 check_ajax_referer( (string) __CLASS__, 'nonce' );
739
740 $this->post_deactivate_or_cancel();
741
742 if ( empty( $_POST['id'] ) ) {
743
744 wp_send_json( [] );
745
746 return;
747 }
748 $this->call_api(
749 array(
750 'type' => 'deactivate',
751 'id' => $_POST['id'],
752 'comment' => isset( $_POST['msg'] ) ? $_POST['msg'] : '',
753 )
754 );
755 wp_send_json( [] );
756
757 }
758
759 /**
760 * Called when the deactivate/cancel button is clicked.
761 */
762 private function post_deactivate_or_cancel() {
763 if ( ! isset( $_POST['type'] ) || ! isset( $_POST['key'] ) ) {
764 return;
765 }
766 if ( 'theme' !== $_POST['type'] ) {
767 return;
768 }
769
770 set_transient( 'ti_sdk_pause_' . $_POST['key'], true, self::PAUSE_DEACTIVATE_WINDOW_DAYS * DAY_IN_SECONDS );
771
772 }
773
774 /**
775 * Calls the API
776 *
777 * @param array $attributes The attributes of the post body.
778 *
779 * @return bool Is the request succesfull?
780 */
781 protected function call_api( $attributes ) {
782 $slug = $this->product->get_slug();
783 $version = $this->product->get_version();
784 $attributes['slug'] = $slug;
785 $attributes['version'] = $version;
786 $attributes['url'] = get_site_url();
787
788 $response = wp_remote_post(
789 self::FEEDBACK_ENDPOINT,
790 array(
791 'body' => $attributes,
792 )
793 );
794
795 return is_wp_error( $response );
796 }
797
798 /**
799 * Should we load this object?.
800 *
801 * @param Product $product Product object.
802 *
803 * @return bool Should we load the module?
804 */
805 public function can_load( $product ) {
806 if ( $this->is_from_partner( $product ) ) {
807 return false;
808 }
809 if ( $product->is_theme() && ( false !== get_transient( 'ti_sdk_pause_' . $product->get_key(), false ) ) ) {
810 return false;
811 }
812
813 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
814 return true;
815 }
816 global $pagenow;
817
818 if ( ! isset( $pagenow ) || empty( $pagenow ) ) {
819 return false;
820 }
821
822 if ( $product->is_plugin() && 'plugins.php' !== $pagenow ) {
823 return false;
824
825 }
826 if ( $product->is_theme() && 'theme-install.php' !== $pagenow ) {
827 return false;
828 }
829
830 return true;
831 }
832
833 /**
834 * Loads module hooks.
835 *
836 * @param Product $product Product details.
837 *
838 * @return Uninstall_Feedback Current module instance.
839 */
840 public function load( $product ) {
841
842 if ( apply_filters( $product->get_key() . '_hide_uninstall_feedback', false ) ) {
843 return;
844 }
845
846 $this->product = $product;
847 add_action( 'admin_head', array( $this, 'load_resources' ) );
848 add_action( 'wp_ajax_' . $this->product->get_key() . '_uninstall_feedback', array( $this, 'post_deactivate' ) );
849
850 return $this;
851 }
852 }
853