1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Overrides; |
4
|
|
|
|
5
|
|
|
class PluginUpgrader extends \Plugin_Upgrader |
6
|
|
|
{ |
7
|
|
|
public function rollback($version, $args = []) |
8
|
|
|
{ |
9
|
|
|
$args = wp_parse_args($args, ['clear_update_cache' => true]); |
10
|
|
|
$this->init(); |
11
|
|
|
$this->upgrade_strings(); |
12
|
|
|
add_filter('upgrader_pre_install', [$this, 'deactivate_plugin_before_upgrade'], 10, 2); |
13
|
|
|
add_filter('upgrader_clear_destination', [$this, 'delete_old_plugin'], 10, 4); |
14
|
|
|
$plugin = dirname($this->skin->plugin); |
15
|
|
|
$this->run([ |
16
|
|
|
'package' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin, $version), |
17
|
|
|
'destination' => WP_PLUGIN_DIR, |
18
|
|
|
'clear_destination' => true, |
19
|
|
|
'clear_working' => true, |
20
|
|
|
'hook_extra' => [ |
21
|
|
|
'plugin' => $this->skin->plugin, |
22
|
|
|
'type' => 'plugin', |
23
|
|
|
'action' => 'update', |
24
|
|
|
], |
25
|
|
|
]); |
26
|
|
|
remove_filter('upgrader_pre_install', [$this, 'deactivate_plugin_before_upgrade']); |
27
|
|
|
remove_filter('upgrader_clear_destination', [$this, 'delete_old_plugin']); |
28
|
|
|
if (!$this->result || is_wp_error($this->result)) { |
29
|
|
|
return $this->result; |
30
|
|
|
} |
31
|
|
|
wp_clean_plugins_cache($args['clear_update_cache']); |
32
|
|
|
return true; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function upgrade_strings() |
36
|
|
|
{ |
37
|
|
|
parent::upgrade_strings(); |
38
|
|
|
$this->strings['process_success'] = _x('Plugin rollback successful! Please wait while it reactivates…', 'admin-text', 'site-reviews'); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|