WordPress.org

Make WordPress Core

Opened 15 months ago

Last modified 10 months ago

#26317 new enhancement

Added Filter to be possible to disable/change the 'New Site Created' email sent to Administration email address

Reported by: vaurdan Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Mail Keywords: has-patch
Focuses: multisite Cc:

Description

While doing my WordPress work, I found the need of disable all the WordPress Multisite notification emails that are sent to the administrator. But one mail keep being sent: "[Sitename] New Site Created".

I decided to analyse the core's code, and found that the email was being sent on line 91, of wp-admin/network/site-new.php, and there was no filter to disable it (it was just a wp_mail call).

$content_mail = sprintf( __( 'New site created by %1$s

Address: %2$s
Name: %3$s' ), $current_user->user_login , get_site_url( $id ), wp_unslash( $title ) );
                wp_mail( get_site_option('admin_email'), sprintf( __( '[%s] New Site Created' ), $current_site->site_name ), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' );

Since I guess that this should be filtered, I decided to create a new filter, by replacing that lines with a single function call:

$user_name = $current_user->user_login;
$address = get_site_url( $id );

wpmu_admin_new_site_notification( $user_name, $address, $title );

The new wpmu_admin_new_site_notification that I created, is declared on wp-includes/ms-functions.php and it as simple as a function that send an email to the administrator, and that have three filters: wpmu_admin_new_site_notification that can be used to bypass the email; update_new_site_notification_email that can change the content of the emaiil; and update_new_site_notification_subject that can be used to change the subject of the email.

You can see more details of this on the .patch file I submitted, with commented code.

Attachments (2)

WordPress-patch.patch (3.1 KB) - added by vaurdan 15 months ago.
Patch to implement this enhancement
wordpress.patch (3.1 KB) - added by vaurdan 12 months ago.
The new patch, with new fixes and related to the SVN revision 27489

Download all attachments as: .zip

Change History (12)

@vaurdan15 months ago

Patch to implement this enhancement

comment:1 @johnbillion15 months ago

  • Cc johnbillion added

comment:2 follow-up: @jeremyfelt15 months ago

  • Milestone changed from Awaiting Review to 3.9
  • Version changed from 3.8 to 3.0

Thanks for the ticket and the patch, vaurdan. It is interesting that we only fire the quick email with wp_mail() to the admin right before an abstracted event for wpmu_welcome_notification().

If we pull this out into a new function, we should identify where else it could be used to notify an admin that a new site has been created. It should also likely not have the wpmu_ prefix, as that was ported over in the WPMU transition. We'd be ok to do something more like wp_new_site_admin_notification() I think.

We can probably move the get_site_url() check into the new function and pass the $id along as we do in wpmu_welcome_notification().

I think it makes sense to see how we can improve this going forward. The new site notification emails are pretty light at the moment. It looks like it has been this way since MU was ported over via [12603].

comment:3 in reply to: ↑ 2 @vaurdan15 months ago

Replying to jeremyfelt:

Thanks for the ticket and the patch, vaurdan. It is interesting that we only fire the quick email with wp_mail() to the admin right before an abstracted event for wpmu_welcome_notification().

Yup, that doesn't make much sense, this was probabily old and forgotten code.

If we pull this out into a new function, we should identify where else it could be used to notify an admin that a new site has been created. It should also likely not have the wpmu_ prefix, as that was ported over in the WPMU transition. We'd be ok to do something more like wp_new_site_admin_notification() I think.

We can probably move the get_site_url() check into the new function and pass the $id along as we do in wpmu_welcome_notification().

I think it makes sense to see how we can improve this going forward. The new site notification emails are pretty light at the moment. It looks like it has been this way since MU was ported over via [12603].

Yes, you're right. I used the prefix wpmu_, just because all the functions there had wpmu_ as well, but makes much more sense using ´wp_´, since there is no wpmu anymore...

comment:4 @3flex14 months ago

  • Cc 3flex added

comment:5 @jeremyfelt14 months ago

  • Component changed from Multisite to Mail
  • Focuses multisite added

comment:6 @spmlucas13 months ago

  • Keywords has-patch added

comment:7 @jeremyfelt12 months ago

  • Keywords needs-patch added; has-patch removed

This patch should be updated / clarified a bit before going in.

From earlier:

  • If we pull this out into a new function, we should identify where else it could be used to notify an admin that a new site has been created. (Otherwise the abstraction may not be necessary)
  • It should also likely not have the wpmu_ prefix, as that was ported over in the WPMU transition. We'd be ok to do something more like wp_new_site_admin_notification() I think.

comment:8 @jeremyfelt12 months ago

  • Milestone changed from 3.9 to Future Release

Going to push this to a future release. We should review what else can be done around this.

comment:9 @vaurdan12 months ago

  • Keywords has-patch added; needs-patch removed

I've fixed the patch with all the suggestions that have been made.
Besides, I did a little research on the code, trying to find where wp_admin_new_site_notification function could be used, but I didn't found any place.
I still think that make a new function is the best decision, mainly because can it be easily hooked and filtered...

So, here is the new .patch, using the latest svn revision (27489).

@vaurdan12 months ago

The new patch, with new fixes and related to the SVN revision 27489

comment:10 @vaurdan10 months ago

Any news on this?

Note: See TracTickets for help on using tickets.