PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.9
Code Manager v1.0.9
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 / resend-key.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
resend-key.php
248 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.0
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
19 $slug = $fs->get_slug();
20
21 $send_button_text = fs_text_inline( 'Send License Key', 'send-license-key', $slug );
22 $cancel_button_text = fs_text_inline( 'Cancel', 'cancel', $slug );
23 $email_address_placeholder = fs_esc_attr_inline( 'Email address', 'email-address', $slug );
24 $other_text = fs_text_inline( 'Other', 'other', $slug );
25
26 $is_freemium = $fs->is_freemium();
27
28 $send_button_text_html = esc_html($send_button_text);
29
30 $button_html = <<< HTML
31 <div class="button-container">
32 <a href="#" class="button button-primary button-send-license-key" tabindex="2">{$send_button_text_html}</a>
33 </div>
34 HTML;
35
36 if ( $is_freemium ) {
37 $current_user = Freemius::_get_current_wp_user();
38 $email = $current_user->user_email;
39 $esc_email = esc_attr( $email );
40 $form_html = <<< HTML
41 <div class="email-address-container">
42 <label><input name="email-address" type="radio" checked="checked" tabindex="1" value="{$esc_email}"> {$email}</label>
43 <label><input name="email-address" type="radio" tabindex="1" value="other">{$other_text}: <input class="email-address" type="text" placeholder="{$email_address_placeholder}"></label>
44 </div>
45 {$button_html}
46 HTML;
47 } else {
48 $email = '';
49 $form_html = <<< HTML
50 {$button_html}
51 <div class="email-address-container">
52 <input class="email-address" type="text" placeholder="{$email_address_placeholder}" tabindex="1">
53 </div>
54 HTML;
55 }
56
57 $message_above_input_field = fs_esc_html_inline( "Enter the email address you've used for the upgrade below and we will resend you the license key.", 'ask-for-upgrade-email-address', $slug );
58 $modal_content_html = <<< HTML
59 <div class="notice notice-error inline license-resend-message"><p></p></div>
60 <p>{$message_above_input_field}</p>
61 <div class="input-container">
62 {$form_html}
63 </div>
64 HTML;
65
66 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
67 ?>
68 <script type="text/javascript">
69 (function ($) {
70 $(document).ready(function () {
71 var contentHtml = <?php echo json_encode( $modal_content_html ); ?>,
72 modalHtml =
73 '<div class="fs-modal fs-modal-license-key-resend <?php echo $is_freemium ? 'fs-freemium' : 'fs-premium' ?>">'
74 + ' <div class="fs-modal-dialog">'
75 + ' <div class="fs-modal-header">'
76 + ' <h4><?php echo esc_js( $send_button_text ) ?></h4>'
77 + ' <a href="#!" class="fs-close" tabindex="3" title="Close"><i class="dashicons dashicons-no" title="<?php echo esc_js( fs_text_x_inline( 'Dismiss', 'as close a window', 'dismiss', $slug ) ) ?>"></i></a>'
78 + ' </div>'
79 + ' <div class="fs-modal-body">'
80 + ' <div class="fs-modal-panel active">' + contentHtml + '</div>'
81 + ' </div>'
82 + ' </div>'
83 + '</div>',
84 $modal = $(modalHtml),
85 $sendButton = $modal.find('.button-send-license-key'),
86 $emailInput = $modal.find('input.email-address'),
87 $feedbackMessage = $modal.find('.license-resend-message'),
88 isFreemium = <?php echo json_encode( $is_freemium ) ?>,
89 userEmail = <?php echo json_encode( $email ) ?>,
90 moduleID = '<?php echo $fs->get_id() ?>',
91 isChild = false;
92
93
94 $modal.appendTo($('body'));
95
96 function registerEventHandlers() {
97 $('a.show-license-resend-modal-<?php echo $fs->get_unique_affix() ?>').click(function (evt) {
98 evt.preventDefault();
99
100 showModal();
101 });
102
103 if (isFreemium) {
104 $modal.on('change', 'input[type=radio][name=email-address]', function () {
105 updateButtonState();
106 });
107
108 $modal.on('focus', 'input.email-address', function () {
109 // Check custom email radio button on email input focus.
110 $($modal.find('input[type=radio]')[1]).prop('checked', true);
111
112 updateButtonState();
113 });
114 }
115
116 $modal.on('input propertychange', 'input.email-address', function () {
117 updateButtonState();
118 });
119
120 $modal.on('blur', 'input.email-address', function () {
121 updateButtonState();
122 });
123
124 $modal.on('click', '.fs-close', function (){
125 closeModal();
126 return false;
127 });
128
129 $modal.on('click', '.button', function (evt) {
130 evt.preventDefault();
131
132 if ($(this).hasClass('disabled')) {
133 return;
134 }
135
136 var email = getEmail();
137
138 disableButton();
139
140 if (!(-1 < email.indexOf('@'))) {
141 return;
142 }
143
144 $.ajax({
145 url : ajaxurl,
146 method : 'POST',
147 data : {
148 action : '<?php echo $fs->get_ajax_action( 'resend_license_key' ) ?>',
149 security : '<?php echo $fs->get_ajax_security( 'resend_license_key' ) ?>',
150 module_id : moduleID,
151 email : email
152 },
153 beforeSend: function () {
154 $sendButton.text('<?php fs_esc_js_echo_inline( 'Sending license key', 'sending-license-key', $slug ) ?>...');
155 },
156 success : function (result) {
157 var resultObj = $.parseJSON(result);
158 if (resultObj.success) {
159 closeModal();
160 } else {
161 showError(resultObj.error);
162 resetButton();
163 }
164 }
165 });
166 });
167 }
168
169 registerEventHandlers();
170
171 resetButton();
172
173 function showModal() {
174 resetModal();
175
176 // Display the dialog box.
177 $modal.addClass('active');
178
179 if (!isFreemium)
180 $emailInput.focus();
181
182 var $body = $('body');
183
184 isChild = $body.hasClass('has-fs-modal');
185 if (isChild) {
186 return;
187 }
188
189 $body.addClass('has-fs-modal');
190 }
191
192 function closeModal() {
193 $modal.removeClass('active');
194
195 // If child modal, do not remove the "has-fs-modal" class of the <body> element to keep its scrollbars hidden.
196 if (isChild) {
197 return;
198 }
199
200 $('body').removeClass('has-fs-modal');
201 }
202
203 function resetButton() {
204 updateButtonState();
205 $sendButton.text(<?php echo json_encode($send_button_text) ?>);
206 }
207
208 function resetModal() {
209 hideError();
210 resetButton();
211 $emailInput.val('');
212 }
213
214 function getEmail() {
215 var email = $emailInput.val().trim();
216
217 if (isFreemium) {
218 if ('other' != $modal.find('input[type=radio][name=email-address]:checked').val()) {
219 email = userEmail;
220 }
221 }
222
223 return email;
224 }
225
226 function updateButtonState() {
227 /**
228 * If email address is not empty, enable the send license key button.
229 */
230 $sendButton.toggleClass('disabled', !( -1 < getEmail().indexOf('@') ));
231 }
232
233 function disableButton() {
234 $sendButton.addClass('disabled');
235 }
236
237 function hideError() {
238 $feedbackMessage.hide();
239 }
240
241 function showError(msg) {
242 $feedbackMessage.find(' > p').html(msg);
243 $feedbackMessage.show();
244 }
245 });
246 })(jQuery);
247 </script>
248