Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,27 @@ if ( file_exists( __DIR__ . '/vendor/easy-digital-downloads/edd-sl-sdk/edd-sl-sd
- `file` - The main plugin file. Not needed for themes.
- `type` - `plugin` or `theme`. Not needed for plugins.
- `weekly_check` - Optional: whether to make a weekly request to confirm the license status. Defaults to true.

## Admin Notices

The SDK includes a `Notices` class for displaying admin notices. The registry automatically handles instantiation, so you can use the static `add()` method directly.

### Adding Notices

You can add notices statically from anywhere in your code before the `admin_notices` hook fires at priority 100:

```php
use EasyDigitalDownloads\Updater\Admin\Notices;

// Add notice using admin_notices hook with translation-ready strings
add_action( 'admin_notices', function() {
Notices::add( array(
'id' => 'my-plugin-license-activated',
'type' => 'success', // 'success', 'error', 'warning', 'info'
'message' => __( 'Your license has been activated successfully!', 'my-plugin-textdomain' ),
'classes' => array( 'my-custom-class' ) // Optional additional CSS classes
) );
}, 10 ); // Priority 10 runs before our render at priority 100
```

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.
8 changes: 4 additions & 4 deletions src/Admin/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Notices {
*
* @var array
*/
private $notices = array();
private static $notices = array();

/**
* Notices constructor.
Expand Down Expand Up @@ -62,7 +62,7 @@ public static function add( array $args ) {
$classes = array_merge( $classes, $args['classes'] );
}

$this->notices[ $args['id'] ] = array(
self::$notices[ $args['id'] ] = array(
'message' => $args['message'],
'classes' => $classes,
);
Expand All @@ -72,11 +72,11 @@ public static function add( array $args ) {
* Render the notices.
*/
public function render() {
if ( empty( $this->notices ) ) {
if ( empty( self::$notices ) ) {
return;
}

foreach ( $this->notices as $id => $args ) {
foreach ( self::$notices as $id => $args ) {
?>
<div id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( implode( ' ', $args['classes'] ) ); ?>">
<p><?php echo wp_kses_post( $args['message'] ); ?></p>
Expand Down