[wp-trac] [WordPress Trac] #36451: get_rest_url() not returning SSL version of the URL when the home_url it's a subdomain
WordPress Trac
noreply at wordpress.org
Mon May 22 18:14:12 UTC 2017
#36451: get_rest_url() not returning SSL version of the URL when the home_url it's
a subdomain
-------------------------+-------------------------------------------------
Reporter: nicholas_io | Owner: johnbillion
Type: defect | Status: assigned
(bug) | Milestone: Awaiting Review
Priority: normal | Version: 4.4
Component: REST API | Resolution:
Severity: major | Focuses: administration, multisite, rest-
Keywords: https | api
-------------------------+-------------------------------------------------
Comment (by westonruter):
I think it could be as easy as [attachment:36451.2.diff]:
{{{#!diff
--- src/wp-includes/rest-api.php
+++ src/wp-includes/rest-api.php
@@ -330,7 +330,7 @@ function get_rest_url( $blog_id = null, $path = '/',
$scheme = 'rest' ) {
$url = add_query_arg( 'rest_route', $path, $url );
}
- if ( is_ssl() ) {
+ if ( is_ssl() || ( is_admin() && force_ssl_admin() ) ) {
// If the current host is the same as the REST URL host,
force the REST URL scheme to HTTPS.
if ( $_SERVER['SERVER_NAME'] === parse_url( get_home_url(
$blog_id ), PHP_URL_HOST ) ) {
$url = set_url_scheme( $url, 'https' );
}}}
This is similar to what `set_url_scheme()` is
[https://github.com/WordPress/wordpress-
develop/blob/5ea3c91d57c17fdadbd0ef910b65c4ff8891ff87/src/wp-includes
/link-template.php#L3424-L3425 doing] which is what is used to obtain URLs
in the admin in the first place.
On the other hand, what if in the admin we opt to use `get_site_url(
$site_id, $prefix, 'admin' )` instead of `get_home_url( … )`? Then we'd
know for sure that the domain would be the same and so HTTPS would be
assured to work.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36451#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list