fix: preserve active tab after saving settings

The _wp_http_referer hidden field didn't include the tab parameter, so
WordPress redirected to the default (API Keys) tab after every save.
Now the JS syncs the referer with the active tab on both tab switch and
page load. Bumped to v0.2.6 to bust JS cache.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-18 10:00:48 +07:00
parent d886aee1d7
commit 14e4270158
2 changed files with 22 additions and 2 deletions

View File

@@ -36,6 +36,14 @@
url.searchParams.set('tab', tab);
window.history.replaceState({}, '', url);
}
// Update the _wp_http_referer so WordPress redirects back to this tab after save.
var $referer = $('#ab-settings-form input[name="_wp_http_referer"]');
if ($referer.length) {
var refUrl = new URL($referer.val(), window.location.origin);
refUrl.searchParams.set('tab', tab);
$referer.val(refUrl.pathname + refUrl.search);
}
});
/*
@@ -55,6 +63,18 @@
$notice.fadeOut(400, function () { $(this).remove(); });
}, 6000);
}
// On load, sync _wp_http_referer with the current tab so the first
// save without switching tabs still returns to the right place.
var currentTab = new URL(window.location).searchParams.get('tab');
if (currentTab) {
var $referer = $('#ab-settings-form input[name="_wp_http_referer"]');
if ($referer.length) {
var refUrl = new URL($referer.val(), window.location.origin);
refUrl.searchParams.set('tab', currentTab);
$referer.val(refUrl.pathname + refUrl.search);
}
}
});
/*