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(
            '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

  • 1
    Is the sites URL set with http or https? If your site uses http but you've relied entirely on a plugin to substitute http for https after the fact without actually migrating fom http to https then that might cause these issues
    – Tom J Nowell
    Sep 4, 2020 at 9:22
  • i edited the question, the get_site_url sends http only if is triggered by the cron hook
    – Alessio
    Sep 4, 2020 at 9:44
  • The documentation says at the top it will return http if is_ssl returns false, are you absolutely sure that the site URL in the options table has https? 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 )
    – Tom J Nowell
    Sep 4, 2020 at 12:25
  • I found the problem, someone was visiting the site in http even if this works in https, thanks
    – Alessio
    Sep 7, 2020 at 8:20


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.