PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.2
Tiered Pricing Table for WooCommerce v2.2.2
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 / connect.php

connect.php in Tiered Pricing Table for WooCommerce 2.2.2, at freemius/templates/connect.php

932 lines 37.3 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.0.7
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 $is_pending_activation = $fs->is_pending_activation();
21 $is_premium_only = $fs->is_only_premium();
22 $has_paid_plans = $fs->has_paid_plan();
23 $is_premium_code = $fs->is_premium();
24 $is_freemium = $fs->is_freemium();
25
26 $fs->_enqueue_connect_essentials();
27
28 $current_user = Freemius::_get_current_wp_user();
29
30 $first_name = $current_user->user_firstname;
31 if ( empty( $first_name ) ) {
32 $first_name = $current_user->nickname;
33 }
34
35 $site_url = get_site_url();
36 $protocol_pos = strpos( $site_url, '://' );
37 if ( false !== $protocol_pos ) {
38 $site_url = substr( $site_url, $protocol_pos + 3 );
39 }
40
41 $freemius_site_www = 'https://freemius.com';
42
43 $freemius_usage_tracking_url = $freemius_site_www . '/wordpress/usage-tracking/' . $fs->get_id() . "/{$slug}/";
44 $freemius_plugin_terms_url = $freemius_site_www . '/terms/' . $fs->get_id() . "/{$slug}/";
45
46 $freemius_site_url = $fs->is_premium() ?
47 $freemius_site_www :
48 $freemius_usage_tracking_url;
49
50 if ( $fs->is_premium() ) {
51 $freemius_site_url .= '?' . http_build_query( array(
52 'id' => $fs->get_id(),
53 'slug' => $slug,
54 ) );
55 }
56
57 $freemius_link = '<a href="' . $freemius_site_url . '" target="_blank" tabindex="1">freemius.com</a>';
58
59 $error = fs_request_get( 'error' );
60
61 $require_license_key = $is_premium_only ||
62 ( $is_freemium && $is_premium_code && fs_request_get_bool( 'require_license', true ) );
63
64 if ( $is_pending_activation ) {
65 $require_license_key = false;
66 }
67
68 if ( $require_license_key ) {
69 $fs->_add_license_activation_dialog_box();
70 }
71
72 $is_optin_dialog = (
73 $fs->is_theme() &&
74 $fs->is_themes_page() &&
75 ( ! $fs->has_settings_menu() || $fs->is_free_wp_org_theme() )
76 );
77
78 if ( $is_optin_dialog ) {
79 $show_close_button = false;
80 $previous_theme_activation_url = '';
81
82 if ( ! $is_premium_code ) {
83 $show_close_button = true;
84 } else if ( $is_premium_only ) {
85 $previous_theme_activation_url = $fs->get_previous_theme_activation_url();
86 $show_close_button = ( ! empty( $previous_theme_activation_url ) );
87 }
88 }
89
90 $is_network_level_activation = (
91 fs_is_network_admin() &&
92 $fs->is_network_active() &&
93 ! $fs->is_network_delegated_connection()
94 );
95
96 $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
97
98 $activate_with_current_user = (
99 is_object( $fs_user ) &&
100 ! $is_pending_activation &&
101 // If requires a license for activation, use the user associated with the license for the opt-in.
102 ! $require_license_key &&
103 ! $is_network_level_activation
104 );
105
106 $optin_params = $fs->get_opt_in_params( array(), $is_network_level_activation );
107 $sites = isset( $optin_params['sites'] ) ? $optin_params['sites'] : array();
108
109 $is_network_upgrade_mode = ( fs_is_network_admin() && $fs->is_network_upgrade_mode() );
110
111 /* translators: %s: name (e.g. Hey John,) */
112 $hey_x_text = esc_html( sprintf( fs_text_x_inline( 'Hey %s,', 'greeting', 'hey-x', $slug ), $first_name ) );
113
114 $is_gdpr_required = ( ! $is_pending_activation && ! $require_license_key ) ?
115 FS_GDPR_Manager::instance()->is_required() :
116 false;
117
118 if ( is_null( $is_gdpr_required ) ) {
119 $is_gdpr_required = $fs->fetch_and_store_current_user_gdpr_anonymously();
120 }
121 ?>
122 <?php
123 if ( $is_optin_dialog ) { ?>
124 <div id="fs_theme_connect_wrapper">
125 <?php
126 if ( $show_close_button ) { ?>
127 <button class="close dashicons dashicons-no"><span class="screen-reader-text">Close connect dialog</span>
128 </button>
129 <?php
130 }
131 ?>
132 <?php
133 }
134 ?>
135 <div id="fs_connect"
136 class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) ) {
137 echo ' fs-anonymous-disabled';
138 } ?><?php echo $require_license_key ? ' require-license-key' : '' ?>">
139 <div class="fs-visual">
140 <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b>
141 <i class="dashicons dashicons-plus fs-first"></i>
142 <?php
143 $vars = array( 'id' => $fs->get_id() );
144 fs_require_once_template( 'plugin-icon.php', $vars );
145 ?>
146 <i class="dashicons dashicons-plus fs-second"></i>
147 <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/>
148 </div>
149 <div class="fs-content">
150 <?php if ( ! empty( $error ) ) : ?>
151 <p class="fs-error"><?php echo esc_html( $error ) ?></p>
152 <?php endif ?>
153 <p><?php
154 $button_label = fs_text_inline( 'Allow & Continue', 'opt-in-connect', $slug );
155 $message = '';
156
157 if ( $is_pending_activation ) {
158 $button_label = fs_text_inline( 'Re-send activation email', 'resend-activation-email', $slug );
159
160 $message = $fs->apply_filters( 'pending_activation_message', sprintf(
161 /* translators: %s: name (e.g. Thanks John!) */
162 fs_text_inline( 'Thanks %s!', 'thanks-x', $slug ) . '<br>' .
163 fs_text_inline( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to %s.', 'pending-activation-message', $slug ),
164 $first_name,
165 '<b>' . $fs->get_plugin_name() . '</b>',
166 '<b>' . $current_user->user_email . '</b>',
167 fs_text_inline( 'complete the install', 'complete-the-install', $slug )
168 ) );
169 } else if ( $require_license_key ) {
170 $button_label = $is_network_upgrade_mode ?
171 fs_text_inline( 'Activate License', 'agree-activate-license', $slug ) :
172 fs_text_inline( 'Agree & Activate License', 'agree-activate-license', $slug );
173
174 $message = $fs->apply_filters(
175 'connect-message_on-premium',
176 ($is_network_upgrade_mode ?
177 '' :
178 /* translators: %s: name (e.g. Hey John,) */
179 $hey_x_text . '<br>'
180 ) .
181 sprintf( fs_text_inline( 'Thanks for purchasing %s! To get started, please enter your license key:', 'thanks-for-purchasing', $slug ), '<b>' . $fs->get_plugin_name() . '</b>' ),
182 $first_name,
183 $fs->get_plugin_name()
184 );
185 } else {
186 $filter = 'connect_message';
187 $default_optin_message = $is_gdpr_required ?
188 fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with %4$s.', 'connect-message', $slug) :
189 fs_text_inline( 'Never miss an important update - opt in to our security and feature updates notifications, and non-sensitive diagnostic tracking with %4$s.', 'connect-message', $slug);
190
191 if ( $fs->is_plugin_update() ) {
192 // If Freemius was added on a plugin update, set different
193 // opt-in message.
194 $default_optin_message = $is_gdpr_required ?
195 fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug ) :
196 fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug );
197
198 // If user customized the opt-in message on update, use
199 // that message. Otherwise, fallback to regular opt-in
200 // custom message if exist.
201 if ( $fs->has_filter( 'connect_message_on_update' ) ) {
202 $filter = 'connect_message_on_update';
203 }
204 }
205
206 $message = $fs->apply_filters(
207 $filter,
208 ($is_network_upgrade_mode ?
209 '' :
210 /* translators: %s: name (e.g. Hey John,) */
211 $hey_x_text . '<br>'
212 ) .
213 sprintf(
214 esc_html( $default_optin_message ),
215 '<b>' . esc_html( $fs->get_plugin_name() ) . '</b>',
216 '<b>' . $current_user->user_login . '</b>',
217 '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
218 $freemius_link
219 ),
220 $first_name,
221 $fs->get_plugin_name(),
222 $current_user->user_login,
223 '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
224 $freemius_link,
225 $is_gdpr_required
226 );
227 }
228
229 if ( $is_network_upgrade_mode ) {
230 $network_integration_text = esc_html( fs_text_inline( 'We\'re excited to introduce the Freemius network-level integration.', 'connect_message_network_upgrade', $slug ) );
231
232 if ($is_premium_code){
233 $message = $network_integration_text . ' ' . sprintf( fs_text_inline( 'During the update process we detected %d site(s) that are still pending license activation.', 'connect_message_network_upgrade-premium', $slug ), count( $sites ) );
234
235 $message .= '<br><br>' . sprintf( fs_text_inline( 'If you\'d like to use the %s on those sites, please enter your license key below and click the activation button.', 'connect_message_network_upgrade-premium-activate-license', $slug ), $is_premium_only ? $fs->get_module_label( true ) : sprintf(
236 /* translators: %s: module type (plugin, theme, or add-on) */
237 fs_text_inline( "%s's paid features", 'x-paid-features', $slug ),
238 $fs->get_module_label( true )
239 ) );
240
241 /* translators: %s: module type (plugin, theme, or add-on) */
242 $message .= ' ' . sprintf( fs_text_inline( 'Alternatively, you can skip it for now and activate the license later, in your %s\'s network-level Account page.', 'connect_message_network_upgrade-premium-skip-license', $slug ), $fs->get_module_label( true ) );
243 }else {
244 $message = $network_integration_text . ' ' . sprintf( fs_text_inline( 'During the update process we detected %s site(s) in the network that are still pending your attention.', 'connect_message_network_upgrade-free', $slug ), count( $sites ) ) . '<br><br>' . ( fs_starts_with( $message, $hey_x_text . '<br>' ) ? substr( $message, strlen( $hey_x_text . '<br>' ) ) : $message );
245 }
246 }
247
248 echo $message;
249 ?></p>
250 <?php if ( $require_license_key ) : ?>
251 <div class="fs-license-key-container">
252 <input id="fs_license_key" name="fs_key" type="text" required maxlength="<?php echo $fs->apply_filters('license_key_maxlength', 32) ?>"
253 placeholder="<?php fs_esc_attr_echo_inline( 'License key', 'license-key', $slug ) ?>" tabindex="1"/>
254 <i class="dashicons dashicons-admin-network"></i>
255 <a class="show-license-resend-modal show-license-resend-modal-<?php echo $fs->get_unique_affix() ?>"
256 href="#"><?php fs_esc_html_echo_inline( "Can't find your license key?", 'cant-find-license-key', $slug ); ?></a>
257 </div>
258
259 <?php
260 /**
261 * Allows developers to include custom HTML after the license input container.
262 *
263 * @author Vova Feldman
264 * @since 2.1.2
265 */
266 $fs->do_action( 'connect/after_license_input' );
267 ?>
268
269 <?php
270 $send_updates_text = sprintf(
271 '%s<span class="action-description"> - %s</span>',
272 $fs->get_text_inline( 'Yes', 'yes' ),
273 $fs->get_text_inline( 'send me security & feature updates, educational content and offers.', 'send-updates' )
274 );
275
276 $do_not_send_updates_text = sprintf(
277 '%s<span class="action-description"> - %s</span>',
278 $fs->get_text_inline( 'No', 'no' ),
279 sprintf(
280 $fs->get_text_inline( 'do %sNOT%s send me security & feature updates, educational content and offers.', 'do-not-send-updates' ),
281 '<span class="underlined">',
282 '</span>'
283 )
284 );
285 ?>
286 <div id="fs_marketing_optin">
287 <span class="fs-message"><?php fs_echo_inline( "Please let us know if you'd like us to contact you for security & feature updates, educational content, and occasional offers:", 'contact-for-updates' ) ?></span>
288 <div class="fs-input-container">
289 <label>
290 <input type="radio" name="allow-marketing" value="true" tabindex="1" />
291 <span class="fs-input-label"><?php echo $send_updates_text ?></span>
292 </label>
293 <label>
294 <input type="radio" name="allow-marketing" value="false" tabindex="1" />
295 <span class="fs-input-label"><?php echo $do_not_send_updates_text ?></span>
296 </label>
297 </div>
298 </div>
299 <?php endif ?>
300 <?php if ( $is_network_level_activation ) : ?>
301 <?php
302 $vars = array(
303 'id' => $fs->get_id(),
304 'sites' => $sites,
305 'require_license_key' => $require_license_key
306 );
307
308 echo fs_get_template( 'partials/network-activation.php', $vars );
309 ?>
310 <?php endif ?>
311 </div>
312 <div class="fs-actions">
313 <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ( ! $require_license_key || $is_network_upgrade_mode ) ) : ?>
314 <a id="skip_activation" href="<?php echo fs_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $fs->get_unique_affix() . '_skip_activation' ), $is_network_level_activation ), $fs->get_unique_affix() . '_skip_activation' ) ?>"
315 class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?></a>
316 <?php endif ?>
317 <?php if ( $is_network_level_activation ) : ?>
318 <a id="delegate_to_site_admins" class="fs-tooltip-trigger <?php echo is_rtl() ? ' rtl' : '' ?>" href="<?php echo fs_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $fs->get_unique_affix() . '_delegate_activation' ) ), $fs->get_unique_affix() . '_delegate_activation' ) ?>"><?php fs_esc_html_echo_inline( 'Delegate to Site Admins', 'delegate-to-site-admins', $slug ) ?><span class="fs-tooltip"><?php fs_esc_html_echo_inline( 'If you click it, this decision will be delegated to the sites administrators.', 'delegate-sites-tooltip', $slug ) ?></span></a>
319 <?php endif ?>
320 <?php if ( $activate_with_current_user ) : ?>
321 <form action="" method="POST">
322 <input type="hidden" name="fs_action"
323 value="<?php echo $fs->get_unique_affix() ?>_activate_existing">
324 <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?>
325 <button class="button button-primary" tabindex="1"
326 type="submit"><?php echo esc_html( $button_label ) ?></button>
327 </form>
328 <?php else : ?>
329 <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
330 <?php unset( $optin_params['sites']); ?>
331 <?php foreach ( $optin_params as $name => $value ) : ?>
332 <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
333 <?php endforeach ?>
334 <button class="button button-primary" tabindex="1"
335 type="submit"<?php if ( $require_license_key ) {
336 echo ' disabled="disabled"';
337 } ?>><?php echo esc_html( $button_label ) ?></button>
338 </form>
339 <?php endif ?>
340 </div><?php
341
342 // Set core permission list items.
343 $permissions = array(
344 'profile' => array(
345 'icon-class' => 'dashicons dashicons-admin-users',
346 'label' => $fs->get_text_inline( 'Your Profile Overview', 'permissions-profile' ),
347 'desc' => $fs->get_text_inline( 'Name and email address', 'permissions-profile_desc' ),
348 'priority' => 5,
349 ),
350 'site' => array(
351 'icon-class' => 'dashicons dashicons-admin-settings',
352 'label' => $fs->get_text_inline( 'Your Site Overview', 'permissions-site' ),
353 'desc' => $fs->get_text_inline( 'Site URL, WP version, PHP info, plugins & themes', 'permissions-site_desc' ),
354 'priority' => 10,
355 ),
356 'notices' => array(
357 'icon-class' => 'dashicons dashicons-testimonial',
358 'label' => $fs->get_text_inline( 'Admin Notices', 'permissions-admin-notices' ),
359 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ),
360 'priority' => 13,
361 ),
362 'events' => array(
363 'icon-class' => 'dashicons dashicons-admin-plugins',
364 'label' => sprintf( $fs->get_text_inline( 'Current %s Events', 'permissions-events' ), ucfirst( $fs->get_module_type() ) ),
365 'desc' => $fs->get_text_inline( 'Activation, deactivation and uninstall', 'permissions-events_desc' ),
366 'priority' => 20,
367 ),
368 );
369
370 // Add newsletter permissions if enabled.
371 if ( $is_gdpr_required || $fs->is_permission_requested( 'newsletter' ) ) {
372 $permissions['newsletter'] = array(
373 'icon-class' => 'dashicons dashicons-email-alt',
374 'label' => $fs->get_text_inline( 'Newsletter', 'permissions-newsletter' ),
375 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ),
376 'priority' => 15,
377 );
378 }
379
380 // Allow filtering of the permissions list.
381 $permissions = $fs->apply_filters( 'permission_list', $permissions );
382
383 // Sort by priority.
384 uasort( $permissions, 'fs_sort_by_priority' );
385
386 if ( ! empty( $permissions ) ) : ?>
387 <div class="fs-permissions">
388 <?php if ( $require_license_key ) : ?>
389 <p class="fs-license-sync-disclaimer"><?php
390 echo sprintf(
391 fs_esc_html_inline( 'The %1$s will be periodically sending data to %2$s to check for security and feature updates, and verify the validity of your license.', 'license-sync-disclaimer', $slug ),
392 $fs->get_module_label( true ),
393 $freemius_link
394 ) ?></p>
395 <?php endif ?>
396 <a class="fs-trigger" href="#" tabindex="1"><?php fs_esc_html_echo_inline( 'What permissions are being granted?', 'what-permissions', $slug ) ?></a>
397 <ul><?php
398 foreach ( $permissions as $id => $permission ) : ?>
399 <li id="fs-permission-<?php echo esc_attr( $id ); ?>"
400 class="fs-permission fs-<?php echo esc_attr( $id ); ?>">
401 <i class="<?php echo esc_attr( $permission['icon-class'] ); ?>"></i>
402
403 <div>
404 <span><?php echo esc_html( $permission['label'] ); ?></span>
405
406 <p><?php echo esc_html( $permission['desc'] ); ?></p>
407 </div>
408 </li>
409 <?php endforeach; ?>
410 </ul>
411 </div>
412 <?php endif ?>
413 <?php if ( $is_premium_code && $is_freemium ) : ?>
414 <div class="fs-freemium-licensing">
415 <p>
416 <?php if ( $require_license_key ) : ?>
417 <?php fs_esc_html_echo_inline( 'Don\'t have a license key?', 'dont-have-license-key', $slug ) ?>
418 <a data-require-license="false" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate Free Version', 'activate-free-version', $slug ) ?></a>
419 <?php else : ?>
420 <?php fs_echo_inline( 'Have a license key?', 'have-license-key', $slug ) ?>
421 <a data-require-license="true" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate License', 'activate-license', $slug ) ?></a>
422 <?php endif ?>
423 </p>
424 </div>
425 <?php endif ?>
426 <div class="fs-terms">
427 <a href="https://freemius.com/privacy/" target="_blank"
428 tabindex="1"><?php fs_esc_html_echo_inline( 'Privacy Policy', 'privacy-policy', $slug ) ?></a>
429 &nbsp;&nbsp;-&nbsp;&nbsp;
430 <a href="<?php echo $require_license_key ? $freemius_plugin_terms_url : $freemius_usage_tracking_url ?>" target="_blank" tabindex="1"><?php $require_license_key ? fs_echo_inline( 'License Agreement', 'license-agreement', $slug ) : fs_echo_inline( 'Terms of Service', 'tos', $slug ) ?></a>
431 </div>
432 </div>
433 <?php
434 if ( $is_optin_dialog ) { ?>
435 </div>
436 <?php
437 }
438 ?>
439 <script type="text/javascript">
440 (function ($) {
441 var $html = $('html');
442
443 <?php
444 if ( $is_optin_dialog ) {
445 if ( $show_close_button ) { ?>
446 var $themeConnectWrapper = $('#fs_theme_connect_wrapper');
447
448 $themeConnectWrapper.find('button.close').on('click', function () {
449 <?php if ( ! empty( $previous_theme_activation_url ) ) { ?>
450 location.href = '<?php echo html_entity_decode( $previous_theme_activation_url ); ?>';
451 <?php } else { ?>
452 $themeConnectWrapper.remove();
453 $html.css({overflow: $html.attr('fs-optin-overflow')});
454 <?php } ?>
455 });
456 <?php
457 }
458 ?>
459
460 $html.attr('fs-optin-overflow', $html.css('overflow'));
461 $html.css({overflow: 'hidden'});
462
463 <?php
464 }
465 ?>
466
467 var $primaryCta = $('.fs-actions .button.button-primary'),
468 primaryCtaLabel = $primaryCta.html(),
469 $form = $('.fs-actions form'),
470 isNetworkActive = <?php echo $is_network_level_activation ? 'true' : 'false' ?>,
471 requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
472 hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>,
473 isNetworkUpgradeMode = <?php echo $is_network_upgrade_mode ? 'true' : 'false' ?>,
474 $licenseSecret,
475 $licenseKeyInput = $('#fs_license_key'),
476 pauseCtaLabelUpdate = false,
477 /**
478 * @author Leo Fajardo (@leorw)
479 * @since 2.1.0
480 */
481 resetLoadingMode = function() {
482 // Reset loading mode.
483 $primaryCta.html(primaryCtaLabel);
484 $primaryCta.prop('disabled', false);
485 $(document.body).css({'cursor': 'auto'});
486 $('.fs-loading').removeClass('fs-loading');
487
488 console.log('resetLoadingMode - Primary button was enabled');
489 },
490 setLoadingMode = function () {
491 $(document.body).css({'cursor': 'wait'});
492 };
493
494 $('.fs-actions .button').on('click', function () {
495 setLoadingMode();
496
497 var $this = $(this);
498
499 setTimeout(function () {
500 if ( ! requireLicenseKey || ! $marketingOptin.hasClass( 'error' ) ) {
501 $this.attr('disabled', 'disabled');
502 }
503 }, 200);
504 });
505
506 if ( isNetworkActive ) {
507 var
508 $multisiteOptionsContainer = $( '#multisite_options_container' ),
509 $allSitesOptions = $( '#all_sites_options' ),
510 $applyOnAllSites = $( '#apply_on_all_sites' ),
511 $sitesListContainer = $( '#sites_list_container' ),
512 totalSites = <?php echo count( $sites ) ?>,
513 maxSitesListHeight = null,
514 $skipActivationButton = $( '#skip_activation' ),
515 $delegateToSiteAdminsButton = $( '#delegate_to_site_admins' );
516
517 $applyOnAllSites.click(function() {
518 var isChecked = $( this ).is( ':checked' );
519
520 if ( isChecked ) {
521 $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
522 updatePrimaryCtaText( 'allow' );
523 }
524
525 $multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' );
526
527 $skipActivationButton.toggle();
528
529 $delegateToSiteAdminsButton.toggle();
530
531 $multisiteOptionsContainer.toggleClass( 'apply-on-all-sites', isChecked );
532
533 $sitesListContainer.toggle( ! isChecked );
534 if ( ! isChecked && null === maxSitesListHeight ) {
535 /**
536 * Set the visible number of rows to 5 (5 * height of the first row).
537 *
538 * @author Leo Fajardo (@leorw)
539 */
540 maxSitesListHeight = ( 5 * $sitesListContainer.find( 'tr:first' ).height() );
541 $sitesListContainer.css( 'max-height', maxSitesListHeight );
542 }
543 });
544
545 $allSitesOptions.find( '.action' ).click(function( evt ) {
546 var actionType = $( evt.target ).data( 'action-type' );
547
548 $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
549 $multisiteOptionsContainer.find( '.action-' + actionType ).toggleClass( 'selected' );
550
551 updatePrimaryCtaText( actionType );
552 });
553
554 $sitesListContainer.delegate( '.action', 'click', function( evt ) {
555 var $this = $( evt.target );
556 if ( $this.hasClass( 'selected' ) ) {
557 return false;
558 }
559
560 $this.parents( 'tr:first' ).find( '.action' ).removeClass( 'selected' );
561 $this.toggleClass( 'selected' );
562
563 var
564 singleSiteActionType = $this.data( 'action-type' ),
565 totalSelected = $sitesListContainer.find( '.action-' + singleSiteActionType + '.selected' ).length;
566
567 $allSitesOptions.find( '.action.selected' ).removeClass( 'selected' );
568
569 if ( totalSelected === totalSites ) {
570 $allSitesOptions.find( '.action-' + singleSiteActionType ).addClass( 'selected' );
571
572 updatePrimaryCtaText( singleSiteActionType );
573 } else {
574 updatePrimaryCtaText( 'mixed' );
575 }
576 });
577
578 if (isNetworkUpgradeMode) {
579 $skipActivationButton.click(function(){
580 $delegateToSiteAdminsButton.hide();
581
582 $skipActivationButton.html('<?php fs_esc_js_echo_inline( 'Skipping, please wait', 'skipping-wait', $slug ) ?>...');
583
584 pauseCtaLabelUpdate = true;
585
586 // Check all sites to be skipped.
587 $allSitesOptions.find('.action.action-skip').click();
588
589 $form.submit();
590
591 pauseCtaLabelUpdate = false;
592
593 return false;
594 });
595
596 $delegateToSiteAdminsButton.click(function(){
597 $delegateToSiteAdminsButton.html('<?php fs_esc_js_echo_inline( 'Delegating, please wait', 'delegating-wait', $slug ) ?>...');
598
599 pauseCtaLabelUpdate = true;
600
601 // Check all sites to be skipped.
602 $allSitesOptions.find('.action.action-delegate').click();
603
604 $form.submit();
605
606 pauseCtaLabelUpdate = false;
607
608 return false;
609 });
610 }
611 }
612
613 /**
614 * @author Leo Fajardo (@leorw)
615 */
616 function updatePrimaryCtaText( actionType ) {
617 if (pauseCtaLabelUpdate)
618 return;
619
620 var text = '<?php fs_esc_js_echo_inline( 'Continue', 'continue', $slug ) ?>';
621
622 switch ( actionType ) {
623 case 'allow':
624 text = '<?php fs_esc_js_echo_inline( 'Allow & Continue', 'opt-in-connect', $slug ) ?>';
625 break;
626 case 'delegate':
627 text = '<?php fs_esc_js_echo_inline( 'Delegate to Site Admins & Continue', 'delegate-to-site-admins-and-continue', $slug ) ?>';
628 break;
629 case 'skip':
630 text = '<?php fs_esc_js_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?>';
631 break;
632 }
633
634 $primaryCta.html( text );
635 }
636
637 var ajaxOptin = ( requireLicenseKey || isNetworkActive );
638
639 $form.on('submit', function () {
640 /**
641 * @author Vova Feldman (@svovaf)
642 * @since 1.1.9
643 */
644 if ( ajaxOptin ) {
645 if (!hasContextUser || isNetworkUpgradeMode) {
646 <?php $action = $require_license_key ? 'activate_license' : 'network_activate' ?>
647
648 $('.fs-error').remove();
649
650 var
651 licenseKey = $licenseKeyInput.val(),
652 data = {
653 action : '<?php echo $fs->get_ajax_action( $action ) ?>',
654 security : '<?php echo $fs->get_ajax_security( $action ) ?>',
655 license_key: licenseKey,
656 module_id : '<?php echo $fs->get_id() ?>'
657 };
658
659 if (requireLicenseKey &&
660 isMarketingAllowedByLicense.hasOwnProperty(licenseKey)
661 ) {
662 var
663 isMarketingAllowed = null,
664 $isMarketingAllowed = $marketingOptin.find( 'input[type="radio"][name="allow-marketing"]:checked');
665
666
667 if ($isMarketingAllowed.length > 0)
668 isMarketingAllowed = ('true' == $isMarketingAllowed.val());
669
670 if ( null == isMarketingAllowedByLicense[ licenseKey ] &&
671 null == isMarketingAllowed
672 ) {
673 $marketingOptin.addClass( 'error' ).show();
674 resetLoadingMode();
675 return false;
676 } else if ( null == isMarketingAllowed ) {
677 isMarketingAllowed = isMarketingAllowedByLicense[ licenseKey ];
678 }
679
680 data.is_marketing_allowed = isMarketingAllowed;
681 }
682
683 $marketingOptin.removeClass( 'error' );
684
685 if ( isNetworkActive ) {
686 var
687 sites = [],
688 applyOnAllSites = $applyOnAllSites.is( ':checked' );
689
690 $sitesListContainer.find( 'tr' ).each(function() {
691 var
692 $this = $( this ),
693 includeSite = ( ! requireLicenseKey || applyOnAllSites || $this.find( 'input' ).is( ':checked' ) );
694
695 if ( ! includeSite )
696 return;
697
698 var site = {
699 uid : $this.find( '.uid' ).val(),
700 url : $this.find( '.url' ).val(),
701 title : $this.find( '.title' ).val(),
702 language: $this.find( '.language' ).val(),
703 charset : $this.find( '.charset' ).val(),
704 blog_id : $this.find( '.blog-id' ).find( 'span' ).text()
705 };
706
707 if ( ! requireLicenseKey) {
708 site.action = $this.find('.action.selected').data('action-type');
709 }
710
711 sites.push( site );
712 });
713
714 data.sites = sites;
715 }
716
717 /**
718 * Use the AJAX opt-in when license key is required to potentially
719 * process the after install failure hook.
720 *
721 * @author Vova Feldman (@svovaf)
722 * @since 1.2.1.5
723 */
724 $.ajax({
725 url : ajaxurl,
726 method : 'POST',
727 data : data,
728 success: function (result) {
729 var resultObj = $.parseJSON(result);
730 if (resultObj.success) {
731 // Redirect to the "Account" page and sync the license.
732 window.location.href = resultObj.next_page;
733 } else {
734 resetLoadingMode();
735
736 // Show error.
737 $('.fs-content').prepend('<p class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</p>');
738 }
739 },
740 error: function () {
741 resetLoadingMode();
742 }
743 });
744
745 return false;
746 }
747 else {
748 if (null == $licenseSecret) {
749 $licenseSecret = $('<input type="hidden" name="license_secret_key" value="" />');
750 $form.append($licenseSecret);
751 }
752
753 // Update secret key if premium only plugin.
754 $licenseSecret.val($licenseKeyInput.val());
755 }
756 }
757
758 return true;
759 });
760
761 $primaryCta.on('click', function () {
762 console.log('Primary button was clicked');
763
764 $(this).addClass('fs-loading');
765 $(this).html('<?php echo esc_js( $is_pending_activation ?
766 fs_text_x_inline( 'Sending email', 'as in the process of sending an email', 'sending-email', $slug ) :
767 fs_text_x_inline( 'Activating', 'as activating plugin', 'activating', $slug )
768 ) ?>...');
769 });
770
771 $('.fs-permissions .fs-trigger').on('click', function () {
772 $('.fs-permissions').toggleClass('fs-open');
773
774 return false;
775 });
776
777 if (requireLicenseKey) {
778 /**
779 * Submit license key on enter.
780 *
781 * @author Vova Feldman (@svovaf)
782 * @since 1.1.9
783 */
784 $licenseKeyInput.keypress(function (e) {
785 if (e.which == 13) {
786 if ('' !== $(this).val()) {
787 $primaryCta.click();
788 return false;
789 }
790 }
791 });
792
793 /**
794 * Disable activation button when empty license key.
795 *
796 * @author Vova Feldman (@svovaf)
797 * @since 1.1.9
798 */
799 $licenseKeyInput.on('keyup paste delete cut', function () {
800 setTimeout(function () {
801 var key = $licenseKeyInput.val();
802
803 if (key == previousLicenseKey){
804 return;
805 }
806
807 if ('' === key) {
808 $primaryCta.attr('disabled', 'disabled');
809 $marketingOptin.hide();
810 } else {
811 $primaryCta.prop('disabled', false);
812
813 if (32 <= key.length){
814 fetchIsMarketingAllowedFlagAndToggleOptin();
815 } else {
816 $marketingOptin.hide();
817 }
818 }
819
820 previousLicenseKey = key;
821 }, 100);
822 }).focus();
823 }
824
825 /**
826 * Set license mode trigger URL.
827 *
828 * @author Vova Feldman (@svovaf)
829 * @since 1.1.9
830 */
831 var
832 $connectLicenseModeTrigger = $('#fs_connect .fs-freemium-licensing a'),
833 href = window.location.href;
834
835 if (href.indexOf('?') > 0) {
836 href += '&';
837 } else {
838 href += '?';
839 }
840
841 if ($connectLicenseModeTrigger.length > 0) {
842 $connectLicenseModeTrigger.attr(
843 'href',
844 href + 'require_license=' + $connectLicenseModeTrigger.attr('data-require-license')
845 );
846 }
847
848 //--------------------------------------------------------------------------------
849 //region GDPR
850 //--------------------------------------------------------------------------------
851 var isMarketingAllowedByLicense = {},
852 $marketingOptin = $('#fs_marketing_optin'),
853 previousLicenseKey = null;
854
855 if (requireLicenseKey) {
856
857 var
858 afterMarketingFlagLoaded = function () {
859 var licenseKey = $licenseKeyInput.val();
860
861 if (null == isMarketingAllowedByLicense[licenseKey]) {
862 $marketingOptin.show();
863
864 if ($marketingOptin.find('input[type=radio]:checked').length > 0){
865 // Focus on button if GDPR opt-in already selected is already selected.
866 $primaryCta.focus();
867 } else {
868 // Focus on the GDPR opt-in radio button.
869 $($marketingOptin.find('input[type=radio]')[0]).focus();
870 }
871 } else {
872 $marketingOptin.hide();
873 $primaryCta.focus();
874 }
875 },
876 /**
877 * @author Leo Fajardo (@leorw)
878 * @since 2.1.0
879 */
880 fetchIsMarketingAllowedFlagAndToggleOptin = function () {
881 var licenseKey = $licenseKeyInput.val();
882
883 if (licenseKey.length < 32) {
884 $marketingOptin.hide();
885 return;
886 }
887
888 if (isMarketingAllowedByLicense.hasOwnProperty(licenseKey)) {
889 afterMarketingFlagLoaded();
890 return;
891 }
892
893 $marketingOptin.hide();
894
895 setLoadingMode();
896
897 $primaryCta.addClass('fs-loading');
898 $primaryCta.attr('disabled', 'disabled');
899 $primaryCta.html('<?php fs_esc_js_echo_inline( 'Please wait', 'please-wait', $slug ) ?>...');
900
901 $.ajax({
902 url : ajaxurl,
903 method : 'POST',
904 data : {
905 action : '<?php echo $fs->get_ajax_action( 'fetch_is_marketing_required_flag_value' ) ?>',
906 security : '<?php echo $fs->get_ajax_security( 'fetch_is_marketing_required_flag_value' ) ?>',
907 license_key: licenseKey,
908 module_id : '<?php echo $fs->get_id() ?>'
909 },
910 success: function (result) {
911 resetLoadingMode();
912
913 if (result.success) {
914 result = result.data;
915
916 // Cache result.
917 isMarketingAllowedByLicense[licenseKey] = result.is_marketing_allowed;
918 }
919
920 afterMarketingFlagLoaded();
921 }
922 });
923 };
924
925 $marketingOptin.find( 'input' ).click(function() {
926 $marketingOptin.removeClass( 'error' );
927 });
928 }
929
930 //endregion
931 })(jQuery);
932 </script>