fix(rest): build signin URLs from restUrl under plain permalinks
credits.js hardcoded siteUrl + /wp-json/aksrt/v1 which 404s when WP uses plain permalinks (?rest_route=...). Prefer aksrtData.restUrl/apiUrl and harden header-userbox path join for the same case.
This commit is contained in:
+20
-7
@@ -11,17 +11,30 @@
|
||||
'use strict';
|
||||
|
||||
var aksrt = window.aksrtData;
|
||||
if (!aksrt || !aksrt.siteUrl) {
|
||||
if (!aksrt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 协议修正:页面是 HTTPS 但 siteUrl 是 HTTP 时,强制使用 HTTPS(避免混合内容拦截)
|
||||
var siteUrl = aksrt.siteUrl;
|
||||
if (window.location.protocol === 'https:' && siteUrl.substring(0, 5) === 'http:') {
|
||||
siteUrl = 'https:' + siteUrl.substring(5);
|
||||
// Prefer restUrl/apiUrl from wp_localize (handles plain permalinks:
|
||||
// /?rest_route=/aksrt/v1/...). Never hardcode /wp-json/ under siteUrl.
|
||||
var REST = '';
|
||||
if (aksrt.restUrl) {
|
||||
REST = String(aksrt.restUrl).replace(/\/?$/, '');
|
||||
} else if (aksrt.apiUrl) {
|
||||
REST = String(aksrt.apiUrl).replace(/\/?$/, '');
|
||||
} else if (aksrt.siteUrl) {
|
||||
var siteUrl = String(aksrt.siteUrl);
|
||||
if (window.location.protocol === 'https:' && siteUrl.substring(0, 5) === 'http:') {
|
||||
siteUrl = 'https:' + siteUrl.substring(5);
|
||||
}
|
||||
REST = siteUrl.replace(/\/$/, '') + '/wp-json/aksrt/v1';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// Force HTTPS if page is HTTPS (mixed content).
|
||||
if (window.location.protocol === 'https:' && REST.substring(0, 5) === 'http:') {
|
||||
REST = 'https:' + REST.substring(5);
|
||||
}
|
||||
|
||||
var REST = siteUrl.replace(/\/$/, '') + '/wp-json/aksrt/v1';
|
||||
var NONCE_HEADER = aksrt.restNonce ? { 'X-WP-Nonce': aksrt.restNonce } : (aksrt.nonce ? { 'X-WP-Nonce': aksrt.nonce } : {});
|
||||
|
||||
function api(path, options) {
|
||||
|
||||
Reference in New Issue
Block a user