Skip to content

Commit 6925f2c

Browse files
committed
Fix theme update logic
1 parent 5fbc37e commit 6925f2c

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/Theme_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ protected function get_item_list() {
439439
protected function filter_item_list( $items, $args ) {
440440
$theme_files = array();
441441
foreach ( $args as $arg ) {
442-
$theme_files[] = $this->fetcher->get_check( $arg )->get_stylesheet_directory();
442+
$theme_files[] = $this->fetcher->get_check( $arg )->get_stylesheet();
443443
}
444444

445445
return Utils\pick_fields( $items, $theme_files );

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,10 @@ protected function update_many( $args, $assoc_args ) {
370370
}
371371
unset( $items_to_update[ $plugin->file ] );
372372
} elseif ( 'theme' === $this->item_type ) {
373-
$theme_root = get_theme_root() . '/' . $item;
374-
if ( ! is_dir( $theme_root ) ) {
375-
continue;
373+
$theme = wp_get_theme( $item );
374+
if ( $theme->exists() ) {
375+
unset( $items_to_update[ $theme->get_stylesheet() ] );
376376
}
377-
unset( $items_to_update[ $theme_root ] );
378377
}
379378
}
380379
}
@@ -431,8 +430,13 @@ protected function update_many( $args, $assoc_args ) {
431430
$transient_filter = function ( $transient ) use ( $items_to_update ) {
432431
foreach ( $items_to_update as $name => $item_data ) {
433432
if ( isset( $transient->response[ $name ] ) ) {
434-
$transient->response[ $name ]->new_version = $item_data['update_version'];
435-
$transient->response[ $name ]->package = $item_data['update_package'];
433+
if ( is_object( $transient->response[ $name ] ) ) {
434+
$transient->response[ $name ]->new_version = $item_data['update_version'];
435+
$transient->response[ $name ]->package = $item_data['update_package'];
436+
} else {
437+
$transient->response[ $name ]['new_version'] = $item_data['update_version'];
438+
$transient->response[ $name ]['package'] = $item_data['update_package'];
439+
}
436440
}
437441
}
438442
return $transient;

src/WP_CLI/ParseThemeNameInput.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,38 @@ private function get_all_themes() {
7676
}
7777

7878
foreach ( wp_get_themes() as $key => $theme ) {
79-
$file = $theme->get_stylesheet_directory();
79+
$stylesheet = $theme->get_stylesheet();
8080

81-
$update_info = ( isset( $all_update_info->response[ $theme->get_stylesheet() ] ) && null !== $all_update_info->response[ $theme->get_stylesheet() ] ) ? (array) $all_update_info->response[ $theme->get_stylesheet() ] : null;
81+
$update_info = ( isset( $all_update_info->response[ $stylesheet ] ) && null !== $all_update_info->response[ $theme->get_stylesheet() ] ) ? (array) $all_update_info->response[ $theme->get_stylesheet() ] : null;
8282

83-
$items[ $file ] = [
83+
$items[ $stylesheet ] = [
8484
'name' => $key,
8585
'status' => $this->get_status( $theme ),
8686
'update' => (bool) $update_info,
8787
'update_version' => isset( $update_info['new_version'] ) ? $update_info['new_version'] : null,
8888
'update_package' => isset( $update_info['package'] ) ? $update_info['package'] : null,
8989
'version' => $theme->get( 'Version' ),
90-
'update_id' => $theme->get_stylesheet(),
90+
'update_id' => $stylesheet,
9191
'title' => $theme->get( 'Name' ),
9292
'description' => wordwrap( $theme->get( 'Description' ) ),
9393
'author' => $theme->get( 'Author' ),
94-
'auto_update' => in_array( $theme->get_stylesheet(), $auto_updates, true ),
94+
'auto_update' => in_array( $stylesheet, $auto_updates, true ),
9595
];
9696

9797
// Compare version and update information in theme list.
9898
if ( isset( $theme_version_info[ $key ] ) && false === $theme_version_info[ $key ] ) {
99-
$items[ $file ]['update'] = 'version higher than expected';
99+
$items[ $stylesheet ]['update'] = 'version higher than expected';
100100
}
101101

102102
if ( is_multisite() ) {
103103
if ( ! empty( $site_enabled[ $key ] ) && ! empty( $network_enabled[ $key ] ) ) {
104-
$items[ $file ]['enabled'] = 'network,site';
104+
$items[ $stylesheet ]['enabled'] = 'network,site';
105105
} elseif ( ! empty( $network_enabled[ $key ] ) ) {
106-
$items[ $file ]['enabled'] = 'network';
106+
$items[ $stylesheet ]['enabled'] = 'network';
107107
} elseif ( ! empty( $site_enabled[ $key ] ) ) {
108-
$items[ $file ]['enabled'] = 'site';
108+
$items[ $stylesheet ]['enabled'] = 'site';
109109
} else {
110-
$items[ $file ]['enabled'] = 'no';
110+
$items[ $stylesheet ]['enabled'] = 'no';
111111
}
112112
}
113113
}

0 commit comments

Comments
 (0)