PluginProbe
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs / 2.7.3
BlockSpare – Gutenberg Blocks, AI Content Generator & Site Builder for News, Magazine & Blogs v2.7.3
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 +192 -65 1.2.3 → 2.7.3 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 );
@@ -78,10 +121,10 @@
78 121 }
79 122 ?>
80 123 <script type="text/javascript">
81 124 (function ($) {
82 - var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ) ?>,
83 - modalHtml =
125 + var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ) ?>,
126 + modalHtml =
84 127 '<div class="fs-modal fs-modal-deactivation-feedback<?php echo empty( $confirmation_message ) ? ' no-confirmation-message' : ''; ?>">'
85 128 + ' <div class="fs-modal-dialog">'
86 129 + ' <div class="fs-modal-header">'
87 130 + ' <h4><?php fs_esc_attr_echo_inline( 'Quick Feedback', 'quick-feedback' , $slug ) ?></h4>'
@@ -91,26 +134,28 @@
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>'
99 143 + '</div>',
100 - $modal = $(modalHtml),
101 - $deactivateLink = $('#the-list .deactivate > [data-module-id=<?php echo $fs->get_id() ?>].fs-module-id').prev(),
102 - selectedReasonID = false,
103 - redirectLink = '',
104 - $anonymousFeedback = $modal.find( '.anonymous-feedback-label' ),
105 - isAnonymous = <?php echo ( $is_anonymous ? 'true' : 'false' ); ?>,
106 - otherReasonID = <?php echo Freemius::REASON_OTHER; ?>,
107 - dontShareDataReasonID = <?php echo Freemius::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION; ?>,
108 - deleteThemeUpdateData = <?php echo $fs->is_theme() && $fs->is_premium() && ! $fs->has_any_active_valid_license() ? 'true' : 'false' ?>,
144 + $modal = $(modalHtml),
145 + selectedReasonID = false,
146 + redirectLink = '',
147 + $anonymousFeedback = $modal.find( '.anonymous-feedback-label' ),
148 + $feedbackSnooze = $modal.find( '.feedback-from-snooze-label' ),
149 + isAnonymous = <?php echo ( $is_anonymous ? 'true' : 'false' ); ?>,
150 + otherReasonID = <?php echo Freemius::REASON_OTHER; ?>,
151 + dontShareDataReasonID = <?php echo Freemius::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION; ?>,
152 + deleteThemeUpdateData = <?php echo $fs->is_theme() && $fs->is_premium() && ! $fs->has_any_active_valid_license() ? 'true' : 'false' ?>,
109 153 $subscriptionCancellationModal = $( '.fs-modal-subscription-cancellation-<?php echo $fs->get_id() ?>' ),
110 - showDeactivationFeedbackForm = <?php echo ( $show_deactivation_feedback_form ? 'true' : 'false' ) ?>;
154 + showDeactivationFeedbackForm = <?php echo ( $show_deactivation_feedback_form ? 'true' : 'false' ) ?>,
155 + $body = $( 'body' );
111 156
112 - $modal.appendTo($('body'));
157 + $modal.appendTo( $body );
113 158
114 159 if ( 0 !== $subscriptionCancellationModal.length ) {
115 160 $subscriptionCancellationModal.on( '<?php echo $fs->get_action_tag( 'subscription_cancellation_action' ) ?>', function( evt, cancelSubscription ) {
116 161 var shouldDeactivateModule = ( $modal.hasClass( 'no-confirmation-message' ) && ! showDeactivationFeedbackForm );
@@ -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' ) ?>',
@@ -180,9 +225,13 @@
180 225
181 226 registerEventHandlers();
182 227
183 228 function registerEventHandlers() {
184 - $deactivateLink.click(function (evt) {
229 + $body.on( 'click', '#the-list .deactivate > a', function ( evt ) {
230 + if ( 0 === $( this ).next( '[data-module-id=<?php echo $fs->get_id() ?>].fs-module-id' ).length ) {
231 + return true;
232 + }
233 +
185 234 evt.preventDefault();
186 235
187 236 redirectLink = $(this).attr('href');
188 237
@@ -225,12 +274,8 @@
225 274 <?php
226 275 } ?>
227 276
228 277 $modal.on('input propertychange', '.reason-input input', function () {
229 - if (!isOtherReasonSelected()) {
230 - return;
231 - }
232 -
233 278 var reason = $(this).val().trim();
234 279
235 280 /**
236 281 * If reason is not empty, remove the error-message class of the message container
@@ -236,11 +281,14 @@
236 281 * If reason is not empty, remove the error-message class of the message container
237 282 * to change the message color back to default.
238 283 */
239 284 if (reason.length > 0) {
240 - $('.message').removeClass('error-message');
241 - enableDeactivateButton();
242 - }
285 + $('.message').removeClass('error-message');
286 + }
287 +
288 + toggleDeactivationButtonPrimary( reason.length > 0 );
289 +
290 + changeDeactivateButtonText();
243 291 });
244 292
245 293 $modal.on('blur', '.reason-input input', function () {
246 294 var $userReason = $(this);
@@ -255,10 +303,10 @@
255 303 * to change the message color to red.
256 304 */
257 305 if (0 === $userReason.val().trim().length) {
258 306 $('.message').addClass('error-message');
259 - disableDeactivateButton();
260 - }
307 + changeDeactivateButtonText();
308 + }
261 309 }, 150);
262 310 });
263 311
264 312 $modal.on('click', '.fs-modal-footer .button', function (evt) {
@@ -271,17 +319,36 @@
271 319 var _parent = $(this).parents('.fs-modal:first');
272 320 var _this = $(this);
273 321
274 322 if (_this.hasClass('allow-deactivate')) {
275 - 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 = '';
276 327
277 - 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 ) {
278 345 if ( ! deleteThemeUpdateData ) {
279 346 // If no selected reason, just deactivate the plugin.
280 347 window.location.href = redirectLink;
281 348 } else {
282 349 $.ajax({
283 - url : ajaxurl,
350 + url : <?php echo Freemius::ajax_url() ?>,
284 351 method : 'POST',
285 352 data : {
286 353 action : '<?php echo $fs->get_ajax_action( 'delete_theme_update_data' ) ?>',
287 354 security : '<?php echo $fs->get_ajax_security( 'delete_theme_update_data' ) ?>',
@@ -287,10 +354,9 @@
287 354 security : '<?php echo $fs->get_ajax_security( 'delete_theme_update_data' ) ?>',
288 355 module_id: '<?php echo $fs->get_id() ?>'
289 356 },
290 357 beforeSend: function() {
291 - _parent.find( '.fs-modal-footer .button' ).addClass( 'disabled' );
292 - _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 ) ) ?>...' );
293 359 },
294 360 complete : function() {
295 361 window.location.href = redirectLink;
296 362 }
@@ -299,30 +365,29 @@
299 365
300 366 return;
301 367 }
302 368
303 - var $selected_reason = $radio.parents('li:first'),
304 - $input = $selected_reason.find('textarea, input[type="text"]'),
305 - userReason = ( 0 !== $input.length ) ? $input.val().trim() : '';
369 + var snoozePeriod = 0,
370 + shouldSnooze = $feedbackSnooze.find( '.feedback-from-snooze-checkbox' ).is( ':checked' );
306 371
307 - if (isOtherReasonSelected() && ( '' === userReason )) {
308 - return;
309 - }
372 + if ( shouldSnooze && <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> == selectedReasonID ) {
373 + snoozePeriod = parseInt($feedbackSnooze.find('select').val(), 10);
374 + }
310 375
311 376 $.ajax({
312 - url : ajaxurl,
377 + url : <?php echo Freemius::ajax_url() ?>,
313 378 method : 'POST',
314 379 data : {
315 - action : '<?php echo $fs->get_ajax_action( 'submit_uninstall_reason' ) ?>',
316 - security : '<?php echo $fs->get_ajax_security( 'submit_uninstall_reason' ) ?>',
317 - module_id : '<?php echo $fs->get_id() ?>',
318 - reason_id : $radio.val(),
319 - reason_info : userReason,
320 - 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
321 387 },
322 388 beforeSend: function () {
323 - _parent.find('.fs-modal-footer .button').addClass('disabled');
324 - _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 ) ) ?>...');
325 390 },
326 391 complete : function () {
327 392 // Do not show the dialog box, deactivate the plugin.
328 393 window.location.href = redirectLink;
@@ -360,22 +425,19 @@
360 425 var _parent = $(this).parents('li:first');
361 426
362 427 $modal.find('.reason-input').remove();
363 428 $modal.find( '.internal-message' ).hide();
364 - $modal.find('.button-deactivate').html('<?php echo esc_js( sprintf(
365 - fs_text_inline( 'Submit & %s', 'deactivation-modal-button-submit' , $slug ),
366 - $fs->is_plugin() ?
367 - $deactivate_text :
368 - sprintf( $activate_x_text, $theme_text )
369 - ) ) ?>');
429 + $modal.find('.button-deactivate').html('<?php echo esc_js( $submit_deactivate_text ) ?>');
370 430
371 - enableDeactivateButton();
372 -
373 431 if ( _parent.hasClass( 'has-internal-message' ) ) {
374 432 _parent.find( '.internal-message' ).show();
375 433 }
376 434
377 - if (_parent.hasClass('has-input')) {
435 + if ( ! _parent.hasClass('has-input') ) {
436 + toggleDeactivationButtonPrimary( true );
437 + } else {
438 + toggleDeactivationButtonPrimary( false );
439 +
378 440 var inputType = _parent.data('input-type'),
379 441 inputPlaceholder = _parent.data('input-placeholder'),
380 442 reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" maxlength="128" />' : '<textarea rows="5" maxlength="128"></textarea>' ) + '</div>';
381 443
@@ -383,13 +445,62 @@
383 445 _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
384 446
385 447 if (isOtherReasonSelected()) {
386 448 showMessage('<?php echo esc_js( fs_text_inline( 'Kindly tell us the reason so we can improve.', 'ask-for-reason-message' , $slug ) ); ?>');
387 - disableDeactivateButton();
388 - }
449 + changeDeactivateButtonText();
450 + }
389 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 + }
390 459 });
391 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 +
392 503 // If the user has clicked outside the window, cancel it.
393 504 $modal.on('click', function (evt) {
394 505 var $target = $(evt.target);
395 506
@@ -448,10 +559,8 @@
448 559
449 560 function resetModal() {
450 561 selectedReasonID = false;
451 562
452 - enableDeactivateButton();
453 -
454 563 // Uncheck all radio buttons.
455 564 $modal.find('input[type="radio"]').prop('checked', false);
456 565
457 566 // Remove all input fields ( textfield, textarea ).
@@ -458,10 +567,10 @@
458 567 $modal.find('.reason-input').remove();
459 568
460 569 $modal.find('.message').hide();
461 570
462 - if ( isAnonymous ) {
463 - $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' ?> );
464 573
465 574 // Hide, since by default there is no selected reason.
466 575 $anonymousFeedback.hide();
467 576 }
@@ -486,15 +595,33 @@
486 595 function showMessage(message) {
487 596 $modal.find('.message').text(message).show();
488 597 }
489 598
490 - function enableDeactivateButton() {
491 - $modal.find('.button-deactivate').removeClass('disabled');
492 - }
599 + /**
600 + * @author Xiaheng Chen (@xhchen)
601 + *
602 + * @since 2.4.2
603 + */
604 + function changeDeactivateButtonText() {
605 + if ( ! isOtherReasonSelected()) {
606 + return;
607 + }
493 608
494 - function disableDeactivateButton() {
495 - $modal.find('.button-deactivate').addClass('disabled');
496 - }
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 + }
497 624
498 625 function showPanel(panelType) {
499 626 $modal.find( '.fs-modal-panel' ).removeClass( 'active' );
500 627 $modal.find( '[data-panel-id="' + panelType + '"]' ).addClass( 'active' );