@@ -6,12 +6,14 @@ final class PostProcessConfig {
6
6
7
7
public readonly ?string $ destination_url ;
8
8
public readonly ?array $ hosts_to_rewrite ;
9
+ public readonly ?array $ replacement_patterns ;
9
10
public readonly ?string $ site_url ;
10
11
11
12
public function __construct () {
12
13
if ( Options::getValue ( 'skipURLRewrite ' ) === '1 ' ) {
13
14
$ this ->destination_url = null ;
14
15
$ this ->hosts_to_rewrite = null ;
16
+ $ this ->replacement_patterns = null ;
15
17
$ this ->site_url = null ;
16
18
return ;
17
19
}
@@ -25,6 +27,40 @@ public function __construct() {
25
27
Controller::getHookName ( 'set_wordpress_site_url ' ),
26
28
untrailingslashit ( SiteInfo::getUrl ( 'site ' ) )
27
29
);
30
+
31
+ $ wordpress_site_url = untrailingslashit ( $ this ->site_url );
32
+ $ destination_url = untrailingslashit ( $ this ->destination_url );
33
+ $ destination_url_c = addcslashes ( $ destination_url , '/ ' );
34
+ $ destination_url_rel = URLHelper::getProtocolRelativeURL ( $ destination_url );
35
+ $ destination_url_rel_c = addcslashes ( $ destination_url_rel , '/ ' );
36
+
37
+ $ replacement_patterns = [
38
+ $ wordpress_site_url => $ destination_url ,
39
+ URLHelper::getProtocolRelativeURL ( $ wordpress_site_url ) =>
40
+ URLHelper::getProtocolRelativeURL ( $ destination_url ),
41
+ addcslashes ( URLHelper::getProtocolRelativeURL ( $ wordpress_site_url ), '/ ' ) =>
42
+ addcslashes ( URLHelper::getProtocolRelativeURL ( $ destination_url ), '/ ' ),
43
+ ];
44
+
45
+ foreach ( $ this ->hosts_to_rewrite as $ host ) {
46
+ if ( $ host ) {
47
+ $ host_rel = URLHelper::getProtocolRelativeURL ( 'http:// ' . $ host );
48
+ $ host_rel_c = addcslashes ( $ host_rel , '/ ' );
49
+
50
+ $ replacement_patterns [ 'http: ' . $ host_rel ] = $ destination_url ;
51
+ $ replacement_patterns [ 'https: ' . $ host_rel ] = $ destination_url ;
52
+ $ replacement_patterns [ $ host_rel ] = $ destination_url_rel ;
53
+ $ replacement_patterns [ 'http: ' . $ host_rel_c ] = $ destination_url_c ;
54
+ $ replacement_patterns [ 'https: ' . $ host_rel_c ] = $ destination_url_c ;
55
+ $ replacement_patterns [ addcslashes ( $ host_rel , '/ ' ) ] = $ destination_url_rel_c ;
56
+ }
57
+ }
58
+
59
+ $ this ->replacement_patterns = $ replacement_patterns ;
60
+
61
+ if ( STATIC_DEPLOY_DEBUG ) {
62
+ WsLog::l ( 'PostProcessConfig: ' . json_encode ( $ this ->toArray () ) );
63
+ }
28
64
}
29
65
30
66
/**
@@ -42,6 +78,10 @@ public function toArray(): array
42
78
$ arr ['hosts_to_rewrite ' ] = $ this ->hosts_to_rewrite ;
43
79
}
44
80
81
+ if ( $ this ->replacement_patterns ) {
82
+ $ arr ['replacement_patterns ' ] = $ this ->replacement_patterns ;
83
+ }
84
+
45
85
if ( $ this ->site_url ) {
46
86
$ arr ['site_url ' ] = $ this ->site_url ;
47
87
}
0 commit comments