Skip to content

Instantly share code, notes, and snippets.

@adamcbrewer
Created March 14, 2012 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcbrewer/2038212 to your computer and use it in GitHub Desktop.
Save adamcbrewer/2038212 to your computer and use it in GitHub Desktop.
WP: Email Users On Post
<?php
function email_members($post_ID) {
global $wpdb;
// fetch the list of users registered
foreach( $wpdb->get_results("SELECT user_email FROM $wpdb->users;") as $key => $object) {
$user_emails[] = $object->user_email;
}
$users = implode(',', $user_emails);
$subject = "";
$message = "";
$headers .= 'From: ' . "\r\n";
mail($users, $subject, $message, $headers);
return $post_ID;
}
add_action('publish_post', 'email_members');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment