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

Blueprints: Write sunrise.php to /internal in enableMultisite step #1401

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { getWordPressModule } from '@wp-playground/wordpress-builds';
import { unzip } from './unzip';
import { enableMultisite } from './enable-multisite';
import { PHPRequestHandler } from '@php-wasm/universal';
import {
enablePlatformMuPlugins,
preloadRequiredMuPlugin,
} from '@wp-playground/wordpress';

const DOCROOT = '/test-dir';
describe('Blueprint step enableMultisite', () => {
Expand All @@ -14,11 +18,13 @@ describe('Blueprint step enableMultisite', () => {
documentRoot: DOCROOT,
});
const php = await requestHandler.getPrimaryPhp();

await unzip(php, {
zipFile: await getWordPressModule(),
extractToPath: DOCROOT,
});
// Ensure we're preloading platform-level mu-plugins
await enablePlatformMuPlugins(php);
await preloadRequiredMuPlugin(php);
return { php, requestHandler };
}

Expand Down
15 changes: 9 additions & 6 deletions packages/playground/blueprints/src/lib/steps/enable-multisite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { joinPaths, phpVar } from '@php-wasm/util';
import { phpVar } from '@php-wasm/util';
import { StepHandler } from '.';
import { defineWpConfigConsts } from './define-wp-config-consts';
import { login } from './login';
Expand Down Expand Up @@ -149,7 +149,6 @@ echo json_encode($deactivated_plugins);

await defineWpConfigConsts(playground, {
consts: {
SUNRISE: 'on',
MULTISITE: true,
SUBDOMAIN_INSTALL: false,
SITE_ID_CURRENT_SITE: 1,
Expand All @@ -159,15 +158,19 @@ echo json_encode($deactivated_plugins);
},
});

// Create a sunrise.php file to tell WordPress which site to load
// by default. Without this, requiring `wp-load.php` will result in
// a redirect to the main site.
// Preload a sunrise.php file. Without it, requiring `wp-load.php`
// would result in a redirect to the main site.
//
// Normally that's a drop-in plugin living in wp-content, but:
// * We only need this logic in Playground runtime.
// * We don't want to modify the user site in any way not explicitly
// requested.
const playgroundUrl = new URL(await playground.absoluteUrl);
const wpInstallationFolder = isURLScoped(playgroundUrl)
? 'scope:' + getURLScope(playgroundUrl)
: null;
await playground.writeFile(
joinPaths(docroot, '/wp-content/sunrise.php'),
'/internal/shared/mu-plugins/sunrise.php',
`<?php
if ( !defined( 'BLOG_ID_CURRENT_SITE' ) ) {
define( 'BLOG_ID_CURRENT_SITE', 1 );
Expand Down
Loading