PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.4.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.4.0
2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 All 65 releases
← All changes | assets/js/integration_settings.js +65 -3 1.10.6 → 2.4.0 View file →
@@ -25,9 +25,9 @@
25 25 var originalCursor = btn.style.cursor;
26 26
27 27 btn.disabled = true;
28 28 btn.style.cursor = "wait";
29 - btn.innerHTML = SUBSCRPT_SPINNER_SVG + "Installing…";
29 + btn.innerHTML = SUBSCRPT_SPINNER_SVG + (btn.dataset.busyLabel || wp.i18n.__("Installing…", "subscription"));
30 30
31 31 var data = new FormData();
32 32 data.append("action", "subscrpt_install_integration_plugin");
33 33 data.append("plugin_slug", slug);
@@ -46,9 +46,11 @@
46 46 btn.disabled = false;
47 47 btn.style.cursor = originalCursor;
48 48 btn.innerHTML = originalHTML;
49 49 // eslint-disable-next-line no-alert
50 - window.alert((result.data && result.data.message) || "Installation failed. Please try again.");
50 + window.alert(
51 + (result.data && result.data.message) || wp.i18n.__("Installation failed. Please try again.", "subscription"),
52 + );
51 53 }
52 54 })
53 55 .catch(function () {
54 56 btn.disabled = false;
@@ -54,9 +56,69 @@
54 56 btn.disabled = false;
55 57 btn.style.cursor = originalCursor;
56 58 btn.innerHTML = originalHTML;
57 59 // eslint-disable-next-line no-alert
58 - window.alert("Installation failed. Please try again.");
60 + window.alert(wp.i18n.__("Installation failed. Please try again.", "subscription"));
61 + });
62 +}
63 +
64 +/**
65 + * Links and buttons that cannot carry an inline handler — e.g. inside a settings field
66 + * description, which is passed through wp_kses_post() — declare the slug in
67 + * data-subscrpt-install-plugin instead.
68 + */
69 +document.addEventListener("click", function (event) {
70 + var btn = event.target.closest("[data-subscrpt-install-plugin]");
71 + if (!btn || btn.disabled) {
72 + return;
73 + }
74 + event.preventDefault();
75 + subscrptInstallPlugin(btn, btn.dataset.subscrptInstallPlugin);
76 +});
77 +
78 +/**
79 + * Activate an already installed integration plugin from the integrations page.
80 + *
81 + * @param {HTMLButtonElement} btn The clicked button element.
82 + * @param {string} pluginFile The plugin basename, e.g. "tutor/tutor.php".
83 + */
84 +function subscrptActivatePlugin(btn, pluginFile) {
85 + var originalHTML = btn.innerHTML;
86 + var originalCursor = btn.style.cursor;
87 +
88 + btn.disabled = true;
89 + btn.style.cursor = "wait";
90 + btn.innerHTML = SUBSCRPT_SPINNER_SVG + "Activating…";
91 +
92 + var data = new FormData();
93 + data.append("action", "subscrpt_activate_integration_plugin");
94 + data.append("plugin_file", pluginFile);
95 + data.append("nonce", subscrptIntegrations.nonce);
96 +
97 + fetch(subscrptIntegrations.ajaxUrl, { method: "POST", body: data })
98 + .then(function (response) {
99 + return response.json();
100 + })
101 + .then(function (result) {
102 + if (result.success) {
103 + var url = new URL(window.location.href);
104 + url.searchParams.delete("subscrpt_installed");
105 + url.searchParams.set("subscrpt_activated", "1");
106 + window.location.href = url.toString();
107 + } else {
108 + btn.disabled = false;
109 + btn.style.cursor = originalCursor;
110 + btn.innerHTML = originalHTML;
111 + // eslint-disable-next-line no-alert
112 + window.alert((result.data && result.data.message) || "Activation failed. Please try again.");
113 + }
114 + })
115 + .catch(function () {
116 + btn.disabled = false;
117 + btn.style.cursor = originalCursor;
118 + btn.innerHTML = originalHTML;
119 + // eslint-disable-next-line no-alert
120 + window.alert("Activation failed. Please try again.");
59 121 });
60 122 }
61 123
62 124 function wpSubsInstallPaypalIntegration() {