Skip to content

Commit debe923

Browse files
committed
Refactor README examples for Notices class to enhance clarity and translation support
- Remove outdated examples and consolidate notice usage into a single example - Update notice ID and message to include translation-ready strings - Simplify documentation for adding notices using the admin_notices hook This improves the usability of the README for developers implementing admin notifications.
1 parent 9669654 commit debe923

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

readme.md

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -120,40 +120,15 @@ You can add notices statically from anywhere in your code before the `admin_noti
120120
```php
121121
use EasyDigitalDownloads\Updater\Admin\Notices;
122122

123-
// Basic usage - can be called from anywhere
124-
Notices::add( array(
125-
'id' => 'my-notice-id',
126-
'type' => 'success', // 'success', 'error', 'warning', 'info'
127-
'message' => 'Your license has been activated successfully!',
128-
'classes' => array( 'my-custom-class' ) // Optional additional CSS classes
129-
) );
130-
131-
// Example: Add notice from an early hook (this works)
132-
add_action( 'admin_init', function() {
133-
Notices::add( array(
134-
'id' => 'early-notice',
135-
'type' => 'info',
136-
'message' => 'Notice added during admin_init',
137-
) );
138-
} );
139-
140-
// Example: Add notice from admin_notices at lower priority (this works)
123+
// Add notice using admin_notices hook with translation-ready strings
141124
add_action( 'admin_notices', function() {
142125
Notices::add( array(
143-
'id' => 'priority-notice',
144-
'type' => 'warning',
145-
'message' => 'Notice added at default priority (10)',
126+
'id' => 'my-plugin-license-activated',
127+
'type' => 'success', // 'success', 'error', 'warning', 'info'
128+
'message' => __( 'Your license has been activated successfully!', 'my-plugin-textdomain' ),
129+
'classes' => array( 'my-custom-class' ) // Optional additional CSS classes
146130
) );
147131
}, 10 ); // Priority 10 runs before our render at priority 100
148-
149-
// This would NOT work - priority 200 runs after our render at priority 100
150-
add_action( 'admin_notices', function() {
151-
Notices::add( array(
152-
'id' => 'too-late-notice',
153-
'type' => 'error',
154-
'message' => 'This notice will not display!',
155-
) );
156-
}, 200 ); // Too late - render already happened at priority 100
157132
```
158133

159134
The notices will be automatically displayed on admin pages. The registry takes care of instantiating the `Notices` class, and the `Notices` class handles rendering and styling according to WordPress admin notice standards.

0 commit comments

Comments
 (0)