|
27 | 27 | return $overrides;
|
28 | 28 | }, 999 );
|
29 | 29 |
|
30 |
| -// ensure siteurl and home options are always https |
31 |
| -function force_https_fix_options() { |
32 |
| - // only update database if constants are not set |
33 |
| - if ( ! defined( 'WP_HOME' ) ) { |
34 |
| - update_option( 'home', set_url_scheme( get_option( 'home' ), 'https' ) ); |
35 |
| - } |
36 |
| - |
37 |
| - if ( ! defined( 'WP_SITEURL' ) ) { |
38 |
| - update_option( 'siteurl', set_url_scheme( get_option( 'siteurl' ), 'https' ) ); |
39 |
| - } |
40 |
| -} |
41 |
| -add_action( 'init', 'force_https_fix_options', 1 ); |
42 |
| - |
43 | 30 | // enforce https dynamically via filters (does not modify database)
|
44 | 31 | function force_https_filter_home( $value ) {
|
45 | 32 | return set_url_scheme( $value, 'https' );
|
46 | 33 | }
|
47 | 34 | add_filter( 'pre_option_home', 'force_https_filter_home' );
|
48 | 35 | add_filter( 'pre_option_siteurl', 'force_https_filter_home' );
|
49 | 36 |
|
50 |
| -// force https redirect on frontend, admin, and login |
| 37 | +// force https redirect on frontend, admin, and login |
51 | 38 | function force_https_redirect() {
|
52 | 39 | if ( ! is_ssl() && empty( $_SERVER['HTTPS'] ) && ! defined( 'WP_CLI' ) && ! headers_sent() ) {
|
53 | 40 | wp_safe_redirect( set_url_scheme( home_url( $_SERVER['REQUEST_URI'] ), 'https' ), 301 );
|
54 | 41 | exit;
|
55 | 42 | }
|
56 | 43 | }
|
57 | 44 |
|
58 |
| -// apply https redirect to all key areas |
59 |
| -foreach ( array( 'init', 'admin_init', 'login_init' ) as $hook ) { |
60 |
| - add_action( $hook, 'force_https_redirect', 10 ); |
| 45 | +// apply https redirect to all key areas |
| 46 | +foreach ( array( 'init', 'admin_init', 'login_init' ) as $hook ) { |
| 47 | + add_action( $hook, 'force_https_redirect', 10 ); |
61 | 48 | }
|
62 | 49 |
|
63 | 50 | // enforce https on all urls by replacing http with https
|
|
0 commit comments