Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueprints: Add enableMultisite step #888

Merged
merged 44 commits into from
Jan 29, 2024
Merged

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Dec 20, 2023

Description

Adds a enableMultisite step that turns Playground into a Multisite WordPress installation. The step does not create any sites, but it does create all the necessary tables in the database. In particular, it:

  1. Deactivates all the plugins – as required by WordPress
  2. Submits the Multisite activation form in wp-admin. This will break if the admin username/password isn't admin/password. Ideally it would just run a script, but I didn't find a working way to do it.
  3. Creates a sunrise.php file to tell WordPress which site is the default one by populating the $_SERVER array.
  4. Re-activates all the deactivated plugins

Example Blueprint:

{
    "landingPage":"/wp-admin/network/sites.php",
    "steps": [
        { "step": "enableMultisite" }
    ]
}

CleanShot 2024-01-23 at 14 21 32@2x

Other changes

URL rewriting

This PR also ships a URL rewriting logic in the service worker. This
is to ensure that requests to URLs like /mysite/wp-admin/ are still
resolved to the /wp-admin/index.php file.

Internally, this is done by adding a x-rewrite-url header to the
request whenever the URL matches a rewrite rule after an initial 404.

Move the sqlite-database-integration plugin to mu-plugins

Activating a multisite requires disabling all the plugins. However, we cannot disable the SQLite integration plugin as the database connection relies on it. Therefore, this PR makes the SQLite integration an mu-plugin instead to ensure it is always on and unaffected by the multisite activation.

E2E tests in CI now run with sudo

Multisites don't work with custom port numbers like the http://localhost:5400 used by Playground's CI. Therefore, this PR rewires the CI E2E setup to use just http://localhost and starts the tests with sudo to enable binding to port 80.

Testing instructions

Multisites don't work with non-standard ports, like localhost:5400 used by Playground dev server. To test this PR, you'll need a local test domain running via HTTPS.

One way to get it set up is with Laravel Valet. Once your Valet is installed, run:

valet proxy playground.test http://localhost:5400 --secure

Your dev server is now available via https://playground.test.

Follow-up work

  • Activate the multisite by calling PHP functions, not submitting the form in /wp-admin. This will allow this step to work even when the admin username and password are customized.

This step enables multisite support in the WordPress installation. It
does not create any sites, but it does create the necessary tables in
the database.

Example Blueprint:

```json
{
    "landingPage":"/wp-admin/network.php",
    "steps": [
        { "step": "enableMultisite" }
    ]
}
```

 ## URL rewriting

This PR also ships a URL rewriting logic in the service worker. This
is to ensure that requests to URLs like `/mysite/wp-admin/` are still
resolved to the `/wp-admin/index.php` file.

Internally, this is done by adding a `x-rewrite-url` header to the
request whenever the URL matches a rewrite rule after an initial 404.

CC @dmsnell
@adamziel adamziel changed the title Noodling on multisites @adamziel Blueprints: Add enableMultisite step Jan 23, 2024
@adamziel adamziel marked this pull request as ready for review January 23, 2024 13:31
@adamziel adamziel mentioned this pull request Jan 23, 2024
@adamziel
Copy link
Collaborator Author

adamziel commented Jan 24, 2024

Something is off in the site editor – many ajax requests fail with 401:

CleanShot 2024-01-24 at 09 49 34@2x

@adamziel
Copy link
Collaborator Author

This could be related to URL rewriting – multisites send these requests to /wp-json/wp/v2/templates?context=edit&_locale=user whereas single sites send them to /index.php?rest_route=%2Fwp%2Fv2%2Fblock-patterns%2Fpatterns&_locale=user

@adamziel adamziel changed the title @adamziel Blueprints: Add enableMultisite step Blueprints: Add enableMultisite step Jan 26, 2024
@adamziel adamziel merged commit db16cc6 into trunk Jan 29, 2024
5 checks passed
@adamziel adamziel deleted the experiment/multisite-support branch January 29, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant