Skip to content

Commit 6742d6c

Browse files
authored
Update force-https.php
1 parent 73c3622 commit 6742d6c

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

force-https.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,24 @@
2727
return $overrides;
2828
}, 999 );
2929

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-
4330
// enforce https dynamically via filters (does not modify database)
4431
function force_https_filter_home( $value ) {
4532
return set_url_scheme( $value, 'https' );
4633
}
4734
add_filter( 'pre_option_home', 'force_https_filter_home' );
4835
add_filter( 'pre_option_siteurl', 'force_https_filter_home' );
4936

50-
// force https redirect on frontend, admin, and login
37+
// force https redirect on frontend, admin, and login
5138
function force_https_redirect() {
5239
if ( ! is_ssl() && empty( $_SERVER['HTTPS'] ) && ! defined( 'WP_CLI' ) && ! headers_sent() ) {
5340
wp_safe_redirect( set_url_scheme( home_url( $_SERVER['REQUEST_URI'] ), 'https' ), 301 );
5441
exit;
5542
}
5643
}
5744

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 );
6148
}
6249

6350
// enforce https on all urls by replacing http with https

0 commit comments

Comments
 (0)