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

I’d appreciate any insights you have!

2 Answers
2

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;
} 

Leave a Comment