Skip to content

Commit

Permalink
fix: use filter during upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
preda-bogdan committed Apr 2, 2024
1 parent d5d744c commit d64848d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion load.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return;
}
// Current SDK version and path.
$themeisle_sdk_version = '3.3.16';
$themeisle_sdk_version = '3.3.18';
$themeisle_sdk_path = dirname( __FILE__ );

global $themeisle_sdk_max_version;
Expand Down
20 changes: 17 additions & 3 deletions src/Modules/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ private function start_rollback_theme() {
add_filter( 'update_theme_complete_actions', array( $this, 'alter_links_theme_upgrade' ) );
$rollback = $this->get_rollback();
$transient = get_site_transient( 'update_themes' );
$slug = $this->product->get_slug();
$folder = $slug;
$folder = $this->product->get_slug();
$version = $rollback['version'];
$temp_array = array(
'new_version' => $version,
Expand All @@ -285,8 +284,23 @@ private function start_rollback_theme() {
$nonce = 'upgrade-theme_' . $theme;
$url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );

/**
* The rollback will attach a temporary theme for the rollback to the transient.
* However, when executing the upgrade for the attached theme we need to change the slug to the original theme slug.
* This is because it will use the slug to create a temp folder for the theme used during the upgrade.
*/
add_filter(
'upgrader_package_options',
function( $options ) use ( $folder, $theme ) {
if ( isset( $options['hook_extra']['theme'] ) && $options['hook_extra']['theme'] === $theme && isset( $options['hook_extra']['temp_backup']['slug'] ) ) {
$options['hook_extra']['temp_backup']['slug'] = $folder;
}
return $options;
}
);

$upgrader = new \Theme_Upgrader( new \Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
$upgrader->upgrade( $slug );
$upgrader->upgrade( $theme );
delete_transient( $this->product->get_key() . '_warning_rollback' );
wp_die(
'',
Expand Down

0 comments on commit d64848d

Please sign in to comment.