I would just use str_replace()
to handle a “pseudo” shortcode. Something like this:
$body = sprintf('Hey {{username}}, your awesome post has been published!
See <%s>', get_permalink($post) );
// Add replacement values to the array as necessary.
$old = array( '{{username}}' );
$new = array( esc_html($user->display_name) );
$body = str_replace( $old, $new, $body );
// Now send to the post author.
wp_mail($user->user_email, 'Your post has been published!', $body);
I just worked from what you started with. I’m assuming you’re doing something ahead of this to get the $user
object. Also, I made the replacement values for str_replace()
as arrays, so you can add to that as necessary (instead of running it multiple times).