-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy-aware-https-fix.php
More file actions
48 lines (41 loc) · 932 Bytes
/
proxy-aware-https-fix.php
File metadata and controls
48 lines (41 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Plugin Name: Proxy-Aware HTTPS Fix
* Description: Enforces HTTPS detection and correct REST API resolution behind reverse proxies.
* Version: 1.3
* Author: BitCryptic
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
add_action(
'plugins_loaded',
function () {
$host = $_SERVER['HTTP_HOST'] ?? '';
$proto = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '';
if (
( ! isset( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] !== 'on' ) &&
( $proto === 'https' || strpos( $host, '.' ) !== false )
) {
$_SERVER['HTTPS'] = 'on';
}
}
);
add_filter(
'home_url',
function ( $url ) {
return str_starts_with( $url, 'http:' ) ? 'https:' . substr( $url, 5 ) : $url;
}
);
add_filter(
'site_url',
function ( $url ) {
return str_starts_with( $url, 'http:' ) ? 'https:' . substr( $url, 5 ) : $url;
}
);
add_filter(
'rank_math/rest_api_url',
function () {
return get_site_url( null, '/wp-json/' );
}
);