WP酷 WP酷
  • 主题
  • 教程
  • 插件
  • 官方 QQ 群
  • 建站推荐
  • 联系
  • nicetheme® 奈思主题
  • 注册
    登录
立即登录
  • 请到 [后台->外观->菜单] 中设置菜单
首页 › WordPress 开发 › 借助Github – 为WordPress插件添加自动更新功能

借助Github – 为WordPress插件添加自动更新功能

PCDotFan8年前

借助Github - 为WordPress插件添加自动更新功能-WP酷

前段时间我发布了《WordPress非官方主题/插件添加升级功能》此篇文章,使用自建网站服务器的方式给 WordPress 主题或插件提供升级点。当然,缺点在于如果服务器不够稳定,极有可能出现意想不到的后果。本文来自 DeveWork ,将与大家一同实现借助 Github ,为 WordPress 插件添加自动更新的功能,只要稍加修改,相信国内高人一定能整合出适合主题的版本。

WordPress-GitHub-Plugin-Updater 简介

WordPress-GitHub-Plugin-Updater 是一个WordPress 的第三方类。如果你的WordPress 插件是托管到Github 上的,借助这个类可以实现类似WordPress 官方的自动更新升级机制。难得可贵的是,这个类不仅仅支持公共仓库(public repositories),也支持私有仓库的项目(private repositories)——当然前提你是GitHub 的付费用户。支持私有仓库意味着你可以将你的收费插件托管到Github 上而不必担心文件泄露的问题。

 

WordPress-GitHub-Plugin-Updater 使用方法

Github 主页:https://github.com/jkudish/WordPress-GitHub-Plugin-Updater

下载zip 压缩包解压后安装WordPress后台上,项目本身就是一个插件,你可以安装来查看是如何的运作的。

要集成到你的插件的话,将updater.php  放到你的插件目录下,然后在插件主文件写入下面的代码,注意相关文件名称要修改为你的插件的:

add_action( 'init', 'github_plugin_updater_test_init' );
function github_plugin_updater_test_init() {
 
	include_once 'updater.php';
 
	define( 'WP_GITHUB_FORCE_UPDATE', true );
 
	if (is_admin()) { // note the use of is_admin() to double check that this is happening in the admin
    $config = array(
        'slug' => plugin_basename(__FILE__), // this is the slug of your plugin
        'proper_folder_name' => 'plugin-name', // this is the name of the folder your plugin lives in
        'api_url' => 'https://api.github.com/repos/username/repository-name', // the github API url of your github repo
        'raw_url' => 'https://raw.github.com/username/repository-name/master', // the github raw url of your github repo
        'github_url' => 'https://github.com/username/repository-name', // the github url of your github repo
        'zip_url' => 'https://github.com/username/repository-name/zipball/master', // the zip url of the github repo
        'sslverify' => true // wether WP should check the validity of the SSL cert when getting an update, see https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/2 and https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/4 for details
        'requires' => '3.0', // which version of WordPress does your plugin require?
        'tested' => '3.3', // which version of WordPress is your plugin tested up to?
        'readme' => 'README.md', // which file to use as the readme for the version number
        'access_token' => '', // Access private repositories by authorizing under Appearance > Github Updates when this example plugin is installed
    );
    new WP_GitHub_Updater($config);
}
 
}

 access_token 这个参数是私有仓库才需要,如果是公开项目不必填写。私有项目必须按照下面的步骤去获取 Github 应用的 Client ID 与 Client Secret 激活之。

借助Github - 为WordPress插件添加自动更新功能-WP酷

如果填写正确,那么后台会适时提示更新,如下图:

借助Github - 为WordPress插件添加自动更新功能-WP酷

 

 

#Github#WordPress第三方主题升级
1
分享

本站下载管理系统「dl.mywpku.com」因年久失修而永久关闭。若需获得往年主题,请至 WP酷的百度网盘(提取码: 5rbm) 自行搜索下载。默认解压密码为「www.mywpku.com」。

对您造成的不便,敬请谅解!

PCDotFan 站长
文章 435评论 859
相关文章
  • [6.0 更新中文汉化]极度流行的SEO插件 – WordPress SEO by Yoast
  • WordPress 新用户注册邮件链接提示「您的密码重设链接无效」
  • AMP – 为 WordPress 移动站点操作全球访问优化
  • 去除谷歌服务 – WordPress 国外主题全方位加速
  • 使用 WP-CLI 简化 WordPress 操作流程
  • WordPress 基础开发 – 一探 WordPress Hook 机制及示例应用
  • 优化静态资源 – WordPress 国外主题全方位加速
  • WordPress 实现微信登录
评论 (9)
再想想
  • Rain_Division

    感觉还是手动的比较好。。。

    8年前
  • arm linux

    辛苦啦~~~~~~~~

    8年前
  • 郑永

    自动更新貌似不安全 。

    8年前
    • WP酷

      @郑永 这个还真没研究过……

      8年前
  • 敦煌信息网

    终于找到使用办法了。。搞了个插件不知道怎么用。谢谢博主

    8年前
  • 网络兼职

    自动更细没问题,但是文章源从哪来呢

    8年前
  • 云落

    我的那个主题也支持自定更新,只是不是github,是OSC

    8年前
  • 网上开店

    谢谢啊!

    8年前
  • 网赚

    学习下

    8年前
PCDotFan
站长
若无特别注明,则默认我发布的所有文章均为内容原创 / 翻译原创,转载时请保留来源。
435文章
859评论
3K获赞
猜你喜欢
WordPress自定义个性化文章版权声明
10年前
WP-PostViews续集:精简版代码
10年前
免插件实现WP-Postviews统计功能
10年前
  • 杂记
  • WordPress 付费主题推荐
Copyright © 2023 WP酷. Designed by nicetheme. 琼ICP备13002067号-1