Skip to content

Commit

Permalink
Remove Username from Emails
Browse files Browse the repository at this point in the history
hide the username in emails which include a password or password reset link (like password reset or new account mail -> if password is to be generated automatically). This is an advise from Trusted Shops. Can be turned off in GZD email settings.
  • Loading branch information
dennisnissle committed Mar 31, 2017
1 parent c893bd2 commit 72d004e
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 291 deletions.
Binary file modified i18n/languages/woocommerce-germanized-de_DE.mo
Binary file not shown.
330 changes: 186 additions & 144 deletions i18n/languages/woocommerce-germanized-de_DE.po

Large diffs are not rendered by default.

Binary file modified i18n/languages/woocommerce-germanized-de_DE_formal.mo
Binary file not shown.
329 changes: 185 additions & 144 deletions i18n/languages/woocommerce-germanized-de_DE_formal.po

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions includes/admin/settings/class-wc-gzd-settings-germanized.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,15 @@ public function get_email_settings() {

$settings = array_merge( $settings, array(

array(
'title' => __( 'Hide Username', 'woocommerce-germanized' ),
'desc' => __( 'Hide username from email content if password or password reset link is embedded.', 'woocommerce-germanized' ),
'desc_tip' => __( 'Trusted Shops advises to not show the username together with an account password or password reset link. This option hides (or masks) the username in those specific cases.', 'woocommerce-germanized' ),
'id' => 'woocommerce_gzd_hide_username_with_password',
'default' => 'yes',
'type' => 'checkbox',
),

array( 'type' => 'sectionend', 'id' => 'email_options' ),

array( 'title' => __( 'Email Attachment Options', 'woocommerce-germanized' ), 'type' => 'title', 'id' => 'email_attachment_options', 'desc' => '<div class="notice inline notice-warning"><p>' . sprintf( __( 'Want to attach automatically generated PDF files to emails instead of plain text? %sUpgrade to %spro%s%s', 'woocommerce-germanized' ), '<a style="margin-left: 1em" href="https://vendidero.de/woocommerce-germanized" class="button">', '<span class="wc-gzd-pro">', '</span>', '</a>' ) . '</p></div>' ),
Expand Down
45 changes: 44 additions & 1 deletion includes/class-wc-gzd-emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,57 @@ public function __construct() {

// Change email template path if is germanized email template
add_filter( 'woocommerce_template_directory', array( $this, 'set_woocommerce_template_dir' ), 10, 2 );

// Map partially refunded order mail template to correct email instance
add_filter( 'woocommerce_gzd_email_template_id_comparison', array( $this, 'check_for_partial_refund_mail' ), 10, 3 );
// Hide username if an email contains a password or password reset link (TS advises to do so)
if ( 'yes' === get_option( 'woocommerce_gzd_hide_username_with_password' ) )
add_filter( 'woocommerce_before_template_part', array( $this, 'maybe_set_gettext_username_filter' ), 10, 4 );

if ( is_admin() )
$this->admin_hooks();
}

public function maybe_set_gettext_username_filter( $template_name, $template_path, $located, $args ) {

$templates = array(
'emails/customer-reset-password.php' => 'maybe_hide_username_password_reset',
'emails/plain/customer-reset-password.php' => 'maybe_hide_username_password_reset',
);

// If the password is generated automatically and sent by email, hide the username
if ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) ) {
$templates = array_merge( $templates, array(
'emails/customer-new-account.php' => 'maybe_hide_username_new_account',
'emails/plain/customer-new-account.php' => 'maybe_hide_username_new_account'
) );
}

if ( isset( $templates[ $template_name ] ) ) {
add_filter( 'gettext', array( $this, $templates[ $template_name ] ), 10, 3 );
}
}

public function maybe_hide_username_password_reset( $translated, $original, $domain ) {
if ( 'woocommerce' === $domain ) {
if ( 'Someone requested that the password be reset for the following account:' === $original ) {
return __( 'Someone requested a password reset for your account.', 'woocommerce-germanized' );
} else if ( 'Username: %s' === $original ) {
remove_filter( 'gettext', array( $this, 'maybe_hide_username_password_reset' ), 10, 3 );
return '';
}
}

return $translated;
}

public function maybe_hide_username_new_account( $translated, $original, $domain ) {
if ( 'woocommerce' === $domain && 'Thanks for creating an account on %s. Your username is <strong>%s</strong>' === $original ) {
remove_filter( 'gettext', array( $this, 'maybe_hide_username_new_account' ), 10, 3 );
return __( 'Thanks for creating an account on %s.', 'woocommerce-germanized' );
}
return $translated;
}

public function check_for_partial_refund_mail( $result, $mail_id, $tpl ) {

if ( $mail_id === 'customer_partially_refunded_order' && $tpl === 'customer_refunded_order' )
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Bug reports may be filed via our [GitHub repository](https://github.com/vendider
* Fix - Small Business VAT total tax removal (as Trusted Shops advised)
* Fix - FontAwesome Update to latest version
* Fix - Use frontend options filter for admin billing_title field
* Fix - By default remove username from password reset, new account mail if password or reset link is included (Trusted Shops advised)

= 1.8.6 =
* Fix - plugin_locale filter in WC_GZD_Install
Expand Down
2 changes: 1 addition & 1 deletion templates/emails/customer-new-account-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<p><?php printf( __( "Thanks for creating an account on %s. Your username is %s. Please follow the activation link to activate your account:", 'woocommerce-germanized' ), esc_html( $blogname ), '<strong>' . esc_html( $user_login ) . '</strong>' ); ?></p>
<p><?php printf( __( "Thanks for creating an account on %s. Please follow the activation link to activate your account:", 'woocommerce-germanized' ), esc_html( $blogname ) ); ?></p>

<p><a class="wc-button button" href="<?php echo esc_attr( $user_activation_url );?>"><?php _e( 'Activate your account', 'woocommerce-germanized' );?></a></p>

Expand Down
2 changes: 1 addition & 1 deletion templates/emails/plain/customer-new-account-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

echo "= " . $email_heading . " =\n\n";

echo sprintf( __( "Thanks for creating an account on %s. Your username is %s. Please follow the activation link to activate your account:", 'woocommerce-germanized' ), esc_html( $blogname ), esc_html( $user_login ) ) . "\n\n";
echo sprintf( __( "Thanks for creating an account on %s. Please follow the activation link to activate your account:", 'woocommerce-germanized' ), esc_html( $blogname ) ) . "\n\n";

echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";

Expand Down

0 comments on commit 72d004e

Please sign in to comment.