| @@ -15,53 +15,57 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | $fs = freemius( $VARS['id'] ); |
| 17 | 17 | $slug = $fs->get_slug(); |
| 18 | 18 | |
| 19 | - $confirmation_message = $fs->apply_filters( 'uninstall_confirmation_message', '' ); | |
| 19 | + $subscription_cancellation_dialog_box_template_params = $VARS['subscription_cancellation_dialog_box_template_params']; | |
| 20 | + $show_deactivation_feedback_form = $VARS['show_deactivation_feedback_form']; | |
| 21 | + $confirmation_message = $VARS['uninstall_confirmation_message']; | |
| 20 | 22 | |
| 21 | - $reasons = $VARS['reasons']; | |
| 23 | + $is_anonymous = ( ! $fs->is_registered() ); | |
| 24 | + $anonymous_feedback_checkbox_html = ''; | |
| 22 | 25 | |
| 23 | - $reasons_list_items_html = ''; | |
| 26 | + $reasons_list_items_html = ''; | |
| 24 | 27 | |
| 25 | - foreach ( $reasons as $reason ) { | |
| 26 | - $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' ); | |
| 28 | + if ( $show_deactivation_feedback_form ) { | |
| 29 | + $reasons = $VARS['reasons']; | |
| 27 | 30 | |
| 28 | - if ( isset( $reason['internal_message'] ) && ! empty( $reason['internal_message'] ) ) { | |
| 29 | - $list_item_classes .= ' has-internal-message'; | |
| 30 | - $reason_internal_message = $reason['internal_message']; | |
| 31 | - } else { | |
| 32 | - $reason_internal_message = ''; | |
| 33 | - } | |
| 34 | - | |
| 35 | - $reason_input_type = ( ! empty( $reason['input_type'] ) ? $reason['input_type'] : '' ); | |
| 36 | - $reason_input_placeholder = ( ! empty( $reason['input_placeholder'] ) ? $reason['input_placeholder'] : '' ); | |
| 37 | - | |
| 38 | - $reason_list_item_html = <<< HTML | |
| 39 | - <li class="{$list_item_classes}" | |
| 40 | - data-input-type="{$reason_input_type}" | |
| 41 | - data-input-placeholder="{$reason_input_placeholder}"> | |
| 42 | - <label> | |
| 43 | - <span> | |
| 44 | - <input type="radio" name="selected-reason" value="{$reason['id']}"/> | |
| 45 | - </span> | |
| 46 | - <span>{$reason['text']}</span> | |
| 47 | - </label> | |
| 48 | - <div class="internal-message">{$reason_internal_message}</div> | |
| 49 | - </li> | |
| 31 | + foreach ( $reasons as $reason ) { | |
| 32 | + $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' ); | |
| 33 | + | |
| 34 | + if ( isset( $reason['internal_message'] ) && ! empty( $reason['internal_message'] ) ) { | |
| 35 | + $list_item_classes .= ' has-internal-message'; | |
| 36 | + $reason_internal_message = $reason['internal_message']; | |
| 37 | + } else { | |
| 38 | + $reason_internal_message = ''; | |
| 39 | + } | |
| 40 | + | |
| 41 | + $reason_input_type = ( ! empty( $reason['input_type'] ) ? $reason['input_type'] : '' ); | |
| 42 | + $reason_input_placeholder = ( ! empty( $reason['input_placeholder'] ) ? $reason['input_placeholder'] : '' ); | |
| 43 | + | |
| 44 | + $reason_list_item_html = <<< HTML | |
| 45 | + <li class="{$list_item_classes}" | |
| 46 | + data-input-type="{$reason_input_type}" | |
| 47 | + data-input-placeholder="{$reason_input_placeholder}"> | |
| 48 | + <label> | |
| 49 | + <span> | |
| 50 | + <input type="radio" name="selected-reason" value="{$reason['id']}"/> | |
| 51 | + </span> | |
| 52 | + <span>{$reason['text']}</span> | |
| 53 | + </label> | |
| 54 | + <div class="internal-message">{$reason_internal_message}</div> | |
| 55 | + </li> | |
| 50 | 56 | HTML; |
| 51 | 57 | |
| 52 | - $reasons_list_items_html .= $reason_list_item_html; | |
| 53 | - } | |
| 58 | + $reasons_list_items_html .= $reason_list_item_html; | |
| 59 | + } | |
| 54 | 60 | |
| 55 | - $is_anonymous = ( ! $fs->is_registered() ); | |
| 56 | - if ( $is_anonymous ) { | |
| 57 | - $anonymous_feedback_checkbox_html = sprintf( | |
| 58 | - '<label class="anonymous-feedback-label"><input type="checkbox" class="anonymous-feedback-checkbox"> %s</label>', | |
| 59 | - fs_esc_html_inline( 'Anonymous feedback', 'anonymous-feedback', $slug ) | |
| 60 | - ); | |
| 61 | - } else { | |
| 62 | - $anonymous_feedback_checkbox_html = ''; | |
| 63 | - } | |
| 61 | + if ( $is_anonymous ) { | |
| 62 | + $anonymous_feedback_checkbox_html = sprintf( | |
| 63 | + '<label class="anonymous-feedback-label"><input type="checkbox" class="anonymous-feedback-checkbox"> %s</label>', | |
| 64 | + fs_esc_html_inline( 'Anonymous feedback', 'anonymous-feedback', $slug ) | |
| 65 | + ); | |
| 66 | + } | |
| 67 | + } | |
| 64 | 68 | |
| 65 | 69 | // Aliases. |
| 66 | 70 | $deactivate_text = fs_text_inline( 'Deactivate', 'deactivate', $slug ); |
| 67 | 71 | $theme_text = fs_text_inline( 'Theme', 'theme', $slug ); |
| @@ -67,10 +71,13 @@ | ||
| 67 | 71 | $theme_text = fs_text_inline( 'Theme', 'theme', $slug ); |
| 68 | 72 | $activate_x_text = fs_text_inline( 'Activate %s', 'activate-x', $slug ); |
| 69 | 73 | |
| 70 | 74 | fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' ); |
| 75 | + | |
| 76 | + if ( ! empty( $subscription_cancellation_dialog_box_template_params ) ) { | |
| 77 | + fs_require_template( 'forms/subscription-cancellation.php', $subscription_cancellation_dialog_box_template_params ); | |
| 78 | + } | |
| 71 | 79 | ?> |
| 72 | -<?php $fs->_maybe_add_subscription_cancellation_dialog_box() ?> | |
| 73 | 80 | <script type="text/javascript"> |
| 74 | 81 | (function ($) { |
| 75 | 82 | var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ) ?>, |
| 76 | 83 | modalHtml = |
| @@ -98,18 +105,27 @@ | ||
| 98 | 105 | isAnonymous = <?php echo ( $is_anonymous ? 'true' : 'false' ); ?>, |
| 99 | 106 | otherReasonID = <?php echo Freemius::REASON_OTHER; ?>, |
| 100 | 107 | dontShareDataReasonID = <?php echo Freemius::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION; ?>, |
| 101 | 108 | deleteThemeUpdateData = <?php echo $fs->is_theme() && $fs->is_premium() && ! $fs->has_any_active_valid_license() ? 'true' : 'false' ?>, |
| 102 | - $subscriptionCancellationModal = $( '.fs-modal-subscription-cancellation-<?php echo $fs->get_id() ?>' ); | |
| 109 | + $subscriptionCancellationModal = $( '.fs-modal-subscription-cancellation-<?php echo $fs->get_id() ?>' ), | |
| 110 | + showDeactivationFeedbackForm = <?php echo ( $show_deactivation_feedback_form ? 'true' : 'false' ) ?>; | |
| 103 | 111 | |
| 104 | 112 | $modal.appendTo($('body')); |
| 105 | 113 | |
| 106 | 114 | if ( 0 !== $subscriptionCancellationModal.length ) { |
| 107 | 115 | $subscriptionCancellationModal.on( '<?php echo $fs->get_action_tag( 'subscription_cancellation_action' ) ?>', function( evt, cancelSubscription ) { |
| 116 | + var shouldDeactivateModule = ( $modal.hasClass( 'no-confirmation-message' ) && ! showDeactivationFeedbackForm ); | |
| 117 | + | |
| 108 | 118 | if ( false === cancelSubscription ) { |
| 109 | - showModal(); | |
| 119 | + if ( ! shouldDeactivateModule ) { | |
| 120 | + showModal(); | |
| 121 | + } | |
| 110 | 122 | |
| 111 | 123 | $subscriptionCancellationModal.trigger( 'closeModal' ); |
| 124 | + | |
| 125 | + if ( shouldDeactivateModule ) { | |
| 126 | + deactivateModule(); | |
| 127 | + } | |
| 112 | 128 | } else { |
| 113 | 129 | var $errorMessage = $subscriptionCancellationModal.find( '.notice-error' ); |
| 114 | 130 | |
| 115 | 131 | <?php |
| @@ -139,9 +155,14 @@ | ||
| 139 | 155 | $subscriptionCancellationModal.removeClass( 'has-subscription-actions' ); |
| 140 | 156 | $subscriptionCancellationModal.find( '.fs-modal-footer .button-primary' ).removeClass( 'warn' ); |
| 141 | 157 | |
| 142 | 158 | $subscriptionCancellationModal.remove(); |
| 143 | - showModal(); | |
| 159 | + | |
| 160 | + if ( ! shouldDeactivateModule ) { | |
| 161 | + showModal(); | |
| 162 | + } else { | |
| 163 | + deactivateModule(); | |
| 164 | + } | |
| 144 | 165 | } else { |
| 145 | 166 | $errorMessage.find( '> p' ).html( result.error ); |
| 146 | 167 | $errorMessage.show(); |
| 147 | 168 | |
| @@ -190,9 +211,17 @@ | ||
| 190 | 211 | evt.preventDefault(); |
| 191 | 212 | |
| 192 | 213 | redirectLink = $(this).attr('href'); |
| 193 | 214 | |
| 194 | - showModal(); | |
| 215 | + if ( 0 != $subscriptionCancellationModal.length ) { | |
| 216 | + $subscriptionCancellationModal.trigger( 'showModal' ); | |
| 217 | + } else { | |
| 218 | + if ( $modal.hasClass( 'no-confirmation-message' ) && ! showDeactivationFeedbackForm ) { | |
| 219 | + deactivateModule(); | |
| 220 | + } else { | |
| 221 | + showModal(); | |
| 222 | + } | |
| 223 | + } | |
| 195 | 224 | }); |
| 196 | 225 | <?php |
| 197 | 226 | } ?> |
| 198 | 227 | |
| @@ -242,9 +271,9 @@ | ||
| 242 | 271 | var _parent = $(this).parents('.fs-modal:first'); |
| 243 | 272 | var _this = $(this); |
| 244 | 273 | |
| 245 | 274 | if (_this.hasClass('allow-deactivate')) { |
| 246 | - var $radio = $('input[type="radio"]:checked'); | |
| 275 | + var $radio = $modal.find('input[type="radio"]:checked'); | |
| 247 | 276 | |
| 248 | 277 | if (0 === $radio.length) { |
| 249 | 278 | if ( ! deleteThemeUpdateData ) { |
| 250 | 279 | // If no selected reason, just deactivate the plugin. |
| @@ -302,9 +331,13 @@ | ||
| 302 | 331 | } else if (_this.hasClass('button-deactivate')) { |
| 303 | 332 | // Change the Deactivate button's text and show the reasons panel. |
| 304 | 333 | _parent.find('.button-deactivate').addClass('allow-deactivate'); |
| 305 | 334 | |
| 306 | - showPanel('reasons'); | |
| 335 | + if ( showDeactivationFeedbackForm ) { | |
| 336 | + showPanel('reasons'); | |
| 337 | + } else { | |
| 338 | + deactivateModule(); | |
| 339 | + } | |
| 307 | 340 | } |
| 308 | 341 | }); |
| 309 | 342 | |
| 310 | 343 | $modal.on('click', 'input[type="radio"]', function () { |
| @@ -343,9 +376,9 @@ | ||
| 343 | 376 | |
| 344 | 377 | if (_parent.hasClass('has-input')) { |
| 345 | 378 | var inputType = _parent.data('input-type'), |
| 346 | 379 | inputPlaceholder = _parent.data('input-placeholder'), |
| 347 | - reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>'; | |
| 380 | + reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" maxlength="128" />' : '<textarea rows="5" maxlength="128"></textarea>' ) + '</div>'; | |
| 348 | 381 | |
| 349 | 382 | _parent.append($(reasonInputHtml)); |
| 350 | 383 | _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus(); |
| 351 | 384 | |
| @@ -492,6 +525,15 @@ | ||
| 492 | 525 | |
| 493 | 526 | function getCurrentPanel() { |
| 494 | 527 | return $modal.find('.fs-modal-panel.active').attr('data-panel-id'); |
| 495 | 528 | } |
| 529 | + | |
| 530 | + /** | |
| 531 | + * @author Leo Fajardo (@leorw) | |
| 532 | + * | |
| 533 | + * @since 2.3.0 | |
| 534 | + */ | |
| 535 | + function deactivateModule() { | |
| 536 | + window.location.href = redirectLink; | |
| 537 | + } | |
| 496 | 538 | })(jQuery); |
| 497 | 539 | </script> |