Fix enabled-sources checkbox not persisting when all unchecked

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 <noreply@anthropic.com>
This commit is contained in:
peptiderepo
2026-04-20 12:18:59 +07:00
parent 4791e54821
commit 86ceea0da1
5 changed files with 26 additions and 4 deletions

View File

@@ -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

View File

@@ -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( '<input type="hidden" name="%s" value="" />', $id );
foreach ( ( $args['options'] ?? [] ) as $v => $label ) {
$is_checked = in_array( $v, $current, true );
$disabled = strpos( $label, 'coming soon' ) !== false ? ' disabled' : '';

View File

@@ -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();

View File

@@ -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' ];
}

View File

@@ -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__ ) );