国产探花免费观看_亚洲丰满少妇自慰呻吟_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://m.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ā)表
主站蜘蛛池模板: 邓州市| 金阳县| 瑞昌市| 江孜县| 云南省| 五常市| 策勒县| 靖宇县| 博爱县| 博罗县| 紫阳县| 双峰县| 松原市| 乐亭县| 松溪县| 东莞市| 宜兴市| 淮北市| 罗源县| 平顶山市| 永和县| 霍城县| 麟游县| 冕宁县| 建瓯市| 息烽县| 漳浦县| 镇平县| 龙岩市| 黑山县| 桂平市| 德保县| 亚东县| 石嘴山市| 通化市| 桓仁| 定襄县| 神池县| 襄樊市| 花垣县| 六枝特区|