We'll create fresh WordPress site with Sewn In Notifications installed. You have 20 minutes to test the plugin after that site we'll be deleted.
A plugin for WordPress that creates a very pluggable framework to add notifications on the front end of your application. Notifications can be generated by query variables or through template functions and actions.
This plugin can be used to create site wide notifications, or you can narrow it down to specific pages.
The most basic way to add notifications is sitewide. You can add the “show” action to a template like your header.php file. This is the most powerful use for the plugin: uniform, centralized notifications.
<?php do_action( 'sewn/notifications/show' ); ?>
The simplest way to extend the notification center is to add query variable key/value pairs to generate a new message when url query variables are submitted.
<?php
add_filter( 'sewn/notifications/queries', 'custom_add_query_notifications' );
function custom_add_query_notifications( $queries )
{
$queries[] = array(
'key' => 'update',
'value' => 'true',
'message' => "Updated.",
'args' => 'fade=true'
);
$queries[] = array(
'key' => 'update',
'value' => 'failed',
'message' => "Unable to update.",
'args' => 'dismiss=true&error=true'
);
$queries[] = array(
'key' => 'update',
'value' => 'finished',
'message' => "Finished!",
'args' => 'fade=10000' // wait ten seconds before fading
);
return $queries;
}
?>
Now whenever a query variable is added to the end of a page, a message can be shown in the notification center.
So http://example.com/path/to/page/?update=true
will generate the message: “Updated.” in the notification center.
When adding a message, there are arguments you can use to customize the functionality.
error
When set to true, this will add the error class to the message. Default: falsefade
When set to true, this will fade the message out after 3 seconds. You can change the pause time by setting fade to a number (in milliseconds). Default: falsedismiss
Allows a message to be dismissed by the user with a close button. Default: falseevent
Allows message to be persistent, so that it shows up on each page load unless dismissed. The event tracks the message and updates the user’s meta when the message is dismissed, so it will stop showing up. Default: falsepage
Lock a message to a specific page only. When page is set, a is_page($page)
check will be performed before showing the message. Particularly useful when setting up query variable pairs. Default: falseAdd notifications manually anywhere before the show
action.
if ( $something_happened ) :
do_action( 'sewn/notifications/add', $message, $args );
endif;