49 lines
1.0 KiB
PHP
49 lines
1.0 KiB
PHP
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Show a notice on the admin panel.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @param string $message The message to show in the notice
|
|
* @param string $type The 'type' of notice, e.g. info (default), success, warning, or error
|
|
* @param bool $dismissible Whether the notice should be dismissible
|
|
*
|
|
* @return string
|
|
*/
|
|
function nmsp_admin_notice( string $message, string $type = 'info', bool $dismissible = true ) {
|
|
$classes = 'notice';
|
|
switch ($type) {
|
|
case 'success':
|
|
$classes .= ' notice-success';
|
|
break;
|
|
case 'warning':
|
|
$classes .= ' notice-warning';
|
|
break;
|
|
case 'error':
|
|
$classes .= ' notice-error';
|
|
break;
|
|
case 'info':
|
|
default:
|
|
$classes .= ' notice-info';
|
|
}
|
|
|
|
if ( $dismissible ) {
|
|
$classes .= ' is-dismissible';
|
|
}
|
|
|
|
add_action( 'admin_notices', function () use ( $classes, $message ) {
|
|
ob_start();
|
|
?>
|
|
<div class="<?php echo $classes; ?>">
|
|
<p><?php _e( $message, 'nmsp-plugin-name-text-domain' ); ?></p>
|
|
</div>
|
|
<?php
|
|
echo ob_get_clean();
|
|
});
|
|
}
|