mirror of
https://ghproxy.net/https://github.com/fairpm/fair-plugin.git
synced 2025-09-04 08:50:35 +08:00
add Git Updater Lite based updater for packages (#131)
This commit is contained in:
parent
1b98b515c6
commit
245370cbe9
3 changed files with 75 additions and 0 deletions
|
@ -36,6 +36,7 @@ function bootstrap() {
|
|||
Pings\bootstrap();
|
||||
Salts\bootstrap();
|
||||
Settings\bootstrap();
|
||||
Updater\bootstrap();
|
||||
User_Notification\bootstrap();
|
||||
Version_Check\bootstrap();
|
||||
|
||||
|
|
73
inc/updater/namespace.php
Normal file
73
inc/updater/namespace.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace FAIR\Updater;
|
||||
|
||||
use Fragen\Git_Updater;
|
||||
|
||||
/**
|
||||
* Exit if called directly.
|
||||
*/
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap.
|
||||
*/
|
||||
function bootstrap() {
|
||||
add_action( 'init', __NAMESPACE__ . '\\init' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather all plugins/themes with data in Update URI and DID header.
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
function init() {
|
||||
/** @var array */
|
||||
$package_arr = [];
|
||||
|
||||
// Seems to be required for PHPUnit testing on GitHub workflow.
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
$plugin_path = trailingslashit( WP_PLUGIN_DIR );
|
||||
$plugins = get_plugins();
|
||||
foreach ( $plugins as $file => $plugin ) {
|
||||
if ( empty( $plugin['UpdateURI'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$plugin_id = get_file_data( $plugin_path . $file, [ 'PluginID' => 'Plugin ID' ] )['PluginID'];
|
||||
|
||||
if ( ! empty( $plugin_id ) ) {
|
||||
$package_arr[] = $plugin_path . $file;
|
||||
}
|
||||
}
|
||||
|
||||
$theme_path = WP_CONTENT_DIR . '/themes/';
|
||||
$themes = wp_get_themes();
|
||||
foreach ( $themes as $file => $theme ) {
|
||||
if ( empty( $theme->get( 'UpdateURI' ) ) ) {
|
||||
continue;
|
||||
}
|
||||
$theme_id = get_file_data( $theme_path . $file . '/style.css', [ 'ThemeID' => 'Theme ID' ] )['ThemeID'];
|
||||
|
||||
if ( ! empty( $theme_id ) ) {
|
||||
$package_arr[] = $theme_path . $file . '/style.css';
|
||||
}
|
||||
}
|
||||
|
||||
run( $package_arr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Git Updater Lite for potential packages.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function run( $package_arr ) {
|
||||
foreach ( $package_arr as $package ) {
|
||||
( new Git_Updater\Lite( $package ) )->run();
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ require_once __DIR__ . '/inc/importers/namespace.php';
|
|||
require_once __DIR__ . '/inc/pings/namespace.php';
|
||||
require_once __DIR__ . '/inc/salts/namespace.php';
|
||||
require_once __DIR__ . '/inc/settings/namespace.php';
|
||||
require_once __DIR__ . '/inc/updater/namespace.php';
|
||||
require_once __DIR__ . '/inc/user-notification/namespace.php';
|
||||
require_once __DIR__ . '/inc/version-check/namespace.php';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue