@wp-playground/wordpress 0.9.46 → 1.0.0
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 +86 -22
- package/package.json +7 -6
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{joinPaths as
|
|
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
|
|
2
2
|
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';
|
|
3
3
|
if (!file_exists($wp_load)) {
|
|
4
4
|
echo '0';
|
|
@@ -6,10 +6,10 @@ 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 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
|
|
10
10
|
require '${e.documentRoot}/wp-includes/version.php';
|
|
11
11
|
echo $wp_version;
|
|
12
|
-
`})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return
|
|
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
|
|
13
13
|
|
|
14
14
|
// Allow adding filters/actions prior to loading WordPress.
|
|
15
15
|
// $function_to_add MUST be a string.
|
|
@@ -36,7 +36,82 @@ echo is_blog_installed() ? '1' : '0';
|
|
|
36
36
|
require_once $mu_plugin;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
`),await e.writeFile("/internal/shared/mu-plugins/
|
|
39
|
+
`),await e.writeFile("/internal/shared/mu-plugins/1-auto-login.php",`<?php
|
|
40
|
+
/**
|
|
41
|
+
* Returns the username to auto-login as, if any.
|
|
42
|
+
* @return string|false
|
|
43
|
+
*/
|
|
44
|
+
function playground_get_username_for_auto_login() {
|
|
45
|
+
/**
|
|
46
|
+
* Allow users to auto-login as a specific user on their first visit.
|
|
47
|
+
*
|
|
48
|
+
* Prevent the auto-login if it already happened by checking for the
|
|
49
|
+
* playground_auto_login_already_happened cookie.
|
|
50
|
+
* This is used to allow the user to logout.
|
|
51
|
+
*/
|
|
52
|
+
if ( defined('PLAYGROUND_AUTO_LOGIN_AS_USER') && !isset($_COOKIE['playground_auto_login_already_happened']) ) {
|
|
53
|
+
return PLAYGROUND_AUTO_LOGIN_AS_USER;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Allow users to auto-login as a specific user by passing the
|
|
57
|
+
* playground_force_auto_login_as_user GET parameter.
|
|
58
|
+
*/
|
|
59
|
+
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']);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Logs the user in on their first visit if the Playground runtime told us to.
|
|
66
|
+
*/
|
|
67
|
+
function playground_auto_login() {
|
|
68
|
+
$user_name = playground_get_username_for_auto_login();
|
|
69
|
+
if ( false === $user_name ) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (wp_doing_ajax() || defined('REST_REQUEST')) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if ( is_user_logged_in() ) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
$user = get_user_by('login', $user_name);
|
|
79
|
+
if (!$user) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
wp_set_current_user( $user->ID, $user->user_login );
|
|
83
|
+
wp_set_auth_cookie( $user->ID );
|
|
84
|
+
do_action( 'wp_login', $user->user_login, $user );
|
|
85
|
+
setcookie('playground_auto_login_already_happened', '1');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Autologin users from the wp-login.php page.
|
|
90
|
+
*
|
|
91
|
+
* The wp hook isn't triggered on
|
|
92
|
+
**/
|
|
93
|
+
add_action('init', function() {
|
|
94
|
+
playground_auto_login();
|
|
95
|
+
/**
|
|
96
|
+
* Check if the request is for the login page.
|
|
97
|
+
*/
|
|
98
|
+
if (is_login() && is_user_logged_in() && isset($_GET['redirect_to'])) {
|
|
99
|
+
wp_redirect(esc_url($_GET['redirect_to']));
|
|
100
|
+
exit;
|
|
101
|
+
}
|
|
102
|
+
}, 1);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Disable the Site Admin Email Verification Screen for any session started
|
|
106
|
+
* via autologin.
|
|
107
|
+
*/
|
|
108
|
+
add_filter('admin_email_check_interval', function($interval) {
|
|
109
|
+
if(false === playground_get_username_for_auto_login()) {
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
return $interval;
|
|
113
|
+
});
|
|
114
|
+
`),await e.writeFile("/internal/shared/mu-plugins/0-playground.php",`<?php
|
|
40
115
|
// Needed because gethostbyname( 'wordpress.org' ) returns
|
|
41
116
|
// a private network IP address for some reason.
|
|
42
117
|
add_filter( 'allowed_redirect_hosts', function( $deprecated = '' ) {
|
|
@@ -66,17 +141,6 @@ echo is_blog_installed() ? '1' : '0';
|
|
|
66
141
|
$playground_consts = array_keys($playground_consts);
|
|
67
142
|
}
|
|
68
143
|
set_error_handler(function($severity, $message, $file, $line) use($playground_consts) {
|
|
69
|
-
/**
|
|
70
|
-
* We're forced to use this deprecated hook to ensure SSL operations work without
|
|
71
|
-
* the kitchen-sink bundled. See https://github.com/WordPress/wordpress-playground/pull/1504
|
|
72
|
-
* for more context.
|
|
73
|
-
*/
|
|
74
|
-
if (
|
|
75
|
-
strpos($message, "Hook http_api_transports is deprecated") !== false ||
|
|
76
|
-
strpos($message, "Hook http_api_transports is <strong>deprecated</strong>") !== false
|
|
77
|
-
) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
144
|
/**
|
|
81
145
|
* This is a temporary workaround to hide the 32bit integer warnings that
|
|
82
146
|
* appear when using various time related function, such as strtotime and mktime.
|
|
@@ -116,18 +180,18 @@ echo is_blog_installed() ? '1' : '0';
|
|
|
116
180
|
}
|
|
117
181
|
return false;
|
|
118
182
|
});
|
|
119
|
-
})();`)}async function
|
|
183
|
+
})();`)}async function R(e,a="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
|
|
120
184
|
// Render PHPInfo if the requested page is /phpinfo.php
|
|
121
|
-
if ( ${d(
|
|
185
|
+
if ( ${d(a)} === $_SERVER['REQUEST_URI'] ) {
|
|
122
186
|
phpinfo();
|
|
123
187
|
exit;
|
|
124
188
|
}
|
|
125
|
-
`)}async function
|
|
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
|
|
126
190
|
// Do not preload this if WordPress comes with a custom db.php file.
|
|
127
|
-
if(file_exists(${d(
|
|
191
|
+
if(file_exists(${d(o)})) {
|
|
128
192
|
return;
|
|
129
193
|
}
|
|
130
|
-
?>`,
|
|
194
|
+
?>`,p="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(p,u+s),await e.writeFile("/internal/shared/preload/0-sqlite.php",u+`<?php
|
|
131
195
|
|
|
132
196
|
/**
|
|
133
197
|
* Loads the SQLite integration plugin before WordPress is loaded
|
|
@@ -177,7 +241,7 @@ class Playground_SQLite_Integration_Loader {
|
|
|
177
241
|
$GLOBALS['wpdb']->$name = $value;
|
|
178
242
|
}
|
|
179
243
|
protected function load_sqlite_integration() {
|
|
180
|
-
require_once ${d(
|
|
244
|
+
require_once ${d(p)};
|
|
181
245
|
}
|
|
182
246
|
}
|
|
183
247
|
$wpdb = $GLOBALS['wpdb'] = new Playground_SQLite_Integration_Loader();
|
|
@@ -199,4 +263,4 @@ if(!function_exists('mysqli_connect')) {
|
|
|
199
263
|
var_dump(isset($wpdb));
|
|
200
264
|
die("SQLite integration not loaded " . get_class($wpdb));
|
|
201
265
|
}
|
|
202
|
-
`)}async function
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/wordpress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "WordPress-related plumbing for WordPress Playground",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,16 +28,17 @@
|
|
|
28
28
|
"access": "public",
|
|
29
29
|
"directory": "../../../dist/packages/playground/wordpress"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "9461d056ede8310ecfe01b72b5b095998a742ea3",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"comlink": "^4.4.1",
|
|
34
34
|
"express": "4.19.2",
|
|
35
35
|
"ini": "4.1.2",
|
|
36
|
+
"wasm-feature-detect": "1.8.0",
|
|
36
37
|
"ws": "8.18.0",
|
|
37
38
|
"yargs": "17.7.2",
|
|
38
|
-
"@php-wasm/universal": "0.
|
|
39
|
-
"@php-wasm/util": "0.
|
|
40
|
-
"@wp-playground/common": "0.
|
|
41
|
-
"@php-wasm/node": "0.
|
|
39
|
+
"@php-wasm/universal": "1.0.0",
|
|
40
|
+
"@php-wasm/util": "1.0.0",
|
|
41
|
+
"@wp-playground/common": "1.0.0",
|
|
42
|
+
"@php-wasm/node": "1.0.0"
|
|
42
43
|
}
|
|
43
44
|
}
|