Skip to content

Commit

Permalink
Resolve issue with an incorrectly set file path causing issues with h…
Browse files Browse the repository at this point in the history
…ooks to work. For more info see: https://wordpress.org/support/topic/found-a-bug-19/
  • Loading branch information
DevinWalker committed Jan 10, 2023
1 parent 82c49e7 commit 0c6c323
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 16 additions & 5 deletions includes/class-rollback-plugin-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public function rollback( $plugin, $args = array() ) {

$url = $download_endpoint . $plugin_slug . '.' . $plugin_version . '.zip';

add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
$is_plugin_active = is_plugin_active( $plugin );

add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
add_filter( 'upgrader_pre_install', array( $this, 'active_before' ), 10, 2 );
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
add_filter( 'upgrader_post_install', array( $this, 'active_after' ), 10, 2 );

$this->run( array(
'package' => $url,
Expand All @@ -66,17 +70,24 @@ public function rollback( $plugin, $args = array() ) {
'plugin' => $plugin,
'type' => 'plugin',
'action' => 'update',
'bulk' => 'false',
),
) );

// Cleanup our hooks, in case something else does a upgrade on this connection.
remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
remove_filter( 'upgrader_pre_install', array( $this, 'active_before' ) );
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
remove_filter( 'upgrader_post_install', array( $this, 'active_after' ) );

if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}

if( $is_plugin_active ) {
activate_plugin( $plugin );
}

// Force refresh of plugin update information.
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );

Expand Down
3 changes: 1 addition & 2 deletions includes/rollback-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// Theme rollback.
if ( ! empty( $_GET['theme_file'] ) && file_exists( WP_CONTENT_DIR . '/themes/' . $_GET['theme_file'] ) ) {


// Theme specific vars.
$title = $_GET['rollback_name'];
$nonce = 'upgrade-theme_' . $_GET['theme_file'];
Expand Down Expand Up @@ -39,7 +38,7 @@

$upgrader = new WP_Rollback_Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin', 'version' ) ) );

$result = $upgrader->rollback( $this->plugin_file );
$result = $upgrader->rollback( plugin_basename($this->plugin_file) );

if ( ! is_wp_error( $result ) && $result ) {
do_action( 'wpr_plugin_success', $_GET['plugin_file'], $version );
Expand Down

0 comments on commit 0c6c323

Please sign in to comment.