@wp-playground/wordpress 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/index.js +34 -10
  2. package/package.json +7 -6
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{joinPaths as r,phpVar as d}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as c,withPHPIniValues as f,PHP as g,setPhpIniEntries as w,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";async function v(e){async function a(n,s){const o=new g(await e.createPhpRuntime());return e.sapiName&&o.setSapiName(e.sapiName),n&&(o.requestHandler=n),e.phpIniEntries&&w(o,e.phpIniEntries),s?(await L(o),await m(o,"/",e.createFiles||{}),await R(o,r(new URL(e.siteUrl).pathname,"phpinfo.php"))):h(await n.getPrimaryPhp(),o,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await o.setSpawnHandler(e.spawnHandler(n.processManager)),$({php:o,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),o}const t=new c({phpFactory:async({isPrimary:n})=>a(t,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:E,getFileNotFoundAction:e.getFileNotFoundAction??P}),i=await t.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(i),e.wordPressZip&&await T(i,await e.wordPressZip),e.constants)for(const n in e.constants)i.defineConstant(n,e.constants[n]);if(i.defineConstant("WP_HOME",e.siteUrl),i.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(i),e.sqliteIntegrationPluginZip&&await S(i,await e.sqliteIntegrationPluginZip),await _(i)||await y(i),!await _(i))throw new Error("WordPress installation has failed.");return t}async function _(e){return(await e.run({code:`<?php
1
+ import{joinPaths as a,phpVar as d}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as c,withPHPIniValues as f,PHP as g,setPhpIniEntries as w,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";import{logger as y}from"@php-wasm/logger";async function U(e){async function r(n,s){const o=new g(await e.createPhpRuntime());return e.sapiName&&o.setSapiName(e.sapiName),n&&(o.requestHandler=n),e.phpIniEntries&&w(o,e.phpIniEntries),s?(await L(o),await m(o,"/",e.createFiles||{}),await S(o,a(new URL(e.siteUrl).pathname,"phpinfo.php"))):h(await n.getPrimaryPhp(),o,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await o.setSpawnHandler(e.spawnHandler(n.processManager)),$({php:o,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),o}const t=new c({phpFactory:async({isPrimary:n})=>r(t,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:R,getFileNotFoundAction:e.getFileNotFoundAction??b}),i=await t.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(i),e.wordPressZip&&await O(i,await e.wordPressZip),e.constants)for(const n in e.constants)i.defineConstant(n,e.constants[n]);if(i.defineConstant("WP_HOME",e.siteUrl),i.defineConstant("WP_SITEURL",e.siteUrl),e.hooks?.beforeDatabaseSetup&&await e.hooks.beforeDatabaseSetup(i),e.sqliteIntegrationPluginZip&&await T(i,await e.sqliteIntegrationPluginZip),await _(i)||await P(i),!await _(i))throw new Error("WordPress installation has failed.");return t}async function _(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,10 +6,22 @@ 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 y(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"}}))}function P(e){return{type:"internal-redirect",uri:"/index.php"}}async function W(e){const i=(await(await e.getPrimaryPhp()).run({code:`<?php
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
+ $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
11
+ if (!file_exists($wp_load)) {
12
+ echo '0';
13
+ exit;
14
+ }
15
+ require $wp_load;
16
+ $option_result = update_option(
17
+ 'permalink_structure',
18
+ '/%year%/%monthnum%/%day%/%postname%/'
19
+ );
20
+ echo $option_result ? '1' : '0';
21
+ `,env:{DOCUMENT_ROOT:e.documentRoot}})).text!=="1"&&y.warn("Failed to default to pretty permalinks after WP install.")}function b(e){return{type:"internal-redirect",uri:"/index.php"}}async function W(e){const i=(await(await e.getPrimaryPhp()).run({code:`<?php
10
22
  require '${e.documentRoot}/wp-includes/version.php';
11
23
  echo $wp_version;
12
- `})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return b(i)}function b(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const i=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return i!==null?i[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
24
+ `})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return E(i)}function E(e){if(/-(alpha|beta|RC)\d*-\d+$/.test(e))return"nightly";if(/-(beta|RC)\d*$/.test(e))return"beta";const i=e.match(/^(\d+\.\d+)(?:\.\d+)?$/);return i!==null?i[1]:e}const R=[{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
13
25
 
14
26
  // Allow adding filters/actions prior to loading WordPress.
15
27
  // $function_to_add MUST be a string.
@@ -57,7 +69,7 @@ echo is_blog_installed() ? '1' : '0';
57
69
  * playground_force_auto_login_as_user GET parameter.
58
70
  */
59
71
  if ( defined('PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED') && isset($_GET['playground_force_auto_login_as_user']) ) {
60
- return esc_attr($_GET['playground_force_auto_login_as_user']);
72
+ return $_GET['playground_force_auto_login_as_user'];
61
73
  }
62
74
  return false;
63
75
  }
@@ -95,8 +107,8 @@ echo is_blog_installed() ? '1' : '0';
95
107
  /**
96
108
  * Check if the request is for the login page.
97
109
  */
98
- if (is_login() && is_user_logged_in() && isset($_GET['redirect_to'])) {
99
- wp_redirect(esc_url($_GET['redirect_to']));
110
+ if (is_login() && is_user_logged_in() && !empty($_GET['redirect_to'])) {
111
+ wp_redirect($_GET['redirect_to']);
100
112
  exit;
101
113
  }
102
114
  }, 1);
@@ -152,6 +164,18 @@ echo is_blog_installed() ? '1' : '0';
152
164
  if (strpos($message, "fit in a PHP integer") !== false) {
153
165
  return;
154
166
  }
167
+ /**
168
+ * Networking support in Playground registers a http_api_transports filter.
169
+ *
170
+ * This filter is deprecated, and no longer actively used, but is needed for wp_http_supports().
171
+ * @see https://core.trac.wordpress.org/ticket/37708
172
+ */
173
+ if (
174
+ strpos($message, "http_api_transports") !== false &&
175
+ strpos($message, "since version 6.4.0 with no alternative available") !== false
176
+ ) {
177
+ return;
178
+ }
155
179
  /**
156
180
  * Playground defines some constants upfront, and some of them may be redefined
157
181
  * in wp-config.php. For example, SITE_URL or WP_DEBUG. This is expected and
@@ -180,13 +204,13 @@ echo is_blog_installed() ? '1' : '0';
180
204
  }
181
205
  return false;
182
206
  });
183
- })();`)}async function R(e,a="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
207
+ })();`)}async function S(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
184
208
  // Render PHPInfo if the requested page is /phpinfo.php
185
- if ( ${d(a)} === $_SERVER['REQUEST_URI'] ) {
209
+ if ( ${d(r)} === $_SERVER['REQUEST_URI'] ) {
186
210
  phpinfo();
187
211
  exit;
188
212
  }
189
- `)}async function S(e,a){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,a,"/tmp/sqlite-database-integration");const t="/internal/shared/sqlite-database-integration",i=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(i,t),await e.defineConstant("SQLITE_MAIN_FILE","1");const s=(await e.readFileAsText(r(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",d(t)).replace("'{SQLITE_PLUGIN}'",d(r(t,"load.php"))),o=r(await e.documentRoot,"wp-content/db.php"),u=`<?php
213
+ `)}async function T(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 t="/internal/shared/sqlite-database-integration",i=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(i,t),await e.defineConstant("SQLITE_MAIN_FILE","1");const s=(await e.readFileAsText(a(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",d(t)).replace("'{SQLITE_PLUGIN}'",d(a(t,"load.php"))),o=a(await e.documentRoot,"wp-content/db.php"),u=`<?php
190
214
  // Do not preload this if WordPress comes with a custom db.php file.
191
215
  if(file_exists(${d(o)})) {
192
216
  return;
@@ -263,4 +287,4 @@ if(!function_exists('mysqli_connect')) {
263
287
  var_dump(isset($wpdb));
264
288
  die("SQLite integration not loaded " . get_class($wpdb));
265
289
  }
266
- `)}async function T(e,a){e.mkdir("/tmp/unzipped-wordpress"),await l(e,a,"/tmp/unzipped-wordpress"),e.fileExists("/tmp/unzipped-wordpress/wordpress.zip")&&await l(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(r(t,"wp-config-sample.php"))){const i=e.listFiles(t);if(i.length){const n=i[0];e.fileExists(r(t,n,"wp-config-sample.php"))&&(t=r(t,n))}}if(e.isDir(e.documentRoot)&&I(e.documentRoot,e)){for(const i of e.listFiles(t)){const n=r(t,i),s=r(e.documentRoot,i);e.mv(n,s)}e.rmdir(t,{recursive:!0})}else e.mv(t,e.documentRoot);!e.fileExists(r(e.documentRoot,"wp-config.php"))&&e.fileExists(r(e.documentRoot,"wp-config-sample.php"))&&e.writeFile(r(e.documentRoot,"wp-config.php"),e.readFileAsText(r(e.documentRoot,"/wp-config-sample.php")))}function I(e,a){const t=a.listFiles(e);return t.length===0||t.length===1&&t[0]==="playground-site-metadata.json"}export{v as bootWordPress,P as getFileNotFoundActionForWordPress,W as getLoadedWordPressVersion,R as preloadPhpInfoRoute,S as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,T as unzipWordPress,b as versionStringToLoadedWordPressVersion,E as wordPressRewriteRules};
290
+ `)}async function O(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");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(t,"wp-config-sample.php"))){const i=e.listFiles(t);if(i.length){const n=i[0];e.fileExists(a(t,n,"wp-config-sample.php"))&&(t=a(t,n))}}if(e.isDir(e.documentRoot)&&I(e.documentRoot,e)){for(const i of e.listFiles(t)){const n=a(t,i),s=a(e.documentRoot,i);e.mv(n,s)}e.rmdir(t,{recursive:!0})}else e.mv(t,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 I(e,r){const t=r.listFiles(e);return t.length===0||t.length===1&&t[0]==="playground-site-metadata.json"}export{U as bootWordPress,b as getFileNotFoundActionForWordPress,W as getLoadedWordPressVersion,S as preloadPhpInfoRoute,T as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,O as unzipWordPress,E as versionStringToLoadedWordPressVersion,R as wordPressRewriteRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/wordpress",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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": "dbf1c413c29eeeafe97a286008c146dd5e0c2740",
31
+ "gitHead": "fd76ee2ebbe3d3ff71cf19ab7fe010dca8bcc17b",
32
32
  "dependencies": {
33
33
  "comlink": "^4.4.1",
34
34
  "events": "3.3.0",
@@ -37,9 +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.2",
41
- "@php-wasm/util": "1.0.2",
42
- "@wp-playground/common": "1.0.2",
43
- "@php-wasm/node": "1.0.2"
40
+ "@php-wasm/universal": "1.0.4",
41
+ "@php-wasm/util": "1.0.4",
42
+ "@php-wasm/logger": "1.0.4",
43
+ "@wp-playground/common": "1.0.4",
44
+ "@php-wasm/node": "1.0.4"
44
45
  }
45
46
  }