lexo / plugin-updater
WordPress插件更新器
1.1.1
2023-10-27 09:54 UTC
Requires
- php: >=7.4.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-27 11:58:33 UTC
README
自托管WordPress插件的更新器。
版本控制
创建版本标签时考虑了语义化版本控制。提交信息遵循常规提交约定。
兼容性
- WordPress版本
>=4.7。测试并良好运行至6.3.2。 - PHP版本
>=7.4.1。测试并良好运行至8.2.10。
安装
composer require lexo/plugin-updater
默认值
private array $args = [ 'basename' => '', 'slug' => '', 'version' => '', 'remote_path' => '', 'remote_args' => [ 'timeout' => 10, 'headers' => [ 'Accept' => 'application/json' ] ], 'cache_key' => 'custom_cache_key_update', 'cache_expiration' => DAY_IN_SECONDS, 'cache' => true, ];
设置方法
所有方法都是可链的。最后调用 run() 方法。
-
setBasename(string $basename): PluginUpdater -
setSlug(string $slug): PluginUpdater -
setVersion(string $version): PluginUpdater -
setRemotePath(string $remote_path): PluginUpdater -
setRemoteArgs(array $remote_args): PluginUpdater -
setCacheKey(string $cache_key): PluginUpdater -
setCacheExpiration(float $cache_expiration): PluginUpdater -
setCache(bool $cache): PluginUpdater
使用示例
(new PluginUpdater()) ->setBasename(BASENAME) ->setSlug(PLUGIN_SLUG) ->setVersion(VERSION) ->setRemotePath('https://website.tld/path/info.json') ->setCacheKey(CACHE_KEY) ->setCacheExpiration(12 * HOUR_IN_SECONDS) ->setCache(true) ->run();
JSON文件
文件 info.json 可以命名为你喜欢的任何名字,但必须是一个有效的JSON文件。其结构应如下所示
{
"name": "Plugin name",
"slug": "plugin-slug",
"author": "<a href='https://www.domain.tld/'>Author Name</a>",
"author_profile": "https://www.domain.tld/",
"donate_link": "https://www.domain.tld/",
"version": "1.2.3",
"download_url": "https://website.tld/path/plugin-slug-1.2.3.zip",
"requires": "4.7",
"tested": "6.0.2",
"requires_php": "7.4.1",
"sections": {
"description": "Lorem ipsum description",
"changelog": "Lorem ipsum changelog"
},
"banners": {
"low": "https://website.tld/path/banner-772x250.jpg",
"high": "https://website.tld/path/banner-1544x500.jpg"
}
}
过滤器
- {slug}/plugin_sections
参数
apply_filters('{slug}/plugin_sections', $args);
- $args (array) 将用于更新信息弹出窗口的章节。