Skip to content

DataView: add notices config to suppress built-in save notices#44

Merged
zinigor merged 1 commit into
mainfrom
feature/configurable-notices
Jun 2, 2026
Merged

DataView: add notices config to suppress built-in save notices#44
zinigor merged 1 commit into
mainfrom
feature/configurable-notices

Conversation

@zinigor
Copy link
Copy Markdown
Contributor

@zinigor zinigor commented Jun 2, 2026

Problem

When a DataView page lives under the WordPress Settings menu, two "Settings saved." notices appear after every save:

  1. WordPress core — for pages under options-general.php, admin-header.php includes wp-admin/options-head.php, whose back-compat block fires for ?page=...&updated=1:

    if ( isset( $_GET['updated'] ) && isset( $_GET['page'] ) ) {
        // For back-compat with plugins that don't use the Settings API and just set updated=1 in the redirect.
        add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' );
    }

    This is the native notice with id="setting-error-settings_updated". DataView's redirect (updated=1) is exactly the case this path was written for.

  2. DataViewRequestRouter::render_notices() also fires on isset($_GET['updated']), echoing a second notice in the page body.

Both key on the same ?updated param, so a consumer can't suppress just one.

Change

Add a notices config option (bool, default true). When false, render_notices() returns early, letting the host environment own save notices:

new DataView([
    'slug'    => 'my_settings',
    'mode'    => 'singular',
    'storage' => 'option',
    'notices' => false, // host (WP Settings) renders the save notice
    'fields'  => [ /* ... */ ],
]);

Validation/error output (render_errors()) is a separate path and is unaffected.

Tests

4 new tests: config default (true), config override (false), and render_notices() output present-when-enabled / empty-when-disabled. Full suite: 274 passing, 1 pre-existing unrelated skip.

🤖 Generated with Claude Code

When a DataView page lives under the WordPress "Settings" menu, core's
options-head.php already renders a native "Settings saved." notice for the
`updated=1` redirect (its documented back-compat path for plugins that don't
use the Settings API). DataView's own render_notices() also fires on
`?updated`, so the notice appears twice — one plain notice and one with
id="setting-error-settings_updated".

Add a `notices` config option (default true). When false, render_notices()
returns early, letting the host environment own save notices. Error/validation
output (render_errors) is a separate path and unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zinigor zinigor self-assigned this Jun 2, 2026
@zinigor zinigor merged commit 4c53182 into main Jun 2, 2026
6 checks passed
@zinigor zinigor deleted the feature/configurable-notices branch June 2, 2026 16:50
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.

1 participant