这段代码正是我想要的,但我想添加文章作者的用户名。
// 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 );
最合适的回答,由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