A WordPress plugin that demonstrates how to use the @wordpress/notices store across all admin pages, not just the block editor. It provides a custom command to display sample notice messages anywhere in the WordPress admin.
- 🎯 Universal Notice System: Display WordPress notices on any admin page (dashboard, settings, etc.)
- 💬 Command Integration: Uses WordPress's command palette to trigger notices
- 🔔 Snackbar Notifications: Shows elegant snackbar-style notifications
- 🎨 Block Editor Compatible: Automatically detects and adapts to the block editor environment
This plugin solves a common challenge: the @wordpress/notices store works perfectly in the block editor, but doesn't render notifications on traditional admin pages. The plugin provides:
- A custom
<Notices />component that renders snackbar notifications from thecore/noticesstore - A command palette integration that triggers sample notices
- Smart detection to avoid duplicate notices in the block editor
-
Clone or copy this plugin to your WordPress plugins directory:
wp-content/plugins/notices-showcase/
-
Install dependencies:
npm install
-
Build the plugin:
npm run build
-
Activate the plugin in WordPress admin
- Open the WordPress command palette (typically
Cmd+KorCtrl+K) - Search for "Show Sample Notice"
- Press Enter to display the notification
The notice will appear as a snackbar at the bottom-left of the screen on any admin page.
You can dispatch notices from your own code anywhere in the WordPress admin:
import { dispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';
const { createSuccessNotice } = dispatch(noticesStore);
createSuccessNotice('Your custom message here', {
type: 'snackbar',
isDismissible: true,
explicitDismiss: true,
});- notices-showcase.php - Main plugin file, handles asset enqueueing
- src/index.js - Entry point, registers the command and renders components
- src/components/Notices.js - Core component that renders notices outside the block editor
- src/styles.css - Minimal styling for notice positioning
- package.json - Dependencies and build scripts
Start the development server with hot reloading:
npm startBuild for production:
npm run build- Uses
@wordpress/scriptsfor build configuration - Leverages
@wordpress/commandsfor command palette integration - Implements
@wordpress/datastores for notice management - Detects block editor context to prevent duplicate notices
- Fixed positioning at bottom-left with high z-index for visibility
- WordPress 5.9+
- Node.js and npm for building
This is a demonstration/showcase plugin for educational purposes.