Getting notice functionality in the admin panel
This commit is contained in:
@ -66,7 +66,7 @@ class AdminSettings {
|
||||
public function register_scripts(): void {
|
||||
wp_enqueue_style( 'nmsp-plugin-name-admin-css', plugins_url( '../assets/css/nmsp-plugin-name-admin.css', __FILE__ ), array(), '1.0.0', 'screen' );
|
||||
|
||||
wp_register_script( 'nmsp-plugin-name-admin-js', plugins_url( '../assets/js/nmsp-plugin-name-admin.js', __FILE__ ), array( 'jquery' ), '1.0.0', false );
|
||||
wp_register_script( 'nmsp-plugin-name-admin-js', plugins_url( '../assets/js/nmsp-plugin-name-admin.js', __FILE__ ), array(), '1.0.0', false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
48
admin/nmsp-admin-functions.php
Normal file
48
admin/nmsp-admin-functions.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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();
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user