[WordPress] 外掛分享: Use Client’s Time Zone

前言介紹

  • 這款 WordPress 外掛「Use Client's Time Zone」是 2012-09-19 上架。
  • 目前有 200 個安裝啟用數。
  • 上一次更新是 2023-10-13,距離現在已有 569 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 1.5 以上版本才可以安裝。
  • 有 7 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

drmikegreen |

外掛標籤

time zone | client's time zone | default time zone |

內容簡介

這個外掛使用“使用 JavaScript 自動偵測時區”(http://pellepim.bitbucket.org/jstz/)來檢索客戶端的時區,第一次客戶端訪問網站時,將包含客戶端時區的 cookie 設置在客戶端上,並重新加載頁面。然後 PHP 會讀取這個 cookie,並使用 date_default_timezone_set()函數(需要 PHP 5> = 5.1.0)設置 PHP 腳本的默認時區。因為它運行在所有外掛加載之後,所以它會改變其後所有 PHP 的時區。當你希望用戶在某些日期上看到某些文章時,這很有用。例如,如果文章的 slug 包含日期數字,比如“xyz-daynr”,那麼可以通過主題模板中的“$slug =‘ xyz’.date(j);”來指定文章。這個 cookie 不會在十年內過期,但如果用戶更改時區,它會被重置。所以,除非用戶刪除 cookie 或移動頁面,只有在十年內重新加載頁面。

版權所有2012-2015 M.D. Green,SaeSolved:LLC

許可證

本程式是免費軟件;您可以按照 GNU 通用公共許可證的條款重新分發和修改它,詳情請參閱 Free Software Foundation 的許可證;其版本為許可證的第2版,或(按您的選擇)任何以後的版本。

本程序是基於無任何保證的情況下分發的,并且沒有任何明示或暗示擔保商品的適用性或適合特定目的。詳情請參考 GNU 通用公共許可證。
1. 在我們的論壇上發布了一個注意事項,如果使用 date_default_timezone_set 更改時區,站點可能會遇到問題。WP 預期它始終為 UTC,並通過其他方式實現在不同時區中顯示的內容:
https://vip.wordpress.com/documentation/vip-development-tips-tricks/use-current_time-not-date_default_timezone_set/
https://weston.ruter.net/2013/04/02/do-not-change-the-default-timezone-from-utc-in-wordpress/

作者在經過測試的網站上沒有觀察到有任何問題與使用此外掛。然而,基於上述帖子,激活此外掛後應檢查沒有與日期有關的操作出現了問題 - 即使沒有在測試的網站中觀察到任何問題。

待完成項:如果可能的話,開發一種方法,用於產生現有外掛功能而不是使用 date_default_timezone_set()函數。

原文外掛簡介

This plugin retrieves the time zone of the client using “Automatic Timezone Detection Using JavaScript” (http://pellepim.bitbucket.org/jstz/) the first time that a client accesses the site, sets a cookie containing the client’s time zone on the client, and reloads the page. This cookie is then read by PHP and the date_default_timezone_set() function (requires PHP 5 >= 5.1.0) is used to set the default time zone for PHP scripts. Since it runs just after all of the plugins are loaded, it changes the time zone for all of the PHP that follows. It is useful in cases where one wants users to see certain posts on certain days. E.g., if the post slug contains the day number, like “xyz-daynr,” then the post can be specified by “$slug = ‘xyz’.date(j);” in a theme template. The cookie does not expire for ten years, but is reset if the user changes time zones. So, unless the user deletes cookies or moves the page reload only occurs once every ten years.
NOTE:
A remark was posted in our forum stating that sites may experience problems if changing timezones using date_default_timezone_set. WP expects it to always be UTC and display of things in different timezones are achieved in other ways:
https://vip.wordpress.com/documentation/vip-development-tips-tricks/use-current_time-not-date_default_timezone_set/

Do not change the default timezone from UTC in WordPress


The author has not observed any problems on the sites on which this plugin has been tested. Based on the foregoing post, however,it would be wise to check that no date-related operations are going awry after activating this plugin — even though no problems have been observed with the sites tested.
Copyright 2012-2023 M.D. Green, SaeSolved:: LLC
License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Use Client's Time Zone」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.1 | 1.1.1 | 1.1.2 | 1.1.3 | 1.3.2 |

延伸相關外掛(你可能也想知道)

暫無相關外掛推薦。

文章
Filter
Apply Filters
Mastodon