Skip to:
Content
Pages
Categories
Search
Top
Bottom

New User Notification Email to Admin

  • @michaelpfaff

    Participant

    How do I get custom profile fields that I add to user registration to appear in the notification email to the admin? Right now I just get username and email? I want to see the custom (optional) field if they fill it out.

Viewing 1 replies (of 1 total)
  • @michaelpfaff

    Participant

    I figured this out by cobbling together some code. Just copy this into a new .php file, upload to /plugins and activate. You’ll need to change ‘Referrer’ to whatever profile field you have instead.

    <?php
    /*
    Plugin Name: Custom New User Email
    Description: Changes the copy in the email sent out to new users
    */
     
    // Redefine user notification function
    if ( !function_exists('wp_new_user_notification') ) {
        function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
            $user = get_userdata( $user_id );
          
    	// The blogname option is escaped with esc_html on the way into the database in sanitize_option
    	// we want to reverse this for the plain text arena of emails.
    	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    	
    	// find the profile field for referrer
    	$field1 = xprofile_get_field_data( 'Referrer', $user_id );
    
    	$message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
    	$message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
    	$message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n\r\n";
    	$message .= sprintf(__('Referrer: %s'), $field1) . "\r\n";
    
    	@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
    
    	if ( empty($plaintext_pass) )
    		return;
    
    	$message  = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    	$message .= wp_login_url() . "\r\n";
    
    	wp_mail($user->user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
     
         }
    }
     
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘New User Notification Email to Admin’ is closed to new replies.
Skip to toolbar