Skip to content

Commit ea7911b

Browse files
committed
fix(purge): harden missing-option fallback against filtered defaults
Settings::get_defaults() runs every field through wp_stream_settings_option_fields, which Network::get_network_admin_fields() uses to strip 'records_ttl' from the per-site option's defaults set. Outside any admin context (Action Scheduler, WP-CLI, system cron) the per-site option_key is in effect, so the filtered defaults never contained general_records_ttl. Without this fallback the auto-purge silently no-ops on every install where the option is missing, defeating the whole point of fixing this on bloated sites. Hardcoded fallback to 30 days (the documented default on the settings field itself) when general_records_ttl is absent after the merge. Caught by section 9 of the e2e plan. Refs XWPENG-28
1 parent 185fab8 commit ea7911b

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎classes/class-admin.php‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,22 @@ public function purge_scheduled_action() {
927927
$options = wp_parse_args( (array) get_option( 'wp_stream', array() ), $defaults );
928928
}
929929

930-
if ( ! empty( $options['general_keep_records_indefinitely'] ) || empty( $options['general_records_ttl'] ) ) {
930+
// Hardcoded TTL fallback. Settings::get_defaults() runs every settings
931+
// field through the `wp_stream_settings_option_fields` filter, which
932+
// Network::get_network_admin_fields() uses to strip the `records_ttl`
933+
// field from the per-site option's defaults set. When this callback runs
934+
// outside any admin context (Action Scheduler, WP-CLI, system cron), the
935+
// per-site option_key is in effect, so the filtered defaults array does
936+
// not contain general_records_ttl at all. Without this fallback the
937+
// purge silently no-ops on every install where the option is missing,
938+
// defeating the whole point of fixing this on bloated sites.
939+
// Mirrors the 30-day default declared on the settings field itself
940+
// (classes/class-settings.php, `records_ttl` field).
941+
if ( empty( $options['general_records_ttl'] ) ) {
942+
$options['general_records_ttl'] = 30;
943+
}
944+
945+
if ( ! empty( $options['general_keep_records_indefinitely'] ) ) {
931946
return;
932947
}
933948

0 commit comments

Comments
 (0)