diff --git a/readme.md b/readme.md index b7f6917..95498f1 100644 --- a/readme.md +++ b/readme.md @@ -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. diff --git a/src/Admin/Notices.php b/src/Admin/Notices.php index 2e147e9..1da0705 100644 --- a/src/Admin/Notices.php +++ b/src/Admin/Notices.php @@ -23,7 +23,7 @@ class Notices { * * @var array */ - private $notices = array(); + private static $notices = array(); /** * Notices constructor. @@ -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, ); @@ -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 ) { ?>