| @@ -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 | } |
| @@ -69,9 +77,9 @@ | ||
| 69 | 77 | |
| 70 | 78 | $is_optin_dialog = ( |
| 71 | 79 | $fs->is_theme() && |
| 72 | 80 | $fs->is_themes_page() && |
| 73 | - ( ! $fs->has_settings_menu() || $fs->is_free_wp_org_theme() ) | |
| 81 | + $fs->show_opt_in_on_themes_page() | |
| 74 | 82 | ); |
| 75 | 83 | |
| 76 | 84 | if ( $is_optin_dialog ) { |
| 77 | 85 | $show_close_button = false; |
| @@ -107,8 +115,16 @@ | ||
| 107 | 115 | $is_network_upgrade_mode = ( fs_is_network_admin() && $fs->is_network_upgrade_mode() ); |
| 108 | 116 | |
| 109 | 117 | /* translators: %s: name (e.g. Hey John,) */ |
| 110 | 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 | + ); | |
| 111 | 127 | ?> |
| 112 | 128 | <?php |
| 113 | 129 | if ( $is_optin_dialog ) { ?> |
| 114 | 130 | <div id="fs_theme_connect_wrapper"> |
| @@ -120,27 +136,62 @@ | ||
| 120 | 136 | } |
| 121 | 137 | ?> |
| 122 | 138 | <?php |
| 123 | 139 | } |
| 140 | + | |
| 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 ); | |
| 124 | 148 | ?> |
| 125 | 149 | <div id="fs_connect" |
| 126 | 150 | class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) ) { |
| 127 | 151 | echo ' fs-anonymous-disabled'; |
| 128 | 152 | } ?><?php echo $require_license_key ? ' require-license-key' : '' ?>"> |
| 129 | - <div class="fs-visual"> | |
| 130 | - <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b> | |
| 131 | - <i class="dashicons dashicons-plus fs-first"></i> | |
| 132 | - <?php | |
| 133 | - $vars = array( 'id' => $fs->get_id() ); | |
| 134 | - fs_require_once_template( 'plugin-icon.php', $vars ); | |
| 135 | - ?> | |
| 136 | - <i class="dashicons dashicons-plus fs-second"></i> | |
| 137 | - <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/> | |
| 138 | - </div> | |
| 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 | + ); | |
| 161 | + | |
| 162 | + fs_require_once_template( 'plugin-icon.php', $vars ); | |
| 163 | + ?> | |
| 164 | + </div> | |
| 165 | + <div class="fs-box-container"> | |
| 139 | 166 | <div class="fs-content"> |
| 167 | + <?php $fs->do_action( 'connect/before_message', $activation_state ) ?> | |
| 168 | + | |
| 140 | 169 | <?php if ( ! empty( $error ) ) : ?> |
| 141 | - <p class="fs-error"><?php echo esc_html( $error ) ?></p> | |
| 170 | + <div class="fs-error"><?php echo $fs->apply_filters( 'connect_error_esc_html', esc_html( $error ) ) ?></div> | |
| 142 | 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 | + ?> | |
| 143 | 194 | <p><?php |
| 144 | 195 | $button_label = fs_text_inline( 'Allow & Continue', 'opt-in-connect', $slug ); |
| 145 | 196 | $message = ''; |
| 146 | 197 | |
| @@ -149,42 +200,50 @@ | ||
| 149 | 200 | |
| 150 | 201 | $message = $fs->apply_filters( 'pending_activation_message', sprintf( |
| 151 | 202 | /* translators: %s: name (e.g. Thanks John!) */ |
| 152 | 203 | fs_text_inline( 'Thanks %s!', 'thanks-x', $slug ) . '<br>' . |
| 153 | - 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 ), | |
| 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 ), | |
| 154 | 205 | $first_name, |
| 155 | 206 | '<b>' . $fs->get_plugin_name() . '</b>', |
| 156 | 207 | '<b>' . $current_user->user_email . '</b>', |
| 157 | - fs_text_inline( 'complete the install', 'complete-the-install', $slug ) | |
| 208 | + fs_text_inline( 'complete the opt-in', 'complete-the-opt-in', $slug ) | |
| 158 | 209 | ) ); |
| 159 | 210 | } else if ( $require_license_key ) { |
| 160 | - $button_label = $is_network_upgrade_mode ? | |
| 161 | - fs_text_inline( 'Activate License', 'agree-activate-license', $slug ) : | |
| 162 | - fs_text_inline( 'Agree & Activate License', 'agree-activate-license', $slug ); | |
| 211 | + $button_label = fs_text_inline( 'Activate License', 'activate-license', $slug ); | |
| 163 | 212 | |
| 164 | 213 | $message = $fs->apply_filters( |
| 165 | 214 | 'connect-message_on-premium', |
| 166 | - ($is_network_upgrade_mode ? | |
| 167 | - '' : | |
| 168 | - /* translators: %s: name (e.g. Hey John,) */ | |
| 169 | - $hey_x_text . '<br>' | |
| 170 | - ) . | |
| 171 | - 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>' ), | |
| 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>' ), | |
| 172 | 216 | $first_name, |
| 173 | 217 | $fs->get_plugin_name() |
| 174 | 218 | ); |
| 175 | 219 | } else { |
| 176 | - $filter = 'connect_message'; | |
| 177 | - $default_optin_message = 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);; | |
| 220 | + $filter = 'connect_message'; | |
| 178 | 221 | |
| 179 | - if ( $fs->is_plugin_update() ) { | |
| 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 { | |
| 180 | 231 | // If Freemius was added on a plugin update, set different |
| 181 | 232 | // opt-in message. |
| 182 | - $default_optin_message = fs_text_inline( 'Please help us improve %1$s! If you opt in, some data about your usage of %1$s will be sent to %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug ); | |
| 183 | 233 | |
| 184 | - // If user customized the opt-in message on update, use | |
| 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 | |
| 185 | 244 | // that message. Otherwise, fallback to regular opt-in |
| 186 | - // custom message if exist. | |
| 245 | + // custom message if exists. | |
| 187 | 246 | if ( $fs->has_filter( 'connect_message_on_update' ) ) { |
| 188 | 247 | $filter = 'connect_message_on_update'; |
| 189 | 248 | } |
| 190 | 249 | } |
| @@ -190,25 +249,21 @@ | ||
| 190 | 249 | } |
| 191 | 250 | |
| 192 | 251 | $message = $fs->apply_filters( |
| 193 | 252 | $filter, |
| 194 | - ($is_network_upgrade_mode ? | |
| 195 | - '' : | |
| 196 | - /* translators: %s: name (e.g. Hey John,) */ | |
| 197 | - $hey_x_text . '<br>' | |
| 198 | - ) . | |
| 199 | 253 | sprintf( |
| 200 | - esc_html( $default_optin_message ), | |
| 254 | + $default_optin_message, | |
| 201 | 255 | '<b>' . esc_html( $fs->get_plugin_name() ) . '</b>', |
| 202 | 256 | '<b>' . $current_user->user_login . '</b>', |
| 203 | - '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>', | |
| 204 | - $freemius_link | |
| 257 | + '<a href="' . $site_url . '" target="_blank" rel="noopener noreferrer">' . $site_url . '</a>', | |
| 258 | + $freemius_activation_terms_html | |
| 205 | 259 | ), |
| 206 | 260 | $first_name, |
| 207 | 261 | $fs->get_plugin_name(), |
| 208 | 262 | $current_user->user_login, |
| 209 | - '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>', | |
| 210 | - $freemius_link | |
| 263 | + '<a href="' . $site_url . '" target="_blank" rel="noopener noreferrer">' . $site_url . '</a>', | |
| 264 | + $freemius_activation_terms_html, | |
| 265 | + true | |
| 211 | 266 | ); |
| 212 | 267 | } |
| 213 | 268 | |
| 214 | 269 | if ( $is_network_upgrade_mode ) { |
| @@ -233,14 +288,55 @@ | ||
| 233 | 288 | echo $message; |
| 234 | 289 | ?></p> |
| 235 | 290 | <?php if ( $require_license_key ) : ?> |
| 236 | 291 | <div class="fs-license-key-container"> |
| 237 | - <input id="fs_license_key" name="fs_key" type="text" required maxlength="32" | |
| 292 | + <input id="fs_license_key" name="fs_key" type="text" required maxlength="<?php echo $fs->apply_filters('license_key_maxlength', 32) ?>" | |
| 238 | 293 | placeholder="<?php fs_esc_attr_echo_inline( 'License key', 'license-key', $slug ) ?>" tabindex="1"/> |
| 239 | 294 | <i class="dashicons dashicons-admin-network"></i> |
| 240 | 295 | <a class="show-license-resend-modal show-license-resend-modal-<?php echo $fs->get_unique_affix() ?>" |
| 241 | 296 | href="#"><?php fs_esc_html_echo_inline( "Can't find your license key?", 'cant-find-license-key', $slug ); ?></a> |
| 242 | 297 | </div> |
| 298 | + | |
| 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 | + ?> | |
| 308 | + | |
| 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 | + ); | |
| 315 | + | |
| 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> | |
| 243 | 339 | <?php endif ?> |
| 244 | 340 | <?php if ( $is_network_level_activation ) : ?> |
| 245 | 341 | <?php |
| 246 | 342 | $vars = array( |
| @@ -251,22 +347,28 @@ | ||
| 251 | 347 | |
| 252 | 348 | echo fs_get_template( 'partials/network-activation.php', $vars ); |
| 253 | 349 | ?> |
| 254 | 350 | <?php endif ?> |
| 351 | + | |
| 352 | + <?php $fs->do_action( 'connect/after_message', $activation_state ) ?> | |
| 255 | 353 | </div> |
| 256 | 354 | <div class="fs-actions"> |
| 355 | + <?php $fs->do_action( 'connect/before_actions', $activation_state ) ?> | |
| 356 | + | |
| 257 | 357 | <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ( ! $require_license_key || $is_network_upgrade_mode ) ) : ?> |
| 258 | 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' ) ?>" |
| 259 | 359 | class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'Skip', 'verb', 'skip', $slug ) ?></a> |
| 260 | 360 | <?php endif ?> |
| 261 | - <?php if ( $is_network_level_activation ) : ?> | |
| 361 | + <?php if ( $is_network_level_activation && $fs->apply_filters( 'show_delegation_option', true ) ) : ?> | |
| 262 | 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> |
| 263 | 363 | <?php endif ?> |
| 264 | 364 | <?php if ( $activate_with_current_user ) : ?> |
| 265 | 365 | <form action="" method="POST"> |
| 266 | 366 | <input type="hidden" name="fs_action" |
| 267 | - value="<?php echo $fs->get_unique_affix() ?>_activate_existing"> | |
| 268 | - <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?> | |
| 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"> | |
| 269 | 371 | <button class="button button-primary" tabindex="1" |
| 270 | 372 | type="submit"><?php echo esc_html( $button_label ) ?></button> |
| 271 | 373 | </form> |
| 272 | 374 | <?php else : ?> |
| @@ -272,10 +374,12 @@ | ||
| 272 | 374 | <?php else : ?> |
| 273 | 375 | <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/"> |
| 274 | 376 | <?php unset( $optin_params['sites']); ?> |
| 275 | 377 | <?php foreach ( $optin_params as $name => $value ) : ?> |
| 276 | - <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>"> | |
| 378 | + <input type="hidden" name="<?php echo esc_attr( $name ) ?>" value="<?php echo esc_attr( $value ) ?>"> | |
| 277 | 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"> | |
| 278 | 382 | <button class="button button-primary" tabindex="1" |
| 279 | 383 | type="submit"<?php if ( $require_license_key ) { |
| 280 | 384 | echo ' disabled="disabled"'; |
| 281 | 385 | } ?>><?php echo esc_html( $button_label ) ?></button> |
| @@ -280,85 +384,49 @@ | ||
| 280 | 384 | echo ' disabled="disabled"'; |
| 281 | 385 | } ?>><?php echo esc_html( $button_label ) ?></button> |
| 282 | 386 | </form> |
| 283 | 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 ) ?> | |
| 284 | 395 | </div><?php |
| 396 | + $permission_manager = FS_Permission_Manager::instance( $fs ); | |
| 285 | 397 | |
| 286 | 398 | // Set core permission list items. |
| 287 | - $permissions = array( | |
| 288 | - 'profile' => array( | |
| 289 | - 'icon-class' => 'dashicons dashicons-admin-users', | |
| 290 | - 'label' => $fs->get_text_inline( 'Your Profile Overview', 'permissions-profile' ), | |
| 291 | - 'desc' => $fs->get_text_inline( 'Name and email address', 'permissions-profile_desc' ), | |
| 292 | - 'priority' => 5, | |
| 293 | - ), | |
| 294 | - 'site' => array( | |
| 295 | - 'icon-class' => 'dashicons dashicons-admin-settings', | |
| 296 | - 'label' => $fs->get_text_inline( 'Your Site Overview', 'permissions-site' ), | |
| 297 | - 'desc' => $fs->get_text_inline( 'Site URL, WP version, PHP info, plugins & themes', 'permissions-site_desc' ), | |
| 298 | - 'priority' => 10, | |
| 299 | - ), | |
| 300 | - 'notices' => array( | |
| 301 | - 'icon-class' => 'dashicons dashicons-testimonial', | |
| 302 | - 'label' => $fs->get_text_inline( 'Admin Notices', 'permissions-admin-notices' ), | |
| 303 | - 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ), | |
| 304 | - 'priority' => 13, | |
| 305 | - ), | |
| 306 | - 'events' => array( | |
| 307 | - 'icon-class' => 'dashicons dashicons-admin-plugins', | |
| 308 | - 'label' => sprintf( $fs->get_text_inline( 'Current %s Events', 'permissions-events' ), ucfirst( $fs->get_module_type() ) ), | |
| 309 | - 'desc' => $fs->get_text_inline( 'Activation, deactivation and uninstall', 'permissions-events_desc' ), | |
| 310 | - 'priority' => 20, | |
| 311 | - ), | |
| 312 | -// 'plugins_themes' => array( | |
| 313 | -// 'icon-class' => 'dashicons dashicons-admin-settings', | |
| 314 | -// 'label' => fs_text_inline( 'Plugins & Themes', 'permissions-plugins_themes' ), | |
| 315 | -// 'desc' => fs_text_inline( 'Titles, versions and state.', 'permissions-plugins_themes_desc' ), | |
| 316 | -// 'priority' => 30, | |
| 317 | -// ), | |
| 318 | - ); | |
| 399 | + $permissions = array(); | |
| 319 | 400 | |
| 320 | - // Add newsletter permissions if enabled. | |
| 321 | - if ( $fs->is_permission_requested( 'newsletter' ) ) { | |
| 322 | - $permissions['newsletter'] = array( | |
| 323 | - 'icon-class' => 'dashicons dashicons-email-alt', | |
| 324 | - 'label' => $fs->get_text_inline( 'Newsletter', 'permissions-newsletter' ), | |
| 325 | - 'desc' => $fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ), | |
| 326 | - 'priority' => 15, | |
| 327 | - ); | |
| 328 | - } | |
| 401 | + // Add newsletter permissions if enabled. | |
| 402 | + if ( $fs->is_permission_requested( 'newsletter' ) ) { | |
| 403 | + $permissions[] = $permission_manager->get_newsletter_permission(); | |
| 404 | + } | |
| 329 | 405 | |
| 330 | - // Allow filtering of the permissions list. | |
| 331 | - $permissions = $fs->apply_filters( 'permission_list', $permissions ); | |
| 406 | + $permissions = $permission_manager->get_permissions( | |
| 407 | + $require_license_key, | |
| 408 | + $permissions | |
| 409 | + ); | |
| 332 | 410 | |
| 333 | - // Sort by priority. | |
| 334 | - uasort( $permissions, 'fs_sort_by_priority' ); | |
| 335 | - | |
| 336 | 411 | if ( ! empty( $permissions ) ) : ?> |
| 337 | 412 | <div class="fs-permissions"> |
| 338 | - <?php if ( $require_license_key ) : ?> | |
| 339 | - <p class="fs-license-sync-disclaimer"><?php | |
| 340 | - echo sprintf( | |
| 341 | - 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 ), | |
| 342 | - $fs->get_module_label( true ), | |
| 343 | - $freemius_link | |
| 344 | - ) ?></p> | |
| 345 | - <?php endif ?> | |
| 346 | - <a class="fs-trigger" href="#" tabindex="1"><?php fs_esc_html_echo_inline( 'What permissions are being granted?', 'what-permissions', $slug ) ?></a> | |
| 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 ?> | |
| 347 | 424 | <ul><?php |
| 348 | - foreach ( $permissions as $id => $permission ) : ?> | |
| 349 | - <li id="fs-permission-<?php echo esc_attr( $id ); ?>" | |
| 350 | - class="fs-permission fs-<?php echo esc_attr( $id ); ?>"> | |
| 351 | - <i class="<?php echo esc_attr( $permission['icon-class'] ); ?>"></i> | |
| 352 | - | |
| 353 | - <div> | |
| 354 | - <span><?php echo esc_html( $permission['label'] ); ?></span> | |
| 355 | - | |
| 356 | - <p><?php echo esc_html( $permission['desc'] ); ?></p> | |
| 357 | - </div> | |
| 358 | - </li> | |
| 359 | - <?php endforeach; ?> | |
| 360 | - </ul> | |
| 425 | + foreach ( $permissions as $permission ) { | |
| 426 | + $permission_manager->render_permission( $permission ); | |
| 427 | + } | |
| 428 | + ?></ul> | |
| 361 | 429 | </div> |
| 362 | 430 | <?php endif ?> |
| 363 | 431 | <?php if ( $is_premium_code && $is_freemium ) : ?> |
| 364 | 432 | <div class="fs-freemium-licensing"> |
| @@ -372,16 +440,31 @@ | ||
| 372 | 440 | <?php endif ?> |
| 373 | 441 | </p> |
| 374 | 442 | </div> |
| 375 | 443 | <?php endif ?> |
| 444 | + </div> | |
| 376 | 445 | <div class="fs-terms"> |
| 377 | - <a href="https://freemius.com/privacy/" target="_blank" | |
| 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 | + - | |
| 448 | + <a href="https://freemius.com/privacy/" target="_blank" rel="noopener" | |
| 378 | 449 | tabindex="1"><?php fs_esc_html_echo_inline( 'Privacy Policy', 'privacy-policy', $slug ) ?></a> |
| 379 | 450 | - |
| 380 | - <a href="<?php echo $freemius_site_www ?>/terms/" target="_blank" tabindex="1"><?php fs_echo_inline( 'Terms of Service', 'tos', $slug ) ?></a> | |
| 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; ?> | |
| 381 | 456 | </div> |
| 382 | 457 | </div> |
| 383 | 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 | + | |
| 384 | 467 | if ( $is_optin_dialog ) { ?> |
| 385 | 468 | </div> |
| 386 | 469 | <?php |
| 387 | 470 | } |
| @@ -414,8 +497,9 @@ | ||
| 414 | 497 | } |
| 415 | 498 | ?> |
| 416 | 499 | |
| 417 | 500 | var $primaryCta = $('.fs-actions .button.button-primary'), |
| 501 | + primaryCtaLabel = $primaryCta.html(), | |
| 418 | 502 | $form = $('.fs-actions form'), |
| 419 | 503 | isNetworkActive = <?php echo $is_network_level_activation ? 'true' : 'false' ?>, |
| 420 | 504 | requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>, |
| 421 | 505 | hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>, |
| @@ -421,48 +505,65 @@ | ||
| 421 | 505 | hasContextUser = <?php echo $activate_with_current_user ? 'true' : 'false' ?>, |
| 422 | 506 | isNetworkUpgradeMode = <?php echo $is_network_upgrade_mode ? 'true' : 'false' ?>, |
| 423 | 507 | $licenseSecret, |
| 424 | 508 | $licenseKeyInput = $('#fs_license_key'), |
| 425 | - pauseCtaLabelUpdate = false; | |
| 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' ); | |
| 426 | 520 | |
| 521 | + console.log('resetLoadingMode - Primary button was enabled'); | |
| 522 | + }, | |
| 523 | + setLoadingMode = function () { | |
| 524 | + $( document.body ).addClass( 'fs-loading' ); | |
| 525 | + }; | |
| 526 | + | |
| 427 | 527 | $('.fs-actions .button').on('click', function () { |
| 428 | - // Set loading mode. | |
| 429 | - $(document.body).css({'cursor': 'wait'}); | |
| 528 | + setLoadingMode(); | |
| 430 | 529 | |
| 431 | 530 | var $this = $(this); |
| 432 | - $this.css({'cursor': 'wait'}); | |
| 433 | 531 | |
| 434 | 532 | setTimeout(function () { |
| 435 | - $this.attr('disabled', 'disabled'); | |
| 533 | + if ( ! requireLicenseKey || ! $marketingOptin.hasClass( 'error' ) ) { | |
| 534 | + $this.attr('disabled', 'disabled'); | |
| 535 | + } | |
| 436 | 536 | }, 200); |
| 437 | 537 | }); |
| 438 | 538 | |
| 439 | 539 | if ( isNetworkActive ) { |
| 440 | 540 | var |
| 441 | - $multisiteOptionsContainer = $( '#multisite_options_container' ), | |
| 442 | - $allSitesOptions = $( '#all_sites_options' ), | |
| 443 | - $applyOnAllSites = $( '#apply_on_all_sites' ), | |
| 444 | - $sitesListContainer = $( '#sites_list_container' ), | |
| 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' ), | |
| 445 | 545 | totalSites = <?php echo count( $sites ) ?>, |
| 446 | 546 | maxSitesListHeight = null, |
| 447 | 547 | $skipActivationButton = $( '#skip_activation' ), |
| 448 | - $delegateToSiteAdminsButton = $( '#delegate_to_site_admins' ); | |
| 548 | + $delegateToSiteAdminsButton = $( '#delegate_to_site_admins' ), | |
| 549 | + hasAnyInstall = <?php echo ! is_null( $fs->find_first_install() ) ? 'true' : 'false' ?>; | |
| 449 | 550 | |
| 450 | 551 | $applyOnAllSites.click(function() { |
| 451 | 552 | var isChecked = $( this ).is( ':checked' ); |
| 452 | 553 | |
| 453 | - if ( ! isChecked ) { | |
| 454 | - $multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' ); | |
| 455 | - } else { | |
| 554 | + if ( isChecked ) { | |
| 456 | 555 | $multisiteOptionsContainer.find( '.action' ).removeClass( 'selected' ); |
| 457 | 556 | updatePrimaryCtaText( 'allow' ); |
| 458 | 557 | } |
| 459 | 558 | |
| 460 | - $skipActivationButton.toggle(); | |
| 559 | + $multisiteOptionsContainer.find( '.action-allow' ).addClass( 'selected' ); | |
| 461 | 560 | |
| 561 | + $skipActivationButton.toggle(); | |
| 562 | + | |
| 462 | 563 | $delegateToSiteAdminsButton.toggle(); |
| 463 | 564 | |
| 464 | - $multisiteOptionsContainer.toggleClass( 'apply-on-all-sites', isChecked ); | |
| 565 | + $multisiteOptionsContainer.toggleClass( 'fs-apply-on-all-sites', isChecked ); | |
| 465 | 566 | |
| 466 | 567 | $sitesListContainer.toggle( ! isChecked ); |
| 467 | 568 | if ( ! isChecked && null === maxSitesListHeight ) { |
| 468 | 569 | /** |
| @@ -483,8 +584,13 @@ | ||
| 483 | 584 | |
| 484 | 585 | updatePrimaryCtaText( actionType ); |
| 485 | 586 | }); |
| 486 | 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 | + | |
| 487 | 593 | $sitesListContainer.delegate( '.action', 'click', function( evt ) { |
| 488 | 594 | var $this = $( evt.target ); |
| 489 | 595 | if ( $this.hasClass( 'selected' ) ) { |
| 490 | 596 | return false; |
| @@ -507,9 +613,9 @@ | ||
| 507 | 613 | updatePrimaryCtaText( 'mixed' ); |
| 508 | 614 | } |
| 509 | 615 | }); |
| 510 | 616 | |
| 511 | - if (isNetworkUpgradeMode) { | |
| 617 | + if ( isNetworkUpgradeMode || hasAnyInstall ) { | |
| 512 | 618 | $skipActivationButton.click(function(){ |
| 513 | 619 | $delegateToSiteAdminsButton.hide(); |
| 514 | 620 | |
| 515 | 621 | $skipActivationButton.html('<?php fs_esc_js_echo_inline( 'Skipping, please wait', 'skipping-wait', $slug ) ?>...'); |
| @@ -530,8 +636,18 @@ | ||
| 530 | 636 | $delegateToSiteAdminsButton.html('<?php fs_esc_js_echo_inline( 'Delegating, please wait', 'delegating-wait', $slug ) ?>...'); |
| 531 | 637 | |
| 532 | 638 | pauseCtaLabelUpdate = true; |
| 533 | 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 | + | |
| 534 | 650 | // Check all sites to be skipped. |
| 535 | 651 | $allSitesOptions.find('.action.action-delegate').click(); |
| 536 | 652 | |
| 537 | 653 | $form.submit(); |
| @@ -537,8 +653,18 @@ | ||
| 537 | 653 | $form.submit(); |
| 538 | 654 | |
| 539 | 655 | pauseCtaLabelUpdate = false; |
| 540 | 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 | + | |
| 541 | 667 | return false; |
| 542 | 668 | }); |
| 543 | 669 | } |
| 544 | 670 | } |
| @@ -569,8 +695,29 @@ | ||
| 569 | 695 | |
| 570 | 696 | var ajaxOptin = ( requireLicenseKey || isNetworkActive ); |
| 571 | 697 | |
| 572 | 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 | + | |
| 573 | 720 | /** |
| 574 | 721 | * @author Vova Feldman (@svovaf) |
| 575 | 722 | * @since 1.1.9 |
| 576 | 723 | */ |
| @@ -575,19 +722,62 @@ | ||
| 575 | 722 | * @since 1.1.9 |
| 576 | 723 | */ |
| 577 | 724 | if ( ajaxOptin ) { |
| 578 | 725 | if (!hasContextUser || isNetworkUpgradeMode) { |
| 579 | - <?php $action = $require_license_key ? 'activate_license' : 'network_activate' ?> | |
| 726 | + var action = null, | |
| 727 | + security = null; | |
| 580 | 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 | + | |
| 581 | 737 | $('.fs-error').remove(); |
| 582 | 738 | |
| 583 | - var data = { | |
| 584 | - action : '<?php echo $fs->get_ajax_action( $action ) ?>', | |
| 585 | - security : '<?php echo $fs->get_ajax_security( $action ) ?>', | |
| 586 | - license_key: $licenseKeyInput.val(), | |
| 587 | - module_id : '<?php echo $fs->get_id() ?>' | |
| 588 | - }; | |
| 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 | + }; | |
| 589 | 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 | + | |
| 590 | 780 | if ( isNetworkActive ) { |
| 591 | 781 | var |
| 592 | 782 | sites = [], |
| 593 | 783 | applyOnAllSites = $applyOnAllSites.is( ':checked' ); |
| @@ -604,14 +794,15 @@ | ||
| 604 | 794 | uid : $this.find( '.uid' ).val(), |
| 605 | 795 | url : $this.find( '.url' ).val(), |
| 606 | 796 | title : $this.find( '.title' ).val(), |
| 607 | 797 | language: $this.find( '.language' ).val(), |
| 608 | - charset : $this.find( '.charset' ).val(), | |
| 609 | 798 | blog_id : $this.find( '.blog-id' ).find( 'span' ).text() |
| 610 | 799 | }; |
| 611 | 800 | |
| 612 | 801 | if ( ! requireLicenseKey) { |
| 613 | 802 | site.action = $this.find('.action.selected').data('action-type'); |
| 803 | + } else if ( isNetworkDelegating ) { | |
| 804 | + site.action = 'delegate'; | |
| 614 | 805 | } |
| 615 | 806 | |
| 616 | 807 | sites.push( site ); |
| 617 | 808 | }); |
| @@ -616,8 +807,12 @@ | ||
| 616 | 807 | sites.push( site ); |
| 617 | 808 | }); |
| 618 | 809 | |
| 619 | 810 | data.sites = sites; |
| 811 | + | |
| 812 | + if ( hasAnyInstall ) { | |
| 813 | + data.has_any_install = hasAnyInstall; | |
| 814 | + } | |
| 620 | 815 | } |
| 621 | 816 | |
| 622 | 817 | /** |
| 623 | 818 | * Use the AJAX opt-in when license key is required to potentially |
| @@ -626,9 +821,9 @@ | ||
| 626 | 821 | * @author Vova Feldman (@svovaf) |
| 627 | 822 | * @since 1.2.1.5 |
| 628 | 823 | */ |
| 629 | 824 | $.ajax({ |
| 630 | - url : ajaxurl, | |
| 825 | + url : <?php echo Freemius::ajax_url() ?>, | |
| 631 | 826 | method : 'POST', |
| 632 | 827 | data : data, |
| 633 | 828 | success: function (result) { |
| 634 | 829 | var resultObj = $.parseJSON(result); |
| @@ -635,17 +830,16 @@ | ||
| 635 | 830 | if (resultObj.success) { |
| 636 | 831 | // Redirect to the "Account" page and sync the license. |
| 637 | 832 | window.location.href = resultObj.next_page; |
| 638 | 833 | } else { |
| 834 | + resetLoadingMode(); | |
| 835 | + | |
| 639 | 836 | // Show error. |
| 640 | - $('.fs-content').prepend('<p class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</p>'); | |
| 641 | - | |
| 642 | - // Reset loading mode. | |
| 643 | - $primaryCta.removeClass('fs-loading').css({'cursor': 'auto'}); | |
| 644 | - $primaryCta.html('<?php echo esc_js( $button_label ) ?>'); | |
| 645 | - $primaryCta.prop('disabled', false); | |
| 646 | - $(document.body).css({'cursor': 'auto'}); | |
| 837 | + $('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>'); | |
| 647 | 838 | } |
| 839 | + }, | |
| 840 | + error: function () { | |
| 841 | + resetLoadingMode(); | |
| 648 | 842 | } |
| 649 | 843 | }); |
| 650 | 844 | |
| 651 | 845 | return false; |
| @@ -663,9 +857,20 @@ | ||
| 663 | 857 | |
| 664 | 858 | return true; |
| 665 | 859 | }); |
| 666 | 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 | + | |
| 667 | 870 | $primaryCta.on('click', function () { |
| 871 | + console.log('Primary button was clicked'); | |
| 872 | + | |
| 668 | 873 | $(this).addClass('fs-loading'); |
| 669 | 874 | $(this).html('<?php echo esc_js( $is_pending_activation ? |
| 670 | 875 | fs_text_x_inline( 'Sending email', 'as in the process of sending an email', 'sending-email', $slug ) : |
| 671 | 876 | fs_text_x_inline( 'Activating', 'as activating plugin', 'activating', $slug ) |
| @@ -701,13 +906,28 @@ | ||
| 701 | 906 | * @since 1.1.9 |
| 702 | 907 | */ |
| 703 | 908 | $licenseKeyInput.on('keyup paste delete cut', function () { |
| 704 | 909 | setTimeout(function () { |
| 705 | - if ('' === $licenseKeyInput.val()) { | |
| 910 | + var key = $licenseKeyInput.val(); | |
| 911 | + | |
| 912 | + if (key == previousLicenseKey){ | |
| 913 | + return; | |
| 914 | + } | |
| 915 | + | |
| 916 | + if ('' === key) { | |
| 706 | 917 | $primaryCta.attr('disabled', 'disabled'); |
| 918 | + $marketingOptin.hide(); | |
| 707 | 919 | } else { |
| 708 | - $primaryCta.prop('disabled', false); | |
| 920 | + $primaryCta.prop('disabled', false); | |
| 921 | + | |
| 922 | + if (32 <= key.length){ | |
| 923 | + fetchIsMarketingAllowedFlagAndToggleOptin(); | |
| 924 | + } else { | |
| 925 | + $marketingOptin.hide(); | |
| 926 | + } | |
| 709 | 927 | } |
| 928 | + | |
| 929 | + previousLicenseKey = key; | |
| 710 | 930 | }, 100); |
| 711 | 931 | }).focus(); |
| 712 | 932 | } |
| 713 | 933 | |
| @@ -732,6 +952,92 @@ | ||
| 732 | 952 | 'href', |
| 733 | 953 | href + 'require_license=' + $connectLicenseModeTrigger.attr('data-require-license') |
| 734 | 954 | ); |
| 735 | 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 | |
| 736 | 1040 | })(jQuery); |
| 737 | -</script> | |
| 1041 | +</script> | |
| 1042 | +<?php | |
| 1043 | + fs_require_once_template( 'api-connectivity-message-js.php' ); | |