← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Rollback.php
+8
-32
3.10.1
→
3.4.7
View file →
| @@ -97,9 +97,9 @@ | ||
| 97 | 97 | * @return array Array of versions. |
| 98 | 98 | */ |
| 99 | 99 | private function get_api_versions() { |
| 100 | 100 | |
| 101 | - $cache_key = $this->product->get_cache_key(); | |
| 101 | + $cache_key = $this->product->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->product->get_version() ) . 'versions'; | |
| 102 | 102 | $cache_versions = get_transient( $cache_key ); |
| 103 | 103 | if ( false === $cache_versions ) { |
| 104 | 104 | $versions = $this->get_remote_versions(); |
| 105 | 105 | set_transient( $cache_key, $versions, 5 * DAY_IN_SECONDS ); |
| @@ -119,11 +119,9 @@ | ||
| 119 | 119 | $url = $this->get_versions_api_url(); |
| 120 | 120 | if ( empty( $url ) ) { |
| 121 | 121 | return []; |
| 122 | 122 | } |
| 123 | - $response = function_exists( 'wp_remote_get_wp_remote_get' ) | |
| 124 | - ? wp_remote_get_wp_remote_get( $url ) | |
| 125 | - : wp_remote_get( $url ); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get | |
| 123 | + $response = wp_remote_get( $url ); | |
| 126 | 124 | if ( is_wp_error( $response ) ) { |
| 127 | 125 | return array(); |
| 128 | 126 | } |
| 129 | 127 | $response = wp_remote_retrieve_body( $response ); |
| @@ -192,9 +190,9 @@ | ||
| 192 | 190 | /** |
| 193 | 191 | * Start the rollback operation. |
| 194 | 192 | */ |
| 195 | 193 | public function start_rollback() { |
| 196 | - if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], $this->product->get_key() . '_rollback' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 194 | + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], $this->product->get_key() . '_rollback' ) ) { | |
| 197 | 195 | wp_nonce_ays( '' ); |
| 198 | 196 | } |
| 199 | 197 | |
| 200 | 198 | if ( $this->product->is_plugin() ) { |
| @@ -229,14 +227,11 @@ | ||
| 229 | 227 | set_site_transient( 'update_plugins', $plugin_transient ); |
| 230 | 228 | |
| 231 | 229 | $transient = get_transient( $this->product->get_key() . '_warning_rollback' ); |
| 232 | 230 | |
| 233 | - // Style fix for the api link that gets outside the content. | |
| 234 | - echo '<style>body#error-page{word-break:break-word;}</style>'; | |
| 235 | - | |
| 236 | 231 | if ( false === $transient ) { |
| 237 | 232 | set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 ); |
| 238 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 233 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); | |
| 239 | 234 | $title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version ); |
| 240 | 235 | $plugin = $plugin_folder . '/' . $plugin_file; |
| 241 | 236 | $nonce = 'upgrade-plugin_' . $plugin; |
| 242 | 237 | $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin ); |
| @@ -245,9 +240,9 @@ | ||
| 245 | 240 | $upgrader->upgrade( $plugin ); |
| 246 | 241 | delete_transient( $this->product->get_key() . '_warning_rollback' ); |
| 247 | 242 | wp_die( |
| 248 | 243 | '', |
| 249 | - esc_attr( $title ), | |
| 244 | + $title, | |
| 250 | 245 | array( |
| 251 | 246 | 'response' => 200, |
| 252 | 247 | ) |
| 253 | 248 | ); |
| @@ -272,14 +267,11 @@ | ||
| 272 | 267 | set_site_transient( 'update_themes', $transient ); |
| 273 | 268 | |
| 274 | 269 | $transient = get_transient( $this->product->get_key() . '_warning_rollback' ); |
| 275 | 270 | |
| 276 | - // Style fix for the api link that gets outside the content. | |
| 277 | - echo '<style>body#error-page{word-break:break-word;}</style>'; | |
| 278 | - | |
| 279 | 271 | if ( false === $transient ) { |
| 280 | 272 | set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 ); |
| 281 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 273 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); | |
| 282 | 274 | $title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version ); |
| 283 | 275 | $theme = $folder . '/style.css'; |
| 284 | 276 | $nonce = 'upgrade-theme_' . $theme; |
| 285 | 277 | $url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme ); |
| @@ -288,9 +280,9 @@ | ||
| 288 | 280 | $upgrader->upgrade( $theme ); |
| 289 | 281 | delete_transient( $this->product->get_key() . '_warning_rollback' ); |
| 290 | 282 | wp_die( |
| 291 | 283 | '', |
| 292 | - esc_attr( $title ), | |
| 284 | + $title, | |
| 293 | 285 | array( |
| 294 | 286 | 'response' => 200, |
| 295 | 287 | ) |
| 296 | 288 | ); |
| @@ -342,9 +334,9 @@ | ||
| 342 | 334 | * |
| 343 | 335 | * @return bool Which version is greater? |
| 344 | 336 | */ |
| 345 | 337 | public function sort_rollback_array( $a, $b ) { |
| 346 | - return version_compare( $b['version'], $a['version'] ); | |
| 338 | + return version_compare( $a['version'], $b['version'], '<' ) > 0; | |
| 347 | 339 | } |
| 348 | 340 | |
| 349 | 341 | /** |
| 350 | 342 | * Load module logic. |
| @@ -374,27 +366,11 @@ | ||
| 374 | 366 | ); |
| 375 | 367 | } |
| 376 | 368 | |
| 377 | 369 | /** |
| 378 | - * Fires after the option has been updated. | |
| 379 | - * | |
| 380 | - * @param mixed $old_value The old option value. | |
| 381 | - * @param mixed $value The new option value. | |
| 382 | - * @param string $option Option name. | |
| 383 | - */ | |
| 384 | - public function update_active_plugins_action( $old_value, $value, $option ) { | |
| 385 | - delete_site_transient( 'update_plugins' ); | |
| 386 | - wp_cache_delete( 'plugins', 'plugins' ); | |
| 387 | - } | |
| 388 | - | |
| 389 | - /** | |
| 390 | 370 | * Set the rollback hook. Strangely, this does not work if placed in the ThemeIsle_SDK_Rollback class, so it is being called from there instead. |
| 391 | 371 | */ |
| 392 | 372 | public function add_hooks() { |
| 393 | 373 | add_action( 'admin_post_' . $this->product->get_key() . '_rollback', array( $this, 'start_rollback' ) ); |
| 394 | 374 | add_action( 'admin_footer', array( $this, 'add_footer' ) ); |
| 395 | - | |
| 396 | - // This hook will be invoked after the plugin activation. | |
| 397 | - // We use this to force an update of the cache so that Update is present immediate after a rollback. | |
| 398 | - add_action( 'update_option_active_plugins', array( $this, 'update_active_plugins_action' ), 10, 3 ); | |
| 399 | 375 | } |
| 400 | 376 | } |