File tree Expand file tree Collapse file tree 7 files changed +33
-13
lines changed Expand file tree Collapse file tree 7 files changed +33
-13
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ parameters:
22
22
count : 6
23
23
- message : ' #^In method "WP2Static\\\S+::\S+", you should not use the \$_(GET|POST) superglobal#'
24
24
path : src/CoreOptions.php
25
- count : 25
25
+ count : 26
26
26
- message : ' #^In method "WP2Static\\\S+::\S+", you should not use the \$_(GET|POST) superglobal#'
27
27
path : src/ViewRenderer.php
28
28
count : 32
Original file line number Diff line number Diff line change @@ -333,6 +333,16 @@ public static function optionSpecs() : array {
333
333
'Don \'t rewrite any URLs. This may give a slight speed-up when the '
334
334
. ' deployment URL is the same as WordPress \'s URL. '
335
335
),
336
+ // TODO: Enable by default for new sites in a future release.
337
+ self ::makeOptionSpec (
338
+ 'boolean ' ,
339
+ 'useHomeUrlAsRoot ' ,
340
+ '0 ' ,
341
+ 'Use WP_HOME as Crawl Root ' ,
342
+ 'This gives better results when the WordPress home URL and site URL '
343
+ . ' are different, as in when WordPress is installed in a subdirectory. '
344
+ . ' Use this option if you are using Bedrock. '
345
+ ),
336
346
];
337
347
338
348
$ ret = [];
@@ -805,6 +815,12 @@ public static function savePosted( string $screen = 'core' ) : void {
805
815
[ 'value ' => isset ( $ _POST ['skipURLRewrite ' ] ) ? 1 : 0 ],
806
816
[ 'name ' => 'skipURLRewrite ' ]
807
817
);
818
+
819
+ $ wpdb ->update (
820
+ $ table_name ,
821
+ [ 'value ' => isset ( $ _POST ['useHomeUrlAsRoot ' ] ) ? 1 : 0 ],
822
+ [ 'name ' => 'useHomeUrlAsRoot ' ]
823
+ );
808
824
break ;
809
825
}
810
826
}
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ public function crawlSite( string $static_site_path ) : void {
114
114
115
115
foreach ( $ crawlable_paths as $ root_relative_path ) {
116
116
$ absolute_uri = new URL (
117
- rtrim ( SiteInfo::getURL ( 'home ' ), '/ ' ) . $ root_relative_path
117
+ rtrim ( SiteInfo::getUrl ( 'crawl_root ' ), '/ ' ) . $ root_relative_path
118
118
);
119
119
$ urls [] = [
120
120
'url ' => $ absolute_uri ->get (),
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public static function detect() : array {
32
32
null
33
33
);
34
34
35
- $ wp_site_url = SiteInfo::getURL ( 'home ' );
35
+ $ wp_site_url = SiteInfo::getUrl ( 'crawl_root ' );
36
36
$ base_uri = rtrim ( $ wp_site_url , '/ ' );
37
37
38
38
if ( $ port_override ) {
Original file line number Diff line number Diff line change @@ -50,21 +50,16 @@ public static function rewriteFileContents( string $file_contents ) : string
50
50
CoreOptions::getValue ( 'deploymentURL ' )
51
51
);
52
52
53
- $ wordpress_home_url = apply_filters (
54
- 'wp2static_set_wordpress_home_url ' ,
55
- untrailingslashit ( SiteInfo::getUrl ( 'home ' ) )
56
- );
57
-
58
- $ wordpress_home_url = untrailingslashit ( $ wordpress_home_url );
53
+ $ crawl_root = untrailingslashit ( SiteInfo::getUrl ( 'crawl_root ' ) );
59
54
$ destination_url = untrailingslashit ( $ destination_url );
60
55
$ destination_url_rel = URLHelper::getProtocolRelativeURL ( $ destination_url );
61
56
$ destination_url_rel_c = addcslashes ( $ destination_url_rel , '/ ' );
62
57
63
58
$ replacement_patterns = [
64
- $ wordpress_home_url => $ destination_url ,
65
- URLHelper::getProtocolRelativeURL ( $ wordpress_home_url ) =>
59
+ $ crawl_root => $ destination_url ,
60
+ URLHelper::getProtocolRelativeURL ( $ crawl_root ) =>
66
61
URLHelper::getProtocolRelativeURL ( $ destination_url ),
67
- addcslashes ( URLHelper::getProtocolRelativeURL ( $ wordpress_home_url ), '/ ' ) =>
62
+ addcslashes ( URLHelper::getProtocolRelativeURL ( $ crawl_root ), '/ ' ) =>
68
63
addcslashes ( URLHelper::getProtocolRelativeURL ( $ destination_url ), '/ ' ),
69
64
];
70
65
Original file line number Diff line number Diff line change @@ -27,21 +27,29 @@ class SiteInfo {
27
27
*/
28
28
public function __construct () {
29
29
$ upload_path_and_url = wp_upload_dir ();
30
+ $ home_url = trailingslashit ( get_home_url () );
30
31
$ site_url = trailingslashit ( site_url () );
31
32
33
+ if ( (int ) CoreOptions::getValue ( 'useHomeUrlAsRoot ' ) === 1 ) {
34
+ $ crawl_root_url = $ home_url ;
35
+ } else {
36
+ $ crawl_root_url = $ site_url ;
37
+ }
38
+
32
39
// properties which should not change during plugin execution
33
40
self ::$ info = apply_filters (
34
41
'wp2static_siteinfo ' ,
35
42
[
36
43
// Core
44
+ 'crawl_root_url ' => $ crawl_root_url ,
37
45
'site_path ' => ABSPATH ,
38
46
'site_url ' => $ site_url ,
39
47
40
48
/*
41
49
Note: 'home_path' => get_home_path(),
42
50
// errors trying to find it in WP2Static\get_home_path()...
43
51
*/
44
- 'home_url ' => trailingslashit ( get_home_url () ) ,
52
+ 'home_url ' => $ home_url ,
45
53
'includes_path ' => trailingslashit ( ABSPATH . WPINC ),
46
54
'includes_url ' => includes_url (),
47
55
Original file line number Diff line number Diff line change 43
43
<?php echo $ row ( 'crawlConcurrency ' ); ?>
44
44
<?php echo $ row ( 'skipURLRewrite ' ); ?>
45
45
<?php echo $ row ( 'hostsToRewrite ' ); ?>
46
+ <?php echo $ row ( 'useHomeUrlAsRoot ' ); ?>
46
47
</tbody>
47
48
</table>
48
49
You can’t perform that action at this time.
0 commit comments