Hello,
I am trying to add a welcome message automatically as user registers, based on this snippet. 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, I saw it was possible to retrieve the message ID, once it has been created/saved :
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 ?
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
);