@wp-playground/wordpress 3.0.43 → 3.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +31 -7
- package/index.cjs.map +1 -1
- package/index.js +102 -72
- package/index.js.map +1 -1
- package/package.json +7 -7
package/index.cjs
CHANGED
|
@@ -352,7 +352,7 @@ function skip_whitespace($tokens) {
|
|
|
352
352
|
ob_clean();
|
|
353
353
|
echo false === $return_value ? '0' : '1';
|
|
354
354
|
ob_end_flush();
|
|
355
|
-
`})).text!=="1")throw new Error("Failed to rewrite constants in wp-config.php.")}async function
|
|
355
|
+
`})).text!=="1")throw new Error("Failed to rewrite constants in wp-config.php.")}async function $(e,n){const t=a.joinPaths(n,"wp-config.php"),i={DB_NAME:"wordpress"};!e.fileExists(t)&&e.fileExists(a.joinPaths(n,"wp-config-sample.php"))&&await e.writeFile(t,await e.readFileAsBuffer(a.joinPaths(n,"wp-config-sample.php"))),await g(e,t,i,"skip")}async function I(e){const n=await m(e);return await w(n,e),n}async function w(e,n){var d,s;const t=await e.getPrimaryPhp();if((d=n.hooks)!=null&&d.beforeWordPressFiles&&await n.hooks.beforeWordPressFiles(t),n.wordPressZip&&await S(t,await n.wordPressZip),n.constants)for(const l in n.constants)t.defineConstant(l,n.constants[l]);n.dataSqlPath&&(t.defineConstant("DB_DIR",a.dirname(n.dataSqlPath)),t.defineConstant("DB_FILE",a.basename(n.dataSqlPath))),t.defineConstant("WP_HOME",n.siteUrl),t.defineConstant("WP_SITEURL",n.siteUrl),await $(t,e.documentRoot),(s=n.hooks)!=null&&s.beforeDatabaseSetup&&await n.hooks.beforeDatabaseSetup(t);let i=!1;n.sqliteIntegrationPluginZip&&(i=!0,await T(t,await n.sqliteIntegrationPluginZip));const r=n.wordpressInstallMode??"download-and-install",o=!!n.dataSqlPath;if(["download-and-install","install-from-existing-files"].includes(r)){await f(e,{usesSqlite:i,hasCustomDatabasePath:o});try{await _(t)}catch(l){throw o||await p(e),l}o||await p(e)}else if(r==="install-from-existing-files-if-needed"){if(await f(e,{usesSqlite:i,hasCustomDatabasePath:o}),!await b(t))try{await _(t)}catch(l){throw o||await p(e),l}o||await p(e)}return e}async function f(e,{usesSqlite:n,hasCustomDatabasePath:t}){const i=await e.getPrimaryPhp();if(i.isFile("/internal/shared/preload/0-sqlite.php"))return;const r=a.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");if(!i.isDir(r)&&!n&&!t)throw new Error("Error connecting to the MySQL database.")}async function p(e){const n=await e.getPrimaryPhp();if(await L(n))return;if(n.isFile("/internal/shared/preload/0-sqlite.php"))throw new Error("Error connecting to the SQLite database.");const i=a.joinPaths(e.documentRoot,"wp-content/mu-plugins/sqlite-database-integration");throw n.isDir(i)?new Error("Error connecting to the SQLite database."):new Error("Error connecting to the MySQL database.")}async function m(e){const n=e.spawnHandler??u.sandboxedSpawnHandlerFactory;async function t(r,o=!1){const d=await e.createPhpRuntime(o),s=new u.PHP(d);if(e.sapiName&&s.setSapiName(e.sapiName),r&&(s.requestHandler=r),e.phpIniEntries&&u.setPhpIniEntries(s,e.phpIniEntries),s.defineConstant("WP_SQLITE_AST_DRIVER",!0),e.constants)for(const l in e.constants)s.defineConstant(l,e.constants[l]);return o&&!s.isFile("/internal/.boot-files-written")&&(await E(s),await u.writeFiles(s,"/",e.createFiles||{}),await R(s,a.joinPaths(new URL(e.siteUrl).pathname,"phpinfo.php")),await u.writeFiles(s,"/internal",{".boot-files-written":""})),n&&await s.setSpawnHandler(n(r?()=>r.instanceManager.acquirePHPInstance({considerPrimary:!1}):void 0)),s.enableRuntimeRotation({recreateRuntime:e.createPhpRuntime,maxRequests:400}),e.onPHPInstanceCreated&&await e.onPHPInstanceCreated(s,{isPrimary:o}),s}const i=new u.PHPRequestHandler({documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:k,getFileNotFoundAction:e.getFileNotFoundAction??P,cookieStore:e.cookieStore,php:e.maxPhpInstances===1?await t(void 0,!0):void 0,phpFactory:e.maxPhpInstances!==1?async({isPrimary:r})=>t(i,r):void 0,maxPhpInstances:e.maxPhpInstances});return i}async function b(e){return(await e.run({code:`<?php
|
|
356
356
|
ob_start();
|
|
357
357
|
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
358
358
|
if (!file_exists($wp_load)) {
|
|
@@ -620,7 +620,31 @@ function skip_whitespace($tokens) {
|
|
|
620
620
|
$log_file = WP_CONTENT_DIR . '/debug.log';
|
|
621
621
|
define('ERROR_LOG_FILE', $log_file);
|
|
622
622
|
ini_set('error_log', $log_file);
|
|
623
|
-
?>`),await e.writeFile("/internal/shared/
|
|
623
|
+
?>`),await e.writeFile("/internal/shared/mu-plugins/sitemap-redirect.php",`<?php
|
|
624
|
+
/**
|
|
625
|
+
* Redirect sitemap.xml to wp-sitemap.xml for non-root installations.
|
|
626
|
+
*
|
|
627
|
+
* WordPress seems to only generate the sitemap.xml → wp-sitemap.xml rewrite
|
|
628
|
+
* rule when installed at the domain root. This mu-plugin handles the
|
|
629
|
+
* redirect for non-root installations.
|
|
630
|
+
*/
|
|
631
|
+
if (isset($_SERVER['REQUEST_URI'])) {
|
|
632
|
+
$site_url = site_url();
|
|
633
|
+
$parsed = parse_url($site_url);
|
|
634
|
+
$base_path = isset($parsed['path']) ? rtrim($parsed['path'], '/') : '';
|
|
635
|
+
|
|
636
|
+
$request_uri = $_SERVER['REQUEST_URI'];
|
|
637
|
+
if (
|
|
638
|
+
$request_uri === $base_path . '/sitemap.xml' ||
|
|
639
|
+
strpos($request_uri, $base_path . '/sitemap.xml?') === 0 ||
|
|
640
|
+
strpos($request_uri, $base_path . '/sitemap.xml/') === 0
|
|
641
|
+
) {
|
|
642
|
+
$query_string = strpos($request_uri, '?') !== false ? substr($request_uri, strpos($request_uri, '?')) : '';
|
|
643
|
+
header('Location: ' . $base_path . '/wp-sitemap.xml' . $query_string, true, 301);
|
|
644
|
+
exit;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
`),await e.writeFile("/internal/shared/preload/error-handler.php",`<?php
|
|
624
648
|
(function() {
|
|
625
649
|
$playground_consts = [];
|
|
626
650
|
if(file_exists('/internal/shared/consts.json')) {
|
|
@@ -674,12 +698,12 @@ function skip_whitespace($tokens) {
|
|
|
674
698
|
phpinfo();
|
|
675
699
|
exit;
|
|
676
700
|
}
|
|
677
|
-
`)}async function T(e,n){await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await c.unzipFile(e,n,"/tmp/sqlite-database-integration");const t="/internal/shared/sqlite-database-integration",i=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(i,t),await e.defineConstant("SQLITE_MAIN_FILE","1");const o=(await e.readFileAsText(a.joinPaths(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",a.phpVar(t)).replace("'{SQLITE_PLUGIN}'",a.phpVar(a.joinPaths(t,"load.php"))),
|
|
701
|
+
`)}async function T(e,n){await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await c.unzipFile(e,n,"/tmp/sqlite-database-integration");const t="/internal/shared/sqlite-database-integration",i=`/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;await e.mv(i,t),await e.defineConstant("SQLITE_MAIN_FILE","1");const o=(await e.readFileAsText(a.joinPaths(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",a.phpVar(t)).replace("'{SQLITE_PLUGIN}'",a.phpVar(a.joinPaths(t,"load.php"))),d=a.joinPaths(await e.documentRoot,"wp-content/db.php"),s=`<?php
|
|
678
702
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
679
|
-
if(file_exists(${a.phpVar(
|
|
703
|
+
if(file_exists(${a.phpVar(d)})) {
|
|
680
704
|
return;
|
|
681
705
|
}
|
|
682
|
-
?>`,
|
|
706
|
+
?>`,l="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(l,s+o),await e.writeFile("/internal/shared/preload/0-sqlite.php",s+`<?php
|
|
683
707
|
|
|
684
708
|
/**
|
|
685
709
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -729,7 +753,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
729
753
|
$GLOBALS['wpdb']->$name = $value;
|
|
730
754
|
}
|
|
731
755
|
protected function load_sqlite_integration() {
|
|
732
|
-
require_once ${a.phpVar(
|
|
756
|
+
require_once ${a.phpVar(l)};
|
|
733
757
|
}
|
|
734
758
|
}
|
|
735
759
|
/**
|
|
@@ -760,5 +784,5 @@ if(!function_exists('mysqli_connect')) {
|
|
|
760
784
|
var_dump(isset($wpdb));
|
|
761
785
|
die("SQLite integration not loaded " . get_class($wpdb));
|
|
762
786
|
}
|
|
763
|
-
`)}async function
|
|
787
|
+
`)}async function S(e,n){e.mkdir("/tmp/unzipped-wordpress"),await c.unzipFile(e,n,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await c.unzipFile(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let t=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";if(!e.fileExists(a.joinPaths(t,"wp-config-sample.php"))){const r=e.listFiles(t);if(r.length){const o=r[0];e.fileExists(a.joinPaths(t,o,"wp-config-sample.php"))&&(t=a.joinPaths(t,o))}}const i=(r,o,d)=>{if(d.isDir(r)&&d.isDir(o))for(const s of d.listFiles(r)){const l=a.joinPaths(r,s),v=a.joinPaths(o,s);i(l,v,d)}else{if(d.fileExists(o)){const s=r.replace(/^\/tmp\/unzipped-wordpress\//,"/");h.logger.warn(`Cannot unzip WordPress files at ${o}: ${s} already exists.`);return}d.mv(r,o)}};i(t,e.documentRoot,e),e.fileExists(t)&&e.rmdir(t,{recursive:!0}),!e.fileExists(a.joinPaths(e.documentRoot,"wp-config.php"))&&e.fileExists(a.joinPaths(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(a.joinPaths(e.documentRoot,"wp-config.php"),e.readFileAsText(a.joinPaths(e.documentRoot,"/wp-config-sample.php")))}const U=c.createMemoizedFetch(fetch),C="https://github.com/WordPress/WordPress/archive/refs/heads/master.zip";async function O(e="latest"){if(e===null)e="latest";else if(e.startsWith("https://")||e.startsWith("http://")){const i=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),r=Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+r.substring(0,8),source:"inferred"}}else if(e==="trunk"||e==="nightly"){const i=new Date().toISOString().split("T")[0];return{releaseUrl:`${C}?ts=${i}`,version:"trunk",source:"inferred"}}let t=await(await U("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();t=t.offers.filter(i=>i.response==="autoupdate");for(const i of t){if(e==="beta"&&(i.version.includes("beta")||i.version.includes("RC")))return{releaseUrl:i.download,version:i.version,source:"api"};if(e==="latest"&&!i.version.includes("beta")&&!i.version.includes("RC"))return{releaseUrl:i.download,version:i.version,source:"api"};if(i.version.substring(0,e.length)===e)return{releaseUrl:i.download,version:i.version,source:"api"}}return e.match(/^\d+\.\d+\.0$/)&&(e=e.split(".").slice(0,2).join(".")),{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}exports.bootRequestHandler=m;exports.bootWordPress=w;exports.bootWordPressAndRequestHandler=I;exports.defineWpConfigConstants=g;exports.ensureWpConfig=$;exports.getFileNotFoundActionForWordPress=P;exports.getLoadedWordPressVersion=W;exports.preloadPhpInfoRoute=R;exports.preloadSqliteIntegration=T;exports.resolveWordPressRelease=O;exports.setupPlatformLevelMuPlugins=E;exports.unzipWordPress=S;exports.versionStringToLoadedWordPressVersion=y;exports.wordPressRewriteRules=k;
|
|
764
788
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { phpVars as m, joinPaths as
|
|
1
|
+
import { phpVars as m, joinPaths as o, dirname as b, basename as y, phpVar as u } from "@php-wasm/util";
|
|
2
2
|
import { createMemoizedFetch as P, unzipFile as c } from "@wp-playground/common";
|
|
3
3
|
import { logger as g } from "@php-wasm/logger";
|
|
4
|
-
import { sandboxedSpawnHandlerFactory as k, PHPRequestHandler as E, withPHPIniValues as R, PHP as T, setPhpIniEntries as
|
|
5
|
-
const
|
|
4
|
+
import { sandboxedSpawnHandlerFactory as k, PHPRequestHandler as E, withPHPIniValues as R, PHP as T, setPhpIniEntries as S, writeFiles as f } from "@php-wasm/universal";
|
|
5
|
+
const x = `<?php
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Rewrites the wp-config.php file to ensure specific constants are defined
|
|
@@ -348,11 +348,11 @@ function skip_whitespace($tokens) {
|
|
|
348
348
|
return $output;
|
|
349
349
|
}
|
|
350
350
|
`;
|
|
351
|
-
async function
|
|
351
|
+
async function v(e, n, t, i = "rewrite") {
|
|
352
352
|
const r = m({ wpConfigPath: n, constants: t, whenAlreadyDefined: i });
|
|
353
353
|
if ((await e.run({
|
|
354
354
|
code: `<?php ob_start(); ?>
|
|
355
|
-
${
|
|
355
|
+
${x}
|
|
356
356
|
$wp_config_path = ${r.wpConfigPath};
|
|
357
357
|
$wp_config = file_get_contents($wp_config_path);
|
|
358
358
|
$new_wp_config = rewrite_wp_config_to_define_constants($wp_config, ${r.constants}, ${r.whenAlreadyDefined});
|
|
@@ -365,57 +365,57 @@ async function x(e, n, t, i = "rewrite") {
|
|
|
365
365
|
throw new Error("Failed to rewrite constants in wp-config.php.");
|
|
366
366
|
}
|
|
367
367
|
async function I(e, n) {
|
|
368
|
-
const t =
|
|
368
|
+
const t = o(n, "wp-config.php"), i = {
|
|
369
369
|
DB_NAME: "wordpress"
|
|
370
370
|
};
|
|
371
|
-
!e.fileExists(t) && e.fileExists(
|
|
371
|
+
!e.fileExists(t) && e.fileExists(o(n, "wp-config-sample.php")) && await e.writeFile(
|
|
372
372
|
t,
|
|
373
373
|
await e.readFileAsBuffer(
|
|
374
|
-
|
|
374
|
+
o(n, "wp-config-sample.php")
|
|
375
375
|
)
|
|
376
|
-
), await
|
|
376
|
+
), await v(e, t, i, "skip");
|
|
377
377
|
}
|
|
378
378
|
async function V(e) {
|
|
379
379
|
const n = await U(e);
|
|
380
380
|
return await L(n, e), n;
|
|
381
381
|
}
|
|
382
382
|
async function L(e, n) {
|
|
383
|
-
var
|
|
383
|
+
var d, a;
|
|
384
384
|
const t = await e.getPrimaryPhp();
|
|
385
|
-
if ((
|
|
386
|
-
for (const
|
|
387
|
-
t.defineConstant(
|
|
388
|
-
n.dataSqlPath && (t.defineConstant("DB_DIR", b(n.dataSqlPath)), t.defineConstant("DB_FILE", y(n.dataSqlPath))), t.defineConstant("WP_HOME", n.siteUrl), t.defineConstant("WP_SITEURL", n.siteUrl), await I(t, e.documentRoot), (
|
|
385
|
+
if ((d = n.hooks) != null && d.beforeWordPressFiles && await n.hooks.beforeWordPressFiles(t), n.wordPressZip && await N(t, await n.wordPressZip), n.constants)
|
|
386
|
+
for (const l in n.constants)
|
|
387
|
+
t.defineConstant(l, n.constants[l]);
|
|
388
|
+
n.dataSqlPath && (t.defineConstant("DB_DIR", b(n.dataSqlPath)), t.defineConstant("DB_FILE", y(n.dataSqlPath))), t.defineConstant("WP_HOME", n.siteUrl), t.defineConstant("WP_SITEURL", n.siteUrl), await I(t, e.documentRoot), (a = n.hooks) != null && a.beforeDatabaseSetup && await n.hooks.beforeDatabaseSetup(t);
|
|
389
389
|
let i = !1;
|
|
390
|
-
n.sqliteIntegrationPluginZip && (i = !0, await
|
|
390
|
+
n.sqliteIntegrationPluginZip && (i = !0, await F(
|
|
391
391
|
t,
|
|
392
392
|
await n.sqliteIntegrationPluginZip
|
|
393
393
|
));
|
|
394
|
-
const r = n.wordpressInstallMode ?? "download-and-install",
|
|
394
|
+
const r = n.wordpressInstallMode ?? "download-and-install", s = !!n.dataSqlPath;
|
|
395
395
|
if (["download-and-install", "install-from-existing-files"].includes(
|
|
396
396
|
r
|
|
397
397
|
)) {
|
|
398
398
|
await _(e, {
|
|
399
399
|
usesSqlite: i,
|
|
400
|
-
hasCustomDatabasePath:
|
|
400
|
+
hasCustomDatabasePath: s
|
|
401
401
|
});
|
|
402
402
|
try {
|
|
403
403
|
await h(t);
|
|
404
|
-
} catch (
|
|
405
|
-
throw
|
|
404
|
+
} catch (l) {
|
|
405
|
+
throw s || await p(e), l;
|
|
406
406
|
}
|
|
407
|
-
|
|
407
|
+
s || await p(e);
|
|
408
408
|
} else if (r === "install-from-existing-files-if-needed") {
|
|
409
409
|
if (await _(e, {
|
|
410
410
|
usesSqlite: i,
|
|
411
|
-
hasCustomDatabasePath:
|
|
412
|
-
}), !await
|
|
411
|
+
hasCustomDatabasePath: s
|
|
412
|
+
}), !await $(t))
|
|
413
413
|
try {
|
|
414
414
|
await h(t);
|
|
415
|
-
} catch (
|
|
416
|
-
throw
|
|
415
|
+
} catch (l) {
|
|
416
|
+
throw s || await p(e), l;
|
|
417
417
|
}
|
|
418
|
-
|
|
418
|
+
s || await p(e);
|
|
419
419
|
}
|
|
420
420
|
return e;
|
|
421
421
|
}
|
|
@@ -426,7 +426,7 @@ async function _(e, {
|
|
|
426
426
|
const i = await e.getPrimaryPhp();
|
|
427
427
|
if (i.isFile("/internal/shared/preload/0-sqlite.php"))
|
|
428
428
|
return;
|
|
429
|
-
const r =
|
|
429
|
+
const r = o(
|
|
430
430
|
e.documentRoot,
|
|
431
431
|
"wp-content/mu-plugins/sqlite-database-integration"
|
|
432
432
|
);
|
|
@@ -439,7 +439,7 @@ async function p(e) {
|
|
|
439
439
|
return;
|
|
440
440
|
if (n.isFile("/internal/shared/preload/0-sqlite.php"))
|
|
441
441
|
throw new Error("Error connecting to the SQLite database.");
|
|
442
|
-
const i =
|
|
442
|
+
const i = o(
|
|
443
443
|
e.documentRoot,
|
|
444
444
|
"wp-content/mu-plugins/sqlite-database-integration"
|
|
445
445
|
);
|
|
@@ -447,9 +447,12 @@ async function p(e) {
|
|
|
447
447
|
}
|
|
448
448
|
async function U(e) {
|
|
449
449
|
const n = e.spawnHandler ?? k;
|
|
450
|
-
async function t(r,
|
|
451
|
-
const
|
|
452
|
-
|
|
450
|
+
async function t(r, s = !1) {
|
|
451
|
+
const d = await e.createPhpRuntime(s), a = new T(d);
|
|
452
|
+
if (e.sapiName && a.setSapiName(e.sapiName), r && (a.requestHandler = r), e.phpIniEntries && S(a, e.phpIniEntries), a.defineConstant("WP_SQLITE_AST_DRIVER", !0), e.constants)
|
|
453
|
+
for (const l in e.constants)
|
|
454
|
+
a.defineConstant(l, e.constants[l]);
|
|
455
|
+
return s && /**
|
|
453
456
|
* Only the first PHP instance of the first worker created
|
|
454
457
|
* during WordPress boot writes these files – otherwise we'll keep
|
|
455
458
|
* overwriting them with concurrent writers living in other worker
|
|
@@ -459,12 +462,12 @@ async function U(e) {
|
|
|
459
462
|
* mechanism. It works, because secondary workers are only booted
|
|
460
463
|
* once the primary worker has fully booted.
|
|
461
464
|
*/
|
|
462
|
-
!
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
), await f(
|
|
465
|
+
!a.isFile("/internal/.boot-files-written") && (await A(a), await f(a, "/", e.createFiles || {}), await q(
|
|
466
|
+
a,
|
|
467
|
+
o(new URL(e.siteUrl).pathname, "phpinfo.php")
|
|
468
|
+
), await f(a, "/internal", {
|
|
466
469
|
".boot-files-written": ""
|
|
467
|
-
})), n && await
|
|
470
|
+
})), n && await a.setSpawnHandler(
|
|
468
471
|
n(
|
|
469
472
|
r ? () => r.instanceManager.acquirePHPInstance(
|
|
470
473
|
{
|
|
@@ -472,10 +475,10 @@ async function U(e) {
|
|
|
472
475
|
}
|
|
473
476
|
) : void 0
|
|
474
477
|
)
|
|
475
|
-
),
|
|
478
|
+
), a.enableRuntimeRotation({
|
|
476
479
|
recreateRuntime: e.createPhpRuntime,
|
|
477
480
|
maxRequests: 400
|
|
478
|
-
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(
|
|
481
|
+
}), e.onPHPInstanceCreated && await e.onPHPInstanceCreated(a, { isPrimary: s }), a;
|
|
479
482
|
}
|
|
480
483
|
const i = new E({
|
|
481
484
|
documentRoot: e.documentRoot || "/wordpress",
|
|
@@ -499,7 +502,7 @@ async function U(e) {
|
|
|
499
502
|
});
|
|
500
503
|
return i;
|
|
501
504
|
}
|
|
502
|
-
async function
|
|
505
|
+
async function $(e) {
|
|
503
506
|
return (await e.run({
|
|
504
507
|
code: `<?php
|
|
505
508
|
ob_start();
|
|
@@ -543,7 +546,7 @@ async function h(e) {
|
|
|
543
546
|
}
|
|
544
547
|
})
|
|
545
548
|
);
|
|
546
|
-
if (!await
|
|
549
|
+
if (!await $(e))
|
|
547
550
|
throw new Error(
|
|
548
551
|
`Failed to install WordPress – installer responded with "${(i = n.text) == null ? void 0 : i.substring(
|
|
549
552
|
0,
|
|
@@ -877,6 +880,33 @@ async function A(e) {
|
|
|
877
880
|
define('ERROR_LOG_FILE', $log_file);
|
|
878
881
|
ini_set('error_log', $log_file);
|
|
879
882
|
?>`
|
|
883
|
+
), await e.writeFile(
|
|
884
|
+
"/internal/shared/mu-plugins/sitemap-redirect.php",
|
|
885
|
+
`<?php
|
|
886
|
+
/**
|
|
887
|
+
* Redirect sitemap.xml to wp-sitemap.xml for non-root installations.
|
|
888
|
+
*
|
|
889
|
+
* WordPress seems to only generate the sitemap.xml → wp-sitemap.xml rewrite
|
|
890
|
+
* rule when installed at the domain root. This mu-plugin handles the
|
|
891
|
+
* redirect for non-root installations.
|
|
892
|
+
*/
|
|
893
|
+
if (isset($_SERVER['REQUEST_URI'])) {
|
|
894
|
+
$site_url = site_url();
|
|
895
|
+
$parsed = parse_url($site_url);
|
|
896
|
+
$base_path = isset($parsed['path']) ? rtrim($parsed['path'], '/') : '';
|
|
897
|
+
|
|
898
|
+
$request_uri = $_SERVER['REQUEST_URI'];
|
|
899
|
+
if (
|
|
900
|
+
$request_uri === $base_path . '/sitemap.xml' ||
|
|
901
|
+
strpos($request_uri, $base_path . '/sitemap.xml?') === 0 ||
|
|
902
|
+
strpos($request_uri, $base_path . '/sitemap.xml/') === 0
|
|
903
|
+
) {
|
|
904
|
+
$query_string = strpos($request_uri, '?') !== false ? substr($request_uri, strpos($request_uri, '?')) : '';
|
|
905
|
+
header('Location: ' . $base_path . '/wp-sitemap.xml' . $query_string, true, 301);
|
|
906
|
+
exit;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
`
|
|
880
910
|
), await e.writeFile(
|
|
881
911
|
"/internal/shared/preload/error-handler.php",
|
|
882
912
|
`<?php
|
|
@@ -930,7 +960,7 @@ async function A(e) {
|
|
|
930
960
|
})();`
|
|
931
961
|
);
|
|
932
962
|
}
|
|
933
|
-
async function
|
|
963
|
+
async function q(e, n = "/phpinfo.php") {
|
|
934
964
|
await e.writeFile(
|
|
935
965
|
"/internal/shared/preload/phpinfo.php",
|
|
936
966
|
`<?php
|
|
@@ -944,29 +974,29 @@ async function F(e, n = "/phpinfo.php") {
|
|
|
944
974
|
`
|
|
945
975
|
);
|
|
946
976
|
}
|
|
947
|
-
async function
|
|
977
|
+
async function F(e, n) {
|
|
948
978
|
await e.isDir("/tmp/sqlite-database-integration") && await e.rmdir("/tmp/sqlite-database-integration", {
|
|
949
979
|
recursive: !0
|
|
950
980
|
}), await e.mkdir("/tmp/sqlite-database-integration"), await c(e, n, "/tmp/sqlite-database-integration");
|
|
951
981
|
const t = "/internal/shared/sqlite-database-integration", i = `/tmp/sqlite-database-integration/${(await e.listFiles("/tmp/sqlite-database-integration"))[0]}`;
|
|
952
982
|
await e.mv(i, t), await e.defineConstant("SQLITE_MAIN_FILE", "1");
|
|
953
|
-
const
|
|
954
|
-
|
|
983
|
+
const s = (await e.readFileAsText(
|
|
984
|
+
o(t, "db.copy")
|
|
955
985
|
)).replace(
|
|
956
986
|
"'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",
|
|
957
987
|
u(t)
|
|
958
988
|
).replace(
|
|
959
989
|
"'{SQLITE_PLUGIN}'",
|
|
960
|
-
u(
|
|
961
|
-
),
|
|
990
|
+
u(o(t, "load.php"))
|
|
991
|
+
), d = o(await e.documentRoot, "wp-content/db.php"), a = `<?php
|
|
962
992
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
963
|
-
if(file_exists(${u(
|
|
993
|
+
if(file_exists(${u(d)})) {
|
|
964
994
|
return;
|
|
965
995
|
}
|
|
966
|
-
?>`,
|
|
967
|
-
await e.writeFile(
|
|
996
|
+
?>`, l = "/internal/shared/mu-plugins/sqlite-database-integration.php";
|
|
997
|
+
await e.writeFile(l, a + s), await e.writeFile(
|
|
968
998
|
"/internal/shared/preload/0-sqlite.php",
|
|
969
|
-
|
|
999
|
+
a + `<?php
|
|
970
1000
|
|
|
971
1001
|
/**
|
|
972
1002
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -1016,7 +1046,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
1016
1046
|
$GLOBALS['wpdb']->$name = $value;
|
|
1017
1047
|
}
|
|
1018
1048
|
protected function load_sqlite_integration() {
|
|
1019
|
-
require_once ${u(
|
|
1049
|
+
require_once ${u(l)};
|
|
1020
1050
|
}
|
|
1021
1051
|
}
|
|
1022
1052
|
/**
|
|
@@ -1053,46 +1083,46 @@ if(!function_exists('mysqli_connect')) {
|
|
|
1053
1083
|
`
|
|
1054
1084
|
);
|
|
1055
1085
|
}
|
|
1056
|
-
async function
|
|
1086
|
+
async function N(e, n) {
|
|
1057
1087
|
e.mkdir("/tmp/unzipped-wordpress"), await c(e, n, "/tmp/unzipped-wordpress"), e.fileExists("/tmp/unzipped-wordpress/wordpress.zip") && await c(
|
|
1058
1088
|
e,
|
|
1059
1089
|
"/tmp/unzipped-wordpress/wordpress.zip",
|
|
1060
1090
|
"/tmp/unzipped-wordpress"
|
|
1061
1091
|
);
|
|
1062
1092
|
let t = e.fileExists("/tmp/unzipped-wordpress/wordpress") ? "/tmp/unzipped-wordpress/wordpress" : e.fileExists("/tmp/unzipped-wordpress/build") ? "/tmp/unzipped-wordpress/build" : "/tmp/unzipped-wordpress";
|
|
1063
|
-
if (!e.fileExists(
|
|
1093
|
+
if (!e.fileExists(o(t, "wp-config-sample.php"))) {
|
|
1064
1094
|
const r = e.listFiles(t);
|
|
1065
1095
|
if (r.length) {
|
|
1066
|
-
const
|
|
1096
|
+
const s = r[0];
|
|
1067
1097
|
e.fileExists(
|
|
1068
|
-
|
|
1069
|
-
) && (t =
|
|
1098
|
+
o(t, s, "wp-config-sample.php")
|
|
1099
|
+
) && (t = o(t, s));
|
|
1070
1100
|
}
|
|
1071
1101
|
}
|
|
1072
|
-
const i = (r,
|
|
1073
|
-
if (
|
|
1074
|
-
for (const
|
|
1075
|
-
const
|
|
1076
|
-
i(
|
|
1102
|
+
const i = (r, s, d) => {
|
|
1103
|
+
if (d.isDir(r) && d.isDir(s))
|
|
1104
|
+
for (const a of d.listFiles(r)) {
|
|
1105
|
+
const l = o(r, a), w = o(s, a);
|
|
1106
|
+
i(l, w, d);
|
|
1077
1107
|
}
|
|
1078
1108
|
else {
|
|
1079
|
-
if (
|
|
1080
|
-
const
|
|
1109
|
+
if (d.fileExists(s)) {
|
|
1110
|
+
const a = r.replace(
|
|
1081
1111
|
/^\/tmp\/unzipped-wordpress\//,
|
|
1082
1112
|
"/"
|
|
1083
1113
|
);
|
|
1084
1114
|
g.warn(
|
|
1085
|
-
`Cannot unzip WordPress files at ${
|
|
1115
|
+
`Cannot unzip WordPress files at ${s}: ${a} already exists.`
|
|
1086
1116
|
);
|
|
1087
1117
|
return;
|
|
1088
1118
|
}
|
|
1089
|
-
|
|
1119
|
+
d.mv(r, s);
|
|
1090
1120
|
}
|
|
1091
1121
|
};
|
|
1092
|
-
i(t, e.documentRoot, e), e.fileExists(t) && e.rmdir(t, { recursive: !0 }), !e.fileExists(
|
|
1093
|
-
|
|
1122
|
+
i(t, e.documentRoot, e), e.fileExists(t) && e.rmdir(t, { recursive: !0 }), !e.fileExists(o(e.documentRoot, "wp-config.php")) && e.fileExists(o(e.documentRoot, "wp-config-sample.php")) && e.writeFile(
|
|
1123
|
+
o(e.documentRoot, "wp-config.php"),
|
|
1094
1124
|
e.readFileAsText(
|
|
1095
|
-
|
|
1125
|
+
o(e.documentRoot, "/wp-config-sample.php")
|
|
1096
1126
|
)
|
|
1097
1127
|
);
|
|
1098
1128
|
}
|
|
@@ -1104,7 +1134,7 @@ async function Z(e = "latest") {
|
|
|
1104
1134
|
const i = await crypto.subtle.digest(
|
|
1105
1135
|
"SHA-1",
|
|
1106
1136
|
new TextEncoder().encode(e)
|
|
1107
|
-
), r = Array.from(new Uint8Array(i)).map((
|
|
1137
|
+
), r = Array.from(new Uint8Array(i)).map((s) => s.toString(16).padStart(2, "0")).join("");
|
|
1108
1138
|
return {
|
|
1109
1139
|
releaseUrl: e,
|
|
1110
1140
|
version: "custom-" + r.substring(0, 8),
|
|
@@ -1154,15 +1184,15 @@ export {
|
|
|
1154
1184
|
U as bootRequestHandler,
|
|
1155
1185
|
L as bootWordPress,
|
|
1156
1186
|
V as bootWordPressAndRequestHandler,
|
|
1157
|
-
|
|
1187
|
+
v as defineWpConfigConstants,
|
|
1158
1188
|
I as ensureWpConfig,
|
|
1159
1189
|
W as getFileNotFoundActionForWordPress,
|
|
1160
1190
|
j as getLoadedWordPressVersion,
|
|
1161
|
-
|
|
1162
|
-
|
|
1191
|
+
q as preloadPhpInfoRoute,
|
|
1192
|
+
F as preloadSqliteIntegration,
|
|
1163
1193
|
Z as resolveWordPressRelease,
|
|
1164
1194
|
A as setupPlatformLevelMuPlugins,
|
|
1165
|
-
|
|
1195
|
+
N as unzipWordPress,
|
|
1166
1196
|
O as versionStringToLoadedWordPressVersion,
|
|
1167
1197
|
D as wordPressRewriteRules
|
|
1168
1198
|
};
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/wordpress",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.44",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
"access": "public",
|
|
36
36
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "16881b9b024e961a5254be5b366fad096585c310",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"express": "4.22.0",
|
|
41
41
|
"ini": "4.1.2",
|
|
42
42
|
"wasm-feature-detect": "1.8.0",
|
|
43
43
|
"ws": "8.18.3",
|
|
44
44
|
"yargs": "17.7.2",
|
|
45
|
-
"@php-wasm/universal": "3.0.
|
|
46
|
-
"@php-wasm/util": "3.0.
|
|
47
|
-
"@php-wasm/logger": "3.0.
|
|
48
|
-
"@wp-playground/common": "3.0.
|
|
49
|
-
"@php-wasm/node": "3.0.
|
|
45
|
+
"@php-wasm/universal": "3.0.44",
|
|
46
|
+
"@php-wasm/util": "3.0.44",
|
|
47
|
+
"@php-wasm/logger": "3.0.44",
|
|
48
|
+
"@wp-playground/common": "3.0.44",
|
|
49
|
+
"@php-wasm/node": "3.0.44"
|
|
50
50
|
},
|
|
51
51
|
"packageManager": "npm@10.9.2",
|
|
52
52
|
"overrides": {
|