| 1 |
<?php if (!defined('ABSPATH')) { |
| 2 |
exit; // Exit if accessed directly. |
| 3 |
} |
| 4 |
/** |
| 5 |
* @var string $message |
| 6 |
* @var bool $is_sent |
| 7 |
* @var bool $is_error |
| 8 |
* @var string $offer_email Address the account could confirm ('' when none) |
| 9 |
* @var string $offer_reason 'unverified' | 'diverged' | 'recovery' | '' |
| 10 |
* @var string $confirm_email Address a valid mailed link is about to confirm ('' when none) |
| 11 |
* @var string $token |
| 12 |
* @var string $action_url |
| 13 |
*/ |
| 14 |
?> |
| 15 |
<section class="fct-email-claim fct-alert" role="region" aria-label="<?php esc_attr_e('Confirm your email address', 'fluent-cart'); ?>"> |
| 16 |
<h2><?php esc_html_e('Confirm your email address', 'fluent-cart'); ?></h2> |
| 17 |
<?php if ($message): ?> |
| 18 |
<p role="<?php echo $is_error ? 'alert' : 'status'; ?>"><?php echo esc_html($message); ?></p> |
| 19 |
<?php endif; ?> |
| 20 |
|
| 21 |
<?php if ($token && $confirm_email): ?> |
| 22 |
<p> |
| 23 |
<?php |
| 24 |
// translators: %1$s is the email address being confirmed |
| 25 |
printf(esc_html__('Confirm %1$s as the email address for this account. Your contact email will be updated and any purchases made with it will appear here.', 'fluent-cart'), '<strong>' . esc_html($confirm_email) . '</strong>'); |
| 26 |
?> |
| 27 |
</p> |
| 28 |
<form method="post" action="<?php echo esc_url($action_url); ?>" data-auto-confirm> |
| 29 |
<?php wp_nonce_field(\FluentCart\App\Services\CustomerIdentity\EmailClaimPortal::NONCE_ACTION); ?> |
| 30 |
<input type="hidden" name="<?php echo esc_attr(\FluentCart\App\Services\CustomerIdentity\EmailClaimPortal::ACTION_FIELD); ?>" value="confirm"> |
| 31 |
<input type="hidden" name="<?php echo esc_attr(\FluentCart\App\Services\CustomerIdentity\EmailClaimService::QUERY_TOKEN); ?>" value="<?php echo esc_attr($token); ?>"> |
| 32 |
<button type="submit" class="fct-email-claim-button" data-loading-text="<?php esc_attr_e('Confirming…', 'fluent-cart'); ?>" aria-live="polite"><?php esc_html_e('Confirm email address', 'fluent-cart'); ?></button> |
| 33 |
</form> |
| 34 |
<?php elseif ($offer_email): ?> |
| 35 |
<p> |
| 36 |
<?php |
| 37 |
if ($offer_reason === 'unverified') { |
| 38 |
// translators: %1$s is the account email address. |
| 39 |
printf(esc_html__('Your email address %1$s is not verified yet. Please verify your email before you start using your customer portal.', 'fluent-cart'), '<strong>' . esc_html($offer_email) . '</strong>'); |
| 40 |
} elseif ($offer_reason === 'diverged') { |
| 41 |
// translators: %1$s is the account's email address |
| 42 |
printf(esc_html__('Your account and customer email addresses do not match. Confirm %1$s to access your customer portal and update your contact email.', 'fluent-cart'), '<strong>' . esc_html($offer_email) . '</strong>'); |
| 43 |
} else { |
| 44 |
// translators: %1$s is the account's email address |
| 45 |
printf(esc_html__('Purchases made with %1$s as a guest are not yet part of this account. Confirm the address to bring them in.', 'fluent-cart'), '<strong>' . esc_html($offer_email) . '</strong>'); |
| 46 |
} |
| 47 |
?> |
| 48 |
</p> |
| 49 |
<form method="post" action="<?php echo esc_url($action_url); ?>"> |
| 50 |
<?php wp_nonce_field(\FluentCart\App\Services\CustomerIdentity\EmailClaimPortal::NONCE_ACTION); ?> |
| 51 |
<input type="hidden" name="<?php echo esc_attr(\FluentCart\App\Services\CustomerIdentity\EmailClaimPortal::ACTION_FIELD); ?>" value="send"> |
| 52 |
<button type="submit" class="fct-email-claim-button" data-loading-text="<?php esc_attr_e('Sending…', 'fluent-cart'); ?>" aria-live="polite"><?php echo $is_sent ? esc_html__('Resend confirmation email', 'fluent-cart') : esc_html__('Send confirmation email', 'fluent-cart'); ?></button> |
| 53 |
</form> |
| 54 |
<?php endif; ?> |
| 55 |
<p><a href="<?php echo esc_url(wp_logout_url($action_url)); ?>"><?php esc_html_e('Log out', 'fluent-cart'); ?></a></p> |
| 56 |
</section> |
| 57 |
<script> |
| 58 |
(function () { |
| 59 |
const notice = document.currentScript.previousElementSibling; |
| 60 |
notice.querySelectorAll('form').forEach(function (form) { |
| 61 |
const button = form.querySelector('[data-loading-text]'); |
| 62 |
if (!button) { |
| 63 |
return; |
| 64 |
} |
| 65 |
const label = button.textContent; |
| 66 |
form.addEventListener('submit', function (event) { |
| 67 |
if (form.getAttribute('aria-busy') === 'true') { |
| 68 |
event.preventDefault(); |
| 69 |
return; |
| 70 |
} |
| 71 |
if (event.defaultPrevented) { |
| 72 |
return; |
| 73 |
} |
| 74 |
form.setAttribute('aria-busy', 'true'); |
| 75 |
button.disabled = true; |
| 76 |
button.textContent = button.dataset.loadingText; |
| 77 |
}); |
| 78 |
// Restore the form when the browser returns to it from its page cache. |
| 79 |
window.addEventListener('pageshow', function (event) { |
| 80 |
if (!event.persisted) { |
| 81 |
return; |
| 82 |
} |
| 83 |
form.removeAttribute('aria-busy'); |
| 84 |
button.disabled = false; |
| 85 |
button.textContent = label; |
| 86 |
}); |
| 87 |
// Only the server-validated claim form may confirm automatically. |
| 88 |
// Keep the button as a fallback when JavaScript is unavailable. |
| 89 |
if (form.hasAttribute('data-auto-confirm') && typeof form.requestSubmit === 'function') { |
| 90 |
form.requestSubmit(); |
| 91 |
} |
| 92 |
}); |
| 93 |
})(); |
| 94 |
</script> |
| 95 |
|