How do I allow users to follow a post and then allow admins to email all users who have followed that post?

I’m looking to build out the following functionality, but I’m having trouble finding any help on it:

user follows a post > user’s email is pulled into an admin page and associated with said post > admin can then email all users who have followed a single post, updating them when a significant change has been made

Read More

I’d appreciate any insights you have!

Related posts

Leave a Reply

2 comments

  1. I don’t think its polite to send email to all users who Favorited your post. Because some people favorite your post to bookmark it. So don’t combine favorite with follow.

    So here is my suggestion:

    For bookmarking, use WP favorite posts plugin.

    As for the follow there is no plugin exists for normal wordpress installation. However there is a plugin available for buddypress. Its called buddypress follow me.

    You need to replace buddypress functions with default wordpress functions.

    For example, this line uses the function bp_loggedin_user_id(). You need to replace it with get_current_user_id()

    If you don’t have experience in wordpress, then hire an experienced programmer. He/she can finish it within 1 hour.

    I think modifying buddypress plugin is better than coding everything from scratch.

    All the best

    Update

    If you are going to code it from scratch, here is some code

    function wpse_follow() {
        if(!is_user_logged_in()) {
        return false;
        }
        global $post;
        $current_user = get_current_user_id();
        $followers = get_post_meta($post->ID, 'followers');
        if(!$followers) {
        $first_follower = array($current_user);
        update_post_meta($post->ID, 'followers', $first_follower);
        } else {
        $pushed_array = array_push($followers, $current_user);
        update_post_meta($post->ID, 'followers', $pushed_array);
        }
    }
    

    Later you can get the followers array by using this code.

    global $post;
    $followers = get_post_meta($post->ID, 'followers');
    

    Lets retrieve emails of subscribed users.

    $user_emails = array();
    foreach ($followers as $follower) {
        $email = get_user_by('id', $follower);
        $user_emails[] = $email;
    } 
    
  2. Thanks for the answers, people! I got this up and running by leveraging the work already done by http://wordpress.org/extend/plugins/wp-favorite-posts/ and http://yoast.com/wordpress/email-commenters/.

    I edited WP Favorite Posts to create a new DB table and add user emails to an array every time they favorited a post, and then remove the email if they unfavorite. I then rewrote Email Commenters to use the new string of emails associated with WPFP, rather than the commenters.

    The result is pretty simple, where an admin can click the mail link, and open a mailto to the appropriate users to let them know of important changes.