Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wp-playground/wordpress

Package Overview
Dependencies
Maintainers
0
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wp-playground/wordpress - npm Package Compare versions

Comparing version 0.9.46 to 1.0.0

108

index.js

@@ -1,2 +0,2 @@

import{joinPaths as a,phpVar as d}from"@php-wasm/util";import{unzipFile as l}from"@wp-playground/common";import{PHPRequestHandler as f,withPHPIniValues as g,PHP as w,setPhpIniEntries as _,writeFiles as m,proxyFileSystem as h,rotatePHPRuntime as $}from"@php-wasm/universal";async function k(e){async function r(n,o){const s=new w(await e.createPhpRuntime());return e.sapiName&&s.setSapiName(e.sapiName),n&&(s.requestHandler=n),e.phpIniEntries&&_(s,e.phpIniEntries),o?(await L(s),await m(s,"/",e.createFiles||{}),await S(s,a(new URL(e.siteUrl).pathname,"phpinfo.php"))):h(await n.getPrimaryPhp(),s,["/tmp",n.documentRoot,"/internal/shared"]),e.spawnHandler&&await s.setSpawnHandler(e.spawnHandler(n.processManager)),$({php:s,cwd:n.documentRoot,recreateRuntime:e.createPhpRuntime,maxRequests:400}),s}const t=new f({phpFactory:async({isPrimary:n})=>r(t,n),documentRoot:e.documentRoot||"/wordpress",absoluteUrl:e.siteUrl,rewriteRules:E,getFileNotFoundAction:e.getFileNotFoundAction??b}),i=await t.getPrimaryPhp();if(e.hooks?.beforeWordPressFiles&&await e.hooks.beforeWordPressFiles(i),e.wordPressZip&&await F(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 R(i,await e.sqliteIntegrationPluginZip),await c(i)||await P(i),!await c(i))throw new Error("WordPress installation has failed.");return t}async function c(e){return(await e.run({code:`<?php
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
$wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php';

@@ -9,6 +9,6 @@ if (!file_exists($wp_load)) {

echo is_blog_installed() ? '1' : '0';
`,env:{DOCUMENT_ROOT:e.documentRoot}})).text==="1"}async function P(e){await g(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 b(e){return{type:"internal-redirect",uri:"/index.php"}}async function q(e){const i=(await(await e.getPrimaryPhp()).run({code:`<?php
`,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
require '${e.documentRoot}/wp-includes/version.php';
echo $wp_version;
`})).text;if(!i)throw new Error("Unable to read loaded WordPress version.");return y(i)}function y(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
`})).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

@@ -40,3 +40,78 @@ // Allow adding filters/actions prior to loading WordPress.

}
`),await e.writeFile("/internal/shared/mu-plugins/0-playground.php",`<?php
`),await e.writeFile("/internal/shared/mu-plugins/1-auto-login.php",`<?php
/**
* Returns the username to auto-login as, if any.
* @return string|false
*/
function playground_get_username_for_auto_login() {
/**
* Allow users to auto-login as a specific user on their first visit.
*
* Prevent the auto-login if it already happened by checking for the
* playground_auto_login_already_happened cookie.
* This is used to allow the user to logout.
*/
if ( defined('PLAYGROUND_AUTO_LOGIN_AS_USER') && !isset($_COOKIE['playground_auto_login_already_happened']) ) {
return PLAYGROUND_AUTO_LOGIN_AS_USER;
}
/**
* Allow users to auto-login as a specific user by passing the
* playground_force_auto_login_as_user GET parameter.
*/
if ( defined('PLAYGROUND_FORCE_AUTO_LOGIN_ENABLED') && isset($_GET['playground_force_auto_login_as_user']) ) {
return esc_attr($_GET['playground_force_auto_login_as_user']);
}
return false;
}
/**
* Logs the user in on their first visit if the Playground runtime told us to.
*/
function playground_auto_login() {
$user_name = playground_get_username_for_auto_login();
if ( false === $user_name ) {
return;
}
if (wp_doing_ajax() || defined('REST_REQUEST')) {
return;
}
if ( is_user_logged_in() ) {
return;
}
$user = get_user_by('login', $user_name);
if (!$user) {
return;
}
wp_set_current_user( $user->ID, $user->user_login );
wp_set_auth_cookie( $user->ID );
do_action( 'wp_login', $user->user_login, $user );
setcookie('playground_auto_login_already_happened', '1');
}
/**
* Autologin users from the wp-login.php page.
*
* The wp hook isn't triggered on
**/
add_action('init', function() {
playground_auto_login();
/**
* Check if the request is for the login page.
*/
if (is_login() && is_user_logged_in() && isset($_GET['redirect_to'])) {
wp_redirect(esc_url($_GET['redirect_to']));
exit;
}
}, 1);
/**
* Disable the Site Admin Email Verification Screen for any session started
* via autologin.
*/
add_filter('admin_email_check_interval', function($interval) {
if(false === playground_get_username_for_auto_login()) {
return 0;
}
return $interval;
});
`),await e.writeFile("/internal/shared/mu-plugins/0-playground.php",`<?php
// Needed because gethostbyname( 'wordpress.org' ) returns

@@ -72,13 +147,2 @@ // a private network IP address for some reason.

/**
* We're forced to use this deprecated hook to ensure SSL operations work without
* the kitchen-sink bundled. See https://github.com/WordPress/wordpress-playground/pull/1504
* for more context.
*/
if (
strpos($message, "Hook http_api_transports is deprecated") !== false ||
strpos($message, "Hook http_api_transports is <strong>deprecated</strong>") !== false
) {
return;
}
/**
* This is a temporary workaround to hide the 32bit integer warnings that

@@ -122,14 +186,14 @@ * appear when using various time related function, such as strtotime and mktime.

});
})();`)}async function S(e,r="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
})();`)}async function R(e,a="/phpinfo.php"){await e.writeFile("/internal/shared/preload/phpinfo.php",`<?php
// Render PHPInfo if the requested page is /phpinfo.php
if ( ${d(r)} === $_SERVER['REQUEST_URI'] ) {
if ( ${d(a)} === $_SERVER['REQUEST_URI'] ) {
phpinfo();
exit;
}
`)}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 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 o=(await e.readFileAsText(a(t,"db.copy"))).replace("'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'",d(t)).replace("'{SQLITE_PLUGIN}'",d(a(t,"load.php"))),s=a(await e.documentRoot,"wp-content/db.php"),p=`<?php
`)}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
// Do not preload this if WordPress comes with a custom db.php file.
if(file_exists(${d(s)})) {
if(file_exists(${d(o)})) {
return;
}
?>`,u="/internal/shared/mu-plugins/sqlite-database-integration.php";await e.writeFile(u,p+o),await e.writeFile("/internal/shared/preload/0-sqlite.php",p+`<?php
?>`,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

@@ -184,3 +248,3 @@ /**

protected function load_sqlite_integration() {
require_once ${d(u)};
require_once ${d(p)};
}

@@ -207,2 +271,2 @@ }

}
`)}async function F(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),o=a(e.documentRoot,i);e.mv(n,o)}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{k as bootWordPress,b as getFileNotFoundActionForWordPress,q as getLoadedWordPressVersion,S as preloadPhpInfoRoute,R as preloadSqliteIntegration,L as setupPlatformLevelMuPlugins,F as unzipWordPress,y as versionStringToLoadedWordPressVersion,E as wordPressRewriteRules};
`)}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};
{
"name": "@wp-playground/wordpress",
"version": "0.9.46",
"version": "1.0.0",
"description": "WordPress-related plumbing for WordPress Playground",

@@ -31,3 +31,3 @@ "repository": {

},
"gitHead": "fa393bcf69536e421246aa8e321e3e9af4b61c7b",
"gitHead": "9461d056ede8310ecfe01b72b5b095998a742ea3",
"dependencies": {

@@ -37,9 +37,10 @@ "comlink": "^4.4.1",

"ini": "4.1.2",
"wasm-feature-detect": "1.8.0",
"ws": "8.18.0",
"yargs": "17.7.2",
"@php-wasm/universal": "0.9.46",
"@php-wasm/util": "0.9.46",
"@wp-playground/common": "0.9.46",
"@php-wasm/node": "0.9.46"
"@php-wasm/universal": "1.0.0",
"@php-wasm/util": "1.0.0",
"@wp-playground/common": "1.0.0",
"@php-wasm/node": "1.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc