| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* WP VR rollback. |
| 9 |
* |
| 10 |
* WP VR rollback handler class is responsible for rolling back WP VR to |
| 11 |
* previous version. |
| 12 |
* |
| 13 |
* @since 5.7.0 |
| 14 |
*/ |
| 15 |
class WPVR_Rollback { |
| 16 |
|
| 17 |
/** |
| 18 |
* Package URL. |
| 19 |
* |
| 20 |
* Holds the package URL. |
| 21 |
* |
| 22 |
* @since 5.7.0 |
| 23 |
* @access protected |
| 24 |
* |
| 25 |
* @var string Package URL. |
| 26 |
*/ |
| 27 |
protected $package_url; |
| 28 |
|
| 29 |
/** |
| 30 |
* Version. |
| 31 |
* |
| 32 |
* Holds the version. |
| 33 |
* |
| 34 |
* @since 5.7.0 |
| 35 |
* @access protected |
| 36 |
* |
| 37 |
* @var string Package URL. |
| 38 |
*/ |
| 39 |
protected $version; |
| 40 |
|
| 41 |
/** |
| 42 |
* Plugin name. |
| 43 |
* |
| 44 |
* Holds the plugin name. |
| 45 |
* |
| 46 |
* @since 5.7.0 |
| 47 |
* @access protected |
| 48 |
* |
| 49 |
* @var string Plugin name. |
| 50 |
*/ |
| 51 |
protected $plugin_name; |
| 52 |
|
| 53 |
/** |
| 54 |
* Plugin slug. |
| 55 |
* |
| 56 |
* Holds the plugin slug. |
| 57 |
* |
| 58 |
* @since 5.7.0 |
| 59 |
* @access protected |
| 60 |
* |
| 61 |
* @var string Plugin slug. |
| 62 |
*/ |
| 63 |
protected $plugin_slug; |
| 64 |
|
| 65 |
/** |
| 66 |
* Rollback constructor. |
| 67 |
* |
| 68 |
* Initializing WP VR rollback. |
| 69 |
* |
| 70 |
* @since 5.7.0 |
| 71 |
* @access public |
| 72 |
* |
| 73 |
* @param array $args Optional. Rollback arguments. Default is an empty array. |
| 74 |
*/ |
| 75 |
public function __construct( $args = [] ) { |
| 76 |
foreach ( $args as $key => $value ) { |
| 77 |
$this->{$key} = $value; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Print inline style. |
| 83 |
* |
| 84 |
* Add an inline CSS to the rollback page. |
| 85 |
* |
| 86 |
* @since 5.7.0 |
| 87 |
* @access private |
| 88 |
*/ |
| 89 |
private function print_inline_style() { |
| 90 |
?> |
| 91 |
<style> |
| 92 |
.wrap { |
| 93 |
overflow: hidden; |
| 94 |
max-width: 850px; |
| 95 |
margin: auto; |
| 96 |
font-family: Courier, monospace; |
| 97 |
} |
| 98 |
|
| 99 |
h1 { |
| 100 |
background: #4775f6; |
| 101 |
text-align: center; |
| 102 |
color: #fff !important; |
| 103 |
padding: 70px !important; |
| 104 |
text-transform: uppercase; |
| 105 |
letter-spacing: 1px; |
| 106 |
} |
| 107 |
|
| 108 |
h1 img { |
| 109 |
max-width: 300px; |
| 110 |
display: block; |
| 111 |
margin: auto auto 50px; |
| 112 |
} |
| 113 |
</style> |
| 114 |
<?php |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Apply package. |
| 119 |
* |
| 120 |
* Change the plugin data when WordPress checks for updates. This method |
| 121 |
* modifies package data to update the plugin from a specific URL containing |
| 122 |
* the version package. |
| 123 |
* |
| 124 |
* @since 5.7.0 |
| 125 |
* @access protected |
| 126 |
*/ |
| 127 |
protected function apply_package() { |
| 128 |
$update_plugins = get_site_transient( 'update_plugins' ); |
| 129 |
if ( ! is_object( $update_plugins ) ) { |
| 130 |
$update_plugins = new \stdClass(); |
| 131 |
} |
| 132 |
|
| 133 |
$plugin_info = new \stdClass(); |
| 134 |
$plugin_info->new_version = $this->version; |
| 135 |
$plugin_info->slug = $this->plugin_slug; |
| 136 |
$plugin_info->package = $this->package_url; |
| 137 |
$plugin_info->url = 'https://rextheme.com/wpvr/'; |
| 138 |
|
| 139 |
$update_plugins->response[ $this->plugin_name ] = $plugin_info; |
| 140 |
|
| 141 |
set_site_transient( 'update_plugins', $update_plugins ); |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Upgrade. |
| 146 |
* |
| 147 |
* Run WordPress upgrade to rollback WP VR to previous version. |
| 148 |
* |
| 149 |
* @since 5.7.0 |
| 150 |
* @access protected |
| 151 |
*/ |
| 152 |
protected function upgrade() { |
| 153 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
| 154 |
|
| 155 |
$this->plugin_name = 'wpvr'; |
| 156 |
$upgrader_args = [ |
| 157 |
'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this->plugin_name ), |
| 158 |
'plugin' => $this->plugin_name, |
| 159 |
'nonce' => 'upgrade-plugin_' . $this->plugin_name, |
| 160 |
'title' => __( 'WP VR Plugin Rollback', 'wpvr' ), |
| 161 |
]; |
| 162 |
|
| 163 |
$this->print_inline_style(); |
| 164 |
|
| 165 |
$upgrader = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $upgrader_args ) ); |
| 166 |
$upgrader->upgrade( $this->plugin_name ); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Run. |
| 171 |
* |
| 172 |
* Rollback WP VR to previous versions. |
| 173 |
* |
| 174 |
* @since 5.7.0 |
| 175 |
* @access public |
| 176 |
*/ |
| 177 |
public function run() { |
| 178 |
$this->apply_package(); |
| 179 |
$this->upgrade(); |
| 180 |
} |
| 181 |
} |
| 182 |
|