|
27 | 27 | return $overrides; |
28 | 28 | }, 999 ); |
29 | 29 |
|
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 |
31 | 31 | // home_url and site_url should not be in force_https_securize_url because it would run on every call unnecessarily |
32 | 32 | function force_https_filter_home( $value ) { |
| 33 | + if ( is_ssl() ) { |
| 34 | + return $value; |
| 35 | + } |
33 | 36 | return set_url_scheme( $value, 'https' ); |
34 | 37 | } |
| 38 | + |
35 | 39 | // no priority needed since pre_option filters override values immediately |
36 | 40 | add_filter( 'pre_option_home', 'force_https_filter_home' ); |
37 | 41 | add_filter( 'pre_option_siteurl', 'force_https_filter_home' ); |
38 | 42 |
|
39 | 43 | // enforce https by redirecting non-ssl requests on frontend, admin, and login pages |
40 | 44 | 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() ) { |
44 | 47 | return; |
45 | 48 | } |
46 | 49 |
|
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'] ) ) { |
49 | 52 | return; |
50 | 53 | } |
51 | 54 |
|
52 | | - // redirect to https version of the requested url with a permanent redirect |
| 55 | + // redirect to https version of the requested url |
53 | 56 | wp_redirect( set_url_scheme( home_url( $_SERVER['REQUEST_URI'] ), 'https' ), 301 ); |
54 | 57 | exit; |
55 | 58 | } |
|
0 commit comments