Skip to content

Commit

Permalink
Remote.html: Install WordPress if it isn't installed yet (#1425)
Browse files Browse the repository at this point in the history
## What is this PR doing?

Runs the WordPress installation process in remote.html when the loaded
WordPress instance isn't installed yet.

This is to enable the official WordPress release `.zip` to just work in
Playground. Currently it doesn't because remote.html expects a
pre-installed WordPress build with a pre-populated SQLite database
already baked-in. This PR, in conjunction with #1425 and #1426, remove
that requirement.

Related to [Boot
Protocol](#1398)

## Testing Instructions

Confirm the CI checks pass.
  • Loading branch information
adamziel authored May 20, 2024
1 parent 25349e2 commit b7dac82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 30 additions & 1 deletion packages/playground/remote/src/lib/worker-thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
preloadSqliteIntegration,
wordPressRewriteRules,
} from '@wp-playground/wordpress';
import { PHPRequestHandler } from '@php-wasm/universal';
import { PHPRequestHandler, withPHPIniValues } from '@php-wasm/universal';
import {
SyncProgressCallback,
bindOpfs,
Expand All @@ -21,6 +21,7 @@ import {
import {
defineSiteUrl,
defineWpConfigConsts,
runWpInstallationWizard,
unzip,
} from '@wp-playground/blueprints';

Expand Down Expand Up @@ -228,6 +229,34 @@ try {
new File([sqliteIntegrationZip], 'sqlite.zip')
);

// Install WordPress if it isn't installed yet
const isInstalled =
(
await primaryPhp.run({
code: `<?php
require '${primaryPhp.documentRoot}/wp-load.php';
echo is_blog_installed() ? '1' : '0';
`,
})
).text === '1';
if (!isInstalled) {
// Disable networking for the installation wizard
// to avoid loopback requests and also speed it up.
// @TODO: Expose withPHPIniValues as a function from the
// php-wasm library.
await withPHPIniValues(
primaryPhp,
{
disable_functions: 'fsockopen',
allow_url_fopen: '0',
},
async () =>
await runWpInstallationWizard(primaryPhp, {
options: {},
})
);
}

// Always setup the current site URL.
await defineSiteUrl(primaryPhp, {
siteUrl: scopedSiteUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// @ts-ignore
import url from './sqlite-database-integration.zip?url';

Expand All @@ -10,4 +9,3 @@ import url from './sqlite-database-integration.zip?url';
*/
export const size = 83956;
export { url };

0 comments on commit b7dac82

Please sign in to comment.