Hi I have a cron that uses this command to set the proxy
add_action('http_api_curl', array(__CLASS__, 'addProxy'), 10, 3);
inside the addProxy
function there is this
curl_setopt($handle, CURLOPT_USERAGENT, $agent);
The problem is when within the execution of this function I want to execute an example action
return wp_remote_get(
$url,
array(
'headers' => array(
'Authorization' => 'Bearer ' . $api_key,
),
'timeout' => self::CURL_TIMEOUT,
)
);
wp_remote_get runs with the proxy What I need is for it to run without the proxy
Is there any command to run wp_remote_get without proxy? (ignore proxy)
CodePudding user response:
There is no such parameter of the wp_remote_get
to overwrite http_api_curl
hook added action functions.
To achieve what you want and solve your issue you need to update your cron function and check whether to execute its body in all cases, for example:
class __CLASS__ {
public function addProxy ( $handle, array $parsed_args, $url ) {
// You can distinct your wp_remote_get call by specific $url value
if ( 'https://service.com/auth' === $url ) {
return;
}
// Or... you can distinct by some $parsed_args like headers
if ( array_key_exists( 'Authorisation,' $parsed_args['headers'] ) ) {
return;
}
// the rest of your current addProxy() function body with the curl options...
...
}
This way you can avoid executing the addProxy
on certain requests, like
wp_remote_get( 'https://service.com/auth', array(...), );
The above will not trigger the execution of the addProxy
function body code...