This code does exactly what I want, but I want to add the username of the author of the post.

// BCC Admin
if (get_option('jr_bcc_apply_emails')=='yes') :
    wp_mail( get_option('admin_email'), __('[copy] going for "', APP_TD).$post->post_title.'"',  $message, '', $attachments );

I tried the id_author almost everywhere but it doesn't work:

.., APP_TD).$post->post_title.'".$post->id_author',  $message, '', $attachments );

1 Answer 1


$post->post_author will return the ID of the post author, which you can then use with the WP_User object to retrieve the username and add to the outgoing email:

if (get_option('jr_bcc_apply_emails')=='yes') :
  $author = new WP_User( $post->post_author );
  $username = $author->user_login;
  $to = get_option('admin_email');
  $subject = __('[copy] going for "', APP_TD).$post->post_title.'"';
  $message .+ " {$username}";
  wp_mail( $to, $subject,  $message, '', $attachments );

Codex: WP_Post

Codex: WP_User

  • Thank you for the answer! I tried to insert that but when i receive the email i don't have that data. Probably is just a matter of position in that function but i tried everything that i know and nothing appears Jul 6, 2014 at 23:54
  • I've updated my answer to include your code updated with the username added to the subject. Jul 7, 2014 at 2:14
  • Sorry for the delay and thank you for your help! Your code worked but like you said appears in the subject the name of the author and if i put after or before the message i don't receive the attached files. It's normal? Jul 7, 2014 at 23:47
  • I've updated the answer to include the author's name after the message (and also formatted for clarity). Jul 8, 2014 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.