diff --git a/README.md b/README.md index e50b7d9..2d6940c 100644 --- a/README.md +++ b/README.md @@ -80,4 +80,12 @@ By default all notices are shown within single site admin screens. If you have M ```php // Register new info notice to the queue. $notices->add( 'custom-success', 'This is a custom dismissible notice.', 'success', true, true ); -``` \ No newline at end of file +``` + + +### Frontend Compatibility +If you'd like to print the notices in the front-end, then use the below action to your template. + +```php +do_action( 'front_notices' ); +``` diff --git a/composer.json b/composer.json index dc3d94b..1cf3cfd 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "duckdev/wp-flash-notices", "description": "WordPress admin notices as flash notice using transient API to display after page reload.", + "version": "1.0.1", "license": "GPL-2.0+", "authors": [ { diff --git a/wp-flash-notices.php b/wp-flash-notices.php index 4ef083b..8530a0d 100755 --- a/wp-flash-notices.php +++ b/wp-flash-notices.php @@ -64,12 +64,27 @@ class WP_Flash_Notices { * * @since 1.0.0 */ - public function __construct( $transient = 'jj_wp_flash_notices' ) { + public function __construct( $transient = 'duckdev_wp_flash_notices' ) { // Make sure you set this unique, otherwise all notices will mixup. $this->transient = $transient; + /** + * Filter hook to add new notice types. + * + * @param array $types Notice types (default wp notices). + * @param string $transient Transient name. + * + * @since 1.0.1 + */ + $this->types = apply_filters( + 'wp_flash_notices_notice_types', + $this->types, + $this->transient + ); + // Render notices using WP action. add_action( 'admin_notices', [ $this, 'render' ] ); + add_action( 'front_notices', [ $this, 'render' ] ); add_action( 'network_admin_notices', [ $this, 'render' ] ); // Save all queued notices to transient. @@ -235,15 +250,15 @@ class WP_Flash_Notices { /** * Filter hook to modify the fetched notices array. * - * @param string $transient Transient name to identify the plugin. * @param array $notices Notice list. + * @param string $transient Transient name to identify the plugin. * @param bool $network Is network notice?. * * @since 1.0.0 */ return apply_filters( 'wp_flash_notices_fetch', - $this->transient, $notices, + $this->transient, $network ); } @@ -379,4 +394,4 @@ class WP_Flash_Notices { $this->clear( $network ); } } -} \ No newline at end of file +}