How to customize the e-mail notification of a new wordpress user and find out the role of a registered user

In one of the articles, I talked about how to add a user role selection when registering in WordPress. Now I

I’ll tell you how to customize an e-mail notification about a new WordPress user, so that the site administrator can know what role the new user has registered with.
By default, the new user registration letter contains the following information:

  • New user name
  • New User Email

We need to add information about the user's role to this letter. To do this, edit the system filepluggable.php, which is located:

Advertising

Advertising

/wp-include/pluggable.php

You need to find the function in it:

function wp_new_user_notification($user_id, $plaintext_pass = ”)

After the line:

$message .= sprintf(__(‘E-mail: %s’), $user->user_email) . “rn”;

You need to add the line responsible for the output of the user role:

$message .= sprintf(__(‘Role: %s’), $roles = implode(‘, ‘, $user->roles)) . “rn”;

Also here you can add any of your text, or a code for displaying any other information about the user.
Now how it works:

1. The user is registered in our online store and indicates the type of user the wholesaler or retail buyer

2. A letter is sent to the administrator’s mail stating that a new user is registered

Addition:Be careful, when you update WordPress, the pluggable.php file is overwritten and a new one is created. Therefore, save it and when updating, simply replace it or edit it again.