Skip to content

Instantly share code, notes, and snippets.

@ramonfincken
Last active November 14, 2024 14:36
Show Gist options
  • Save ramonfincken/525c9f38097a5ee19421fa0b1d94e7ce to your computer and use it in GitHub Desktop.
Save ramonfincken/525c9f38097a5ee19421fa0b1d94e7ce to your computer and use it in GitHub Desktop.
/**
* Filters the HTTP request arguments before the request is made.
*
* This function checks if the request URL is for WordPress updates or plugin/theme information.
* If so, it replaces the default API URL with our URLs.
* Cloned from wpe_use_wpe_api_services
*
* @param bool|array $c Whether to preempt the request return. Default false.
* @param array $args HTTP request arguments.
* @param string $url The request URL.
*
* @return bool|array The response or false if not preempting the request.
*/
function klarned_override_api_services( $c, $args, $url ) {
if ( strpos( $url, 'downloads.wordpress.org' ) !== false && apply_filters( 'klarned_override_api_downloads', true ) ) {
// Replace the default API URL with WPE's URL.
$url = str_replace( '://downloads.wordpress.org', '://dotorg-downloads-proxy.yourdomain.com', $url );
return wp_remote_request( $url, $args );
}
return $c;
}
add_filter( 'pre_http_request', 'klarned_override_api_services', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment