PHP code example of yahnis-elsts / admin-notices

1. Go to this page and download the library: Download yahnis-elsts/admin-notices library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yahnis-elsts / admin-notices example snippets

 
	

use \YeEasyAdminNotices\V1\AdminNotice;

AdminNotice::create()
	->success('Hello world!')
	->show();

AdminNotice::create()->success('Success')->show();
 
AdminNotice::create()->error('Error')->show(); 

AdminNotice::create()->warning('Warning')->show();

AdminNotice::create()->info('Information')->show();

AdminNotice::create()
	->info()
	->text('<script>/* This will be displayed as plain text. */</script>')
	->show();

AdminNotice::create()
	->info()
	->html('Tip: Go to <a href="#">Settings -&gt; My Plugin</a> to configure the plugin.')
	->show();

AdminNotice::create()
	->rawHtml('<p>First paragraph</p><p>Second paragraph</p>')
	->show();

AdminNotice::create()
	->text('You can hide this notice by clicking the "(x)" =>')
	->dismissible()
	->show();

AdminNotice::create('my-notice-id')
	->persistentlyDismissible(AdminNotice::DISMISS_PER_SITE)
	->success('This notice can be permanently dismissed.')
	->show();

AdminNotice::create('my-notice-id')
	->persistentlyDismissible(AdminNotice::DISMISS_PER_SITE, WEEK_IN_SECONDS)
	->success('This notice can be dismissed for 1 week.')
	->show();

AdminNotice::cleanUpDatabase('myplugin-');

AdminNotice::create()
	->info()
	->text('This message will only appear on the "Plugins -> Installed Plugins" page')
	->onPage('plugins')
	->show();
	
add_action('admin_menu', function() {
	$id = add_options_page(
		'Example',
		'Example',
		'manage_options',
		'example-admin-page',
		'__return_false'
	);

	AdminNotice::create()
		->info()
		->text('This will appear on "Settings -> Example"')
		->onPage($id)
		->show();
});