wordpressにユーザー登録した際に
ユーザーに届くメールのカスタマイズについてご質問です。
(サイト管理者がユーザー登録してユーザーにメールで通知する場合です。)
以下のプラグインを作成しメールのカスタマイズをしています。
<?php /* Plugin Name: Custom New User Mail Description: 新規ユーザー登録時に送信されるメール内容を変更します */ // 登録メールの内容を変更します。 if ( !function_exists('wp_new_user_notification') ) { function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) { if ( $deprecated !== null ) { _deprecated_argument( __FUNCTION__, '4.3.1' ); } global $wpdb, $wp_hasher; $user = get_userdata( $user_id ); // ブログ名(サイト名)はHTMLのページに表示できるようエスケープ(HTMLの特殊文字を変換)しているため元に戻す $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // === 管理者宛のメール === // 管理者用件名 $subject = "{$blogname}に新規ユーザーが登録されました。"; // 管理者用本文 $message = "ユーザー名は " . $user->user_login . " です。"; @wp_mail(get_option('admin_email'), $subject, $message); // === この部分は変更しないようにしてください === // `$deprecated was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notifcation. if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) { return; } // Generate something random for a password reset key. $key = wp_generate_password( 20, false ); /** This action is documented in wp-login.php */ do_action( 'retrieve_password_key', $user->user_login, $key ); // Now insert the key, hashed, into the DB. if ( empty( $wp_hasher ) ) { require_once ABSPATH . WPINC . '/class-phpass.php'; $wp_hasher = new PasswordHash( 8, true ); } $hashed = time() . ':' . $wp_hasher->HashPassword( $key ); $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) ); // === / ここまで === // === 登録ユーザー宛のメール === // ユーザー用件名 $subject = "[{$blogname}] 会員登録を行いました。"; // ユーザー用本文 $message = "会員サイトへメンバー登録いたしましたのでログインする際に必要なIDとパスワードをお知らせします。\r\n\r\n"; $message .= "●━━━━━━━━━━━━━━━━━━━━━━━━━━━●\r\n\r\n"; $message .= "ユーザー名:{$user->user_login}\r\n"; $message .= "パスワード:{$user->$plaintext_pass}\r\n\r\n"; $message .= "●━━━━━━━━━━━━━━━━━━━━━━━━━━━●\r\n\r\n"; $message .= "ログインURL\r\n"; $message .= "http://member.miu-flower.com/ \r\n\r\n"; wp_mail($user->user_email, $subject, $message); } } ?>
以下のコードの
$message .= "パスワード:{$user->$plaintext_pass}\r\n\r\n";
パスワードの表示ができません。
何か間違いが分かる方がいらっしゃれば
ご教授ください。
お願い致します。
回答2件
あなたの回答
tips
プレビュー