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

Support wp_mail() #276

Closed
mikachan opened this issue May 10, 2023 · 11 comments
Closed

Support wp_mail() #276

mikachan opened this issue May 10, 2023 · 11 comments
Labels

Comments

@mikachan
Copy link
Member

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)!

image

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:

  1. Install Create Block Theme on a WordPress Playground instance (example)
  2. Go to Appearance -> Manage Theme Fonts -> Add Google font button
  3. Select a Google font from the dropdown menu
  4. Select a font variant from the list of fonts
  5. Click the 'Add Google fonts to your theme' button
  6. You should see the above error
@adamziel
Copy link
Collaborator

How weird is that rename() somehow leads to a sendmail issue?!

What I think is happening is this:

  1. class-manage-fonts.php calls rename() and fails because $temp_filename is not a string (as seen at the top of the Fatal Error message)
  2. Some error handler in WordPress notices that and tries to send an email to notify the admin
  3. 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:

https://github.com/WordPress/create-block-theme/blob/0e9b25247975eb2d5e47b65ebfcea077ccf5210f/admin/class-manage-fonts.php#L221-L227

@adamziel
Copy link
Collaborator

adamziel commented May 10, 2023

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?

@mikachan
Copy link
Member Author

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.

@mikachan
Copy link
Member Author

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

@adamziel
Copy link
Collaborator

adamziel commented Jun 2, 2023

Thinking about Playground - it would be good to turn that fatal error into a warning somewhere here:

@carolinan
Copy link

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.

@adamziel
Copy link
Collaborator

cc @dmsnell – you might be interested this issue as it touches the major PHP/JavaScript integration points

@dmsnell
Copy link
Member

dmsnell commented Jun 20, 2023

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.

@eliot-akira
Copy link
Collaborator

eliot-akira commented Jun 20, 2023

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.

@adamziel adamziel changed the title Issue with Create Block Theme plugin fonts: wasm_popen: mode 'w' not supported Support wp_mail() Oct 4, 2023
@adamziel adamziel mentioned this issue Oct 4, 2023
10 tasks
@adamziel
Copy link
Collaborator

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("[email protected]", "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()
);

@adamziel
Copy link
Collaborator

The original problem related to the Create Block Theme is also fixed. Google fonts may be used whenever the networking support is enabled.

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

No branches or pull requests

5 participants