Display of sender's name on message pages

Continuing the discussion from Showing empty account pages and sending welcome email:

I tried the code presented in the above topic and customised ‘sender__display_name’. However, the sender name on the message page is not ‘sender__display_name’ but the actual sendername. See the red text.As the message is sent from the administrator account, it would not be good security practice for the administrator’s username to be displayed.
How can I make this part also ‘sender__display_name’?

add_action(
	'hivepress/v1/models/user/register',
	function($user_id, $values){
		$admin_email = get_option('admin_email');
		
		if(!$admin_email){
			return;
		}
		
		$user = \HivePress\Models\User::query()->filter(['email' => $admin_email])->get_first();
		
		if(!$user){
			return;
		}
		
		( new \HivePress\Models\Message() )->fill(
			[
				'sender'               => $user->get_id(),
				'sender__display_name' => 'うめま 管理者',
				'sender__email'        => $user->get_email(),
				'recipient'            => $user_id,
				'read'                 => 0,
				'text' => 'ご登録ありがとうございます!ご不明点・問題点等ありましたらこちらから管理者へメッセージください。',
			]
		)->save();
	},
	1000,
	2
);

Hi,

Thanks for reporting this, the bug is confirmed, and we’ll fix it as soon as possible. Currently, the workaround is to overwrite the template parts with a child theme: How to override template parts - HivePress Help Center

Thanks for the reply.
Hopefully the bug will be fixed.
If it takes longer I’ll try to override the template parts but I don’t know how to do that.
Is the file to be changed ‘templates/page/page-title.php’?
How do I change the title of the individual message pages?

Sorry for the confusion, there should be display name everywhere in messages. For example, here’s the message sender template part hivepress-messages/templates/message/view/message-sender.php at master · hivepress/hivepress-messages · GitHub and this is where the messages page title is set hivepress-messages/includes/controllers/class-message.php at master · hivepress/hivepress-messages · GitHub Both use “display_name” instead of “username”. Please make sure that after setting the Display Name format in HivePress/Settings/Users, you re-saved the user profile, a new display name should be generated.

I have found the cause.
As you can see from the code shown previously, ‘sender__display_name’ is defined as ‘うめま 管理者’, only in the scope of sending the welcome message.
It does not override the name of the administrator itself. This is why the name of the administrator is displayed on message pages and message sender templates that are outside the scope of the welcome message.

Here is a new suggestion.
As I asked in the link topic, if I could implement forbidding login by username and forcing login by email address, would there be any security issues with changing the administrator’s username itself to ‘うめま 管理者’?

Hi,

We will test this issue in more detail with the dev team. Yes, you can force users to log in only by email, but note that this will not affect the display itself, only the login process. The display is configured in HivePress > Settings > Users.

Thank you. I wish your team all the best.
Iwill continue to ask about specific code validation in this link.

https://community.hivepress.io/t/how-to-force-people-to-log-in-with-their-email-address-instead-of-their-username/12676

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.