You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify Notices class by converting to single static property
- Remove hybrid storage system with separate $static_notices property
- Convert existing $notices property to static for cleaner implementation
- Eliminate merging logic from constructor
- Update add() and render() methods to use self::$notices directly
- Update README with comprehensive priority examples and clearer usage
- Registry instantiation makes manual initialization unnecessary
Fixes#23
Copy file name to clipboardExpand all lines: readme.md
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,42 +111,49 @@ if ( file_exists( __DIR__ . '/vendor/easy-digital-downloads/edd-sl-sdk/edd-sl-sd
111
111
112
112
## Admin Notices
113
113
114
-
The SDK includes a `Notices` class for displaying admin notices.
114
+
The SDK includes a `Notices` class for displaying admin notices. The registry automatically handles instantiation, so you can use the static `add()` method directly.
115
115
116
-
### Initialization
116
+
### Adding Notices
117
117
118
-
First, initialize the notices system in your plugin (typically during `admin_init`):
118
+
You can add notices statically from anywhere in your code before the `admin_notices` hook fires at priority 100:
119
119
120
120
```php
121
121
use EasyDigitalDownloads\Updater\Admin\Notices;
122
122
123
-
// Initialize notices rendering (typically in your plugin's main file or during admin_init)
124
-
add_action( 'admin_init', function() {
125
-
new Notices();
126
-
} );
127
-
```
128
-
129
-
### Adding Notices
130
-
131
-
Once initialized, you can add notices statically from anywhere in your code:
// Example: Add notice from an early hook (this works)
132
+
add_action( 'admin_init', function() {
144
133
Notices::add( array(
145
-
'id' => 'license-activated',
146
-
'type' => 'success',
147
-
'message' => 'License activated successfully!',
134
+
'id' => 'early-notice',
135
+
'type' => 'info',
136
+
'message' => 'Notice added during admin_init',
148
137
) );
149
138
} );
139
+
140
+
// Example: Add notice from admin_notices at lower priority (this works)
141
+
add_action( 'admin_notices', function() {
142
+
Notices::add( array(
143
+
'id' => 'priority-notice',
144
+
'type' => 'warning',
145
+
'message' => 'Notice added at default priority (10)',
146
+
) );
147
+
}, 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
150
157
```
151
158
152
-
The notices will be automatically displayed on admin pages. The `Notices` class handles rendering and styling according to WordPress admin notice standards.
159
+
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