From 6fcfc7f62beeed9de219c146daafa45ecfd328a4 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sat, 5 Jul 2025 12:47:38 -0700 Subject: [PATCH] Refactor for reuse of functions elsewhere (#150) --- inc/updater/namespace.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/inc/updater/namespace.php b/inc/updater/namespace.php index 41a2b3a..bd5404e 100644 --- a/inc/updater/namespace.php +++ b/inc/updater/namespace.php @@ -15,7 +15,7 @@ if ( ! defined( 'WPINC' ) ) { * Bootstrap. */ function bootstrap() { - add_action( 'init', __NAMESPACE__ . '\\init' ); + add_action( 'init', __NAMESPACE__ . '\\run' ); } /** @@ -23,9 +23,9 @@ function bootstrap() { * * @return stdClass */ -function init() { +function get_packages() { /** @var array */ - $package_arr = []; + $packages = []; // Seems to be required for PHPUnit testing on GitHub workflow. if ( ! function_exists( 'get_plugins' ) ) { @@ -41,7 +41,7 @@ function init() { $plugin_id = get_file_data( $plugin_path . $file, [ 'PluginID' => 'Plugin ID' ] )['PluginID']; if ( ! empty( $plugin_id ) ) { - $package_arr[] = $plugin_path . $file; + $packages['plugins'][] = $plugin_path . $file; } } @@ -54,11 +54,11 @@ function init() { $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'; + $packages['themes'][] = $theme_path . $file . '/style.css'; } } - run( $package_arr ); + return $packages; } /** @@ -66,8 +66,12 @@ function init() { * * @return void */ -function run( $package_arr ) { - foreach ( $package_arr as $package ) { +function run() { + $packages = get_packages(); + $plugins = $packages['plugins'] ?? []; + $themes = $packages['themes'] ?? []; + $packages = array_merge( $plugins, $themes); + foreach ( $packages as $package ) { ( new Git_Updater\Lite( $package ) )->run(); } }