我想将这段代码添加到我的函数中。php文件,这样当用户创建第一篇帖子时,他会收到一封祝贺他的电子邮件。
function set_mail_html_content_type() {
return \'text/html\';
}
add_action( \'publish_post\', \'author_publish_notice\', 10 ,2 );
function author_publish_notice( $ID, $post ) {
if( \'post\' == $post->post_type && count_user_posts(the_author_meta(\'ID\') == 1); ) {
return;
}
$to = \'[email protected]\';
$subject = \'Your Article Is Online\';
$message = \'<h1>Congratulations!</h1> <p>Your article is now online and
is sure to receives trillions of comments. Please do hang around and answer any questions
viewers may have!</p> <p><a href="\' . get_permalink( $ID ) . \'">\' . $post->post_title . \'</a></p>\';
add_filter( \'wp_mail_content_type\', \'set_mail_html_content_type\' );
wp_mail( $to, $subject, $message );
remove_filter( \'wp_mail_content_type\', \'set_mail_html_content_type\' );
}
然而,我对这句话有疑问:
$to = \'[email protected]\';
要检索作者的电子邮件,codex显示如下:
<?php the_author_email(); ?>
这有意义吗?:
$to = the_author_email();
此外,这足以添加一个条件,即该帖子是作者的第一篇帖子:
if( \'post\' == $post->post_type && count_user_posts(the_author_meta(\'ID\') == 1); )
谢谢你的时间和帮助