WP_HTTP_Proxy
- Since
- 2.8.0
- Source
wp-includes/class-wp-http-proxy.php:42
Core class used to implement HTTP API proxy support.
Description
There are caveats to proxy support. It requires that defines be made in the wp-config.php file to enable proxy support. There are also a few filters that plugins can hook into for some of the constants.
Please note that only BASIC authentication is supported by most transports.
cURL MAY support more methods (such as NTLM authentication) depending on your environment.
The constants are as follows:
- WP_PROXY_HOST - Enable proxy support and host for connecting.
- WP_PROXY_PORT - Proxy port for connection. No default, must be defined.
- WP_PROXY_USERNAME - Proxy username, if it requires authentication.
- WP_PROXY_PASSWORD - Proxy password, if it requires authentication.
- WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy.
You do not need to have localhost and the site host in this list, because they will not be passed through the proxy. The list should be presented in a comma separated list, wildcards using * are supported. Example: *.wordpress.org
An example can be as seen below.
define('WP_PROXY_HOST', '192.168.84.101');
define('WP_PROXY_PORT', '8080');
define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org');Compatibility
- WordPress
- since 2.8.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 1
Every hook that fires from inside WP_HTTP_Proxy, in the order it appears in the class, grouped by the method that fires it.
Methods · 9
- is_enabled()Whether proxy connection should be used.
- use_authentication()Whether authentication should be used.
- host()Retrieve the host for the proxy server.
- port()Retrieve the port for the proxy server.
- username()Retrieve the username for proxy authentication.
- password()Retrieve the password for proxy authentication.
- authentication()Retrieve authentication string for proxy authentication.
- authentication_header()Retrieve header string for proxy authentication.
- send_through_proxy()Determines whether the request should be sent through a proxy.
Source code
#[AllowDynamicProperties]class WP_HTTP_Proxy { /** * Whether proxy connection should be used. * * Constants which control this behavior: * * - `WP_PROXY_HOST` * - `WP_PROXY_PORT` * * @since 2.8.0 * * @return bool */ public function is_enabled() { return defined( 'WP_PROXY_HOST' ) && defined( 'WP_PROXY_PORT' ); } /** * Whether authentication should be used. * * Constants which control this behavior: * * - `WP_PROXY_USERNAME` * - `WP_PROXY_PASSWORD` * * @since 2.8.0 * * @return bool */ public function use_authentication() { return defined( 'WP_PROXY_USERNAME' ) && defined( 'WP_PROXY_PASSWORD' ); } /** * Retrieve the host for the proxy server. * * @since 2.8.0 * * @return string */ public function host() { if ( defined( 'WP_PROXY_HOST' ) ) { return WP_PROXY_HOST; } return ''; } /** * Retrieve the port for the proxy server. * * @since 2.8.0 * * @return string */ public function port() { if ( defined( 'WP_PROXY_PORT' ) ) { return WP_PROXY_PORT; } return ''; } /** * Retrieve the username for proxy authentication. * * @since 2.8.0 * * @return string */ public function username() { if ( defined( 'WP_PROXY_USERNAME' ) ) { return WP_PROXY_USERNAME; } return ''; }Changelog
Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/class-wp-http-proxy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.