PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.13
Code Manager v1.0.13
1.0.48 1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / freemius / templates / forms / optout.php
code-manager / freemius / templates / forms Last commit date
deactivation 4 years ago affiliation.php 4 years ago data-debug-mode.php 4 years ago index.php 4 years ago license-activation.php 4 years ago optout.php 4 years ago premium-versions-upgrade-handler.php 4 years ago premium-versions-upgrade-metadata.php 4 years ago resend-key.php 4 years ago subscription-cancellation.php 4 years ago trial-start.php 4 years ago user-change.php 4 years ago
optout.php
337 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 1.2.1.5
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * @var array $VARS
15 * @var Freemius $fs
16 */
17 $fs = freemius( $VARS['id'] );
18 $slug = $fs->get_slug();
19
20 $action = $fs->is_tracking_allowed() ?
21 'stop_tracking' :
22 'allow_tracking';
23
24 $reconnect_url = $fs->get_activation_url( array(
25 'nonce' => wp_create_nonce( $fs->get_unique_affix() . '_reconnect' ),
26 'fs_action' => ( $fs->get_unique_affix() . '_reconnect' ),
27 ) );
28
29 $plugin_title = "<strong>{$fs->get_plugin()->title}</strong>";
30 $opt_out_text = fs_text_x_inline( 'Opt Out', 'verb', 'opt-out', $slug );
31 $opt_in_text = fs_text_x_inline( 'Opt In', 'verb', 'opt-in', $slug );
32
33 if ( $fs->is_premium() ) {
34 $opt_in_message_appreciation = fs_text_inline( 'Connectivity to the licensing engine was successfully re-established. Automatic security & feature updates are now available through the WP Admin Dashboard.', 'premium-opt-in-message-appreciation', $slug );
35
36 $opt_out_message_subtitle = sprintf( fs_text_inline( 'Warning: Opting out will block automatic updates', 'premium-opt-out-message-appreciation', $slug ), $fs->get_module_type() );
37 $opt_out_message_usage_tracking = sprintf( fs_text_inline( 'Ongoing connectivity with the licensing engine is essential for receiving automatic security & feature updates of the paid product. To receive these updates, data like your license key, %1$s version, and WordPress version, is periodically sent to the server to check for updates. By opting out, you understand that your site won\'t receive automatic updates for %2$s from within the WP Admin Dashboard. This can put your site at risk, and we highly recommend to keep this connection active. If you do choose to opt-out, you\'ll need to check for %1$s updates and install them manually.', 'premium-opt-out-message-usage-tracking', $slug ), $fs->get_module_type(), $plugin_title );
38
39 $primary_cta_label = fs_text_inline( 'I\'d like to keep automatic updates', 'premium-opt-out-cancel', $slug );
40 } else {
41 $opt_in_message_appreciation = sprintf( fs_text_inline( 'We appreciate your help in making the %s better by letting us track some usage data.', 'opt-in-message-appreciation', $slug ), $fs->get_module_type() );
42
43 $opt_out_message_subtitle = $opt_in_message_appreciation;
44 $opt_out_message_usage_tracking = sprintf( fs_text_inline( "Usage tracking is done in the name of making %s better. Making a better user experience, prioritizing new features, and more good things. We'd really appreciate if you'll reconsider letting us continue with the tracking.", 'opt-out-message-usage-tracking', $slug ), $plugin_title );
45 $primary_cta_label = fs_text_inline( 'On second thought - I want to continue helping', 'opt-out-cancel', $slug );
46 }
47
48 $opt_out_message_clicking_opt_out = sprintf(
49 fs_text_inline( 'By clicking "Opt Out", we will no longer be sending any data from %s to %s.', 'opt-out-message-clicking-opt-out', $slug ),
50 $plugin_title,
51 sprintf(
52 '<a href="%s" target="_blank" rel="noopener">%s</a>',
53 'https://freemius.com',
54 'freemius.com'
55 )
56 );
57
58 $admin_notice_params = array(
59 'id' => '',
60 'slug' => $fs->get_id(),
61 'type' => 'success',
62 'sticky' => false,
63 'plugin' => $fs->get_plugin()->title,
64 'message' => $opt_in_message_appreciation
65 );
66
67 $admin_notice_html = fs_get_template( 'admin-notice.php', $admin_notice_params );
68
69 $modal_content_html = "
70 <h2" . ( $fs->is_premium() ? ' style="color: red"' : '' ) . ">{$opt_out_message_subtitle}</h2>
71 <div class=\"notice notice-error inline opt-out-error-message\"><p></p></div>
72 <p>{$opt_out_message_usage_tracking}</p>
73 <p>{$opt_out_message_clicking_opt_out}</p>
74 <label class=\"fs-permission-extensions\"><div class=\"fs-switch fs-small fs-round fs-" . ( $fs->is_extensions_tracking_allowed() ? 'on' : 'off' ) . "\"><div class=\"fs-toggle\"></div></div> " . fs_text_inline( 'Plugins & themes tracking' ) . " <span class=\"fs-switch-feedback success\"></span></label>";
75
76 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
77 fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
78 ?>
79 <script type="text/javascript">
80 (function( $ ) {
81 $( document ).ready(function() {
82 var modalContentHtml = <?php echo json_encode( $modal_content_html ) ?>,
83 modalHtml =
84 '<div class="fs-modal fs-modal-opt-out">'
85 + ' <div class="fs-modal-dialog">'
86 + ' <div class="fs-modal-header">'
87 + ' <h4><?php echo esc_js( $opt_out_text ) ?></h4>'
88 + ' </div>'
89 + ' <div class="fs-modal-body">'
90 + ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
91 + ' </div>'
92 + ' <div class="fs-modal-footer">'
93 + ' <button class="button <?php echo $fs->is_premium() ? 'button-primary warn' : 'button-secondary' ?> button-opt-out" tabindex="1"><?php echo esc_js( $opt_out_text ) ?></button>'
94 + ' <button class="button <?php echo $fs->is_premium() ? 'button-secondary' : 'button-primary' ?> button-close" tabindex="2"><?php echo esc_js( $primary_cta_label ) ?></button>'
95 + ' </div>'
96 + ' </div>'
97 + '</div>',
98 $modal = $(modalHtml),
99 $adminNotice = $( <?php echo json_encode( $admin_notice_html ) ?> ),
100 action = '<?php echo $action ?>',
101 actionLinkSelector = 'span.opt-in-or-opt-out.<?php echo $slug ?> a',
102 $optOutButton = $modal.find( '.button-opt-out' ),
103 $optOutErrorMessage = $modal.find( '.opt-out-error-message' ),
104 $extensionsTracking = $modal.find( '.fs-permission-extensions' ),
105 $body = $( 'body' ),
106 moduleID = '<?php echo $fs->get_id() ?>';
107
108 $modal.data( 'action', action );
109 $modal.appendTo( $body );
110
111 function registerActionLinkClick() {
112 $body.on( 'click', actionLinkSelector, function( evt ) {
113 evt.preventDefault();
114
115 if ( 'stop_tracking' == $modal.data( 'action' ) ) {
116 showModal();
117 } else {
118 optIn();
119 }
120
121 return false;
122 });
123 }
124
125 function registerEventHandlers() {
126 registerActionLinkClick();
127
128 $modal.on( 'click', '.button-opt-out', function( evt ) {
129 evt.preventDefault();
130
131 if ( $( this ).hasClass( 'disabled' ) ) {
132 return;
133 }
134
135 disableOptOutButton();
136 optOut();
137 });
138
139 // If the user has clicked outside the window, close the modal.
140 $modal.on( 'click', '.fs-close, .button-close', function() {
141 closeModal();
142 return false;
143 });
144 }
145
146 <?php if ( $fs->is_registered() ) : ?>
147 registerEventHandlers();
148 <?php endif ?>
149
150 function showModal() {
151 resetModal();
152
153 // Display the dialog box.
154 $modal.addClass( 'active' );
155 $body.addClass( 'has-fs-modal' );
156 }
157
158 function closeModal() {
159 $modal.removeClass( 'active' );
160 $body.removeClass( 'has-fs-modal' );
161 }
162
163 function resetOptOutButton() {
164 enableOptOutButton();
165 $optOutButton.text( <?php echo json_encode( $opt_out_text ) ?> );
166 }
167
168 function resetModal() {
169 hideError();
170 resetOptOutButton();
171 }
172
173 function optIn() {
174 sendRequest();
175 }
176
177 function optOut() {
178 sendRequest();
179 }
180
181 function sendRequest() {
182 var $actionLink = $( actionLinkSelector );
183
184 $.ajax({
185 url: ajaxurl,
186 method: 'POST',
187 data: {
188 action : ( 'stop_tracking' == action ?
189 '<?php echo $fs->get_ajax_action( 'stop_tracking' ) ?>' :
190 '<?php echo $fs->get_ajax_action( 'allow_tracking' ) ?>'
191 ),
192 security : ( 'stop_tracking' == action ?
193 '<?php echo $fs->get_ajax_security( 'stop_tracking' ) ?>' :
194 '<?php echo $fs->get_ajax_security( 'allow_tracking' ) ?>'
195 ),
196 module_id: moduleID,
197 _wp_http_referer: '<?php echo $fs->current_page_url() ?>'
198 },
199 beforeSend: function() {
200 if ( 'allow_tracking' == action ) {
201 $actionLink.text( '<?php fs_esc_js_echo_inline( 'Opting in', 'opting-in', $slug ) ?>...' );
202 } else {
203 $optOutButton.text( '<?php fs_esc_js_echo_inline( 'Opting out', 'opting-out', $slug ) ?>...' );
204 }
205 },
206 success: function( resultObj ) {
207 if ( resultObj.success ) {
208 if ( 'allow_tracking' == action ) {
209 action = 'stop_tracking';
210 $actionLink.text( '<?php echo esc_js( $opt_out_text ) ?>' );
211 showOptInAppreciationMessageAndScrollToTop();
212 } else {
213 action = 'allow_tracking';
214 $actionLink.text( '<?php echo esc_js( $opt_in_text ) ?>' );
215 closeModal();
216
217 if ( $adminNotice.length > 0 ) {
218 $adminNotice.remove();
219 }
220 }
221
222 $modal.data( 'action', action );
223 } else {
224 showError( resultObj.error );
225 resetOptOutButton();
226 }
227 }
228 });
229 }
230
231 var isUpdatingPermission = false;
232 $extensionsTracking.on('click', function() {
233 if (isUpdatingPermission) {
234 return false;
235 }
236
237 isUpdatingPermission = true;
238
239 var $switch = $extensionsTracking.find( '.fs-switch' ),
240 $switchFeedback = $extensionsTracking.find( '.fs-switch-feedback' );
241
242 $switch
243 .toggleClass( 'fs-on' )
244 .toggleClass( 'fs-off' );
245
246 $switchFeedback.html( '<i class="fs-ajax-spinner"></i>' );
247
248 $.ajax({
249 url: ajaxurl,
250 method: 'POST',
251 data: {
252 action : '<?php echo $fs->get_ajax_action( 'update_tracking_permission' ) ?>',
253 security : '<?php echo $fs->get_ajax_security( 'update_tracking_permission' ) ?>',
254 module_id : moduleID,
255 _wp_http_referer: '<?php echo $fs->current_page_url() ?>',
256 permission: 'extensions',
257 is_enabled: $switch.hasClass('fs-on')
258 },
259 success: function( resultObj ) {
260 if ( resultObj.success ) {
261 $switchFeedback.html( '<i class="dashicons dashicons-yes"></i> <?php echo esc_js( fs_text_inline( 'Saved', 'saved', $slug ) ) ?>' )
262 } else {
263 $switch
264 .toggleClass( 'fs-on' )
265 .toggleClass( 'fs-off' );
266 }
267
268 isUpdatingPermission = false;
269 }
270 });
271 });
272
273 function enableOptOutButton() {
274 $optOutButton.removeClass( 'disabled' );
275 }
276
277 function disableOptOutButton() {
278 $optOutButton.addClass( 'disabled' );
279 }
280
281 function hideError() {
282 $optOutErrorMessage.hide();
283 }
284
285 function showOptInAppreciationMessageAndScrollToTop() {
286 $adminNotice.insertAfter( $( '#wpbody-content' ).find( ' > .wrap > h1' ) );
287 window.scrollTo(0, 0);
288 }
289
290 function showError( msg ) {
291 $optOutErrorMessage.find( ' > p' ).html( msg );
292 $optOutErrorMessage.show();
293 }
294
295 <?php if ( $fs->is_theme() ) : ?>
296 /**
297 * Add opt-in/out button to the active theme's buttons collection
298 * in the theme's extended details overlay.
299 *
300 * @author Vova Feldman (@svovaf)
301 * @since 1.2.2.7
302 */
303 $('.theme-overlay').contentChange(function () {
304 if (0 === $('.theme-overlay.active').length) {
305 // Add opt-in/out button only to the currently active theme.
306 return;
307 }
308
309 if ($('#fs_theme_opt_in_out').length > 0){
310 // Button already there.
311 return;
312 }
313
314 var label = (('stop_tracking' == action) ?
315 '<?php echo esc_js( $opt_out_text ) ?>' :
316 '<?php echo esc_js( $opt_in_text ) ?>'),
317 href = (('stop_tracking' != action) ?
318 '<?php echo ( $fs->is_registered() ? '' : esc_js( $reconnect_url ) ) ?>' :
319 '');
320
321 var $actionLink = $('<a id="fs_theme_opt_in_out" href="' + encodeURI(href) + '" class="button">' + label + '</a>');
322
323 actionLinkSelector = '#fs_theme_opt_in_out';
324
325 $modal.data( 'action', action );
326
327 $('.theme-wrap .theme-actions .active-theme').append($actionLink);
328
329 if ('' === href) {
330 registerActionLinkClick();
331 }
332 });
333 <?php endif ?>
334 });
335 })( jQuery );
336 </script>
337