From 6925f2c44831b2ed97d32ac84653e5d959eeeb76 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 1 Feb 2024 17:28:10 +0100 Subject: [PATCH] Fix theme update logic --- src/Theme_Command.php | 2 +- src/WP_CLI/CommandWithUpgrade.php | 16 ++++++++++------ src/WP_CLI/ParseThemeNameInput.php | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Theme_Command.php b/src/Theme_Command.php index 2cde5b4a..d65d97fa 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -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 ); diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index a759d541..566c25fc 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -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 ] ); } } } @@ -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; diff --git a/src/WP_CLI/ParseThemeNameInput.php b/src/WP_CLI/ParseThemeNameInput.php index a5924ee2..34d75a82 100644 --- a/src/WP_CLI/ParseThemeNameInput.php +++ b/src/WP_CLI/ParseThemeNameInput.php @@ -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'; } } }