@@ -39,8 +39,8 @@ function force_https_filter_home( $value ) {
39
39
// enforce https by redirecting non-ssl requests on frontend, admin, and login pages
40
40
function force_https_redirect () {
41
41
42
- // exit if already using https, headers are sent, or running via cli
43
- if ( is_ssl () || headers_sent () || defined ( 'WP_CLI ' ) ) {
42
+ // exit if already using https, headers are sent, or running via cli or ajax, or no request uri exists
43
+ if ( is_ssl () || headers_sent () || defined ( 'WP_CLI ' ) || ( defined ( ' DOING_AJAX ' ) && DOING_AJAX ) || ! isset ( $ _SERVER [ ' REQUEST_URI ' ] ) ) {
44
44
return ;
45
45
}
46
46
@@ -50,9 +50,9 @@ function force_https_redirect() {
50
50
}
51
51
52
52
// apply https redirect during initialization, admin, and login
53
- foreach ( [ 'init ' , 'admin_init ' , ' login_init ' ] as $ hook ) {
54
- add_action ( $ hook , 'force_https_redirect ' , 10 );
55
- }
53
+ add_action ( 'init ' , 'force_https_redirect ' , 10 );
54
+ add_action ( ' admin_init ' , 'force_https_redirect ' , 10 );
55
+ add_action ( ' login_init ' , ' force_https_redirect ' , 10 );
56
56
57
57
// enforce https for valid urls only
58
58
function force_https_securize_url ( $ value ) {
@@ -125,7 +125,7 @@ function force_https_filter_output( $content ) {
125
125
add_filter ( 'the_content ' , 'force_https_process_content ' , 20 );
126
126
function force_https_process_content ( $ content ) {
127
127
return preg_replace_callback (
128
- '#(<(?:a|img|script|iframe|link|source|form)[^>]+\s(?:href|src)=[" \'])(http://|// )([^" \']+)#i ' ,
128
+ '#(<(?:a|img|script|iframe|link|source|form)[^>]+\s(?:href|src)=[" \'])(http://)([^" \']+)#i ' ,
129
129
function ( $ matches ) {
130
130
return $ matches [1 ] . 'https:// ' . $ matches [3 ];
131
131
},
0 commit comments