Skip to content

Conversation

@mchirag2002
Copy link

While using CLI, the $_SERVER['https'] variable is absent which leads to an unexpected behaviour when site_url related functions are executed. The previous fix solves the issue in most parts except for the network_site_url() function which is utilised by a lot of plugins and cron jobs in multisite installations.

This PR extends the solution implemented in #4473 and fixes the issue: #5973 which was also raised here

The following are the changes the PR makes:

$ wp option get siteurl
https://example.com

// before PR fix
$ wp eval "echo network_site_url();"
http://example.com

// after PR fix
$ wp eval "echo network_site_url();"
https://example.com

@mchirag2002 mchirag2002 requested a review from a team as a code owner October 18, 2024 14:42
@schlessera
Copy link
Member

Thanks for the PR, @mchirag2002 !

Thinking through this, I'm not sure this is something we can easily fix. On one hand, the proposed fix only applies to one arbitrary function, and will create a mismatch in URLs between what that function returns, and what other related functions would return (that would then still end up with http instead of https). It would make more sense to hook into set_url_scheme() instead to make sure all URLs are treated in the same manner.

On the other hand, assuming https as scheme when there is nothing to suggest HTTPS is supported can lead to new problems. On local environments during development, you'll often see setups that us insecure http during development because of the complexity involved of making certificates work on local machines.

I'm wondering if we shouldn't rather allow for a flag like --assume-https that could be set in the wp-cli.yml file for a site and that would then make sure is_ssl() returns true...

@swissspidy swissspidy linked an issue Nov 4, 2025 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

network_site_url() is returned with HTTP instead of HTTPS

2 participants