I just downloaded and configured the simple forums plugin within the past week.  It went live today.  I noticed that I was not getting emails when new topics were created in the categories that I am subscribed to (but I was getting emails for individual threads I was subscribed to).

Digging into the files, I found the following code on /forum/forum-posts-reply.php 

//Send thread followers emails letting them know the thread has been updated.
      sforum_sendFollowersPostNotifications($post, $topic, $forum);

Which is the code that was sending me emails properly when someone replied to a thread.

I looked for something similar in /forum/forum-topics-create.php that would generate an email when a NEW topic was created but I couldn't find it anywhere.  After looking at the function, it seemed to me that the same function is used to send both emails (new topics and replies). So I just copied the code into the forum-topics-create.php file and tested it.  It seemed to work fine!  

I just re-downloaded the simple forum plugin and checked it from a fresh download ... the code is missing from forum-topics-create.php

So my question is this...

Was I right to insert that code so that email will get sent when someone subscribes to a forum ... or is there a different code that does that and I am just not seeing it.  My fix seemed to work but I'm nervous it wasn't the right thing to do.  Is the sforum_sendFollowersPostNotifications functions intended to send both types of subscriber emails or is there a different function I should be using?


Great find, Wizzle.

That line was missing and it sounds like you added it back in the right place.  

I've released an update with that fix and PHP 7 support.

Thanks for letting us know, much appreciated!

Dave Edis - Senior Developer

Hi Wizzle, 

It works as you describe in option A:

>A. get emails for all new threads within the category AND for all replies to threads in the category

How could I modify the line on  /forum/forum-posts-reply.php (the code that was missing) so that replies to a topic only send emails to people specifically subscribed to that topic, but not to people that are just generally subscribed to the entire category.

Hmm, there's no easy way to do that.  What you'd probably need to do was modify sforum_sendFollowersPostNotifications() to check how many posts were in a topic ( $topic['posts'] ) and then update sforum_db_getFollowerEmails() to only return forum subscriber emails if the topic only had 1 post.  

It would take a bit of custom programming and experimentation.

Dave Edis - Senior Developer

Thanks Dave.

I'm digging deep for a little help here. I really have no idea what I'm doing, but I think I've found a route to make this change pretty easy.  But in order to test it, I'll have to set up a new site, install CMSB, membership plugin, forum plugin etc to have a testing playground (my site that I need it for is now active.) So before I go through all that, let me know if this approach sound decent (pretty please!)

Currently, the page creating a new topic (forum-topics-create.php) and the page generating a reply to a topic (forum-posts-reply.php) both use the same function to send the email notifications. It's called sforum_sendFollowersPostNotifications($post, $topic, $forum);  

That function exists on the page simpleForum.php, but within that function is a call to another function  foreach (sforum_db_getFollowerEmails($topic['num'], $forum['num']) as $followerEmail) . This function seems to be where the list of people following a specific topic are joined together with those follow the entire category to make a single array of email addresses for the notification.  The function code looks like

function sforum_db_getFollowerEmails($topicNum, $forumNum) {
  global $TABLE_PREFIX;
  $followersQuery   = mysql_escapef("SELECT tu.email
                                      FROM `{$TABLE_PREFIX}_frm_topic_follow` tf
                                      JOIN `{$TABLE_PREFIX}".accountsTable()."` tu
                                        ON tf.userNum = tu.num
                                      WHERE tf.topicNum = ?
                                      SELECT fu.email
                                      FROM `{$TABLE_PREFIX}_frm_forum_follow` ff
                                      JOIN `{$TABLE_PREFIX}".accountsTable()."` fu
                                        ON ff.userNum = fu.num
                                      WHERE ff.forumNum = ? 
                                       ", $topicNum, $forumNum  );
  $followers = mysql_fetch($followersQuery);
  return array_pluck($followers, 'email');

My Plan is basically this...

1. Leave the sforum_db_getFollowerEmails function alone, but make another very similar function that does not combine the general category followers but instead it only includes the followers of the specific topic.  I would call it sforum_db_getReplyFollowerEmails.

2. Leave the sforum_sendFollowersPostNotifications function alone, but make another very similar function called sforum_sendReplyFollowersPostNotifications .  The only difference is that this function would call the new sforum_db_getReplyFollowerEmails from step 1.

3. On forum-posts-reply.php replace sforum_sendFollowersPostNotifications($post, $topic, $forum);
with sforum_sendReplyFollowersPostNotifications($post, $topic, $forum);

If that plan seems reasonable, I would just need help modifying the QUERY in the code block above. 

Hi wizzle, 

Sounds good.  You're getting into some pretty advanced code here.  If at any point you want us to do some consulting to get this working for you just email me direct at dave@interactivetools.com.  Beyond that, you can split the query in sforum_db_getFollowerEmails()  into two queries, and debug it by calling sforum_db_getFollowerEmails() directly from a test script.  Or create a copy of the function sforum_db_getFollowerEmails2().

Let me know how it goes!

Dave Edis - Senior Developer

Thanks Dave. I'm a novice so this will take some digging on my part.

I did just notice that the auto-generated emails say 

If you don't want to receive updates on this forum topic, please unsubscribe.

So what if I unsubscribe from the forum topic, but I'm still subscribed to the overall forum Category?  Does this link prevent me from getting email notices for replies to that specific topic even if I am subscribed to the entire Forum Category, or does the category subscription override the individual topics?

Hi Wizzle, 

Just wanted to follow up and see if you made any progress with this?  I believe the category subscription overrides.  If you want some minor enhancements to the plugin let me know what they are and I can take a look.

Dave Edis - Senior Developer