內容簡介
這是一個非常簡單的 WordPress 外掛程式,可用於在伺服器端或客戶端創建前端通知。預設有 4 種通知類型:成功、錯誤、警告、一般,或者您可以創建自定義的通知類型。伺服器端的通知存儲在會話中,直到顯示。
這個外掛程式希望有朝一日能解決複雜 WordPress 網站的問題,其中有多個外掛程式,每個外掛程式都有自己的提示,都需要進行樣式設置。
但是現在,對開發人員來說,這個通知 API 是在其佈景主題中創建自定義功能時的有用工具。
伺服器端使用方法
<?php
WP_Notices::success( $title, $message, $timer, $priority );
WP_Notices::warning( '登錄失敗', '您輸入了不正確的用戶名或密碼,請重試。');
WP_Notices::error( $title, $message, $timer, $priority );
WP_Notices::general( $title, $message, $timer, $priority );
WP_Notices::custom( $type, $title, $message, $timer, $priority );
?>
客戶端使用方法
jQuery(document).ready(function($){
$.WP_Notices.success( title,message, scroll_to, timer, callback );
$.WP_Notices.error( title, message, scroll_to, timer, callback );
$.WP_Notices.general( title, message, scroll_to, timer, callback );
$.WP_Notices.warning( title, message, scroll_to, timer, callback );
// 自定義類型
$.WP_Notices.render_notice( type, title, message, scroll_to, timer, callback );
// 使用 callback 參數
$.WP_Notices.warning( '表單錯誤', '無效的表單輸入。', false, 3000, function( $notice ) {
console.log( $notice );
});
});
選項
add_filter( 'notice_api_options', 'customize_notice_options' );
function customize_notice_options( $options )
{
$options = array(
'prepend_selector' => '#content',
'container_class' => 'notices-container',
'before_title' => '<strong>',
'after_title' => ':</strong> ',
'scrolling_speed' => 500,
);
return $options;
}
外掛標籤
開發者團隊
📦 歷史版本下載
原文外掛簡介
This is a very simple WordPress plugin for creating frontend notices server side or client side. There are 4 notice types by default success, error, warning, general or you can create custom notice types. Server side notices are stored in the session until displayed.
This plugin hopes to one day solve the problem of complex WordPress sites with multiple plugins all having their own Notices that all require styling.
But for now, the Notices API is useful tool for developers creating custom functionality in their theme.
Server Side Usage
Client Side Usage
jQuery(document).ready(function($){
$.WP_Notices.success( title,message, scroll_to, timer, callback );
$.WP_Notices.error( title, message, scroll_to, timer, callback );
$.WP_Notices.general( title, message, scroll_to, timer, callback );
$.WP_Notices.warning( title, message, scroll_to, timer, callback );
// Custom type
$.WP_Notices.render_notice( type, title, message, scroll_to, timer, callback );
// Using the callback parameter
$.WP_Notices.warning( 'Form Error', 'Invalid form input.', false, 3000, function( $notice ) {
console.log( $notice );
});
});
Options
add_filter( 'notice_api_options', 'customize_notice_options' );
function customize_notice_options( $options )
{
$options = array(
'prepend_selector' => '#content',
'container_class' => 'notices-container',
'before_title' => '',
'after_title' => ': ',
'scrolling_speed' => 500,
);
return $options;
}
