Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote.html: Install WordPress if it isn't installed yet #1425

Merged
merged 11 commits into from
May 20, 2024
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 };

Loading