mirror of
https://ghproxy.net/https://github.com/fairpm/fair-plugin.git
synced 2025-09-04 08:39:02 +08:00
Signed-off-by: Ryan McCue <me@ryanmccue.info> Signed-off-by: Andy Fragen <andy@thefragens.com> Signed-off-by: costdev <79332690+costdev@users.noreply.github.com> Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com> Signed-off-by: Joe Dolson <design@joedolson.com> Co-authored-by: Andy Fragen <andy@thefragens.com> Co-authored-by: costdev <79332690+costdev@users.noreply.github.com> Co-authored-by: Joe Dolson <design@joedolson.com>
66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Update FAIR packages.
|
|
*
|
|
* @package FAIR
|
|
*/
|
|
|
|
namespace FAIR\Updater;
|
|
|
|
use FAIR\Packages;
|
|
|
|
/**
|
|
* Bootstrap.
|
|
*/
|
|
function bootstrap() {
|
|
add_action( 'init', __NAMESPACE__ . '\\run' );
|
|
}
|
|
|
|
/**
|
|
* Gather all plugins/themes with data in Update URI and DID header.
|
|
*
|
|
* @return array
|
|
*/
|
|
function get_packages() : array {
|
|
$packages = [];
|
|
|
|
// 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 ) {
|
|
$plugin_id = get_file_data( $plugin_path . $file, [ 'PluginID' => 'Plugin ID' ] )['PluginID'];
|
|
if ( ! empty( $plugin_id ) ) {
|
|
$packages['plugins'][ $plugin_id ] = $plugin_path . $file;
|
|
}
|
|
}
|
|
|
|
$theme_path = WP_CONTENT_DIR . '/themes/';
|
|
$themes = wp_get_themes();
|
|
foreach ( $themes as $file => $theme ) {
|
|
$theme_id = get_file_data( $theme_path . $file . '/style.css', [ 'ThemeID' => 'Theme ID' ] )['ThemeID'];
|
|
if ( ! empty( $theme_id ) ) {
|
|
$packages['themes'][ $theme_id ] = $theme_path . $file . '/style.css';
|
|
}
|
|
}
|
|
|
|
return $packages;
|
|
}
|
|
|
|
/**
|
|
* Run FAIR\Updater\Updater for potential packages.
|
|
*
|
|
* @return void
|
|
*/
|
|
function run() {
|
|
$packages = get_packages();
|
|
$plugins = $packages['plugins'] ?? [];
|
|
$themes = $packages['themes'] ?? [];
|
|
$packages = array_merge( $plugins, $themes );
|
|
foreach ( $packages as $did => $filepath ) {
|
|
( new Updater( $did, $filepath ) )->run();
|
|
}
|
|
}
|