Make WordPress Core

Opened 11 years ago

Last modified 4 years ago

#26317 new enhancement

Ad filter for changing the 'New Site Created' email sent to site's admin email

Reported by: vaurdan's profile vaurdan Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Mail Keywords: has-patch needs-refresh
Focuses: administration, 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 11 years ago.
Patch to implement this enhancement
wordpress.patch (3.1 KB) - added by vaurdan 10 years ago.
The new patch, with new fixes and related to the SVN revision 27489

Download all attachments as: .zip

Change History (14)

@vaurdan
11 years ago

Patch to implement this enhancement

#1 @johnbillion
11 years ago

  • Cc johnbillion added

#2 follow-up: @jeremyfelt
11 years 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].

#3 in reply to: ↑ 2 @vaurdan
11 years 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...

#4 @3flex
11 years ago

  • Cc 3flex added

#5 @jeremyfelt
11 years ago

  • Component changed from Multisite to Mail
  • Focuses multisite added

#6 @spmlucas
10 years ago

  • Keywords has-patch added

#7 @jeremyfelt
10 years 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.

#8 @jeremyfelt
10 years 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.

#9 @vaurdan
10 years 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).

@vaurdan
10 years ago

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

#10 @vaurdan
10 years ago

Any news on this?

#11 @chriscct7
9 years ago

  • Keywords needs-refresh added

#12 @desrosj
4 years ago

  • Focuses administration added
  • Milestone set to Future Release
  • Summary changed from Added Filter to be possible to disable/change the 'New Site Created' email sent to Administration email address to Ad filter for changing the 'New Site Created' email sent to site's admin email

The most recent patch needs to another refresh.

Note: See TracTickets for help on using tickets.