Last active
November 14, 2024 23:56
-
-
Save afragen/494f5674ab18947a865c12d94f76155d to your computer and use it in GitHub Desktop.
Fixes Rollback Auto-Update scraping when `home_url('/')` is redirected.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Fix Rollback Auto-Update scrape for home_url redirect. | |
* | |
* @package Fix_RAU_Scrape_Redirect | |
* | |
* Plugin Name: Fix Rollback Auto-Update HomeURL redirect | |
* Plugin URI: https://gist.github.com/afragen/494f5674ab18947a865c12d94f76155d | |
* Description: Redirecting the home URL can interfere with Rollback Auto-Update scraping. This fixes by adding the scrape query args when appropriate. | |
* Version: 0.1.0 | |
* Author: Andy Fragen | |
* License: MIT | |
* Requires at least: 6.6 | |
* Requires PHP: 7.4 | |
* Gist Plugin URI: https://gist.github.com/afragen/494f5674ab18947a865c12d94f76155d | |
*/ | |
namespace WP_Upgrade_Install_Team; | |
add_filter( 'wp_redirect', __NAMESPACE__ . '\filter_wp_redirect', 10, 1 ); | |
/** | |
* Filters the redirect location. | |
* | |
* @param string $location The path or URL to redirect to. | |
* @return string The path or URL to redirect to. | |
*/ | |
function filter_wp_redirect( string $location ): string { | |
if ( isset( $_REQUEST['wp_scrape_key'], $_REQUEST['wp_scrape_nonce'] ) ) { | |
$location = add_query_arg( | |
array( | |
'wp_scrape_key' => $_REQUEST['wp_scrape_key'], | |
'wp_scrape_nonce' => $_REQUEST['wp_scrape_nonce'], | |
), | |
$location | |
); | |
} | |
return $location; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment