From e82255264ec607a667a81ffad820c1db9c35507c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 00:30:28 +0000 Subject: [PATCH 1/7] Initial plan From cc8900f995a052f00a924aa610217dc259395fd6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 00:32:25 +0000 Subject: [PATCH 2/7] Add HTTP proxy configuration documentation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- references/config.md | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/references/config.md b/references/config.md index a09d1f39..54bb7ab1 100644 --- a/references/config.md +++ b/references/config.md @@ -389,3 +389,70 @@ To set the same environment variable value for every shell session, you’ll nee # Always use vim to edit a post export EDITOR=vim + +## HTTP proxy configuration + +If you're working in an environment that requires HTTP requests to be made through a proxy server, you can configure WP-CLI to use a proxy for WordPress core HTTP requests. + +While php-curl honors the `HTTP_PROXY` environment variable automatically, WordPress's HTTP API (used by WordPress core) requires proxy settings to be explicitly configured via constants. WP-CLI doesn't automatically trust the `HTTP_PROXY` environment variable for security reasons, but you can manually configure proxy support using the `require` configuration option in `wp-cli.yml`. + +### Example configuration + +Create a proxy configuration PHP file that reads the proxy settings from environment variables and defines the appropriate WordPress constants: + +**wp-cli.yml:** +```yaml +require: + - proxy.php +``` + +**proxy.php:** +```php + Date: Tue, 3 Feb 2026 00:33:12 +0000 Subject: [PATCH 3/7] Improve proxy configuration code robustness Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- references/config.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/references/config.md b/references/config.md index 54bb7ab1..f00af6b0 100644 --- a/references/config.md +++ b/references/config.md @@ -417,18 +417,20 @@ require: * uses for HTTP requests. */ -$proxy_host = getenv( 'HTTP_PROXY' ); +$proxy_env = getenv( 'HTTP_PROXY' ); -if ( ! $proxy_host ) { +if ( ! $proxy_env ) { return; } -$proxy_url = parse_url( $proxy_host ); +$proxy_url = parse_url( $proxy_env ); -if ( isset( $proxy_url['host'] ) ) { - define( 'WP_PROXY_HOST', $proxy_url['host'] ); +if ( ! is_array( $proxy_url ) || ! isset( $proxy_url['host'] ) ) { + return; } +define( 'WP_PROXY_HOST', $proxy_url['host'] ); + if ( isset( $proxy_url['port'] ) ) { define( 'WP_PROXY_PORT', $proxy_url['port'] ); } From 888bd9007cd14cddca6dc0d2db1bbb8a2280a700 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 01:29:30 +0000 Subject: [PATCH 4/7] Add proxy configuration for WP-CLI's own HTTP requests Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- references/config.md | 90 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/references/config.md b/references/config.md index f00af6b0..6b40b014 100644 --- a/references/config.md +++ b/references/config.md @@ -392,11 +392,11 @@ To set the same environment variable value for every shell session, you’ll nee ## HTTP proxy configuration -If you're working in an environment that requires HTTP requests to be made through a proxy server, you can configure WP-CLI to use a proxy for WordPress core HTTP requests. +If you're working in an environment that requires HTTP requests to be made through a proxy server, you can configure proxy support for both WordPress core HTTP requests and WP-CLI's own HTTP requests. -While php-curl honors the `HTTP_PROXY` environment variable automatically, WordPress's HTTP API (used by WordPress core) requires proxy settings to be explicitly configured via constants. WP-CLI doesn't automatically trust the `HTTP_PROXY` environment variable for security reasons, but you can manually configure proxy support using the `require` configuration option in `wp-cli.yml`. +While php-curl honors the `HTTP_PROXY` environment variable automatically, neither WordPress's HTTP API nor WP-CLI's HTTP request functionality automatically trust the `HTTP_PROXY` environment variable for security reasons. However, you can manually configure proxy support using the `require` configuration option in `wp-cli.yml`. -### Example configuration +### Configuring proxy for WordPress core HTTP requests Create a proxy configuration PHP file that reads the proxy settings from environment variables and defines the appropriate WordPress constants: @@ -457,4 +457,86 @@ $ HTTP_PROXY=http://username:password@proxy.example.com:8080 wp plugin update -- This approach configures the proxy for HTTP requests made by WordPress core when using WP-CLI. The proxy configuration works similarly to defining these constants in `wp-config.php`, but is specific to WP-CLI execution. -**Note:** This configuration affects HTTP requests made through WordPress's HTTP API (used by core, plugins, and themes). HTTP requests made directly by WP-CLI commands may require additional configuration. For more information about WordPress's built-in proxy support, see the [`WP_Http_Proxy`](https://developer.wordpress.org/reference/classes/wp_http_proxy/) class documentation. +### Configuring proxy for WP-CLI's own HTTP requests + +WP-CLI makes HTTP requests using the Requests library (via `WP_CLI\Utils\http_request()`). To configure proxy support for these requests, you need to hook into WP-CLI's HTTP request process and add proxy options. + +**wp-cli.yml:** +```yaml +require: + - proxy.php +``` + +**proxy.php (extended):** +```php + Date: Tue, 3 Feb 2026 01:29:57 +0000 Subject: [PATCH 5/7] Remove trailing whitespace Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- references/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/references/config.md b/references/config.md index 6b40b014..284fb31c 100644 --- a/references/config.md +++ b/references/config.md @@ -515,7 +515,7 @@ if ( class_exists( 'WP_CLI' ) ) { $r['proxy'] = $proxy_env; return $r; }; - + // Hook into http_request_args to modify all HTTP requests made by WP-CLI WP_CLI::add_hook( 'http_request_args', $add_proxy_to_request ); } From 85fe0e20a2104da3d0f5c2f949c68bd6c3ff22c2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 01:30:22 +0000 Subject: [PATCH 6/7] Clarify unused parameter in hook callback Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- references/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/references/config.md b/references/config.md index 284fb31c..7ce75899 100644 --- a/references/config.md +++ b/references/config.md @@ -507,7 +507,7 @@ if ( class_exists( 'WP_CLI' ) ) { * Add proxy configuration to WP-CLI HTTP requests. * * @param array $r Request arguments - * @param string $url Request URL + * @param string $url Request URL (unused but required by hook signature) * @return array Modified request arguments */ $add_proxy_to_request = function( $r, $url ) use ( $proxy_env ) { From 50e0150393b498076ce435697bd38b398931d453 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 01:30:53 +0000 Subject: [PATCH 7/7] Add clarifying comments for proxy configuration Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- references/config.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/references/config.md b/references/config.md index 7ce75899..a7489048 100644 --- a/references/config.md +++ b/references/config.md @@ -506,12 +506,18 @@ if ( class_exists( 'WP_CLI' ) ) { /** * Add proxy configuration to WP-CLI HTTP requests. * + * The http_request_args hook passes both $r (request args) and $url parameters. + * While $url is not used in this simple proxy configuration, it's required + * by the hook signature and could be used for URL-specific proxy rules. + * * @param array $r Request arguments - * @param string $url Request URL (unused but required by hook signature) + * @param string $url Request URL * @return array Modified request arguments */ $add_proxy_to_request = function( $r, $url ) use ( $proxy_env ) { // Set proxy for the Requests library + // The Requests library accepts proxy URLs in the same format as HTTP_PROXY + // and handles parsing internally, so we can pass the raw environment variable $r['proxy'] = $proxy_env; return $r; };