WordPress.org

Ready to get started?Download WordPress

Forums

Fatal error: Cannot redeclare wp_new_user_notification() (5 posts)

  1. SFC
    Member
    Posted 3 years ago #

    I receive the error Fatal error: Cannot redeclare wp_new_user_notification() (previously declared in C:\inetpub\wwwroot\inet_IPS\projectA\wordpress\wp-includes\pluggable.php:1193) in C:\inetpub\wwwroot\inet_IPS\projectA\wordpress\wp-content\plugins\new_user_notification.php on line 49

    The point of my plugin is to redefine the pluggable function wp_new_user_notification() and add the phone number to the email output? What am I doing wrong? Is my plugin syntax wrong at the top in the header or do I need to do something different to use one of the pluggable functions?

    Thanks,
    SFC

    <?php
    /*
    Plugin Name: wp_new_user_notification add phone
    Plugin URI: http://InternetProgrammingServices.com/
    Description: wp_new_user_notification with the addition of phone added to email sent to admin
    Author: Susan F. Cooley
    Version: 1
    Author URI: http://InternetProgrammingServices.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
     */
    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);
    
    	$phone = get_user_meta( $user_id ,'phone' , true);  
    
    	// 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(__('Phone: %s'), $phone) . "\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(__('Phone: %s'), $phone) . "\r\n";
    	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    	$message .= wp_login_url() . "\r\n";
    
    	wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
    
    }
    ?>
  2. SFC
    Member
    Posted 3 years ago #

    The reason I posted in the Hacks forum is because until I can get my plugin to work my only solution is to hack the pluggable.php which I'd rather not have to do.
    SFC

  3. Alex Cragg
    Member
    Posted 3 years ago #

    Hi Susan,

    There are already a few plugins that redeclare this email, mine being one of them: New User Email Setup, so you could either use that, or take a look at the code I use. It doesn't add a phone number to the registration though.

    Looking at your code, I'm not sure that using get_user_meta here would do anything, unless that has already been set by another plugin before the wp_new_user_notification is triggered. Your code doesn't create any extra registration fields for the register page, so I'm assuming that's being handled by another plugin?

    Alex

  4. SFC
    Member
    Posted 3 years ago #

    Alex,

    You are correct I've added the the phone number field to the wp-login.php via a hack and was trying hard to pass the phone number to the admin registration email without hacking anything. I'll review your plugin and see if I can determine what I'm doing wrong.

    Thanks for your response.
    SFC

  5. azureardee
    Member
    Posted 3 years ago #

    Hello SFC,

    I hope this is still useful to you, but I shall reply so that others can benefit from this.

    You just have to add the condition if (!function_exists('wp_new_user_notification') { before your function. Don't worry, it will still override the default pluggable method. I think the plug-in is loaded *before* pluggable.php, but register_activation_hook (the action that corresponds when you "Activate" a plug-in) is loaded *after* pluggable.php. So yes, you still need to check.

    <?php
    /*
    Plugin Name: wp_new_user_notification add phone
    Plugin URI: http://InternetProgrammingServices.com/
    Description: wp_new_user_notification with the addition of phone added to email sent to admin
    Author: Susan F. Cooley
    Version: 1
    Author URI: http://InternetProgrammingServices.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, $plaintext_pass = '') {
    	$user = new WP_User($user_id);
    
    	$user_login = stripslashes($user->user_login);
    	$user_email = stripslashes($user->user_email);
    
    	$phone = get_user_meta( $user_id ,'phone' , true);  
    
    	// 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(__('Phone: %s'), $phone) . "\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(__('Phone: %s'), $phone) . "\r\n";
    	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
    	$message .= wp_login_url() . "\r\n";
    
    	wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
    
    }
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic