| @@ -2,13 +2,13 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Contains the class that is used to register and retrieve notices like errors, warnings, success messages, etc. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Notices |
| 6 | - * @author Eric Daams | |
| 7 | - * @copyright Copyright (c) 2019, Studio 164a | |
| 6 | + * @author David Bisset | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 9 | * @since 1.0.0 |
| 10 | - * @version 1.5.4 | |
| 10 | + * @version 1.6.37 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // Exit if accessed directly. |
| 14 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -214,8 +214,44 @@ | ||
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | 216 | public function get_notices() { |
| 217 | 217 | return $this->notices; |
| 218 | + } | |
| 219 | + | |
| 220 | + /** | |
| 221 | + * Remove a notice, based on the text of the notice. | |
| 222 | + * | |
| 223 | + * @since 1.6.37 | |
| 224 | + * | |
| 225 | + * @param string $text The text to search for. Regex supported. | |
| 226 | + * @return void | |
| 227 | + */ | |
| 228 | + public function clear_notice( $text ) { | |
| 229 | + foreach ( $this->notices as $type => $notices ) { | |
| 230 | + foreach ( $notices as $i => $notice_text ) { | |
| 231 | + if ( $notice_text === $text || preg_match( $text, $notice_text ) ) { | |
| 232 | + unset( $this->notices[ $type ][ $i ] ); | |
| 233 | + } | |
| 234 | + } | |
| 235 | + } | |
| 236 | + | |
| 237 | + charitable_get_session()->set( 'notices', $this->notices ); | |
| 238 | + } | |
| 239 | + | |
| 240 | + /** | |
| 241 | + * Clear notices by type. | |
| 242 | + * | |
| 243 | + * @since 1.6.37 | |
| 244 | + * | |
| 245 | + * @param string $type The type of notice. | |
| 246 | + * @return void | |
| 247 | + */ | |
| 248 | + public function clear_notices_by_type( $type ) { | |
| 249 | + if ( array_key_exists( $type, $this->notices ) ) { | |
| 250 | + $this->notices[ $type ] = array(); | |
| 251 | + } | |
| 252 | + | |
| 253 | + charitable_get_session()->set( 'notices', $this->notices ); | |
| 218 | 254 | } |
| 219 | 255 | |
| 220 | 256 | /** |
| 221 | 257 | * Clear out all existing notices. |