Skip to content

Commit

Permalink
Merge pull request #225 from Codeinwp/fix/theme_rollback_wp63
Browse files Browse the repository at this point in the history
fix: rollback for themes WP6.3
  • Loading branch information
preda-bogdan authored Apr 4, 2024
2 parents d2ed2ef + 23cf7e8 commit 2bc005f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Modules/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ 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( $theme );
delete_transient( $this->product->get_key() . '_warning_rollback' );
Expand Down

0 comments on commit 2bc005f

Please sign in to comment.