@@ -18,6 +18,11 @@ import {
18
18
wordPressRewriteRules ,
19
19
} from '.' ;
20
20
import { joinPaths } from '@php-wasm/util' ;
21
+ import { logger } from '@php-wasm/logger' ;
22
+ import {
23
+ getLoadedWordPressVersion ,
24
+ isSupportedWordPressVersion ,
25
+ } from './version-detect' ;
21
26
22
27
export type PhpIniOptions = Record < string , string > ;
23
28
export type Hook = ( php : PHP ) => void | Promise < void > ;
@@ -190,13 +195,48 @@ export async function bootWordPress(options: BootOptions) {
190
195
php . defineConstant ( 'WP_HOME' , options . siteUrl ) ;
191
196
php . defineConstant ( 'WP_SITEURL' , options . siteUrl ) ;
192
197
193
- // @TODO Assert WordPress core files are in place
194
-
195
198
// Run "before database" hooks to mount/copy more files in
196
199
if ( options . hooks ?. beforeDatabaseSetup ) {
197
200
await options . hooks . beforeDatabaseSetup ( php ) ;
198
201
}
199
202
203
+ // @TODO Assert WordPress core files are in place
204
+
205
+ const remoteAssetListPath = joinPaths (
206
+ requestHandler . documentRoot ,
207
+ 'wordpress-remote-asset-paths'
208
+ ) ;
209
+ // Use a common WP static asset to guess whether we are using a minified WP build.
210
+ const commonStaticAssetPath = joinPaths (
211
+ requestHandler . documentRoot ,
212
+ 'wp-admin/css/common.css'
213
+ ) ;
214
+ if (
215
+ ! php . fileExists ( remoteAssetListPath ) &&
216
+ ! php . fileExists ( commonStaticAssetPath )
217
+ ) {
218
+ // We are missing the remote asset listing and a common static file.
219
+ // This looks like a minified WP build missing a remote asset listing.
220
+ const loadedWordPressVersion = await getLoadedWordPressVersion (
221
+ requestHandler
222
+ ) ;
223
+ 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` ;
227
+ try {
228
+ const remoteAssetPaths = await fetch ( listUrl ) . then ( ( res ) =>
229
+ res . text ( )
230
+ ) ;
231
+ php . writeFile ( remoteAssetListPath , remoteAssetPaths ) ;
232
+ } catch ( e ) {
233
+ logger . warn (
234
+ `Failed to fetch remote asset paths from ${ listUrl } `
235
+ ) ;
236
+ }
237
+ }
238
+ }
239
+
200
240
if ( options . sqliteIntegrationPluginZip ) {
201
241
await preloadSqliteIntegration (
202
242
php ,
0 commit comments