Skip to content

Commit 2034e5e

Browse files
Prefer pretty permalinks like WP install does (#1832)
## Motivation for the change, related issues The WordPress installation process defaults to pretty permalinks if it can enable them and get a valid response from a loopback request. Unfortunately, at the time we run the WP installation process in Playground, the PHP request handler has not yet been put into place to handle those requests. In addition, even if the request handler was in place in time, @adamziel [mentioned](#1644 (comment)): > I vaguely remember disabling the networking in installWordPress made for a dramatic installation speedup in web browsers As a workaround, we can manually set the `permalink_structure` as part of WordPress installation within `bootWordPress()`. Closes #1644 ## Implementation details Manually sets the `permalink_structure` as part of WordPress installation within `bootWordPress()`. ## Testing Instructions (or ideally a Blueprint) Manual testing after creating nightly WP build which was pre-installed using this logic using Playground CLI. Loading the nightly build locally shows permalinks enabled.
1 parent 7a460a3 commit 2034e5e

File tree

1 file changed

+24
-0
lines changed
  • packages/playground/wordpress/src

1 file changed

+24
-0
lines changed

packages/playground/wordpress/src/boot.ts

+24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
wordPressRewriteRules,
2121
} from '.';
2222
import { joinPaths } from '@php-wasm/util';
23+
import { logger } from '@php-wasm/logger';
2324

2425
export type PhpIniOptions = Record<string, string>;
2526
export type Hook = (php: PHP) => void | Promise<void>;
@@ -270,6 +271,29 @@ async function installWordPress(php: PHP) {
270271
},
271272
})
272273
);
274+
275+
const defaultedToPrettyPermalinks = await php.run({
276+
code: `<?php
277+
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
278+
if (!file_exists($wp_load)) {
279+
echo '0';
280+
exit;
281+
}
282+
require $wp_load;
283+
$option_result = update_option(
284+
'permalink_structure',
285+
'/%year%/%monthnum%/%day%/%postname%/'
286+
);
287+
echo $option_result ? '1' : '0';
288+
`,
289+
env: {
290+
DOCUMENT_ROOT: php.documentRoot,
291+
},
292+
});
293+
294+
if (defaultedToPrettyPermalinks.text !== '1') {
295+
logger.warn('Failed to default to pretty permalinks after WP install.');
296+
}
273297
}
274298

275299
export function getFileNotFoundActionForWordPress(

0 commit comments

Comments
 (0)