
內容簡介
一個用於 WordPress 的外掛程式,可在應用程式的前端上方創建可插入框架,以新增訊息通知。通知可以透過查詢變數或透過模板函數和動作生成。
此外掛程式可用於創建全站通知,或您可以縮小範圍以鎖定特定頁面。
將通知中心添加到您的模板中
添加通知的最基本方式是全站式的。您可以向模板添加 “show” 動作,例如 header.php 文件。這是該外掛程式的最強大用途:統一、集中的通知。
<?php do_action( 'sewn/notifications/show' ); ?>
創建查詢變數通知
擴展通知中心的最簡單方法是添加查詢變數鍵/值對,以在提交 URL 查詢變數時生成新訊息。
<?php
add_filter( 'sewn/notifications/queries', 'custom_add_query_notifications' );
function custom_add_query_notifications( $queries )
{
$queries[] = array(
'key' => 'update',
'value' => 'true',
'message' => "已更新。",
'args' => 'fade=true'
);
$queries[] = array(
'key' => 'update',
'value' => 'failed',
'message' => "無法更新。",
'args' => 'dismiss=true&error=true'
);
$queries[] = array(
'key' => 'update',
'value' => 'finished',
'message' => "完成!",
'args' => 'fade=10000' // 等待十秒後淡出
);
return $queries;
}
?>
現在,每當在頁面末端添加查詢變數時,都可以在通知中心中顯示一則訊息。
例如,http://example.com/path/to/page/?update=true 會在通知中心中生成訊息:“已更新。”
訊息引數
在添加訊息時,您可以使用引數來自訂功能。
error 當設定為 true 時,這將向訊息添加錯誤類別。預設值:false
fade 當設定為 true 時,這將在 3 秒後淡出訊息。您可以通過將 fade 設置為數字(以毫秒為單位)來更改暫停時間。預設值:false
dismiss 允許用戶使用關閉按鈕關閉訊息。預設值:false
event 允許訊息持久存在,因此每次頁面載入時都會出現,除非被解除。事件追蹤訊息,並在用戶關閉訊息時更新用戶 meta,因此將停止顯示訊息。預設值:false
page 僅鎖定訊息到特定頁面。設置 page 時,在顯示訊息之前,將執行 is_page($page) 檢查。尤其適用於設置查詢變數對時。預設值:false
手動生成通知
可以在 show 動作之前的任何地方手動添加通知。
if ( $something_happened ) :
do_action( 'sewn/notifications/add', $message, $args );
endif;
外掛標籤
開發者團隊
原文外掛簡介
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.
Add the Notification Center to Your Template(s)
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.
Create Query Variable Notifications
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.
'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.
Arguments for Messages
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: false
fade 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: false
dismiss Allows a message to be dismissed by the user with a close button. Default: false
event 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: false
page 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: false
Maually Generate Notifications
Add notifications manually anywhere before the show action.
if ( $something_happened ) :
do_action( 'sewn/notifications/add', $message, $args );
endif;
