From 86ceea0da1bc6cf775231f289295a489ee45330c Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Mon, 20 Apr 2026 12:18:59 +0700 Subject: [PATCH] Fix enabled-sources checkbox not persisting when all unchecked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Browser omits checkbox fields from POST when none are checked, so the prautoblogger_enabled_sources option retained its previous value (with Reddit). Added a hidden input to the checkboxes renderer so an empty value is always submitted. Also replaced the hardcoded "Collecting sources from Reddit…" pipeline status with a dynamic message reflecting actually-enabled sources. Bump 0.6.2 → 0.6.3. Co-Authored-By: Claude Opus 4.6 --- CHANGELOG.md | 11 +++++++++++ includes/admin/class-admin-page.php | 5 +++++ includes/core/class-pipeline-runner.php | 5 ++++- includes/core/class-source-collector.php | 5 ++++- prautoblogger.php | 4 ++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e94ca96..3760ae6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to PRAutoBlogger will be documented in this file. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project uses [Semantic Versioning](https://semver.org/). +## [0.6.3] — 2026-04-20 + +### Fixed +- **Unchecking all sources still used Reddit.** Browser omits checkbox fields + from POST when none are checked, so the `prautoblogger_enabled_sources` + option never updated. Added a hidden input so an empty value is always + submitted — unchecking all sources now correctly saves `[]`. +- **Pipeline status hardcoded "Reddit".** The "Collecting sources…" stage + message now reflects the actually-enabled sources instead of always + saying "Reddit". + ## [0.6.2] — 2026-04-20 ### Added diff --git a/includes/admin/class-admin-page.php b/includes/admin/class-admin-page.php index e9b850f..61881cb 100755 --- a/includes/admin/class-admin-page.php +++ b/includes/admin/class-admin-page.php @@ -158,6 +158,11 @@ class PRAutoBlogger_Admin_Page { case 'checkboxes': $current = json_decode( (string) $value, true ) ?: []; + // Hidden input ensures an empty value is POSTed when all boxes + // are unchecked — without this, the browser omits the field + // entirely, so WordPress never fires the sanitize callback and + // the old value persists in wp_options. + printf( '', $id ); foreach ( ( $args['options'] ?? [] ) as $v => $label ) { $is_checked = in_array( $v, $current, true ); $disabled = strpos( $label, 'coming soon' ) !== false ? ' disabled' : ''; diff --git a/includes/core/class-pipeline-runner.php b/includes/core/class-pipeline-runner.php index d888779..a1b575f 100755 --- a/includes/core/class-pipeline-runner.php +++ b/includes/core/class-pipeline-runner.php @@ -156,7 +156,10 @@ class PRAutoBlogger_Pipeline_Runner { private function orchestrate( PRAutoBlogger_Cost_Tracker $cost_tracker ): array { $target = absint( get_option( 'prautoblogger_daily_article_target', 1 ) ); - $this->broadcast_stage( __( 'Collecting sources from Reddit…', 'prautoblogger' ) ); + $enabled = json_decode( get_option( 'prautoblogger_enabled_sources', '["reddit"]' ), true ); + $source_labels = is_array( $enabled ) ? implode( ', ', $enabled ) : 'reddit'; + /* translators: %s is a comma-separated list of enabled source names, e.g. "reddit, llm_research". */ + $this->broadcast_stage( sprintf( __( 'Collecting sources from %s…', 'prautoblogger' ), $source_labels ) ); ( new PRAutoBlogger_Source_Collector() ) ->set_cost_tracker( $cost_tracker ) ->collect_from_all_sources(); diff --git a/includes/core/class-source-collector.php b/includes/core/class-source-collector.php index e615fc8..672446a 100755 --- a/includes/core/class-source-collector.php +++ b/includes/core/class-source-collector.php @@ -46,7 +46,10 @@ class PRAutoBlogger_Source_Collector { * @return int Total number of new records inserted. */ public function collect_from_all_sources(): int { - $enabled = json_decode( get_option( 'prautoblogger_enabled_sources', '["reddit"]' ), true ); + $raw = get_option( 'prautoblogger_enabled_sources', '["reddit"]' ); + $enabled = json_decode( (string) $raw, true ); + // Only fall back to reddit if the option is corrupt (non-JSON). + // An empty array '[]' is a valid choice — the user disabled all sources. if ( ! is_array( $enabled ) ) { $enabled = [ 'reddit' ]; } diff --git a/prautoblogger.php b/prautoblogger.php index 542020d..a2bef4b 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.6.2 + * Version: 0.6.3 * 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.6.2' ); +define( 'PRAUTOBLOGGER_VERSION', '0.6.3' ); define( 'PRAUTOBLOGGER_DB_VERSION', '1.1.0' ); define( 'PRAUTOBLOGGER_PLUGIN_FILE', __FILE__ ); define( 'PRAUTOBLOGGER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );