PluginProbe
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs / 2.6.2
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs v2.6.2
5.0.1 4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 All 39 releases
← All changes | freemius/templates/forms/deactivation/form.php +174 -51 1.3.3 → 2.6.2 View file →
@@ -23,8 +23,9 @@
23 23 $is_anonymous = ( ! $fs->is_registered() );
24 24 $anonymous_feedback_checkbox_html = '';
25 25
26 26 $reasons_list_items_html = '';
27 + $snooze_select_html = '';
27 28
28 29 if ( $show_deactivation_feedback_form ) {
29 30 $reasons = $VARS['reasons'];
30 31
@@ -63,8 +64,43 @@
63 64 '<label class="anonymous-feedback-label"><input type="checkbox" class="anonymous-feedback-checkbox"> %s</label>',
64 65 fs_esc_html_inline( 'Anonymous feedback', 'anonymous-feedback', $slug )
65 66 );
66 67 }
68 +
69 + $snooze_periods = array(
70 + array(
71 + 'increment' => fs_text_inline( 'hour', $slug ),
72 + 'quantity' => number_format_i18n(1),
73 + 'value' => 6 * WP_FS__TIME_10_MIN_IN_SEC,
74 + ),
75 + array(
76 + 'increment' => fs_text_inline( 'hours', $slug ),
77 + 'quantity' => number_format_i18n(24),
78 + 'value' => WP_FS__TIME_24_HOURS_IN_SEC,
79 + ),
80 + array(
81 + 'increment' => fs_text_inline( 'days', $slug ),
82 + 'quantity' => number_format_i18n(7),
83 + 'value' => WP_FS__TIME_WEEK_IN_SEC,
84 + ),
85 + array(
86 + 'increment' => fs_text_inline( 'days', $slug ),
87 + 'quantity' => number_format_i18n(30),
88 + 'value' => 30 * WP_FS__TIME_24_HOURS_IN_SEC,
89 + ),
90 + );
91 +
92 + $snooze_select_html = '<select>';
93 + foreach ($snooze_periods as $period) {
94 + $snooze_select_html .= sprintf(
95 + '<option value="%s">%s %s</option>',
96 + $period['value'],
97 + $period['quantity'],
98 + $period['increment']
99 + );
100 + }
101 +
102 + $snooze_select_html .= '</select>';
67 103 }
68 104
69 105 // Aliases.
70 106 $deactivate_text = fs_text_inline( 'Deactivate', 'deactivate', $slug );
@@ -70,8 +106,15 @@
70 106 $deactivate_text = fs_text_inline( 'Deactivate', 'deactivate', $slug );
71 107 $theme_text = fs_text_inline( 'Theme', 'theme', $slug );
72 108 $activate_x_text = fs_text_inline( 'Activate %s', 'activate-x', $slug );
73 109
110 + $submit_deactivate_text = sprintf(
111 + fs_text_inline( 'Submit & %s', 'deactivation-modal-button-submit', $slug ),
112 + $fs->is_plugin() ?
113 + $deactivate_text :
114 + sprintf( $activate_x_text, $theme_text )
115 + );
116 +
74 117 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
75 118
76 119 if ( ! empty( $subscription_cancellation_dialog_box_template_params ) ) {
77 120 fs_require_template( 'forms/subscription-cancellation.php', $subscription_cancellation_dialog_box_template_params );
@@ -91,8 +134,9 @@
91 134 + ' <div class="fs-modal-panel active" data-panel-id="reasons"><h3><strong><?php echo esc_js( sprintf( fs_text_inline( 'If you have a moment, please let us know why you are %s', 'deactivation-share-reason' , $slug ), ( $fs->is_plugin() ? fs_text_inline( 'deactivating', 'deactivating', $slug ) : fs_text_inline( 'switching', 'switching', $slug ) ) ) ) ?>:</strong></h3><ul id="reasons-list">' + reasonsHtml + '</ul></div>'
92 135 + ' </div>'
93 136 + ' <div class="fs-modal-footer">'
94 137 + ' <?php echo $anonymous_feedback_checkbox_html ?>'
138 + + ' <label style="display: none" class="feedback-from-snooze-label"><input type="checkbox" class="feedback-from-snooze-checkbox"> <span><?php fs_esc_js_echo_inline( 'Snooze this panel during troubleshooting', 'snooze-panel-during-troubleshooting', $slug ) ?></span><span style="display: none"><?php fs_esc_js_echo_inline( 'Snooze this panel for', 'snooze-panel-for', $slug ) ?> <?php echo $snooze_select_html ?></span></label>'
95 139 + ' <a href="#" class="button button-secondary button-deactivate"></a>'
96 140 + ' <a href="#" class="button button-secondary button-close"><?php fs_esc_js_echo_inline( 'Cancel', 'cancel', $slug ) ?></a>'
97 141 + ' </div>'
98 142 + ' </div>'
@@ -100,8 +144,9 @@
100 144 $modal = $(modalHtml),
101 145 selectedReasonID = false,
102 146 redirectLink = '',
103 147 $anonymousFeedback = $modal.find( '.anonymous-feedback-label' ),
148 + $feedbackSnooze = $modal.find( '.feedback-from-snooze-label' ),
104 149 isAnonymous = <?php echo ( $is_anonymous ? 'true' : 'false' ); ?>,
105 150 otherReasonID = <?php echo Freemius::REASON_OTHER; ?>,
106 151 dontShareDataReasonID = <?php echo Freemius::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION; ?>,
107 152 deleteThemeUpdateData = <?php echo $fs->is_theme() && $fs->is_premium() && ! $fs->has_any_active_valid_license() ? 'true' : 'false' ?>,
@@ -134,9 +179,9 @@
134 179 fs_text_inline( 'subscription', 'subscription', $slug );
135 180 ?>
136 181
137 182 $.ajax({
138 - url : ajaxurl,
183 + url : <?php echo Freemius::ajax_url() ?>,
139 184 method : 'POST',
140 185 data : {
141 186 action : '<?php echo $fs->get_ajax_action( 'cancel_subscription_or_trial' ) ?>',
142 187 security : '<?php echo $fs->get_ajax_security( 'cancel_subscription_or_trial' ) ?>',
@@ -229,12 +274,8 @@
229 274 <?php
230 275 } ?>
231 276
232 277 $modal.on('input propertychange', '.reason-input input', function () {
233 - if (!isOtherReasonSelected()) {
234 - return;
235 - }
236 -
237 278 var reason = $(this).val().trim();
238 279
239 280 /**
240 281 * If reason is not empty, remove the error-message class of the message container
@@ -240,11 +281,14 @@
240 281 * If reason is not empty, remove the error-message class of the message container
241 282 * to change the message color back to default.
242 283 */
243 284 if (reason.length > 0) {
244 - $('.message').removeClass('error-message');
245 - enableDeactivateButton();
246 - }
285 + $('.message').removeClass('error-message');
286 + }
287 +
288 + toggleDeactivationButtonPrimary( reason.length > 0 );
289 +
290 + changeDeactivateButtonText();
247 291 });
248 292
249 293 $modal.on('blur', '.reason-input input', function () {
250 294 var $userReason = $(this);
@@ -259,10 +303,10 @@
259 303 * to change the message color to red.
260 304 */
261 305 if (0 === $userReason.val().trim().length) {
262 306 $('.message').addClass('error-message');
263 - disableDeactivateButton();
264 - }
307 + changeDeactivateButtonText();
308 + }
265 309 }, 150);
266 310 });
267 311
268 312 $modal.on('click', '.fs-modal-footer .button', function (evt) {
@@ -275,17 +319,36 @@
275 319 var _parent = $(this).parents('.fs-modal:first');
276 320 var _this = $(this);
277 321
278 322 if (_this.hasClass('allow-deactivate')) {
279 - var $radio = $modal.find('input[type="radio"]:checked');
323 + var
324 + $radio = $modal.find('input[type="radio"]:checked'),
325 + isReasonSelected = (0 < $radio.length),
326 + userReason = '';
280 327
281 - if (0 === $radio.length) {
328 + if ( isReasonSelected ) {
329 + var $selectedReason = $radio.parents('li:first'),
330 + $reasonInput = $selectedReason.find('textarea, input[type="text"]');
331 +
332 + if ( 0 < $reasonInput.length ) {
333 + userReason = $reasonInput.val().trim();
334 + }
335 + }
336 +
337 + if ( otherReasonID == selectedReasonID && '' === userReason ) {
338 + // If the 'Other' is selected and a reason is not provided (aka it's empty), treat it as if a reason wasn't selected at all.
339 + isReasonSelected = false;
340 + }
341 +
342 + _parent.find( '.fs-modal-footer .button' ).addClass( 'disabled' );
343 +
344 + if ( ! isReasonSelected ) {
282 345 if ( ! deleteThemeUpdateData ) {
283 346 // If no selected reason, just deactivate the plugin.
284 347 window.location.href = redirectLink;
285 348 } else {
286 349 $.ajax({
287 - url : ajaxurl,
350 + url : <?php echo Freemius::ajax_url() ?>,
288 351 method : 'POST',
289 352 data : {
290 353 action : '<?php echo $fs->get_ajax_action( 'delete_theme_update_data' ) ?>',
291 354 security : '<?php echo $fs->get_ajax_security( 'delete_theme_update_data' ) ?>',
@@ -291,10 +354,9 @@
291 354 security : '<?php echo $fs->get_ajax_security( 'delete_theme_update_data' ) ?>',
292 355 module_id: '<?php echo $fs->get_id() ?>'
293 356 },
294 357 beforeSend: function() {
295 - _parent.find( '.fs-modal-footer .button' ).addClass( 'disabled' );
296 - _parent.find( '.fs-modal-footer .button-secondary' ).text( 'Processing...' );
358 + _parent.find( '.fs-modal-footer .button-deactivate' ).text( '<?php echo esc_js( fs_text_inline( 'Processing', 'processing', $slug ) ) ?>...' );
297 359 },
298 360 complete : function() {
299 361 window.location.href = redirectLink;
300 362 }
@@ -303,30 +365,29 @@
303 365
304 366 return;
305 367 }
306 368
307 - var $selected_reason = $radio.parents('li:first'),
308 - $input = $selected_reason.find('textarea, input[type="text"]'),
309 - userReason = ( 0 !== $input.length ) ? $input.val().trim() : '';
369 + var snoozePeriod = 0,
370 + shouldSnooze = $feedbackSnooze.find( '.feedback-from-snooze-checkbox' ).is( ':checked' );
310 371
311 - if (isOtherReasonSelected() && ( '' === userReason )) {
312 - return;
313 - }
372 + if ( shouldSnooze && <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> == selectedReasonID ) {
373 + snoozePeriod = parseInt($feedbackSnooze.find('select').val(), 10);
374 + }
314 375
315 376 $.ajax({
316 - url : ajaxurl,
377 + url : <?php echo Freemius::ajax_url() ?>,
317 378 method : 'POST',
318 379 data : {
319 - action : '<?php echo $fs->get_ajax_action( 'submit_uninstall_reason' ) ?>',
320 - security : '<?php echo $fs->get_ajax_security( 'submit_uninstall_reason' ) ?>',
321 - module_id : '<?php echo $fs->get_id() ?>',
322 - reason_id : $radio.val(),
323 - reason_info : userReason,
324 - is_anonymous: isAnonymousFeedback()
380 + action : '<?php echo $fs->get_ajax_action( 'submit_uninstall_reason' ) ?>',
381 + security : '<?php echo $fs->get_ajax_security( 'submit_uninstall_reason' ) ?>',
382 + module_id : '<?php echo $fs->get_id() ?>',
383 + reason_id : $radio.val(),
384 + reason_info : userReason,
385 + is_anonymous : isAnonymousFeedback(),
386 + snooze_period: snoozePeriod
325 387 },
326 388 beforeSend: function () {
327 - _parent.find('.fs-modal-footer .button').addClass('disabled');
328 - _parent.find('.fs-modal-footer .button-secondary').text('Processing...');
389 + _parent.find('.fs-modal-footer .button-deactivate').text('<?php echo esc_js( fs_text_inline( 'Processing', 'processing', $slug ) ) ?>...');
329 390 },
330 391 complete : function () {
331 392 // Do not show the dialog box, deactivate the plugin.
332 393 window.location.href = redirectLink;
@@ -364,22 +425,19 @@
364 425 var _parent = $(this).parents('li:first');
365 426
366 427 $modal.find('.reason-input').remove();
367 428 $modal.find( '.internal-message' ).hide();
368 - $modal.find('.button-deactivate').html('<?php echo esc_js( sprintf(
369 - fs_text_inline( 'Submit & %s', 'deactivation-modal-button-submit' , $slug ),
370 - $fs->is_plugin() ?
371 - $deactivate_text :
372 - sprintf( $activate_x_text, $theme_text )
373 - ) ) ?>');
429 + $modal.find('.button-deactivate').html('<?php echo esc_js( $submit_deactivate_text ) ?>');
374 430
375 - enableDeactivateButton();
376 -
377 431 if ( _parent.hasClass( 'has-internal-message' ) ) {
378 432 _parent.find( '.internal-message' ).show();
379 433 }
380 434
381 - if (_parent.hasClass('has-input')) {
435 + if ( ! _parent.hasClass('has-input') ) {
436 + toggleDeactivationButtonPrimary( true );
437 + } else {
438 + toggleDeactivationButtonPrimary( false );
439 +
382 440 var inputType = _parent.data('input-type'),
383 441 inputPlaceholder = _parent.data('input-placeholder'),
384 442 reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" maxlength="128" />' : '<textarea rows="5" maxlength="128"></textarea>' ) + '</div>';
385 443
@@ -387,13 +445,62 @@
387 445 _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
388 446
389 447 if (isOtherReasonSelected()) {
390 448 showMessage('<?php echo esc_js( fs_text_inline( 'Kindly tell us the reason so we can improve.', 'ask-for-reason-message' , $slug ) ); ?>');
391 - disableDeactivateButton();
392 - }
449 + changeDeactivateButtonText();
450 + }
393 451 }
452 +
453 + $anonymousFeedback.toggle( <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> != selectedReasonID );
454 + $feedbackSnooze.toggle( <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> == selectedReasonID );
455 +
456 + if ( <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> == selectedReasonID ) {
457 + updateDeactivationButtonOnTrouble();
458 + }
394 459 });
395 460
461 + var toggleDeactivationButtonPrimary = function ( isPrimary ) {
462 + if ( isPrimary ) {
463 + $modal.find('.button-deactivate')
464 + .removeClass( 'button-secondary' )
465 + .addClass( 'button-primary' );
466 + } else {
467 + $modal.find('.button-deactivate')
468 + .addClass( 'button-secondary' )
469 + .removeClass( 'button-primary' );
470 + }
471 + };
472 +
473 + var snooze = false;
474 +
475 + var updateDeactivationButtonOnTrouble = function () {
476 + if ( snooze ) {
477 + $modal.find('.button-deactivate').html('<?php echo esc_js( sprintf(
478 + fs_text_inline( 'Snooze & %s', 'snooze-modal-button-submit' , $slug ),
479 + $fs->is_plugin() ?
480 + $deactivate_text :
481 + sprintf( $activate_x_text, $theme_text )
482 + ) ) ?>');
483 + } else {
484 + $modal.find('.button-deactivate').html('<?php echo esc_js(
485 + $fs->is_plugin() ?
486 + $deactivate_text :
487 + sprintf( $activate_x_text, $theme_text )
488 + ) ?>');
489 + }
490 + };
491 +
492 + $feedbackSnooze.on( 'click', 'input', function () {
493 + var $spans = $feedbackSnooze.find( 'span' );
494 +
495 + snooze = ( ! snooze );
496 +
497 + $( $spans[0] ).toggle();
498 + $( $spans[1] ).toggle();
499 +
500 + updateDeactivationButtonOnTrouble();
501 + });
502 +
396 503 // If the user has clicked outside the window, cancel it.
397 504 $modal.on('click', function (evt) {
398 505 var $target = $(evt.target);
399 506
@@ -452,10 +559,8 @@
452 559
453 560 function resetModal() {
454 561 selectedReasonID = false;
455 562
456 - enableDeactivateButton();
457 -
458 563 // Uncheck all radio buttons.
459 564 $modal.find('input[type="radio"]').prop('checked', false);
460 565
461 566 // Remove all input fields ( textfield, textarea ).
@@ -462,10 +567,10 @@
462 567 $modal.find('.reason-input').remove();
463 568
464 569 $modal.find('.message').hide();
465 570
466 - if ( isAnonymous ) {
467 - $anonymousFeedback.find( 'input' ).prop( 'checked', false );
571 + if ( isAnonymous ) {
572 + $anonymousFeedback.find( 'input' ).prop( 'checked', <?php echo $fs->apply_filters( 'default_to_anonymous_feedback', false ) ? 'true' : 'false' ?> );
468 573
469 574 // Hide, since by default there is no selected reason.
470 575 $anonymousFeedback.hide();
471 576 }
@@ -490,15 +595,33 @@
490 595 function showMessage(message) {
491 596 $modal.find('.message').text(message).show();
492 597 }
493 598
494 - function enableDeactivateButton() {
495 - $modal.find('.button-deactivate').removeClass('disabled');
496 - }
599 + /**
600 + * @author Xiaheng Chen (@xhchen)
601 + *
602 + * @since 2.4.2
603 + */
604 + function changeDeactivateButtonText() {
605 + if ( ! isOtherReasonSelected()) {
606 + return;
607 + }
497 608
498 - function disableDeactivateButton() {
499 - $modal.find('.button-deactivate').addClass('disabled');
500 - }
609 + var
610 + $userReason = $modal.find('.reason-input input'),
611 + $deactivateButton = $modal.find('.button-deactivate');
612 +
613 + if (0 === $userReason.val().trim().length) {
614 + // If the reason is empty, just change the text to 'Deactivate' (plugin) or 'Activate themeX' (theme).
615 + $deactivateButton.html('<?php echo
616 + $fs->is_plugin() ?
617 + $deactivate_text :
618 + sprintf( $activate_x_text, $theme_text )
619 + ?>');
620 + } else {
621 + $deactivateButton.html('<?php echo esc_js( $submit_deactivate_text ) ?>');
622 + }
623 + }
501 624
502 625 function showPanel(panelType) {
503 626 $modal.find( '.fs-modal-panel' ).removeClass( 'active' );
504 627 $modal.find( '[data-panel-id="' + panelType + '"]' ).addClass( 'active' );