arraypress / wp-register-notices
Declarative WordPress admin notices — dismissible, per-user, and shown after a redirect.
v1.0.0
2026-08-25 15:44 UTC
Requires
- php: >=8.3
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13.5
- wp-coding-standards/wpcs: ^3.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Declare a plugin's admin notices, including the ones that have to survive a redirect.
What it does
An admin notice is easy until it needs to appear after a save. Then it is a transient, or a query argument, or a flag in user meta — and a dismissal that has to be remembered per user, and a condition that decides whether it is shown at all.
This is the declaration. You describe the notices once; showing, dismissing and remembering are handled.
Features
- Declare a notice with its message, type and when it should appear
- Show one after a redirect, without inventing a transient for it
- Let a user dismiss a notice and have it stay dismissed, for that user
- Show a notice only while a condition holds — no API key set, say
- Bring a dismissed notice back, when whatever it warned about returns
- Keep notices out of screens they have nothing to do with
Installation
composer require arraypress/wp-register-notices
Quick start
add_action( 'admin_init', function () { register_admin_notices( 'myplugin', [ 'settings_saved' => [ 'message' => __( 'Settings saved.', 'my-plugin' ), 'type' => 'success', ], 'needs_api_key' => [ 'message' => __( 'Add an API key to start syncing.', 'my-plugin' ), 'type' => 'warning', 'persistent' => true, 'condition' => fn(): bool => ! get_option( 'myplugin_api_key' ), ], ] ); } );
Showing one after a save is the part that is usually fiddly:
wp_safe_redirect( admin_notice_url( 'settings_saved' ) ); exit;
Requirements
- PHP 8.3 or later
- WordPress 7.1 or later
License
GPL-2.0-or-later