Skip to content

Conversation

@t-hamano
Copy link
Contributor

@t-hamano t-hamano commented Nov 28, 2025

What?

This PR will add email notifications for notes to the Gutenberg plugin, which was implemented in core.

Why?

Backward compatibility.

How?

This PR is broadly divided into the following three hooks:

  • gutenberg_register_wp_notes_notify_setting: Registers a note notification setting to the Discussion screen.
  • gutenberg_new_comment_via_rest_notify_postauthor: Send an email when a comment is inserted via the REST API
  • gutenberg_filter_note_notification_text, gutenberg_filter_note_notification_subject: Filter an email subject and content

Testing Instructions

Note: The email notification feature has been implemented in the latest WordPress core, so don't forget to downgrade the WordPress version to 6.8 and test it.

To test this PR, you'll need to set up an SMTP server in your wp-env environment. One way to do this is to temporarily set up Gmail's SMTP server:

// Setup Gmail SMTP.
add_action( 'phpmailer_init',function( $phpmailer ) {
	$phpmailer->isSMTP();
	$phpmailer->Host       = 'smtp.gmail.com';
	$phpmailer->SMTPAuth   = true;
	$phpmailer->Port       = 587;
	$phpmailer->SMTPSecure = 'tls';
	$phpmailer->FromName   = get_bloginfo( 'name' );

	// Your Gmail address.
	$phpmailer->Username   = '[email protected]';
	// Your Gmail address.
	$phpmailer->From       = '[email protected]';
	// Your Gmail "App" password.
	// https://support.google.com/mail/answer/185833?hl=en
	$phpmailer->Password   = 'xxxx xxxx xxxx xxxx';

	// Send all emails to the fixed address.
	$phpmailer->clearAddresses();
	$phpmailer->clearCCs();
	$phpmailer->clearBCCs();
	$phpmailer->clearReplyTos();
	// Your Gmail address.
	$phpmailer->addAddress( '[email protected]' );
} );

// Set the from email address.
add_filter( 'wp_mail_from', function( $email ) {
	// Your Gmail address.
	return '[email protected]';
} );

// Log failed emails. If you encounter an error, please check the log.
add_action( 'wp_mail_failed', function ( $error ) {
	error_log( print_r( $error->get_error_message(), true ) );
} );
  1. Create a post.
  2. Log in with a different user account and add a note to that post.
  3. An email should be sent.

@t-hamano t-hamano self-assigned this Nov 28, 2025
@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting labels Nov 28, 2025
)
);

add_settings_field(
Copy link
Contributor Author

@t-hamano t-hamano Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the UI is different from the core, as it is not possible to inject new settings into existing sections.

Core

Image

Gutenberg

Image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need to register this setting for WP < 6.9. I think it's currently registered for all versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we could check if the settings were already registered via get_registered_settings, but apparently that's not the case. Fixed in 1a34a21.

@github-actions
Copy link

github-actions bot commented Nov 28, 2025

Flaky tests detected in 667c0c4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20050507215
📝 Reported issues:

@t-hamano t-hamano marked this pull request as ready for review November 28, 2025 12:16
@github-actions
Copy link

github-actions bot commented Nov 28, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: adamsilverstein <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! left some small nitpick feedback. Also, I only reviewed the code, it would be good to have some manual testing which I did not do.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested using WP Mail Debugger and this is working as expected.

@t-hamano
Copy link
Contributor Author

t-hamano commented Dec 9, 2025

Thanks both of you for the reviews!

@t-hamano t-hamano merged commit f8d8b2e into trunk Dec 9, 2025
35 checks passed
@t-hamano t-hamano deleted the notes-email-notification branch December 9, 2025 06:14
@github-actions github-actions bot added this to the Gutenberg 22.3 milestone Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants