From 14e427015888e29d7a639f8274928726017fd304 Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Sat, 18 Apr 2026 10:00:48 +0700 Subject: [PATCH] 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 --- assets/js/admin.js | 20 ++++++++++++++++++++ prautoblogger.php | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 5e8e247..5ca8e42 100755 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -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); + } + } }); /* diff --git a/prautoblogger.php b/prautoblogger.php index 5aca883..5c6de94 100644 --- a/prautoblogger.php +++ b/prautoblogger.php @@ -8,7 +8,7 @@ declare(strict_types=1); * Plugin Name: PRAutoBlogger * Plugin URI: https://peptiderepo.com/prautoblogger * Description: Monitors social media for trending topics, generates SEO-friendly blog posts using AI, and publishes them on a daily schedule with full cost tracking and self-improvement metrics. - * Version: 0.2.5 + * Version: 0.2.6 * Requires at least: 6.0 * Requires PHP: 7.4 * Author: PeptideRepo @@ -35,7 +35,7 @@ if ( ! defined( 'ABSPATH' ) ) { | and limits without magic strings. */ -define( 'PRAUTOBLOGGER_VERSION', '0.2.5' ); +define( 'PRAUTOBLOGGER_VERSION', '0.2.6' ); define( 'PRAUTOBLOGGER_DB_VERSION', '1.1.0' ); define( 'PRAUTOBLOGGER_PLUGIN_FILE', __FILE__ ); define( 'PRAUTOBLOGGER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );