Guide for displaying admin notices in Klytos CMS. Use when showing success, error, warning, or info messages to admin users, implementing flash messages after form submissions, creating persistent warnings that survive page loads, adding conditional notices that auto-hide when conditions change, or handling notice dismissal via AJAX. Also trigger when working with the NoticeManager, transient notices, or the notice.before_render filter.
Guide for displaying admin notices in Klytos CMS. Use when showing success, error, warning, or info messages to admin users, implementing flash messages after form submissions, creating persistent warnings that survive page loads, adding conditional notices that auto-hide when conditions change, or handling notice dismissal via AJAX. Also trigger when working with the NoticeManager, transient notices, or the notice.before_render filter.
Klytos Admin Notices API
When to Use This Skill
Use this reference when you need to display messages to admin users. Klytos provides two types of notices:
Only show on this admin page (e.g., 'dashboard', 'settings'). Empty = all pages.
condition_hook
string
''
Filter hook name. Notice only renders when the filter returns true.
ads
bool
true
Whether the notice is advertising. true = advertising (default), false = system/non-advertising.
The ads Field (Advertising vs System Notices)
Every persistent notice has an ads field that defaults to true. This means any notice not explicitly marked as ads => false is considered advertising.
ads => true (default): Advertising notice. Can be hidden globally via Settings > Notices.
ads => false: System/non-advertising notice. Always visible regardless of the ads toggle.
Users can disable advertising notices in Settings > Notices > Show advertising notices. When disabled, only ads => false notices are rendered. Transient/flash notices are always shown regardless of this setting.
// Plugin advertising notice (default ads=true, can be hidden by user).klytos_add_persistent_notice( 'my-promo', 'Try our premium features!', 'info', true );
// System notice (always visible).klytos_add_persistent_notice( 'config-warning', 'Missing API key.', 'warning', true, [
'ads' => false,
] );
The condition_hook Pattern
This is the key innovation. A persistent notice declares a filter hook name. At render time, the Notice API calls klytos_apply_filters( $condition_hook, true ). If it returns false, the notice is silently skipped -- no code needs to delete it.
// Register a conditional persistent notice.klytos_add_persistent_notice( 'ssl-missing', 'Your site is not using HTTPS.', 'error', false, [
'condition_hook' => 'notice.condition.ssl_missing',
] );
// Register the condition filter.klytos_add_filter( 'notice.condition.ssl_missing', function ( bool$show ): bool {
return ! isset( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] !== 'on';
} );
// Notice auto-hides when HTTPS is enabled -- no code needs to remove it.
Idempotent
klytos_add_persistent_notice() is idempotent by ID. Calling it multiple times with the same ID updates the existing notice instead of creating duplicates. Safe to call on every page load.
Examples
// Simple persistent notice (all pages, dismissible).klytos_add_persistent_notice( 'welcome', 'Welcome to Klytos! Start by creating your first page.', 'info' );
// Page-specific, non-dismissible.klytos_add_persistent_notice( 'no-pages', 'No pages published yet.', 'warning', false, [
'context' => 'dashboard',
] );
// Conditional: only shows when a config value is missing.klytos_add_persistent_notice( 'missing-email', 'Please configure your email settings.', 'warning', true, [
'context' => 'settings',
'condition_hook' => 'notice.condition.missing_email',
] );
klytos_add_filter( 'notice.condition.missing_email', function ( bool$show ): bool {
$config = klytos_app()->getSiteConfig()->get();
returnempty( $config['email_from'] ?? '' );
} );
3. Dismissing Notices
Programmatically
klytos_dismiss_notice( string$id ): void
Dismisses a persistent notice for the current user session. The notice stays in storage but won't render for this user until the session expires.
Via AJAX (Automatic)
Dismissible notices render an X button. Clicking it:
Fades out the notice element with a CSS transition.
Sends a POST to /admin/api/notices.php with action=dismiss and the notice id.
The server stores the dismiss in the session.
No plugin code needed -- this is handled automatically.
Returns all notices that should be rendered on the current page. Handles transient, session flash, and persistent notices. Filters by context, condition hooks, and dismiss state.
5. Manager Access (Advanced)
For advanced use cases, access the NoticeManager directly:
$manager = klytos_app()->getNoticeManager();
// Create a persistent notice with full control.$manager->create( [
'id' => 'my-notice',
'message' => 'Custom notice text.',
'type' => 'warning',
'dismissible' => true,
'context' => 'dashboard',
'condition_hook' => 'notice.condition.my_custom',
'ads' => false, // System notice, always visible.
] );
// Delete a persistent notice from storage entirely.$manager->delete( 'my-notice' );
// List all persistent notices.$notices = $manager->list();
// Ensure a system notice exists (idempotent create/update).$manager->ensureSystemNotice( 'sys-check', [
'message' => 'System check warning.',
'type' => 'error',
'dismissible' => false,
] );
6. Hooks & Filters
Actions
Hook
Fired When
Arguments
notice.created
Persistent notice created
array $notice
notice.dismissed
Notice dismissed
string $id
notice.deleted
Persistent notice deleted
string $id
notice.render.before
Before rendering notices
array $notices
notice.render.after
After rendering notices
array $notices
Filters
Hook
Purpose
Arguments
notice.transient.add
Modify transient notice before queuing
array $notice
notice.before_render
Add/remove/reorder notices before render
array $notices, string $page
notice.render_html
Customize per-notice HTML output
string $html, array $notice
{condition_hook}
Control conditional persistent notices
bool $show
Example: Add a notice from a plugin hook
klytos_add_filter( 'notice.before_render', function ( array$notices, string$page ): array {
if ( $page === 'settings' ) {
$notices[] = [
'id' => 'plugin-tip',
'message' => 'Tip: Configure your social media links below.',
'type' => 'info',
'dismissible' => true,
'persistent' => false,
];
}
return$notices;
} );
7. CSS Classes
Notices use the existing Klytos alert component classes:
Class
Purpose
.alert
Base alert styling
.alert-success
Green (success tokens)
.alert-error
Red (error tokens)
.alert-warning
Amber (warning tokens)
.alert-info
Blue (info tokens)
.alert-dismissible
Flex layout with space for X btn
.alert-close
The X dismiss button
Colors come from --klytos-{type}-subtle (background), --klytos-{type}-text (text), defined in klytos-tokens.css.
8. AJAX Endpoint
URL: /admin/api/notices.php
Method
Action
Parameters
Description
GET
--
?page=
List renderable notices
POST
dismiss
id
Dismiss a persistent notice
POST
dismiss-all
--
Dismiss all dismissible notices
Requires authentication and CSRF token.
9. Settings > Notices Panel
The admin Settings page includes a Notices section where site owners can:
Toggle advertising notices: Checkbox "Show advertising notices" (stored in notices.show_ads site config). When unchecked, all notices with ads => true are hidden.
View all active notices: Table showing every persistent notice with ID, type, message, and ADS/System badge.
Dismiss All: Button to dismiss all dismissible persistent notices at once for the current session.
Site Config Key
// Read the ads toggle.$showAds = klytos_config( 'notices.show_ads' ); // default: true// Set programmatically.klytos_set_config( 'notices', ['show_ads' => false] );