wp-forge / wp-update-handler
一个基于自定义更新服务器API响应更新自定义插件和主题的WordPress包。
1.0.2
2024-02-16 18:07 UTC
Requires
- wp-forge/helpers: ^2.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-16 19:21:48 UTC
README
一个基于来自自定义更新服务器的JSON REST API响应更新自定义插件和主题的WordPress包。
查看WordPress GitHub Release API存储库,了解如何快速启动一个使用Cloudflare Workers从GitHub获取版本的自定义更新服务器。
插件
此包假定您的自定义插件信息API将以与WordPress插件信息API相同的形状响应。但是,如果您的API响应具有不同的形状,您可以将字段映射到您的API返回的字段。
用法
基本示例
<?php /** * Plugin Name: My Plugin */ require __DIR__ . '/vendor/autoload.php'; use WP_Forge\WPUpdateHandler\PluginUpdater; $url = 'https://my-update-api.com/plugins/plugin-name'; // Custom API GET endpoint new PluginUpdater( __FILE__, $url );
具有数据映射和数据覆盖的高级示例
<?php /** * Plugin Name: My Plugin */ require __DIR__ . '/vendor/autoload.php'; use WP_Forge\WPUpdateHandler\PluginUpdater; $file = __FILE__; // Can be absolute path to main plugin file, or the plugin basename. $url = 'https://my-update-api.com/plugins/plugin-name'; // Custom API GET endpoint $pluginUpdater = new PluginUpdater( $file, $url ); /* * Keys are the fields that WordPress is expecting (look at the WP Plugin Info API response). * Values are the keys returned by your custom API. * * Use dot notation to map nested keys. */ $pluginUpdater->setDataMap( [ 'requires' => 'requires.wp', 'requires' => 'requires.php', 'banners.2x' => 'banners.retina', ] ); /* * Explicitly set specific values that will be provided to WordPress. */ $pluginUpdater->setDataOverrides( [ 'banners' => [ '2x' => 'https://my.cdn.com/banner-123-retina.jpg', '1x' => 'https://my.cdn.com/banner-123.jpg', ], 'icons' => [ '2x' => 'https://my.cdn.com/icon-123-retina.jpg', '1x' => 'https://my.cdn.com/icon-123.jpg', ], ] );
主题
此包假定您的自定义主题信息API将以与WordPress主题信息API相同的形状响应。但是,如果您的API响应具有不同的形状,您可以将字段映射到您的API返回的字段。
用法
基本示例
<?php /** * Theme Name: My Theme */ require __DIR__ . '/vendor/autoload.php'; use WP_Forge\WPUpdateHandler\ThemeUpdater; $url = 'https://my-update-api.com/theme/theme-name'; // Custom API GET endpoint new ThemeUpdater( wp_get_theme('my-theme'), $url );
具有数据映射和数据覆盖的高级示例
<?php /** * Theme Name: My Theme */ require __DIR__ . '/vendor/autoload.php'; use WP_Forge\WPUpdateHandler\ThemeUpdater; $theme = wp_get_theme('my-theme'); // Get the theme's WP_Theme instance. $url = 'https://my-update-api.com/themes/theme-name'; // Custom API GET endpoint $themeUpdater = new ThemeUpdater( $file, $url ); /* * Keys are the fields that WordPress is expecting (look at the WP Theme Info API response). * Values are the keys returned by your custom API. * * Use dot notation to map nested keys. */ $themeUpdater->setDataMap( [ 'requires' => 'requires.wp', 'requires' => 'requires.php', 'banners.2x' => 'banners.retina', ] ); /* * Explicitly set specific values that will be provided to WordPress. */ $themeUpdater->setDataOverrides( [ 'banners' => [ '2x' => 'https://my.cdn.com/banner-123-retina.jpg', '1x' => 'https://my.cdn.com/banner-123.jpg', ], 'icons' => [ '2x' => 'https://my.cdn.com/icon-123-retina.jpg', '1x' => 'https://my.cdn.com/icon-123.jpg', ], ] );