使用get_users()
作用Reference
function notify_editors( $post_id ) {
$post = get_post( $post_id );
// Get all editors
$editors = get_users( [ \'role__in\' => [ \'editor\'] ] );
foreach ( $editors as $editor ) {
// Setup email
$subject = "Post Published: " . $post->post_title;
$message = \' Hi \' . $editor->display_name . \',
Your post, "\' . $post->post_title . \'" has just been published.
View post: \' . get_permalink( $post_id ) . \'Thanks\';
// and send...
wp_mail( $editor->user_email, $subject, $message );
}
}
add_action( \'publish_post\', \'notify_editors\' );
你可以阅读更多
here, 关于可选
headers
可以添加以下字段的参数
from
,
cc
,
content-type
等