From 42d2d22c7244c0c2b55bb8e1b39c4594a5a3fd5a Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Fri, 23 Apr 2010 20:40:18 +0000
Subject: [PATCH] Send an email to a user when they create a new blog.

---
 unl.php | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/unl.php b/unl.php
index 2b716bd..e40b5e1 100644
--- a/unl.php
+++ b/unl.php
@@ -119,9 +119,49 @@ function unl_new_blog($blogId)
 {
 	switch_to_blog($blogId);
 	switch_theme('unl_modern', 'unl_modern');
+	unl_new_blog_notification($blogId);
 	restore_current_blog();
 }
 
+
+function unl_new_blog_notification($blogId)
+{
+    $welcomeEmail =
+'Your new SITE_NAME blog has been successfully set up at:
+BLOG_URL
+
+You can log in to the administrator account with your My.UNL account
+Login Here: BLOG_URLwp-admin/
+
+We hope you enjoy your new weblog.
+Thanks!
+
+--The WordPress Team
+SITE_NAME';
+
+    $url = get_blogaddress_by_id($blogId);
+    $user = wp_get_current_user();
+    $title = get_bloginfo('title');
+    
+    $currentSite = $GLOBALS['current_site'];
+
+    $welcomeEmail = str_replace( "SITE_NAME", $currentSite->site_name, $welcomeEmail );
+    $welcomeEmail = str_replace( "BLOG_TITLE", $title, $welcomeEmail );
+    $welcomeEmail = str_replace( "BLOG_URL", $url, $welcomeEmail );
+
+    $admin_email = get_site_option( "admin_email" );
+    if( $admin_email == '' )
+        $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
+    $from_name = get_site_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
+    $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
+    $message = $welcomeEmail;
+    if( empty( $current_site->site_name ) )
+        $currentSite->site_name = "WordPress MU";
+    $subject = apply_filters( 'update_welcome_subject', sprintf(__('New %1$s Blog: %2$s'), $currentSite->site_name, stripslashes( $title ) ) );
+    wp_mail($user->user_email, $subject, $message, $message_headers);
+    return true;
+}
+
 add_action('set_current_user', 'unl_set_current_user', 0);
 add_action('plugins_loaded', 'unl_init');
 add_action('auth_redirect', 'unl_auth_redirect');
-- 
GitLab