Automatically Notify Your Members on New Posts on WordPress 3.1+


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. /**
  2.  * Automatically Notify Your Members on New Posts
  3.  * Send an email to all registered users when a post is published, for wordpress 3.1+
  4.  * Simply place this code into your functions.php file.
  5.  * source : http://wp-snippets.com/575/automatically-notify-your-members-on-new-posts/
  6.  */
  7. function email_members($post_ID) {
  8. //global $wpdb;
  9. //$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
  10. $wp_user_search = new WP_User_Query( array( 'fields' => array('user_email') ) );
  11. $usersarray = $wp_user_search->get_results();
  12. $arrUsers = array ();
  13. for ($arr = $usersarray, $mU = count ($arr), $iU = 0; $iU < $mU; $iU++) {
  14. $arrUsers[] = $arr[$iU]->user_email;
  15. } // for
  16. $users = implode(",", $arrUsers);
  17.  
  18. mail($users, "New post notification : " . get_bloginfo('name') , "A new post has been published on " . get_bloginfo('siteurl') );
  19. return $post_ID;
  20. }
  21. add_action('publish_post', 'email_members');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.