国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > CMS > Wordpress > 正文

WordPress 主題更新提示實(shí)現(xiàn)方法

2024-09-07 00:50:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

之前我曾經(jīng)轉(zhuǎn)載過(guò)一個(gè)類似的功能,但太復(fù)雜了,而且不是很實(shí)用,于是還是自己寫(xiě)了一個(gè),支持遠(yuǎn)程文件的緩存,避免對(duì)速度的影響.

首先你要準(zhǔn)備一個(gè) JSON 文件,放到你的網(wǎng)站目錄里,JSON 文件內(nèi)容例子,代碼如下:

{"Version":"1.0","text":"<p>這是要給用戶說(shuō)的話</p>"}

注意,一個(gè)值是最新主題的版本,版本是自動(dòng)和當(dāng)前用戶主題的 style.css 里的版本進(jìn)行對(duì)比,如果用戶的主題不是最新版本就在后臺(tái)的頂部顯示第二個(gè)屬性的內(nèi)容,然后在 functions.php 里放下邊的代碼:

  1. $theme_update_json = 'http://www.survivalescaperooms.com /update.json';//注意你的地址 
  2. define( 'theme_update_json'$theme_update_json ); 
  3.  
  4. $themefolder = strtolower( wp_get_theme() ); 
  5. define( 'theme_folder'$themefolder ); 
  6.  
  7. $theme_update_json_path = TEMPLATEPATH . '/update.json'
  8. define( 'theme_update_json_path'$theme_update_json_path ); 
  9.  
  10. function Bing_get_update_json(){ 
  11.  $fp = @file_get_contents( theme_update_json, 'r' ); 
  12.  if( !$fp ) return
  13.  file_put_contents( theme_update_json_path, $fp ); 
  14. add_action( 'theme_' . theme_folder . '_update''Bing_get_update_json' ); 
  15.  
  16. function Bing_theme_version_compare(){ 
  17.  global $update_json
  18.  if( !file_exists( theme_update_json_path ) ) return false; 
  19.  $theme_data = wp_get_theme(); 
  20.  $update_json = @file_get_contents( theme_update_json_path, 'r' ); 
  21.  $update_json = json_decode( $update_json, true ); 
  22.  if( version_compare( $update_json['Version'], $theme_data['Version'], '>' ) ) return true; 
  23.  return false; 
  24.  
  25. function Bing_update_schedule_event(){ 
  26.  global $pagenow
  27.  if$pagenow == 'themes.php' && isset( $_GET['activated'] ) && !wp_next_scheduled( 'theme_' . theme_folder . '_update' ) ) wp_schedule_event( current_time( 'timestamp' ), 'daily''theme_' . theme_folder . '_update' ); 
  28. add_action( 'load-themes.php''Bing_update_schedule_event' ); 
  29.  
  30. function Bing_notices_update(){ 
  31.  if( !Bing_theme_version_compare() ) return
  32.  global $update_json
  33.  echo '<div id="message" class="updated fade">' . $update_json['text'] . '</div>'
  34. add_action( 'admin_notices''Bing_notices_update' ); 

注意修改成你的 JSON 文件地址,每一天去服務(wù)器下載一次你的最新 JSON 文件保存到本地.

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 察哈| 二连浩特市| 长顺县| 凉山| 木里| 乌恰县| 米林县| 惠东县| 遂宁市| 永泰县| 印江| 攀枝花市| 北安市| 瑞昌市| 濮阳县| 高州市| 茌平县| 南通市| 大洼县| 疏附县| 龙南县| 安国市| 洪雅县| 张家口市| 赫章县| 伊宁县| 新丰县| 广东省| 定安县| 阿勒泰市| 射洪县| 雅安市| 乐东| 石台县| 宿迁市| 旬阳县| 墨玉县| 大英县| 甘德县| 大竹县| 石泉县|