我认为使用wp\\u mail()函数可以做到这一点(https://developer.wordpress.org/reference/functions/wp_mail/) 沿着publish_post
行动
事实上,publish\\u post action codex页面有一个示例:
https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post
function post_published_notification( $ID, $post ) {
$author = $post->post_author; /* Post author ID. */
$name = get_the_author_meta( \'display_name\', $author );
$email = get_the_author_meta( \'user_email\', $author );
$title = $post->post_title;
$permalink = get_permalink( $ID );
$edit = get_edit_post_link( $ID, \'\' );
$to[] = sprintf( \'%s <%s>\', $name, $email );
$subject = sprintf( \'Published: %s\', $title );
$message = sprintf (\'Congratulations, %s! Your article “%s” has been published.\' . "\\n\\n", $name, $title );
$message .= sprintf( \'View: %s\', $permalink );
$headers[] = \'\';
wp_mail( $to, $subject, $message, $headers );
}
add_action( \'publish_post\', \'post_published_notification\', 10, 2 );
可以对其进行修改,以从自定义字段获取电子邮件地址。