Posted by Epic Alex on Wed 13 May 14:46
report abuse | View followups from epicalex | download | new post
- <?php
- /*
- Plugin Name: New User Email Setup
- Plugin URI: http://www.epicalex.com/new-user-email-set-up/
- Version: 0.3
- Author: Alex Cragg
- Author URI: http://epicalex.com/
- Description: A Plugin to setup the registration email sent to new users. THIS VERSION ONLY COMPATIBLE WITH WP 2.7
- */
- /*
- Copyright (C) 2007 Alex Cragg
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>
- */
- $nue_root = WP_PLUGIN_URL. "/newuseremail/";
- add_action('admin_menu', 'newuseremailoptions');
- add_action('admin_head', 'nue_add_css');
- add_action('admin_init', 'nue_admin_init' );
- function nue_admin_init(){
- register_setting('nue-options-group', 'newuseremailhtml');
- register_setting('nue-options-group', 'newuseremailfromaddress');
- register_setting('nue-options-group', 'newuseremailfrom');
- register_setting('nue-options-group', 'newuseremailsubject');
- register_setting('nue-options-group', 'newuseremailtext');
- register_setting('nue-options-group', 'newuseremailadminsubject');
- register_setting('nue-options-group', 'newuseremailadmintext');
- }
- function newuseremailactivate() {
- 'html' => 'text/HTML',
- 'fromaddress' => 'Enter your admin email here',
- 'from' => 'Enter the name you want your admin email sent from here. eg. Admin',
- 'subject' => 'Welcome to %blogname%',
- 'text' => 'Welcome %username% please find below your login details.<br /> I hope you enjoy our site.<br /> <strong>Username:</strong> %username%<br /> <strong>Password:</strong> %password%<br /> %loginurl%',
- 'adminsubject' => '%blogname% - New User Registration',
- 'admintext' => 'There is a new user registered on your blog:<br /> <strong>Username:</strong> %username%<br /> <strong>Email:</strong> %useremail%'
- );
- // if old options exist, update to new system
- foreach( $nue_options as $key => $value ) {
- if( $existing = get_option( 'newuseremail' . $key ) ) {
- $nue_options[$key] = $existing;
- delete_option( 'newuseremail' . $key );
- }
- }
- update_option('newuseremail_options', $nue_options);
- }
- function newuser_mail($to, $subject, $message, $headers = '') {
- $nue_option_array = get_option('newuseremail_options');
- global $phpmailer;
- require_once(ABSPATH . WPINC . '/class-phpmailer.php');
- require_once(ABSPATH . WPINC . '/class-smtp.php');
- $phpmailer = new PHPMailer();
- }
- $mail = apply_filters('wp_mail', $mail);
- if ( $headers == '' ) {
- $headers = "MIME-Version: 1.0\n" .
- "From: " . apply_filters('wp_mail_from', "wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']))) . "\n" .
- "Content-Type: text/HTML; charset=\"" . get_option('blog_charset') . "\"\n";
- }
- $phpmailer->ClearAddresses();
- $phpmailer->ClearCCs();
- $phpmailer->ClearBCCs();
- $phpmailer->ClearReplyTos();
- $phpmailer->ClearAllRecipients();
- $phpmailer->ClearCustomHeaders();
- $phpmailer->FromName = "WordPress";
- $phpmailer->AddAddress("$to", "");
- $phpmailer->Subject = $subject;
- $phpmailer->Body = $message;
- if ($nue_option_array['html'] == 'text/HTML' ) {
- $phpmailer->IsHTML( true );
- } else {
- $phpmailer->IsHTML( false );
- }
- $phpmailer->IsMail(); // set mailer to use php mail()
- foreach ( $mailheaders as $line ) {
- case "From":
- $phpmailer->FromName = str_replace( '"', '', substr( $header[1], 0, strpos( $header[1], '<' ) - 1 ) );
- } else {
- $phpmailer->FromName = $from;
- }
- break;
- default:
- if ( $line != '' && $header[0] != 'MIME-Version' && $header[0] != 'Content-Type' )
- $phpmailer->AddCustomHeader( $line );
- break;
- }
- }
- $result = @$phpmailer->Send();
- return $result;
- }
- endif;
- function wp_new_user_notification($user_id, $plaintext_pass = '') {
- $nue_option_array = get_option('newuseremail_options');
- $user = new WP_User($user_id);
- $find = array('/%username%/i', '/%password%/i', '/%blogname%/i', '/%siteurl%/i', '/%loginurl%/i', '/%useremail%/i');
- $replace = array($user_login, $plaintext_pass, get_option('blogname'), get_option('siteurl'), get_option('siteurl').'/wp-login.php', $user_email);
- $headers .= "MIME-Version: 1.0\n" .
- "From: ". $user_email . "\n" .
- "Content-Type: ". $nue_option_array['html'] ." charset=\"" . get_option('blog_charset') . "\"\n";
- @newuser_mail($nue_option_array['fromaddress'], $subject, $message, $headers);
- return;
- $headers .= "MIME-Version: 1.0\n" .
- "From: ". $nue_option_array['from'] ."<". $nue_option_array['fromaddress'] . ">\n" .
- "Content-Type: ". $nue_option_array['html'] ." charset=\"" . get_option('blog_charset') . "\"\n";
- newuser_mail($user_email, $subject, $message, $headers);
- }
- }
- function printnewuseremailAdminOptions() {
- if ($_REQUEST['submit']) {
- update_newuseremail();
- }
- ?>
- <div class="wrap">
- <div id="icon-newusermail" class="icon32">
- <br/>
- </div>
- <h2>New User Email</h2> <?php
- print_newuseremail();
- ?></div><?php
- }
- function update_newuseremail() {
- $nue_options['html'] = $_POST['newuseremailhtml'];
- }
- $nue_options['from'] = $_POST['newuseremailfrom'];
- }
- $nue_options['fromaddress'] = $_POST['newuseremailfromaddress'];
- }
- $nue_options['subject'] = $_POST['newuseremailsubject'];
- }
- $nue_options['text'] = $_POST['newuseremailtext'];
- }
- $nue_options['adminsubject'] = $_POST['newuseremailadminsubject'];
- }
- $nue_options['admintext'] = $_POST['newuseremailadmintext'];
- }
- update_option('newuseremail_options', $nue_options);
- ?>
- <div class="updated"><p><strong><?php _e("Settings Updated.", "NewUserEmail");?></strong></p></div>
- <?php
- }
- }
- function nue_add_css() {
- }
- function print_newuseremail() {
- ?>
- <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
- <?php
- wp_nonce_field('update-options');
- ?>
- <?php settings_fields('nue-options-group'); ?>
- <div id="poststuff" class="meta-box-sortables">
- <div class="postbox close-me nue-left">
- <h3 class="hndle"><span><?php _e('User Email Settings','NewUserEmail'); ?></span></h3>
- <div class="inside">
- <h4>Allow HTML in Email Content?</h4>
- <label for="newuseremailhtml_yes">
- <input id="newuseremailhtml_yes" type="radio" value="text/HTML" <?php if (get_option("newuseremailhtml") == "text/HTML") { _e('checked="checked"', "NewUserEmail"); }?> name="newuseremailhtml"/>
- Yes
- </label>
- <label for="newuseremailhtml_no">
- <input id="newuseremailhtml_no" type="radio" value="text/plain" <?php if (get_option("newuseremailhtml") == "text/plain") { _e('checked="checked"', "NewUserEmail"); }?> name="newuseremailhtml"/>
- No
- </label>
- <h4>Registration Email Subject</h4>
- <input id="newuseremailsubject" type="text" size="40" style="font-size: 12px;" value="<?php _e(stripslashes(get_option('newuseremailsubject')), 'NewUserEmail') ?>" name="newuseremailsubject"/>
- <h4>Registration Email Text</h4>
- <textarea id="newuseremailtext" style="width: 98%; font-size: 12px;" rows="4" cols="60" name="newuseremailtext"><?php _e(stripslashes(get_option('newuseremailtext')), 'NewUserEmail') ?>
- </textarea>
- <p>Use this to create a custom email that is sent to new users when they register. It overides the default text and you can write anything at all in here, but remember to use the following variables so that your users still know how to login!</p>
- <p>%username%, %useremail%, %password%, %siteurl%, %blogname%, and %loginurl%.</p>
- <p>
- Note the percentage signs (%), each variable must have percentage signs around them with <strong>no spaces</strong>. For an example text, using some of the variables, please see above.
- </p>
- <p><strong>IMPORTANT:</strong> Make sure that you test out your new email by registering yourself so that you see what your users are receiving.</p>
- <h4>From Address</h4>
- <input id="newuseremailfromaddress" type="text" size="40" style="font-size: 12px;" value="<?php _e(stripslashes(get_option('newuseremailfromaddress')), 'NewUserEmail') ?>" name="newuseremailfromaddress"/>
- <p>NB You must have this email set up as a real email address, otherwise it will be sent from your host's mailbox, which looks ugly! This can be different from the address you have set up in your general WordPress options.</p>
- <h4>From Name</h4>
- <input id="newuseremailfrom" type="text" size="40" style="font-size: 12px;" value="<?php _e(stripslashes(get_option('newuseremailfrom')), 'NewUserEmail') ?>" name="newuseremailfrom"/>
- <p>This could be something like 'Epic Alex', or 'Admin'.</p>
- <div class="submit">
- <input type="submit" name="submit" value="<?php _e('Save', 'NewUserEmail') ?>" />
- </div>
- </div>
- </div>
- <div class="postbox close-me nue-right">
- <h3 class="hndle"><span><?php _e('Admin Email Settings','NewUserEmail'); ?></span></h3>
- <div class="inside">
- <h4>Administration Notification Email Subject</h4>
- <input id="newuseremailadminsubject" type="text" size="40" style="font-size: 12px;" value="<?php _e(stripslashes(get_option('newuseremailadminsubject')), 'NewUserEmail') ?>" name="newuseremailadminsubject"/>
- <h4>Administration Notification Email Text</h4>
- <textarea id="newuseremailadmintext" style="width: 98%; font-size: 12px;" rows="4" cols="60" name="newuseremailadmintext"><?php _e(stripslashes(get_option('newuseremailadmintext')), 'NewUserEmail') ?>
- </textarea>
- <p>
- This is to define the email that is sent to the Blog Administrator when a new user registers, you can use the same variables as above.
- </p>
- <div class="submit">
- <input type="submit" name="submit" value="<?php _e('Save', 'NewUserEmail') ?>" />
- </div>
- </div>
- </div>
- <div class="clear"></div>
- <div class="postbox close-me">
- <h3 class="hndle"><span><?php _e('Test','NewUserEmail'); ?></span></h3>
- <div class="inside">
- <p>Once you have saved the above options, this will show you approx. how the email will look, without any of the variables replaced, but with line breaks and formating etc, so send a test one to see it fully in action!</p>
- <h4>New User Email</h4>
- <?php
- echo "<strong>Subject: </strong>" . get_option('newuseremailsubject'). "<br />";
- echo "<strong>From: </strong>" . get_option('newuseremailfrom') . " - " . get_option('newuseremailfromaddress'). "<br/><br/>";
- echo get_option('newuseremailtext');
- ?>
- <h4>Admin Email</h4>
- <?php
- echo "<strong>Subject: </strong>" . get_option('newuseremailadminsubject'). "<br /><br/>";
- echo get_option('newuseremailadmintext');
- ?>
- </div>
- </div>
- <div class="postbox close-me">
- <h3 class="hndle"><span><?php _e('Support','NewUserEmail'); ?></span></h3>
- <div class="inside">
- <h4>Help Me!</h4>
- <p>If you need help with this plugin, or if you want to make a suggestion, then please email me at alex AT epicalex DOT com<p>
- <h4>Support This Plugin!</h4>
- <p>There are a few ways you can support me to say thanks for making this plugin, you can donate by paypal, or you can sign up to something through one of my affiliate links such as Bluehost or Dreamhost.</p>
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
- <input type="hidden" name="cmd" value="_s-xclick">
- <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
- <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
- <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIH0QYJKoZIhvcNAQcEoIIHwjCCB74CAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYCTL5BBkUz91Q8Eczlpdag+dUOTVGLYyJ01JqQZJ6eL/mngkh0Al9ZHLs4Eg6zRi0uZKDL9mL1jA44lXccYXvQR/2U/AbR/Iqt5Bm53knQK21jvWBfCfWu0F6n4DeGWE6Z6ph47K/E4KzA1PPF+yDFWhmOXZum+p1/u3g0JfptjJTELMAkGBSsOAwIaBQAwggFNBgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECInNw4EXU+hKgIIBKC4cqsD8qa0rvG0VBADN+AfZ2evApv8UZSRE83hetSvW0gSTtlWdcrryTgXH+4buOWVoia3Q9h2ZQoS7TG2Lsg/ked/HKsq56N31NmuwvwIOWRUCUVdQBjVLI/1WAkoI4dHPiJZrEzwk6ZnUB+cny6NbbJPAdy0iV0iWhMPACBlUeWWZyyf5oX4Zps3Jdc6LSxZFTQfyCafkTN9Q40nD2cS96or4pR1TTFMhIW/vRBYs57SxXezRB3lGXKhCB6OhUMUz7Tu++fVCxlZfU3rMjVvVMuW1fOytBd+FYelLRrPJI1OL92hn5bqtEWhgKV7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22CAQAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCBXzpWmoBa5e9fo6ujionW1hUhPkOBakTr3YCDjbYfvJEiv/2P+IobhOGJr85+XHhN0v4gUkEDI8r2/rNk1m0GA8HKddvTjyGw/XqXa+LSTlDYkqI8OwR8GEYj4efEtcRpRYBxV8KxAW93YDWzFGvruKnnLbDAF6VR5w/cCMn5hzGCAZowggGWAgEBMIGUMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMDcwOTE2MTIzNTI5WjAjBgkqhkiG9w0BCQQxFgQUO8VgKDY/L7ZK6dixcQQcelKP8jgwDQYJKoZIhvcNAQEBBQAEgYBwO7oj0n+w5qzFm7YhGpFhfFs9IY9OSZ48icbxpamPVBariw6d1/XRxYhe6W/7UGyAVRlKW1Nm5pHRvxWY9UAmHXMlMtHprs/OT3u8BJQ9E1T6a8qsHwdAQtefD52raiBwxPoEz7FXVjXD9SbSn33PLRmPIhiPJ4S+wSZudwKGfw==-----END PKCS7-----
- ">
- </form>
- <script src=http://www.bluehost.com/src/js/epicskitours/CODE15/88x31/3.gif></script>
- <p>when you visit www.dreamhost.com and sign up for hosting, be sure to use the promo code ALEXMYSOUTHAM to get $50 off your bill, PLUS 10% extra bandwidth!</p>
- </div>
- </div>
- </div>
- </form>
- <script type="text/javascript">
- <!--
- jQuery('.postbox h3').before('<div class="handlediv" title="Click to toggle"><br /></div>');
- jQuery('.postbox h3').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); } );
- jQuery(this).addClass("closed");
- });
- //-->
- </script>
- <?php }
- function newuseremailoptions() {
- add_options_page(
- 'New User Email',
- 'New User Email',
- 'manage_options',
- __FILE__,
- 'printnewuseremailAdminOptions'
- );
- }
- ?>
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.