From 62273eb3bd90dfd6ab56845ddd3ba7d8120568db Mon Sep 17 00:00:00 2001 From: Joel James Date: Thu, 18 Jul 2019 19:34:22 +0530 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=91=8C=20Added=20transient=20name=20t?= =?UTF-8?q?o=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wp-flash-notices.php | 71 ++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/wp-flash-notices.php b/wp-flash-notices.php index eb48342..4ef083b 100755 --- a/wp-flash-notices.php +++ b/wp-flash-notices.php @@ -106,11 +106,13 @@ class WP_Flash_Notices { /** * Filter hook to modify notice item before adding to queue. * - * @param array $notice Notice item. + * @param string $key Notice key. + * @param array $notice Notice item. + * @param string $transient Transient name to identify the plugin. * * @since 1.0.0 */ - apply_filters( 'wp_flash_notices_notice_item', $notice ); + apply_filters( 'wp_flash_notices_notice_item', $key, $notice, $this->transient ); // Multisite network admin notices. if ( is_multisite() && $network ) { @@ -126,14 +128,16 @@ class WP_Flash_Notices { * Note: The notice item is not yet added to the transient when this * action hook is fired. * - * @param array $notice Notice item inserted. - * @param array $notices Current notice queue. - * @param array $network_notices Current network notices queue. + * @param array $notice Notice item inserted. + * @param string $transient Transient name to identify the plugin. + * @param array $notices Current notice queue. + * @param array $network_notices Current network notices queue. * * @since 1.0.0 */ do_action( 'wp_flash_notices_after_queue_insert', $notice, + $this->transient, $this->notices, $this->network_notices ); @@ -163,12 +167,14 @@ class WP_Flash_Notices { /** * Action hook fired after saving queued notices to transient. * - * @param array $notices Notice queue. - * @param array $network_notices Network notices queue. + * @param string $transient Transient name to identify the plugin. + * @param array $notices Notice queue. + * @param array $network_notices Network notices queue. * * @since 1.0.0 */ do_action( 'wp_flash_notices_after_save', + $this->transient, $this->notices, $this->network_notices ); @@ -193,13 +199,19 @@ class WP_Flash_Notices { /** * Filter hook to modify the notice item. * - * @param array $notice Current notice. - * @param array $notices Notice list. - * @param bool $network Is network notice?. + * @param array $notice Current notice. + * @param string $transient Transient name to identify the plugin. + * @param array $notices Notice list. + * @param bool $network Is network notice?. * * @since 1.0.0 */ - return apply_filters( 'wp_flash_notices_get', $notice, $notices, $network ); + return apply_filters( 'wp_flash_notices_get', + $notice, + $this->transient, + $notices, + $network + ); } /** @@ -223,12 +235,17 @@ class WP_Flash_Notices { /** * Filter hook to modify the fetched notices array. * - * @param array $notices Notice list. - * @param bool $network Is network notice?. + * @param string $transient Transient name to identify the plugin. + * @param array $notices Notice list. + * @param bool $network Is network notice?. * * @since 1.0.0 */ - return apply_filters( 'wp_flash_notices_fetch', $notices, $network ); + return apply_filters( 'wp_flash_notices_fetch', + $this->transient, + $notices, + $network + ); } /** @@ -253,11 +270,12 @@ class WP_Flash_Notices { /** * Action hook fired after clearing notices from transient. * - * @param bool $network Network notice?. + * @param string $transient Transient name to identify the plugin. + * @param bool $network Network notice?. * * @since 1.0.0 */ - do_action( 'wp_flash_notices_after_clear', $network ); + do_action( 'wp_flash_notices_after_clear', $this->transient, $network ); } /** @@ -278,11 +296,12 @@ class WP_Flash_Notices { /** * Filter hook to disable auto rendering of admin notices. * - * @param bool $enable Should render. + * @param bool $enable Should render. + * @param string $transient Transient name to identify the plugin. * * @since 1.0.0 */ - if ( apply_filters( 'wp_flash_notices_auto_render', true ) ) { + if ( apply_filters( 'wp_flash_notices_auto_render', true, $this->transient ) ) { $network = is_network_admin(); // Get all notices. @@ -316,12 +335,17 @@ class WP_Flash_Notices { * * We are using this hook to clear all notices after rendering. * - * @param array $notices Notices array. - * @param bool $network Is network admin?. + * @param string $transient Transient name to identify the plugin. + * @param array $notices Notices array. + * @param bool $network Is network admin?. * * @since 1.0.0 */ - do_action( 'wp_flash_notices_after_render', $notices, $network ); + do_action( 'wp_flash_notices_after_render', + $this->transient, + $notices, + $network + ); } } @@ -345,11 +369,12 @@ class WP_Flash_Notices { * notices using `clear` method. Otherwise notices will be there * and there no point in using this library anymore. * - * @param bool $enable Should clear automatically after render?. + * @param bool $enable Should clear automatically after render?. + * @param string $transient Transient name to identify the plugin. * * @since 1.0.0 */ - if ( apply_filters( 'wp_flash_notices_auto_clear', true ) ) { + if ( apply_filters( 'wp_flash_notices_auto_clear', true, $this->transient ) ) { // Clear all notices. $this->clear( $network ); } From 07098f3a5604fc9965bddba61a08701936da8116 Mon Sep 17 00:00:00 2001 From: Joel James Date: Thu, 25 Jul 2019 18:34:17 +0530 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=A6=20=20Releasing=201.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + wp-flash-notices.php | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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..1a85a45 100755 --- a/wp-flash-notices.php +++ b/wp-flash-notices.php @@ -64,10 +64,24 @@ 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( 'network_admin_notices', [ $this, 'render' ] ); From 4eb163f91fac18d1fcbfc62738609dfc77965fc1 Mon Sep 17 00:00:00 2001 From: Mostafa Soufi Date: Wed, 12 May 2021 12:10:46 +0300 Subject: [PATCH 3/6] Fix fetching notices by passing the correct value --- wp-flash-notices.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-flash-notices.php b/wp-flash-notices.php index 1a85a45..6b3dde9 100755 --- a/wp-flash-notices.php +++ b/wp-flash-notices.php @@ -249,15 +249,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 ); } From 8bb8a34a4f8ba705f075e21b9238da1aa12c8b45 Mon Sep 17 00:00:00 2001 From: Mostafa Soufi Date: Fri, 14 May 2021 12:07:13 +0300 Subject: [PATCH 4/6] Support frontend hook --- README.md | 8 ++++++++ wp-flash-notices.php | 1 + 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index e50b7d9..22624e3 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 ); +``` + + +### 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'); ``` \ No newline at end of file diff --git a/wp-flash-notices.php b/wp-flash-notices.php index 6b3dde9..1ecc4b8 100755 --- a/wp-flash-notices.php +++ b/wp-flash-notices.php @@ -84,6 +84,7 @@ class WP_Flash_Notices { // 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. From 5f73e11803841b6da49dd9825e51fb71aa02625e Mon Sep 17 00:00:00 2001 From: Joel James Date: Fri, 14 May 2021 14:56:09 +0530 Subject: [PATCH 5/6] Update wp-flash-notices.php --- wp-flash-notices.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-flash-notices.php b/wp-flash-notices.php index 1ecc4b8..8530a0d 100755 --- a/wp-flash-notices.php +++ b/wp-flash-notices.php @@ -251,7 +251,7 @@ class WP_Flash_Notices { * Filter hook to modify the fetched notices array. * * @param array $notices Notice list. - * @param string $transient Transient name to identify the plugin. + * @param string $transient Transient name to identify the plugin. * @param bool $network Is network notice?. * * @since 1.0.0 @@ -394,4 +394,4 @@ class WP_Flash_Notices { $this->clear( $network ); } } -} \ No newline at end of file +} From d3769c722ff5d8e8eee48ced7d9ca27c6b565473 Mon Sep 17 00:00:00 2001 From: Joel James Date: Fri, 14 May 2021 14:56:44 +0530 Subject: [PATCH 6/6] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 22624e3..2d6940c 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,9 @@ $notices->add( 'custom-success', 'This is a custom dismissible notice.', 'succes ``` -### Frontend compatibility +### 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'); -``` \ No newline at end of file +do_action( 'front_notices' ); +```