PluginProbe
Tiered Pricing Table for WooCommerce / 2.1
Tiered Pricing Table for WooCommerce v2.1
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / freemius / templates / forms / optout.php

optout.php in Tiered Pricing Table for WooCommerce 2.1, at freemius/templates/forms/optout.php

268 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $opt_out_message_appreciation = sprintf( fs_text_inline( 'We appreciate your help in making the %s better by letting us track some usage data.', 'opt-out-message-appreciation', $slug ), $fs->get_module_type() );
33 $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 );
34 $opt_out_message_clicking_opt_out = sprintf(
35 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 ),
36 $plugin_title,
37 sprintf(
38 '<a href="%s" target="_blank">%s</a>',
39 'https://freemius.com',
40 'freemius.com'
41 )
42 );
43
44 $admin_notice_params = array(
45 'id' => '',
46 'slug' => $fs->get_id(),
47 'type' => 'success',
48 'sticky' => false,
49 'plugin' => $fs->get_plugin()->title,
50 'message' => $opt_out_message_appreciation
51 );
52
53 $admin_notice_html = fs_get_template( 'admin-notice.php', $admin_notice_params );
54
55 $modal_content_html = <<< HTML
56 <h2>{$opt_out_message_appreciation}</h2>
57 <div class="notice notice-error inline opt-out-error-message"><p></p></div>
58 <p>{$opt_out_message_usage_tracking}</p>
59 <p>{$opt_out_message_clicking_opt_out}</p>
60 HTML;
61
62 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
63 fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
64 ?>
65 <script type="text/javascript">
66 (function( $ ) {
67 $( document ).ready(function() {
68 var modalContentHtml = <?php echo json_encode( $modal_content_html ) ?>,
69 modalHtml =
70 '<div class="fs-modal fs-modal-opt-out">'
71 + ' <div class="fs-modal-dialog">'
72 + ' <div class="fs-modal-header">'
73 + ' <h4><?php echo esc_js( $opt_out_text ) ?></h4>'
74 + ' </div>'
75 + ' <div class="fs-modal-body">'
76 + ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
77 + ' </div>'
78 + ' <div class="fs-modal-footer">'
79 + ' <button class="button button-secondary button-opt-out" tabindex="1"><?php echo esc_js( $opt_out_text ) ?></button>'
80 + ' <button class="button button-primary button-close" tabindex="2"><?php fs_esc_js_echo_inline( 'On second thought - I want to continue helping', 'opt-out-cancel', $slug ) ?></button>'
81 + ' </div>'
82 + ' </div>'
83 + '</div>',
84 $modal = $( modalHtml ),
85 $adminNotice = $( <?php echo json_encode( $admin_notice_html ) ?> ),
86 action = '<?php echo $action ?>',
87 $actionLink = $( 'span.opt-in-or-opt-out.<?php echo $slug ?> a' ),
88 $optOutButton = $modal.find( '.button-opt-out' ),
89 $optOutErrorMessage = $modal.find( '.opt-out-error-message' ),
90 moduleID = '<?php echo $fs->get_id() ?>';
91
92 $actionLink.attr( 'data-action', action );
93 $modal.appendTo( $( 'body' ) );
94
95 function registerActionLinkClick() {
96 $actionLink.click(function( evt ) {
97 evt.preventDefault();
98
99 if ( 'stop_tracking' == $actionLink.attr( 'data-action' ) ) {
100 showModal();
101 } else {
102 optIn();
103 }
104
105 return false;
106 });
107 }
108
109 function registerEventHandlers() {
110 registerActionLinkClick();
111
112 $modal.on( 'click', '.button-opt-out', function( evt ) {
113 evt.preventDefault();
114
115 if ( $( this ).hasClass( 'disabled' ) ) {
116 return;
117 }
118
119 disableOptOutButton();
120 optOut();
121 });
122
123 // If the user has clicked outside the window, close the modal.
124 $modal.on( 'click', '.fs-close, .button-close', function() {
125 closeModal();
126 return false;
127 });
128 }
129
130 registerEventHandlers();
131
132 function showModal() {
133 resetModal();
134
135 // Display the dialog box.
136 $modal.addClass( 'active' );
137 $( 'body' ).addClass( 'has-fs-modal' );
138 }
139
140 function closeModal() {
141 $modal.removeClass( 'active' );
142 $( 'body' ).removeClass( 'has-fs-modal' );
143 }
144
145 function resetOptOutButton() {
146 enableOptOutButton();
147 $optOutButton.text( <?php echo json_encode( $opt_out_text ) ?> );
148 }
149
150 function resetModal() {
151 hideError();
152 resetOptOutButton();
153 }
154
155 function optIn() {
156 sendRequest();
157 }
158
159 function optOut() {
160 sendRequest();
161 }
162
163 function sendRequest() {
164 $.ajax({
165 url: ajaxurl,
166 method: 'POST',
167 data: {
168 action : ( 'stop_tracking' == action ?
169 '<?php echo $fs->get_ajax_action( 'stop_tracking' ) ?>' :
170 '<?php echo $fs->get_ajax_action( 'allow_tracking' ) ?>'
171 ),
172 security : ( 'stop_tracking' == action ?
173 '<?php echo $fs->get_ajax_security( 'stop_tracking' ) ?>' :
174 '<?php echo $fs->get_ajax_security( 'allow_tracking' ) ?>'
175 ),
176 module_id: moduleID
177 },
178 beforeSend: function() {
179 if ( 'opt-in' == action ) {
180 $actionLink.text( '<?php fs_esc_js_echo_inline( 'Opting in', 'opting-in', $slug ) ?>...' );
181 } else {
182 $optOutButton.text( '<?php fs_esc_js_echo_inline( 'Opting out', 'opting-out', $slug ) ?>...' );
183 }
184 },
185 success: function( resultObj ) {
186 if ( resultObj.success ) {
187 if ( 'allow_tracking' == action ) {
188 action = 'stop_tracking';
189 $actionLink.text( '<?php echo esc_js( $opt_out_text ) ?>' );
190 showOptInAppreciationMessageAndScrollToTop();
191 } else {
192 action = 'allow_tracking';
193 $actionLink.text( '<?php echo esc_js( $opt_in_text ) ?>' );
194 closeModal();
195
196 if ( $adminNotice.length > 0 ) {
197 $adminNotice.remove();
198 }
199 }
200
201 $actionLink.attr( 'data-action', action );
202 } else {
203 showError( resultObj.error );
204 resetOptOutButton();
205 }
206 }
207 });
208 }
209
210 function enableOptOutButton() {
211 $optOutButton.removeClass( 'disabled' );
212 }
213
214 function disableOptOutButton() {
215 $optOutButton.addClass( 'disabled' );
216 }
217
218 function hideError() {
219 $optOutErrorMessage.hide();
220 }
221
222 function showOptInAppreciationMessageAndScrollToTop() {
223 $adminNotice.insertAfter( $( '#wpbody-content' ).find( ' > .wrap > h1' ) );
224 window.scrollTo(0, 0);
225 }
226
227 function showError( msg ) {
228 $optOutErrorMessage.find( ' > p' ).html( msg );
229 $optOutErrorMessage.show();
230 }
231
232 <?php if ( $fs->is_theme() ) : ?>
233 /**
234 * Add opt-in/out button to the active theme's buttons collection
235 * in the theme's extended details overlay.
236 *
237 * @author Vova Feldman (@svovaf)
238 * @since 1.2.2.7
239 */
240 $('.theme-overlay').contentChange(function () {
241 if (!$(this).find('.theme-overlay').hasClass('active')) {
242 // Add opt-in/out button only to the currently active theme.
243 return;
244 }
245
246 if ($('#fs_theme_opt_in_out').length > 0){
247 // Button already there.
248 return;
249 }
250
251 var label = (('stop_tracking' == action) ?
252 '<?php echo esc_js( $opt_out_text ) ?>' :
253 '<?php echo esc_js( $opt_in_text ) ?>'),
254 href = (('stop_tracking' != action) ?
255 '<?php echo esc_js( $reconnect_url ) ?>' :
256 '');
257
258 $actionLink = $('<a id="fs_theme_opt_in_out" href="' + encodeURI(href) + '" class="button" data-action="' + action + '">' + label + '</a>');
259
260 $('.theme-wrap .theme-actions .active-theme').append($actionLink);
261
262 registerActionLinkClick();
263 });
264 <?php endif ?>
265 });
266 })( jQuery );
267 </script>
268