Skip to content

Commit 53685f6

Browse files
Feature: adds support for alternate WP styles (#3)
1 parent 3b334af commit 53685f6

File tree

9 files changed

+194
-46
lines changed

9 files changed

+194
-46
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,58 @@ $notice = AdminNotices::show('my_notice', 'This is a notice')
366366
->urgency($urgency);
367367
```
368368

369+
### `alternateStyles($useAlternate)`, `standardStyles()`
370+
371+
**Default:** false
372+
373+
Sets whether the notice should use the alternate WordPress notice styles. **Only works when the
374+
wrapper is enabled.**
375+
376+
Parameters:
377+
378+
1. `bool $useAlternate = true` - Whether the notice should use the alternate WordPress notice
379+
styles
380+
381+
```php
382+
use StellarWP\AdminNotices\AdminNotices;
383+
384+
// Use the alternate WordPress notice styles
385+
$notice = AdminNotices::show('my_notice', 'This is a notice')
386+
->alternateStyles();
387+
388+
// Use the standard WordPress notice styles, only necessary to revert back
389+
$notice = AdminNotices::show('my_notice', 'This is a notice')
390+
->alternateStyles()
391+
->standardStyles();
392+
```
393+
394+
### `inline($inline)`, `notInline()`
395+
396+
**Default:** false
397+
398+
Sets whether the notice should be displayed in the WP "inline" location, at the top of the admin
399+
page. **Only works when the wrapper is enabled.**
400+
401+
Parameters:
402+
403+
1. `bool $inline = true` - Whether the notice should be displayed inline
404+
405+
```php
406+
use StellarWP\AdminNotices\AdminNotices;
407+
408+
// Display the notice inline
409+
$notice = AdminNotices::show('my_notice', 'This is a notice')
410+
->inline();
411+
412+
// Display the notice in the standard location
413+
$notice = AdminNotices::show('my_notice', 'This is a notice')
414+
->inline(false);
415+
416+
// Also has an alias for readability
417+
$notice = AdminNotices::show('my_notice', 'This is a notice')
418+
->notInline();
419+
```
420+
369421
### `dismissible($dismissible)`, `notDismissible()`
370422

371423
**Default:** false

src/Actions/RenderAdminNotice.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ private function getWrapperClasses(AdminNotice $notice): string
5656
$classes[] = 'inline';
5757
}
5858

59+
if ($notice->usesAlternateStyles()) {
60+
$classes[] = 'notice-alt';
61+
}
62+
5963
return implode(' ', $classes);
6064
}
6165
}

src/AdminNotice.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class AdminNotice
6060
*/
6161
protected $urgency;
6262

63+
/**
64+
* @var bool
65+
*/
66+
protected $alternateStyles = false;
67+
6368
/**
6469
* @var bool
6570
*/
@@ -238,26 +243,80 @@ public function urgency($urgency): self
238243
return $this;
239244
}
240245

246+
/**
247+
* Alias for setting the urgency to info
248+
*
249+
* @since 1.1.0
250+
*/
241251
public function asInfo(): self
242252
{
243253
return $this->urgency(NoticeUrgency::info());
244254
}
245255

256+
/**
257+
* Alias for setting the urgency to success
258+
*
259+
* @since 1.1.0
260+
*/
246261
public function asSuccess(): self
247262
{
248263
return $this->urgency(NoticeUrgency::success());
249264
}
250265

266+
/**
267+
* Alias for setting the urgency to warning
268+
*
269+
* @since 1.1.0
270+
*/
251271
public function asWarning(): self
252272
{
253273
return $this->urgency(NoticeUrgency::warning());
254274
}
255275

276+
/**
277+
* Alias for setting the urgency to error
278+
*
279+
* @since 1.1.0
280+
*/
256281
public function asError(): self
257282
{
258283
return $this->urgency(NoticeUrgency::error());
259284
}
260285

286+
/**
287+
* Uses the alternate WP notice styles
288+
*
289+
* @unreleased
290+
*/
291+
public function alternateStyles(bool $altStyle = true): self
292+
{
293+
$this->alternateStyles = $altStyle;
294+
295+
return $this;
296+
}
297+
298+
/**
299+
* Uses the standard WP notice styles
300+
*
301+
* @unreleased
302+
*/
303+
public function standardStyles(): self
304+
{
305+
$this->alternateStyles = false;
306+
307+
return $this;
308+
}
309+
310+
/**
311+
* Returns whether the notice uses the alternate WP notice styles
312+
*
313+
* @unreleased
314+
*/
315+
public function usesAlternateStyles(): bool
316+
{
317+
return $this->alternateStyles;
318+
}
319+
261320
/**
262321
* Sets the notice to display without the standard WordPress wrapper
263322
*

tests/unit/Actions/DisplayNoticesInAdminTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DisplayNoticesInAdminTest extends TestCase
2121
protected $originalServer;
2222

2323
/**
24-
* @unreleased
24+
* @since 1.0.0
2525
*/
2626
protected function setUp(): void
2727
{
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
}
3131

3232
/**
33-
* @unreleased
33+
* @since 1.0.0
3434
*/
3535
protected function tearDown(): void
3636
{
@@ -39,7 +39,7 @@ protected function tearDown(): void
3939
}
4040

4141
/**
42-
* @unreleased
42+
* @since 1.0.0
4343
*/
4444
public function testShouldEchoNothingWithNoNotices(): void
4545
{
@@ -50,7 +50,7 @@ public function testShouldEchoNothingWithNoNotices(): void
5050
}
5151

5252
/**
53-
* @unreleased
53+
* @since 1.0.0
5454
*/
5555
public function testShouldAcceptMultipleNotices(): void
5656
{
@@ -66,7 +66,7 @@ public function testShouldAcceptMultipleNotices(): void
6666
* @covers ::passesDateLimits
6767
* @dataProvider passDateLimitsDataProvider
6868
*
69-
* @unreleased
69+
* @since 1.0.0
7070
*/
7171
public function testPassesDateLimits(AdminNotice $notice, bool $shouldPass): void
7272
{
@@ -104,7 +104,7 @@ public function passDateLimitsDataProvider(): array
104104
* @dataProvider passWhenCallbackDataProvider
105105
* @covers ::passesWhenCallback
106106
*
107-
* @unreleased
107+
* @since 1.0.0
108108
*/
109109
public function testPassesWhenCallback(AdminNotice $notice, bool $shouldPass): void
110110
{
@@ -120,7 +120,7 @@ public function testPassesWhenCallback(AdminNotice $notice, bool $shouldPass): v
120120
}
121121

122122
/**
123-
* @unreleased
123+
* @since 1.0.0
124124
*/
125125
public function passWhenCallbackDataProvider(): array
126126
{
@@ -145,7 +145,7 @@ public function passWhenCallbackDataProvider(): array
145145
* @dataProvider passUserCapabilitiesDataProvider
146146
* @covers ::passesUserCapabilities
147147
*
148-
* @unreleased
148+
* @since 1.0.0
149149
*/
150150
public function testPassesUserCapabilities(AdminNotice $notice, bool $shouldPass): void
151151
{
@@ -241,7 +241,7 @@ public function testShouldPassScreenConditionsWhenConditionMatchesWPScreen(): vo
241241
/**
242242
* Produces a simple mock with predictable output.
243243
*
244-
* @unreleased
244+
* @since 1.0.0
245245
*/
246246
private function getSimpleMockNotice($output): AdminNotice
247247
{

tests/unit/Actions/RenderAdminNoticeTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class RenderAdminNoticeTest extends TestCase
1010
{
1111
/**
12-
* @unreleased
12+
* @since 1.0.0
1313
*/
1414
public function testShouldRenderNoticeWithoutWrapper(): void
1515
{
@@ -25,7 +25,7 @@ public function testShouldRenderNoticeWithoutWrapper(): void
2525
/**
2626
* Tests the wrapper and that the default urgency is info
2727
*
28-
* @unreleased
28+
* @since 1.0.0
2929
*/
3030
public function testShouldRenderNoticeInWrapper(): void
3131
{
@@ -42,7 +42,7 @@ public function testShouldRenderNoticeInWrapper(): void
4242
}
4343

4444
/**
45-
* @unreleased
45+
* @since 1.0.0
4646
*/
4747
public function testShouldIncludeDismissibleClass(): void
4848
{
@@ -59,7 +59,7 @@ public function testShouldIncludeDismissibleClass(): void
5959
}
6060

6161
/**
62-
* @unreleased
62+
* @since 1.0.0
6363
*/
6464
public function testShouldIncludeAutoParagraphs(): void
6565
{
@@ -77,7 +77,7 @@ public function testShouldIncludeAutoParagraphs(): void
7777
}
7878

7979
/**
80-
* @unreleased
80+
* @since 1.0.0
8181
*/
8282
public function testShouldRenderCallbackOutput(): void
8383
{

0 commit comments

Comments
 (0)