@wp-playground/wordpress 1.0.17 → 1.0.19
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 +39 -8
- package/index.js.map +1 -0
- package/package.json +7 -7
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{joinPaths as a,phpVar as l}from"@php-wasm/util";import{createMemoizedFetch as _,unzipFile as d}from"@wp-playground/common";import{PHPRequestHandler as
|
|
1
|
+
import{joinPaths as a,phpVar as l}from"@php-wasm/util";import{createMemoizedFetch as _,unzipFile as d}from"@wp-playground/common";import{PHPRequestHandler as g,withPHPIniValues as f,PHP as h,setPhpIniEntries as w,writeFiles as m,proxyFileSystem as b,rotatePHPRuntime as y}from"@php-wasm/universal";import{logger as $}from"@php-wasm/logger";async function q(e){async function r(n,o){const s=new h(await e.createPhpRuntime());return e.sapiName&&s.setSapiName(e.sapiName),n&&(s.requestHandler=n),e.phpIniEntries&&w(s,e.phpIniEntries),o?(await T(s),await m(s,"/",e.createFiles||{}),await L(s,a(new URL(e.siteUrl).pathname,"phpinfo.php"))):b(await n.getPrimaryPhp(),s,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await s.setSpawnHandler(e.spawnHandler(n.processManager)),y({php:s,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),s}const i=new g({phpFactory:async({isPrimary:n})=>r(i,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:S,getFileNotFoundAction:e.getFileNotFoundAction??E}),t=await i.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(t),e.wordPressZip&&await v(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 I(t,await e.sqliteIntegrationPluginZip),await c(t)||await P(t),!await c(t))throw new Error("WordPress installation has failed.");return i}async function c(e){return(await e.run({code:`<?php
|
|
2
2
|
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
3
3
|
if (!file_exists($wp_load)) {
|
|
4
4
|
echo '0';
|
|
@@ -6,7 +6,7 @@ if (!file_exists($wp_load)) {
|
|
|
6
6
|
}
|
|
7
7
|
require $wp_load;
|
|
8
8
|
echo is_blog_installed() ? '1' : '0';
|
|
9
|
-
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function
|
|
9
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function P(e){await f(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"}})),(await e.run({code:`<?php
|
|
10
10
|
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
11
11
|
if (!file_exists($wp_load)) {
|
|
12
12
|
echo '0';
|
|
@@ -18,10 +18,10 @@ $option_result = update_option(
|
|
|
18
18
|
'/%year%/%monthnum%/%day%/%postname%/'
|
|
19
19
|
);
|
|
20
20
|
echo $option_result ? '1' : '0';
|
|
21
|
-
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"
|
|
21
|
+
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&$.warn("Failed to default to pretty permalinks after WP install.")}function E(e){return{type:"internal-redirect",uri:"/index.php"}}async function A(e){const t=(await(await e.getPrimaryPhp()).run({code:`<?php
|
|
22
22
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
23
23
|
echo $wp_version;
|
|
24
|
-
`})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return R(t)}function R(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 S=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function
|
|
24
|
+
`})).text;if(!t)throw new Error("Unable to read loaded WordPress version.");return R(t)}function R(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 S=[{match:/^\/(.*?)(\/wp-(content|admin|includes)\/.*)/g,replacement:"$2"}];async function T(e){await e.mkdir("/internal/shared/mu-plugins"),await e.writeFile("/internal/shared/preload/env.php",`<?php
|
|
25
25
|
|
|
26
26
|
// Allow adding filters/actions prior to loading WordPress.
|
|
27
27
|
// $function_to_add MUST be a string.
|
|
@@ -107,6 +107,26 @@ echo $option_result ? '1' : '0';
|
|
|
107
107
|
if (!$user) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* We're about to set cookies and redirect. It will log the user in
|
|
113
|
+
* if the headers haven't been sent yet.
|
|
114
|
+
*
|
|
115
|
+
* However, if they have been sent already – e.g. there a PHP
|
|
116
|
+
* notice was printed, we'll exit the script with a bunch of errors
|
|
117
|
+
* on the screen and without the user being logged in. This
|
|
118
|
+
* will happen on every page load and will effectively make Playground
|
|
119
|
+
* unusable.
|
|
120
|
+
*
|
|
121
|
+
* Therefore, we just won't auto-login if headers have been sent. Maybe
|
|
122
|
+
* we'll be able to finish the operation in one of the future requests
|
|
123
|
+
* or maybe not, but at least we won't end up with a permanent white screen.
|
|
124
|
+
*/
|
|
125
|
+
if (headers_sent()) {
|
|
126
|
+
_doing_it_wrong('playground_auto_login', 'Headers already sent, the Playground runtime will not auto-login the user', '1.0.0');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
110
130
|
/**
|
|
111
131
|
* This approach is described in a comment on
|
|
112
132
|
* https://developer.wordpress.org/reference/functions/wp_set_current_user/
|
|
@@ -114,8 +134,18 @@ echo $option_result ? '1' : '0';
|
|
|
114
134
|
wp_set_current_user( $user->ID, $user->user_login );
|
|
115
135
|
wp_set_auth_cookie( $user->ID );
|
|
116
136
|
do_action( 'wp_login', $user->user_login, $user );
|
|
137
|
+
|
|
117
138
|
setcookie('playground_auto_login_already_happened', '1');
|
|
118
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Confirm that nothing in WordPress, plugins, or filters have finalized
|
|
142
|
+
* the headers sending phase. See the comment above for more context.
|
|
143
|
+
*/
|
|
144
|
+
if (headers_sent()) {
|
|
145
|
+
_doing_it_wrong('playground_auto_login', 'Headers already sent, the Playground runtime will not auto-login the user', '1.0.0');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
/**
|
|
120
150
|
* Reload page to ensure the user is logged in correctly.
|
|
121
151
|
* WordPress uses cookies to determine if the user is logged in,
|
|
@@ -230,13 +260,13 @@ echo $option_result ? '1' : '0';
|
|
|
230
260
|
}
|
|
231
261
|
return false;
|
|
232
262
|
});
|
|
233
|
-
})();`)}async function
|
|
263
|
+
})();`)}async function L(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
|
|
234
264
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
235
|
-
if ( ${l(
|
|
265
|
+
if ( ${l(r)} === $_SERVER['REQUEST_URI'] ) {
|
|
236
266
|
phpinfo();
|
|
237
267
|
exit;
|
|
238
268
|
}
|
|
239
|
-
`)}async function I(e,
|
|
269
|
+
`)}async function I(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 d(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 o=(await e.readFileAsText(a(i,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",l(i)).replace("'{SQLITE_PLUGIN}'",l(a(i,"load.php"))),s=a(await e.documentRoot,"wp-content/db.php"),u=`<?php
|
|
240
270
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
241
271
|
if(file_exists(${l(s)})) {
|
|
242
272
|
return;
|
|
@@ -313,4 +343,5 @@ if(!function_exists('mysqli_connect')) {
|
|
|
313
343
|
var_dump(isset($wpdb));
|
|
314
344
|
die("SQLite integration not loaded " . get_class($wpdb));
|
|
315
345
|
}
|
|
316
|
-
`)}async function
|
|
346
|
+
`)}async function v(e,r){e.mkdir("/tmp/unzipped-wordpress"),await d(e,r,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await d(e,"/tmp/unzipped-wordpress/wordpress.zip","/tmp/unzipped-wordpress");let i=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(i,"wp-config-sample.php"))){const t=e.listFiles(i);if(t.length){const n=t[0];e.fileExists(a(i,n,"wp-config-sample.php"))&&(i=a(i,n))}}if(e.isDir(e.documentRoot)&&U(e.documentRoot,e)){for(const t of e.listFiles(i)){const n=a(i,t),o=a(e.documentRoot,t);e.mv(n,o)}e.rmdir(i,{recursive:!0})}else e.mv(i,e.documentRoot);!e.fileExists(a(e.documentRoot,"wp-config.php"))&&e.fileExists(a(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(a(e.documentRoot,"wp-config.php"),e.readFileAsText(a(e.documentRoot,"/wp-config-sample.php")))}function U(e,r){const i=r.listFiles(e);return i.length===0||i.length===1&&i[0]==="playground-site-metadata.json"}const O=_(fetch);async function N(e="latest"){if(e.startsWith("https://")||e.startsWith("http://")){const t=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),n=Array.from(new Uint8Array(t)).map(o=>o.toString(16).padStart(2,"0")).join("");return{releaseUrl:e,version:"custom-"+n.substring(0,8),source:"inferred"}}else if(e==="trunk"||e==="nightly")return{releaseUrl:"https://wordpress.org/nightly-builds/wordpress-latest.zip",version:"nightly-"+new Date().toISOString().split("T")[0],source:"inferred"};let i=await(await O("https://api.wordpress.org/core/version-check/1.7/?channel=beta")).json();i=i.offers.filter(t=>t.response==="autoupdate");for(const t of i){if(e==="beta"&&t.version.includes("beta"))return{releaseUrl:t.download,version:t.version,source:"api"};if(e==="latest"&&!t.version.includes("beta"))return{releaseUrl:t.download,version:t.version,source:"api"};if(t.version.substring(0,e.length)===e)return{releaseUrl:t.download,version:t.version,source:"api"}}return{releaseUrl:`https://wordpress.org/wordpress-${e}.zip`,version:e,source:"inferred"}}export{q as bootWordPress,E as getFileNotFoundActionForWordPress,A as getLoadedWordPressVersion,L as preloadPhpInfoRoute,I as preloadSqliteIntegration,N as resolveWordPressRelease,T as setupPlatformLevelMuPlugins,v as unzipWordPress,R as versionStringToLoadedWordPressVersion,S as wordPressRewriteRules};
|
|
347
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public",
|
|
29
29
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "13938f0d995655ef9e174ddc9ef51408210237d5",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"comlink": "^4.4.1",
|
|
34
34
|
"events": "3.3.0",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"wasm-feature-detect": "1.8.0",
|
|
38
38
|
"ws": "8.18.0",
|
|
39
39
|
"yargs": "17.7.2",
|
|
40
|
-
"@php-wasm/universal": "1.0.
|
|
41
|
-
"@php-wasm/util": "1.0.
|
|
42
|
-
"@php-wasm/logger": "1.0.
|
|
43
|
-
"@wp-playground/common": "1.0.
|
|
44
|
-
"@php-wasm/node": "1.0.
|
|
40
|
+
"@php-wasm/universal": "1.0.19",
|
|
41
|
+
"@php-wasm/util": "1.0.19",
|
|
42
|
+
"@php-wasm/logger": "1.0.19",
|
|
43
|
+
"@wp-playground/common": "1.0.19",
|
|
44
|
+
"@php-wasm/node": "1.0.19"
|
|
45
45
|
}
|
|
46
46
|
}
|