I would like to send an email to all editors of my blog when a new article has been published. I found many plugins but I want to solve this problem without plugins. In addition, I found a tutorial to send an email, but this is only for administrators of the blog but not for editors (Front-End Editor email notification issue). I would be happy if you could give me a tip or advice. Thank you.
<?php
function notifyauthor( $post_id ) {
$post = get_post( $post_id );
$author = get_userdata( $post->post_author ); // How can I specify the role of the editors here?
$subject = "Post Published: " . $post->post_title;
$message = ' Hi ' . $author->display_name . ',
Your post, "' . $post->post_title . '" has just been published.
View post: ' . get_permalink( $post_id ) . 'Thanks';
wp_mail( $role->user_email, $subject, $message );
}
add_action( 'publish_post', 'notifyauthor' );