oberonlai/wp-updater
Composer 安装命令:
composer require oberonlai/wp-updater
包简介
Self hosted WordPress plugin update server
README 文档
README
Simple WordPress Class for self host plugin updating server
from How to Configure Self-Hosted Updates for Your Private Plugins
Requirements
Installation
Install with composer
Run the following in your terminal to install with Composer.
$ composer require oberonlai/wp-updater
WP Metabox PSR-4 autoloading and can be used with the Composer's autoloader. Below is a basic example of getting started, though your setup may be different depending on how you are using Composer.
require __DIR__ . '/vendor/autoload.php'; use ODS\Updater; $options = array( ... ); $books = new Updater( $options );
See Composer's basic usage guide for details on working with Composer and autoloading.
Basic Usage
Below is a basic example of setting up a plugin updater.
// Require the Composer autoloader. require __DIR__ . '/vendor/autoload.php'; // Import PostTypes. use ODS\Updater;
Usage
To create a updater, first instantiate an instance of Updater. The class takes one argument, which is an associative
array.
$updater = new Updater( array( 'plugin_slug' => 'my-plugin', 'version' => '1.0.0', 'json_url' => 'https://mydomain.com/my-plugin.json', ));
License Manger
You can add the license argument when creating the Updater instance. The license key is used to verify the authenticity of the plugin. The license key is stored in the database and is used to verify the authenticity of the plugin.
$updater = new Updater( array( 'plugin_slug' => 'my-plugin', 'version' => '1.0.0', 'json_url' => 'https://mydomain.com/my-plugin-validate.php', 'license' => get_option( 'my-plugin_license_key' ), ));
In the my-plugin-validate.php file, you can add the following code to verify the license key.
<?php $array = array( "name" => "My Plugin", "slug" => "my-plugin", "author" => "<a href='https://mydomain.com/my-plugin/'>Author</a>", "author_profile" => "https://mydomain.com", "version" => "1.0.1", "requires" => "5.6", "tested" => "6.2.2", "requires_php" => "7.4", "added" => "2021-04-05 00:00:00", "last_updated" => "2023-06-29 00:00:00", "homepage" => "https://mydoamin.com", "sections" => array( "description" => "My plugin description", "installation" => "My plugin installation", "changelog" => "<p>v1.0.1</p><p>Change log</p>" ), "banners" => array( "low" => "https://mydomain.com/my-plugin-banner-low.jpg", "high" => "https://mydomain.com/my-plugin-banner-high.jpg" ) ); // no update is available by default $update[ 'download_url' ] = ''; if( ! empty( $_GET['license_key' ] ) && license_check_logic( $_GET[ 'license_key' ] ) { $update[ 'download_url' ] = 'pass the URL to plugin ZIP archive here'; } ... header( 'Content-Type: application/json' ); echo json_encode( $update );
license_check_logic is a function that checks the license key. If the license key is valid, the function add the download URL to the update array.
You also can get the plugin slug and site url from client's site with $_GET['slug'] and $_GET['site_url'].
Preparations
You will need a hosting space to store the information file of the plugin and the zip file of the new version of the plugin. You can use space such as Dropbox or Google Drive, or you can place it on your own server. My top recommendation is to host it on GitHub, as it allows integration with version control processes.
my-plugin.json
This is an example of a JSON-formatted file for the plugin information. It includes the following fields:
{
"name": "My Plugin",
"slug": "my-plugin",
"author": "<a href='https://mydomain.com/my-plugin/'>Author</a>",
"author_profile": "https://mydomain.com",
"version": "1.0.1",
"download_url": "https://mydomain.com/my-plugin.zip",
"requires": "5.6",
"tested": "6.2.2",
"requires_php": "7.4",
"added": "2021-04-05 00:00:00",
"last_updated": "2023-06-29 00:00:00",
"homepage": "https://mydoamin.com",
"sections": {
"description": "My plugin description",
"installation": "My plugin installation",
"changelog": "<p>v1.0.1</p><p>Change log</p>"
},
"banners": {
"low": "https://mydomain.com/my-plugin-banner-low.jpg",
"high": "https://mydomain.com/my-plugin-banner-high.jpg"
}
}
If you want to push a notification for a new update, simply increment the version number in the plugin. The download_url indicates the location to download the new version of the plugin.
Hooks - ods_updater_after_purge
Allow plugin developers to perform additional tasks after the plugin update is completed, such as updating database tables, displaying notification alerts, and other behaviors. These tasks can be handled through this hook point.
add_action('ods_updater_after_purge', function( $upgrader, $options ){ // do stuff when plugin updated. });
oberonlai/wp-updater 适用场景与选型建议
oberonlai/wp-updater 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 oberonlai/wp-updater 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oberonlai/wp-updater 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-30