Skip to content

Instantly share code, notes, and snippets.

@JoelLisenby
Last active September 26, 2024 17:02
Show Gist options
  • Save JoelLisenby/85bb9dd5ad8572374c364fbceb164863 to your computer and use it in GitHub Desktop.
Save JoelLisenby/85bb9dd5ad8572374c364fbceb164863 to your computer and use it in GitHub Desktop.
WordPress vs WPengine Proxy Function for Plugin Updates
<?php
// Add to functions.php or your own plugin
define('WP_PROXY_HOST', 'your.proxy.server');
define('WP_PROXY_PORT', 'proxy_port_number');
define('WP_PROXY_USERNAME', 'your_username');
define('WP_PROXY_PASSWORD', 'your_password');
// Optional, if you need to bypass proxy for local addresses
// define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
add_filter('http_request_args', 'apply_proxy_for_updates', 10, 2);
function apply_proxy_for_updates($http_args, $url) {
// Check if the URL is for an update check or download
if (strpos($url, 'wordpress.org') !== false) {
$http_args['proxy'] = array(
'host' => WP_PROXY_HOST,
'port' => WP_PROXY_PORT,
// Add username and password if your proxy requires authentication
'username' => WP_PROXY_USERNAME,
'password' => WP_PROXY_PASSWORD,
);
}
return $http_args;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment