PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 3.6.0
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v3.6.0
3.6.0 3.5.0 trunk 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 All 110 releases
← All changes | freemius/templates/connect.php +852 -235 1.43.6.0 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /**
3 3 * @package Freemius
4 4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
5 + * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 6 * @since 1.0.7
7 7 */
8 8
9 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -13,10 +13,10 @@
13 13 /**
14 14 * @var array $VARS
15 15 * @var Freemius $fs
16 16 */
17 - $slug = $VARS['slug'];
18 - $fs = freemius( $slug );
17 + $fs = freemius( $VARS['id'] );
18 + $slug = $fs->get_slug();
19 19
20 20 $is_pending_activation = $fs->is_pending_activation();
21 21 $is_premium_only = $fs->is_only_premium();
22 22 $has_paid_plans = $fs->has_paid_plan();
@@ -24,8 +24,17 @@
24 24 $is_freemium = $fs->is_freemium();
25 25
26 26 $fs->_enqueue_connect_essentials();
27 27
28 + /**
29 + * Enqueueing the styles in `_enqueue_connect_essentials()` is too late, as we need them in the HEADER. Therefore, inject the styles inline to avoid FOUC.
30 + *
31 + * @author Vova Feldman (@svovaf)
32 + */
33 + echo "<style>\n";
34 + include WP_FS__DIR_CSS . '/admin/connect.css';
35 + echo "</style>\n";
36 +
28 37 $current_user = Freemius::_get_current_wp_user();
29 38
30 39 $first_name = $current_user->user_firstname;
31 40 if ( empty( $first_name ) ) {
@@ -31,34 +40,33 @@
31 40 if ( empty( $first_name ) ) {
32 41 $first_name = $current_user->nickname;
33 42 }
34 43
35 - $site_url = get_site_url();
44 + $site_url = Freemius::get_unfiltered_site_url();
36 45 $protocol_pos = strpos( $site_url, '://' );
37 46 if ( false !== $protocol_pos ) {
38 47 $site_url = substr( $site_url, $protocol_pos + 3 );
39 48 }
40 49
41 - $freemius_site_www = 'https://freemius.com';
50 + $freemius_usage_tracking_url = $fs->get_usage_tracking_terms_url();
51 + $freemius_plugin_terms_url = $fs->get_eula_url();
42 52
43 - $freemius_site_url = $freemius_site_www . '/' . ( $fs->is_premium() ?
44 - 'wordpress/' :
45 - // Insights platform information.
46 - 'wordpress/usage-tracking/' . $fs->get_id() . "/{$slug}/" );
53 + $error = fs_request_get( 'error' );
47 54
48 - if ( $fs->is_premium() ) {
49 - $freemius_site_url .= '?' . http_build_query( array(
50 - 'id' => $fs->get_id(),
51 - 'slug' => $slug,
52 - ) );
53 - }
55 + $has_release_on_freemius = $fs->has_release_on_freemius();
54 56
55 - $freemius_link = '<a href="' . $freemius_site_url . '" target="_blank" tabindex="1">freemius.com</a>';
57 + $require_license_key = $is_premium_only ||
58 + (
59 + $is_freemium &&
60 + ( $is_premium_code || ! $has_release_on_freemius ) &&
61 + fs_request_get_bool( 'require_license', ( $is_premium_code || $has_release_on_freemius ) )
62 + );
56 63
57 - $error = fs_request_get( 'error' );
64 + $freemius_activation_terms_url = ($fs->is_premium() && $require_license_key) ?
65 + $fs->get_license_activation_terms_url() :
66 + $freemius_usage_tracking_url;
58 67
59 - $require_license_key = $is_premium_only ||
60 - ( $is_freemium && $is_premium_code && fs_request_get_bool( 'require_license', true ) );
68 + $freemius_activation_terms_html = '<a href="' . esc_url( $freemius_activation_terms_url ) . '" target="_blank" rel="noopener" tabindex="1">freemius.com</a>';
61 69
62 70 if ( $is_pending_activation ) {
63 71 $require_license_key = false;
64 72 }
@@ -66,247 +74,747 @@
66 74 if ( $require_license_key ) {
67 75 $fs->_add_license_activation_dialog_box();
68 76 }
69 77
70 - $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
71 - $activate_with_current_user = is_object( $fs_user ) && ! $is_pending_activation;
78 + $is_optin_dialog = (
79 + $fs->is_theme() &&
80 + $fs->is_themes_page() &&
81 + $fs->show_opt_in_on_themes_page()
82 + );
83 +
84 + if ( $is_optin_dialog ) {
85 + $show_close_button = false;
86 + $previous_theme_activation_url = '';
87 +
88 + if ( ! $is_premium_code ) {
89 + $show_close_button = true;
90 + } else if ( $is_premium_only ) {
91 + $previous_theme_activation_url = $fs->get_previous_theme_activation_url();
92 + $show_close_button = ( ! empty( $previous_theme_activation_url ) );
93 + }
94 + }
95 +
96 + $is_network_level_activation = (
97 + fs_is_network_admin() &&
98 + $fs->is_network_active() &&
99 + ! $fs->is_network_delegated_connection()
100 + );
101 +
102 + $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
103 +
104 + $activate_with_current_user = (
105 + is_object( $fs_user ) &&
106 + ! $is_pending_activation &&
107 + // If requires a license for activation, use the user associated with the license for the opt-in.
108 + ! $require_license_key &&
109 + ! $is_network_level_activation
110 + );
111 +
112 + $optin_params = $fs->get_opt_in_params( array(), $is_network_level_activation );
113 + $sites = isset( $optin_params['sites'] ) ? $optin_params['sites'] : array();
114 +
115 + $is_network_upgrade_mode = ( fs_is_network_admin() && $fs->is_network_upgrade_mode() );
116 +
117 + /* translators: %s: name (e.g. Hey John,) */
118 + $hey_x_text = esc_html( sprintf( fs_text_x_inline( 'Hey %s,', 'greeting', 'hey-x', $slug ), $first_name ) );
119 +
120 + $activation_state = array(
121 + 'is_license_activation' => $require_license_key,
122 + 'is_pending_activation' => $is_pending_activation,
123 + 'is_gdpr_required' => true,
124 + 'is_network_level_activation' => $is_network_level_activation,
125 + 'is_dialog' => $is_optin_dialog,
126 + );
72 127 ?>
73 -<div id="fs_connect"
74 - class="wrap<?php if ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) {
75 - echo ' fs-anonymous-disabled';
76 - } ?>">
77 - <div class="fs-visual">
78 - <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b>
79 - <i class="dashicons dashicons-plus fs-first"></i>
80 - <?php
81 - $vars = array( 'slug' => $slug );
82 - fs_require_once_template( 'plugin-icon.php', $vars );
83 - ?>
84 - <i class="dashicons dashicons-plus fs-second"></i>
85 - <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/>
86 - </div>
87 - <div class="fs-content">
88 - <?php if ( ! empty( $error ) ) : ?>
89 - <p class="fs-error"><?php echo esc_html( $error ) ?></p>
90 - <?php endif ?>
91 - <p><?php
92 - $button_label = 'opt-in-connect';
128 +<?php
129 + if ( $is_optin_dialog ) { ?>
130 +<div id="fs_theme_connect_wrapper">
131 + <?php
132 + if ( $show_close_button ) { ?>
133 + <button class="close dashicons dashicons-no"><span class="screen-reader-text">Close connect dialog</span>
134 + </button>
135 + <?php
136 + }
137 + ?>
138 + <?php
139 + }
93 140
94 - if ( $is_pending_activation ) {
95 - $button_label = 'resend-activation-email';
141 + /**
142 + * Allows developers to include custom HTML before the opt-in content.
143 + *
144 + * @author Vova Feldman
145 + * @since 2.3.2
146 + */
147 + $fs->do_action( 'connect/before', $activation_state );
148 + ?>
149 + <div id="fs_connect"
150 + class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) ) {
151 + echo ' fs-anonymous-disabled';
152 + } ?><?php echo $require_license_key ? ' require-license-key' : '' ?>">
153 + <div class="fs-header">
154 + <!-- <b class="fs-site-icon"><i class="dashicons dashicons-wordpress-alt"></i></b>-->
155 + <?php
156 + $size = 50;
157 + $vars = array(
158 + 'id' => $fs->get_id(),
159 + 'size' => $size,
160 + );
96 161
97 - echo $fs->apply_filters( 'pending_activation_message', sprintf(
98 - fs_text( 'thanks-x', $slug ) . '<br>' .
99 - fs_text( 'pending-activation-message', $slug ),
100 - $first_name,
101 - '<b>' . $fs->get_plugin_name() . '</b>',
102 - '<b>' . $current_user->user_email . '</b>',
103 - fs_text( 'complete-the-install', $slug )
104 - ) );
105 - } else if ( $require_license_key ) {
106 - $button_label = 'agree-activate-license';
162 + fs_require_once_template( 'plugin-icon.php', $vars );
163 + ?>
164 + </div>
165 + <div class="fs-box-container">
166 + <div class="fs-content">
167 + <?php $fs->do_action( 'connect/before_message', $activation_state ) ?>
107 168
108 - echo $fs->apply_filters( 'connect-message_on-premium',
109 - sprintf( fs_text( 'hey-x', $slug ), $first_name ) . '<br>' .
110 - sprintf( fs_text( 'thanks-for-purchasing', $slug ), '<b>' . $fs->get_plugin_name() . '</b>' ),
111 - $first_name,
112 - $fs->get_plugin_name()
113 - );
114 - } else {
115 - $filter = 'connect_message';
116 - $default_optin_message = 'connect-message';
169 + <?php if ( ! empty( $error ) ) : ?>
170 + <div class="fs-error"><?php echo $fs->apply_filters( 'connect_error_esc_html', esc_html( $error ) ) ?></div>
171 + <?php endif ?>
172 + <?php
173 + if ( ! $is_pending_activation && ! $require_license_key ) {
174 + if ( ! $fs->is_plugin_update() ) {
175 + echo $fs->apply_filters( 'connect-header', sprintf(
176 + '<h2 style="text-align: center">%s</h2>',
177 + esc_html( fs_text_inline( 'Never miss an important update', 'connect-header' ) )
178 + ) );
179 + } else {
180 + echo $fs->apply_filters( 'connect-header_on-update', sprintf(
181 + '<h2>%s</h2>',
182 + sprintf(
183 + esc_html(
184 + /* translators: %1$s: plugin name (e.g., "Awesome Plugin"); %2$s: version (e.g., "1.2.3") */
185 + fs_text_inline('Thank you for updating to %1$s v%2$s!', 'connect-header_on-update' )
186 + ),
187 + esc_html( $fs->get_plugin_name() ),
188 + $fs->get_plugin_version()
189 + )
190 + ) );
191 + }
192 + }
193 + ?>
194 + <p><?php
195 + $button_label = fs_text_inline( 'Allow & Continue', 'opt-in-connect', $slug );
196 + $message = '';
117 197
118 - if ( $fs->is_plugin_update() ) {
119 - // If Freemius was added on a plugin update, set different
120 - // opt-in message.
121 - $default_optin_message = 'connect-message_on-update';
198 + if ( $is_pending_activation ) {
199 + $button_label = fs_text_inline( 'Re-send activation email', 'resend-activation-email', $slug );
122 200
123 - // If user customized the opt-in message on update, use
124 - // that message. Otherwise, fallback to regular opt-in
125 - // custom message if exist.
126 - if ( $fs->has_filter( 'connect_message_on_update' ) ) {
127 - $filter = 'connect_message_on_update';
201 + $message = $fs->apply_filters( 'pending_activation_message', sprintf(
202 + /* translators: %s: name (e.g. Thanks John!) */
203 + fs_text_inline( 'Thanks %s!', 'thanks-x', $slug ) . '<br>' .
204 + fs_text_inline( 'You should receive a confirmation email for %s to your mailbox at %s. Please make sure you click the button in that email to %s.', 'pending-activation-message', $slug ),
205 + $first_name,
206 + '<b>' . $fs->get_plugin_name() . '</b>',
207 + '<b>' . $current_user->user_email . '</b>',
208 + fs_text_inline( 'complete the opt-in', 'complete-the-opt-in', $slug )
209 + ) );
210 + } else if ( $require_license_key ) {
211 + $button_label = fs_text_inline( 'Activate License', 'activate-license', $slug );
212 +
213 + $message = $fs->apply_filters(
214 + 'connect-message_on-premium',
215 + sprintf( fs_text_inline( 'Welcome to %s! To get started, please enter your license key:', 'thanks-for-purchasing', $slug ), '<b>' . $fs->get_plugin_name() . '</b>' ),
216 + $first_name,
217 + $fs->get_plugin_name()
218 + );
219 + } else {
220 + $filter = 'connect_message';
221 +
222 + if ( ! $fs->is_plugin_update() ) {
223 + $default_optin_message = esc_html(
224 + sprintf(
225 + /* translators: %s: module type (plugin, theme, or add-on) */
226 + fs_text_inline( 'Opt in to get email notifications for security & feature updates, educational content, and occasional offers, and to share some basic WordPress environment info. This will help us make the %s more compatible with your site and better at doing what you need it to.', 'connect-message', $slug ),
227 + $fs->get_module_label( true )
228 + )
229 + );
230 + } else {
231 + // If Freemius was added on a plugin update, set different
232 + // opt-in message.
233 +
234 + /* translators: %s: module type (plugin, theme, or add-on) */
235 + $default_optin_message = esc_html( sprintf( fs_text_inline( 'We have introduced this opt-in so you never miss an important update and help us make the %s more compatible with your site and better at doing what you need it to.', 'connect-message_on-update_why' ), $fs->get_module_label( true ) ) );
236 +
237 + $default_optin_message .= '<br><br>' . esc_html( fs_text_inline( 'Opt in to get email notifications for security & feature updates, educational content, and occasional offers, and to share some basic WordPress environment info.', 'connect-message_on-update', $slug ) );
238 +
239 + if ( $fs->is_enable_anonymous() ) {
240 + $default_optin_message .= ' ' . esc_html( fs_text_inline( 'If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update_skip', $slug ) );
241 + }
242 +
243 + // If user customized the opt-in message on update, use
244 + // that message. Otherwise, fallback to regular opt-in
245 + // custom message if exists.
246 + if ( $fs->has_filter( 'connect_message_on_update' ) ) {
247 + $filter = 'connect_message_on_update';
248 + }
128 249 }
250 +
251 + $message = $fs->apply_filters(
252 + $filter,
253 + sprintf(
254 + $default_optin_message,
255 + '<b>' . esc_html( $fs->get_plugin_name() ) . '</b>',
256 + '<b>' . $current_user->user_login . '</b>',
257 + '<a href="' . $site_url . '" target="_blank" rel="noopener noreferrer">' . $site_url . '</a>',
258 + $freemius_activation_terms_html
259 + ),
260 + $first_name,
261 + $fs->get_plugin_name(),
262 + $current_user->user_login,
263 + '<a href="' . $site_url . '" target="_blank" rel="noopener noreferrer">' . $site_url . '</a>',
264 + $freemius_activation_terms_html,
265 + true
266 + );
129 267 }
130 268
131 - echo $fs->apply_filters( $filter,
132 - sprintf( fs_text( 'hey-x', $slug ), $first_name ) . '<br>' .
133 - sprintf(
134 - fs_text( $default_optin_message, $slug ),
135 - '<b>' . $fs->get_plugin_name() . '</b>',
136 - '<b>' . $current_user->user_login . '</b>',
137 - '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
138 - $freemius_link
139 - ),
140 - $first_name,
141 - $fs->get_plugin_name(),
142 - $current_user->user_login,
143 - '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
144 - $freemius_link
145 - );
146 - }
147 - ?></p>
148 - <?php if ( $require_license_key ) : ?>
149 - <div class="fs-license-key-container">
150 - <input id="fs_license_key" name="fs_key" type="text" required maxlength="32"
151 - placeholder="<?php fs_echo( 'license-key', $slug ) ?>" tabindex="1"/>
152 - <i class="dashicons dashicons-admin-network"></i>
153 - <a class="show-license-resend-modal show-license-resend-modal-<?php echo $slug; ?>"
154 - href="#"><?php fs_echo( 'cant-find-license-key' ); ?></a>
155 - </div>
156 - <?php endif ?>
157 - </div>
158 - <div class="fs-actions">
159 - <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ! $require_license_key ) : ?>
160 - <a href="<?php echo fs_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $slug . '_skip_activation' ) ), $slug . '_skip_activation' ) ?>"
161 - class="button button-secondary" tabindex="2"><?php fs_echo( 'skip', $slug ) ?></a>
162 - <?php endif ?>
269 + if ( $is_network_upgrade_mode ) {
270 + $network_integration_text = esc_html( fs_text_inline( 'We\'re excited to introduce the Freemius network-level integration.', 'connect_message_network_upgrade', $slug ) );
163 271
164 - <?php if ( $activate_with_current_user ) : ?>
165 - <form action="" method="POST">
166 - <input type="hidden" name="fs_action" value="<?php echo $slug ?>_activate_existing">
167 - <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?>
168 - <button class="button button-primary" tabindex="1"
169 - type="submit"<?php if ( $require_license_key ) {
170 - echo ' disabled="disabled"';
171 - } ?>><?php fs_echo( $button_label, $slug ) ?></button>
172 - </form>
173 - <?php else : ?>
174 - <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
175 - <?php $params = $fs->get_opt_in_params() ?>
176 - <?php foreach ( $params as $name => $value ) : ?>
177 - <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
178 - <?php endforeach ?>
179 - <button class="button button-primary" tabindex="1"
180 - type="submit"<?php if ( $require_license_key ) {
181 - echo ' disabled="disabled"';
182 - } ?>><?php fs_echo( $button_label, $slug ) ?></button>
183 - </form>
184 - <?php endif ?>
185 - </div><?php
272 + if ($is_premium_code){
273 + $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 ) );
186 274
187 - // Set core permission list items.
188 - $permissions = array(
189 - 'profile' => array(
190 - 'icon-class' => 'dashicons dashicons-Admin-users',
191 - 'label' => $fs->get_text( 'permissions-profile' ),
192 - 'desc' => $fs->get_text( 'permissions-profile_desc' ),
193 - 'priority' => 5,
194 - ),
195 - 'site' => array(
196 - 'icon-class' => 'dashicons dashicons-Admin-settings',
197 - 'label' => $fs->get_text( 'permissions-site' ),
198 - 'desc' => $fs->get_text( 'permissions-site_desc' ),
199 - 'priority' => 10,
200 - ),
201 - 'notices' => array(
202 - 'icon-class' => 'dashicons dashicons-testimonial',
203 - 'label' => $fs->get_text( 'permissions-Admin-notices' ),
204 - 'desc' => $fs->get_text( 'permissions-newsletter_desc' ),
205 - 'priority' => 13,
206 - ),
207 - 'events' => array(
208 - 'icon-class' => 'dashicons dashicons-Admin-plugins',
209 - 'label' => $fs->get_text( 'permissions-events' ),
210 - 'desc' => $fs->get_text( 'permissions-events_desc' ),
211 - 'priority' => 20,
212 - ),
213 -// 'plugins_themes' => array(
214 -// 'icon-class' => 'dashicons dashicons-Admin-settings',
215 -// 'label' => fs_text( 'permissions-plugins_themes' ),
216 -// 'desc' => fs_text( 'permissions-plugins_themes_desc' ),
217 -// 'priority' => 30,
218 -// ),
219 - );
275 + $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(
276 + /* translators: %s: module type (plugin, theme, or add-on) */
277 + fs_text_inline( "%s's paid features", 'x-paid-features', $slug ),
278 + $fs->get_module_label( true )
279 + ) );
220 280
221 - // Add newsletter permissions if enabled.
222 - if ( $fs->is_permission_requested( 'newsletter' ) ) {
223 - $permissions['newsletter'] = array(
224 - 'icon-class' => 'dashicons dashicons-email-alt',
225 - 'label' => $fs->get_text( 'permissions-newsletter' ),
226 - 'desc' => $fs->get_text( 'permissions-newsletter_desc' ),
227 - 'priority' => 15,
228 - );
229 - }
281 + /* translators: %s: module type (plugin, theme, or add-on) */
282 + $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 ) );
283 + }else {
284 + $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 );
285 + }
286 + }
230 287
231 - // Allow filtering of the permissions list.
232 - $permissions = $fs->apply_filters( 'permission_list', $permissions );
288 + echo $message;
289 + ?></p>
290 + <?php if ( $require_license_key ) : ?>
291 + <div class="fs-license-key-container">
292 + <input id="fs_license_key" name="fs_key" type="text" required maxlength="<?php echo $fs->apply_filters('license_key_maxlength', 32) ?>"
293 + placeholder="<?php fs_esc_attr_echo_inline( 'License key', 'license-key', $slug ) ?>" tabindex="1"/>
294 + <i class="dashicons dashicons-admin-network"></i>
295 + <a class="show-license-resend-modal show-license-resend-modal-<?php echo $fs->get_unique_affix() ?>"
296 + href="#"><?php fs_esc_html_echo_inline( "Can't find your license key?", 'cant-find-license-key', $slug ); ?></a>
297 + </div>
233 298
234 - // Sort by priority.
235 - uasort( $permissions, 'fs_sort_by_priority' );
299 + <?php
300 + /**
301 + * Allows developers to include custom HTML after the license input container.
302 + *
303 + * @author Vova Feldman
304 + * @since 2.1.2
305 + */
306 + $fs->do_action( 'connect/after_license_input', $activation_state );
307 + ?>
236 308
237 - if ( ! empty( $permissions ) ) : ?>
238 - <div class="fs-permissions">
239 - <?php if ( $require_license_key ) : ?>
240 - <p class="fs-license-sync-disclaimer"><?php printf( fs_esc_html( 'license-sync-disclaimer', $slug ), $freemius_link ) ?></p>
241 - <?php endif ?>
242 - <a class="fs-trigger" href="#" tabindex="1"><?php fs_echo( 'what-permissions', $slug ) ?></a>
243 - <ul><?php
244 - foreach ( $permissions as $id => $permission ) : ?>
245 - <li id="fs-permission-<?php echo esc_attr( $id ); ?>"
246 - class="fs-permission fs-<?php echo esc_attr( $id ); ?>">
247 - <i class="<?php echo esc_attr( $permission['icon-class'] ); ?>"></i>
309 + <?php
310 + $send_updates_text = sprintf(
311 + '%s<span class="action-description"> - %s</span>',
312 + $fs->get_text_inline( 'Yes', 'yes' ),
313 + $fs->get_text_inline( 'send me security & feature updates, educational content and offers.', 'send-updates' )
314 + );
248 315
249 - <div>
250 - <span><?php echo esc_html( $permission['label'] ); ?></span>
316 + $do_not_send_updates_text = sprintf(
317 + '%s<span class="action-description"> - %s</span>',
318 + $fs->get_text_inline( 'No', 'no' ),
319 + sprintf(
320 + $fs->get_text_inline( 'do %sNOT%s send me security & feature updates, educational content and offers.', 'do-not-send-updates' ),
321 + '<span class="underlined">',
322 + '</span>'
323 + )
324 + );
325 + ?>
326 + <div id="fs_marketing_optin">
327 + <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>
328 + <div class="fs-input-container">
329 + <label>
330 + <input type="radio" name="allow-marketing" value="true" tabindex="1" />
331 + <span class="fs-input-label"><?php echo $send_updates_text ?></span>
332 + </label>
333 + <label>
334 + <input type="radio" name="allow-marketing" value="false" tabindex="1" />
335 + <span class="fs-input-label"><?php echo $do_not_send_updates_text ?></span>
336 + </label>
337 + </div>
338 + </div>
339 + <?php endif ?>
340 + <?php if ( $is_network_level_activation ) : ?>
341 + <?php
342 + $vars = array(
343 + 'id' => $fs->get_id(),
344 + 'sites' => $sites,
345 + 'require_license_key' => $require_license_key
346 + );
251 347
252 - <p><?php echo esc_html( $permission['desc'] ); ?></p>
253 - </div>
254 - </li>
255 - <?php endforeach; ?>
256 - </ul>
348 + echo fs_get_template( 'partials/network-activation.php', $vars );
349 + ?>
350 + <?php endif ?>
351 +
352 + <?php $fs->do_action( 'connect/after_message', $activation_state ) ?>
353 + </div>
354 + <div class="fs-actions">
355 + <?php $fs->do_action( 'connect/before_actions', $activation_state ) ?>
356 +
357 + <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ( ! $require_license_key || $is_network_upgrade_mode ) ) : ?>
358 + <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' ) ?>"
359 + class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?></a>
360 + <?php endif ?>
361 + <?php if ( $is_network_level_activation && $fs->apply_filters( 'show_delegation_option', true ) ) : ?>
362 + <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>
363 + <?php endif ?>
364 + <?php if ( $activate_with_current_user ) : ?>
365 + <form action="" method="POST">
366 + <input type="hidden" name="fs_action"
367 + value="<?php echo esc_attr( $fs->get_unique_affix() . '_activate_existing' ) ?>">
368 + <?php wp_nonce_field( $fs->get_unique_affix() . '_activate_existing' ) ?>
369 + <input type="hidden" name="is_extensions_tracking_allowed" value="1">
370 + <input type="hidden" name="is_diagnostic_tracking_allowed" value="1">
371 + <button class="button button-primary" tabindex="1"
372 + type="submit"><?php echo esc_html( $button_label ) ?></button>
373 + </form>
374 + <?php else : ?>
375 + <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
376 + <?php unset( $optin_params['sites']); ?>
377 + <?php foreach ( $optin_params as $name => $value ) : ?>
378 + <input type="hidden" name="<?php echo esc_attr( $name ) ?>" value="<?php echo esc_attr( $value ) ?>">
379 + <?php endforeach ?>
380 + <input type="hidden" name="is_extensions_tracking_allowed" value="1">
381 + <input type="hidden" name="is_diagnostic_tracking_allowed" value="1">
382 + <button class="button button-primary" tabindex="1"
383 + type="submit"<?php if ( $require_license_key ) {
384 + echo ' disabled="disabled"';
385 + } ?>><?php echo esc_html( $button_label ) ?></button>
386 + </form>
387 + <?php endif ?>
388 + <?php if ( $require_license_key ) : ?>
389 + <a id="license_issues_link"
390 + href="<?php echo esc_url( $fs->apply_filters( 'known_license_issues_url', 'https://freemius.com/help/documentation/wordpress-sdk/license-activation-issues/' ) ) ?>"
391 + target="_blank"><?php fs_esc_html_echo_inline( 'License issues?', 'license-issues', $slug ) ?></a>
392 + <?php endif ?>
393 +
394 + <?php $fs->do_action( 'connect/after_actions', $activation_state ) ?>
395 + </div><?php
396 + $permission_manager = FS_Permission_Manager::instance( $fs );
397 +
398 + // Set core permission list items.
399 + $permissions = array();
400 +
401 + // Add newsletter permissions if enabled.
402 + if ( $fs->is_permission_requested( 'newsletter' ) ) {
403 + $permissions[] = $permission_manager->get_newsletter_permission();
404 + }
405 +
406 + $permissions = $permission_manager->get_permissions(
407 + $require_license_key,
408 + $permissions
409 + );
410 +
411 + if ( ! empty( $permissions ) ) : ?>
412 + <div class="fs-permissions">
413 + <?php if ( $require_license_key ) : ?>
414 + <a class="fs-trigger wp-core-ui" href="#" tabindex="1" style="color: inherit;"><?php echo sprintf(
415 + fs_esc_html_inline( 'For delivery of security & feature updates, and license management, %s needs to', 'license-sync-disclaimer', $slug ) . '<b class="fs-arrow"></b>',
416 + sprintf( '<nobr class="button-link" style="color: inherit;">%s</nobr>', esc_html( $fs->get_plugin_title() ) )
417 + ) ?></a>
418 + <?php else : ?>
419 + <a class="fs-trigger wp-core-ui" href="#" tabindex="1" style="color: inherit;"><?php printf(
420 + fs_esc_html_inline( 'This will allow %s to', 'this-will-allow-x', $slug ) . '<b class="fs-arrow"></b>',
421 + sprintf( '<nobr class="button-link" style="color: inherit;">%s</nobr>', esc_html( $fs->get_plugin_title() ) )
422 + ) ?></a>
423 + <?php endif ?>
424 + <ul><?php
425 + foreach ( $permissions as $permission ) {
426 + $permission_manager->render_permission( $permission );
427 + }
428 + ?></ul>
429 + </div>
430 + <?php endif ?>
431 + <?php if ( $is_premium_code && $is_freemium ) : ?>
432 + <div class="fs-freemium-licensing">
433 + <p>
434 + <?php if ( $require_license_key ) : ?>
435 + <?php fs_esc_html_echo_inline( 'Don\'t have a license key?', 'dont-have-license-key', $slug ) ?>
436 + <a data-require-license="false" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate Free Version', 'activate-free-version', $slug ) ?></a>
437 + <?php else : ?>
438 + <?php fs_echo_inline( 'Have a license key?', 'have-license-key', $slug ) ?>
439 + <a data-require-license="true" tabindex="1"><?php fs_esc_html_echo_inline( 'Activate License', 'activate-license', $slug ) ?></a>
440 + <?php endif ?>
441 + </p>
257 442 </div>
258 443 <?php endif ?>
259 - <?php if ( $is_premium_code && $is_freemium ) : ?>
260 - <div class="fs-freemium-licensing">
261 - <p>
262 - <?php if ( $require_license_key ) : ?>
263 - <?php fs_echo( 'dont-have-license-key', $slug ) ?>
264 - <a data-require-license="false" tabindex="1"><?php fs_echo( 'activate-free-version', $slug ) ?></a>
265 - <?php else : ?>
266 - <?php fs_echo( 'have-license-key', $slug ) ?>
267 - <a data-require-license="true" tabindex="1"><?php fs_echo( 'activate-license', $slug ) ?></a>
268 - <?php endif ?>
269 - </p>
444 + </div>
445 + <div class="fs-terms">
446 + <a class="fs-tooltip-trigger<?php echo is_rtl() ? ' rtl' : '' ?>" href="<?php echo esc_url( $freemius_activation_terms_url ) ?>" target="_blank" rel="noopener" tabindex="1">Powered by Freemius<?php if ( $require_license_key ) : ?> <span class="fs-tooltip" style="width: 170px"><?php echo esc_html( $fs->get_text_inline( 'Freemius is our licensing and software updates engine', 'permissions-extensions_desc' ) ) ?></span><?php endif ?></a>
447 + &nbsp;&nbsp;-&nbsp;&nbsp;
448 + <a href="https://freemius.com/privacy/" target="_blank" rel="noopener"
449 + tabindex="1"><?php fs_esc_html_echo_inline( 'Privacy Policy', 'privacy-policy', $slug ) ?></a>
450 + &nbsp;&nbsp;-&nbsp;&nbsp;
451 + <?php if ($require_license_key) : ?>
452 + <a href="<?php echo esc_url( $freemius_plugin_terms_url ) ?>" target="_blank" rel="noopener" tabindex="1"><?php fs_echo_inline( 'License Agreement', 'license-agreement', $slug ) ?></a>
453 + <?php else : ?>
454 + <a href="<?php echo esc_url( $freemius_usage_tracking_url ) ?>" target="_blank" rel="noopener" tabindex="1"><?php fs_echo_inline( 'Terms of Service', 'tos', $slug ) ?></a>
455 + <?php endif; ?>
270 456 </div>
271 - <?php endif ?>
272 - <div class="fs-terms">
273 - <a href="https://freemius.com/privacy/" target="_blank"
274 - tabindex="1"><?php fs_echo( 'privacy-policy', $slug ) ?></a>
275 - &nbsp;&nbsp;-&nbsp;&nbsp;
276 - <a href="<?php echo $freemius_site_www ?>/terms/" target="_blank" tabindex="1"><?php fs_echo( 'tos', $slug ) ?></a>
277 457 </div>
458 + <?php
459 + /**
460 + * Allows developers to include custom HTML after the opt-in content.
461 + *
462 + * @author Vova Feldman
463 + * @since 2.3.2
464 + */
465 + $fs->do_action( 'connect/after', $activation_state );
466 +
467 + if ( $is_optin_dialog ) { ?>
278 468 </div>
469 +<?php
470 + }
471 +?>
279 472 <script type="text/javascript">
280 473 (function ($) {
281 - var $primaryCta = $('.fs-actions .button.button-primary'),
282 - $form = $('.fs-actions form'),
283 - requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
284 - hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>,
474 + var $html = $('html');
475 +
476 + <?php
477 + if ( $is_optin_dialog ) {
478 + if ( $show_close_button ) { ?>
479 + var $themeConnectWrapper = $('#fs_theme_connect_wrapper');
480 +
481 + $themeConnectWrapper.find('button.close').on('click', function () {
482 + <?php if ( ! empty( $previous_theme_activation_url ) ) { ?>
483 + location.href = '<?php echo html_entity_decode( $previous_theme_activation_url ); ?>';
484 + <?php } else { ?>
485 + $themeConnectWrapper.remove();
486 + $html.css({overflow: $html.attr('fs-optin-overflow')});
487 + <?php } ?>
488 + });
489 + <?php
490 + }
491 + ?>
492 +
493 + $html.attr('fs-optin-overflow', $html.css('overflow'));
494 + $html.css({overflow: 'hidden'});
495 +
496 + <?php
497 + }
498 + ?>
499 +
500 + var $primaryCta = $('.fs-actions .button.button-primary'),
501 + primaryCtaLabel = $primaryCta.html(),
502 + $form = $('.fs-actions form'),
503 + isNetworkActive = <?php echo $is_network_level_activation ? 'true' : 'false' ?>,
504 + requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
505 + hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>,
506 + isNetworkUpgradeMode = <?php echo $is_network_upgrade_mode ? 'true' : 'false' ?>,
285 507 $licenseSecret,
286 - $licenseKeyInput = $('#fs_license_key');
508 + $licenseKeyInput = $('#fs_license_key'),
509 + pauseCtaLabelUpdate = false,
510 + isNetworkDelegating = false,
511 + /**
512 + * @author Leo Fajardo (@leorw)
513 + * @since 2.1.0
514 + */
515 + resetLoadingMode = function() {
516 + // Reset loading mode.
517 + $primaryCta.html(primaryCtaLabel);
518 + $primaryCta.prop('disabled', false);
519 + $( '.fs-loading' ).removeClass( 'fs-loading' );
287 520
521 + console.log('resetLoadingMode - Primary button was enabled');
522 + },
523 + setLoadingMode = function () {
524 + $( document.body ).addClass( 'fs-loading' );
525 + };
526 +
288 527 $('.fs-actions .button').on('click', function () {
289 - // Set loading mode.
290 - $(document.body).css({'cursor': 'wait'});
528 + setLoadingMode();
291 529
292 530 var $this = $(this);
293 - $this.css({'cursor': 'wait'});
294 531
295 532 setTimeout(function () {
296 - $this.attr('disabled', 'disabled');
533 + if ( ! requireLicenseKey || ! $marketingOptin.hasClass( 'error' ) ) {
534 + $this.attr('disabled', 'disabled');
535 + }
297 536 }, 200);
298 537 });
299 538
539 + if ( isNetworkActive ) {
540 + var
541 + $multisiteOptionsContainer = $( '.fs-multisite-options-container' ),
542 + $allSitesOptions = $( '.fs-all-sites-options' ),
543 + $applyOnAllSites = $( '.fs-apply-on-all-sites-checkbox' ),
544 + $sitesListContainer = $( '.fs-sites-list-container' ),
545 + totalSites = <?php echo count( $sites ) ?>,
546 + maxSitesListHeight = null,
547 + $skipActivationButton = $( '#skip_activation' ),
548 + $delegateToSiteAdminsButton = $( '#delegate_to_site_admins' ),
549 + hasAnyInstall = <?php echo ! is_null( $fs->find_first_install() ) ? 'true' : 'false' ?>;
550 +
551 + $applyOnAllSites.click(function() {
552 + var isChecked = $( this ).is( ':checked' );
553 +
554 + if ( isChecked ) {
555 + $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
556 + updatePrimaryCtaText( 'allow' );
557 + }
558 +
559 + $multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' );
560 +
561 + $skipActivationButton.toggle();
562 +
563 + $delegateToSiteAdminsButton.toggle();
564 +
565 + $multisiteOptionsContainer.toggleClass( 'fs-apply-on-all-sites', isChecked );
566 +
567 + $sitesListContainer.toggle( ! isChecked );
568 + if ( ! isChecked && null === maxSitesListHeight ) {
569 + /**
570 + * Set the visible number of rows to 5 (5 * height of the first row).
571 + *
572 + * @author Leo Fajardo (@leorw)
573 + */
574 + maxSitesListHeight = ( 5 * $sitesListContainer.find( 'tr:first' ).height() );
575 + $sitesListContainer.css( 'max-height', maxSitesListHeight );
576 + }
577 + });
578 +
579 + $allSitesOptions.find( '.action' ).click(function( evt ) {
580 + var actionType = $( evt.target ).data( 'action-type' );
581 +
582 + $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' );
583 + $multisiteOptionsContainer.find( '.action-' + actionType ).toggleClass( 'selected' );
584 +
585 + updatePrimaryCtaText( actionType );
586 + });
587 +
588 + $sitesListContainer.delegate( 'td:not(:first-child)', 'click', function() {
589 + // If a site row is clicked, trigger a click on the checkbox.
590 + $( this ).parent().find( 'td:first-child input' ).click();
591 + } );
592 +
593 + $sitesListContainer.delegate( '.action', 'click', function( evt ) {
594 + var $this = $( evt.target );
595 + if ( $this.hasClass( 'selected' ) ) {
596 + return false;
597 + }
598 +
599 + $this.parents( 'tr:first' ).find( '.action' ).removeClass( 'selected' );
600 + $this.toggleClass( 'selected' );
601 +
602 + var
603 + singleSiteActionType = $this.data( 'action-type' ),
604 + totalSelected = $sitesListContainer.find( '.action-' + singleSiteActionType + '.selected' ).length;
605 +
606 + $allSitesOptions.find( '.action.selected' ).removeClass( 'selected' );
607 +
608 + if ( totalSelected === totalSites ) {
609 + $allSitesOptions.find( '.action-' + singleSiteActionType ).addClass( 'selected' );
610 +
611 + updatePrimaryCtaText( singleSiteActionType );
612 + } else {
613 + updatePrimaryCtaText( 'mixed' );
614 + }
615 + });
616 +
617 + if ( isNetworkUpgradeMode || hasAnyInstall ) {
618 + $skipActivationButton.click(function(){
619 + $delegateToSiteAdminsButton.hide();
620 +
621 + $skipActivationButton.html('<?php fs_esc_js_echo_inline( 'Skipping, please wait', 'skipping-wait', $slug ) ?>...');
622 +
623 + pauseCtaLabelUpdate = true;
624 +
625 + // Check all sites to be skipped.
626 + $allSitesOptions.find('.action.action-skip').click();
627 +
628 + $form.submit();
629 +
630 + pauseCtaLabelUpdate = false;
631 +
632 + return false;
633 + });
634 +
635 + $delegateToSiteAdminsButton.click(function(){
636 + $delegateToSiteAdminsButton.html('<?php fs_esc_js_echo_inline( 'Delegating, please wait', 'delegating-wait', $slug ) ?>...');
637 +
638 + pauseCtaLabelUpdate = true;
639 +
640 + /**
641 + * Set to true so that the form submission handler can differentiate delegation from license
642 + * activation and the proper AJAX action will be used (when delegating, the action should be
643 + * `network_activate` and not `activate_license`).
644 + *
645 + * @author Leo Fajardo (@leorw)
646 + * @since 2.3.0
647 + */
648 + isNetworkDelegating = true;
649 +
650 + // Check all sites to be skipped.
651 + $allSitesOptions.find('.action.action-delegate').click();
652 +
653 + $form.submit();
654 +
655 + pauseCtaLabelUpdate = false;
656 +
657 + /**
658 + * Set to false so that in case the previous AJAX request has failed, the form submission handler
659 + * can differentiate license activation from delegation and the proper AJAX action will be used
660 + * (when activating a license, the action should be `activate_license` and not `network_activate`).
661 + *
662 + * @author Leo Fajardo (@leorw)
663 + * @since 2.3.0
664 + */
665 + isNetworkDelegating = false;
666 +
667 + return false;
668 + });
669 + }
670 + }
671 +
672 + /**
673 + * @author Leo Fajardo (@leorw)
674 + */
675 + function updatePrimaryCtaText( actionType ) {
676 + if (pauseCtaLabelUpdate)
677 + return;
678 +
679 + var text = '<?php fs_esc_js_echo_inline( 'Continue', 'continue', $slug ) ?>';
680 +
681 + switch ( actionType ) {
682 + case 'allow':
683 + text = '<?php fs_esc_js_echo_inline( 'Allow & Continue', 'opt-in-connect', $slug ) ?>';
684 + break;
685 + case 'delegate':
686 + text = '<?php fs_esc_js_echo_inline( 'Delegate to Site Admins & Continue', 'delegate-to-site-admins-and-continue', $slug ) ?>';
687 + break;
688 + case 'skip':
689 + text = '<?php fs_esc_js_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?>';
690 + break;
691 + }
692 +
693 + $primaryCta.html( text );
694 + }
695 +
696 + var ajaxOptin = ( requireLicenseKey || isNetworkActive );
697 +
300 698 $form.on('submit', function () {
699 + var $extensionsPermission = $( '#fs_permission_extensions .fs-switch' ),
700 + isExtensionsTrackingAllowed = ( $extensionsPermission.length > 0 ) ?
701 + $extensionsPermission.hasClass( 'fs-on' ) :
702 + null;
703 +
704 + var $diagnosticPermission = $( '#fs_permission_diagnostic .fs-switch' ),
705 + isDiagnosticTrackingAllowed = ( $diagnosticPermission.length > 0 ) ?
706 + $diagnosticPermission.hasClass( 'fs-on' ) :
707 + null;
708 +
709 + if ( null === isExtensionsTrackingAllowed ) {
710 + $( 'input[name=is_extensions_tracking_allowed]' ).remove();
711 + } else {
712 + $( 'input[name=is_extensions_tracking_allowed]' ).val( isExtensionsTrackingAllowed ? 1 : 0 );
713 + }
714 +
715 + // We are not showing switch to enable/disable diagnostic tracking while activating free version. So, don't remove hidden `is_diagnostic_tracking_allowed` element from DOM and change the value only if switch is available.
716 + if ( null !== isDiagnosticTrackingAllowed ) {
717 + $( 'input[name=is_diagnostic_tracking_allowed]' ).val( isDiagnosticTrackingAllowed ? 1 : 0 );
718 + }
719 +
301 720 /**
302 721 * @author Vova Feldman (@svovaf)
303 722 * @since 1.1.9
304 723 */
305 - if (requireLicenseKey) {
306 - if (!hasContextUser) {
724 + if ( ajaxOptin ) {
725 + if (!hasContextUser || isNetworkUpgradeMode) {
726 + var action = null,
727 + security = null;
728 +
729 + if ( requireLicenseKey && ! isNetworkDelegating ) {
730 + action = '<?php echo $fs->get_ajax_action( 'activate_license' ) ?>';
731 + security = '<?php echo $fs->get_ajax_security( 'activate_license' ) ?>';
732 + } else {
733 + action = '<?php echo $fs->get_ajax_action( 'network_activate' ) ?>';
734 + security = '<?php echo $fs->get_ajax_security( 'network_activate' ) ?>';
735 + }
736 +
307 737 $('.fs-error').remove();
308 738
739 + var
740 + licenseKey = $licenseKeyInput.val(),
741 + data = {
742 + action : action,
743 + security : security,
744 + license_key: licenseKey,
745 + module_id : '<?php echo $fs->get_id() ?>'
746 + };
747 +
748 + if (
749 + requireLicenseKey &&
750 + ! isNetworkDelegating &&
751 + isMarketingAllowedByLicense.hasOwnProperty(licenseKey)
752 + ) {
753 + var
754 + isMarketingAllowed = null,
755 + $isMarketingAllowed = $marketingOptin.find( 'input[type="radio"][name="allow-marketing"]:checked');
756 +
757 +
758 + if ($isMarketingAllowed.length > 0)
759 + isMarketingAllowed = ('true' == $isMarketingAllowed.val());
760 +
761 + if ( null == isMarketingAllowedByLicense[ licenseKey ] &&
762 + null == isMarketingAllowed
763 + ) {
764 + $marketingOptin.addClass( 'error' ).show();
765 + resetLoadingMode();
766 + return false;
767 + } else if ( null == isMarketingAllowed ) {
768 + isMarketingAllowed = isMarketingAllowedByLicense[ licenseKey ];
769 + }
770 +
771 + data.is_marketing_allowed = isMarketingAllowed;
772 +
773 + data.is_extensions_tracking_allowed = isExtensionsTrackingAllowed;
774 +
775 + data.is_diagnostic_tracking_allowed = isDiagnosticTrackingAllowed;
776 + }
777 +
778 + $marketingOptin.removeClass( 'error' );
779 +
780 + if ( isNetworkActive ) {
781 + var
782 + sites = [],
783 + applyOnAllSites = $applyOnAllSites.is( ':checked' );
784 +
785 + $sitesListContainer.find( 'tr' ).each(function() {
786 + var
787 + $this = $( this ),
788 + includeSite = ( ! requireLicenseKey || applyOnAllSites || $this.find( 'input' ).is( ':checked' ) );
789 +
790 + if ( ! includeSite )
791 + return;
792 +
793 + var site = {
794 + uid : $this.find( '.uid' ).val(),
795 + url : $this.find( '.url' ).val(),
796 + title : $this.find( '.title' ).val(),
797 + language: $this.find( '.language' ).val(),
798 + blog_id : $this.find( '.blog-id' ).find( 'span' ).text()
799 + };
800 +
801 + if ( ! requireLicenseKey) {
802 + site.action = $this.find('.action.selected').data('action-type');
803 + } else if ( isNetworkDelegating ) {
804 + site.action = 'delegate';
805 + }
806 +
807 + sites.push( site );
808 + });
809 +
810 + data.sites = sites;
811 +
812 + if ( hasAnyInstall ) {
813 + data.has_any_install = hasAnyInstall;
814 + }
815 + }
816 +
309 817 /**
310 818 * Use the AJAX opt-in when license key is required to potentially
311 819 * process the after install failure hook.
312 820 *
@@ -313,16 +821,11 @@
313 821 * @author Vova Feldman (@svovaf)
314 822 * @since 1.2.1.5
315 823 */
316 824 $.ajax({
317 - url : ajaxurl,
825 + url : <?php echo Freemius::ajax_url() ?>,
318 826 method : 'POST',
319 - data : {
320 - action : '<?php echo $fs->get_ajax_action( 'activate_license' ) ?>',
321 - security : '<?php echo $fs->get_ajax_security( 'activate_license' ) ?>',
322 - license_key: $licenseKeyInput.val(),
323 - slug : '<?php echo $slug ?>'
324 - },
827 + data : data,
325 828 success: function (result) {
326 829 var resultObj = $.parseJSON(result);
327 830 if (resultObj.success) {
328 831 // Redirect to the "Account" page and sync the license.
@@ -327,17 +830,16 @@
327 830 if (resultObj.success) {
328 831 // Redirect to the "Account" page and sync the license.
329 832 window.location.href = resultObj.next_page;
330 833 } else {
834 + resetLoadingMode();
835 +
331 836 // Show error.
332 - $('.fs-content').prepend('<p class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</p>');
333 -
334 - // Reset loading mode.
335 - $primaryCta.removeClass('fs-loading').css({'cursor': 'auto'});
336 - $primaryCta.html(<?php echo json_encode( fs_text( $button_label, $slug ) ) ?>);
337 - $primaryCta.prop('disabled', false);
338 - $(document.body).css({'cursor': 'auto'});
837 + $('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>');
339 838 }
839 + },
840 + error: function () {
841 + resetLoadingMode();
340 842 }
341 843 });
342 844
343 845 return false;
@@ -355,11 +857,25 @@
355 857
356 858 return true;
357 859 });
358 860
861 + $( '#fs_connect .fs-permissions .fs-switch' ).on( 'click', function () {
862 + $( this )
863 + .toggleClass( 'fs-on' )
864 + .toggleClass( 'fs-off' );
865 +
866 + $( this ).closest( '.fs-permission' )
867 + .toggleClass( 'fs-disabled' );
868 + });
869 +
359 870 $primaryCta.on('click', function () {
871 + console.log('Primary button was clicked');
872 +
360 873 $(this).addClass('fs-loading');
361 - $(this).html(<?php echo json_encode( fs_text( $is_pending_activation ? 'sending-email' : 'activating', $slug ) ) ?> +'...');
874 + $(this).html('<?php echo esc_js( $is_pending_activation ?
875 + fs_text_x_inline( 'Sending email', 'as in the process of sending an email', 'sending-email', $slug ) :
876 + fs_text_x_inline( 'Activating', 'as activating plugin', 'activating', $slug )
877 + ) ?>...');
362 878 });
363 879
364 880 $('.fs-permissions .fs-trigger').on('click', function () {
365 881 $('.fs-permissions').toggleClass('fs-open');
@@ -390,13 +906,28 @@
390 906 * @since 1.1.9
391 907 */
392 908 $licenseKeyInput.on('keyup paste delete cut', function () {
393 909 setTimeout(function () {
394 - if ('' === $licenseKeyInput.val()) {
910 + var key = $licenseKeyInput.val();
911 +
912 + if (key == previousLicenseKey){
913 + return;
914 + }
915 +
916 + if ('' === key) {
395 917 $primaryCta.attr('disabled', 'disabled');
918 + $marketingOptin.hide();
396 919 } else {
397 - $primaryCta.prop('disabled', false);
920 + $primaryCta.prop('disabled', false);
921 +
922 + if (32 <= key.length){
923 + fetchIsMarketingAllowedFlagAndToggleOptin();
924 + } else {
925 + $marketingOptin.hide();
926 + }
398 927 }
928 +
929 + previousLicenseKey = key;
399 930 }, 100);
400 931 }).focus();
401 932 }
402 933
@@ -421,6 +952,92 @@
421 952 'href',
422 953 href + 'require_license=' + $connectLicenseModeTrigger.attr('data-require-license')
423 954 );
424 955 }
956 +
957 + //--------------------------------------------------------------------------------
958 + //region GDPR
959 + //--------------------------------------------------------------------------------
960 + var isMarketingAllowedByLicense = {},
961 + $marketingOptin = $('#fs_marketing_optin'),
962 + previousLicenseKey = null;
963 +
964 + if (requireLicenseKey) {
965 +
966 + var
967 + afterMarketingFlagLoaded = function () {
968 + var licenseKey = $licenseKeyInput.val();
969 +
970 + if (null == isMarketingAllowedByLicense[licenseKey]) {
971 + $marketingOptin.show();
972 +
973 + if ($marketingOptin.find('input[type=radio]:checked').length > 0){
974 + // Focus on button if GDPR opt-in already selected is already selected.
975 + $primaryCta.focus();
976 + } else {
977 + // Focus on the GDPR opt-in radio button.
978 + $($marketingOptin.find('input[type=radio]')[0]).focus();
979 + }
980 + } else {
981 + $marketingOptin.hide();
982 + $primaryCta.focus();
983 + }
984 + },
985 + /**
986 + * @author Leo Fajardo (@leorw)
987 + * @since 2.1.0
988 + */
989 + fetchIsMarketingAllowedFlagAndToggleOptin = function () {
990 + var licenseKey = $licenseKeyInput.val();
991 +
992 + if (licenseKey.length < 32) {
993 + $marketingOptin.hide();
994 + return;
995 + }
996 +
997 + if (isMarketingAllowedByLicense.hasOwnProperty(licenseKey)) {
998 + afterMarketingFlagLoaded();
999 + return;
1000 + }
1001 +
1002 + $marketingOptin.hide();
1003 +
1004 + setLoadingMode();
1005 +
1006 + $primaryCta.addClass('fs-loading');
1007 + $primaryCta.attr('disabled', 'disabled');
1008 + $primaryCta.html('<?php fs_esc_js_echo_inline( 'Please wait', 'please-wait', $slug ) ?>...');
1009 +
1010 + $.ajax({
1011 + url : <?php echo Freemius::ajax_url() ?>,
1012 + method : 'POST',
1013 + data : {
1014 + action : '<?php echo $fs->get_ajax_action( 'fetch_is_marketing_required_flag_value' ) ?>',
1015 + security : '<?php echo $fs->get_ajax_security( 'fetch_is_marketing_required_flag_value' ) ?>',
1016 + license_key: licenseKey,
1017 + module_id : '<?php echo $fs->get_id() ?>'
1018 + },
1019 + success: function (result) {
1020 + resetLoadingMode();
1021 +
1022 + if (result.success) {
1023 + result = result.data;
1024 +
1025 + // Cache result.
1026 + isMarketingAllowedByLicense[licenseKey] = result.is_marketing_allowed;
1027 + }
1028 +
1029 + afterMarketingFlagLoaded();
1030 + }
1031 + });
1032 + };
1033 +
1034 + $marketingOptin.find( 'input' ).click(function() {
1035 + $marketingOptin.removeClass( 'error' );
1036 + });
1037 + }
1038 +
1039 + //endregion
425 1040 })(jQuery);
426 -</script>
1041 +</script>
1042 +<?php
1043 + fs_require_once_template( 'api-connectivity-message-js.php' );