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