1. Go to this page and download the library: Download duckdev/wp-flash-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/ */
// Notice with a green bar.
$notices->add( 'settings-saved', 'Your settings have been saved.', 'success' );
// Notice with a red bar.
$notices->add( 'import-failed', 'The import could not be completed.', 'error' );
// Notice with a yellow bar.
$notices->add( 'license-expiring', 'Your license expires in 3 days.', 'warning' );
// Notice with a blue bar, without a dismiss button.
$notices->add( 'sync-running', 'A sync is currently running.', 'info', false );
// Network admin notice (multisite).
$notices->add( 'network-update', 'All sites have been updated.', 'success', true, true );
$notice = $notices->get( 'settings-saved' ); // ?Notice
$notices->fetch(); // Notice[] keyed by notice key
$notices->clear(); // Delete the stored queue
do_action( 'my_plugin_front_notices' );
use FoxeLabs\Notices\Contracts\RendererInterface;
use FoxeLabs\Notices\Support\Notice;
class MyRenderer implements RendererInterface {
public function render( array $notices ): void {
foreach ( $notices as $notice ) {
printf( '<div class="my-toast my-toast--%s">%s</div>', esc_attr( $notice->type() ), esc_html( $notice->message() ) );
}
}
}
$notices = new \FoxeLabs\Notices\Notices( 'my_plugin', null, new MyRenderer() );
$notices->register();
use FoxeLabs\Notices\Storage\TransientStore;
use FoxeLabs\Notices\Support\KeyPrefixer;
$store = new TransientStore( new KeyPrefixer( 'my_plugin' ), HOUR_IN_SECONDS );
$notices = new \FoxeLabs\Notices\Notices( 'my_plugin', $store );