简体   繁体   中英

Override WordPress New User registration welcome email

I have create a php file in my plugins directory called welcome_email_override.php

Code:

<?php

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
        );
 }

}


?>

But for some reason my plugin is not kicking in and the WP is using the old new user welcome email.

How are you expecting to load the file? Is it loaded as part of a plugin, or is this supposed to be the plugin? If so, you need a proper plugin header so that you can activate it as a plugin in the plugin panel.

Otherwise, if you are just trying load this function to override the default new user email, then you can add it to your theme's functions.php file.

(Also, you've got a typo in the password argument - "plan..." vs. "plain...")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM