Skip to content

Commit 0f6a304

Browse files
committed
Simplify
1 parent a913b35 commit 0f6a304

File tree

1 file changed

+1
-42
lines changed

1 file changed

+1
-42
lines changed

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -389,48 +389,7 @@ protected function get_upgrader( $assoc_args ) {
389389
$force = Utils\get_flag_value( $assoc_args, 'force', false );
390390
$insecure = Utils\get_flag_value( $assoc_args, 'insecure', false );
391391
$upgrader_class = $this->get_upgrader_class( $force );
392-
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.
397-
if ( ! class_exists( '\WP_Upgrader' ) ) {
398-
if ( file_exists( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ) ) {
399-
include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
400-
}
401-
}
402-
403-
if ( ! class_exists( '\WP_Upgrader_Skin' ) ) {
404-
if ( file_exists( ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php' ) ) {
405-
include ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
406-
}
407-
}
408-
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.
413-
$uses_insecure_flag = false;
414-
415-
$reflection = new \ReflectionClass( $upgrader_class );
416-
$constructor = $reflection->getConstructor();
417-
if ( $constructor ) {
418-
$arguments = $constructor->getParameters();
419-
foreach ( $arguments as $argument ) {
420-
if ( 'insecure' === $argument->name ) {
421-
$uses_insecure_flag = true;
422-
break;
423-
}
424-
}
425-
}
426-
427-
$skin = new ExtensionUpgraderSkin();
428-
429-
if ( $uses_insecure_flag ) {
430-
return new $upgrader_class( $skin, $insecure );
431-
}
432-
433-
return new $upgrader_class( $skin );
392+
return Utils\get_upgrader( $upgrader_class, $insecure, new ExtensionUpgraderSkin() );
434393
}
435394

436395
protected function update_many( $args, $assoc_args ) {

0 commit comments

Comments
 (0)