• I created a plugin that should override the default WP new registration email, but it isn’t working.

    I created a file in my plugins directory called welcome_email_override.php, activated it and when I register a test user, the default WP email is still sent.

    Is there anyway to do this without modifying the pluggable.php file?

    Here is my code:

    <?php
    
    /*
    Plugin Name: wp_new_user_notification change subject line
    Plugin URI: https://www.premiumstockmusic.com
    Description: wp_new_user_notification changing the subject line
    Author: Dennis Monsewicz
    Version: 1
    Author URI: https://dennismonsewicz.com
    */
    
    /**
     * Notify the blog admin of a new user, normally via email.
     *
     * @since 2.0
     *
     * @param int $user_id User ID
     * @param string $plaintext_pass Optional. The user's plaintext password
     */
    
    if ( !function_exists('wp_new_user_notification') ) {
    
     function wp_new_user_notification($user_id, $plantext_pass = '') {
       	$user = new WP_User( $user_id );
    
    		$user_login = stripslashes( $user->user_login );
    		$user_email = stripslashes( $user->user_email );
    
    		$message  = sprintf( __('New user registration on %s:'), get_option('blogname') ) . "\r\n\r\n";
    		$message .= sprintf( __('Username: %s'), $user_login ) . "\r\n\r\n";
    		$message .= sprintf( __('E-mail: %s'), $user_email ) . "\r\n";
    
    		@wp_mail(
    			get_option('admin_email'),
    			sprintf(__('[%s] New User Registration'), get_option('blogname') ),
    			$message
    		);
    
    		if ( empty( $plaintext_pass ) )
    			return;
    
    		$message  = __('Hi there,') . "\r\n\r\n";
    		$message .= sprintf( __("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n";
    		$message .= wp_login_url() . "\r\n";
    		$message .= sprintf( __('Username: %s'), $user_login ) . "\r\n";
    		$message .= sprintf( __('Password: %s'), $plaintext_pass ) . "\r\n\r\n";
    		$message .= sprintf( __('If you have any problems, please contact me at %s.'), get_option('admin_email') ) . "\r\n\r\n";
    		$message .= __('Adios!');
    
    		wp_mail(
    			$user_email,
    			'Welcome to Premium Stock Music',
    			$message
    		);
     }
    
    }
    ?>

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code should work unless there is another plugin that is able to register the same function first. It is not in effect immediately after activation, but it should be once WP is reinitialized with a new request.

    In fact it does work on my installation, though I was only getting the admin notice, not the user notice. I then noticed you misspelled the password parameter (“plantext” instead of “plaintext”) which caused the function to abort after the admin email.

    If all else fails you could hook the ‘wp_mail’ filter and check for the subject line. When the correct subject is found, replace all the parameters with your own values.

Viewing 1 replies (of 1 total)
  • The topic ‘Overriding default new user registration email’ is closed to new replies.