Skip to content

Commit

Permalink
feat(reader-activation): prevent updating user email in my-account
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Jul 29, 2022
1 parent c806bfe commit 7d49db4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function init() {
add_action( 'init', [ __CLASS__, 'add_rewrite_endpoints' ] );
add_action( 'template_redirect', [ __CLASS__, 'handle_password_reset_request' ] );
add_action( 'template_redirect', [ __CLASS__, 'redirect_to_account_details' ] );
add_action( 'template_redirect', [ __CLASS__, 'edit_account_prevent_email_update' ] );
add_filter( 'woocommerce_save_account_details_required_fields', [ __CLASS__, 'remove_required_fields' ] );
}

Expand Down Expand Up @@ -223,6 +224,21 @@ public static function wc_get_template( $template, $template_name ) {
}
return $template;
}

/**
* Prevent updating email via Edit Account page.
*/
public static function edit_account_prevent_email_update() {
if (
! Donations::is_platform_stripe()
|| empty( $_POST['account_email'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
|| ! \is_user_logged_in()
|| ! Reader_Activation::is_enabled()
) {
return;
}
$_POST['account_email'] = wp_get_current_user()->user_email;
}
}

WooCommerce_My_Account::init();
8 changes: 8 additions & 0 deletions includes/reader-revenue/my-account/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
}
}
}

.edit-account {
input {
&:disabled {
background-color: #f5f5f5;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="account_email"><?php esc_html_e( 'Email address', 'newspack' ); ?>&nbsp;<span class="required">*</span></label>
<input type="email" class="woocommerce-Input woocommerce-Input--email input-text" name="account_email" id="account_email" autocomplete="email" value="<?php echo esc_attr( $user->user_email ); ?>" />
<input type="email" disabled class="woocommerce-Input woocommerce-Input--email input-text" name="account_email" id="account_email" autocomplete="email" value="<?php echo esc_attr( $user->user_email ); ?>" />
</p>

<?php do_action( 'woocommerce_edit_account_form' ); ?>
Expand Down

0 comments on commit 7d49db4

Please sign in to comment.