I have a problem with a plugin I'm working on, I have implemented a cron that 2 times a day makes a call to update the data, the call is made with the wp_remote_post function.
$response = wp_remote_post(
ENDPOINT,
array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
'domainUrl' => get_site_url(),
),
'body' => wp_json_encode( $body ),
)
);
the problem is in the get_site_url()
function.
For a site that uses the https protocol, get_site_url()
returns the domain in https when the call is triggered from the frontend or wordpress hooks except cron, instead when get_site_url()
is triggered by the cron hook it returns http.
What may be causing this behavior and how I could fix it?
Thanks
http
orhttps
? If your site useshttp
but you've relied entirely on a plugin to substitutehttp
forhttps
after the fact without actually migrating fom http to https then that might cause these issuesget_site_url
sends http only if is triggered by the cron hookhttp
ifis_ssl
returns false, are you absolutely sure that the site URL in the options table hashttps
? Have you physically checked the raw value? And that it isn't being filtered or overriden by code? ( Note that the documentation page also has the solution to your question at the very top of the page, then again in the function signature, then again in the parameter list, and several times in the comments at the bottom )