提交到Wordpress官网上的主题,当有新版本时会提示你更新,那么未提交到官网上的主题如何实现该功能呢?国外Wordpress爱好者给出了解决方案,具体实现方法:

第一步,下载所需文件

下载地址

第二步、为主题添加远程检测版本功能

将下载的文件解压后,将里面的theme-updates文件夹放到主题根目录中,打开主题functions.php文件添加:

//Initialize the update checker.

require 'theme-updates/theme-update-checker.php';

$example_update_checker = new ThemeUpdateChecker(

'example-theme', //Theme folder name, AKA "slug".

'http://w-shadow.com/files/example-theme-updates/info.json' //URL of the metadata file.

);

  
其中:

example-theme 主题的名称,不一定非得与主题名称一字不差,可任意。

http://w-shadow.com/files/example-theme-updates/info.json 下载的 info.json 文件的存放位置。

可以在空间新建一个文件夹,并修改相应的链接地址。

第三步、修改远程更新数据

编辑 info.json 文件

{

"version" : "2.0",

"details_url" : "http://w-shadow.com/files/example-theme-updates/details.html",

"download_url" : "http://w-shadow.com/files/example-theme-updates/example-theme.zip"

}

  
其中:

第2行 主题的版本号

第3行 升级说明文件链接

第4行 主题下载链接

修改相应链接,指向自己存放的文件位置。

当所使用主题的版本号低于info.json文件中版本号时,后台会提示更新,并可以实现与官网主题相同的一键升级功能。提示功能仅限于正在使用中的主题,未启用的无效。

到原文作者处查看详细参数:Automatic Updates For Private And Commercial Themes