-
Notifications
You must be signed in to change notification settings - Fork 268
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
PHP: Use auto_prepend_file to preload mu-plugins (instead of creating them in wp-content/mu-plugins) #1366
Conversation
… them in wp-content/mu-plugins) Closes #1318 More description TBD Let's see which tests fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the use of auto_prepend_file
here, it seems like a better solution from mu-plugins.
One thing that came to my mind is that some plugins might want to use auto_prepend_file
, for example Wordfence.
This is an edge case and they could add their PHP file to /internal/preload
.
@@ -1,3 +1,107 @@ | |||
export * from './rewrite-rules'; | |||
|
|||
export const RecommendedPHPVersion = '8.0'; | |||
|
|||
export const envPHP_to_loadMuPlugins = `<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why store this PHP code in JS? Would it be possible to load it from PHP files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out a way to do it that would work with all the build systems (Bun, ESBuild, Rollup). Bun has a .toml
config file where we can define a custom loader, but it is only used with a few specific commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes, it's nice to be able to read see everything inline anyway.
Problem addressed by this PR
This PR moves the Playground mu-plugins from
/wordpress/wp-content/mu-plugins
, where they may interfere with the user-provided files and pollute the git repository, to/internal/mu-plugins
, where they're invisible to the Playground consumer and don't show up in exports or OPFS mounts.Closes #1318
Changes made
Technically, this PR uses the
auto_prepend_file
PHP options to pre-load the following script:From here, preloading files is as simple as creating them in
/internal/preload
. This PR ships a few such preloaded files:consts.php
, that enables predefining PHP constants without affectingwp-config.php
.env.php
, that preloads mu-plugins from/internal/mu-plugins
using the method described by @brandonpayton.phpinfo.php
, that just callsphpinfo();
when the request URL is/phpinfo.php
– this prevents creating an actualphpinfo.php
file in the document root. This involves a slight change in the path resolution logic which will have to change even more soon to solve Static files run as PHP when path includes directory like<some-dir>.php/
#1365.From there, the SQLite integration plugin and the Playground mu-plugins are placed in
/internal/mu-plugins
and do not affect the WordPress file structure.This PR also reduces code duplication by moving some parts of the WordPress setup to the
@wp-playground/wordpress
package where they can be imported by both the web and the CLI versions of Playground. We'll only see more of these moving forward.Follow-up work
@wp-playground/cli
to build and setup WordPress inpackages/playground/wordpress-builds/build/Dockerfile
wp-content
directory. Source it from the/internal/mu-plugins
directory same way as in the CLI build.wp-content/db.php
wp-content/plugins
wp-config.php
– defining PHP constants may require rewriting it and it might be desirable to keep those changes on exportTesting instructions