Support wp_mail()
mikachan opened this issue ยท 11 comments
This issue is very specific to using the Create Block Theme plugin on a WordPress Playground instance, so it could be that there needs to be a fix in that plugin instead/as well!
Create Block Theme allows you to add font files to your WordPress install. When I add a Google font in a Playground instance, I'm seeing the following error: wasm_popen: mode 'w' not supported (cmd: /usr/sbin/sendmail -t -i)!
I think this is because the 'w' mode is not supported by Playground WebAssembly implementation, or perhaps it's a permissions issue. I wondered if there was a possible fix for this or a way around this from the Create Block Theme side.
To reproduce:
- Install Create Block Theme on a WordPress Playground instance (example)
- Go to Appearance -> Manage Theme Fonts -> Add Google font button
- Select a Google font from the dropdown menu
- Select a font variant from the list of fonts
- Click the 'Add Google fonts to your theme' button
- You should see the above error
How weird is that rename() somehow leads to a sendmail issue?!
What I think is happening is this:
- class-manage-fonts.php calls rename() and fails because
$temp_filenameis not a string (as seen at the top of the Fatal Error message) - Some error handler in WordPress notices that and tries to send an email to notify the admin
- Sending the email fails because of the
popen()thing
Let's keep this issue open to track the w mode, but it won't fix the problem you're having. For that, you'll need to figure out why $temp_file is not a string here:
My guess: Installing Google fonts involves network calls. Playground in the browser doesn't support that at the moment because of CORS and SSL problems โ see the related issue. Can the Google fonts feature be disabled for now?
That makes sense, thanks for explaining! Yes, we could disable adding Google fonts, as there is also the ability to add local fonts which works well with Playground. Maybe we could disable Google fonts if the plugin is on a Playground instance for now.
Thanks for your help. Happy for this to be closed as a duplicate of #85.
Oh I've just seen your first comment! I'm sure that wasn't there before, I'm going to blame GitHub ๐
Let's keep this issue open to track the w mode, but it won't fix the problem you're having. For that, you'll need to figure out why $temp_file is not a string here:
Ok! We'll take a look at the $temp_file string issue. I've opened an issue here: WordPress/create-block-theme#360
Thinking about Playground - it would be good to turn that fatal error into a warning somewhere here:
I mentioned this issue to Adam during WCEU - and came here to open a new issue; good to know it is documented and is being discussed.
cc @dmsnell โ you might be interested this issue as it touches the major PHP/JavaScript integration points
we may not be able to support sending email in the browser without a socket layer that can be used for TCP. this probably mirrors the mysql issues.
maybe a good start, in addition to any error reporting, is to disable sending emails from WordPress by default. there are some plugins out there to do that, but I don't see a simple way in WordPress to toggle them off. maybe if we included a plugin to do this we could prevent a number of email-related bugs.
I saw this repo recently, which could be useful in figuring out how to disable all emails.
WordPress Email Documentation - https://github.com/johnbillion/wp_mail
This document lists all the situations where WordPress core sends an email, how and when they happen, and how to filter or disable each one.
This list was last updated for WordPress 6.2.
..All emails sent by WordPress go through the pluggable wp_mail() function.
Calling wp_mail() no longer trigges a fatal error. popen("mail", "w") is supported since #596. The following code snippet now prints "done" instead of a fatal error:
<?php
require "/wordpress/wp-load.php";
wp_mail("wp@playground.wordpress.net", "Subject", "Message");
echo 'done';Under the hood, wp_mail attempts to run /bin/sendmail which won't work in the browser. This is fine. The function call will simply return false. If the developer wishes to actually support sending emails, they'll need to specify a custom process spawn handler as follows:
playground.setSpawnHandler(
((command: string, processApi: any) => {
if (command.startsWith('/usr/bin/env stty size ')) {
processApi.stdout(`18 140`);
processApi.exit(0);
} else if (command.startsWith('less')) {
processApi.on('stdin', (data: Uint8Array) => {
processApi.stdout(data);
});
processApi.flushStdin();
processApi.exit(0);
}
}).toString()
);The original problem related to the Create Block Theme is also fixed. Google fonts may be used whenever the networking support is enabled.