From e4e247c2898904e60a474c8fa8bea7ebb9f0c8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 20 Dec 2023 10:07:05 +0100 Subject: [PATCH] Noodling on multisites --- .../php-wasm/universal/src/lib/base-php.ts | 2 +- .../php-wasm/web/src/lib/web-php-endpoint.ts | 2 +- packages/playground/client/src/index.ts | 38 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/php-wasm/universal/src/lib/base-php.ts b/packages/php-wasm/universal/src/lib/base-php.ts index 78d6b736fc..d60f9e04c9 100644 --- a/packages/php-wasm/universal/src/lib/base-php.ts +++ b/packages/php-wasm/universal/src/lib/base-php.ts @@ -446,7 +446,7 @@ export abstract class BasePHP implements IsomorphicLocalPHP { } } - defineConstant(key: string, value: string | number | null) { + defineConstant(key: string, value: string | boolean | number | null) { let consts = {}; try { consts = JSON.parse( diff --git a/packages/php-wasm/web/src/lib/web-php-endpoint.ts b/packages/php-wasm/web/src/lib/web-php-endpoint.ts index cd38f43325..e08514b9f4 100644 --- a/packages/php-wasm/web/src/lib/web-php-endpoint.ts +++ b/packages/php-wasm/web/src/lib/web-php-endpoint.ts @@ -175,7 +175,7 @@ export class WebPHPEndpoint implements IsomorphicLocalPHP { } /** @inheritDoc @php-wasm/web!WebPHP.defineConstant */ - defineConstant(key: string, value: string | number | null): void { + defineConstant(key: string, value: string | boolean | number | null): void { _private.get(this)!.php.defineConstant(key, value); } diff --git a/packages/playground/client/src/index.ts b/packages/playground/client/src/index.ts index 885ad5461a..fc48b09762 100644 --- a/packages/playground/client/src/index.ts +++ b/packages/playground/client/src/index.ts @@ -90,6 +90,44 @@ export async function startPlaygroundWeb({ await runBlueprintSteps(compiled, playground); progressTracker.finish(); + await playground.defineConstant('WP_ALLOW_MULTISITE', true); + await playground.defineConstant('DOMAIN_CURRENT_SITE', 'localhost:5400'); + await playground.defineConstant( + 'PATH_CURRENT_SITE', + new URL(await playground.absoluteUrl).pathname + ); + + const response = await playground.run({ + code: `tables( 'ms_global' ) as $table => $prefixed_table ) { + $wpdb->$table = $prefixed_table; + } + require_once '/wordpress/wp-admin/includes/upgrade.php'; + + $result = install_network(); + var_dump($result); + require_once '/wordpress/wp-admin/includes/upgrade.php'; + $base = "${new URL(await playground.absoluteUrl).pathname}"; + $result = populate_network( 1, "localhost:5400", sanitize_email( "adam@adamziel.com" ), wp_unslash( "My network!" ), $base, $subdomain_install = false ); + var_dump($result); + `, + }); + console.log(response.text); + + await playground.defineConstant('MULTISITE', true); + await playground.defineConstant('SUBDOMAIN_INSTALL', false); + await playground.defineConstant('SITE_ID_CURRENT_SITE', 1); + await playground.defineConstant('BLOG_ID_CURRENT_SITE', 1); + console.log('defined'); + return playground; }