rollback.php 3.6 KB

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