Make WordPress Core

Opened 7 years ago

Last modified 2 months ago

#49564 new feature request

Allow developers to set mail headers in wpmu_welcome_user_notification function

Reported by: ionvv Owned by:
Priority: normal Milestone: Awaiting Review
Component: Networks and Sites Version:
Severity: minor Keywords: has-patch has-unit-tests
Cc: Focuses: multisite

Description

Hi,

with multisite, when using update_welcome_user_email hook to change the email content it's not possible to send the email in HTML format because the header is hardcoded, see line 1700 in ms-functions.php https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/ms-functions.php#L1700

Maybe we can change the following:

 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";

to

$message_headers[] = "From: \"{$from_name}\" <{$admin_email}>\n";
$message_headers[] = 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
$message_headers = apply_filters( 'update_welcome_user_headers', $message_headers );

which will allow developers to filter headers with update_welcome_user_headers

Let me know what you think about it.

Warm regards,
Ion

Attachments (1)

49564.diff​ (2.0 KB ) - added by donmhico 7 years ago.

Download all attachments as: .zip

Change History (5)

#1 @ionvv
7 years ago

  • Summary Allow users to set mail headers in wpmu_welcome_user_notification function → Allow developers to set mail headers in wpmu_welcome_user_notification function

@donmhico
7 years ago

#2 @donmhico
7 years ago

Hello @ionvv,

Thanks for the ticket and for including a solution. I made a patch 49564.diff from your proposed solution and added docs

#3 @realloc
2 months ago

  • Keywords needs-refresh added

The patch no longer applies cleanly. The lines above $message_headers have changed since it was uploaded: the $admin_email fallback now uses wp_parse_url( network_home_url(), PHP_URL_HOST ) instead of $_SERVER['SERVER_NAME'], and the $from_name assignment was rewritten to use strict comparison. Both appear as context lines in the diff. Marking this as needs-refresh.

Last edited 2 months ago by realloc (previous) (diff)

This ticket was mentioned in ​PR #12849 on ​WordPress/wordpress-develop by ​@irozum.


2 months ago
#4

  • Keywords has-unit-tests added; needs-refresh removed

Adds a new update_welcome_user_headers filter to wpmu_welcome_user_notification(), letting developers customize the headers of the Multisite "account activation successful" welcome email — for example to send it as HTML (Content-Type: text/html) or override the From address — the same way update_welcome_user_email already lets them customize the message body. Previously the headers were built as a single hardcoded string with no filter hook, so a plugin could change the email content but not its headers. The header construction now builds a $message_headers array (still fully compatible with wp_mail(), which accepts either a string or an array of header lines) and runs it through the new filter before sending, mirroring the existing new_site_email array-filter pattern already used by wpmu_new_site_admin_notification() elsewhere in this file.

## Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Implementation, tests, and PR description. Reviewed by Igor Rozum.

Note: See TracTickets for help on using tickets.