← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Rollback.php
+33
-9
3.1.3
→
3.10.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_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->product->get_version() ) . 'versions'; | |
| 101 | + $cache_key = $this->product->get_cache_key(); | |
| 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,9 +119,11 @@ | ||
| 119 | 119 | $url = $this->get_versions_api_url(); |
| 120 | 120 | if ( empty( $url ) ) { |
| 121 | 121 | return []; |
| 122 | 122 | } |
| 123 | - $response = wp_remote_get( $url ); | |
| 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 | |
| 124 | 126 | if ( is_wp_error( $response ) ) { |
| 125 | 127 | return array(); |
| 126 | 128 | } |
| 127 | 129 | $response = wp_remote_retrieve_body( $response ); |
| @@ -166,9 +168,9 @@ | ||
| 166 | 168 | if ( $this->product->requires_license() && strlen( $license ) < 10 ) { |
| 167 | 169 | return ''; |
| 168 | 170 | } |
| 169 | 171 | |
| 170 | - return sprintf( '%s?edd_action=get_versions&name=%s&url=%s&license=%s', $this->product->get_store_url(), urlencode( $this->product->get_name() ), urlencode( get_site_url() ), $license ); | |
| 172 | + return sprintf( '%slicense/versions/%s/%s/%s/%s', Product::API_URL, rawurlencode( $this->product->get_name() ), $license, urlencode( get_site_url() ), $this->product->get_version() ); | |
| 171 | 173 | } |
| 172 | 174 | |
| 173 | 175 | /** |
| 174 | 176 | * Show the rollback links in the plugin page. |
| @@ -190,9 +192,9 @@ | ||
| 190 | 192 | /** |
| 191 | 193 | * Start the rollback operation. |
| 192 | 194 | */ |
| 193 | 195 | public function start_rollback() { |
| 194 | - if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], $this->product->get_key() . '_rollback' ) ) { | |
| 196 | + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], $this->product->get_key() . '_rollback' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 195 | 197 | wp_nonce_ays( '' ); |
| 196 | 198 | } |
| 197 | 199 | |
| 198 | 200 | if ( $this->product->is_plugin() ) { |
| @@ -227,11 +229,14 @@ | ||
| 227 | 229 | set_site_transient( 'update_plugins', $plugin_transient ); |
| 228 | 230 | |
| 229 | 231 | $transient = get_transient( $this->product->get_key() . '_warning_rollback' ); |
| 230 | 232 | |
| 233 | + // Style fix for the api link that gets outside the content. | |
| 234 | + echo '<style>body#error-page{word-break:break-word;}</style>'; | |
| 235 | + | |
| 231 | 236 | if ( false === $transient ) { |
| 232 | 237 | set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 ); |
| 233 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); | |
| 238 | + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 234 | 239 | $title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version ); |
| 235 | 240 | $plugin = $plugin_folder . '/' . $plugin_file; |
| 236 | 241 | $nonce = 'upgrade-plugin_' . $plugin; |
| 237 | 242 | $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin ); |
| @@ -240,9 +245,9 @@ | ||
| 240 | 245 | $upgrader->upgrade( $plugin ); |
| 241 | 246 | delete_transient( $this->product->get_key() . '_warning_rollback' ); |
| 242 | 247 | wp_die( |
| 243 | 248 | '', |
| 244 | - $title, | |
| 249 | + esc_attr( $title ), | |
| 245 | 250 | array( |
| 246 | 251 | 'response' => 200, |
| 247 | 252 | ) |
| 248 | 253 | ); |
| @@ -267,11 +272,14 @@ | ||
| 267 | 272 | set_site_transient( 'update_themes', $transient ); |
| 268 | 273 | |
| 269 | 274 | $transient = get_transient( $this->product->get_key() . '_warning_rollback' ); |
| 270 | 275 | |
| 276 | + // Style fix for the api link that gets outside the content. | |
| 277 | + echo '<style>body#error-page{word-break:break-word;}</style>'; | |
| 278 | + | |
| 271 | 279 | if ( false === $transient ) { |
| 272 | 280 | set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 ); |
| 273 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); | |
| 281 | + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 274 | 282 | $title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version ); |
| 275 | 283 | $theme = $folder . '/style.css'; |
| 276 | 284 | $nonce = 'upgrade-theme_' . $theme; |
| 277 | 285 | $url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme ); |
| @@ -280,9 +288,9 @@ | ||
| 280 | 288 | $upgrader->upgrade( $theme ); |
| 281 | 289 | delete_transient( $this->product->get_key() . '_warning_rollback' ); |
| 282 | 290 | wp_die( |
| 283 | 291 | '', |
| 284 | - $title, | |
| 292 | + esc_attr( $title ), | |
| 285 | 293 | array( |
| 286 | 294 | 'response' => 200, |
| 287 | 295 | ) |
| 288 | 296 | ); |
| @@ -334,9 +342,9 @@ | ||
| 334 | 342 | * |
| 335 | 343 | * @return bool Which version is greater? |
| 336 | 344 | */ |
| 337 | 345 | public function sort_rollback_array( $a, $b ) { |
| 338 | - return version_compare( $a['version'], $b['version'], '<' ) > 0; | |
| 346 | + return version_compare( $b['version'], $a['version'] ); | |
| 339 | 347 | } |
| 340 | 348 | |
| 341 | 349 | /** |
| 342 | 350 | * Load module logic. |
| @@ -366,11 +374,27 @@ | ||
| 366 | 374 | ); |
| 367 | 375 | } |
| 368 | 376 | |
| 369 | 377 | /** |
| 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 | + /** | |
| 370 | 390 | * 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. |
| 371 | 391 | */ |
| 372 | 392 | public function add_hooks() { |
| 373 | 393 | add_action( 'admin_post_' . $this->product->get_key() . '_rollback', array( $this, 'start_rollback' ) ); |
| 374 | 394 | 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 ); | |
| 375 | 399 | } |
| 376 | 400 | } |