Return to Snippet

Revision: 53221
at November 16, 2011 20:45 by eniris


Updated Code
/**
 * Automatically Notify Your Members on New Posts
 * Send an email to all registered users when a post is published, for wordpress 3.1+
 * Simply place this code into your functions.php file.
 * source : http://wp-snippets.com/575/automatically-notify-your-members-on-new-posts/
 */
function email_members($post_ID)  {
    //global $wpdb;
    //$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
	$wp_user_search = new WP_User_Query( array( 'fields' => array('user_email') ) );
	$usersarray = $wp_user_search->get_results();
	$arrUsers = array ();
	for ($arr = $usersarray, $mU = count ($arr), $iU = 0; $iU < $mU; $iU++) {
		$arrUsers[] = $arr[$iU]->user_email;
	} // for
	$users = implode(",", $arrUsers);
	
	mail($users, "New post notification : " . get_bloginfo('name') , "A new post has been published on " . get_bloginfo('siteurl') );
    return $post_ID;
}
add_action('publish_post', 'email_members');

Revision: 53220
at November 16, 2011 20:36 by eniris


Initial Code
/**
 * Automatically Notify Your Members on New Posts
 * Send an email to all registered users when a post is published, for wordpress 3.1+
 * source : http://wp-snippets.com/575/automatically-notify-your-members-on-new-posts/
 */
function email_members($post_ID)  {
    //global $wpdb;
    //$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
	$wp_user_search = new WP_User_Query( array( 'fields' => array('user_email') ) );
	$usersarray = $wp_user_search->get_results();
	$arrUsers = array ();
	for ($arr = $usersarray, $mU = count ($arr), $iU = 0; $iU < $mU; $iU++) {
		$arrUsers[] = $arr[$iU]->user_email;
	} // for
	$users = implode(",", $arrUsers);
	
	mail($users, "New post notification : " . get_bloginfo('name') , "A new post has been published on " . get_bloginfo('siteurl') );
    return $post_ID;
}
add_action('publish_post', 'email_members');

Initial URL

                                

Initial Description
Send an email to all registered users when a post is published, for wordpress 3.1+

Initial Title
Automatically Notify Your Members on New Posts on WordPress 3.1+

Initial Tags
email, wordpress

Initial Language
PHP