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

feat(my-account): add email change feature flag #3758

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public static function init() {
\add_filter( 'wcs_my_account_redirect_to_single_subscription', [ __CLASS__, 'redirect_to_single_subscription' ] );
\add_filter( 'wc_memberships_members_area_my-memberships_actions', [ __CLASS__, 'hide_cancel_button_from_memberships_table' ] );
\add_filter( 'wc_memberships_my_memberships_column_names', [ __CLASS__, 'remove_next_bill_on' ], 21 );

}
}

Expand Down Expand Up @@ -624,6 +623,7 @@ public static function edit_account_prevent_email_update() {
empty( $_POST['account_email'] ) // phpcs:ignore WordPress.Security.NonceVerification.Missing
|| ! \is_user_logged_in()
|| ! Reader_Activation::is_enabled()
|| self::is_email_change_enabled()
) {
return;
}
Expand Down Expand Up @@ -762,6 +762,19 @@ public static function update_payment_methods_for_all_subs() {
'pending-cancel',
];
}

/**
* Whether email changes are enabled.
*/
public static function is_email_change_enabled() {
$is_enabled = defined( 'NEWSPACK_EMAIL_CHANGE_ENABLED' ) && NEWSPACK_EMAIL_CHANGE_ENABLED;
/**
* Filters whether or not to allow email changes in My Account.
*
* @param bool $enabled Whether or not to allow email changes.
*/
return \apply_filters( 'newspack_email_change_enabled', $is_enabled );
}
}

WooCommerce_My_Account::init();
11 changes: 8 additions & 3 deletions includes/reader-revenue/templates/myaccount-edit-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
$is_error = $_GET['is_error']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
}

$without_password = true === Reader_Activation::is_reader_without_password( $user );
$is_reader = true === Reader_Activation::is_user_reader( $user );
$without_password = true === Reader_Activation::is_reader_without_password( $user );
$is_reader = true === Reader_Activation::is_user_reader( $user );
$is_email_change_enabled = true === WooCommerce_My_Account::is_email_change_enabled();
?>

<?php
Expand Down Expand Up @@ -63,8 +64,12 @@ class="woocommerce-Input woocommerce-Input--text input-text"

<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide mt0">
<label for="account_email_display"><?php \esc_html_e( 'Email address', 'newspack-plugin' ); ?>
<input type="email" disabled class="woocommerce-Input woocommerce-Input--email input-text" name="account_email_display" id="account_email_display" autocomplete="email" value="<?php echo \esc_attr( $user->user_email ); ?>" />
<?php if ( $is_email_change_enabled ) : ?>
<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 ); ?>" />
<?php else : ?>
<input type="email" class="woocommerce-Input woocommerce-Input--email input-text" name="account_email_display" id="account_email_display" autocomplete="email" disabled value="<?php echo \esc_attr( $user->user_email ); ?>" />
<input type="hidden" class="woocommerce-Input woocommerce-Input--email input-text" name="account_email" id="account_email" autocomplete="email" value="<?php echo \esc_attr( $user->user_email ); ?>" />
<?php endif; ?>
</p>

<?php
Expand Down