Skip to content

Commit a913b35

Browse files
Copilotswissspidy
andcommitted
Add detailed comments explaining the code duplication in get_upgrader
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 07282aa commit a913b35

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ protected function get_upgrader( $assoc_args ) {
390390
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
391391
$upgrader_class = $this->get_upgrader_class( $force );
392392

393-
// Use custom upgrader skin for extensions to display update progress
393+
// We need to use ExtensionUpgraderSkin instead of the default UpgraderSkin
394+
// to display which extension is being updated. Since the skin is passed to
395+
// the upgrader constructor and cannot be changed afterward, we must duplicate
396+
// the upgrader creation logic from Utils\get_upgrader() here.
394397
if ( ! class_exists( '\WP_Upgrader' ) ) {
395398
if ( file_exists( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ) ) {
396399
include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
@@ -403,6 +406,10 @@ protected function get_upgrader( $assoc_args ) {
403406
}
404407
}
405408

409+
// Check if the upgrader class constructor supports the insecure flag.
410+
// This check is done on each call to maintain compatibility with the
411+
// original Utils\get_upgrader() behavior, though it could be optimized
412+
// with caching if performance becomes a concern.
406413
$uses_insecure_flag = false;
407414

408415
$reflection = new \ReflectionClass( $upgrader_class );

0 commit comments

Comments
 (0)