admin-templates
1 year ago
base
4 months ago
controls
4 months ago
editor-templates
2 months ago
elements
4 months ago
interfaces
1 year ago
libraries
1 year ago
managers
2 months ago
settings
2 months ago
template-library
2 months ago
widgets
2 months ago
api.php
8 months ago
autoloader.php
7 months ago
beta-testers.php
3 years ago
compatibility.php
1 year ago
conditions.php
3 years ago
db.php
4 months ago
editor-assets-api.php
2 months ago
embed.php
1 year ago
fonts.php
1 year ago
frontend.php
2 months ago
heartbeat.php
3 years ago
maintenance-mode.php
7 months ago
maintenance.php
1 year ago
plugin.php
3 months ago
preview.php
7 months ago
rollback.php
4 months ago
shapes.php
9 months ago
stylesheet.php
8 months ago
tracker.php
6 months ago
user-data.php
7 months ago
user.php
5 months ago
utils.php
2 months ago
rollback.php
200 lines
| 1 | <?php |
| 2 | namespace Elementor; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | exit; // Exit if accessed directly. |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Elementor rollback. |
| 10 | * |
| 11 | * Elementor rollback handler class is responsible for rolling back Elementor to |
| 12 | * previous version. |
| 13 | * |
| 14 | * @since 1.5.0 |
| 15 | */ |
| 16 | class Rollback { |
| 17 | |
| 18 | /** |
| 19 | * Package URL. |
| 20 | * |
| 21 | * Holds the package URL. |
| 22 | * |
| 23 | * @since 1.5.0 |
| 24 | * @access protected |
| 25 | * |
| 26 | * @var string Package URL. |
| 27 | */ |
| 28 | protected $package_url; |
| 29 | |
| 30 | /** |
| 31 | * Version. |
| 32 | * |
| 33 | * Holds the version. |
| 34 | * |
| 35 | * @since 1.5.0 |
| 36 | * @access protected |
| 37 | * |
| 38 | * @var string Package URL. |
| 39 | */ |
| 40 | protected $version; |
| 41 | |
| 42 | /** |
| 43 | * Plugin name. |
| 44 | * |
| 45 | * Holds the plugin name. |
| 46 | * |
| 47 | * @since 1.5.0 |
| 48 | * @access protected |
| 49 | * |
| 50 | * @var string Plugin name. |
| 51 | */ |
| 52 | protected $plugin_name; |
| 53 | |
| 54 | /** |
| 55 | * Plugin slug. |
| 56 | * |
| 57 | * Holds the plugin slug. |
| 58 | * |
| 59 | * @since 1.5.0 |
| 60 | * @access protected |
| 61 | * |
| 62 | * @var string Plugin slug. |
| 63 | */ |
| 64 | protected $plugin_slug; |
| 65 | |
| 66 | /** |
| 67 | * Rollback constructor. |
| 68 | * |
| 69 | * Initializing Elementor rollback. |
| 70 | * |
| 71 | * @since 1.5.0 |
| 72 | * @access public |
| 73 | * |
| 74 | * @param array $args Optional. Rollback arguments. Default is an empty array. |
| 75 | */ |
| 76 | public function __construct( $args = [] ) { |
| 77 | foreach ( $args as $key => $value ) { |
| 78 | $this->{$key} = $value; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Print inline style. |
| 84 | * |
| 85 | * Add an inline CSS to the rollback page. |
| 86 | * |
| 87 | * @since 1.5.0 |
| 88 | * @access private |
| 89 | */ |
| 90 | private function print_inline_style() { |
| 91 | ?> |
| 92 | <style> |
| 93 | .wrap { |
| 94 | overflow: hidden; |
| 95 | max-width: 850px; |
| 96 | margin: auto; |
| 97 | font-family: Courier, monospace; |
| 98 | } |
| 99 | |
| 100 | h1 { |
| 101 | background: #D40C5C; |
| 102 | text-align: center; |
| 103 | color: #fff !important; |
| 104 | padding: 70px !important; |
| 105 | text-transform: uppercase; |
| 106 | letter-spacing: 1px; |
| 107 | } |
| 108 | |
| 109 | h1 img { |
| 110 | max-width: 300px; |
| 111 | display: block; |
| 112 | margin: auto auto 50px; |
| 113 | } |
| 114 | </style> |
| 115 | <?php |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Apply package. |
| 120 | * |
| 121 | * Change the plugin data when WordPress checks for updates. This method |
| 122 | * modifies package data to update the plugin from a specific URL containing |
| 123 | * the version package. |
| 124 | * |
| 125 | * @since 1.5.0 |
| 126 | * @access protected |
| 127 | */ |
| 128 | protected function apply_package() { |
| 129 | $update_plugins = get_site_transient( 'update_plugins' ); |
| 130 | if ( ! is_object( $update_plugins ) ) { |
| 131 | $update_plugins = new \stdClass(); |
| 132 | } |
| 133 | |
| 134 | $plugin_info = new \stdClass(); |
| 135 | $plugin_info->new_version = $this->version; |
| 136 | $plugin_info->slug = $this->plugin_slug; |
| 137 | $plugin_info->package = $this->package_url; |
| 138 | $plugin_info->url = 'https://elementor.com/'; |
| 139 | |
| 140 | $update_plugins->response[ $this->plugin_name ] = $plugin_info; |
| 141 | |
| 142 | // Remove handle beta testers. |
| 143 | remove_filter( 'pre_set_site_transient_update_plugins', [ Plugin::instance()->beta_testers, 'check_version' ] ); |
| 144 | |
| 145 | set_site_transient( 'update_plugins', $update_plugins ); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Upgrade. |
| 150 | * |
| 151 | * Run WordPress upgrade to rollback Elementor to previous version. |
| 152 | * |
| 153 | * @since 1.5.0 |
| 154 | * @access protected |
| 155 | */ |
| 156 | protected function upgrade() { |
| 157 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 158 | |
| 159 | $logo_url = ELEMENTOR_ASSETS_URL . 'images/logo-panel.svg'; |
| 160 | |
| 161 | $upgrader_args = [ |
| 162 | 'url' => 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $this->plugin_name ), |
| 163 | 'plugin' => $this->plugin_name, |
| 164 | 'nonce' => 'upgrade-plugin_' . $this->plugin_name, |
| 165 | 'title' => '<img src="' . $logo_url . '" alt="Elementor">' . esc_html__( 'Rollback to Previous Version', 'elementor' ), |
| 166 | ]; |
| 167 | |
| 168 | $this->print_inline_style(); |
| 169 | |
| 170 | add_filter( 'gettext', [ $this, 'update_installing_string' ], 10, 3 ); |
| 171 | |
| 172 | $upgrader = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( $upgrader_args ) ); |
| 173 | $upgrader->strings['installing_package'] = esc_html__( 'Installing your selected version…', 'elementor' ); |
| 174 | $upgrader->upgrade( $this->plugin_name ); |
| 175 | |
| 176 | remove_filter( 'gettext', [ $this, 'update_installing_string' ], 10 ); |
| 177 | } |
| 178 | |
| 179 | public function update_installing_string( $translation, $text, $domain ) { |
| 180 | if ( 'Installing the latest version…' === $text && 'default' === $domain ) { |
| 181 | return esc_html__( 'Installing your selected version…', 'elementor' ); |
| 182 | } |
| 183 | |
| 184 | return $translation; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Run. |
| 189 | * |
| 190 | * Rollback Elementor to previous versions. |
| 191 | * |
| 192 | * @since 1.5.0 |
| 193 | * @access public |
| 194 | */ |
| 195 | public function run() { |
| 196 | $this->apply_package(); |
| 197 | $this->upgrade(); |
| 198 | } |
| 199 | } |
| 200 |