wp_mail BCC admin

时间:2014-07-06 作者:APDB

这段代码正是我想要的,但我想添加文章作者的用户名。

// 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 );
endif;
我试过了id_author 几乎到处都是,但它不起作用:

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

1 个回复
最合适的回答,由SO网友:karpstrucking 整理而成

$post->post\\u author将返回post author的ID,然后您可以将其与WP\\u用户对象一起使用,以检索用户名并添加到传出的电子邮件中:

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 );
endif;

Codex: WP_Post

Codex: WP_User

结束

相关推荐