admin_notices

最后更新于:2021-11-25 19:43:22

do_action( ‘admin_notices’ )

Prints admin screen notices.

源文件

文件: gc-admin/admin-header.php

View on Trac

add_action( 'admin_notices', 'independence_notice' );

function independence_notice() {
    global $pagenow;
	$admin_pages = [ 'index.php', 'edit.php', 'plugins.php' ];
    if ( in_array( $pagenow, $admin_pages ) ) {
		if ( date( 'j, F' ) === '1, October' ) { 
			?>
			<div class="notice notice-warning is-dismissible">
				<p>Happy Independence Day, Nigeria...</p>
			</div>
			<?
		}
    }
}

//Display admin notices 
function my_test_plugin_admin_notice()
{
	//get the current screen
	$screen = get_current_screen();

	//return if not plugin settings page 
	//To get the exact your screen ID just do var_dump($screen)
	if ( $screen->id !== 'toplevel_page_YOUR_PLUGIN_PAGE_SLUG') return;
		
	//Checks if settings updated 
	if ( isset( $_GET['settings-updated'] ) ) {
		//if settings updated successfully 
		if ( 'true' === $_GET['settings-updated'] ) : ?>

			<div class="notice notice-success is-dismissible">
				<p><?php _e('Congratulations! You did a very good job.', 'textdomain') ?></p>
			</div>

		<?php else : ?>

			<div class="notice notice-warning is-dismissible">
				<p><?php _e('Sorry, I can not go through this.', 'textdomain') ?></p>
			</div>
			
		<?php endif;
	}
}
add_action( 'admin_notices', 'my_test_plugin_admin_notice' );