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

Custom WordPress build with plugins #23

Closed
eliot-akira opened this issue Sep 27, 2022 · 3 comments
Closed

Custom WordPress build with plugins #23

eliot-akira opened this issue Sep 27, 2022 · 3 comments

Comments

@eliot-akira
Copy link
Collaborator

eliot-akira commented Sep 27, 2022

I'd like to create a custom build of wp.data with pre-installed plugins. I got pretty close to achieving it, but for some reason the admin screen shows no plugins. Here's what I did:

  • Edit wasm-build/wordpress-data/prepare-wordpress.sh to download, unzip, and move a plugin folder into ./wordpress/wp-content/plugins/
  • Run npm run build:wp && npm run publish:wp:web

I confirmed that the plugin's static assets were copied to dist-web/wp-content/plugins. I looked in the built file dist-web/wp.js, and the plugin's file paths are included from /preload/wordpress/wp-content/plugins - so I assume the files were successfullly included in wp.data. But somehow the WordPress instance in the browser is not recognizing it.

Any idea or hint would be greatly appreciated.

@eliot-akira
Copy link
Collaborator Author

eliot-akira commented Sep 27, 2022

Using the postMessage function created in app.mjs, I was able to run PHP code via the web worker for debugging.

window.wpWorker = { postMessage }

From the browser console, I could see the contents of the virtual file system.

const { stdout } = await wpWorker.postMessage({
  type: 'run_php',
  code: `<?php
    echo json_encode(
      scandir(__DIR__.'/wp-content/plugins/'),
      JSON_PRETTY_PRINT
    );
  `
})
console.log(stdout)

And the pre-installed plugin does exist there.

(As a tangent, it's probably better to copy it into mu-plugins to be activated by default.)

So, that confirms the build script is successfully including the plugin files in wp.data. That narrows down the cause of the issue somewhat - but still mysterious why the WordPress instance isn't seeing the plugin.

@eliot-akira
Copy link
Collaborator Author

Solved. I added the following line in prepare-wordpress.sh to create a file at mu-plugins/index.php which loads specific plugins.

echo "<?php
require_once ABSPATH.'wp-content/mu-plugins/plugin-name/plugin-name.php';
" > wordpress/wp-content/mu-plugins/index.php

@adamziel
Copy link
Collaborator

Let's add that to first iteration of technical docs, cross-linking with #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants