@wp-playground/wordpress 0.9.30 → 0.9.31
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.js +17 -12
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import{joinPaths as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import{joinPaths as s,phpVar as o}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as f,withPHPIniValues as w,PHP as g,setPhpIniEntries as _,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";async function x(e){async function r(n,d){const a=new g(await e.createPhpRuntime());return e.sapiName&&a.setSapiName(e.sapiName),n&&(a.requestHandler=n),e.phpIniEntries&&_(a,e.phpIniEntries),d?(await L(a),await m(a,"/",e.createFiles||{}),await S(a,s(new URL(e.siteUrl).pathname,"phpinfo.php"))):h(await n.getPrimaryPhp(),a,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await a.setSpawnHandler(e.spawnHandler(n.processManager)),$({php:a,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),a}const i=new f({phpFactory:async({isPrimary:n})=>r(i,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:E,getFileNotFoundAction:e.getFileNotFoundAction??P}),t=await i.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(t),e.wordPressZip&&await I(t,await e.wordPressZip),e.constants)for(const n in e.constants)t.defineConstant(n,e.constants[n]);if(t.defineConstant("WP_HOME",e.siteUrl),t.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(t),e.sqliteIntegrationPluginZip&&await R(t,await e.sqliteIntegrationPluginZip),await c(t)||await b(t),!await c(t))throw new Error("WordPress installation has failed.");return i}async function c(e){return(await e.run({code:`<?php
|
|
2
|
+
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
3
|
+
if (!file_exists($wp_load)) {
|
|
4
|
+
echo '0';
|
|
5
|
+
exit;
|
|
6
|
+
}
|
|
7
|
+
require $wp_load;
|
|
8
|
+
echo is_blog_installed() ? '1' : '0';
|
|
9
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function b(e){await w(e,{disable_functions:"fsockopen",allow_url_fopen:"0"},async()=>await e.request({url:"/wp-admin/install.php?step=2",method:"POST",body:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:"admin",admin_password:"password",admin_password2:"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}}))}function P(e){return{type:"internal-redirect",uri:"/index.php"}}async function k(e){const t=(await(await e.getPrimaryPhp()).run({code:`<?php
|
|
5
10
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
6
11
|
echo $wp_version;
|
|
7
|
-
`})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return
|
|
12
|
+
`})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return y(t)}function y(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const t=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return t!==null?t[1]:e}const E=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function L(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
|
|
8
13
|
|
|
9
14
|
// Allow adding filters/actions prior to loading WordPress.
|
|
10
15
|
// $function_to_add MUST be a string.
|
|
@@ -111,18 +116,18 @@ import{joinPaths as o,phpVar as s}from"@php-wasm/util";import{unzipFile as l}fro
|
|
|
111
116
|
}
|
|
112
117
|
return false;
|
|
113
118
|
});
|
|
114
|
-
})();`)}async function
|
|
119
|
+
})();`)}async function S(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
|
|
115
120
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
116
|
-
if ( ${
|
|
121
|
+
if ( ${o(r)} === $_SERVER['REQUEST_URI'] ) {
|
|
117
122
|
phpinfo();
|
|
118
123
|
exit;
|
|
119
124
|
}
|
|
120
|
-
`)}async function
|
|
125
|
+
`)}async function R(e,r){await e.isDir("/tmp/sqlite-database-integration")&&await e.rmdir("/tmp/sqlite-database-integration",{recursive:!0}),await e.mkdir("/tmp/sqlite-database-integration"),await l(e,r,"/tmp/sqlite-database-integration");const i="/internal/shared/sqlite-database-integration",t=await e.isDir("/tmp/sqlite-database-integration/sqlite-database-integration-main")?"/tmp/sqlite-database-integration/sqlite-database-integration-main":"/tmp/sqlite-database-integration/sqlite-database-integration-develop";await e.mv(t,i),await e.defineConstant("SQLITE_MAIN_FILE","1");const d=(await e.readFileAsText(s(i,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",o(i)).replace("'{SQLITE_PLUGIN}'",o(s(i,"load.php"))),a=s(await e.documentRoot,"wp-content/db.php"),p=`<?php
|
|
121
126
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
122
|
-
if(file_exists(${
|
|
127
|
+
if(file_exists(${o(a)})) {
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
|
-
?>`,
|
|
130
|
+
?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,p+d),await e.writeFile("/internal/shared/preload/0-sqlite.php",p+`<?php
|
|
126
131
|
|
|
127
132
|
/**
|
|
128
133
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -172,7 +177,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
172
177
|
$GLOBALS['wpdb']->$name = $value;
|
|
173
178
|
}
|
|
174
179
|
protected function load_sqlite_integration() {
|
|
175
|
-
require_once ${
|
|
180
|
+
require_once ${o(u)};
|
|
176
181
|
}
|
|
177
182
|
}
|
|
178
183
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -194,4 +199,4 @@ if(!function_exists('mysqli_connect')) {
|
|
|
194
199
|
var_dump(isset($wpdb));
|
|
195
200
|
die("SQLite integration not loaded " . get_class($wpdb));
|
|
196
201
|
}
|
|
197
|
-
`)}async function
|
|
202
|
+
`)}async function I(e,r){e.mkdir("/tmp/unzipped-wordpress"),await l(e,r,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await l(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");const i=e.fileExists("/tmp/unzipped-wordpress/wordpress")?"/tmp/unzipped-wordpress/wordpress":e.fileExists("/tmp/unzipped-wordpress/build")?"/tmp/unzipped-wordpress/build":"/tmp/unzipped-wordpress";e.mv(i,e.documentRoot),!e.fileExists(s(e.documentRoot,"wp-config.php"))&&e.fileExists(s(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(s(e.documentRoot,"wp-config.php"),e.readFileAsText(s(e.documentRoot,"/wp-config-sample.php")))}export{x as bootWordPress,P as getFileNotFoundActionForWordPress,k as getLoadedWordPressVersion,S as preloadPhpInfoRoute,R as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,I as unzipWordPress,y as versionStringToLoadedWordPressVersion,E as wordPressRewriteRules};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/wordpress",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.31",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"access": "public",
|
|
29
29
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "296845449383439f6304f0559eaacf14cef68989",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"comlink": "^4.4.1",
|
|
34
34
|
"express": "4.19.2",
|
|
35
35
|
"ini": "4.1.2",
|
|
36
36
|
"ws": "8.18.0",
|
|
37
37
|
"yargs": "17.7.2",
|
|
38
|
-
"@php-wasm/universal": "0.9.
|
|
39
|
-
"@php-wasm/util": "0.9.
|
|
40
|
-
"@wp-playground/common": "0.9.
|
|
41
|
-
"@php-wasm/node": "0.9.
|
|
38
|
+
"@php-wasm/universal": "0.9.31",
|
|
39
|
+
"@php-wasm/util": "0.9.31",
|
|
40
|
+
"@wp-playground/common": "0.9.31",
|
|
41
|
+
"@php-wasm/node": "0.9.31"
|
|
42
42
|
}
|
|
43
43
|
}
|