WordPress.org

Ready to get started?Download WordPress

Forums

Customizing wp_new_user_notification not working (3 posts)

  1. joschi81
    Member
    Posted 1 year ago #

    Hi there,

    I have a copy of the pluggable function wp_new_user_notification() in my plugin, but it's not working. The text 'test' is not shown in the confirmation e-mail. So, despite my 'unhooking' of the respective function from pluggable.php, the function defined there is being called.

    Any ideas?

    if ( !function_exists('wp_new_user_notification') ) :
    function wp_new_user_notification($user_id, $plaintext_pass = '') {
    	$user = new WP_User($user_id);
    
    	$user_login = stripslashes($user->user_login);
    	$user_email = stripslashes($user->user_email);
    
    	// 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);
    
    	$message  = sprintf(__('New user registration on your site %s:'), $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'), $blogname), $message);
    
    	if ( empty($plaintext_pass) )
    		return;
    
    	$message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
    	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    	$message .= wp_login_url() . "\r\n";
    	$message .= 'test'."\r\n";
    
    	wp_mail($user_email, sprintf(__('[%s] Your username and password blanblana'), $blogname), $message);
    
    }
    endif;

    Thanks!
    joschi81

  2. linux4me2
    Member
    Posted 1 year ago #

    It looks like you have an error in your code. Instead of:
    wp_mail($user_email, sprintf(__('[%s] Your username and password blanblana'), $blogname), $message);
    it should be:
    wp_mail($user_email, sprintf(__('[%s] Your username and password blanblana'), $blogname, $message);
    I'm not sure that the extra ")" in there could be the source of the problem, but that's the first thing I'd try.

    Are there any error messages in your error logs? Is the plugin activated?

  3. joschi81
    Member
    Posted 1 year ago #

    Hi linux4me2,

    no, that's definetely not causing the problem. I think, the ")" has to be there, otherwise not all "(" are closed with ")".

    When I change the name of the function, it is working perfectly. I can test it, because I call wp_new_user_notification from a custom register form in the same plugin. So when I change the function name to wp_new_user_notification_new and call wp_new_user_notification_new($user_id, $user_pass); in my plugin, it is working.

    Very strange. Why does it work in so many demo plugins that I found using Google, but not in my case? Mysterious.

    Regards
    joschi81

Topic Closed

This topic has been closed to new replies.

About this Topic