Skip to content

fix(settings): keep wp_stream option autoload explicit#1936

Open
faisalahammad wants to merge 1 commit into
xwp:developfrom
faisalahammad:fix/1482-wp-stream-autoload-explicit
Open

fix(settings): keep wp_stream option autoload explicit#1936
faisalahammad wants to merge 1 commit into
xwp:developfrom
faisalahammad:fix/1482-wp-stream-autoload-explicit

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

The wp_stream settings option is loaded on every request (Plugin::initSettings::__constructget_options) for exclude rules, logging gates, and role access. Autoload must stay on; turning it off without lazy-loading would add a get_option query on every page load.

This change makes that intent explicit on write paths and repairs any install whose row was flipped to no-autoload.

Fixes #1482

Changes

classes/class-settings.php

Before:

$result = update_option( $this->option_key, $options );

register_setting(
    $this->option_key,
    $this->option_key,
    array( $this, 'sanitize_settings' )
);

After:

// Autoload on purpose: Settings loads this option on every request ...
$result = update_option( $this->option_key, $options, true );

register_setting(
    $this->option_key,
    $this->option_key,
    array(
        'type'              => 'array',
        'sanitize_callback' => array( $this, 'sanitize_settings' ),
        'autoload'          => true,
    )
);

// ensure_option_autoload() on admin_init repairs stray no-autoload rows
// via wp_set_option_autoload() when available (WP 6.4+).

Why: New writes and Settings API saves keep autoload on. A one-shot admin repair covers existing installs that somehow ended up with autoload off. Network settings (wp_stream_network / sitemeta) are untouched.

tests/phpunit/test-class-settings.php

Why: Cover the write path, no→yes repair, idempotency, and network-key no-op.

Testing

Test 1: Fresh save keeps autoload on

  1. Stream → Settings, change a value, Save.
  2. wp db query "SELECT option_name, autoload FROM wp_options WHERE option_name = 'wp_stream'"
    Result: autoload is yes / on / auto-on.

Test 2: Repair path

  1. wp db query "UPDATE wp_options SET autoload = 'no' WHERE option_name = 'wp_stream'"
  2. Load any WP Admin page once.
  3. Re-check the query above.
    Result: autoload is back in the yes-family.

Test 3: Settings still work

  1. Add an exclude rule and trigger matching / non-matching events.
    Result: matching event not logged; non-matching event logged. No PHP notices.

Automated: composer lint, composer lint-tests, PHPUnit Test_Settings (single-site + multisite) pass.

- Pass true on update_option when writing per-site settings
- Register setting with autoload true for the Settings API path
- Repair stray no-autoload rows on admin_init via wp_set_option_autoload
- Add unit tests for write path, repair, idempotency, and network no-op

Settings load on every request for exclude rules, logging gates, and
role access, so autoload stays on by design.

Fixes xwp#1482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revise the autoload value

1 participant