Skip to content

Commit

Permalink
Fix theme update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Feb 1, 2024
1 parent 5fbc37e commit 6925f2c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Theme_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ protected function get_item_list() {
protected function filter_item_list( $items, $args ) {
$theme_files = array();
foreach ( $args as $arg ) {
$theme_files[] = $this->fetcher->get_check( $arg )->get_stylesheet_directory();
$theme_files[] = $this->fetcher->get_check( $arg )->get_stylesheet();
}

return Utils\pick_fields( $items, $theme_files );
Expand Down
16 changes: 10 additions & 6 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,10 @@ protected function update_many( $args, $assoc_args ) {
}
unset( $items_to_update[ $plugin->file ] );
} elseif ( 'theme' === $this->item_type ) {
$theme_root = get_theme_root() . '/' . $item;
if ( ! is_dir( $theme_root ) ) {
continue;
$theme = wp_get_theme( $item );
if ( $theme->exists() ) {
unset( $items_to_update[ $theme->get_stylesheet() ] );
}
unset( $items_to_update[ $theme_root ] );
}
}
}
Expand Down Expand Up @@ -431,8 +430,13 @@ protected function update_many( $args, $assoc_args ) {
$transient_filter = function ( $transient ) use ( $items_to_update ) {
foreach ( $items_to_update as $name => $item_data ) {
if ( isset( $transient->response[ $name ] ) ) {
$transient->response[ $name ]->new_version = $item_data['update_version'];
$transient->response[ $name ]->package = $item_data['update_package'];
if ( is_object( $transient->response[ $name ] ) ) {
$transient->response[ $name ]->new_version = $item_data['update_version'];
$transient->response[ $name ]->package = $item_data['update_package'];
} else {
$transient->response[ $name ]['new_version'] = $item_data['update_version'];
$transient->response[ $name ]['package'] = $item_data['update_package'];
}
}
}
return $transient;
Expand Down
20 changes: 10 additions & 10 deletions src/WP_CLI/ParseThemeNameInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,38 @@ private function get_all_themes() {
}

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

$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;
$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;

$items[ $file ] = [
$items[ $stylesheet ] = [
'name' => $key,
'status' => $this->get_status( $theme ),
'update' => (bool) $update_info,
'update_version' => isset( $update_info['new_version'] ) ? $update_info['new_version'] : null,
'update_package' => isset( $update_info['package'] ) ? $update_info['package'] : null,
'version' => $theme->get( 'Version' ),
'update_id' => $theme->get_stylesheet(),
'update_id' => $stylesheet,
'title' => $theme->get( 'Name' ),
'description' => wordwrap( $theme->get( 'Description' ) ),
'author' => $theme->get( 'Author' ),
'auto_update' => in_array( $theme->get_stylesheet(), $auto_updates, true ),
'auto_update' => in_array( $stylesheet, $auto_updates, true ),
];

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

if ( is_multisite() ) {
if ( ! empty( $site_enabled[ $key ] ) && ! empty( $network_enabled[ $key ] ) ) {
$items[ $file ]['enabled'] = 'network,site';
$items[ $stylesheet ]['enabled'] = 'network,site';
} elseif ( ! empty( $network_enabled[ $key ] ) ) {
$items[ $file ]['enabled'] = 'network';
$items[ $stylesheet ]['enabled'] = 'network';
} elseif ( ! empty( $site_enabled[ $key ] ) ) {
$items[ $file ]['enabled'] = 'site';
$items[ $stylesheet ]['enabled'] = 'site';
} else {
$items[ $file ]['enabled'] = 'no';
$items[ $stylesheet ]['enabled'] = 'no';
}
}
}
Expand Down

0 comments on commit 6925f2c

Please sign in to comment.