Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
42 changes: 42 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,45 @@ 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.

### Initialization

First, initialize the notices system in your plugin (typically during `admin_init`):

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

// Initialize notices rendering (typically in your plugin's main file or during admin_init)
add_action( 'admin_init', function() {
new Notices();
} );
```

### Adding Notices

Once initialized, you can add notices statically from anywhere in your code:

```php
// Add a notice (static method)
Notices::add( array(
'id' => 'my-notice-id',
'type' => 'success', // 'success', 'error', 'warning', 'info'
'message' => 'Your license has been activated successfully!',
'classes' => array( 'my-custom-class' ) // Optional additional CSS classes
) );

// Example: Add notice from an action
add_action( 'some_action', function() {
Notices::add( array(
'id' => 'license-activated',
'type' => 'success',
'message' => 'License activated successfully!',
) );
} );
```

The notices will be automatically displayed on admin pages. The `Notices` class handles rendering and styling according to WordPress admin notice standards.
11 changes: 10 additions & 1 deletion src/Admin/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ class Notices {
*/
private $notices = array();

/**
* Static notices storage.
*
* @var array
*/
private static $static_notices = array();

/**
* Notices constructor.
*/
public function __construct() {
add_action( 'admin_notices', array( $this, 'render' ), 100 );
// Merge static notices into instance notices for rendering
$this->notices = array_merge( $this->notices, self::$static_notices );
}

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

$this->notices[ $args['id'] ] = array(
self::$static_notices[ $args['id'] ] = array(
'message' => $args['message'],
'classes' => $classes,
);
Expand Down