WordPressでパスワード変更を知らせるメールを複数に送る方法

Pocket

クローズドな会員サイトを運営している方からの依頼。

パスワードを忘れて変更されるユーザーが多いようなので、どのユーザーがどれくらいの頻度でパスワード変更しているのかを知りたいとのこと。

そこで、パスワード変更される際に、「パスワードの失効と変更」メール(admin_emailに送られるやつ)と同じものを、特定のメールアドレスへ送るようにした。

以下対応メモ。

  1. wp-includes/pluggables.php を開き、 wp_password_change_nofification() を探す
  2. wp-mail()でメールを送信しているので、メールを送りたい先を追記する
function wp_password_change_notification(&$user) {
	// send a copy of password change notification to the admin
	// but check to see if it's the admin whose password we're changing, and skip this
	if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
		$message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
		// 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);
		wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), $blogname), $message);
		// 追記
		wp_mail( 'your-desired-email@hoge.com', sprintf(__('[%s] Password Lost/Changed'), $blogname), $message);
	}
}

 

この関数の中身を変更すると、パスワード変更のメールを送信しなかったり、文面を変えたりすることも容易にできる。