PluginUpgrader::rollback()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 26
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 26
ccs 0
cts 24
cp 0
rs 9.584
cc 3
nc 2
nop 2
crap 12
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&#8230', 'admin-text', 'site-reviews');
39
    }
40
}
41