-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Notices and small bugfixes and improvements
- Loading branch information
1 parent
2e159d5
commit bda8448
Showing
5 changed files
with
75 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace Custom_PTT\Admin; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Notices Class | ||
* | ||
* This class is responsible for adding admin notices. | ||
* | ||
* @package Custom_PTT\Admin | ||
* @since 0.1.0-alpha | ||
*/ | ||
final class Notices { | ||
|
||
public function __construct() { | ||
$this->init(); | ||
} | ||
|
||
public function init(): void { | ||
add_action( 'admin_notices', array( Notices::class, 'display_admin_notices' ) ); | ||
} | ||
|
||
/** | ||
* Add admin Notices | ||
* | ||
* @param string $severity | ||
* @param string $message | ||
* | ||
* @return void | ||
* @throws Exception | ||
*/ | ||
public static function add_admin_notice( string $severity, string $message ): void { | ||
$notices = get_option( 'custom_ptt_notices', array() ); | ||
$notices[] = array( | ||
'severity' => $severity, | ||
'message' => $message, | ||
); | ||
update_option( 'custom_ptt_notices', $notices ); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public static function display_admin_notices(): void { | ||
$notices = get_option( 'custom_ptt_notices', array() ); | ||
|
||
foreach ( $notices as $notice ) { | ||
printf( '<div class="notice notice-%s is-dismissible"><p>%s</p></div>', esc_attr( $notice['severity'] ), esc_html( $notice['message'] ) ); | ||
} | ||
|
||
delete_option( 'custom_ptt_notices' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters