Skip to content

Commit 9b2c8dc

Browse files
committed
Keep WP assets dir knowledge with build package
1 parent 791c7d7 commit 9b2c8dc

File tree

1 file changed

+14
-8
lines changed
  • packages/playground/wordpress/src

1 file changed

+14
-8
lines changed

packages/playground/wordpress/src/boot.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ import {
1919
} from '.';
2020
import { joinPaths } from '@php-wasm/util';
2121
import { logger } from '@php-wasm/logger';
22+
import { removeURLScope } from '@php-wasm/scopes';
2223
import {
2324
getLoadedWordPressVersion,
2425
isSupportedWordPressVersion,
2526
} from './version-detect';
27+
import { wpVersionToStaticAssetsDirectory } from '@wp-playground/wordpress-builds';
2628

2729
export type PhpIniOptions = Record<string, string>;
2830
export type Hook = (php: PHP) => void | Promise<void>;
@@ -195,11 +197,6 @@ export async function bootWordPress(options: BootOptions) {
195197
php.defineConstant('WP_HOME', options.siteUrl);
196198
php.defineConstant('WP_SITEURL', options.siteUrl);
197199

198-
// Run "before database" hooks to mount/copy more files in
199-
if (options.hooks?.beforeDatabaseSetup) {
200-
await options.hooks.beforeDatabaseSetup(php);
201-
}
202-
203200
// @TODO Assert WordPress core files are in place
204201

205202
const remoteAssetListPath = joinPaths(
@@ -221,9 +218,13 @@ export async function bootWordPress(options: BootOptions) {
221218
requestHandler
222219
);
223220
if (isSupportedWordPressVersion(loadedWordPressVersion)) {
224-
// TODO: Is this an absolute URI we can count on?
225-
const wpAssetBaseUrl = `/wp-${loadedWordPressVersion}`;
226-
const listUrl = `${wpAssetBaseUrl}/wordpress-remote-asset-paths`;
221+
const unscopedBaseUrl = removeURLScope(
222+
new URL(requestHandler.absoluteUrl)
223+
);
224+
const wpStaticAssetsDir = wpVersionToStaticAssetsDirectory(
225+
loadedWordPressVersion
226+
);
227+
const listUrl = `${unscopedBaseUrl.href}/${wpStaticAssetsDir}/wordpress-remote-asset-paths`;
227228
try {
228229
const remoteAssetPaths = await fetch(listUrl).then((res) =>
229230
res.text()
@@ -237,6 +238,11 @@ export async function bootWordPress(options: BootOptions) {
237238
}
238239
}
239240

241+
// Run "before database" hooks to mount/copy more files in
242+
if (options.hooks?.beforeDatabaseSetup) {
243+
await options.hooks.beforeDatabaseSetup(php);
244+
}
245+
240246
if (options.sqliteIntegrationPluginZip) {
241247
await preloadSqliteIntegration(
242248
php,

0 commit comments

Comments
 (0)