deactivation
5 days ago
affiliation.php
5 days ago
data-debug-mode.php
5 days ago
email-address-update.php
5 days ago
index.php
5 days ago
license-activation.php
5 days ago
optout.php
5 days ago
premium-versions-upgrade-handler.php
5 days ago
premium-versions-upgrade-metadata.php
5 days ago
resend-key.php
5 days ago
subscription-cancellation.php
5 days ago
trial-start.php
5 days ago
user-change.php
5 days ago
subscription-cancellation.php
277 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 | * @since 2.2.1 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * @var array $VARS |
| 15 | */ |
| 16 | $fs = freemius( $VARS['id'] ); |
| 17 | $slug = $fs->get_slug(); |
| 18 | |
| 19 | /** |
| 20 | * @var FS_Plugin_License $license |
| 21 | */ |
| 22 | $license = $VARS['license']; |
| 23 | |
| 24 | $has_trial = $VARS['has_trial']; |
| 25 | |
| 26 | $subscription_cancellation_context = $has_trial ? |
| 27 | fs_text_inline( 'trial', 'trial', $slug ) : |
| 28 | fs_text_inline( 'subscription', 'subscription', $slug ); |
| 29 | |
| 30 | $plan = $fs->get_plan(); |
| 31 | $module_label = $fs->get_module_label( true ); |
| 32 | |
| 33 | if ( $VARS['is_license_deactivation'] ) { |
| 34 | $subscription_cancellation_text = ''; |
| 35 | } else { |
| 36 | $subscription_cancellation_text = sprintf( |
| 37 | fs_text_inline( |
| 38 | "Deactivating or uninstalling the %s will automatically disable the license, which you'll be able to use on another site.", |
| 39 | 'deactivation-or-uninstall-message', |
| 40 | $slug |
| 41 | ), |
| 42 | $module_label |
| 43 | ) . ' '; |
| 44 | } |
| 45 | |
| 46 | $subscription_cancellation_text .= sprintf( |
| 47 | fs_text_inline( |
| 48 | 'In case you are NOT planning on using this %s on this site (or any other site) - would you like to cancel the %s as well?', |
| 49 | 'cancel-subscription-message', |
| 50 | $slug |
| 51 | ), |
| 52 | ( $VARS['is_license_deactivation'] ? fs_text_inline( 'license', 'license', $slug ) : $module_label ), |
| 53 | $subscription_cancellation_context |
| 54 | ); |
| 55 | |
| 56 | $cancel_subscription_action_label = sprintf( |
| 57 | fs_esc_html_inline( |
| 58 | "Cancel %s - I no longer need any security & feature updates, nor support for %s because I'm not planning to use the %s on this, or any other site.", |
| 59 | 'cancel-x', |
| 60 | $slug |
| 61 | ), |
| 62 | esc_html( $subscription_cancellation_context ), |
| 63 | sprintf( '<strong>%s</strong>', esc_html( $fs->get_plugin_title() ) ), |
| 64 | esc_html( $module_label ) |
| 65 | ); |
| 66 | |
| 67 | $keep_subscription_active_action_label = esc_html( sprintf( |
| 68 | fs_text_inline( |
| 69 | "Don't cancel %s - I'm still interested in getting security & feature updates, as well as be able to contact support.", |
| 70 | 'dont-cancel-x', |
| 71 | $slug |
| 72 | ), |
| 73 | $subscription_cancellation_context |
| 74 | ) ); |
| 75 | |
| 76 | $subscription_cancellation_text = esc_html( $subscription_cancellation_text ); |
| 77 | |
| 78 | $subscription_cancellation_html = <<< HTML |
| 79 | <div class="notice notice-error inline"><p></p></div><p>{$subscription_cancellation_text}</p> |
| 80 | <ul class="subscription-actions"> |
| 81 | <li> |
| 82 | <label> |
| 83 | <input type="radio" name="cancel-subscription" value="false"/> |
| 84 | <span>{$keep_subscription_active_action_label}</span> |
| 85 | </label> |
| 86 | </li> |
| 87 | <li> |
| 88 | <label> |
| 89 | <input type="radio" name="cancel-subscription" value="true"/> |
| 90 | <span>{$cancel_subscription_action_label}</span> |
| 91 | </label> |
| 92 | </li> |
| 93 | </ul> |
| 94 | HTML; |
| 95 | |
| 96 | $downgrading_plan_text = fs_text_inline( 'Downgrading your plan', 'downgrading-plan', $slug ); |
| 97 | $cancelling_subscription_text = fs_text_inline( 'Cancelling the subscription', 'cancelling-subscription', $slug ); |
| 98 | /* translators: %1$s: Either 'Downgrading your plan' or 'Cancelling the subscription' */ |
| 99 | $downgrade_x_confirm_text = fs_text_inline( '%1$s will immediately stop all future recurring payments and your %2$s plan license will expire in %3$s.', 'downgrade-x-confirm', $slug ); |
| 100 | $prices_increase_text = fs_text_inline( 'Please note that we will not be able to grandfather outdated pricing for renewals/new subscriptions after a cancellation. If you choose to renew the subscription manually in the future, after a price increase, which typically occurs once a year, you will be charged the updated price.', 'pricing-increase-warning', $slug ); |
| 101 | $after_downgrade_non_blocking_text = fs_text_inline( 'You can still enjoy all %s features but you will not have access to %s security & feature updates, nor support.', 'after-downgrade-non-blocking', $slug ); |
| 102 | $after_downgrade_blocking_text = fs_text_inline( 'Once your license expires you can still use the Free version but you will NOT have access to the %s features.', 'after-downgrade-blocking', $slug ); |
| 103 | $after_downgrade_blocking_text_premium_only = fs_text_inline( 'Once your license expires you will no longer be able to use the %s, unless you activate it again with a valid premium license.', 'after-downgrade-blocking-premium-only', $slug ); |
| 104 | |
| 105 | $subscription_cancellation_confirmation_message = $has_trial ? |
| 106 | fs_text_inline( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'cancel-trial-confirm', $slug ) : |
| 107 | sprintf( |
| 108 | '%s %s %s %s', |
| 109 | sprintf( |
| 110 | $downgrade_x_confirm_text, |
| 111 | ($fs->is_only_premium() ? $cancelling_subscription_text : $downgrading_plan_text ), |
| 112 | $plan->title, |
| 113 | human_time_diff( time(), strtotime( $license->expiration ) ) |
| 114 | ), |
| 115 | ( |
| 116 | $license->is_block_features ? |
| 117 | ( |
| 118 | $fs->is_only_premium() ? |
| 119 | sprintf( $after_downgrade_blocking_text_premium_only, $module_label ) : |
| 120 | sprintf( $after_downgrade_blocking_text, $plan->title ) |
| 121 | ) : |
| 122 | sprintf( $after_downgrade_non_blocking_text, $plan->title, $fs->get_module_label( true ) ) |
| 123 | ), |
| 124 | $prices_increase_text, |
| 125 | fs_esc_attr_inline( 'Are you sure you want to proceed?', 'proceed-confirmation', $slug ) |
| 126 | ); |
| 127 | |
| 128 | fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' ); |
| 129 | ?> |
| 130 | <script type="text/javascript"> |
| 131 | (function( $ ) { |
| 132 | var modalHtml = |
| 133 | '<div class="fs-modal fs-modal-subscription-cancellation fs-modal-subscription-cancellation-<?php echo $fs->get_id() ?>">' |
| 134 | + ' <div class="fs-modal-dialog">' |
| 135 | + ' <div class="fs-modal-header">' |
| 136 | + ' <h4><?php echo esc_html( sprintf( fs_text_inline( 'Cancel %s?', 'cancel-x', $slug ), ucfirst( $subscription_cancellation_context ) ) ) ?></h4>' |
| 137 | + ' </div>' |
| 138 | + ' <div class="fs-modal-body">' |
| 139 | + ' <div class="fs-modal-panel active">' + <?php echo json_encode( $subscription_cancellation_html ) ?> + '<p class="fs-price-increase-warning" style="display: none;">' + <?php echo json_encode( $prices_increase_text ) ?> + '</p></div>' |
| 140 | + ' </div>' |
| 141 | + ' <div class="fs-modal-footer">' |
| 142 | + ' <a href="#" class="button button-secondary button-close"><?php fs_esc_attr_echo_inline( 'Cancel', 'cancel', $slug ) ?></a>' |
| 143 | + ' <a href="#" class="button button-primary button-deactivate disabled"><?php fs_esc_attr_echo_inline( 'Proceed', 'proceed', $slug ) ?></a>' |
| 144 | + ' </div>' |
| 145 | + ' </div>' |
| 146 | + '</div>', |
| 147 | $modal = $(modalHtml); |
| 148 | |
| 149 | $modal.appendTo($('body')); |
| 150 | |
| 151 | registerEventHandlers(); |
| 152 | |
| 153 | function registerEventHandlers() { |
| 154 | $modal.on( 'showModal', function() { |
| 155 | showModal(); |
| 156 | }); |
| 157 | |
| 158 | $modal.on( 'closeModal', function() { |
| 159 | closeModal(); |
| 160 | }); |
| 161 | |
| 162 | $modal.on('click', '.fs-modal-footer .button', function (evt) { |
| 163 | evt.preventDefault(); |
| 164 | |
| 165 | if ($(this).hasClass('disabled')) { |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | var _this = $(this), |
| 170 | subscriptionCancellationActionEventName = <?php echo json_encode( $fs->get_action_tag( 'subscription_cancellation_action' ) ) ?>; |
| 171 | |
| 172 | if ( _this.hasClass( 'button-primary' ) ) { |
| 173 | if ( 'true' !== $modal.find( 'input[name="cancel-subscription"]:checked' ).val() ) { |
| 174 | $modal.trigger( subscriptionCancellationActionEventName, false ); |
| 175 | } else { |
| 176 | if ( confirm( <?php echo json_encode( $subscription_cancellation_confirmation_message ) ?> ) ) { |
| 177 | $modal.trigger( subscriptionCancellationActionEventName, true ); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | }); |
| 182 | |
| 183 | $modal.on('click', 'input[type="radio"]', function () { |
| 184 | var |
| 185 | $selectedOption = $( this ), |
| 186 | $primaryButton = $modal.find( '.button-primary' ), |
| 187 | isSelected = ( 'true' === $selectedOption.val() ); |
| 188 | |
| 189 | if ( isSelected ) { |
| 190 | $primaryButton.html( <?php echo json_encode( sprintf( |
| 191 | fs_text_inline( 'Cancel %s & Proceed', 'cancel-x-and-proceed', $slug ), |
| 192 | ucfirst( $subscription_cancellation_context ) |
| 193 | ) ) ?> ); |
| 194 | |
| 195 | $modal.find('.fs-price-increase-warning').show(); |
| 196 | } else { |
| 197 | $primaryButton.html( <?php fs_json_encode_echo_inline( 'Proceed', 'proceed', $slug ) ?> ); |
| 198 | $modal.find('.fs-price-increase-warning').hide(); |
| 199 | } |
| 200 | |
| 201 | $primaryButton.toggleClass( 'warn', isSelected ); |
| 202 | $primaryButton.removeClass( 'disabled' ); |
| 203 | }); |
| 204 | |
| 205 | // If the user has clicked outside the window, cancel it. |
| 206 | $modal.on('click', function (evt) { |
| 207 | var $target = $(evt.target); |
| 208 | |
| 209 | // If the user has clicked anywhere in the modal dialog, just return. |
| 210 | if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) { |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. |
| 215 | if ( |
| 216 | ( ! $target.hasClass( 'button-close' ) ) && |
| 217 | ( $target.parents( '.fs-modal-body' ).length > 0 || $target.parents( '.fs-modal-footer' ).length > 0 ) |
| 218 | ) { |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | closeModal(); |
| 223 | |
| 224 | return false; |
| 225 | }); |
| 226 | } |
| 227 | |
| 228 | function showModal() { |
| 229 | resetModal(); |
| 230 | |
| 231 | // Display the dialog box. |
| 232 | $modal.addClass('active'); |
| 233 | |
| 234 | $('body').addClass('has-fs-modal'); |
| 235 | } |
| 236 | |
| 237 | function closeModal() { |
| 238 | var activeModalsCount = $( '.fs-modal.active' ).length; |
| 239 | |
| 240 | $modal.removeClass('active'); |
| 241 | |
| 242 | // If child modal, do not remove the "has-fs-modal" class of the <body> element to keep its scrollbars hidden. |
| 243 | if ( activeModalsCount > 1 ) { |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | $('body').removeClass('has-fs-modal'); |
| 248 | } |
| 249 | |
| 250 | function resetModal() { |
| 251 | updateButtonLabels(); |
| 252 | |
| 253 | if ( 0 === $modal.find( '.subscription-actions' ).length ) { |
| 254 | $modal.find('.button-deactivate').removeClass('disabled'); |
| 255 | } else { |
| 256 | $modal.find('.button-deactivate').addClass('disabled'); |
| 257 | } |
| 258 | |
| 259 | $modal.find('.fs-price-increase-warning').hide(); |
| 260 | |
| 261 | // Uncheck all radio buttons. |
| 262 | $modal.find('input[type="radio"]').prop('checked', false); |
| 263 | |
| 264 | $modal.find('.message').hide(); |
| 265 | } |
| 266 | |
| 267 | function showMessage(message) { |
| 268 | $modal.find('.message').text(message).show(); |
| 269 | } |
| 270 | |
| 271 | function updateButtonLabels() { |
| 272 | $modal.find('.button-primary').text( <?php fs_json_encode_echo_inline( 'Proceed', 'proceed', $slug ) ?> ); |
| 273 | |
| 274 | $modal.find('.button-secondary').text( <?php fs_json_encode_echo_inline( 'Cancel', 'cancel', $slug ) ?> ); |
| 275 | } |
| 276 | })( jQuery ); |
| 277 | </script> |