| 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 & Deactivate'; |
| 125 |
/** |
| 126 |
* Default cancel button. |
| 127 |
* |
| 128 |
* @var string $button_cancel The text of the cancel button |
| 129 |
*/ |
| 130 |
private $button_cancel = 'Skip & Deactivate'; |
| 131 |
|
| 132 |
/** |
| 133 |
* Loads the additional resources |
| 134 |
*/ |
| 135 |
public 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>×</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( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function has an internal sanitization. |
| 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 |
<?php echo is_rtl() ? 'margin: 0 0 0 10px;' : '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 |
<?php echo is_rtl() ? 'margin-right: auto;' : '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 |
top: 50%; |
| 370 |
transform: translateY(-50%); |
| 371 |
<?php |
| 372 |
echo is_rtl() ? |
| 373 |
'right: -10px; |
| 374 |
border-top: 20px solid transparent; |
| 375 |
border-left: 20px solid #23A1CE; |
| 376 |
border-bottom: 20px solid transparent;' : |
| 377 |
'left: -10px; |
| 378 |
border-top: 20px solid transparent; |
| 379 |
border-right: 20px solid #23A1CE; |
| 380 |
border-bottom: 20px solid transparent;'; |
| 381 |
?> |
| 382 |
} |
| 383 |
|
| 384 |
.ti-plugin-uninstall-feedback-popup { |
| 385 |
display: none; |
| 386 |
position: absolute; |
| 387 |
white-space: normal; |
| 388 |
width: 400px; |
| 389 |
<?php echo is_rtl() ? 'right: calc( 100% + 15px );' : 'left: calc( 100% + 15px );'; ?> |
| 390 |
top: -15px; |
| 391 |
} |
| 392 |
|
| 393 |
.ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i { |
| 394 |
animation: rotation 2s infinite linear; |
| 395 |
display: block; |
| 396 |
float: none; |
| 397 |
align-items: center; |
| 398 |
width: 100%; |
| 399 |
margin: 0 auto; |
| 400 |
height: 100%; |
| 401 |
background: transparent; |
| 402 |
padding: 0; |
| 403 |
} |
| 404 |
|
| 405 |
.ti-plugin-uninstall-feedback-popup.sending-feedback .popup--body i:before { |
| 406 |
padding: 0; |
| 407 |
background: transparent; |
| 408 |
box-shadow: none; |
| 409 |
color: #b4b9be |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
.ti-plugin-uninstall-feedback-popup.active { |
| 414 |
display: block; |
| 415 |
} |
| 416 |
|
| 417 |
tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>"] .deactivate { |
| 418 |
position: relative; |
| 419 |
} |
| 420 |
|
| 421 |
body.ti-feedback-open .ti-feedback-overlay { |
| 422 |
content: ""; |
| 423 |
display: block; |
| 424 |
background-color: rgba(0, 0, 0, 0.5); |
| 425 |
top: 0; |
| 426 |
bottom: 0; |
| 427 |
right: 0; |
| 428 |
left: 0; |
| 429 |
z-index: 10000; |
| 430 |
position: fixed; |
| 431 |
} |
| 432 |
|
| 433 |
@media (max-width: 768px) { |
| 434 |
.ti-plugin-uninstall-feedback-popup { |
| 435 |
position: fixed; |
| 436 |
max-width: 100%; |
| 437 |
margin: 0 auto; |
| 438 |
left: 50%; |
| 439 |
top: 50px; |
| 440 |
transform: translateX(-50%); |
| 441 |
} |
| 442 |
|
| 443 |
.ti-plugin-uninstall-feedback-popup .popup--header:before { |
| 444 |
display: none; |
| 445 |
} |
| 446 |
} |
| 447 |
</style> |
| 448 |
<?php |
| 449 |
} |
| 450 |
|
| 451 |
/** |
| 452 |
* Theme feedback drawer JS. |
| 453 |
*/ |
| 454 |
private function add_theme_feedback_drawer_js() { |
| 455 |
$key = $this->product->get_key(); |
| 456 |
?> |
| 457 |
<script type="text/javascript" id="ti-deactivate-js"> |
| 458 |
(function ($) { |
| 459 |
$(document).ready(function () { |
| 460 |
setTimeout(function () { |
| 461 |
$('.ti-theme-uninstall-feedback-drawer').addClass('active'); |
| 462 |
}, <?php echo absint( self::AUTO_TRIGGER_DEACTIVATE_WINDOW_SECONDS * 1000 ); ?> ); |
| 463 |
|
| 464 |
$('.ti-theme-uninstall-feedback-drawer .toggle').on('click', function (e) { |
| 465 |
e.preventDefault(); |
| 466 |
$('.ti-theme-uninstall-feedback-drawer').toggleClass('active'); |
| 467 |
}); |
| 468 |
|
| 469 |
$('.info-disclosure-link').on('click', function (e) { |
| 470 |
e.preventDefault(); |
| 471 |
$('.info-disclosure-content').toggleClass('active'); |
| 472 |
}); |
| 473 |
|
| 474 |
$('.ti-theme-uninstall-feedback-drawer input[type="radio"]').on('change', function () { |
| 475 |
var radio = $(this); |
| 476 |
if (radio.parent().find('textarea').length > 0 && |
| 477 |
radio.parent().find('textarea').val().length === 0) { |
| 478 |
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 479 |
radio.parent().find('textarea').on('keyup', function (e) { |
| 480 |
if ($(this).val().length === 0) { |
| 481 |
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 482 |
} else { |
| 483 |
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 484 |
} |
| 485 |
}); |
| 486 |
} else { |
| 487 |
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 488 |
} |
| 489 |
}); |
| 490 |
|
| 491 |
$('#<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) { |
| 492 |
e.preventDefault(); |
| 493 |
e.stopPropagation(); |
| 494 |
|
| 495 |
var selectedOption = $( |
| 496 |
'.ti-theme-uninstall-feedback-drawer input[name="ti-deactivate-option"]:checked'); |
| 497 |
$.post(ajaxurl, { |
| 498 |
'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>', |
| 499 |
'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>', |
| 500 |
'id': selectedOption.parent().attr('ti-option-id'), |
| 501 |
'msg': selectedOption.parent().find('textarea').val(), |
| 502 |
'type': 'theme', |
| 503 |
'key': '<?php echo esc_attr( $key ); ?>' |
| 504 |
}); |
| 505 |
$('.ti-theme-uninstall-feedback-drawer').fadeOut(); |
| 506 |
}); |
| 507 |
}); |
| 508 |
})(jQuery); |
| 509 |
|
| 510 |
</script> |
| 511 |
<?php |
| 512 |
do_action( $this->product->get_key() . '_uninstall_feedback_after_js' ); |
| 513 |
} |
| 514 |
|
| 515 |
/** |
| 516 |
* Render the options list. |
| 517 |
* |
| 518 |
* @param array $options the options for the feedback form. |
| 519 |
*/ |
| 520 |
private function render_options_list( $options ) { |
| 521 |
$key = $this->product->get_key(); |
| 522 |
$inputs_row_map = [ |
| 523 |
'text' => 1, |
| 524 |
'textarea' => 2, |
| 525 |
]; |
| 526 |
?> |
| 527 |
<ul class="popup--form"> |
| 528 |
<?php foreach ( $options as $title => $attributes ) { ?> |
| 529 |
<li ti-option-id="<?php echo esc_attr( $attributes['id'] ); ?>"> |
| 530 |
<input type="radio" name="ti-deactivate-option" id="<?php echo esc_attr( $key . $attributes['id'] ); ?>"> |
| 531 |
<label for="<?php echo esc_attr( $key . $attributes['id'] ); ?>"> |
| 532 |
<?php echo esc_attr( str_replace( '{theme}', $this->product->get_name(), $title ) ); ?> |
| 533 |
</label> |
| 534 |
<?php |
| 535 |
if ( array_key_exists( 'type', $attributes ) ) { |
| 536 |
$placeholder = array_key_exists( 'placeholder', $attributes ) ? $attributes['placeholder'] : ''; |
| 537 |
echo '<textarea width="100%" rows="' . esc_attr( $inputs_row_map[ $attributes['type'] ] ) . '" name="comments" placeholder="' . esc_attr( $placeholder ) . '"></textarea>'; |
| 538 |
} |
| 539 |
?> |
| 540 |
</li> |
| 541 |
<?php } ?> |
| 542 |
</ul> |
| 543 |
<?php |
| 544 |
} |
| 545 |
|
| 546 |
/** |
| 547 |
* Render plugin feedback popup. |
| 548 |
*/ |
| 549 |
private function render_plugin_feedback_popup() { |
| 550 |
$button_cancel = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_cancel', $this->button_cancel ); |
| 551 |
$button_submit = apply_filters( $this->product->get_key() . '_feedback_deactivate_button_submit', $this->button_submit ); |
| 552 |
$options = $this->randomize_options( apply_filters( $this->product->get_key() . '_feedback_deactivate_options', $this->options_plugin ) ); |
| 553 |
$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>'; |
| 554 |
|
| 555 |
$options += $this->other; |
| 556 |
?> |
| 557 |
<div class="ti-plugin-uninstall-feedback-popup ti-feedback" id="<?php echo esc_attr( $this->product->get_slug() . '_uninstall_feedback_popup' ); ?>"> |
| 558 |
<div class="popup--header"> |
| 559 |
<h5><?php echo wp_kses( $this->heading_plugin, array( 'span' => true ) ); ?> </h5> |
| 560 |
</div><!--/.popup--header--> |
| 561 |
<div class="popup--body"> |
| 562 |
<?php $this->render_options_list( $options ); ?> |
| 563 |
</div><!--/.popup--body--> |
| 564 |
<div class="popup--footer"> |
| 565 |
<div class="actions"> |
| 566 |
<?php |
| 567 |
echo wp_kses_post( $info_disclosure_link ); |
| 568 |
echo wp_kses_post( $this->get_disclosure_labels() ); |
| 569 |
echo '<div class="buttons">'; |
| 570 |
echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped. |
| 571 |
$button_cancel, |
| 572 |
'secondary', |
| 573 |
$this->product->get_key() . 'ti-deactivate-no', |
| 574 |
false |
| 575 |
); |
| 576 |
echo get_submit_button( //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Function internals are escaped. |
| 577 |
$button_submit, |
| 578 |
'primary', |
| 579 |
$this->product->get_key() . 'ti-deactivate-yes', |
| 580 |
false, |
| 581 |
array( |
| 582 |
'data-after-text' => $button_submit, |
| 583 |
'disabled' => true, |
| 584 |
) |
| 585 |
); |
| 586 |
echo '</div>'; |
| 587 |
?> |
| 588 |
</div><!--/.actions--> |
| 589 |
</div><!--/.popup--footer--> |
| 590 |
</div> |
| 591 |
|
| 592 |
<?php |
| 593 |
} |
| 594 |
|
| 595 |
/** |
| 596 |
* Add plugin feedback popup JS |
| 597 |
*/ |
| 598 |
private function add_plugin_feedback_popup_js() { |
| 599 |
$popup_id = '#' . $this->product->get_slug() . '_uninstall_feedback_popup'; |
| 600 |
$key = $this->product->get_key(); |
| 601 |
?> |
| 602 |
<script type="text/javascript" id="ti-deactivate-js"> |
| 603 |
(function ($) { |
| 604 |
$(document).ready(function () { |
| 605 |
var targetElement = 'tr[data-plugin^="<?php echo esc_attr( $this->product->get_slug() ); ?>/"] span.deactivate a'; |
| 606 |
var redirectUrl = $(targetElement).attr('href'); |
| 607 |
if ($('.ti-feedback-overlay').length === 0) { |
| 608 |
$('body').prepend('<div class="ti-feedback-overlay"></div>'); |
| 609 |
} |
| 610 |
$('<?php echo esc_attr( $popup_id ); ?> ').appendTo($(targetElement).parent()); |
| 611 |
|
| 612 |
$(targetElement).on('click', function (e) { |
| 613 |
e.preventDefault(); |
| 614 |
$('<?php echo esc_attr( $popup_id ); ?> ').addClass('active'); |
| 615 |
$('body').addClass('ti-feedback-open'); |
| 616 |
$('.ti-feedback-overlay').on('click', function () { |
| 617 |
$('<?php echo esc_attr( $popup_id ); ?> ').removeClass('active'); |
| 618 |
$('body').removeClass('ti-feedback-open'); |
| 619 |
}); |
| 620 |
}); |
| 621 |
|
| 622 |
$('<?php echo esc_attr( $popup_id ); ?> .info-disclosure-link').on('click', function (e) { |
| 623 |
e.preventDefault(); |
| 624 |
$(this).parent().find('.info-disclosure-content').toggleClass('active'); |
| 625 |
}); |
| 626 |
|
| 627 |
$('<?php echo esc_attr( $popup_id ); ?> input[type="radio"]').on('change', function () { |
| 628 |
var radio = $(this); |
| 629 |
if (radio.parent().find('textarea').length > 0 && |
| 630 |
radio.parent().find('textarea').val().length === 0) { |
| 631 |
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 632 |
radio.parent().find('textarea').on('keyup', function (e) { |
| 633 |
if ($(this).val().length === 0) { |
| 634 |
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').attr('disabled', 'disabled'); |
| 635 |
} else { |
| 636 |
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 637 |
} |
| 638 |
}); |
| 639 |
} else { |
| 640 |
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').removeAttr('disabled'); |
| 641 |
} |
| 642 |
}); |
| 643 |
|
| 644 |
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-no').on('click', function (e) { |
| 645 |
e.preventDefault(); |
| 646 |
e.stopPropagation(); |
| 647 |
$(targetElement).unbind('click'); |
| 648 |
$('body').removeClass('ti-feedback-open'); |
| 649 |
$('<?php echo esc_attr( $popup_id ); ?>').remove(); |
| 650 |
if (redirectUrl !== '') { |
| 651 |
location.href = redirectUrl; |
| 652 |
} |
| 653 |
}); |
| 654 |
|
| 655 |
$('<?php echo esc_attr( $popup_id ); ?> #<?php echo esc_attr( $key ); ?>ti-deactivate-yes').on('click', function (e) { |
| 656 |
e.preventDefault(); |
| 657 |
e.stopPropagation(); |
| 658 |
$(targetElement).unbind('click'); |
| 659 |
var selectedOption = $( |
| 660 |
'<?php echo esc_attr( $popup_id ); ?> input[name="ti-deactivate-option"]:checked'); |
| 661 |
var data = { |
| 662 |
'action': '<?php echo esc_attr( $key ) . '_uninstall_feedback'; ?>', |
| 663 |
'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>', |
| 664 |
'id': selectedOption.parent().attr('ti-option-id'), |
| 665 |
'msg': selectedOption.parent().find('textarea').val(), |
| 666 |
'type': 'plugin', |
| 667 |
'key': '<?php echo esc_attr( $key ); ?>' |
| 668 |
}; |
| 669 |
$.ajax({ |
| 670 |
type: 'POST', |
| 671 |
url: ajaxurl, |
| 672 |
data: data, |
| 673 |
complete() { |
| 674 |
$('body').removeClass('ti-feedback-open'); |
| 675 |
$('<?php echo esc_attr( $popup_id ); ?>').remove(); |
| 676 |
if (redirectUrl !== '') { |
| 677 |
location.href = redirectUrl; |
| 678 |
} |
| 679 |
}, |
| 680 |
beforeSend() { |
| 681 |
$('<?php echo esc_attr( $popup_id ); ?>').addClass('sending-feedback'); |
| 682 |
$('<?php echo esc_attr( $popup_id ); ?> .popup--footer').remove(); |
| 683 |
$('<?php echo esc_attr( $popup_id ); ?> .popup--body').html('<i class="dashicons dashicons-update-alt"></i>'); |
| 684 |
} |
| 685 |
}); |
| 686 |
}); |
| 687 |
}); |
| 688 |
})(jQuery); |
| 689 |
|
| 690 |
</script> |
| 691 |
<?php |
| 692 |
do_action( $this->product->get_key() . '_uninstall_feedback_after_js' ); |
| 693 |
} |
| 694 |
|
| 695 |
/** |
| 696 |
* Get the disclosure labels markup. |
| 697 |
* |
| 698 |
* @return string |
| 699 |
*/ |
| 700 |
private function get_disclosure_labels() { |
| 701 |
$disclosure_new_labels = apply_filters( $this->product->get_slug() . '_themeisle_sdk_disclosure_content_labels', [], $this->product ); |
| 702 |
$disclosure_labels = array_merge( |
| 703 |
[ |
| 704 |
'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.', |
| 705 |
'items' => [ |
| 706 |
sprintf( '%s %s version %s %s %s %s', '<strong>', ucwords( $this->product->get_type() ), '</strong>', '<code>', $this->product->get_version(), '</code>' ), |
| 707 |
sprintf( '%sCurrent website:%s %s %s %s', '<strong>', '</strong>', '<code>', get_site_url(), '</code>' ), |
| 708 |
sprintf( '%s Uninstall reason %s %s Selected reason from the above survey %s ', '<strong>', '</strong>', '<i>', '</i>' ), |
| 709 |
], |
| 710 |
], |
| 711 |
$disclosure_new_labels |
| 712 |
); |
| 713 |
|
| 714 |
$info_disclosure_content = '<div class="info-disclosure-content"><p>' . wp_kses_post( $disclosure_labels['title'] ) . '</p><ul>'; |
| 715 |
foreach ( $disclosure_labels['items'] as $disclosure_item ) { |
| 716 |
$info_disclosure_content .= sprintf( '<li>%s</li>', wp_kses_post( $disclosure_item ) ); |
| 717 |
} |
| 718 |
$info_disclosure_content .= '</ul></div>'; |
| 719 |
|
| 720 |
return $info_disclosure_content; |
| 721 |
} |
| 722 |
|
| 723 |
/** |
| 724 |
* Randomizes the options array. |
| 725 |
* |
| 726 |
* @param array $options The options array. |
| 727 |
*/ |
| 728 |
public function randomize_options( $options ) { |
| 729 |
$new = array(); |
| 730 |
$keys = array_keys( $options ); |
| 731 |
shuffle( $keys ); |
| 732 |
|
| 733 |
foreach ( $keys as $key ) { |
| 734 |
$new[ $key ] = $options[ $key ]; |
| 735 |
} |
| 736 |
|
| 737 |
return $new; |
| 738 |
} |
| 739 |
|
| 740 |
/** |
| 741 |
* Called when the deactivate button is clicked. |
| 742 |
*/ |
| 743 |
public function post_deactivate() { |
| 744 |
check_ajax_referer( (string) __CLASS__, 'nonce' ); |
| 745 |
|
| 746 |
$this->post_deactivate_or_cancel(); |
| 747 |
|
| 748 |
if ( empty( $_POST['id'] ) ) { |
| 749 |
|
| 750 |
wp_send_json( [] ); |
| 751 |
|
| 752 |
return; |
| 753 |
} |
| 754 |
$this->call_api( |
| 755 |
array( |
| 756 |
'type' => 'deactivate', |
| 757 |
'id' => sanitize_key( $_POST['id'] ), |
| 758 |
'comment' => isset( $_POST['msg'] ) ? sanitize_textarea_field( $_POST['msg'] ) : '', |
| 759 |
) |
| 760 |
); |
| 761 |
wp_send_json( [] ); |
| 762 |
|
| 763 |
} |
| 764 |
|
| 765 |
/** |
| 766 |
* Called when the deactivate/cancel button is clicked. |
| 767 |
*/ |
| 768 |
private function post_deactivate_or_cancel() { |
| 769 |
if ( ! isset( $_POST['type'] ) || ! isset( $_POST['key'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function. |
| 770 |
return; |
| 771 |
} |
| 772 |
if ( 'theme' !== $_POST['type'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function. |
| 773 |
return; |
| 774 |
} |
| 775 |
|
| 776 |
set_transient( 'ti_sdk_pause_' . sanitize_text_field( $_POST['key'] ), true, self::PAUSE_DEACTIVATE_WINDOW_DAYS * DAY_IN_SECONDS );//phpcs:ignore WordPress.Security.NonceVerification.Missing, Nonce already present in caller function. |
| 777 |
|
| 778 |
} |
| 779 |
|
| 780 |
/** |
| 781 |
* Calls the API |
| 782 |
* |
| 783 |
* @param array $attributes The attributes of the post body. |
| 784 |
* |
| 785 |
* @return bool Is the request succesfull? |
| 786 |
*/ |
| 787 |
protected function call_api( $attributes ) { |
| 788 |
$slug = $this->product->get_slug(); |
| 789 |
$version = $this->product->get_version(); |
| 790 |
$attributes['slug'] = $slug; |
| 791 |
$attributes['version'] = $version; |
| 792 |
$attributes['url'] = get_site_url(); |
| 793 |
|
| 794 |
$response = wp_remote_post( |
| 795 |
self::FEEDBACK_ENDPOINT, |
| 796 |
array( |
| 797 |
'body' => $attributes, |
| 798 |
) |
| 799 |
); |
| 800 |
|
| 801 |
return is_wp_error( $response ); |
| 802 |
} |
| 803 |
|
| 804 |
/** |
| 805 |
* Should we load this object?. |
| 806 |
* |
| 807 |
* @param Product $product Product object. |
| 808 |
* |
| 809 |
* @return bool Should we load the module? |
| 810 |
*/ |
| 811 |
public function can_load( $product ) { |
| 812 |
if ( $this->is_from_partner( $product ) ) { |
| 813 |
return false; |
| 814 |
} |
| 815 |
if ( $product->is_theme() && ( false !== get_transient( 'ti_sdk_pause_' . $product->get_key(), false ) ) ) { |
| 816 |
return false; |
| 817 |
} |
| 818 |
|
| 819 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 820 |
return true; |
| 821 |
} |
| 822 |
global $pagenow; |
| 823 |
|
| 824 |
if ( ! isset( $pagenow ) || empty( $pagenow ) ) { |
| 825 |
return false; |
| 826 |
} |
| 827 |
|
| 828 |
if ( $product->is_plugin() && 'plugins.php' !== $pagenow ) { |
| 829 |
return false; |
| 830 |
|
| 831 |
} |
| 832 |
if ( $product->is_theme() && 'theme-install.php' !== $pagenow ) { |
| 833 |
return false; |
| 834 |
} |
| 835 |
|
| 836 |
return true; |
| 837 |
} |
| 838 |
|
| 839 |
/** |
| 840 |
* Loads module hooks. |
| 841 |
* |
| 842 |
* @param Product $product Product details. |
| 843 |
* |
| 844 |
* @return Uninstall_Feedback Current module instance. |
| 845 |
*/ |
| 846 |
public function load( $product ) { |
| 847 |
|
| 848 |
if ( apply_filters( $product->get_key() . '_hide_uninstall_feedback', false ) ) { |
| 849 |
return; |
| 850 |
} |
| 851 |
|
| 852 |
$this->product = $product; |
| 853 |
add_action( 'admin_head', array( $this, 'load_resources' ) ); |
| 854 |
add_action( 'wp_ajax_' . $this->product->get_key() . '_uninstall_feedback', array( $this, 'post_deactivate' ) ); |
| 855 |
|
| 856 |
return $this; |
| 857 |
} |
| 858 |
} |
| 859 |
|