The way I would approach this is:
- Create several AJAX calls using the nopriv hook bound to the subscribe/follow button clicks.
- Within the PHP callback functions, I would insert value of the tag or the followed user into the logged-in user’s meta using
add_user_meta
,get_user_meta
,delete_user_meta
. - Lastly, I would create a conditional function to use in your templates that pulls down the user meta, checks the current tags or users and then return a bool value so you can render the proper state of your buttons.
The AJAX PHP callback would use something like the following:
global $current_user;
get_currentuserinfo();
$tags = get_user_meta($current_user->ID, 'tag_subscription');
if(in_array($tag_slug, $tags))
//do something
else
add_user_meta($current_user->ID, 'tag_subscription', $tag_slug, false);
To remove an element from the user meta array, you would do the following:
delete_user_meta($current_user->ID, 'tag_subscription', $tag_slug);
The conditional template tag would look like this in your template:
if(is_user_subscribed()){
//display this state of the button
}
else{
//display another state of the button
}
Hope this helps you out!