Get all email addresses for Author roles
-
I maintain a multi-author blog. We have a moderation process in place where an author must submit his draft as a private post and notify the group that there is an article awaiting approval. I would like to automate this notification process, but I am a PHP novice. I found the draft-notification plugin which does something similar to what I want except it emails the administrator when a draft is saved. I have successfully modified the script to change it from draft to private post, but I don’t know enough about the WP API to figure out how to grab all the email addresses of anyone with an Author role in order to email them the notice.
Here’s the script as it currently stands. Can someone give me some guidance in how to write a snippet that will grab the email addresses from each user with the role of Author and email them the notification message?
Thanks a lot!
<?php
function dddn_process($id) {global $wpdb;
$tp = $wpdb->prefix;
$result = $wpdb->get_row(“
SELECT post_status, post_title, user_login, user_nicename, display_name
FROM {$tp}posts, {$tp}users
WHERE {$tp}posts.post_author = {$tp}users.ID
AND {$tp}posts.ID = ‘$id’
“);if ($result->post_status == “private”) {
$message = “”;
$message .= “A private post was submitted/updated on ‘” . get_bloginfo(‘name’) . “‘\n\n”;
$message .= “Title: ” . $result->post_title . “\n\n”;// *** Choose one of the following options to show the author’s name
$message .= “Author: ” . $result->display_name . “\n\n”;
// $message .= “Author: ” . $result->user_nicename . “\n\n”;
// $message .= “Author: ” . $result->user_login . “\n\n”;$message .= “Link: ” . get_permalink($id);
$subject = “Private Post Submitted/Updated on ‘” . get_bloginfo(‘name’) . “‘”;
$recipient = get_bloginfo(‘admin_email’);
mail($recipient, $subject, $message);}
}
add_action(‘save_post’, ‘dddn_process’);
?>
- The topic ‘Get all email addresses for Author roles’ is closed to new replies.