Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[privacy] [activation] If there is no user during activation shows a … #705

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions assets/scss/admin/_gdpr-consent.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#fs_marketing_optin
.fs_gdpr_consent
{
display: none;
margin-top: 10px;
Expand Down Expand Up @@ -62,7 +62,7 @@

.rtl
{
#fs_marketing_optin
.fs_gdpr_consent
{
.fs-input-container
{
Expand All @@ -78,4 +78,27 @@
margin-right: 20px;
}
}
}
}

#fs_personal_data
{
.fs-fields-container {
display: flex;
flex-wrap: wrap;
margin: 0 -15px;

.fs-input-container {
padding: 0 15px;
box-sizing: border-box;
flex: 1 1 50%;

input {
width: 100%;
}

&:last-child {
flex: 1 1 100%;
}
}
}
}
31 changes: 16 additions & 15 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -13763,7 +13763,10 @@ function _activate_license_ajax_action() {
fs_request_get( 'module_id', null, 'post' ),
fs_request_get( 'user_id', null ),
fs_request_get_bool( 'is_extensions_tracking_allowed', null ),
fs_request_get_bool( 'is_diagnostic_tracking_allowed', null )
fs_request_get_bool( 'is_diagnostic_tracking_allowed', null ),
fs_request_get( 'user_firstname', null ),
fs_request_get( 'user_lastname', null ),
fs_request_get( 'user_email', null )
);

if (
Expand Down Expand Up @@ -14026,7 +14029,10 @@ private function activate_license(
$plugin_id = null,
$license_owner_id = null,
$is_extensions_tracking_allowed = null,
$is_diagnostic_tracking_allowed = null
$is_diagnostic_tracking_allowed = null,
$user_firstname = null,
$user_lastname = null,
$user_email = null
) {
$this->_logger->entrance();

Expand All @@ -14052,7 +14058,8 @@ private function activate_license(
) );

$error = false;
$next_page = false;
$error_code = false;
$next_page = false;

$has_valid_blog_id = is_numeric( $blog_id );

Expand Down Expand Up @@ -14186,9 +14193,9 @@ private function activate_license(
$fs->update_connectivity_info( $is_connected );
} else {
$next_page = $fs->opt_in(
false,
false,
false,
$user_email || false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we pass $user_email as is instead of having a fallback false value here?

$user_firstname || false,
$user_lastname || false,
$license_key,
false,
false,
Expand All @@ -14199,6 +14206,7 @@ private function activate_license(

if ( isset( $next_page->error ) ) {
$error = $next_page->error;
$error_code = $next_page->code;
} else {
if ( $is_network_activation_or_migration ) {
/**
Expand Down Expand Up @@ -14267,6 +14275,7 @@ private function activate_license(

if ( false !== $error ) {
$result['error'] = $fs->apply_filters( 'opt_in_error_message', $error );
$result['error_code'] = $error_code;
} else {
if ( $fs->is_addon() || $fs->has_addons() ) {
/**
Expand Down Expand Up @@ -17214,9 +17223,6 @@ function get_opt_in_params( $override_with = array(), $network_level_or_blog_id
$versions = $this->get_versions();

$params = array_merge( $versions, array(
'user_firstname' => $current_user->user_firstname,
'user_lastname' => $current_user->user_lastname,
'user_email' => $current_user->user_email,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the $current_user variable is no longer used, we can remove the declaration above.

'plugin_slug' => $this->_slug,
'plugin_id' => $this->get_id(),
'plugin_public_key' => $this->get_public_key(),
Expand Down Expand Up @@ -17329,11 +17335,6 @@ function opt_in(
) {
$this->_logger->entrance();

if ( false === $email ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this if block is now removed, we also need to deal with the Freemius::_get_user_by_email( $email ) call below which may cause unexpected behavior as it can now accept a false value.

Instead of removing it, I think it should be something like if ( false === $email && empty( $license_key ) ) { ....

$current_user = self::_get_current_wp_user();
$email = $current_user->user_email;
}

/**
* @since 1.2.1 If activating with license key, ignore the context-user
* since the user will be automatically loaded from the license.
Expand Down Expand Up @@ -21349,7 +21350,7 @@ private function _sync_plugin_license(
* associated with that ID is not included in the user's licenses collection.
* Save previous value to manage remote license renewals.
*/
$was_license_expired_before_sync = $this->_license->is_expired();
$was_license_expired_before_sync = $this->_license && $this->_license->is_expired();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use is_object( $this->_license ) instead of this style.

$this->_sync_licenses(
$site->license_id,
( $is_context_single_site ?
Expand Down
5 changes: 1 addition & 4 deletions templates/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@
} else {
$current_user = Freemius::_get_current_wp_user();

// Add site and user info to the request, this information
// Add site info to the request, this information
// is NOT being stored unless the user complete the purchase
// and agrees to the TOS.
$context_params = array_merge( $context_params, array(
'user_firstname' => $current_user->user_firstname,
'user_lastname' => $current_user->user_lastname,
'user_email' => $current_user->user_email,
'home_url' => home_url(),
) );

Expand Down
74 changes: 62 additions & 12 deletions templates/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,34 @@ class="wrap<?php if ( ! fs_is_network_admin() && ( ! $fs->is_enable_anonymous()
)
);
?>
<div id="fs_marketing_optin">
<!-- BEGIN EXPLICIT DATA FIELDS -->
<div id="fs_personal_data" class="fs_gdpr_consent">
<!--
The fields below are used to explicitly collect missing information in cases where it is not possible
to assign an existing user to the license being activated. This was done to avoid sending private data
in any case.
-->
<span class="fs-message"><?php fs_echo_inline( "Please enter at least a valid email address to activate your license:",
'email-is-requested' ) ?></span>
<div class="fs-fields-container">
<div class="fs-input-container">
<label for="first_name" class="screen-reader-text">First name</label>
<input type="text" id="first_name" name="first_name" placeholder="First name"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the fs_ prefix for the id attribute.

class="fs-input">
</div>
<div class="fs-input-container">
<label for="last_name" class="screen-reader-text">Last name</label>
<input type="text" id="last_name" name="last_name" placeholder="Last name" class="fs-input">
</div>
<div class="fs-input-container">
<label for="user_email" class="screen-reader-text">Email (required)</label>
<input type="email" id="user_email" name="user_email" placeholder="Email (required)"
class="fs-input" required>
</div>
</div>
</div>
<!-- END EXPLICIT DATA FIELDS -->
<div id="fs_marketing_optin" class="fs_gdpr_consent">
<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>
<div class="fs-input-container">
<label>
Expand Down Expand Up @@ -525,6 +552,11 @@ class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'S
$( document.body ).addClass( 'fs-loading' );
};

$('#fs_personal_data input').on('focus', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need spaces here (similar to PHP). There are examples here:
https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/#examples-of-good-spacing

So it should be like this:

$( '#fs_personal_data input' ).on( 'focus', function() {
    $( '#fs_personal_data' ).removeClass( 'error' );
    resetLoadingMode();
} );

$('#fs_personal_data').removeClass('error');
resetLoadingMode();
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


$('.fs-actions .button').on('click', function () {
setLoadingMode();

Expand Down Expand Up @@ -697,6 +729,19 @@ function updatePrimaryCtaText( actionType ) {
var ajaxOptin = ( requireLicenseKey || isNetworkActive );

$form.on('submit', function () {
const personal_data = {};
if ($personalData.is(':visible')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the comment above about spacing.

const email_field = document.querySelector('#user_email');
if (!email_field.checkValidity()) {
$personalData.addClass( 'error' ).show();
resetLoadingMode();
return false;
} else {
personal_data.user_firstname = $('#first_name').val();
personal_data.user_lastname = $('#last_name').val();
personal_data.user_email = $(email_field).val();
}
}
var $extensionsPermission = $( '#fs_permission_extensions .fs-switch' ),
isExtensionsTrackingAllowed = ( $extensionsPermission.length > 0 ) ?
$extensionsPermission.hasClass( 'fs-on' ) :
Expand Down Expand Up @@ -743,7 +788,8 @@ function updatePrimaryCtaText( actionType ) {
action : action,
security : security,
license_key: licenseKey,
module_id : '<?php echo $fs->get_id() ?>'
module_id : '<?php echo $fs->get_id() ?>',
...personal_data
};

if (
Expand Down Expand Up @@ -827,15 +873,17 @@ function updatePrimaryCtaText( actionType ) {
method : 'POST',
data : data,
success: function (result) {
var resultObj = $.parseJSON(result);
if (resultObj.success) {
// Redirect to the "Account" page and sync the license.
window.location.href = resultObj.next_page;
} else {
resetLoadingMode();

// Show error.
$('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>');
var resultObj = $.parseJSON(result);
if (resultObj.success) {
// Redirect to the "Account" page and sync the license.
window.location.href = resultObj.next_page;
} else {
resetLoadingMode();
// Show error.
$('.fs-content').prepend('<div class="fs-error">' + (resultObj.error.message ? resultObj.error.message : resultObj.error) + '</div>');
if (resultObj.error_code === 'empty_email') {
$('#fs_personal_data').show();
}
}
},
error: function () {
Expand Down Expand Up @@ -960,6 +1008,7 @@ function updatePrimaryCtaText( actionType ) {
//--------------------------------------------------------------------------------
var isMarketingAllowedByLicense = {},
$marketingOptin = $('#fs_marketing_optin'),
$personalData = $('#fs_personal_data')
previousLicenseKey = null;

if (requireLicenseKey) {
Expand Down Expand Up @@ -1034,11 +1083,12 @@ function updatePrimaryCtaText( actionType ) {

$marketingOptin.find( 'input' ).click(function() {
$marketingOptin.removeClass( 'error' );
$personalData.removeClass( 'error' );
});
}

//endregion
})(jQuery);
</script>
<?php
fs_require_once_template( 'api-connectivity-message-js.php' );
fs_require_once_template( 'api-connectivity-message-js.php' );
Loading