PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.0
Code Manager v1.0.0
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 5 years ago affiliation.php 5 years ago data-debug-mode.php 5 years ago index.php 5 years ago license-activation.php 5 years ago optout.php 5 years ago premium-versions-upgrade-handler.php 5 years ago premium-versions-upgrade-metadata.php 5 years ago resend-key.php 5 years ago subscription-cancellation.php 5 years ago trial-start.php 5 years ago user-change.php 5 years ago
optout.php
330 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">%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 $actionLink = $( '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 moduleID = '<?php echo $fs->get_id() ?>';
106
107 $actionLink.attr( 'data-action', action );
108 $modal.appendTo( $( 'body' ) );
109
110 function registerActionLinkClick() {
111 $actionLink.click(function( evt ) {
112 evt.preventDefault();
113
114 if ( 'stop_tracking' == $actionLink.attr( 'data-action' ) ) {
115 showModal();
116 } else {
117 optIn();
118 }
119
120 return false;
121 });
122 }
123
124 function registerEventHandlers() {
125 registerActionLinkClick();
126
127 $modal.on( 'click', '.button-opt-out', function( evt ) {
128 evt.preventDefault();
129
130 if ( $( this ).hasClass( 'disabled' ) ) {
131 return;
132 }
133
134 disableOptOutButton();
135 optOut();
136 });
137
138 // If the user has clicked outside the window, close the modal.
139 $modal.on( 'click', '.fs-close, .button-close', function() {
140 closeModal();
141 return false;
142 });
143 }
144
145 <?php if ( $fs->is_registered() ) : ?>
146 registerEventHandlers();
147 <?php endif ?>
148
149 function showModal() {
150 resetModal();
151
152 // Display the dialog box.
153 $modal.addClass( 'active' );
154 $( 'body' ).addClass( 'has-fs-modal' );
155 }
156
157 function closeModal() {
158 $modal.removeClass( 'active' );
159 $( 'body' ).removeClass( 'has-fs-modal' );
160 }
161
162 function resetOptOutButton() {
163 enableOptOutButton();
164 $optOutButton.text( <?php echo json_encode( $opt_out_text ) ?> );
165 }
166
167 function resetModal() {
168 hideError();
169 resetOptOutButton();
170 }
171
172 function optIn() {
173 sendRequest();
174 }
175
176 function optOut() {
177 sendRequest();
178 }
179
180 function sendRequest() {
181 $.ajax({
182 url: ajaxurl,
183 method: 'POST',
184 data: {
185 action : ( 'stop_tracking' == action ?
186 '<?php echo $fs->get_ajax_action( 'stop_tracking' ) ?>' :
187 '<?php echo $fs->get_ajax_action( 'allow_tracking' ) ?>'
188 ),
189 security : ( 'stop_tracking' == action ?
190 '<?php echo $fs->get_ajax_security( 'stop_tracking' ) ?>' :
191 '<?php echo $fs->get_ajax_security( 'allow_tracking' ) ?>'
192 ),
193 module_id: moduleID,
194 _wp_http_referer: '<?php echo $fs->current_page_url() ?>'
195 },
196 beforeSend: function() {
197 if ( 'allow_tracking' == action ) {
198 $actionLink.text( '<?php fs_esc_js_echo_inline( 'Opting in', 'opting-in', $slug ) ?>...' );
199 } else {
200 $optOutButton.text( '<?php fs_esc_js_echo_inline( 'Opting out', 'opting-out', $slug ) ?>...' );
201 }
202 },
203 success: function( resultObj ) {
204 if ( resultObj.success ) {
205 if ( 'allow_tracking' == action ) {
206 action = 'stop_tracking';
207 $actionLink.text( '<?php echo esc_js( $opt_out_text ) ?>' );
208 showOptInAppreciationMessageAndScrollToTop();
209 } else {
210 action = 'allow_tracking';
211 $actionLink.text( '<?php echo esc_js( $opt_in_text ) ?>' );
212 closeModal();
213
214 if ( $adminNotice.length > 0 ) {
215 $adminNotice.remove();
216 }
217 }
218
219 $actionLink.attr( 'data-action', action );
220 } else {
221 showError( resultObj.error );
222 resetOptOutButton();
223 }
224 }
225 });
226 }
227
228 var isUpdatingPermission = false;
229 $extensionsTracking.on('click', function() {
230 if (isUpdatingPermission) {
231 return false;
232 }
233
234 isUpdatingPermission = true;
235
236 var $switch = $extensionsTracking.find( '.fs-switch' ),
237 $switchFeedback = $extensionsTracking.find( '.fs-switch-feedback' );
238
239 $switch
240 .toggleClass( 'fs-on' )
241 .toggleClass( 'fs-off' );
242
243 $switchFeedback.html( '<i class="fs-ajax-spinner"></i>' );
244
245 $.ajax({
246 url: ajaxurl,
247 method: 'POST',
248 data: {
249 action : '<?php echo $fs->get_ajax_action( 'update_tracking_permission' ) ?>',
250 security : '<?php echo $fs->get_ajax_security( 'update_tracking_permission' ) ?>',
251 module_id : moduleID,
252 _wp_http_referer: '<?php echo $fs->current_page_url() ?>',
253 permission: 'extensions',
254 is_enabled: $switch.hasClass('fs-on')
255 },
256 success: function( resultObj ) {
257 if ( resultObj.success ) {
258 $switchFeedback.html( '<i class="dashicons dashicons-yes"></i> <?php echo esc_js( fs_text_inline( 'Saved', 'saved', $slug ) ) ?>' )
259 } else {
260 $switch
261 .toggleClass( 'fs-on' )
262 .toggleClass( 'fs-off' );
263 }
264
265 isUpdatingPermission = false;
266 }
267 });
268 });
269
270 function enableOptOutButton() {
271 $optOutButton.removeClass( 'disabled' );
272 }
273
274 function disableOptOutButton() {
275 $optOutButton.addClass( 'disabled' );
276 }
277
278 function hideError() {
279 $optOutErrorMessage.hide();
280 }
281
282 function showOptInAppreciationMessageAndScrollToTop() {
283 $adminNotice.insertAfter( $( '#wpbody-content' ).find( ' > .wrap > h1' ) );
284 window.scrollTo(0, 0);
285 }
286
287 function showError( msg ) {
288 $optOutErrorMessage.find( ' > p' ).html( msg );
289 $optOutErrorMessage.show();
290 }
291
292 <?php if ( $fs->is_theme() ) : ?>
293 /**
294 * Add opt-in/out button to the active theme's buttons collection
295 * in the theme's extended details overlay.
296 *
297 * @author Vova Feldman (@svovaf)
298 * @since 1.2.2.7
299 */
300 $('.theme-overlay').contentChange(function () {
301 if (0 === $('.theme-overlay.active').length) {
302 // Add opt-in/out button only to the currently active theme.
303 return;
304 }
305
306 if ($('#fs_theme_opt_in_out').length > 0){
307 // Button already there.
308 return;
309 }
310
311 var label = (('stop_tracking' == action) ?
312 '<?php echo esc_js( $opt_out_text ) ?>' :
313 '<?php echo esc_js( $opt_in_text ) ?>'),
314 href = (('stop_tracking' != action) ?
315 '<?php echo ( $fs->is_registered() ? '' : esc_js( $reconnect_url ) ) ?>' :
316 '');
317
318 $actionLink = $('<a id="fs_theme_opt_in_out" href="' + encodeURI(href) + '" class="button" data-action="' + action + '">' + label + '</a>');
319
320 $('.theme-wrap .theme-actions .active-theme').append($actionLink);
321
322 if ('' === href) {
323 registerActionLinkClick();
324 }
325 });
326 <?php endif ?>
327 });
328 })( jQuery );
329 </script>
330