Email a Custom Address When a Site Is Created
Sends a short notice with the new site's name, address and creator to an address you choose, in addition to WordPress's own network admin email.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_notify_to = '[email protected]'; // Recipient(s).
add_action( 'wp_initialize_site', function ( $site, $args ) use ( $wpide_notify_to ) {
$user = ! empty( $args['user_id'] ) ? get_userdata( $args['user_id'] ) : wp_get_current_user();
$title = ! empty( $args['title'] ) ? $args['title'] : $site->domain . $site->path;
$url = set_url_scheme( 'http://' . $site->domain . $site->path );
$body = sprintf(
"A new site was created on %1\$s.\n\nName: %2\$s\nAddress: %3\$s\nCreated by: %4\$s\nManage: %5\$s\n",
get_network()->site_name,
$title,
$url,
$user && $user->exists() ? $user->user_login . ' <' . $user->user_email . '>' : 'unknown',
network_admin_url( 'site-info.php?id=' . (int) $site->blog_id )
);
wp_mail( $wpide_notify_to, sprintf( '[%s] New site: %s', get_network()->site_name, $title ), $body );
}, 300, 2 );
Notes
Set $wpide_notify_to; separate several addresses with commas.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.