
內容簡介
此外掛會在管理列(所有管理頁面頂部)增加一個動態且實用的時鐘,顯示部落格伺服器的時間。隨著時間的流逝,時鐘會自動更新數字,和數位時鐘一樣。
此外掛也支援靜態模式。在所有管理頁面頂部,會以時間戳記字串的方式呈現,代替動態時鐘。這個靜態管理時間小工具可以被點擊,以就地更新時間(無需重新載入頁面),顯示新的當前伺服器時間。
此外掛也提供「部落格時間」小工具,提供了相同的功能作為管理小工具,不過可以讓你在側邊欄(sidebar)使用。你也可以透過在佈景主題樣板中使用範本標籤 c2c_blog_time() 直接使用此外掛的功能。
注意:對於前端小工具而言,如果勾選了「使用動態時鐘?」的配置選項,此外掛會產生時間戳記而非時鐘。所顯示的時間是當頁面載入時的時間,或者是在小工具上次檢索時間後所顯示的時間。它不會在顯示時自動增加時間。預設情況下,小工具顯示動態時鐘,且會持續增加時間。
這最適合於查看伺服器/部落格時間,以判斷部落格中時效性文章、評論或操作的日期(例如監控何時應該關閉競賽文章的評論等,或僅僅是考慮伺服器所在時區)。或者,當靜態以時間戳記而非時鐘的方式呈現時,它可以指示/保存頁面載入的時間。
鳴謝 Moment.js 提供 JavaScript 日期套件。
連結:外掛首頁 | 外掛目錄頁面 | GitHub | 作者首頁
範本標籤
此外掛提供了一個範本標籤供在佈景主題樣板、functions.php 或其他外掛中使用。
函式
<? php function c2c_blog_time($time_format ='',$echo = true)?>
返回並/或顯示網站的格式化時間。
參數
$time_format (string)
選擇性的。PHP 時間格式字串。更多資訊請參考 https://www.php.net/manual/en/datetime.format.php。預設值是 ``(如果沒有修改預設時間格式,則使用 g:i A)。
$echo (bool)
選擇性的。是否輸出模板資訊?預設值是 true。
範例
<? php // 輸出網站當前的時間。
c2c_blog_time();
?>
<? php // 取得值以供代碼使用,因此不顯示/輸出它。
$site_date = c2c_blog_time('M d, Y', false);
?>
掛勾
此外掛公開了四個可供掛勾的篩選器。使用這些篩選器的程式碼理想上應該放在 mu-plugin 或專屬外掛(攸關本自述文件範圍之外)。不那麼理想的做法是將其放入使用中佈景主題的 functions.php 中。
c2c_blog_time(filter)
'c2c_blog_time' 鉤子允許您使用另一種方法安全地調用 c2c_blog_time(),這樣,如果外掛被停用或刪除,那麼您對函式的呼叫不會導致網站出現錯誤。
參數:
與 c2c_blog_time() 相同的參數。
外掛標籤
開發者團隊
原文外掛簡介
This plugin adds a dynamic, functional clock to the admin bar (at top of all admin pages) to show the server time for the blog. The clock automatically updates as time passes, as you would expect of a digital clock.
This plugin also supports a static mode which puts a timestamp string at the top of all admin pages instead of the dynamic clock. This static admin time widget can be clicked to update the time in-place (without a page reload) to show the new current server time.
Also provided is a “Blog Time” widget providing the same functionality as the admin widget, but for your sidebars. You may also utilize the plugin’s functionality directly within a theme template via use of the template tag c2c_blog_time().
NOTE: For the front-end widget, if the “Use dynamic clock?” configuration option is unchecked, this plugin generates a timestamp and NOT a clock. The time being displayed is the time of the page load, or if clicked, the time when the widget last retrieved the time. It won’t actively increment time on the display. By default the widget displays a dynamic clock that does increment time.
This is most useful to see the server/blog time to judge when a time sensitive post, comment, or action would be dated by the blog (i.e. such as monitoring for when to close comments on a contest post, or just accounting for the server being hosted in a different timezone). Or, when used statically as a timestamp and not a clock, it can indicate/preserve when the page was loaded.
Thanks to Moment.js for the JavaScript date handling library.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Template Tags
The plugin provides one template tag for use in your theme templates, functions.php, or plugins.
Functions
Returns and/or displays the formatted time for the site.
Arguments
$time_format (string)
Optional. PHP-style time format string. See https://www.php.net/manual/en/datetime.format.php for more info. Default is ” (which, unless otherwise modified, uses the default time forat: ‘g:i A’).
$echo (bool)
Optional. Echo the template info? Default is true.
Examples
Hooks
The plugin exposes four filters for hooking. Code using these filters should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain). Less ideally, you could put them in your active theme’s functions.php file.
c2c_blog_time (filter)
The 'c2c_blog_time' hook allows you to use an alternative approach to safely invoke c2c_blog_time() in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.
Arguments:
same as for c2c_blog_time()
Example:
Instead of:
Do:
c2c_blog_time_format (filter)
The 'c2c_blog_time_format' hook allows you to customize the default format for the blog time. By default this is ‘g:i A’ (though this may be different if modified by localization).
Arguments:
$format (string): The default format for the blog time.
Example:
/**
* Change the default blog time string
*
* @param string $format The default time format.
* @return string
*/
function change_blog_time_format( $format ) {
return 'b, g:i A';
}
add_filter( 'c2c_blog_time_format', 'change_blog_time_format' );
c2c_blog_time_toolbar_widget_for_user (filter)
The c2c_blog_time_toolbar_widget_for_user hook allows you to control if the admin toolbar clock widget should be shown, on a per-user basis. By default the admin toolbar clock is shown to everyone who can see the admin toolbar.
Arguments:
$shown (boolean): Whether the admin toolbar clock widget should be shown. Default of true.
Example:
/**
* Only show the admin toolbar clock for the 'boss' user.
*
* @param $show bool Status of whether the admin toolbar clock should be shown.
* @return bool
*/
function restrict_blog_time_widget_appearance( $show ) {
return 'boss' === get_current_user()->user_login;
}
add_filter( 'c2c_blog_time_toolbar_widget_for_user', 'restrict_blog_time_widget_appearance' );
c2c_blog_time_active_clock (filter)
The 'c2c_blog_time_active_clock' hook returns the boolean value indicating if the Javascript-powered dynamic clock introduced in v2.0 should be enabled or if instead the v1.x era behavior of a static timestamp that can be clicked to update the timestamp via AJAX should be enabled. By default the dynamic clock is enabled.
Arguments:
$allow (boolean): Boolean indicating if the admin widget should be a dynamic clock. Default is true.
Example:
// Disable the dynamic clock and use the static timestamp (whcih can be clicked to update the time via AJAX) instead.
add_filter( 'c2c_blog_time_active_clock', '__return_false' );
