Created
December 12, 2016 22:26
-
-
Save BeardedGinger/f4f10d1b384aebff3b573d721f9726ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'set_url_scheme', 'lc_force_secure_scheme', 10, 3 ); | |
/** | |
* Force all URLs run through the set_url_scheme to always be https if they're | |
* being accessed through our reverse proxy. | |
* | |
* @param string $url The complete URL including scheme and path. | |
* @param string $scheme Scheme applied to the URL. One of 'http', 'https', or 'relative'. | |
* @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login', | |
* 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. | |
*/ | |
function lc_force_secure_scheme( $url, $scheme, $orig_scheme ) { | |
if ( ! lc_is_reverse_proxy() ) | |
return $url; | |
$scheme = 'https'; | |
$url = trim( $url ); | |
if ( substr( $url, 0, 2 ) === '//' ) | |
$url = 'http:' . $url; | |
$url = preg_replace( '#^\w+://#', $scheme . '://', $url ); | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment