Skip to content
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
65 changes: 36 additions & 29 deletions assets/js/thank-you.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global wu_thank_you */
/* eslint-disable no-console */
(() => {
"use strict";
const TransitionText = (element, has_icon = false) => {
Expand Down Expand Up @@ -65,24 +67,29 @@
document.querySelectorAll(".wu-resend-verification-email").forEach((element) => element.addEventListener("click", async (event) => {
event.preventDefault();
const transitional_text = TransitionText(element, true).text(wu_thank_you.i18n.resending_verification_email, [ "wu-text-gray-400" ]);
const request = await fetch(
wu_thank_you.ajaxurl,
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
action: "wu_resend_verification_email",
_ajax_nonce: wu_thank_you.resend_verification_email_nonce
}),
try {
const request = await fetch(
wu_thank_you.ajaxurl,
{
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
action: "wu_resend_verification_email",
_ajax_nonce: wu_thank_you.resend_verification_email_nonce
}),
}
);
const response = await request.json();
if (response.success) {
transitional_text.text(wu_thank_you.i18n.email_sent, [ "wu-text-green-700" ], true).done();
} else {
transitional_text.text(response?.data?.[ 0 ]?.message || wu_thank_you.i18n.request_failed, [ "wu-text-red-600" ], true).done();
}
);
const response = await request.json();
if (response.success) {
transitional_text.text(wu_thank_you.i18n.email_sent, [ "wu-text-green-700" ], true).done();
} else {
transitional_text.text(response.data[ 0 ].message, [ "wu-text-red-600" ], true).done();
} catch (e) {
console.error("Resend verification email failed:", e);
transitional_text.text(wu_thank_you.i18n.request_failed, [ "wu-text-red-600" ], true).done();
}
}));
if (! document.getElementById("wu-sites")) {
Expand Down Expand Up @@ -120,16 +127,16 @@
},
mounted() {
/*
* Kick wp-cron immediately to start the async site creation ASAP.
*
* Always start polling regardless of has_pending_site. The page may
* load before the pending site is created (during Stripe webhook
* delay). Without polling, the user stares at "Creating" forever
* even after the site is ready.
*
* @since 2.4.13
*/
fetch("/wp-cron.php?doing_wp_cron");
* Kick wp-cron immediately to start the async site creation ASAP.
*
* Always start polling regardless of has_pending_site. The page may
* load before the pending site is created (during Stripe webhook
* delay). Without polling, the user stares at "Creating" forever
* even after the site is ready.
*
* @since 2.4.13
*/
fetch(wu_thank_you.wp_cron_url);
this.check_site_created();
},
methods: {
Expand Down Expand Up @@ -169,10 +176,10 @@
this.running_count++;
// Kick cron every 3 polls to keep Action Scheduler active during site creation.
if (this.running_count % 3 === 0) {
fetch("/wp-cron.php?doing_wp_cron");
fetch(wu_thank_you.wp_cron_url);
}
if (this.running_count > 60) {
fetch("/wp-cron.php?doing_wp_cron");
fetch(wu_thank_you.wp_cron_url);
if (! this.is_post_redirect) {
// Use the _t cache-bust redirect (not location.reload) so the next
// page load sets is_post_redirect = true, preventing a second redirect
Expand Down
2 changes: 2 additions & 0 deletions inc/ui/class-thank-you-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ public function register_scripts() {
'has_pending_site' => $has_pending_site,
'next_queue' => wu_get_next_queue_run(),
'ajaxurl' => admin_url('admin-ajax.php'),
'wp_cron_url' => admin_url('admin-ajax.php?action=wu_wp_cron'),
'resend_verification_email_nonce' => wp_create_nonce('wu_resend_verification_email_nonce'),
'membership_hash' => $this->membership ? $this->membership->get_hash() : false,
'i18n' => [
'resending_verification_email' => __('Resending verification email...', 'ultimate-multisite'),
'email_sent' => __('Verification email sent!', 'ultimate-multisite'),
'request_failed' => __('Request failed. Please try again.', 'ultimate-multisite'),
],
]
);
Expand Down
Loading