Skip to content

Commit 6451593

Browse files
authored
Update force-https.php
1 parent b27cbf8 commit 6451593

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

force-https.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,32 @@
2727
return $overrides;
2828
}, 999 );
2929

30-
// enforce https at the database level before wordpress processes these values
30+
// enforce https at the database level only if wordpress is incorrectly detecting http
3131
// home_url and site_url should not be in force_https_securize_url because it would run on every call unnecessarily
3232
function force_https_filter_home( $value ) {
33+
if ( is_ssl() ) {
34+
return $value;
35+
}
3336
return set_url_scheme( $value, 'https' );
3437
}
38+
3539
// no priority needed since pre_option filters override values immediately
3640
add_filter( 'pre_option_home', 'force_https_filter_home' );
3741
add_filter( 'pre_option_siteurl', 'force_https_filter_home' );
3842

3943
// enforce https by redirecting non-ssl requests on frontend, admin, and login pages
4044
function force_https_redirect() {
41-
42-
// exit if already using https, headers are sent, running via cli, cron, or ajax, or no request uri exists
43-
if ( is_ssl() || headers_sent() || defined( 'WP_CLI' ) || defined( 'DOING_CRON' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! isset( $_SERVER['REQUEST_URI'] ) ) {
45+
// exit if already using https
46+
if ( is_ssl() ) {
4447
return;
4548
}
4649

47-
// fallback check for https in server if is_ssl fails
48-
if ( ! empty( $_SERVER['HTTPS'] ) ) {
50+
// exit if headers are sent, running via cli, cron, ajax, or if no request uri exists
51+
if ( headers_sent() || defined( 'WP_CLI' ) || defined( 'DOING_CRON' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ! isset( $_SERVER['REQUEST_URI'] ) ) {
4952
return;
5053
}
5154

52-
// redirect to https version of the requested url with a permanent redirect
55+
// redirect to https version of the requested url
5356
wp_redirect( set_url_scheme( home_url( $_SERVER['REQUEST_URI'] ), 'https' ), 301 );
5457
exit;
5558
}

0 commit comments

Comments
 (0)