# Send HTML message to newly registered user automatically

**URL:** <https://community.hivepress.io/t/send-html-message-to-newly-registered-user-automatically/14960>\
**Category:** Messages\
**Tags:** code\
**Created:** [February 10, 2025, 7:22am UTC](https://community.hivepress.io/t/send-html-message-to-newly-registered-user-automatically/14960 "2025-02-10T07:22:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![condorito.fr](https://community.hivepress.io/user_avatar/community.hivepress.io/condorito.fr/32/11449_2.png) [@condorito.fr](https://community.hivepress.io/u/condorito.fr)\
**Post date:** [February 10, 2025, 7:22am UTC](https://community.hivepress.io/t/send-html-message-to-newly-registered-user-automatically/14960/1 "2025-02-10T07:22:55Z")

</div>

Hello,

I am trying to add a welcome message automatically as user registers, based on this [snippet](https://community.hivepress.io/t/showing-empty-account-pages-and-sending-welcome-email/2653/7). Thanks Yehven, by the way !

However, it seems HTML (even basic like link) is sanitized. And I would like to provide some links.

Reading the [documentation](https://docs.hivepress.io/developer-docs/framework/models), I saw it was possible to retrieve the message ID, once it has been created/saved :

 ![image](https://community.hivepress.io/uploads/default/original/2X/c/cecc9234e6d30a0420ef64125244bbf7af82e0fc.png)

So I want to retrieve the message ID, and update the comment content value with some HTML. However, I can’t. I get an error message saying that `get_id()` method is not recognized (even though the original message is saved correctly in DB).

What’s wrong with my code ?

```auto
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;
		}
		//add message. 
		$admin_welcome_message = ( new \HivePress\Models\Message() )->fill(
			[
				'sender' => $user->get_id(),
				'sender__display_name' => $user->get_display_name(),
				'sender__email' => $user->get_email(),
				'recipient' => $user_id,
				'read' => 0,
				'text' => 'Some basic welcome message, as it get sanitized',
			]
		)->save();

        //error happens here. 
		$admin_msg_id = $admin_welcome_message->get_id();

		$new_content = "This is the <b>updated</b><br> <a href='https://google.com/'>comment</a> content."; 

		$comment_data = array(
			'comment_ID' => $admin_msg_id,
			'comment_content' => $new_content,
		);
		wp_update_comment($comment_data); 
				
	},
	1000,
	2
);

```

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [February 10, 2025, 8:52pm UTC](https://community.hivepress.io/t/send-html-message-to-newly-registered-user-automatically/14960/3 "2025-02-10T20:52:34Z")

</div>

Hi,

Please try to call `save()` separately, after filling it with values. This issue occurs because `save()` returns `true` or `false` (can be used for checking if the model is successfully saved in the DB) instead of the model object.

`$admin_welcome_message->save();`

Hope this helps

---

<div class="post-metadata">

**Author:** ![condorito.fr](https://community.hivepress.io/user_avatar/community.hivepress.io/condorito.fr/32/11449_2.png) [@condorito.fr](https://community.hivepress.io/u/condorito.fr)\
**Post date:** [February 10, 2025, 9:30pm UTC](https://community.hivepress.io/t/send-html-message-to-newly-registered-user-automatically/14960/4 "2025-02-10T21:30:36Z")

</div>

Thank you Boss ! It works like a charm !! 👌

Here’s the updated code, for those interested :

```auto
//add a default HTML message as user registers
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;
		}
		//add message. 
		$admin_welcome_message = ( new \HivePress\Models\Message() )->fill(
			[
				'sender' => $user->get_id(),
				'sender__display_name' => $user->get_display_name(),
				'sender__email' => $user->get_email(),
				'recipient' => $user_id,
				'read' => 0,
				'text' => 'Plain text message', //will be replaced soon !
			]
		);
			
		$admin_welcome_message->save();	

		$new_content = "This is the <b>updated</b><br> <a href='https://google.com/'>HTML</a> content."; //much better 
		
		$comment_data = array(
			'comment_ID' => $admin_welcome_message->get_id(),
			'comment_content' => $new_content,
		);
		wp_update_comment($comment_data); 				
	},
	1000,
	2
);

```

 ![image](https://community.hivepress.io/uploads/default/original/2X/f/f906d557192e9d727bf9250461abc3d92a122bc5.png)

You will notice `<br>` seems to be sanitized (stripped off), so if you want the same behaviour, you just need to add carriage returns, same for paragraphs (double carriage returns).

$new\_content = "I will jump here  
to next line.

And here is a paragraph.

And another one.  
";

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [March 12, 2025, 9:30pm UTC](https://community.hivepress.io/t/send-html-message-to-newly-registered-user-automatically/14960/5 "2025-03-12T21:30:43Z")

</div>

Closed on March 12, 2025, 9:30pm UTC

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